mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:32:56 +00:00
[NTOSKRNL]
Implement ObSetHandleAttributes. Rename the ObIsKernelHandle macro to ObpIsKernelHandle to avoid ambiguities (ObIsKernelHandle is a public Vista+ API). Check for NtCurrentProcess and NtCurrentThread in ObpIsKernelHandle, since those are always non-kernel handles. svn path=/trunk/; revision=61037
This commit is contained in:
parent
10ec38c1a9
commit
91105c7915
5 changed files with 71 additions and 26 deletions
|
@ -61,9 +61,11 @@
|
||||||
#else
|
#else
|
||||||
#define KERNEL_HANDLE_FLAG 0x80000000
|
#define KERNEL_HANDLE_FLAG 0x80000000
|
||||||
#endif
|
#endif
|
||||||
#define ObIsKernelHandle(Handle, ProcessorMode) \
|
#define ObpIsKernelHandle(Handle, ProcessorMode) \
|
||||||
(((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) && \
|
((((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) == KERNEL_HANDLE_FLAG) && \
|
||||||
((ProcessorMode) == KernelMode))
|
((ProcessorMode) == KernelMode) && \
|
||||||
|
((Handle) != NtCurrentProcess()) && \
|
||||||
|
((Handle) != NtCurrentThread()))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Converts to and from a Kernel Handle to a normal handle
|
// Converts to and from a Kernel Handle to a normal handle
|
||||||
|
|
|
@ -1714,7 +1714,7 @@ ObpCloseHandle(IN HANDLE Handle,
|
||||||
return STATUS_INVALID_HANDLE;
|
return STATUS_INVALID_HANDLE;
|
||||||
|
|
||||||
/* Check if we're dealing with a kernel handle */
|
/* Check if we're dealing with a kernel handle */
|
||||||
if (ObIsKernelHandle(Handle, AccessMode))
|
if (ObpIsKernelHandle(Handle, AccessMode))
|
||||||
{
|
{
|
||||||
/* Use the kernel table and convert the handle */
|
/* Use the kernel table and convert the handle */
|
||||||
HandleTable = ObpKernelHandleTable;
|
HandleTable = ObpKernelHandleTable;
|
||||||
|
@ -3197,8 +3197,52 @@ ObSetHandleAttributes(IN HANDLE Handle,
|
||||||
IN POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags,
|
IN POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags,
|
||||||
IN KPROCESSOR_MODE PreviousMode)
|
IN KPROCESSOR_MODE PreviousMode)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED;
|
OBP_SET_HANDLE_ATTRIBUTES_CONTEXT SetHandleAttributesContext;
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
BOOLEAN Result, AttachedToSystemProcess = FALSE;
|
||||||
|
PHANDLE_TABLE HandleTable;
|
||||||
|
KAPC_STATE ApcState;
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
/* Check if this is a kernel handle */
|
||||||
|
if (ObpIsKernelHandle(Handle, PreviousMode))
|
||||||
|
{
|
||||||
|
/* Use the kernel table and convert the handle */
|
||||||
|
HandleTable = ObpKernelHandleTable;
|
||||||
|
Handle = ObKernelHandleToHandle(Handle);
|
||||||
|
|
||||||
|
/* Check if we're not in the system process */
|
||||||
|
if (PsGetCurrentProcess() != PsInitialSystemProcess)
|
||||||
|
{
|
||||||
|
/* Attach to the system process */
|
||||||
|
KeStackAttachProcess(&PsInitialSystemProcess->Pcb, &ApcState);
|
||||||
|
AttachedToSystemProcess = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Get the current process' handle table */
|
||||||
|
HandleTable = PsGetCurrentProcess()->ObjectTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize the handle attribute context */
|
||||||
|
SetHandleAttributesContext.PreviousMode = PreviousMode;
|
||||||
|
SetHandleAttributesContext.Information = *HandleFlags;
|
||||||
|
|
||||||
|
/* Invoke the ObpSetHandleAttributes callback */
|
||||||
|
Result = ExChangeHandle(HandleTable,
|
||||||
|
Handle,
|
||||||
|
ObpSetHandleAttributes,
|
||||||
|
(ULONG_PTR)&SetHandleAttributesContext);
|
||||||
|
|
||||||
|
/* Did we attach to the system process? */
|
||||||
|
if (AttachedToSystemProcess)
|
||||||
|
{
|
||||||
|
/* Detach from it */
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the result as an NTSTATUS value */
|
||||||
|
return Result ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
@ -3364,13 +3408,12 @@ NtDuplicateObject(IN HANDLE SourceProcessHandle,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ObIsKernelHandle
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
NTAPI
|
NTAPI
|
||||||
ObIsKernelHandle(IN HANDLE Handle)
|
ObIsKernelHandle(IN HANDLE Handle)
|
||||||
{
|
{
|
||||||
/* We know we're kernel mode, so just check for the kernel handle flag */
|
/* Use the inlined version. We know we are in kernel mode. */
|
||||||
return (BOOLEAN)(((ULONG_PTR)Handle & KERNEL_HANDLE_FLAG) != 0);
|
return ObpIsKernelHandle(Handle, KernelMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -1714,7 +1714,7 @@ NtSetInformationObject(IN HANDLE ObjectHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this is a kernel handle */
|
/* Check if this is a kernel handle */
|
||||||
if (ObIsKernelHandle(ObjectHandle, Context.PreviousMode))
|
if (ObpIsKernelHandle(ObjectHandle, Context.PreviousMode))
|
||||||
{
|
{
|
||||||
/* Get the actual handle */
|
/* Get the actual handle */
|
||||||
ObjectHandle = ObKernelHandleToHandle(ObjectHandle);
|
ObjectHandle = ObKernelHandleToHandle(ObjectHandle);
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ ObQueryObjectAuditingByHandle(IN HANDLE Handle,
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Check if we're dealing with a kernel handle */
|
/* Check if we're dealing with a kernel handle */
|
||||||
if (ObIsKernelHandle(Handle, ExGetPreviousMode()))
|
if (ObpIsKernelHandle(Handle, ExGetPreviousMode()))
|
||||||
{
|
{
|
||||||
/* Use the kernel table and convert the handle */
|
/* Use the kernel table and convert the handle */
|
||||||
HandleTable = ObpKernelHandleTable;
|
HandleTable = ObpKernelHandleTable;
|
||||||
|
|
|
@ -142,7 +142,7 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Use the right Executive Handle */
|
/* Use the right Executive Handle */
|
||||||
if (ObIsKernelHandle(Handles[i], PreviousMode))
|
if (ObpIsKernelHandle(Handles[i], PreviousMode))
|
||||||
{
|
{
|
||||||
/* Use the System Handle Table and decode */
|
/* Use the System Handle Table and decode */
|
||||||
HandleTable = ObpKernelHandleTable;
|
HandleTable = ObpKernelHandleTable;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue