WOW64 bug? Get/SetProcessShutdownParameters

33 views
Skip to first unread message

LukeD

unread,
Oct 18, 2006, 11:58:02 PM10/18/06
to
The "GetProcessShutdownParameters" Windows API function is returning me crazy
results from a 32-bit console application running on Windows Server 2003
Standard x64 Edition (Build 3790.srv03_sp1_gdr.060315-1609: Service Pack 1).

The code below illustrates the problem. Expected results:
GetProcessShutdownParameters returned 1, level=0x0, flags=0x0
SetProcessShutdownParameters(0x290,1) returned 1
GetProcessShutdownParameters returned 1,level=0x290,flags=0x1

Results when compiled as a 32-bit console app and run on win2k3 x64 edition:
GetProcessShutdownParameters returned 1, level=0x0, flags=0x0
SetProcessShutdownParameters(0x290, 1) returned 1
GetProcessShutdownParameters returned 1, level=0x50746553, flags=0x65636f72

I see the expected results when compiled as a 32-bit console application and
run on 32-bit win2k3, and when compiled as an x64 console application and run
on x64 win2k3.

Am I overlooking something, or is this is really a bug? Where do I report
bugs?

Thanks,
Luke.

==== test.cpp ====
#include <windows.h>
#include <cstdio>

int main(void)
{
DWORD level=0x42424242, flags=0x43434343;
BOOL ret;
ret = GetProcessShutdownParameters(&level, &flags);
printf(
"GetProcessShutdownParameters returned %d, level=0x%x, flags=0x%x\n",
ret, level, flags);
ret = SetProcessShutdownParameters(0x290, 1);
printf("SetProcessShutdownParameters(0x290, 1) returned %d\n", ret);
ret = GetProcessShutdownParameters(&level, &flags);
printf(
"GetProcessShutdownParameters returned %d, level=0x%x, flags=0x%x\n",
ret, level, flags);
return 0;
}

Jochen Kalmbach [MVP]

unread,
Oct 19, 2006, 2:08:13 AM10/19/06
to
Hi LukeD!

> The "GetProcessShutdownParameters" Windows API function is returning me crazy
> results from a 32-bit console application running on Windows Server 2003
> Standard x64 Edition (Build 3790.srv03_sp1_gdr.060315-1609: Service Pack 1).
>
> The code below illustrates the problem. Expected results:
> GetProcessShutdownParameters returned 1, level=0x0, flags=0x0
> SetProcessShutdownParameters(0x290,1) returned 1
> GetProcessShutdownParameters returned 1,level=0x290,flags=0x1
>
> Results when compiled as a 32-bit console app and run on win2k3 x64 edition:
> GetProcessShutdownParameters returned 1, level=0x0, flags=0x0
> SetProcessShutdownParameters(0x290, 1) returned 1
> GetProcessShutdownParameters returned 1, level=0x50746553, flags=0x65636f72

I can verify the problem on my w2k3-R2 x64 system...


> Am I overlooking something, or is this is really a bug? Where do I report
> bugs?

You can contact MS product support. Because it is a bug, it should be
free of charge.

I will also try to propagate this bug to the PSDK team...

Greetings
Jochen

LukeD

unread,
Oct 19, 2006, 2:41:01 AM10/19/06
to
"Jochen Kalmbach [MVP]" wrote:

> You can contact MS product support. Because it is a bug, it should be
> free of charge.
>
> I will also try to propagate this bug to the PSDK team...

Thanks Jochen. I might rely on your contacts to propagate this, as I don't
have a support contract with Microsoft, and they seem to require a prepayment
for a single incident.

Luke.

ne...@rtrussell.co.uk

unread,
Oct 19, 2006, 4:09:23 AM10/19/06
to
LukeD wrote:
> Results when compiled as a 32-bit console app and run on win2k3 x64 edition:
> GetProcessShutdownParameters returned 1, level=0x50746553, flags=0x65636f72

Which is "SetProce" when converted to a string, incidentally!

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.

Jochen Kalmbach [MVP]

unread,
Oct 19, 2006, 5:01:53 AM10/19/06
to
Hi LukeD!

Normally you can report bugs without any charging...
http://support.microsoft.com/gp/contactbug/

Greetings
Jochen

Jochen Kalmbach [MVP]

unread,
Oct 19, 2006, 5:26:27 AM10/19/06
to
Hi LukeD!

> Thanks Jochen. I might rely on your contacts to propagate this, as I don't
> have a support contract with Microsoft, and they seem to require a prepayment
> for a single incident.

Hmm... it gets very misterious...

The following code

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int _tmain(void)
{
DWORD level=0x42424242, flags=0x43434343;
BOOL ret = 0;

ret = GetProcessShutdownParameters(&level, &flags);
printf("%d, level=0x%x, flags=0x%x\n", ret, level, flags);

ret = SetProcessShutdownParameters(0x290,1);

for(int i=0; i<10; i++)
{
ret = GetProcessShutdownParameters(&level, &flags);
printf("%d, %d, level=0x%x, flags=0x%x\n", i, ret, level, flags);
}
}

produced the following output:
1, level=0x0, flags=0x0
0, 1, level=0x290, flags=0x1
1, 1, level=0x31202c30, flags=0x656c202c
2, 1, level=0x31202c31, flags=0x656c202c
3, 1, level=0x31202c32, flags=0x656c202c
4, 1, level=0x31202c33, flags=0x656c202c
5, 1, level=0x31202c34, flags=0x656c202c
6, 1, level=0x31202c35, flags=0x656c202c
7, 1, level=0x31202c36, flags=0x656c202c
8, 1, level=0x31202c37, flags=0x656c202c
9, 1, level=0x31202c38, flags=0x656c202c

It seems that it has something to do with the "printf"!...

Hmmm....
If you comment-out the "printf" then you can see the right values in the
debugger...

Hmm... maybe someone other sees the bug !?

Greetings
Jochen

Jochen Kalmbach [MVP]

unread,
Oct 19, 2006, 6:30:31 AM10/19/06
to
Hi!

> If you comment-out the "printf" then you can see the right values in the
> debugger...

It seems to be a major bug in the communication or parameter-handling
with the CSR subsystem... tonight I will try to look at the source...
and will report it to the PSDK team.

Here is a small report code without CRT dependency:

#include <windows.h>
#include <tchar.h>
int _tmain(void)
{
BOOL ret = 0;
char buf[10];
DWORD dwWritten;
for(int i='a'; i<='z'; i++)
{
DWORD level=0x42424242, flags=0x43434343;

// just output some string, so the CSR-Buffer will be filled...
buf[0] = i;
buf[1] = '\n';
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), buf, 2, &dwWritten,
NULL);

// now read the "ShutdownParameters"
ret = GetProcessShutdownParameters(&level, &flags);
if (ret != FALSE)
{
buf[0] = level;
buf[1] = (level >> 8);
buf[2] = (level >> 16);
buf[3] = (level >> 24);
buf[4] = '\n';
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), buf, 5,
&dwWritten, NULL);
}
}
}

Greetings
Jochen

LukeD

unread,
Oct 19, 2006, 7:06:02 AM10/19/06
to
"Jochen Kalmbach [MVP]" wrote:

> Hmm... it gets very misterious...
>
> The following code

...


> produced the following output:
> 1, level=0x0, flags=0x0
> 0, 1, level=0x290, flags=0x1
> 1, 1, level=0x31202c30, flags=0x656c202c
> 2, 1, level=0x31202c31, flags=0x656c202c
> 3, 1, level=0x31202c32, flags=0x656c202c
> 4, 1, level=0x31202c33, flags=0x656c202c
> 5, 1, level=0x31202c34, flags=0x656c202c
> 6, 1, level=0x31202c35, flags=0x656c202c
> 7, 1, level=0x31202c36, flags=0x656c202c
> 8, 1, level=0x31202c37, flags=0x656c202c
> 9, 1, level=0x31202c38, flags=0x656c202c
>
> It seems that it has something to do with the "printf"!...

Yeah, the 8 chars from (char*)&level actually correspond to a prefix of the
previous printf output:
0x30,0x2c,0x20,0x31,0x2c,0x20,0x6c,0x65 = "0, 1, le"
0x31,0x2c,0x20,0x31,0x2c,0x20,0x6c,0x65 = "1, 1, le"
0x32,0x2c,0x20,0x31,0x2c,0x20,0x6c,0x65 = "2, 1, le"
etc.

This is consistent with what Richard noticed in my original example, that
the numbers corresponded to "SetProce".

Perhaps these numbers are left in the freed area of the stack by printf, and
taken from there by the buggy GetProcessShutdownParameters?

> Hmmm....
> If you comment-out the "printf" then you can see the right values in the
> debugger...

Hmm, I might have a look in the debugger when I get back to work in the
morning.

Luke.

Jochen Kalmbach [MVP]

unread,
Oct 19, 2006, 7:13:44 AM10/19/06
to
Hi LukeD!

>> If you comment-out the "printf" then you can see the right values in the
>> debugger...
>
> Hmm, I might have a look in the debugger when I get back to work in the
> morning.

As in my other post stated: it has nothing to do with printf, insteal
with the calling of the CSR-Subsystem which seems to forget to fill the
buffer (which is used for passing parameters) with the correct values;
and therefor the old values (from OutputConsoleA) are still there...

So it seems to be a bug...

Greetings
Jochen

LukeD

unread,
Oct 19, 2006, 7:27:02 AM10/19/06
to
"Jochen Kalmbach [MVP]" wrote:
> As in my other post stated: it has nothing to do with printf, insteal
> with the calling of the CSR-Subsystem which seems to forget to fill the
> buffer (which is used for passing parameters) with the correct values;
> and therefor the old values (from OutputConsoleA) are still there...
>
> So it seems to be a bug...

Ah good work, sorry that I didn't see your post before I sent mine.

Luke.

ne...@rtrussell.co.uk

unread,
Oct 19, 2006, 9:43:42 AM10/19/06
to
Jochen Kalmbach [MVP] wrote:
> Normally you can report bugs without any charging...
> http://support.microsoft.com/gp/contactbug/

Which is no use if you are outside the US. I am in the UK and long ago
gave up trying to report bugs to Microsoft, because they simply refer
you to their UK office (which can only be contacted by phone or fax!).

Jochen Kalmbach [MVP]

unread,
Oct 19, 2006, 12:39:24 PM10/19/06
to
Hi LukeD!

Ok, after looking at the source, it seems that it is again doing a
"SetProcessShutdownParameters" without any valid values... therefor
these bad values will be returned.

On the other hand it means: if you just call
"SetProcessShutdownParameters", then it will set the correct values.
But you must never call "GetProcessShutdownParameters", because this
will lead to a inconsistent state...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Jochen Kalmbach [MVP]

unread,
Oct 20, 2006, 4:55:39 AM10/20/06
to
Hi LukeD!

> Ah good work, sorry that I didn't see your post before I sent mine.

Can you send me an private mail
to "jochen" addd "kalmbachnet" dott "de"!?

Greetings
Jochen

Reply all
Reply to author
Forward
0 new messages