2011-07-23 18:50:20 +00:00
|
|
|
/*
|
2004-09-21 19:17:26 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2011-07-23 18:50:20 +00:00
|
|
|
* PROJECT: ReactOS Win32 Base API
|
|
|
|
* FILE: dll/win32/kernel32/client/resnotify.c
|
|
|
|
* PURPOSE: Memory Resource Notifications
|
2004-09-21 19:17:26 +00:00
|
|
|
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
|
|
|
|
*/
|
|
|
|
|
2011-07-23 18:50:20 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
2004-09-21 19:17:26 +00:00
|
|
|
|
|
|
|
#include <k32.h>
|
|
|
|
|
2004-10-30 22:18:17 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
2004-10-30 22:18:17 +00:00
|
|
|
|
2011-07-23 18:50:20 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2004-09-21 19:17:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
HANDLE
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2011-07-23 18:50:20 +00:00
|
|
|
CreateMemoryResourceNotification(IN MEMORY_RESOURCE_NOTIFICATION_TYPE NotificationType)
|
2004-09-21 19:17:26 +00:00
|
|
|
{
|
|
|
|
UNICODE_STRING EventName;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE hEvent;
|
|
|
|
NTSTATUS Status;
|
2011-07-23 18:50:20 +00:00
|
|
|
|
|
|
|
if (NotificationType > HighMemoryResourceNotification)
|
2004-09-21 19:17:26 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-23 18:50:20 +00:00
|
|
|
|
|
|
|
RtlInitUnicodeString(&EventName,
|
|
|
|
NotificationType ?
|
|
|
|
L"\\KernelObjects\\HighMemoryCondition" :
|
|
|
|
L"\\KernelObjects\\LowMemoryCondition");
|
2004-09-21 19:17:26 +00:00
|
|
|
|
2004-10-24 12:55:19 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&EventName,
|
|
|
|
0,
|
2014-10-27 22:05:51 +00:00
|
|
|
NULL,
|
2004-10-24 12:55:19 +00:00
|
|
|
NULL);
|
2004-09-21 19:17:26 +00:00
|
|
|
|
|
|
|
Status = NtOpenEvent(&hEvent,
|
|
|
|
EVENT_QUERY_STATE | SYNCHRONIZE,
|
|
|
|
&ObjectAttributes);
|
2011-07-23 18:50:20 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2004-09-21 19:17:26 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2011-07-23 18:50:20 +00:00
|
|
|
return NULL;
|
2004-09-21 19:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2011-07-23 18:50:20 +00:00
|
|
|
QueryMemoryResourceNotification(IN HANDLE ResourceNotificationHandle,
|
|
|
|
OUT PBOOL ResourceState)
|
2004-09-21 19:17:26 +00:00
|
|
|
{
|
2011-07-23 18:50:20 +00:00
|
|
|
EVENT_BASIC_INFORMATION EventInfo;
|
2004-09-21 19:17:26 +00:00
|
|
|
NTSTATUS Status;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2011-07-23 18:50:20 +00:00
|
|
|
if ((ResourceNotificationHandle) &&
|
|
|
|
(ResourceNotificationHandle != INVALID_HANDLE_VALUE) &&
|
|
|
|
(ResourceState))
|
2004-09-21 19:17:26 +00:00
|
|
|
{
|
2011-07-23 18:50:20 +00:00
|
|
|
Status = NtQueryEvent(ResourceNotificationHandle,
|
|
|
|
EventBasicInformation,
|
|
|
|
&EventInfo,
|
|
|
|
sizeof(EventInfo),
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
*ResourceState = (EventInfo.EventState == 1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2004-09-21 19:17:26 +00:00
|
|
|
}
|
2011-07-23 18:50:20 +00:00
|
|
|
else
|
2004-09-21 19:17:26 +00:00
|
|
|
{
|
2011-07-23 18:50:20 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2004-09-21 19:17:26 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-09-21 19:17:26 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|