From 205059137077a80cbbcf2499424441371cf75a48 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Mon, 11 Oct 2004 20:59:06 +0000 Subject: [PATCH] Fix NtAllocateVirtualMemory declaration and fix users of the function. --- dlls/kernel/process.c | 7 +++++-- dlls/kernel/virtual.c | 4 ++-- dlls/ntdll/env.c | 9 +++++---- dlls/ntdll/heap.c | 12 ++++++------ dlls/ntdll/loader.c | 3 ++- dlls/ntdll/relay.c | 7 ++++--- dlls/ntdll/thread.c | 9 ++++++--- dlls/ntdll/virtual.c | 15 +++++++++------ include/winternl.h | 2 +- 9 files changed, 40 insertions(+), 28 deletions(-) diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index 4541278e661..1910d72f225 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -379,6 +379,7 @@ static BOOL build_initial_environment( char **environ ) size *= sizeof(WCHAR); /* Now allocate the environment */ + ptr = NULL; if (NtAllocateVirtualMemory(NtCurrentProcess(), &ptr, 0, &size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) != STATUS_SUCCESS) return FALSE; @@ -719,7 +720,8 @@ static RTL_USER_PROCESS_PARAMETERS *init_user_process_params( size_t info_size ) RTL_USER_PROCESS_PARAMETERS *params; size = info_size; - if (NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, NULL, &size, + ptr = NULL; + if (NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &size, MEM_COMMIT, PAGE_READWRITE ) != STATUS_SUCCESS) return NULL; @@ -748,7 +750,8 @@ static RTL_USER_PROCESS_PARAMETERS *init_user_process_params( size_t info_size ) /* environment needs to be a separate memory block */ env_size = info_size - params->Size; if (!env_size) env_size = 1; - if (NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, NULL, &env_size, + ptr = NULL; + if (NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &env_size, MEM_COMMIT, PAGE_READWRITE ) != STATUS_SUCCESS) return NULL; memcpy( ptr, (char *)params + params->Size, info_size - params->Size ); diff --git a/dlls/kernel/virtual.c b/dlls/kernel/virtual.c index 3b5126d106d..c5d8e8d032a 100644 --- a/dlls/kernel/virtual.c +++ b/dlls/kernel/virtual.c @@ -86,10 +86,10 @@ LPVOID WINAPI VirtualAllocEx( DWORD type, /* [in] Type of allocation */ DWORD protect ) /* [in] Type of access protection */ { - LPVOID ret; + LPVOID ret = addr; NTSTATUS status; - if ((status = NtAllocateVirtualMemory( hProcess, &ret, addr, &size, type, protect ))) + if ((status = NtAllocateVirtualMemory( hProcess, &ret, 0, &size, type, protect ))) { SetLastError( RtlNtStatusToDosError(status) ); ret = NULL; diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index a0ceb1d6baa..c8350197cda 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -65,10 +65,10 @@ NTSTATUS WINAPI RtlCreateEnvironment(BOOLEAN inherit, PWSTR* env) else { ULONG size = 1; - nts = NtAllocateVirtualMemory(NtCurrentProcess(), (void**)env, 0, &size, + PVOID addr = NULL; + nts = NtAllocateVirtualMemory(NtCurrentProcess(), &addr, 0, &size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - if (nts == STATUS_SUCCESS) - memset(*env, 0, size); + if (nts == STATUS_SUCCESS) *env = addr; } return nts; @@ -446,7 +446,8 @@ NTSTATUS WINAPI RtlCreateProcessParameters( RTL_USER_PROCESS_PARAMETERS **result + RuntimeInfo->MaximumLength); total_size = size; - if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, NULL, &total_size, + ptr = NULL; + if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &total_size, MEM_COMMIT, PAGE_READWRITE )) == STATUS_SUCCESS) { RTL_USER_PROCESS_PARAMETERS *params = ptr; diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 6edfea5c035..7950c3e52d9 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -343,12 +343,12 @@ static inline BOOL HEAP_Commit( SUBHEAP *subheap, void *ptr ) if (size > subheap->size) size = subheap->size; if (size <= subheap->commitSize) return TRUE; size -= subheap->commitSize; - if (NtAllocateVirtualMemory( GetCurrentProcess(), &ptr, (char *)subheap + subheap->commitSize, + ptr = (char *)subheap + subheap->commitSize; + if (NtAllocateVirtualMemory( GetCurrentProcess(), &ptr, 0, &size, MEM_COMMIT, PAGE_EXECUTE_READWRITE)) { - WARN("Could not commit %08lx bytes at %08lx for heap %08lx\n", - size, (DWORD)((char *)subheap + subheap->commitSize), - (DWORD)subheap->heap ); + WARN("Could not commit %08lx bytes at %p for heap %p\n", + size, ptr, subheap->heap ); return FALSE; } subheap->commitSize += size; @@ -530,7 +530,7 @@ static BOOL HEAP_InitSubHeap( HEAP *heap, LPVOID address, DWORD flags, if (flags & HEAP_SHARED) commitSize = totalSize; /* always commit everything in a shared heap */ - if (NtAllocateVirtualMemory( GetCurrentProcess(), &address, address, + if (NtAllocateVirtualMemory( GetCurrentProcess(), &address, 0, &commitSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE)) { WARN("Could not commit %08lx bytes for sub-heap %p\n", commitSize, address ); @@ -619,7 +619,7 @@ static SUBHEAP *HEAP_CreateSubHeap( HEAP *heap, void *base, DWORD flags, if (!address) { /* allocate the memory block */ - if (NtAllocateVirtualMemory( GetCurrentProcess(), &address, NULL, &totalSize, + if (NtAllocateVirtualMemory( GetCurrentProcess(), &address, 0, &totalSize, MEM_RESERVE, PAGE_EXECUTE_READWRITE )) { WARN("Could not allocate %08lx bytes\n", totalSize ); diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 76e5a1d3362..0f88a95de2c 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -1139,7 +1139,8 @@ static void load_builtin_callback( void *module, const char *filename ) return; } wm->ldr.Flags |= LDR_WINE_INTERNAL; - NtAllocateVirtualMemory( GetCurrentProcess(), &addr, module, &nt->OptionalHeader.SizeOfImage, + addr = module; + NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &nt->OptionalHeader.SizeOfImage, MEM_SYSTEM | MEM_IMAGE, PAGE_EXECUTE_WRITECOPY ); /* fixup imports */ diff --git a/dlls/ntdll/relay.c b/dlls/ntdll/relay.c index d541e172c94..27edbc42fdc 100644 --- a/dlls/ntdll/relay.c +++ b/dlls/ntdll/relay.c @@ -841,7 +841,8 @@ void SNOOP_SetupDLL(HMODULE hmod) if (p > (*dll)->name && !strcasecmp( p, ".dll" )) *p = 0; size = exports->NumberOfFunctions * sizeof(SNOOP_FUN); - NtAllocateVirtualMemory(GetCurrentProcess(), &addr, NULL, &size, + addr = NULL; + NtAllocateVirtualMemory(GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (!addr) { RtlFreeHeap(GetProcessHeap(),0,*dll); @@ -1006,9 +1007,9 @@ void WINAPI SNOOP_DoEntry( CONTEXT86 *context ) } if (!*rets) { SIZE_T size = 4096; - VOID* addr; + VOID* addr = NULL; - NtAllocateVirtualMemory(GetCurrentProcess(), &addr, NULL, &size, + NtAllocateVirtualMemory(GetCurrentProcess(), &addr, 0, &size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (!addr) return; diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index 761f3fa4f94..4fb14785e75 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -142,7 +142,8 @@ void thread_init(void) server_init_thread( thread_info.pid, thread_info.tid, NULL ); /* create a memory view for the TEB */ - NtAllocateVirtualMemory( GetCurrentProcess(), &addr, teb, &size, + addr = teb; + NtAllocateVirtualMemory( GetCurrentProcess(), &addr, 0, &size, MEM_SYSTEM, PAGE_EXECUTE_READWRITE ); /* create the process heap */ @@ -179,7 +180,8 @@ static void start_thread( struct wine_pthread_thread_info *info ) /* allocate a memory view for the stack */ size = info->stack_size; - NtAllocateVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, info->stack_base, + teb->DeallocationStack = info->stack_base; + NtAllocateVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, 0, &size, MEM_SYSTEM, PAGE_EXECUTE_READWRITE ); /* limit is lower than base since the stack grows down */ teb->Tib.StackBase = (char *)info->stack_base + info->stack_size; @@ -263,7 +265,8 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * teb->wait_fd[1] = -1; teb->htask16 = NtCurrentTeb()->htask16; - NtAllocateVirtualMemory( GetCurrentProcess(), &info->pthread_info.teb_base, teb, &size, + info->pthread_info.teb_base = teb; + NtAllocateVirtualMemory( GetCurrentProcess(), &info->pthread_info.teb_base, 0, &size, MEM_SYSTEM, PAGE_EXECUTE_READWRITE ); info->pthread_info.teb_size = size; info->pthread_info.teb_sel = teb->teb_sel; diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c index 17fb83bf792..e48ea7b834b 100644 --- a/dlls/ntdll/virtual.c +++ b/dlls/ntdll/virtual.c @@ -1153,7 +1153,7 @@ void VIRTUAL_UseLargeAddressSpace(void) * NtAllocateVirtualMemory (NTDLL.@) * ZwAllocateVirtualMemory (NTDLL.@) */ -NTSTATUS WINAPI NtAllocateVirtualMemory( HANDLE process, PVOID *ret, PVOID addr, +NTSTATUS WINAPI NtAllocateVirtualMemory( HANDLE process, PVOID *ret, ULONG zero_bits, ULONG *size_ptr, ULONG type, ULONG protect ) { void *base; @@ -1162,7 +1162,7 @@ NTSTATUS WINAPI NtAllocateVirtualMemory( HANDLE process, PVOID *ret, PVOID addr, NTSTATUS status = STATUS_SUCCESS; struct file_view *view; - TRACE("%p %p %08lx %lx %08lx\n", process, addr, size, type, protect ); + TRACE("%p %p %08lx %lx %08lx\n", process, *ret, size, type, protect ); if (!size) return STATUS_INVALID_PARAMETER; @@ -1176,13 +1176,13 @@ NTSTATUS WINAPI NtAllocateVirtualMemory( HANDLE process, PVOID *ret, PVOID addr, if (size > 0x7fc00000) return STATUS_WORKING_SET_LIMIT_RANGE; /* 2Gb - 4Mb */ - if (addr) + if (*ret) { if (type & MEM_RESERVE) /* Round down to 64k boundary */ - base = ROUND_ADDR( addr, granularity_mask ); + base = ROUND_ADDR( *ret, granularity_mask ); else - base = ROUND_ADDR( addr, page_mask ); - size = (((UINT_PTR)addr + size + page_mask) & ~page_mask) - (UINT_PTR)base; + base = ROUND_ADDR( *ret, page_mask ); + size = (((UINT_PTR)*ret + size + page_mask) & ~page_mask) - (UINT_PTR)base; /* disallow low 64k, wrap-around and kernel space */ if (((char *)base <= (char *)granularity_mask) || @@ -1202,6 +1202,9 @@ NTSTATUS WINAPI NtAllocateVirtualMemory( HANDLE process, PVOID *ret, PVOID addr, type &= ~MEM_TOP_DOWN; } + if (zero_bits) + WARN("zero_bits %lu ignored\n", zero_bits); + /* Compute the alloc type flags */ if (!(type & MEM_SYSTEM)) diff --git a/include/winternl.h b/include/winternl.h index 5dc816e90a6..f1f6c0bfd5f 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -1268,7 +1268,7 @@ NTSTATUS WINAPI NtAccessCheck(PSECURITY_DESCRIPTOR,HANDLE,ACCESS_MASK,PGENERIC_ NTSTATUS WINAPI NtAdjustGroupsToken(HANDLE,BOOLEAN,PTOKEN_GROUPS,ULONG,PTOKEN_GROUPS,PULONG); NTSTATUS WINAPI NtAdjustPrivilegesToken(HANDLE,BOOLEAN,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD); NTSTATUS WINAPI NtAlertThread(HANDLE ThreadHandle); -NTSTATUS WINAPI NtAllocateVirtualMemory(HANDLE,PVOID*,PVOID,ULONG*,ULONG,ULONG); +NTSTATUS WINAPI NtAllocateVirtualMemory(HANDLE,PVOID*,ULONG,ULONG*,ULONG,ULONG); NTSTATUS WINAPI NtCancelIoFile(HANDLE,PIO_STATUS_BLOCK); NTSTATUS WINAPI NtCancelTimer(HANDLE, BOOLEAN*); NTSTATUS WINAPI NtClearEvent(HANDLE);