mirror of
https://github.com/reactos/reactos.git
synced 2025-06-27 11:29:44 +00:00
[KERNEL32]
Revert r64525 - Always allocate a guard page at the bottom of the stack. svn path=/trunk/; revision=66323
This commit is contained in:
parent
14cf90ba59
commit
660ebacbe6
1 changed files with 30 additions and 13 deletions
|
@ -358,6 +358,7 @@ BaseCreateStack(HANDLE hProcess,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PIMAGE_NT_HEADERS Headers;
|
PIMAGE_NT_HEADERS Headers;
|
||||||
ULONG_PTR Stack;
|
ULONG_PTR Stack;
|
||||||
|
BOOLEAN UseGuard;
|
||||||
ULONG PageSize, Dummy, AllocationGranularity;
|
ULONG PageSize, Dummy, AllocationGranularity;
|
||||||
SIZE_T StackReserveHeader, StackCommitHeader, GuardPageSize, GuaranteedStackCommit;
|
SIZE_T StackReserveHeader, StackCommitHeader, GuardPageSize, GuaranteedStackCommit;
|
||||||
DPRINT("BaseCreateStack (hProcess: %p, Max: %lx, Current: %lx)\n",
|
DPRINT("BaseCreateStack (hProcess: %p, Max: %lx, Current: %lx)\n",
|
||||||
|
@ -425,6 +426,18 @@ BaseCreateStack(HANDLE hProcess,
|
||||||
/* Update the Stack Position */
|
/* Update the Stack Position */
|
||||||
Stack += StackReserve - StackCommit;
|
Stack += StackReserve - StackCommit;
|
||||||
|
|
||||||
|
/* Check if we will need a guard page */
|
||||||
|
if (StackReserve > StackCommit)
|
||||||
|
{
|
||||||
|
Stack -= PageSize;
|
||||||
|
StackCommit += PageSize;
|
||||||
|
UseGuard = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UseGuard = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocate memory for the stack */
|
/* Allocate memory for the stack */
|
||||||
Status = NtAllocateVirtualMemory(hProcess,
|
Status = NtAllocateVirtualMemory(hProcess,
|
||||||
(PVOID*)&Stack,
|
(PVOID*)&Stack,
|
||||||
|
@ -444,7 +457,10 @@ BaseCreateStack(HANDLE hProcess,
|
||||||
InitialTeb->StackLimit = (PVOID)Stack;
|
InitialTeb->StackLimit = (PVOID)Stack;
|
||||||
|
|
||||||
/* Create a guard page */
|
/* Create a guard page */
|
||||||
GuardPageSize = PageSize;
|
if (UseGuard)
|
||||||
|
{
|
||||||
|
/* Set the guard page */
|
||||||
|
GuardPageSize = PAGE_SIZE;
|
||||||
Status = NtProtectVirtualMemory(hProcess,
|
Status = NtProtectVirtualMemory(hProcess,
|
||||||
(PVOID*)&Stack,
|
(PVOID*)&Stack,
|
||||||
&GuardPageSize,
|
&GuardPageSize,
|
||||||
|
@ -459,6 +475,7 @@ BaseCreateStack(HANDLE hProcess,
|
||||||
/* Update the Stack Limit keeping in mind the Guard Page */
|
/* Update the Stack Limit keeping in mind the Guard Page */
|
||||||
InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
|
InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
|
||||||
GuardPageSize);
|
GuardPageSize);
|
||||||
|
}
|
||||||
|
|
||||||
/* We are done! */
|
/* We are done! */
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue