From 3c0e179f925f7d7b303d44eaf83c58895e931f7a Mon Sep 17 00:00:00 2001 From: Dmitry Chapyshev Date: Sun, 28 Dec 2008 13:03:05 +0000 Subject: [PATCH] - Add check of params for VirtualAllocEx and VirtualFreeEx - Implement GetWriteWatch (based on Wine) - Fix VirtualQueryEx svn path=/trunk/; revision=38421 --- reactos/dll/win32/kernel32/mem/virtual.c | 69 +++++++++++++++++++----- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/reactos/dll/win32/kernel32/mem/virtual.c b/reactos/dll/win32/kernel32/mem/virtual.c index 6caf2573bad..bb1a3904d0c 100644 --- a/reactos/dll/win32/kernel32/mem/virtual.c +++ b/reactos/dll/win32/kernel32/mem/virtual.c @@ -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 */