mirror of
https://github.com/reactos/reactos.git
synced 2025-05-22 02:25:18 +00:00
[KERNEL32]
- Always allocate a guard page at the bottom of the stack. It doesn't depend on it being reserved or committed, it just has to be here. svn path=/trunk/; revision=64525
This commit is contained in:
parent
0b6013a4f6
commit
960c80a31b
1 changed files with 13 additions and 30 deletions
|
@ -358,7 +358,6 @@ 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",
|
||||||
|
@ -426,18 +425,6 @@ 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,
|
||||||
|
@ -457,26 +444,22 @@ BaseCreateStack(HANDLE hProcess,
|
||||||
InitialTeb->StackLimit = (PVOID)Stack;
|
InitialTeb->StackLimit = (PVOID)Stack;
|
||||||
|
|
||||||
/* Create a guard page */
|
/* Create a guard page */
|
||||||
if (UseGuard)
|
GuardPageSize = PageSize;
|
||||||
|
Status = NtProtectVirtualMemory(hProcess,
|
||||||
|
(PVOID*)&Stack,
|
||||||
|
&GuardPageSize,
|
||||||
|
PAGE_GUARD | PAGE_READWRITE,
|
||||||
|
&Dummy);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Set the guard page */
|
DPRINT1("Failure to set guard page\n");
|
||||||
GuardPageSize = PAGE_SIZE;
|
return Status;
|
||||||
Status = NtProtectVirtualMemory(hProcess,
|
|
||||||
(PVOID*)&Stack,
|
|
||||||
&GuardPageSize,
|
|
||||||
PAGE_GUARD | PAGE_READWRITE,
|
|
||||||
&Dummy);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("Failure to set guard page\n");
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the Stack Limit keeping in mind the Guard Page */
|
|
||||||
InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
|
|
||||||
GuardPageSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update the Stack Limit keeping in mind the Guard Page */
|
||||||
|
InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
|
||||||
|
GuardPageSize);
|
||||||
|
|
||||||
/* We are done! */
|
/* We are done! */
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue