Hi,

This code changes Windows behavior.

Best regards,
Alex Ionescu

On Sat, Oct 4, 2014 at 1:25 PM, <jgar...@svn.reactos.org> wrote:

> Author: jgardou
> Date: Sat Oct  4 20:25:35 2014
> New Revision: 64525
>
> URL: http://svn.reactos.org/svn/reactos?rev=64525&view=rev
> Log:
> [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.
>
> Modified:
>     trunk/reactos/dll/win32/kernel32/client/utils.c
>
> Modified: trunk/reactos/dll/win32/kernel32/client/utils.c
> URL:
> http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/utils.c?rev=64525&r1=64524&r2=64525&view=diff
>
> ==============================================================================
> --- trunk/reactos/dll/win32/kernel32/client/utils.c     [iso-8859-1]
> (original)
> +++ trunk/reactos/dll/win32/kernel32/client/utils.c     [iso-8859-1] Sat
> Oct  4 20:25:35 2014
> @@ -358,7 +358,6 @@
>      NTSTATUS Status;
>      PIMAGE_NT_HEADERS Headers;
>      ULONG_PTR Stack;
> -    BOOLEAN UseGuard;
>      ULONG PageSize, Dummy, AllocationGranularity;
>      SIZE_T StackReserveHeader, StackCommitHeader, GuardPageSize,
> GuaranteedStackCommit;
>      DPRINT("BaseCreateStack (hProcess: %p, Max: %lx, Current: %lx)\n",
> @@ -426,18 +425,6 @@
>      /* Update the Stack Position */
>      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 */
>      Status = NtAllocateVirtualMemory(hProcess,
>                                       (PVOID*)&Stack,
> @@ -457,25 +444,21 @@
>      InitialTeb->StackLimit = (PVOID)Stack;
>
>      /* Create a guard page */
> -    if (UseGuard)
> -    {
> -        /* Set the guard page */
> -        GuardPageSize = PAGE_SIZE;
> -        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);
> -    }
> +    GuardPageSize = PageSize;
> +    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);
>
>      /* We are done! */
>      return STATUS_SUCCESS;
>
>
>
_______________________________________________
Ros-dev mailing list
Ros-dev@reactos.org
http://www.reactos.org/mailman/listinfo/ros-dev

Reply via email to