diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index eb125c07722..da849d55b4d 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -62,7 +62,6 @@ C_SRCS = \ unix/thread.c \ unix/virtual.c \ version.c \ - virtual.c \ wcstring.c RC_SRCS = version.rc diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index d0c2a89d4bb..37dc7c8ab37 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -32,8 +32,8 @@ #include "ddk/wdm.h" #include "wine/exception.h" +WINE_DEFAULT_DEBUG_CHANNEL(thread); WINE_DECLARE_DEBUG_CHANNEL(relay); -WINE_DECLARE_DEBUG_CHANNEL(thread); WINE_DECLARE_DEBUG_CHANNEL(pid); WINE_DECLARE_DEBUG_CHANNEL(timestamp); @@ -303,6 +303,75 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, } +/********************************************************************** + * RtlCreateUserStack (NTDLL.@) + */ +NTSTATUS WINAPI RtlCreateUserStack( SIZE_T commit, SIZE_T reserve, ULONG zero_bits, + SIZE_T commit_align, SIZE_T reserve_align, INITIAL_TEB *stack ) +{ + PROCESS_STACK_ALLOCATION_INFORMATION alloc; + NTSTATUS status; + + TRACE("commit %#lx, reserve %#lx, zero_bits %u, commit_align %#lx, reserve_align %#lx, stack %p\n", + commit, reserve, zero_bits, commit_align, reserve_align, stack); + + if (!commit_align || !reserve_align) + return STATUS_INVALID_PARAMETER; + + if (!commit || !reserve) + { + IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress ); + if (!reserve) reserve = nt->OptionalHeader.SizeOfStackReserve; + if (!commit) commit = nt->OptionalHeader.SizeOfStackCommit; + } + + reserve = (reserve + reserve_align - 1) & ~(reserve_align - 1); + commit = (commit + commit_align - 1) & ~(commit_align - 1); + + if (reserve < commit) reserve = commit; + if (reserve < 0x100000) reserve = 0x100000; + reserve = (reserve + 0xffff) & ~0xffff; /* round to 64K boundary */ + + alloc.ReserveSize = reserve; + alloc.ZeroBits = zero_bits; + status = NtSetInformationProcess( GetCurrentProcess(), ProcessThreadStackAllocation, + &alloc, sizeof(alloc) ); + if (!status) + { + void *addr = alloc.StackBase; + SIZE_T size = page_size; + + NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT, PAGE_NOACCESS ); + addr = (char *)alloc.StackBase + page_size; + NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD ); + addr = (char *)alloc.StackBase + 2 * page_size; + size = reserve - 2 * page_size; + NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT, PAGE_READWRITE ); + + /* note: limit is lower than base since the stack grows down */ + stack->OldStackBase = 0; + stack->OldStackLimit = 0; + stack->DeallocationStack = alloc.StackBase; + stack->StackBase = (char *)alloc.StackBase + reserve; + stack->StackLimit = (char *)alloc.StackBase + 2 * page_size; + } + return status; +} + + +/********************************************************************** + * RtlFreeUserStack (NTDLL.@) + */ +void WINAPI RtlFreeUserStack( void *stack ) +{ + SIZE_T size = 0; + + TRACE("stack %p\n", stack); + + NtFreeVirtualMemory( NtCurrentProcess(), &stack, &size, MEM_RELEASE ); +} + + /****************************************************************************** * RtlGetNtGlobalFlags (NTDLL.@) */ diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c deleted file mode 100644 index 8e512c5d85a..00000000000 --- a/dlls/ntdll/virtual.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Win32 virtual memory functions - * - * Copyright 1997, 2002 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "ntstatus.h" -#define WIN32_NO_STATUS -#define NONAMELESSUNION -#include "windef.h" -#include "winternl.h" -#include "wine/debug.h" -#include "ntdll_misc.h" - -WINE_DEFAULT_DEBUG_CHANNEL(virtual); - - -/********************************************************************** - * RtlCreateUserStack (NTDLL.@) - */ -NTSTATUS WINAPI RtlCreateUserStack( SIZE_T commit, SIZE_T reserve, ULONG zero_bits, - SIZE_T commit_align, SIZE_T reserve_align, INITIAL_TEB *stack ) -{ - PROCESS_STACK_ALLOCATION_INFORMATION alloc; - NTSTATUS status; - - TRACE("commit %#lx, reserve %#lx, zero_bits %u, commit_align %#lx, reserve_align %#lx, stack %p\n", - commit, reserve, zero_bits, commit_align, reserve_align, stack); - - if (!commit_align || !reserve_align) - return STATUS_INVALID_PARAMETER; - - if (!commit || !reserve) - { - IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress ); - if (!reserve) reserve = nt->OptionalHeader.SizeOfStackReserve; - if (!commit) commit = nt->OptionalHeader.SizeOfStackCommit; - } - - reserve = (reserve + reserve_align - 1) & ~(reserve_align - 1); - commit = (commit + commit_align - 1) & ~(commit_align - 1); - - if (reserve < commit) reserve = commit; - if (reserve < 0x100000) reserve = 0x100000; - reserve = (reserve + 0xffff) & ~0xffff; /* round to 64K boundary */ - - alloc.ReserveSize = reserve; - alloc.ZeroBits = zero_bits; - status = NtSetInformationProcess( GetCurrentProcess(), ProcessThreadStackAllocation, - &alloc, sizeof(alloc) ); - if (!status) - { - void *addr = alloc.StackBase; - SIZE_T size = page_size; - - NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT, PAGE_NOACCESS ); - addr = (char *)alloc.StackBase + page_size; - NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD ); - addr = (char *)alloc.StackBase + 2 * page_size; - size = reserve - 2 * page_size; - NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT, PAGE_READWRITE ); - - /* note: limit is lower than base since the stack grows down */ - stack->OldStackBase = 0; - stack->OldStackLimit = 0; - stack->DeallocationStack = alloc.StackBase; - stack->StackBase = (char *)alloc.StackBase + reserve; - stack->StackLimit = (char *)alloc.StackBase + 2 * page_size; - } - return status; -} - - -/********************************************************************** - * RtlFreeUserStack (NTDLL.@) - */ -void WINAPI RtlFreeUserStack( void *stack ) -{ - SIZE_T size = 0; - - TRACE("stack %p\n", stack); - - NtFreeVirtualMemory( NtCurrentProcess(), &stack, &size, MEM_RELEASE ); -}