[PATCH 2/2] kernel32: Set up a guard page at the bottom of the fiber stack.

Zebediah Figura zfigura at codeweavers.com
Wed Jun 12 16:03:52 CDT 2019


On 6/12/19 3:36 PM, Alexandre Julliard wrote:
> Zebediah Figura <zfigura at codeweavers.com> writes:
> 
>> @@ -96,16 +98,19 @@ LPVOID WINAPI CreateFiberEx( SIZE_T stack_commit, SIZE_T stack_reserve, DWORD fl
>>           return NULL;
>>       }
>>   
>> +    GetSystemInfo(&si);
>> +
>>       /* FIXME: should use the thread stack allocation routines here */
>>       /* some applications try to use more stack than they allocate */
>> -    stack_reserve = max(stack_reserve, 1024 * 1024);
>> -    if(!(fiber->stack_allocation = VirtualAlloc( 0, stack_reserve, MEM_COMMIT, PAGE_READWRITE )))
>> +    stack_reserve = max(stack_reserve, 1024 * 1024 - 3 * si.dwPageSize);
>> +    if(!(fiber->stack_allocation = VirtualAlloc( 0, stack_reserve + 3 * si.dwPageSize, MEM_COMMIT, PAGE_READWRITE )))
>>       {
>>           HeapFree( GetProcessHeap(), 0, fiber );
>>           return NULL;
>>       }
>> -    fiber->stack_base  = (char *)fiber->stack_allocation + stack_reserve;
>> -    fiber->stack_limit = fiber->stack_allocation;
>> +    VirtualProtect(fiber->stack_allocation, 3 * si.dwPageSize, PAGE_NOACCESS, &prev);
>> +    fiber->stack_base  = (char *)fiber->stack_allocation + 3 * si.dwPageSize + stack_reserve;
>> +    fiber->stack_limit = (char *)fiber->stack_allocation + 3 * si.dwPageSize;
> 
> Like the FIXME says, this should reuse the thread stack allocation
> routines, instead of reinventing them.
> 
> Currently it's implemented in virtual_alloc_thread_stack(), but this
> could be adapted and exported as RtlCreateUserStack().
> 

Sure, I'll use that approach instead.



More information about the wine-devel mailing list