Fog Creek Software
Discussion Board


I have some code using the VirtualProtect API function (Win32)

It runs perfectly in a test app

Identical code moved into the real app - hangs Windows on this call.

The parameters all seems to be valid as far as I can tell

Anybody familiar with this function any any know pecularities?

Monday, June 2, 2003

Does the function return an error with GetLastError()?  (Or does it just hang before you can get the error?)

Are you sure you are calling it on a committed page?

Make sure you're NOT calling it using the shared virtual address space? 0x80000000 - 0xBFFFFFFF. (BIOS - VIDEO MEMORY)

Make sure the pages were allocated with ONE call to VirtualAlloc. (I don't think you can span page regions from different calls)

Can't think of much else atm.

Dave B.
Monday, June 2, 2003

You need a decent debugger that will give you a real stack probe so you can see the machine state before and after the event.

From the behaviour, that it sticks inside VirtualProtect and doesn't pre-empt out suggests that its a stack fault that's overrun and overwritten the next instruction, but not with zeroes, or that a stack fault has caused an infinite loop within the function.

Simon Lucy
Monday, June 2, 2003

I would say double check the memory is the start of a block allocated with VirtualAlloc.  If the memory is allocated by some wrapper or runtime library function and happens not to fall on a page boundary, VirtualProtect can fail, and fail disasterously

By disasterously, I mean at least some versions (ain't tried them all) of Windows will fairly completely: so completely that the system completely is dead or brain scrambled (forget running the debugger - nothing will work properly from then on) until you flip the power switch

S. Tanna
Monday, June 2, 2003

It is a while since I paddled in these puddles but the NuMega products, including a hardware interrupt I always found invaluable.

Simon Lucy
Monday, June 2, 2003

*  Recent Topics

*  Fog Creek Home