Fix NtAllocateVirtualMemory declaration and fix users of the
function.

diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c
index 4541278..1910d72 100644
--- a/dlls/kernel/process.c
+++ b/dlls/kernel/process.c
@@ -379,6 +379,7 @@
     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 @@
     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 @@
     /* 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 3b5126d..c5d8e8d 100644
--- a/dlls/kernel/virtual.c
+++ b/dlls/kernel/virtual.c
@@ -86,10 +86,10 @@
               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 a0ceb1d..c835019 100644
--- a/dlls/ntdll/env.c
+++ b/dlls/ntdll/env.c
@@ -65,10 +65,10 @@
     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 @@
             + 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 6edfea5..7950c3e 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -343,12 +343,12 @@
     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 @@
 
     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 @@
     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 76e5a1d..0f88a95 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1139,7 +1139,8 @@
         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 d541e17..27edbc4 100644
--- a/dlls/ntdll/relay.c
+++ b/dlls/ntdll/relay.c
@@ -841,7 +841,8 @@
     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 @@
 	}
 	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 761f3fa..4fb1478 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -142,7 +142,8 @@
     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 @@
 
     /* 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 @@
     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 17fb83b..e48ea7b 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1153,7 +1153,7 @@
  *             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 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 @@
 
     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 @@
         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 5dc816e..f1f6c0b 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -1268,7 +1268,7 @@
 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);