mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 20:50:29 +00:00
- Fix some small formatting issues.
svn path=/trunk/; revision=20432
This commit is contained in:
parent
c3366b8062
commit
0b7ed59da0
3 changed files with 186 additions and 152 deletions
|
@ -153,11 +153,13 @@ NtCreateEvent(OUT PHANDLE EventHandle,
|
||||||
&hEvent);
|
&hEvent);
|
||||||
ObDereferenceObject(Event);
|
ObDereferenceObject(Event);
|
||||||
|
|
||||||
/* Check for success and return handle */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status))
|
if(NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
/* Enter SEH for return */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Return the handle to the caller */
|
||||||
*EventHandle = hEvent;
|
*EventHandle = hEvent;
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
@ -320,14 +322,16 @@ NtQueryEvent(IN HANDLE EventHandle,
|
||||||
PKEVENT Event;
|
PKEVENT Event;
|
||||||
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
PEVENT_BASIC_INFORMATION BasicInfo = (PEVENT_BASIC_INFORMATION)EventInformation;
|
PEVENT_BASIC_INFORMATION BasicInfo =
|
||||||
|
(PEVENT_BASIC_INFORMATION)EventInformation;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
|
DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
|
||||||
|
|
||||||
/* Check buffers and class validity */
|
/* Check buffers and class validity */
|
||||||
Status = DefaultQueryInfoBufferCheck(EventInformationClass,
|
Status = DefaultQueryInfoBufferCheck(EventInformationClass,
|
||||||
ExEventInfoClass,
|
ExEventInfoClass,
|
||||||
sizeof(ExEventInfoClass) / sizeof(ExEventInfoClass[0]),
|
sizeof(ExEventInfoClass) /
|
||||||
|
sizeof(ExEventInfoClass[0]),
|
||||||
EventInformation,
|
EventInformation,
|
||||||
EventInformationLength,
|
EventInformationLength,
|
||||||
ReturnLength,
|
ReturnLength,
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS Kernel
|
||||||
* FILE: ntoskrnl/ex/mutant.c
|
* FILE: ntoskrnl/ex/mutant.c
|
||||||
* PURPOSE: Executive Management of Mutants
|
* PURPOSE: Executive Management of Mutants
|
||||||
*
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
||||||
* PROGRAMMERS: Alex Ionescu - Fix tab/space mismatching, tiny fixes to query function and
|
* Thomas Weidenmueller
|
||||||
* add more debug output.
|
|
||||||
* David Welch (welch@cwcom.net)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
@ -19,31 +17,30 @@
|
||||||
#pragma alloc_text(INIT, ExpInitializeMutantImplementation)
|
#pragma alloc_text(INIT, ExpInitializeMutantImplementation)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MUTANT_INCREMENT
|
/* DATA **********************************************************************/
|
||||||
#define MUTANT_INCREMENT 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
POBJECT_TYPE ExMutantObjectType = NULL;
|
POBJECT_TYPE ExMutantObjectType = NULL;
|
||||||
|
|
||||||
static GENERIC_MAPPING ExpMutantMapping = {
|
GENERIC_MAPPING ExpMutantMapping =
|
||||||
|
{
|
||||||
STANDARD_RIGHTS_READ | SYNCHRONIZE | MUTANT_QUERY_STATE,
|
STANDARD_RIGHTS_READ | SYNCHRONIZE | MUTANT_QUERY_STATE,
|
||||||
STANDARD_RIGHTS_WRITE | SYNCHRONIZE,
|
STANDARD_RIGHTS_WRITE | SYNCHRONIZE,
|
||||||
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE | MUTANT_QUERY_STATE,
|
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE | MUTANT_QUERY_STATE,
|
||||||
MUTANT_ALL_ACCESS};
|
MUTANT_ALL_ACCESS
|
||||||
|
};
|
||||||
static const INFORMATION_CLASS_INFO ExMutantInfoClass[] = {
|
|
||||||
|
|
||||||
|
static const INFORMATION_CLASS_INFO ExMutantInfoClass[] =
|
||||||
|
{
|
||||||
/* MutantBasicInformation */
|
/* MutantBasicInformation */
|
||||||
ICI_SQ_SAME( sizeof(MUTANT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY ),
|
ICI_SQ_SAME( sizeof(MUTANT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
STDCALL
|
NTAPI
|
||||||
ExpDeleteMutant(PVOID ObjectBody)
|
ExpDeleteMutant(PVOID ObjectBody)
|
||||||
{
|
{
|
||||||
|
|
||||||
DPRINT("ExpDeleteMutant(ObjectBody 0x%p)\n", ObjectBody);
|
DPRINT("ExpDeleteMutant(ObjectBody 0x%p)\n", ObjectBody);
|
||||||
|
|
||||||
/* Make sure to release the Mutant */
|
/* Make sure to release the Mutant */
|
||||||
|
@ -55,14 +52,13 @@ ExpDeleteMutant(PVOID ObjectBody)
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
STDCALL
|
NTAPI
|
||||||
ExpInitializeMutantImplementation(VOID)
|
ExpInitializeMutantImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
UNICODE_STRING Name;
|
UNICODE_STRING Name;
|
||||||
|
|
||||||
DPRINT("Creating Mutant Object Type\n");
|
DPRINT("Creating Mutant Object Type\n");
|
||||||
|
|
||||||
/* Create the Event Pair Object Type */
|
/* Create the Event Pair Object Type */
|
||||||
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
||||||
RtlInitUnicodeString(&Name, L"Mutant");
|
RtlInitUnicodeString(&Name, L"Mutant");
|
||||||
|
@ -79,7 +75,7 @@ ExpInitializeMutantImplementation(VOID)
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtCreateMutant(OUT PHANDLE MutantHandle,
|
NtCreateMutant(OUT PHANDLE MutantHandle,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
||||||
|
@ -89,22 +85,26 @@ NtCreateMutant(OUT PHANDLE MutantHandle,
|
||||||
HANDLE hMutant;
|
HANDLE hMutant;
|
||||||
PKMUTANT Mutant;
|
PKMUTANT Mutant;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
DPRINT("NtCreateMutant(0x%p, 0x%x, 0x%p)\n", MutantHandle, DesiredAccess, ObjectAttributes);
|
DPRINT("NtCreateMutant(0x%p, 0x%x, 0x%p)\n",
|
||||||
|
MutantHandle, DesiredAccess, ObjectAttributes);
|
||||||
/* Check Output Safety */
|
|
||||||
if(PreviousMode != KernelMode) {
|
|
||||||
|
|
||||||
_SEH_TRY {
|
|
||||||
|
|
||||||
|
/* Check if we were called from user-mode */
|
||||||
|
if(PreviousMode != KernelMode)
|
||||||
|
{
|
||||||
|
/* Enter SEH Block */
|
||||||
|
_SEH_TRY
|
||||||
|
{
|
||||||
|
/* Check handle pointer */
|
||||||
ProbeForWriteHandle(MutantHandle);
|
ProbeForWriteHandle(MutantHandle);
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
}
|
||||||
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
|
_SEH_END;
|
||||||
|
|
||||||
} _SEH_END;
|
/* Bail out if pointer was invalid */
|
||||||
|
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ NtCreateMutant(OUT PHANDLE MutantHandle,
|
||||||
(PVOID*)&Mutant);
|
(PVOID*)&Mutant);
|
||||||
|
|
||||||
/* Check for success */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status)) {
|
if(NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
/* Initalize the Kernel Mutant */
|
/* Initalize the Kernel Mutant */
|
||||||
DPRINT("Initializing the Mutant\n");
|
DPRINT("Initializing the Mutant\n");
|
||||||
KeInitializeMutant(Mutant, InitialOwner);
|
KeInitializeMutant(Mutant, InitialOwner);
|
||||||
|
@ -135,18 +135,20 @@ NtCreateMutant(OUT PHANDLE MutantHandle,
|
||||||
&hMutant);
|
&hMutant);
|
||||||
ObDereferenceObject(Mutant);
|
ObDereferenceObject(Mutant);
|
||||||
|
|
||||||
/* Check for success and return handle */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status)) {
|
if(NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
_SEH_TRY {
|
/* Enter SEH for return */
|
||||||
|
_SEH_TRY
|
||||||
|
{
|
||||||
|
/* Return the handle to the caller */
|
||||||
*MutantHandle = hMutant;
|
*MutantHandle = hMutant;
|
||||||
|
}
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
} _SEH_END;
|
_SEH_END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +160,7 @@ NtCreateMutant(OUT PHANDLE MutantHandle,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtOpenMutant(OUT PHANDLE MutantHandle,
|
NtOpenMutant(OUT PHANDLE MutantHandle,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
IN POBJECT_ATTRIBUTES ObjectAttributes)
|
IN POBJECT_ATTRIBUTES ObjectAttributes)
|
||||||
|
@ -166,22 +168,26 @@ NtOpenMutant(OUT PHANDLE MutantHandle,
|
||||||
HANDLE hMutant;
|
HANDLE hMutant;
|
||||||
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
DPRINT("NtOpenMutant(0x%p, 0x%x, 0x%p)\n", MutantHandle, DesiredAccess, ObjectAttributes);
|
DPRINT("NtOpenMutant(0x%p, 0x%x, 0x%p)\n",
|
||||||
|
MutantHandle, DesiredAccess, ObjectAttributes);
|
||||||
/* Check Output Safety */
|
|
||||||
if(PreviousMode != KernelMode) {
|
|
||||||
|
|
||||||
_SEH_TRY {
|
|
||||||
|
|
||||||
|
/* Check if we were called from user-mode */
|
||||||
|
if(PreviousMode != KernelMode)
|
||||||
|
{
|
||||||
|
/* Enter SEH Block */
|
||||||
|
_SEH_TRY
|
||||||
|
{
|
||||||
|
/* Check handle pointer */
|
||||||
ProbeForWriteHandle(MutantHandle);
|
ProbeForWriteHandle(MutantHandle);
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
}
|
||||||
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
|
_SEH_END;
|
||||||
|
|
||||||
} _SEH_END;
|
/* Bail out if pointer was invalid */
|
||||||
|
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,18 +200,20 @@ NtOpenMutant(OUT PHANDLE MutantHandle,
|
||||||
NULL,
|
NULL,
|
||||||
&hMutant);
|
&hMutant);
|
||||||
|
|
||||||
/* Check for success and return handle */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status)) {
|
if(NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
_SEH_TRY {
|
/* Enter SEH for return */
|
||||||
|
_SEH_TRY
|
||||||
|
{
|
||||||
|
/* Return the handle to the caller */
|
||||||
*MutantHandle = hMutant;
|
*MutantHandle = hMutant;
|
||||||
|
}
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
} _SEH_END;
|
_SEH_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return Status */
|
/* Return Status */
|
||||||
|
@ -216,7 +224,7 @@ NtOpenMutant(OUT PHANDLE MutantHandle,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtQueryMutant(IN HANDLE MutantHandle,
|
NtQueryMutant(IN HANDLE MutantHandle,
|
||||||
IN MUTANT_INFORMATION_CLASS MutantInformationClass,
|
IN MUTANT_INFORMATION_CLASS MutantInformationClass,
|
||||||
OUT PVOID MutantInformation,
|
OUT PVOID MutantInformation,
|
||||||
|
@ -226,20 +234,21 @@ NtQueryMutant(IN HANDLE MutantHandle,
|
||||||
PKMUTANT Mutant;
|
PKMUTANT Mutant;
|
||||||
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
PMUTANT_BASIC_INFORMATION BasicInfo = (PMUTANT_BASIC_INFORMATION)MutantInformation;
|
PMUTANT_BASIC_INFORMATION BasicInfo =
|
||||||
|
(PMUTANT_BASIC_INFORMATION)MutantInformation;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Check buffers and parameters */
|
/* Check buffers and parameters */
|
||||||
Status = DefaultQueryInfoBufferCheck(MutantInformationClass,
|
Status = DefaultQueryInfoBufferCheck(MutantInformationClass,
|
||||||
ExMutantInfoClass,
|
ExMutantInfoClass,
|
||||||
sizeof(ExMutantInfoClass) / sizeof(ExMutantInfoClass[0]),
|
sizeof(ExMutantInfoClass) /
|
||||||
|
sizeof(ExMutantInfoClass[0]),
|
||||||
MutantInformation,
|
MutantInformation,
|
||||||
MutantInformationLength,
|
MutantInformationLength,
|
||||||
ResultLength,
|
ResultLength,
|
||||||
PreviousMode);
|
PreviousMode);
|
||||||
if(!NT_SUCCESS(Status)) {
|
if(!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);
|
DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -252,24 +261,26 @@ NtQueryMutant(IN HANDLE MutantHandle,
|
||||||
(PVOID*)&Mutant,
|
(PVOID*)&Mutant,
|
||||||
NULL);
|
NULL);
|
||||||
/* Check for Status */
|
/* Check for Status */
|
||||||
if(NT_SUCCESS(Status)) {
|
if(NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
_SEH_TRY {
|
/* Enter SEH Block for return */
|
||||||
|
_SEH_TRY
|
||||||
|
{
|
||||||
/* Fill out the Basic Information Requested */
|
/* Fill out the Basic Information Requested */
|
||||||
DPRINT("Returning Mutant Information\n");
|
DPRINT("Returning Mutant Information\n");
|
||||||
BasicInfo->CurrentCount = KeReadStateMutant(Mutant);
|
BasicInfo->CurrentCount = KeReadStateMutant(Mutant);
|
||||||
BasicInfo->OwnedByCaller = (Mutant->OwnerThread == KeGetCurrentThread());
|
BasicInfo->OwnedByCaller = (Mutant->OwnerThread ==
|
||||||
|
KeGetCurrentThread());
|
||||||
BasicInfo->AbandonedState = Mutant->Abandoned;
|
BasicInfo->AbandonedState = Mutant->Abandoned;
|
||||||
|
|
||||||
/* Return the Result Length if requested */
|
/* Return the Result Length if requested */
|
||||||
if(ResultLength) *ResultLength = sizeof(MUTANT_BASIC_INFORMATION);
|
if(ResultLength) *ResultLength = sizeof(MUTANT_BASIC_INFORMATION);
|
||||||
|
}
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
} _SEH_END;
|
_SEH_END;
|
||||||
|
|
||||||
/* Release the Object */
|
/* Release the Object */
|
||||||
ObDereferenceObject(Mutant);
|
ObDereferenceObject(Mutant);
|
||||||
|
@ -279,39 +290,38 @@ NtQueryMutant(IN HANDLE MutantHandle,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtReleaseMutant(IN HANDLE MutantHandle,
|
NtReleaseMutant(IN HANDLE MutantHandle,
|
||||||
IN PLONG PreviousCount OPTIONAL)
|
IN PLONG PreviousCount OPTIONAL)
|
||||||
{
|
{
|
||||||
PKMUTANT Mutant;
|
PKMUTANT Mutant;
|
||||||
KPROCESSOR_MODE PreviousMode;
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
PreviousMode = ExGetPreviousMode();
|
|
||||||
|
|
||||||
DPRINT("NtReleaseMutant(MutantHandle 0x%p PreviousCount 0x%p)\n",
|
DPRINT("NtReleaseMutant(MutantHandle 0x%p PreviousCount 0x%p)\n",
|
||||||
MutantHandle,
|
MutantHandle,
|
||||||
PreviousCount);
|
PreviousCount);
|
||||||
|
|
||||||
/* Check Output Safety */
|
/* Check if we were called from user-mode */
|
||||||
if(PreviousMode != KernelMode && PreviousCount) {
|
if((PreviousCount) && (PreviousMode != KernelMode))
|
||||||
|
{
|
||||||
_SEH_TRY {
|
/* Entry SEH Block */
|
||||||
|
_SEH_TRY
|
||||||
|
{
|
||||||
|
/* Make sure the state pointer is valid */
|
||||||
ProbeForWriteLong(PreviousCount);
|
ProbeForWriteLong(PreviousCount);
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
}
|
||||||
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
|
_SEH_END;
|
||||||
|
|
||||||
} _SEH_END;
|
/* Bail out if pointer was invalid */
|
||||||
|
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,25 +334,30 @@ NtReleaseMutant(IN HANDLE MutantHandle,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* Check for Success and release if such */
|
/* Check for Success and release if such */
|
||||||
if(NT_SUCCESS(Status)) {
|
if(NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
/* release the mutant. doing so might raise an exception which we're
|
/*
|
||||||
required to catch! */
|
* Release the mutant. doing so might raise an exception which we're
|
||||||
_SEH_TRY {
|
* required to catch!
|
||||||
|
*/
|
||||||
LONG Prev = KeReleaseMutant(Mutant, MUTANT_INCREMENT, FALSE, FALSE);
|
_SEH_TRY
|
||||||
|
{
|
||||||
if(PreviousCount) {
|
/* Release the mutant */
|
||||||
|
LONG Prev = KeReleaseMutant(Mutant,
|
||||||
*PreviousCount = Prev;
|
MUTANT_INCREMENT,
|
||||||
}
|
FALSE,
|
||||||
|
FALSE);
|
||||||
} _SEH_EXCEPT(_SEH_ExSystemExceptionFilter) {
|
|
||||||
|
|
||||||
|
/* Return the previous count if requested */
|
||||||
|
if(PreviousCount) *PreviousCount = Prev;
|
||||||
|
}
|
||||||
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
|
}
|
||||||
|
_SEH_END;
|
||||||
|
|
||||||
} _SEH_END;
|
/* Dereference it */
|
||||||
|
|
||||||
ObDereferenceObject(Mutant);
|
ObDereferenceObject(Mutant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS Kernel
|
||||||
* FILE: ntoskrnl/ex/sem.c
|
* FILE: ntoskrnl/ex/sem.c
|
||||||
* PURPOSE: Semaphore Implementation
|
* PURPOSE: Semaphore Implementation
|
||||||
*
|
|
||||||
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
||||||
* David Welch (welch@mcmail.com)
|
* Thomas Weidenmueller
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
@ -22,7 +21,7 @@
|
||||||
|
|
||||||
POBJECT_TYPE ExSemaphoreObjectType;
|
POBJECT_TYPE ExSemaphoreObjectType;
|
||||||
|
|
||||||
static GENERIC_MAPPING ExSemaphoreMapping =
|
GENERIC_MAPPING ExSemaphoreMapping =
|
||||||
{
|
{
|
||||||
STANDARD_RIGHTS_READ | SEMAPHORE_QUERY_STATE,
|
STANDARD_RIGHTS_READ | SEMAPHORE_QUERY_STATE,
|
||||||
STANDARD_RIGHTS_WRITE | SEMAPHORE_MODIFY_STATE,
|
STANDARD_RIGHTS_WRITE | SEMAPHORE_MODIFY_STATE,
|
||||||
|
@ -33,19 +32,20 @@ static GENERIC_MAPPING ExSemaphoreMapping =
|
||||||
static const INFORMATION_CLASS_INFO ExSemaphoreInfoClass[] =
|
static const INFORMATION_CLASS_INFO ExSemaphoreInfoClass[] =
|
||||||
{
|
{
|
||||||
/* SemaphoreBasicInformation */
|
/* SemaphoreBasicInformation */
|
||||||
ICI_SQ_SAME( sizeof(SEMAPHORE_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY ),
|
ICI_SQ_SAME( sizeof(SEMAPHORE_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
STDCALL
|
NTAPI
|
||||||
ExpInitializeSemaphoreImplementation(VOID)
|
ExpInitializeSemaphoreImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
UNICODE_STRING Name;
|
UNICODE_STRING Name;
|
||||||
|
|
||||||
DPRINT("Creating Semaphore Object Type\n");
|
DPRINT("Creating Semaphore Object Type\n");
|
||||||
|
|
||||||
/* Create the Event Pair Object Type */
|
/* Create the Event Pair Object Type */
|
||||||
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
||||||
RtlInitUnicodeString(&Name, L"Semaphore");
|
RtlInitUnicodeString(&Name, L"Semaphore");
|
||||||
|
@ -62,10 +62,10 @@ ExpInitializeSemaphoreImplementation(VOID)
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtCreateSemaphore(OUT PHANDLE SemaphoreHandle,
|
NtCreateSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
||||||
IN LONG InitialCount,
|
IN LONG InitialCount,
|
||||||
IN LONG MaximumCount)
|
IN LONG MaximumCount)
|
||||||
{
|
{
|
||||||
|
@ -75,11 +75,13 @@ NtCreateSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Check Output Safety */
|
/* Check if we were called from user-mode */
|
||||||
if(PreviousMode != KernelMode)
|
if(PreviousMode != KernelMode)
|
||||||
{
|
{
|
||||||
_SEH_TRY
|
/* Enter SEH Block */
|
||||||
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Check handle pointer */
|
||||||
ProbeForWriteHandle(SemaphoreHandle);
|
ProbeForWriteHandle(SemaphoreHandle);
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
@ -88,11 +90,14 @@ NtCreateSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
}
|
}
|
||||||
_SEH_END;
|
_SEH_END;
|
||||||
|
|
||||||
|
/* Bail out if pointer was invalid */
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure the counts make sense */
|
/* Make sure the counts make sense */
|
||||||
if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
|
if ((MaximumCount <= 0) ||
|
||||||
|
(InitialCount < 0) ||
|
||||||
|
(InitialCount > MaximumCount))
|
||||||
{
|
{
|
||||||
DPRINT("Invalid Count Data!\n");
|
DPRINT("Invalid Count Data!\n");
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
@ -126,11 +131,13 @@ NtCreateSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
&hSemaphore);
|
&hSemaphore);
|
||||||
ObDereferenceObject(Semaphore);
|
ObDereferenceObject(Semaphore);
|
||||||
|
|
||||||
/* Check for success and return handle */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status))
|
if(NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
/* Enter SEH Block for return */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Return the handle */
|
||||||
*SemaphoreHandle = hSemaphore;
|
*SemaphoreHandle = hSemaphore;
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
@ -149,7 +156,7 @@ NtCreateSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtOpenSemaphore(OUT PHANDLE SemaphoreHandle,
|
NtOpenSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
IN POBJECT_ATTRIBUTES ObjectAttributes)
|
IN POBJECT_ATTRIBUTES ObjectAttributes)
|
||||||
|
@ -159,11 +166,13 @@ NtOpenSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Check Output Safety */
|
/* Check if we were called from user-mode */
|
||||||
if(PreviousMode != KernelMode)
|
if(PreviousMode != KernelMode)
|
||||||
{
|
{
|
||||||
|
/* Enter SEH Block */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Check handle pointer */
|
||||||
ProbeForWriteHandle(SemaphoreHandle);
|
ProbeForWriteHandle(SemaphoreHandle);
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
@ -172,6 +181,7 @@ NtOpenSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
}
|
}
|
||||||
_SEH_END;
|
_SEH_END;
|
||||||
|
|
||||||
|
/* Bail out if pointer was invalid */
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,17 +194,20 @@ NtOpenSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
NULL,
|
NULL,
|
||||||
&hSemaphore);
|
&hSemaphore);
|
||||||
|
|
||||||
/* Check for success and return handle */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status))
|
if(NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
/* Enter SEH Block for return */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Return the handle */
|
||||||
*SemaphoreHandle = hSemaphore;
|
*SemaphoreHandle = hSemaphore;
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
{
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
} _SEH_END;
|
}
|
||||||
|
_SEH_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return Status */
|
/* Return Status */
|
||||||
|
@ -205,7 +218,7 @@ NtOpenSemaphore(OUT PHANDLE SemaphoreHandle,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtQuerySemaphore(IN HANDLE SemaphoreHandle,
|
NtQuerySemaphore(IN HANDLE SemaphoreHandle,
|
||||||
IN SEMAPHORE_INFORMATION_CLASS SemaphoreInformationClass,
|
IN SEMAPHORE_INFORMATION_CLASS SemaphoreInformationClass,
|
||||||
OUT PVOID SemaphoreInformation,
|
OUT PVOID SemaphoreInformation,
|
||||||
|
@ -215,13 +228,13 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle,
|
||||||
PKSEMAPHORE Semaphore;
|
PKSEMAPHORE Semaphore;
|
||||||
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Check buffers and class validity */
|
/* Check buffers and class validity */
|
||||||
Status = DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
|
Status = DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
|
||||||
ExSemaphoreInfoClass,
|
ExSemaphoreInfoClass,
|
||||||
sizeof(ExSemaphoreInfoClass) / sizeof(ExSemaphoreInfoClass[0]),
|
sizeof(ExSemaphoreInfoClass) /
|
||||||
|
sizeof(ExSemaphoreInfoClass[0]),
|
||||||
SemaphoreInformation,
|
SemaphoreInformation,
|
||||||
SemaphoreInformationLength,
|
SemaphoreInformationLength,
|
||||||
ReturnLength,
|
ReturnLength,
|
||||||
|
@ -244,22 +257,24 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle,
|
||||||
/* Check for success */
|
/* Check for success */
|
||||||
if(NT_SUCCESS(Status))
|
if(NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
/* Entry SEH Block */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
PSEMAPHORE_BASIC_INFORMATION BasicInfo = (PSEMAPHORE_BASIC_INFORMATION)SemaphoreInformation;
|
PSEMAPHORE_BASIC_INFORMATION BasicInfo =
|
||||||
|
(PSEMAPHORE_BASIC_INFORMATION)SemaphoreInformation;
|
||||||
|
|
||||||
/* Return the basic information */
|
/* Return the basic information */
|
||||||
BasicInfo->CurrentCount = KeReadStateSemaphore(Semaphore);
|
BasicInfo->CurrentCount = KeReadStateSemaphore(Semaphore);
|
||||||
BasicInfo->MaximumCount = Semaphore->Limit;
|
BasicInfo->MaximumCount = Semaphore->Limit;
|
||||||
|
|
||||||
/* Return length */
|
/* Return the length */
|
||||||
if(ReturnLength) *ReturnLength = sizeof(SEMAPHORE_BASIC_INFORMATION);
|
if(ReturnLength) *ReturnLength = sizeof(*BasicInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
{
|
{
|
||||||
Status = _SEH_GetExceptionCode();
|
Status = _SEH_GetExceptionCode();
|
||||||
} _SEH_END;
|
}
|
||||||
|
_SEH_END;
|
||||||
|
|
||||||
/* Dereference the Object */
|
/* Dereference the Object */
|
||||||
ObDereferenceObject(Semaphore);
|
ObDereferenceObject(Semaphore);
|
||||||
|
@ -273,22 +288,23 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle,
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
STDCALL
|
NTAPI
|
||||||
NtReleaseSemaphore(IN HANDLE SemaphoreHandle,
|
NtReleaseSemaphore(IN HANDLE SemaphoreHandle,
|
||||||
IN LONG ReleaseCount,
|
IN LONG ReleaseCount,
|
||||||
OUT PLONG PreviousCount OPTIONAL)
|
OUT PLONG PreviousCount OPTIONAL)
|
||||||
{
|
{
|
||||||
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
PKSEMAPHORE Semaphore;
|
PKSEMAPHORE Semaphore;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Check buffer validity */
|
/* Check if we were called from user-mode */
|
||||||
if(PreviousCount && PreviousMode != KernelMode)
|
if((PreviousCount) && (PreviousMode != KernelMode))
|
||||||
{
|
{
|
||||||
|
/* Entry SEH Block */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Make sure the state pointer is valid */
|
||||||
ProbeForWriteLong(PreviousCount);
|
ProbeForWriteLong(PreviousCount);
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
|
@ -297,6 +313,7 @@ NtReleaseSemaphore(IN HANDLE SemaphoreHandle,
|
||||||
}
|
}
|
||||||
_SEH_END;
|
_SEH_END;
|
||||||
|
|
||||||
|
/* Bail out if pointer was invalid */
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,9 +335,10 @@ NtReleaseSemaphore(IN HANDLE SemaphoreHandle,
|
||||||
/* Check for success */
|
/* Check for success */
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Release the semaphore */
|
/* Enter SEH Block */
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
|
/* Release the semaphore */
|
||||||
LONG PrevCount = KeReleaseSemaphore(Semaphore,
|
LONG PrevCount = KeReleaseSemaphore(Semaphore,
|
||||||
IO_NO_INCREMENT,
|
IO_NO_INCREMENT,
|
||||||
ReleaseCount,
|
ReleaseCount,
|
||||||
|
@ -328,10 +346,7 @@ NtReleaseSemaphore(IN HANDLE SemaphoreHandle,
|
||||||
ObDereferenceObject(Semaphore);
|
ObDereferenceObject(Semaphore);
|
||||||
|
|
||||||
/* Return the old count if requested */
|
/* Return the old count if requested */
|
||||||
if(PreviousCount)
|
if(PreviousCount) *PreviousCount = PrevCount;
|
||||||
{
|
|
||||||
*PreviousCount = PrevCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue