mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 19:03:00 +00:00
- Implement new ExHandle* implementation using pushlocks and the Windows 2003 HANDLE_TABLE structure and semantics. Only the currently used base APIs were implemented; support for audit masks still disabled, debug/tracing calls disabled.
- Remove manual overrides of NTDDI_VERSION all over the thread and set it once globally, since ExHandle* was the only non-updated package. The entire kernel now builds with Windows 2003 SP1 as a target. - Remove this entry from kernel fun. svn path=/trunk/; revision=25586
This commit is contained in:
parent
d1c966119b
commit
3e42c58603
19 changed files with 1378 additions and 1054 deletions
|
@ -8,9 +8,6 @@
|
||||||
// Do NOT ask when it will be fixed.
|
// Do NOT ask when it will be fixed.
|
||||||
// Failure to respect this will *ACHIEVE NOTHING*.
|
// Failure to respect this will *ACHIEVE NOTHING*.
|
||||||
//
|
//
|
||||||
// Ex:
|
|
||||||
// - Use pushlocks for handle implementation.
|
|
||||||
//
|
|
||||||
// Ke2:
|
// Ke2:
|
||||||
// - Dispatcher Rewrite (DPCs-Timers-Waits).
|
// - Dispatcher Rewrite (DPCs-Timers-Waits).
|
||||||
//
|
//
|
||||||
|
|
|
@ -66,7 +66,7 @@ CmpCreateHandle(PVOID ObjectBody,
|
||||||
ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
|
||||||
|
|
||||||
/* check that this is a valid kernel pointer */
|
/* check that this is a valid kernel pointer */
|
||||||
ASSERT((ULONG_PTR)ObjectHeader & EX_HANDLE_ENTRY_LOCKED);
|
//ASSERT((ULONG_PTR)ObjectHeader & EX_HANDLE_ENTRY_LOCKED);
|
||||||
|
|
||||||
if (GrantedAccess & MAXIMUM_ALLOWED)
|
if (GrantedAccess & MAXIMUM_ALLOWED)
|
||||||
{
|
{
|
||||||
|
@ -82,9 +82,9 @@ CmpCreateHandle(PVOID ObjectBody,
|
||||||
|
|
||||||
NewEntry.Object = ObjectHeader;
|
NewEntry.Object = ObjectHeader;
|
||||||
if(HandleAttributes & OBJ_INHERIT)
|
if(HandleAttributes & OBJ_INHERIT)
|
||||||
NewEntry.ObAttributes |= EX_HANDLE_ENTRY_INHERITABLE;
|
NewEntry.ObAttributes |= OBJ_INHERIT;
|
||||||
else
|
else
|
||||||
NewEntry.ObAttributes &= ~EX_HANDLE_ENTRY_INHERITABLE;
|
NewEntry.ObAttributes &= ~OBJ_INHERIT;
|
||||||
NewEntry.GrantedAccess = GrantedAccess;
|
NewEntry.GrantedAccess = GrantedAccess;
|
||||||
|
|
||||||
if ((HandleAttributes & OBJ_KERNEL_HANDLE) &&
|
if ((HandleAttributes & OBJ_KERNEL_HANDLE) &&
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -21,6 +21,20 @@ ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset;
|
||||||
ULONG ExpUnicodeCaseTableDataOffset;
|
ULONG ExpUnicodeCaseTableDataOffset;
|
||||||
PVOID ExpNlsSectionPointer;
|
PVOID ExpNlsSectionPointer;
|
||||||
|
|
||||||
|
typedef struct _EXHANDLE
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ULONG TagBits:2;
|
||||||
|
ULONG Index:30;
|
||||||
|
};
|
||||||
|
HANDLE GenericHandleOverlay;
|
||||||
|
ULONG_PTR Value;
|
||||||
|
};
|
||||||
|
} EXHANDLE, *PEXHANDLE;
|
||||||
|
|
||||||
typedef struct _ETIMER
|
typedef struct _ETIMER
|
||||||
{
|
{
|
||||||
KTIMER KeTimer;
|
KTIMER KeTimer;
|
||||||
|
@ -42,13 +56,6 @@ typedef struct
|
||||||
|
|
||||||
#define MAX_FAST_REFS 7
|
#define MAX_FAST_REFS 7
|
||||||
|
|
||||||
#define EX_OBJ_TO_HDR(eob) ((POBJECT_HEADER)((ULONG_PTR)(eob) & \
|
|
||||||
~(EX_HANDLE_ENTRY_PROTECTFROMCLOSE | EX_HANDLE_ENTRY_INHERITABLE | \
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE)))
|
|
||||||
#define EX_HTE_TO_HDR(hte) ((POBJECT_HEADER)((ULONG_PTR)((hte)->Object) & \
|
|
||||||
~(EX_HANDLE_ENTRY_PROTECTFROMCLOSE | EX_HANDLE_ENTRY_INHERITABLE | \
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE)))
|
|
||||||
|
|
||||||
/* Note: we only use a spinlock on SMP. On UP, we cli/sti intead */
|
/* Note: we only use a spinlock on SMP. On UP, we cli/sti intead */
|
||||||
#ifndef CONFIG_SMP
|
#ifndef CONFIG_SMP
|
||||||
#define ExAcquireResourceLock(l, i) { \
|
#define ExAcquireResourceLock(l, i) { \
|
||||||
|
@ -68,6 +75,27 @@ typedef struct
|
||||||
#define ExRundownCompleted _ExRundownCompleted
|
#define ExRundownCompleted _ExRundownCompleted
|
||||||
#define ExGetPreviousMode KeGetPreviousMode
|
#define ExGetPreviousMode KeGetPreviousMode
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Various bits tagged on the handle or handle table
|
||||||
|
//
|
||||||
|
#define EXHANDLE_TABLE_ENTRY_LOCK_BIT 1
|
||||||
|
#define FREE_HANDLE_MASK -1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Number of entries in each table level
|
||||||
|
//
|
||||||
|
#define LOW_LEVEL_ENTRIES (PAGE_SIZE / sizeof(HANDLE_TABLE_ENTRY))
|
||||||
|
#define MID_LEVEL_ENTRIES (PAGE_SIZE / sizeof(PHANDLE_TABLE_ENTRY))
|
||||||
|
#define HIGH_LEVEL_ENTRIES (65535 / (LOW_LEVEL_ENTRIES * MID_LEVEL_ENTRIES))
|
||||||
|
|
||||||
|
//
|
||||||
|
// Maximum index in each table level before we need another table
|
||||||
|
//
|
||||||
|
#define MAX_LOW_INDEX LOW_LEVEL_ENTRIES
|
||||||
|
#define MAX_MID_INDEX (MID_LEVEL_ENTRIES * LOW_LEVEL_ENTRIES)
|
||||||
|
#define MAX_HIGH_INDEX (MID_LEVEL_ENTRIES * MID_LEVEL_ENTRIES * LOW_LEVEL_ENTRIES)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Detect GCC 4.1.2+
|
// Detect GCC 4.1.2+
|
||||||
//
|
//
|
||||||
|
@ -308,104 +336,98 @@ ExfWaitForRundownProtectionRelease(
|
||||||
|
|
||||||
/* HANDLE TABLE FUNCTIONS ***************************************************/
|
/* HANDLE TABLE FUNCTIONS ***************************************************/
|
||||||
|
|
||||||
#define EX_HANDLE_ENTRY_LOCKED (1 << ((sizeof(PVOID) * 8) - 1))
|
typedef VOID
|
||||||
#define EX_HANDLE_ENTRY_PROTECTFROMCLOSE (1 << 0)
|
(NTAPI *PEX_SWEEP_HANDLE_CALLBACK)(
|
||||||
#define EX_HANDLE_ENTRY_INHERITABLE (1 << 1)
|
|
||||||
#define EX_HANDLE_ENTRY_AUDITONCLOSE (1 << 2)
|
|
||||||
|
|
||||||
#define EX_HANDLE_TABLE_CLOSING 0x1
|
|
||||||
|
|
||||||
#define EX_HANDLE_ENTRY_FLAGSMASK (EX_HANDLE_ENTRY_LOCKED | \
|
|
||||||
EX_HANDLE_ENTRY_PROTECTFROMCLOSE | \
|
|
||||||
EX_HANDLE_ENTRY_INHERITABLE | \
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE)
|
|
||||||
|
|
||||||
typedef VOID (NTAPI PEX_SWEEP_HANDLE_CALLBACK)(
|
|
||||||
PHANDLE_TABLE_ENTRY HandleTableEntry,
|
PHANDLE_TABLE_ENTRY HandleTableEntry,
|
||||||
HANDLE Handle,
|
HANDLE Handle,
|
||||||
PVOID Context
|
PVOID Context
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef BOOLEAN (NTAPI PEX_DUPLICATE_HANDLE_CALLBACK)(
|
typedef BOOLEAN
|
||||||
PHANDLE_TABLE HandleTable,
|
(NTAPI *PEX_DUPLICATE_HANDLE_CALLBACK)(
|
||||||
PHANDLE_TABLE_ENTRY HandleTableEntry,
|
IN PEPROCESS Process,
|
||||||
PVOID Context
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef BOOLEAN (NTAPI PEX_CHANGE_HANDLE_CALLBACK)(
|
|
||||||
PHANDLE_TABLE HandleTable,
|
|
||||||
PHANDLE_TABLE_ENTRY HandleTableEntry,
|
|
||||||
PVOID Context
|
|
||||||
);
|
|
||||||
|
|
||||||
VOID
|
|
||||||
ExpInitializeHandleTables(VOID);
|
|
||||||
|
|
||||||
PHANDLE_TABLE
|
|
||||||
ExCreateHandleTable(IN PEPROCESS QuotaProcess OPTIONAL);
|
|
||||||
|
|
||||||
VOID
|
|
||||||
ExDestroyHandleTable(
|
|
||||||
IN PHANDLE_TABLE HandleTable
|
|
||||||
);
|
|
||||||
|
|
||||||
VOID
|
|
||||||
ExSweepHandleTable(
|
|
||||||
IN PHANDLE_TABLE HandleTable,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN PEX_SWEEP_HANDLE_CALLBACK SweepHandleCallback OPTIONAL,
|
IN PHANDLE_TABLE_ENTRY HandleTableEntry,
|
||||||
IN PVOID Context OPTIONAL
|
IN PHANDLE_TABLE_ENTRY NewEntry
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef BOOLEAN
|
||||||
|
(NTAPI *PEX_CHANGE_HANDLE_CALLBACK)(
|
||||||
|
PHANDLE_TABLE_ENTRY HandleTableEntry,
|
||||||
|
ULONG_PTR Context
|
||||||
|
);
|
||||||
|
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
ExpInitializeHandleTables(
|
||||||
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
PHANDLE_TABLE
|
PHANDLE_TABLE
|
||||||
ExDupHandleTable(
|
NTAPI
|
||||||
IN PEPROCESS QuotaProcess OPTIONAL,
|
ExCreateHandleTable(
|
||||||
IN PEX_DUPLICATE_HANDLE_CALLBACK DuplicateHandleCallback OPTIONAL,
|
IN PEPROCESS Process OPTIONAL
|
||||||
IN PVOID Context OPTIONAL,
|
|
||||||
IN PHANDLE_TABLE SourceHandleTable
|
|
||||||
);
|
|
||||||
|
|
||||||
BOOLEAN
|
|
||||||
ExLockHandleTableEntry(
|
|
||||||
IN PHANDLE_TABLE HandleTable,
|
|
||||||
IN PHANDLE_TABLE_ENTRY Entry
|
|
||||||
);
|
);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
NTAPI
|
||||||
ExUnlockHandleTableEntry(
|
ExUnlockHandleTableEntry(
|
||||||
IN PHANDLE_TABLE HandleTable,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN PHANDLE_TABLE_ENTRY Entry
|
IN PHANDLE_TABLE_ENTRY HandleTableEntry
|
||||||
);
|
);
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
|
NTAPI
|
||||||
ExCreateHandle(
|
ExCreateHandle(
|
||||||
IN PHANDLE_TABLE HandleTable,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN PHANDLE_TABLE_ENTRY Entry
|
IN PHANDLE_TABLE_ENTRY HandleTableEntry
|
||||||
);
|
|
||||||
|
|
||||||
BOOLEAN
|
|
||||||
ExDestroyHandle(
|
|
||||||
IN PHANDLE_TABLE HandleTable,
|
|
||||||
IN HANDLE Handle
|
|
||||||
);
|
);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
ExDestroyHandleByEntry(
|
NTAPI
|
||||||
|
ExDestroyHandleTable(
|
||||||
IN PHANDLE_TABLE HandleTable,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN PHANDLE_TABLE_ENTRY Entry,
|
IN PVOID DestroyHandleProcedure OPTIONAL
|
||||||
IN HANDLE Handle
|
);
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
NTAPI
|
||||||
|
ExDestroyHandle(
|
||||||
|
IN PHANDLE_TABLE HandleTable,
|
||||||
|
IN HANDLE Handle,
|
||||||
|
IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL
|
||||||
);
|
);
|
||||||
|
|
||||||
PHANDLE_TABLE_ENTRY
|
PHANDLE_TABLE_ENTRY
|
||||||
|
NTAPI
|
||||||
ExMapHandleToPointer(
|
ExMapHandleToPointer(
|
||||||
IN PHANDLE_TABLE HandleTable,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN HANDLE Handle
|
IN HANDLE Handle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
PHANDLE_TABLE
|
||||||
|
NTAPI
|
||||||
|
ExDupHandleTable(
|
||||||
|
IN PEPROCESS Process,
|
||||||
|
IN PHANDLE_TABLE HandleTable,
|
||||||
|
IN PEX_DUPLICATE_HANDLE_CALLBACK DupHandleProcedure,
|
||||||
|
IN ULONG_PTR Mask
|
||||||
|
);
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
|
NTAPI
|
||||||
ExChangeHandle(
|
ExChangeHandle(
|
||||||
IN PHANDLE_TABLE HandleTable,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN HANDLE Handle,
|
IN HANDLE Handle,
|
||||||
IN PEX_CHANGE_HANDLE_CALLBACK ChangeHandleCallback,
|
IN PEX_CHANGE_HANDLE_CALLBACK ChangeRoutine,
|
||||||
|
IN ULONG_PTR Context
|
||||||
|
);
|
||||||
|
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
ExSweepHandleTable(
|
||||||
|
IN PHANDLE_TABLE HandleTable,
|
||||||
|
IN PEX_SWEEP_HANDLE_CALLBACK EnumHandleProcedure,
|
||||||
IN PVOID Context
|
IN PVOID Context
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,16 @@
|
||||||
GENERIC_EXECUTE | \
|
GENERIC_EXECUTE | \
|
||||||
GENERIC_ALL)
|
GENERIC_ALL)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Bit Flags
|
||||||
|
//
|
||||||
|
#define OBJ_PROTECT_CLOSE 0x01
|
||||||
|
//#define OBJ_INHERIT 0x02
|
||||||
|
#define OBJ_AUDIT_OBJECT_CLOSE 0x04
|
||||||
|
#define OBJ_HANDLE_ATTRIBUTES (OBJ_PROTECT_CLOSE |\
|
||||||
|
OBJ_INHERIT | \
|
||||||
|
OBJ_AUDIT_OBJECT_CLOSE)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Identifies a Kernel Handle
|
// Identifies a Kernel Handle
|
||||||
//
|
//
|
||||||
|
@ -66,6 +76,12 @@
|
||||||
#define ObpGetHandleCountByHandleTable(HandleTable) \
|
#define ObpGetHandleCountByHandleTable(HandleTable) \
|
||||||
((PHANDLE_TABLE)HandleTable)->HandleCount
|
((PHANDLE_TABLE)HandleTable)->HandleCount
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converts from an EXHANDLE object to a POBJECT_HEADER
|
||||||
|
//
|
||||||
|
#define ObpGetHandleObject(x) \
|
||||||
|
((POBJECT_HEADER)((ULONG_PTR)x->Object & ~OBJ_HANDLE_ATTRIBUTES))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Context Structures for Ex*Handle Callbacks
|
// Context Structures for Ex*Handle Callbacks
|
||||||
//
|
//
|
||||||
|
@ -214,9 +230,8 @@ ObpLookupObjectName(
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
NTAPI
|
NTAPI
|
||||||
ObpSetHandleAttributes(
|
ObpSetHandleAttributes(
|
||||||
IN PHANDLE_TABLE HandleTable,
|
|
||||||
IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
|
IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
|
||||||
IN PVOID Context
|
IN ULONG_PTR Context
|
||||||
);
|
);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
/* INCLUDES ******************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
|
||||||
/* Tells the WDK that we don't want to import */
|
/* Always target Windows 2003 Service Pack 1 */
|
||||||
|
#undef NTDDI_VERSION
|
||||||
|
#define NTDDI_VERSION NTDDI_WS03SP1
|
||||||
#define NTKERNELAPI
|
#define NTKERNELAPI
|
||||||
|
|
||||||
/* DDK/IFS/NDK Headers */
|
/* DDK/IFS/NDK Headers */
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#define NTDDI_VERSION NTDDI_WS03
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
@ -952,3 +951,4 @@ KeAreAllApcsDisabled(VOID)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
/* INCLUDES ******************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
|
||||||
#define NTDDI_VERSION NTDDI_WS03
|
|
||||||
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#define NTDDI_VERSION NTDDI_WS03
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
/* INCLUDES ******************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
|
||||||
#define NTDDI_VERSION NTDDI_WS03SP1
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#define NTDDI_VERSION NTDDI_WS03SP1
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
@ -788,3 +787,4 @@ AppCpuInit:
|
||||||
KiIdleLoop();
|
KiIdleLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,16 +131,13 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
|
||||||
if (HandleEntry)
|
if (HandleEntry)
|
||||||
{
|
{
|
||||||
/* Get the object header and validate the type*/
|
/* Get the object header and validate the type*/
|
||||||
ObjectHeader = EX_HTE_TO_HDR(HandleEntry);
|
ObjectHeader = ObpGetHandleObject(HandleEntry);
|
||||||
|
|
||||||
/* Get the granted access and validate it */
|
/* Get the granted access and validate it */
|
||||||
GrantedAccess = HandleEntry->GrantedAccess;
|
GrantedAccess = HandleEntry->GrantedAccess;
|
||||||
|
|
||||||
/* Mask out the internal attributes */
|
/* Mask out the internal attributes */
|
||||||
Attributes = HandleEntry->ObAttributes &
|
Attributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
|
||||||
(EX_HANDLE_ENTRY_PROTECTFROMCLOSE |
|
|
||||||
EX_HANDLE_ENTRY_INHERITABLE |
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE);
|
|
||||||
|
|
||||||
/* Fill out the information */
|
/* Fill out the information */
|
||||||
HandleInformation->HandleAttributes = Attributes;
|
HandleInformation->HandleAttributes = Attributes;
|
||||||
|
@ -588,7 +585,7 @@ ObpCloseHandleTableEntry(IN PHANDLE_TABLE HandleTable,
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Get the object data */
|
/* Get the object data */
|
||||||
ObjectHeader = EX_HTE_TO_HDR(HandleEntry);
|
ObjectHeader = ObpGetHandleObject(HandleEntry);
|
||||||
ObjectType = ObjectHeader->Type;
|
ObjectType = ObjectHeader->Type;
|
||||||
Body = &ObjectHeader->Body;
|
Body = &ObjectHeader->Body;
|
||||||
GrantedAccess = HandleEntry->GrantedAccess;
|
GrantedAccess = HandleEntry->GrantedAccess;
|
||||||
|
@ -621,7 +618,7 @@ ObpCloseHandleTableEntry(IN PHANDLE_TABLE HandleTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The callback allowed us to close it, but does the handle itself? */
|
/* The callback allowed us to close it, but does the handle itself? */
|
||||||
if ((HandleEntry->ObAttributes & EX_HANDLE_ENTRY_PROTECTFROMCLOSE) &&
|
if ((HandleEntry->ObAttributes & OBJ_PROTECT_CLOSE) &&
|
||||||
!(IgnoreHandleProtection))
|
!(IgnoreHandleProtection))
|
||||||
{
|
{
|
||||||
/* It doesn't, are we from user mode? */
|
/* It doesn't, are we from user mode? */
|
||||||
|
@ -650,7 +647,7 @@ ObpCloseHandleTableEntry(IN PHANDLE_TABLE HandleTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destroy and unlock the handle entry */
|
/* Destroy and unlock the handle entry */
|
||||||
ExDestroyHandleByEntry(HandleTable, HandleEntry, Handle);
|
ExDestroyHandle(HandleTable, Handle, HandleEntry);
|
||||||
|
|
||||||
/* Now decrement the handle count */
|
/* Now decrement the handle count */
|
||||||
ObpDecrementHandleCount(Body, PsGetCurrentProcess(), GrantedAccess);
|
ObpDecrementHandleCount(Body, PsGetCurrentProcess(), GrantedAccess);
|
||||||
|
@ -1258,10 +1255,7 @@ ObpCreateUnnamedHandle(IN PVOID Object,
|
||||||
NewEntry.Object = ObjectHeader;
|
NewEntry.Object = ObjectHeader;
|
||||||
|
|
||||||
/* Mask out the internal attributes */
|
/* Mask out the internal attributes */
|
||||||
NewEntry.ObAttributes |= HandleAttributes &
|
NewEntry.ObAttributes |= HandleAttributes & OBJ_HANDLE_ATTRIBUTES;
|
||||||
(EX_HANDLE_ENTRY_PROTECTFROMCLOSE |
|
|
||||||
EX_HANDLE_ENTRY_INHERITABLE |
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE);
|
|
||||||
|
|
||||||
/* Remove what's not in the valid access mask */
|
/* Remove what's not in the valid access mask */
|
||||||
GrantedAccess = DesiredAccess & (ObjectType->TypeInfo.ValidAccessMask |
|
GrantedAccess = DesiredAccess & (ObjectType->TypeInfo.ValidAccessMask |
|
||||||
|
@ -1460,14 +1454,11 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
|
||||||
if (AccessState->GenerateOnClose)
|
if (AccessState->GenerateOnClose)
|
||||||
{
|
{
|
||||||
/* Force the attribute on */
|
/* Force the attribute on */
|
||||||
HandleAttributes|= EX_HANDLE_ENTRY_AUDITONCLOSE;
|
HandleAttributes|= OBJ_AUDIT_OBJECT_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mask out the internal attributes */
|
/* Mask out the internal attributes */
|
||||||
NewEntry.ObAttributes |= HandleAttributes &
|
NewEntry.ObAttributes |= HandleAttributes & OBJ_HANDLE_ATTRIBUTES;
|
||||||
(EX_HANDLE_ENTRY_PROTECTFROMCLOSE |
|
|
||||||
EX_HANDLE_ENTRY_INHERITABLE |
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE);
|
|
||||||
|
|
||||||
/* Get the original desired access */
|
/* Get the original desired access */
|
||||||
DesiredAccess = AccessState->RemainingDesiredAccess |
|
DesiredAccess = AccessState->RemainingDesiredAccess |
|
||||||
|
@ -1697,9 +1688,6 @@ ObpCloseHandle(IN HANDLE Handle,
|
||||||
*
|
*
|
||||||
* The ObpSetHandleAttributes routine <FILLMEIN>
|
* The ObpSetHandleAttributes routine <FILLMEIN>
|
||||||
*
|
*
|
||||||
* @param HandleTable
|
|
||||||
* <FILLMEIN>.
|
|
||||||
*
|
|
||||||
* @param HandleTableEntry
|
* @param HandleTableEntry
|
||||||
* <FILLMEIN>.
|
* <FILLMEIN>.
|
||||||
*
|
*
|
||||||
|
@ -1713,12 +1701,11 @@ ObpCloseHandle(IN HANDLE Handle,
|
||||||
*--*/
|
*--*/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
NTAPI
|
NTAPI
|
||||||
ObpSetHandleAttributes(IN PHANDLE_TABLE HandleTable,
|
ObpSetHandleAttributes(IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
|
||||||
IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
|
IN ULONG_PTR Context)
|
||||||
IN PVOID Context)
|
|
||||||
{
|
{
|
||||||
POBP_SET_HANDLE_ATTRIBUTES_CONTEXT SetHandleInfo = Context;
|
POBP_SET_HANDLE_ATTRIBUTES_CONTEXT SetHandleInfo = (PVOID)Context;
|
||||||
POBJECT_HEADER ObjectHeader = EX_HTE_TO_HDR(HandleTableEntry);
|
POBJECT_HEADER ObjectHeader = ObpGetHandleObject(HandleTableEntry);
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Don't allow operations on kernel objects */
|
/* Don't allow operations on kernel objects */
|
||||||
|
@ -1740,24 +1727,24 @@ ObpSetHandleAttributes(IN PHANDLE_TABLE HandleTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the flag */
|
/* Set the flag */
|
||||||
HandleTableEntry->ObAttributes |= EX_HANDLE_ENTRY_INHERITABLE;
|
HandleTableEntry->ObAttributes |= OBJ_INHERIT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Otherwise this implies we're removing the flag */
|
/* Otherwise this implies we're removing the flag */
|
||||||
HandleTableEntry->ObAttributes &= ~EX_HANDLE_ENTRY_INHERITABLE;
|
HandleTableEntry->ObAttributes &= ~OBJ_INHERIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if making the handle protected */
|
/* Check if making the handle protected */
|
||||||
if (SetHandleInfo->Information.ProtectFromClose)
|
if (SetHandleInfo->Information.ProtectFromClose)
|
||||||
{
|
{
|
||||||
/* Set the flag */
|
/* Set the flag */
|
||||||
HandleTableEntry->ObAttributes |= EX_HANDLE_ENTRY_PROTECTFROMCLOSE;
|
HandleTableEntry->ObAttributes |= OBJ_PROTECT_CLOSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Otherwise, remove it */
|
/* Otherwise, remove it */
|
||||||
HandleTableEntry->ObAttributes &= ~EX_HANDLE_ENTRY_PROTECTFROMCLOSE;
|
HandleTableEntry->ObAttributes &= ~OBJ_PROTECT_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
|
@ -1823,9 +1810,10 @@ ObpCloseHandleCallback(IN PHANDLE_TABLE_ENTRY HandleTableEntry,
|
||||||
*--*/
|
*--*/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
NTAPI
|
NTAPI
|
||||||
ObpDuplicateHandleCallback(IN PHANDLE_TABLE HandleTable,
|
ObpDuplicateHandleCallback(IN PEPROCESS Process,
|
||||||
IN PHANDLE_TABLE_ENTRY HandleTableEntry,
|
IN PHANDLE_TABLE HandleTable,
|
||||||
IN PVOID Context)
|
IN PHANDLE_TABLE_ENTRY OldEntry,
|
||||||
|
IN PHANDLE_TABLE_ENTRY HandleTableEntry)
|
||||||
{
|
{
|
||||||
POBJECT_HEADER ObjectHeader;
|
POBJECT_HEADER ObjectHeader;
|
||||||
BOOLEAN Ret = FALSE;
|
BOOLEAN Ret = FALSE;
|
||||||
|
@ -1834,11 +1822,17 @@ ObpDuplicateHandleCallback(IN PHANDLE_TABLE HandleTable,
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Make sure that the handle is inheritable */
|
/* Make sure that the handle is inheritable */
|
||||||
Ret = (HandleTableEntry->ObAttributes & EX_HANDLE_ENTRY_INHERITABLE) != 0;
|
Ret = (HandleTableEntry->ObAttributes & OBJ_INHERIT) != 0;
|
||||||
if (Ret)
|
if (Ret)
|
||||||
{
|
{
|
||||||
/* Get the object header */
|
/* Get the object header */
|
||||||
ObjectHeader = EX_HTE_TO_HDR(HandleTableEntry);
|
ObjectHeader = ObpGetHandleObject(HandleTableEntry);
|
||||||
|
|
||||||
|
/* Increment the pointer count */
|
||||||
|
InterlockedIncrement(&ObjectHeader->PointerCount);
|
||||||
|
|
||||||
|
/* Release the handle lock */
|
||||||
|
ExUnlockHandleTableEntry(HandleTable, OldEntry);
|
||||||
|
|
||||||
/* Setup the access state */
|
/* Setup the access state */
|
||||||
AccessState.PreviouslyGrantedAccess = HandleTableEntry->GrantedAccess;
|
AccessState.PreviouslyGrantedAccess = HandleTableEntry->GrantedAccess;
|
||||||
|
@ -1848,18 +1842,19 @@ ObpDuplicateHandleCallback(IN PHANDLE_TABLE HandleTable,
|
||||||
&AccessState,
|
&AccessState,
|
||||||
KernelMode,
|
KernelMode,
|
||||||
HandleTableEntry->ObAttributes,
|
HandleTableEntry->ObAttributes,
|
||||||
PsGetCurrentProcess(),
|
Process,
|
||||||
ObInheritHandle);
|
ObInheritHandle);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Return failure */
|
/* Return failure */
|
||||||
|
ObDereferenceObject(&ObjectHeader->Body);
|
||||||
Ret = FALSE;
|
Ret = FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Otherwise increment the pointer count */
|
/* Release the handle lock */
|
||||||
InterlockedIncrement(&ObjectHeader->PointerCount);
|
ExUnlockHandleTableEntry(HandleTable, OldEntry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return duplication result */
|
/* Return duplication result */
|
||||||
|
@ -1906,9 +1901,9 @@ ObpCreateHandleTable(IN PEPROCESS Parent,
|
||||||
|
|
||||||
/* Duplicate the parent's */
|
/* Duplicate the parent's */
|
||||||
HandleTable = ExDupHandleTable(Process,
|
HandleTable = ExDupHandleTable(Process,
|
||||||
|
HandleTable,
|
||||||
ObpDuplicateHandleCallback,
|
ObpDuplicateHandleCallback,
|
||||||
NULL,
|
OBJ_INHERIT);
|
||||||
HandleTable);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1981,7 +1976,7 @@ ObKillProcess(IN PEPROCESS Process)
|
||||||
|
|
||||||
/* Destroy the object table */
|
/* Destroy the object table */
|
||||||
Process->ObjectTable = NULL;
|
Process->ObjectTable = NULL;
|
||||||
ExDestroyHandleTable(HandleTable);
|
ExDestroyHandleTable(HandleTable, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
@ -2121,10 +2116,7 @@ ObDuplicateObject(IN PEPROCESS SourceProcess,
|
||||||
|
|
||||||
/* Fill out the entry */
|
/* Fill out the entry */
|
||||||
NewHandleEntry.Object = ObjectHeader;
|
NewHandleEntry.Object = ObjectHeader;
|
||||||
NewHandleEntry.ObAttributes |= HandleAttributes &
|
NewHandleEntry.ObAttributes |= HandleAttributes & OBJ_HANDLE_ATTRIBUTES;
|
||||||
(EX_HANDLE_ENTRY_PROTECTFROMCLOSE |
|
|
||||||
EX_HANDLE_ENTRY_INHERITABLE |
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE);
|
|
||||||
|
|
||||||
/* Check if we're using a generic mask */
|
/* Check if we're using a generic mask */
|
||||||
if (DesiredAccess & GENERIC_ACCESS)
|
if (DesiredAccess & GENERIC_ACCESS)
|
||||||
|
|
|
@ -1442,10 +1442,9 @@ NtQueryObject(IN HANDLE ObjectHandle,
|
||||||
ObjectInformation;
|
ObjectInformation;
|
||||||
|
|
||||||
/* Set the flags */
|
/* Set the flags */
|
||||||
HandleFlags->Inherit = (HandleInfo.HandleAttributes &
|
HandleFlags->Inherit = HandleInfo.HandleAttributes & OBJ_INHERIT;
|
||||||
EX_HANDLE_ENTRY_INHERITABLE) != 0;
|
|
||||||
HandleFlags->ProtectFromClose = (HandleInfo.HandleAttributes &
|
HandleFlags->ProtectFromClose = (HandleInfo.HandleAttributes &
|
||||||
EX_HANDLE_ENTRY_PROTECTFROMCLOSE) != 0;
|
OBJ_PROTECT_CLOSE) != 0;
|
||||||
|
|
||||||
/* Break out with success */
|
/* Break out with success */
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
|
@ -1581,7 +1580,7 @@ NtSetInformationObject(IN HANDLE ObjectHandle,
|
||||||
if (!ExChangeHandle(ObjectTable,
|
if (!ExChangeHandle(ObjectTable,
|
||||||
ObjectHandle,
|
ObjectHandle,
|
||||||
ObpSetHandleAttributes,
|
ObpSetHandleAttributes,
|
||||||
&Context))
|
(ULONG_PTR)&Context))
|
||||||
{
|
{
|
||||||
/* Some failure */
|
/* Some failure */
|
||||||
Status = STATUS_ACCESS_DENIED;
|
Status = STATUS_ACCESS_DENIED;
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
/* INCLUDES ******************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
|
||||||
#define NTDDI_VERSION NTDDI_WINXP
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
|
@ -560,7 +560,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
|
||||||
if (HandleEntry)
|
if (HandleEntry)
|
||||||
{
|
{
|
||||||
/* Get the object header and validate the type*/
|
/* Get the object header and validate the type*/
|
||||||
ObjectHeader = EX_HTE_TO_HDR(HandleEntry);
|
ObjectHeader = ObpGetHandleObject(HandleEntry);
|
||||||
if (!(ObjectType) || (ObjectType == ObjectHeader->Type))
|
if (!(ObjectType) || (ObjectType == ObjectHeader->Type))
|
||||||
{
|
{
|
||||||
/* Get the granted access and validate it */
|
/* Get the granted access and validate it */
|
||||||
|
@ -572,10 +572,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
|
||||||
InterlockedIncrement(&ObjectHeader->PointerCount);
|
InterlockedIncrement(&ObjectHeader->PointerCount);
|
||||||
|
|
||||||
/* Mask out the internal attributes */
|
/* Mask out the internal attributes */
|
||||||
Attributes = HandleEntry->ObAttributes &
|
Attributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
|
||||||
(EX_HANDLE_ENTRY_PROTECTFROMCLOSE |
|
|
||||||
EX_HANDLE_ENTRY_INHERITABLE |
|
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE);
|
|
||||||
|
|
||||||
/* Check if the caller wants handle information */
|
/* Check if the caller wants handle information */
|
||||||
if (HandleInformation)
|
if (HandleInformation)
|
||||||
|
|
|
@ -829,8 +829,7 @@ ObQueryObjectAuditingByHandle(IN HANDLE Handle,
|
||||||
if(HandleEntry)
|
if(HandleEntry)
|
||||||
{
|
{
|
||||||
/* Check if the flag is set */
|
/* Check if the flag is set */
|
||||||
*GenerateOnClose = (HandleEntry->ObAttributes &
|
*GenerateOnClose = HandleEntry->ObAttributes & OBJ_AUDIT_OBJECT_CLOSE;
|
||||||
EX_HANDLE_ENTRY_AUDITONCLOSE) != 0;
|
|
||||||
|
|
||||||
/* Unlock the entry */
|
/* Unlock the entry */
|
||||||
ExUnlockHandleTableEntry(HandleTable, HandleEntry);
|
ExUnlockHandleTableEntry(HandleTable, HandleEntry);
|
||||||
|
|
|
@ -181,7 +181,7 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the Object Header */
|
/* Get the Object Header */
|
||||||
ObjectHeader = EX_HTE_TO_HDR(HandleEntry);
|
ObjectHeader = ObpGetHandleObject(HandleEntry);
|
||||||
|
|
||||||
/* Get default Object */
|
/* Get default Object */
|
||||||
DefaultObject = ObjectHeader->Type->DefaultObject;
|
DefaultObject = ObjectHeader->Type->DefaultObject;
|
||||||
|
|
|
@ -310,7 +310,7 @@ PspDeleteProcess(IN PVOID ObjectBody)
|
||||||
if (Process->UniqueProcessId)
|
if (Process->UniqueProcessId)
|
||||||
{
|
{
|
||||||
/* Delete the PID */
|
/* Delete the PID */
|
||||||
if (!(ExDestroyHandle(PspCidTable, Process->UniqueProcessId)))
|
if (!(ExDestroyHandle(PspCidTable, Process->UniqueProcessId, NULL)))
|
||||||
{
|
{
|
||||||
/* Something wrong happened, bugcheck */
|
/* Something wrong happened, bugcheck */
|
||||||
KEBUGCHECK(CID_HANDLE_DELETION);
|
KEBUGCHECK(CID_HANDLE_DELETION);
|
||||||
|
@ -360,7 +360,7 @@ PspDeleteThread(IN PVOID ObjectBody)
|
||||||
if (Thread->Cid.UniqueThread)
|
if (Thread->Cid.UniqueThread)
|
||||||
{
|
{
|
||||||
/* Delete the CID Handle */
|
/* Delete the CID Handle */
|
||||||
if (!(ExDestroyHandle(PspCidTable, Thread->Cid.UniqueThread)))
|
if (!(ExDestroyHandle(PspCidTable, Thread->Cid.UniqueThread, NULL)))
|
||||||
{
|
{
|
||||||
/* Something wrong happened, bugcheck */
|
/* Something wrong happened, bugcheck */
|
||||||
KEBUGCHECK(CID_HANDLE_DELETION);
|
KEBUGCHECK(CID_HANDLE_DELETION);
|
||||||
|
|
|
@ -259,7 +259,7 @@ RtlpDestroyAtomHandleTable(PRTL_ATOM_TABLE AtomTable)
|
||||||
ExSweepHandleTable(AtomTable->ExHandleTable,
|
ExSweepHandleTable(AtomTable->ExHandleTable,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
ExDestroyHandleTable(AtomTable->ExHandleTable);
|
ExDestroyHandleTable(AtomTable->ExHandleTable, NULL);
|
||||||
AtomTable->ExHandleTable = NULL;
|
AtomTable->ExHandleTable = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,8 @@ VOID
|
||||||
RtlpFreeAtomHandle(PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
|
RtlpFreeAtomHandle(PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
|
||||||
{
|
{
|
||||||
ExDestroyHandle(AtomTable->ExHandleTable,
|
ExDestroyHandle(AtomTable->ExHandleTable,
|
||||||
(HANDLE)((ULONG_PTR)Entry->HandleIndex << 2));
|
(HANDLE)((ULONG_PTR)Entry->HandleIndex << 2),
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
|
@ -336,7 +337,8 @@ RtlpCreateAtomHandle(PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ExDestroyHandle(AtomTable->ExHandleTable,
|
ExDestroyHandle(AtomTable->ExHandleTable,
|
||||||
Handle);
|
Handle,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue