- Add check of params for VirtualAllocEx and VirtualFreeEx
authorDmitry Chapyshev <dmitry@reactos.org>
Sun, 28 Dec 2008 13:03:05 +0000 (13:03 +0000)
committerDmitry Chapyshev <dmitry@reactos.org>
Sun, 28 Dec 2008 13:03:05 +0000 (13:03 +0000)
- Implement GetWriteWatch (based on Wine)
- Fix VirtualQueryEx

svn path=/trunk/; revision=38421

reactos/dll/win32/kernel32/mem/virtual.c

index 6caf257..bb1a390 100644 (file)
@@ -28,6 +28,12 @@ VirtualAllocEx(IN HANDLE hProcess,
 {
     NTSTATUS Status;
 
+    if (lpAddress != NULL)
+    {
+        SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
+        return NULL;
+    }
+
     /* Allocate the memory */
     Status = NtAllocateVirtualMemory(hProcess,
                                      (PVOID *)&lpAddress,
@@ -76,20 +82,26 @@ VirtualFreeEx(IN HANDLE hProcess,
 {
     NTSTATUS Status;
 
-    /* Free the memory */
-    Status = NtFreeVirtualMemory(hProcess,
-                                 (PVOID *)&lpAddress,
-                                 (PULONG)&dwSize,
-                                 dwFreeType);
-    if (!NT_SUCCESS(Status))
+    if (dwSize == 0 || !(dwFreeType & MEM_RELEASE))
     {
-        /* We failed */
-        SetLastErrorByStatus(Status);
-        return FALSE;
+        /* Free the memory */
+        Status = NtFreeVirtualMemory(hProcess,
+                                     (PVOID *)&lpAddress,
+                                     (PULONG)&dwSize,
+                                     dwFreeType);
+        if (!NT_SUCCESS(Status))
+        {
+            /* We failed */
+            SetLastErrorByStatus(Status);
+            return FALSE;
+        }
+
+        /* Return success */
+        return TRUE;
     }
 
-    /* Return success */
-    return TRUE;
+    SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
+    return FALSE;
 }
 
 /*
@@ -217,7 +229,7 @@ VirtualQueryEx(IN HANDLE hProcess,
                                   (LPVOID)lpAddress,
                                   MemoryBasicInformation,
                                   lpBuffer,
-                                  sizeof(MEMORY_BASIC_INFORMATION),
+                                  dwLength,
                                   &ResultLength);
     if (!NT_SUCCESS(Status))
     {
@@ -257,4 +269,37 @@ VirtualUnlock(IN LPVOID lpAddress,
     return TRUE;
 }
 
+/*
+ * @implemented
+ */
+UINT
+WINAPI
+GetWriteWatch(
+    DWORD  dwFlags,
+    PVOID  lpBaseAddress,
+    SIZE_T dwRegionSize,
+    PVOID *lpAddresses,
+    PULONG_PTR lpdwCount,
+    PULONG lpdwGranularity
+    )
+{
+    NTSTATUS Status;
+
+    Status = NtGetWriteWatch(GetCurrentProcess(),
+                             dwFlags,
+                             lpBaseAddress,
+                             dwRegionSize,
+                             lpAddresses,
+                             lpdwCount,
+                             lpdwGranularity);
+
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastError(RtlNtStatusToDosError(Status));
+        return -1;
+    }
+
+    return 0;
+}
+
 /* EOF */