From ab6e9909fe8b5fd5928f9d732f05707025d34166 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 23 Jul 2011 18:50:20 +0000 Subject: [PATCH] [KERNEL32]: Simplify CreateMemoryResourceNotification and bring up to ReactOS coding standards. [KERNEL32]: Bug: QueryMemoryResourceNotification should set ERROR_INVALID_PARAMETER and fail if the Handle is NULL or INVALID_HANDLE_VALUE. [KERNEL32]: Fix ULONG<->BOOL cast in QueryMemoryResourceNotification as well. svn path=/trunk/; revision=52817 --- reactos/dll/win32/kernel32/client/resntfy.c | 80 ++++++++++----------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/reactos/dll/win32/kernel32/client/resntfy.c b/reactos/dll/win32/kernel32/client/resntfy.c index 2251702f519..cd6bae8deb0 100644 --- a/reactos/dll/win32/kernel32/client/resntfy.c +++ b/reactos/dll/win32/kernel32/client/resntfy.c @@ -1,49 +1,42 @@ -/* $Id$ - * +/* * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: lib/kernel32/mem/resnotify.c - * PURPOSE: Memory Resource Notification + * PROJECT: ReactOS Win32 Base API + * FILE: dll/win32/kernel32/client/resnotify.c + * PURPOSE: Memory Resource Notifications * PROGRAMMER: Thomas Weidenmueller */ -/* INCLUDES ******************************************************************/ +/* INCLUDES *******************************************************************/ #include #define NDEBUG #include -/* FUNCTIONS *****************************************************************/ +/* FUNCTIONS ******************************************************************/ /* * @implemented */ HANDLE WINAPI -CreateMemoryResourceNotification( - MEMORY_RESOURCE_NOTIFICATION_TYPE NotificationType - ) +CreateMemoryResourceNotification(IN MEMORY_RESOURCE_NOTIFICATION_TYPE NotificationType) { UNICODE_STRING EventName; OBJECT_ATTRIBUTES ObjectAttributes; HANDLE hEvent; NTSTATUS Status; - - switch(NotificationType) + + if (NotificationType > HighMemoryResourceNotification) { - case LowMemoryResourceNotification: - RtlInitUnicodeString(&EventName, L"\\KernelObjects\\LowMemoryCondition"); - break; - - case HighMemoryResourceNotification: - RtlInitUnicodeString(&EventName, L"\\KernelObjects\\HighMemoryCondition"); - break; - - default: SetLastError(ERROR_INVALID_PARAMETER); return NULL; } + + RtlInitUnicodeString(&EventName, + NotificationType ? + L"\\KernelObjects\\HighMemoryCondition" : + L"\\KernelObjects\\LowMemoryCondition"); InitializeObjectAttributes(&ObjectAttributes, &EventName, @@ -54,47 +47,46 @@ CreateMemoryResourceNotification( Status = NtOpenEvent(&hEvent, EVENT_QUERY_STATE | SYNCHRONIZE, &ObjectAttributes); - if(!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { - SetLastErrorByStatus(Status); - return NULL; + SetLastErrorByStatus(Status); + return NULL; } return hEvent; } - /* * @implemented */ BOOL WINAPI -QueryMemoryResourceNotification( - HANDLE ResourceNotificationHandle, - PBOOL ResourceState - ) +QueryMemoryResourceNotification(IN HANDLE ResourceNotificationHandle, + OUT PBOOL ResourceState) { - EVENT_BASIC_INFORMATION ebi; + EVENT_BASIC_INFORMATION EventInfo; NTSTATUS Status; - if(ResourceState != NULL) + if ((ResourceNotificationHandle) && + (ResourceNotificationHandle != INVALID_HANDLE_VALUE) && + (ResourceState)) { - Status = NtQueryEvent(ResourceNotificationHandle, - EventBasicInformation, - &ebi, - sizeof(ebi), - NULL); - if(NT_SUCCESS(Status)) - { - *ResourceState = ebi.EventState; - return TRUE; - } + Status = NtQueryEvent(ResourceNotificationHandle, + EventBasicInformation, + &EventInfo, + sizeof(EventInfo), + NULL); + if (NT_SUCCESS(Status)) + { + *ResourceState = (EventInfo.EventState == 1); + return TRUE; + } - SetLastErrorByStatus(Status); + SetLastErrorByStatus(Status); } - else /* ResourceState == NULL */ + else { - SetLastError(ERROR_INVALID_PARAMETER); + SetLastError(ERROR_INVALID_PARAMETER); } return FALSE;