xref: /reactos/dll/win32/kernel32/client/resntfy.c (revision cdf90707)
1 /*
2  * COPYRIGHT:            See COPYING in the top level directory
3  * PROJECT:              ReactOS Win32 Base API
4  * FILE:                 dll/win32/kernel32/client/resntfy.c
5  * PURPOSE:              Memory Resource Notifications
6  * PROGRAMMER:           Thomas Weidenmueller <w3seek@reactos.com>
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <k32.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ******************************************************************/
17 
18 /*
19  * @implemented
20  */
21 HANDLE
22 WINAPI
23 CreateMemoryResourceNotification(IN MEMORY_RESOURCE_NOTIFICATION_TYPE NotificationType)
24 {
25     UNICODE_STRING EventName;
26     OBJECT_ATTRIBUTES ObjectAttributes;
27     HANDLE hEvent;
28     NTSTATUS Status;
29 
30     if (NotificationType > HighMemoryResourceNotification)
31     {
32         SetLastError(ERROR_INVALID_PARAMETER);
33         return NULL;
34     }
35 
36     RtlInitUnicodeString(&EventName,
37                          NotificationType ?
38                          L"\\KernelObjects\\HighMemoryCondition" :
39                          L"\\KernelObjects\\LowMemoryCondition");
40 
41     InitializeObjectAttributes(&ObjectAttributes,
42                                &EventName,
43                                0,
44                                NULL,
45                                NULL);
46 
47     Status = NtOpenEvent(&hEvent,
48                          EVENT_QUERY_STATE | SYNCHRONIZE,
49                          &ObjectAttributes);
50     if (!NT_SUCCESS(Status))
51     {
52         BaseSetLastNTError(Status);
53         return NULL;
54     }
55 
56     return hEvent;
57 }
58 
59 /*
60  * @implemented
61  */
62 BOOL
63 WINAPI
64 QueryMemoryResourceNotification(IN HANDLE ResourceNotificationHandle,
65                                 OUT PBOOL ResourceState)
66 {
67     EVENT_BASIC_INFORMATION EventInfo;
68     NTSTATUS Status;
69 
70     if ((ResourceNotificationHandle) &&
71         (ResourceNotificationHandle != INVALID_HANDLE_VALUE) &&
72         (ResourceState))
73     {
74         Status = NtQueryEvent(ResourceNotificationHandle,
75                               EventBasicInformation,
76                               &EventInfo,
77                               sizeof(EventInfo),
78                               NULL);
79         if (NT_SUCCESS(Status))
80         {
81             *ResourceState = (EventInfo.EventState == 1);
82             return TRUE;
83         }
84 
85         BaseSetLastNTError(Status);
86     }
87     else
88     {
89         SetLastError(ERROR_INVALID_PARAMETER);
90     }
91 
92     return FALSE;
93 }
94 
95 /* EOF */
96