2005-05-09 01:38:29 +00:00
|
|
|
/*
|
2005-01-26 13:58:37 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2005-12-29 18:03:24 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* FILE: ntoskrnl/ex/event.c
|
|
|
|
* PURPOSE: Event support
|
|
|
|
* PROGRAMMERS: Alex Ionescu(alex@relsoft.net)
|
|
|
|
* Thomas Weidenmueller
|
2005-01-07 06:54:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2005-01-07 06:54:27 +00:00
|
|
|
|
2005-11-28 23:25:31 +00:00
|
|
|
#if defined (ALLOC_PRAGMA)
|
|
|
|
#pragma alloc_text(INIT, ExpInitializeEventImplementation)
|
|
|
|
#endif
|
|
|
|
|
2005-01-07 06:54:27 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2014-05-11 23:11:16 +00:00
|
|
|
POBJECT_TYPE ExEventObjectType = NULL;
|
2005-01-07 06:54:27 +00:00
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
GENERIC_MAPPING ExpEventMapping =
|
|
|
|
{
|
2012-09-02 22:06:42 +00:00
|
|
|
STANDARD_RIGHTS_READ | EVENT_QUERY_STATE,
|
|
|
|
STANDARD_RIGHTS_WRITE | EVENT_MODIFY_STATE,
|
|
|
|
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE,
|
|
|
|
EVENT_ALL_ACCESS
|
|
|
|
};
|
2005-03-14 02:08:17 +00:00
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
static const INFORMATION_CLASS_INFO ExEventInfoClass[] =
|
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* EventBasicInformation */
|
|
|
|
ICI_SQ_SAME( sizeof(EVENT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
|
2005-01-22 03:54:23 +00:00
|
|
|
};
|
2005-01-07 06:54:27 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2012-09-03 01:12:58 +00:00
|
|
|
BOOLEAN
|
2005-03-14 02:08:17 +00:00
|
|
|
INIT_FUNCTION
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
ExpInitializeEventImplementation(VOID)
|
|
|
|
{
|
2005-12-29 18:03:24 +00:00
|
|
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
|
|
|
UNICODE_STRING Name;
|
2012-09-03 01:12:58 +00:00
|
|
|
NTSTATUS Status;
|
2005-12-29 18:03:24 +00:00
|
|
|
DPRINT("Creating Event Object Type\n");
|
|
|
|
|
|
|
|
/* Create the Event Object Type */
|
|
|
|
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
|
|
|
RtlInitUnicodeString(&Name, L"Event");
|
|
|
|
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
|
|
|
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KEVENT);
|
|
|
|
ObjectTypeInitializer.GenericMapping = ExpEventMapping;
|
|
|
|
ObjectTypeInitializer.PoolType = NonPagedPool;
|
|
|
|
ObjectTypeInitializer.ValidAccessMask = EVENT_ALL_ACCESS;
|
2012-09-02 22:06:42 +00:00
|
|
|
ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
|
2012-09-03 01:12:58 +00:00
|
|
|
Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ExEventObjectType);
|
|
|
|
if (!NT_SUCCESS(Status)) return FALSE;
|
|
|
|
return TRUE;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 03:54:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
NtClearEvent(IN HANDLE EventHandle)
|
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
PKEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Reference the Object */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
ExGetPreviousMode(),
|
|
|
|
(PVOID*)&Event,
|
|
|
|
NULL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Check for Success */
|
2005-12-29 18:03:24 +00:00
|
|
|
if(NT_SUCCESS(Status))
|
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Clear the Event and Dereference */
|
|
|
|
KeClearEvent(Event);
|
|
|
|
ObDereferenceObject(Event);
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 23:35:19 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-21 23:35:19 +00:00
|
|
|
NtCreateEvent(OUT PHANDLE EventHandle,
|
2005-03-14 02:08:17 +00:00
|
|
|
IN ACCESS_MASK DesiredAccess,
|
|
|
|
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
|
|
|
IN EVENT_TYPE EventType,
|
|
|
|
IN BOOLEAN InitialState)
|
2005-01-21 23:35:19 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
PKEVENT Event;
|
|
|
|
HANDLE hEvent;
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2005-03-14 02:08:17 +00:00
|
|
|
PAGED_CODE();
|
2005-12-29 18:03:24 +00:00
|
|
|
DPRINT("NtCreateEvent(0x%p, 0x%x, 0x%p)\n",
|
|
|
|
EventHandle, DesiredAccess, ObjectAttributes);
|
|
|
|
|
|
|
|
/* Check if we were called from user-mode */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Enter SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Check handle pointer */
|
2005-08-21 17:38:07 +00:00
|
|
|
ProbeForWriteHandle(EventHandle);
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Create the Object */
|
|
|
|
Status = ObCreateObject(PreviousMode,
|
|
|
|
ExEventObjectType,
|
|
|
|
ObjectAttributes,
|
|
|
|
PreviousMode,
|
|
|
|
NULL,
|
|
|
|
sizeof(KEVENT),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
(PVOID*)&Event);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Check for Success */
|
2012-09-09 16:59:23 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2013-04-04 20:11:17 +00:00
|
|
|
/* Initialize the Event */
|
2005-03-14 02:08:17 +00:00
|
|
|
KeInitializeEvent(Event,
|
|
|
|
EventType,
|
|
|
|
InitialState);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Insert it */
|
|
|
|
Status = ObInsertObject((PVOID)Event,
|
|
|
|
NULL,
|
|
|
|
DesiredAccess,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&hEvent);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 18:47:14 +00:00
|
|
|
/* Check for success */
|
2012-09-09 16:59:23 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2005-12-29 18:47:14 +00:00
|
|
|
/* Enter SEH for return */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2005-12-29 18:47:14 +00:00
|
|
|
/* Return the handle to the caller */
|
2005-03-14 02:08:17 +00:00
|
|
|
*EventHandle = hEvent;
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-07 06:54:27 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
|
|
|
}
|
2005-02-28 17:40:15 +00:00
|
|
|
|
2005-01-22 03:54:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
NtOpenEvent(OUT PHANDLE EventHandle,
|
2005-03-14 02:08:17 +00:00
|
|
|
IN ACCESS_MASK DesiredAccess,
|
|
|
|
IN POBJECT_ATTRIBUTES ObjectAttributes)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
HANDLE hEvent;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2005-05-09 01:38:29 +00:00
|
|
|
PAGED_CODE();
|
2005-12-29 18:03:24 +00:00
|
|
|
DPRINT("NtOpenEvent(0x%p, 0x%x, 0x%p)\n",
|
|
|
|
EventHandle, DesiredAccess, ObjectAttributes);
|
|
|
|
|
|
|
|
/* Check if we were called from user-mode */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Enter SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Check handle pointer */
|
2005-08-21 17:38:07 +00:00
|
|
|
ProbeForWriteHandle(EventHandle);
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Open the Object */
|
|
|
|
Status = ObOpenObjectByName(ObjectAttributes,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
2006-05-25 20:50:58 +00:00
|
|
|
NULL,
|
2005-03-14 02:08:17 +00:00
|
|
|
DesiredAccess,
|
|
|
|
NULL,
|
|
|
|
&hEvent);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check for success */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Enter SEH for return */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Return the handle to the caller */
|
2005-03-14 02:08:17 +00:00
|
|
|
*EventHandle = hEvent;
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 03:54:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
NtPulseEvent(IN HANDLE EventHandle,
|
2005-03-14 02:08:17 +00:00
|
|
|
OUT PLONG PreviousState OPTIONAL)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
PKEVENT Event;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2005-03-14 02:08:17 +00:00
|
|
|
PAGED_CODE();
|
2013-08-31 16:02:13 +00:00
|
|
|
DPRINT("NtPulseEvent(EventHandle 0%p PreviousState 0%p)\n",
|
2005-03-14 02:08:17 +00:00
|
|
|
EventHandle, PreviousState);
|
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check if we were called from user-mode */
|
|
|
|
if((PreviousState) && (PreviousMode != KernelMode))
|
|
|
|
{
|
|
|
|
/* Entry SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Make sure the state pointer is valid */
|
2005-08-21 17:38:07 +00:00
|
|
|
ProbeForWriteLong(PreviousState);
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Open the Object */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&Event,
|
|
|
|
NULL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Check for success */
|
2005-12-29 18:03:24 +00:00
|
|
|
if(NT_SUCCESS(Status))
|
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Pulse the Event */
|
|
|
|
LONG Prev = KePulseEvent(Event, EVENT_INCREMENT, FALSE);
|
|
|
|
ObDereferenceObject(Event);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check if caller wants the old state back */
|
|
|
|
if(PreviousState)
|
|
|
|
{
|
|
|
|
/* Entry SEH Block for return */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Return previous state */
|
2005-03-14 02:08:17 +00:00
|
|
|
*PreviousState = Prev;
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2005-01-22 03:54:23 +00:00
|
|
|
}
|
2005-01-07 06:54:27 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return Status */
|
2005-01-22 03:54:23 +00:00
|
|
|
return Status;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 03:54:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
NtQueryEvent(IN HANDLE EventHandle,
|
2005-03-14 02:08:17 +00:00
|
|
|
IN EVENT_INFORMATION_CLASS EventInformationClass,
|
|
|
|
OUT PVOID EventInformation,
|
|
|
|
IN ULONG EventInformationLength,
|
|
|
|
OUT PULONG ReturnLength OPTIONAL)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
PKEVENT Event;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2005-12-29 18:47:14 +00:00
|
|
|
PEVENT_BASIC_INFORMATION BasicInfo =
|
|
|
|
(PEVENT_BASIC_INFORMATION)EventInformation;
|
2005-03-14 02:08:17 +00:00
|
|
|
PAGED_CODE();
|
2005-07-04 22:11:00 +00:00
|
|
|
DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Check buffers and class validity */
|
2005-10-10 13:03:55 +00:00
|
|
|
Status = DefaultQueryInfoBufferCheck(EventInformationClass,
|
|
|
|
ExEventInfoClass,
|
2005-12-29 18:47:14 +00:00
|
|
|
sizeof(ExEventInfoClass) /
|
|
|
|
sizeof(ExEventInfoClass[0]),
|
2005-10-10 13:03:55 +00:00
|
|
|
EventInformation,
|
|
|
|
EventInformationLength,
|
|
|
|
ReturnLength,
|
2010-01-13 22:35:43 +00:00
|
|
|
NULL,
|
2005-10-10 13:03:55 +00:00
|
|
|
PreviousMode);
|
2005-12-29 18:03:24 +00:00
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Invalid buffers */
|
|
|
|
DPRINT("NtQuerySemaphore() failed, Status: 0x%x\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Get the Object */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_QUERY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&Event,
|
|
|
|
NULL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Check for success */
|
2005-12-29 18:03:24 +00:00
|
|
|
if(NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Entry SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return Event Type and State */
|
|
|
|
BasicInfo->EventType = Event->Header.Type;
|
|
|
|
BasicInfo->EventState = KeReadStateEvent(Event);
|
|
|
|
|
|
|
|
/* Return length */
|
|
|
|
if(ReturnLength) *ReturnLength = sizeof(EVENT_BASIC_INFORMATION);
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-05-06 22:25:30 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Dereference the Object */
|
|
|
|
ObDereferenceObject(Event);
|
2005-01-22 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return status */
|
2005-01-22 03:54:23 +00:00
|
|
|
return Status;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 03:54:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
NtResetEvent(IN HANDLE EventHandle,
|
2005-03-14 02:08:17 +00:00
|
|
|
OUT PLONG PreviousState OPTIONAL)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
PKEVENT Event;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2005-03-14 02:08:17 +00:00
|
|
|
PAGED_CODE();
|
2013-08-31 16:02:13 +00:00
|
|
|
DPRINT("NtResetEvent(EventHandle 0%p PreviousState 0%p)\n",
|
2005-03-14 02:08:17 +00:00
|
|
|
EventHandle, PreviousState);
|
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check if we were called from user-mode */
|
2009-08-26 17:31:02 +00:00
|
|
|
if ((PreviousState) && (PreviousMode != KernelMode))
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Entry SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Make sure the state pointer is valid */
|
2005-08-21 17:38:07 +00:00
|
|
|
ProbeForWriteLong(PreviousState);
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the Object */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&Event,
|
|
|
|
NULL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Check for success */
|
2005-12-29 18:03:24 +00:00
|
|
|
if(NT_SUCCESS(Status))
|
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Reset the Event */
|
|
|
|
LONG Prev = KeResetEvent(Event);
|
|
|
|
ObDereferenceObject(Event);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check if caller wants the old state back */
|
|
|
|
if(PreviousState)
|
|
|
|
{
|
|
|
|
/* Entry SEH Block for return */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Return previous state */
|
2005-03-14 02:08:17 +00:00
|
|
|
*PreviousState = Prev;
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2005-01-22 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Return Status */
|
2005-01-22 03:54:23 +00:00
|
|
|
return Status;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:03:24 +00:00
|
|
|
NTAPI
|
2005-01-07 06:54:27 +00:00
|
|
|
NtSetEvent(IN HANDLE EventHandle,
|
2005-03-14 02:08:17 +00:00
|
|
|
OUT PLONG PreviousState OPTIONAL)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
PKEVENT Event;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-26 17:31:02 +00:00
|
|
|
NTSTATUS Status;
|
2005-03-14 02:08:17 +00:00
|
|
|
PAGED_CODE();
|
2013-08-31 16:02:13 +00:00
|
|
|
DPRINT("NtSetEvent(EventHandle 0%p PreviousState 0%p)\n",
|
2005-03-14 02:08:17 +00:00
|
|
|
EventHandle, PreviousState);
|
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check if we were called from user-mode */
|
2006-10-23 20:49:52 +00:00
|
|
|
if ((PreviousState) && (PreviousMode != KernelMode))
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Entry SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Make sure the state pointer is valid */
|
2005-08-21 17:38:07 +00:00
|
|
|
ProbeForWriteLong(PreviousState);
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the Object */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&Event,
|
|
|
|
NULL);
|
2006-10-23 20:49:52 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2005-03-14 02:08:17 +00:00
|
|
|
/* Set the Event */
|
|
|
|
LONG Prev = KeSetEvent(Event, EVENT_INCREMENT, FALSE);
|
|
|
|
ObDereferenceObject(Event);
|
|
|
|
|
2005-12-29 18:03:24 +00:00
|
|
|
/* Check if caller wants the old state back */
|
2006-10-23 20:49:52 +00:00
|
|
|
if (PreviousState)
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Entry SEH Block for return */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
|
|
|
/* Return previous state */
|
2005-03-14 02:08:17 +00:00
|
|
|
*PreviousState = Prev;
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 18:03:24 +00:00
|
|
|
{
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:03:24 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-03-14 02:08:17 +00:00
|
|
|
}
|
2006-10-23 20:49:52 +00:00
|
|
|
}
|
2005-01-22 03:54:23 +00:00
|
|
|
|
2006-10-23 20:49:52 +00:00
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtSetEventBoostPriority(IN HANDLE EventHandle)
|
|
|
|
{
|
|
|
|
PKEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Open the Object */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
ExGetPreviousMode(),
|
|
|
|
(PVOID*)&Event,
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Set the Event */
|
|
|
|
KeSetEventBoostPriority(Event, NULL);
|
|
|
|
ObDereferenceObject(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|