ReactOS  0.4.11-dev-433-g473ca91
obhandle.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for obhandle.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define TAG_OB_HANDLE   'dHbO'
 

Functions

PHANDLE_TABLE NTAPI ObReferenceProcessHandleTable (IN PEPROCESS Process)
 
VOID NTAPI ObDereferenceProcessHandleTable (IN PEPROCESS Process)
 
ULONG NTAPI ObGetProcessHandleCount (IN PEPROCESS Process)
 
NTSTATUS NTAPI ObpReferenceProcessObjectByHandle (IN HANDLE Handle, IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation, OUT PACCESS_MASK AuditMask)
 
BOOLEAN NTAPI ObpEnumFindHandleProcedure (IN PHANDLE_TABLE_ENTRY HandleEntry, IN HANDLE Handle, IN PVOID Context)
 
POBJECT_HANDLE_COUNT_ENTRY NTAPI ObpInsertHandleCount (IN POBJECT_HEADER ObjectHeader)
 
NTSTATUS NTAPI ObpIncrementHandleDataBase (IN POBJECT_HEADER ObjectHeader, IN PEPROCESS Process, IN OUT PULONG NewProcessHandleCount)
 
NTSTATUS NTAPI ObpChargeQuotaForObject (IN POBJECT_HEADER ObjectHeader, IN POBJECT_TYPE ObjectType, OUT PBOOLEAN NewObject)
 
NTSTATUS NTAPI ObpValidateAccessMask (IN PACCESS_STATE AccessState)
 
VOID NTAPI ObpDecrementHandleCount (IN PVOID ObjectBody, IN PEPROCESS Process, IN ACCESS_MASK GrantedAccess, IN POBJECT_TYPE ObjectType)
 
NTSTATUS NTAPI ObpCloseHandleTableEntry (IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleEntry, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode, IN BOOLEAN IgnoreHandleProtection)
 
NTSTATUS NTAPI ObpIncrementHandleCount (IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN ULONG HandleAttributes, IN PEPROCESS Process, IN OB_OPEN_REASON OpenReason)
 
NTSTATUS NTAPI ObpIncrementUnnamedHandleCount (IN PVOID Object, IN PACCESS_MASK DesiredAccess, IN KPROCESSOR_MODE AccessMode, IN ULONG HandleAttributes, IN PEPROCESS Process)
 
NTSTATUS NTAPI ObpCreateUnnamedHandle (IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN ULONG AdditionalReferences, IN ULONG HandleAttributes, IN KPROCESSOR_MODE AccessMode, OUT PVOID *ReturnedObject, OUT PHANDLE ReturnedHandle)
 
NTSTATUS NTAPI ObpCreateHandle (IN OB_OPEN_REASON OpenReason, IN PVOID Object, IN POBJECT_TYPE Type OPTIONAL, IN PACCESS_STATE AccessState, IN ULONG AdditionalReferences, IN ULONG HandleAttributes, IN POBP_LOOKUP_CONTEXT Context, IN KPROCESSOR_MODE AccessMode, OUT PVOID *ReturnedObject, OUT PHANDLE ReturnedHandle)
 
NTSTATUS NTAPI ObpCloseHandle (IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
 
BOOLEAN NTAPI ObpSetHandleAttributes (IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry, IN ULONG_PTR Context)
 
BOOLEAN NTAPI ObpCloseHandleCallback (IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN HANDLE Handle, IN PVOID Context)
 
BOOLEAN NTAPI ObpDuplicateHandleCallback (IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY OldEntry, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
 
VOID NTAPI ObClearProcessHandleTable (IN PEPROCESS Process)
 
NTSTATUS NTAPI ObInitProcess (IN PEPROCESS Parent OPTIONAL, IN PEPROCESS Process)
 
VOID NTAPI ObKillProcess (IN PEPROCESS Process)
 
NTSTATUS NTAPI ObDuplicateObject (IN PEPROCESS SourceProcess, IN HANDLE SourceHandle, IN PEPROCESS TargetProcess OPTIONAL, IN PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options, IN KPROCESSOR_MODE PreviousMode)
 
NTSTATUS NTAPI ObOpenObjectByName (IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
 
NTSTATUS NTAPI ObOpenObjectByPointer (IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
 
BOOLEAN NTAPI ObFindHandleForObject (IN PEPROCESS Process, IN PVOID Object, IN POBJECT_TYPE ObjectType, IN POBJECT_HANDLE_INFORMATION HandleInformation, OUT PHANDLE Handle)
 
NTSTATUS NTAPI ObInsertObject (IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
 
NTSTATUS NTAPI ObSetHandleAttributes (IN HANDLE Handle, IN POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags, IN KPROCESSOR_MODE PreviousMode)
 
NTSTATUS NTAPI ObCloseHandle (IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
 
NTSTATUS NTAPI NtClose (IN HANDLE Handle)
 
NTSTATUS NTAPI NtDuplicateObject (IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
 
BOOLEAN NTAPI ObIsKernelHandle (IN HANDLE Handle)
 

Variables

PHANDLE_TABLE ObpKernelHandleTable = NULL
 
ULONG ObpAccessProtectCloseBit = MAXIMUM_ALLOWED
 

Macro Definition Documentation

#define NDEBUG

Definition at line 17 of file obhandle.c.

#define TAG_OB_HANDLE   'dHbO'

Definition at line 23 of file obhandle.c.

Referenced by ObpInsertHandleCount().

Function Documentation

NTSTATUS NTAPI NtClose ( IN HANDLE  Handle)

Definition at line 3393 of file obhandle.c.

Referenced by _At_(), _main(), _tmain(), AccpCloseObjectHandle(), AddCodepageToRegistry(), BtrfsDeviceAdd::AddDevice(), AddFontsSettingsToRegistry(), AddHotkeySettings(), AddKbLayoutsToRegistry(), AfdBind(), AfdConnect(), AfdSend(), AfdSendTo(), BaseComputeProcessDllPath(), BaseGetNamedObjectDirectory(), BaseInitializeStaticServerData(), BasepCopyFileExW(), BasepIsProcessAllowed(), BasepMapFile(), BasepMoveFileDelayed(), BasepNotifyTrackingService(), BasepOpenFileForMove(), BasepSxsCloseHandles(), BaseSrvCleanupVDMResources(), BaseSrvCreatePairWaitHandles(), BaseSrvDestroyConsoleRecord(), BaseSrvDestroyPairWaitHandles(), BaseSrvIsVdmAllowed(), Beep(), CabinetExtractFile(), CallApphelpWithImage(), CallCacheControl(), CheckForValidPEAndVendor(), CheckTokenMembership(), ClientThread(), CloseCabinet(), CloseDefaultKeys(), CloseDevice(), CloseHandle(), CloseIniBootLoaderStore(), closeTcpFile(), CmGetSystemDriverList(), CmInitSystem1(), CmpCreateControlSet(), CmpCreateHardwareProfile(), CmpInitializeHardwareConfiguration(), CmpInitializeMachineDependentConfiguration(), CmpInitializeRegistryNode(), CmpSetSystemValues(), CmpSetupConfigurationTree(), CmpSetVersionData(), CommandDumpSector(), CommandPartInfo(), ConCfgOpenUserSettings(), ConDrvUnpause(), ConnectConsole(), ConnectRegistry(), ConSrvDeleteConsole(), ConSrvInitConsole(), create_classes_root_hkey(), create_key(), create_registry_key(), CreateBaseAcls(), CreateContext(), CreateDirectoryExW(), CreateDirectoryW(), CreateHardLinkW(), CreateIoCompletionPort(), CreateKeyTest(), CreateNestedKey(), CreatePartitionList(), CreatePipe(), CreateProcessAsUserCommon(), CreateProcessInternalW(), CreateRegistryFile(), CreateWindowStationW(), CSR_API(), CSR_SERVER_DLL_INIT(), CsrApiPortInitialize(), CsrCreateRemoteThread(), CsrGetProcessLuid(), CsrpCheckRequestThreads(), CsrpConnectToServer(), CsrProcessRefcountZero(), CsrSbApiRequestThread(), CsrSetProcessSecurity(), CsrSrvCreateSharedSection(), CsrThreadRefcountZero(), DbgUiIssueRemoteBreakin(), DebugActiveProcess(), DebugActiveProcessStop(), DeleteFileW(), DeleteKeyTest(), DeleteValueTest(), DestroyProtoHive(), do_enumeratekey(), DoesFileExist(), DoesPathExist(), DumpRegistryData(), EnumerateKeyTest(), EnumerateValueTest(), EventThread(), ExpandSymbolicLink(), ExpCreateSystemRootLink(), ExpInitializeCallbacks(), Ext2CloseDevice(), find_devices(), FindClose(), FindFirstChangeNotificationW(), FindFirstFileExW(), FindFirstStreamW(), FindNTOSInstallations(), FormatEx2(), FreeConsole(), get_manifest_in_associated_manifest(), get_manifest_in_manifest_file(), get_manifest_in_pe_file(), get_registry_locale_info(), GetComputerIdentifier(), GetComputerNameFromRegistry(), GetCPFileNameFromRegistry(), GetDiskFreeSpaceExW(), GetDiskFreeSpaceW(), GetDisplayIdentifier(), GetDllList(), GetDosDevicesProtection(), GetDriveTypeW(), GetFileSecurityW(), GetFileSystem(), GetNTObjectSymbolicLinkTarget(), GetRegInt(), GetSocketInformation(), GetSourcePaths(), GetTempFileNameW(), GetTimeouts(), GetUserGeoID(), GetVolumeInformationW(), GetVolumeNameForRoot(), GRAPHICS_BUFFER_Destroy(), GRAPHICS_BUFFER_Initialize(), GuiApplyUserSettings(), GuiConsoleShowConsoleProperties(), GuiDeinitFrontEnd(), GuiInit(), GuiInitFrontEnd(), ImpersonateLoggedOnUser(), InfOpenFile(), InfWriteFile(), IniCacheLoad(), IniCacheSave(), InitFunctionPtrs(), InitializeFmIfsOnce(), InitLogPort(), InstallBtrfsBootCodeToDisk(), InstallDevice(), InstallDriver(), InstallFat12BootCodeToFloppy(), InstallFat16BootCode(), InstallFat16BootCodeToDisk(), InstallFat16BootCodeToFile(), InstallFat32BootCode(), InstallFat32BootCodeToDisk(), InstallFat32BootCodeToFile(), InstallMbrBootCodeToDisk(), IntAllocConsole(), IntAttachConsole(), IntGetCodePageEntry(), IopCreateRootDirectories(), IopInitializePlugPlayServices(), IopMarkBootPartition(), is_mounted_multi_device(), IsAcpiComputer(), IsShimInfrastructureDisabled(), IsThereAValidBootSector(), IsThisARootDirectory(), IsValidLanguageGroup(), IsValidNTOSInstallation_UStr(), keyed_event_thread(), KsecOpenDevice(), LdrOpenImageFileOptionsKey(), LdrpCheckForKnownDll(), LdrpCheckForLoadedDll(), LdrpCreateDllSection(), LdrpInitializeProcess(), LdrpMapDll(), LdrQueryImageFileExecutionOptionsEx(), LdrVerifyImageMatchesChecksum(), ListDirectory(), LoadModule(), LogfBackupFile(), LogfClose(), LogfCreate(), lookup_assembly(), lookup_winsxs(), LsaConnectUntrusted(), LsapCheckLogonProcess(), LsapCloseDbObject(), LsapCloseLsaPort(), LsapCreateDatabaseKeys(), LsapCreateDbObject(), LsapDeleteDbObject(), LsapDeregisterLogonProcess(), LsapEnumLogonSessions(), LsapGetLogonSessionData(), LsapGetObjectAttribute(), LsapIsDatabaseInstalled(), LsapLogonUser(), LsapOpenDbObject(), LsapRegCloseKey(), LsapRegDeleteSubKey(), LsapSetObjectAttribute(), LsarSetSecurityObject(), main(), MoveFileWithProgressW(), MyDeleteFile(), NetUserChangePassword(), NLS_EnumLanguageGroupLocales(), NLS_EnumSystemCodePages(), NLS_EnumSystemLanguageGroups(), NlsInit(), NlsUninit(), NtQueryOpenSubKeys(), ObDuplicateObject(), ObInitSystem(), ObpCreateDosDevicesDirectory(), OpenAndMapFile(), OpenBootStore_UStr(), OpenFile(), OpenIniBootLoaderStore(), OpenWindowStationW(), parse_file(), Phase1InitializationDiscard(), PipGetDriverTagPriority(), BtrfsDeviceAdd::populate_device_tree(), PortThreadRoutine(), PrintProcess(), PrintThreads(), PrivMoveFileIdentityW(), ProcessIdToSessionId(), ProcessLocaleRegistry(), QueryDosDeviceW(), ReadBlock(), RegCloseKey(), RegCopyTreeW(), RegDeleteKeyExW(), RegDeleteKeyValueW(), RegisterUncProvider(), registry_callback(), RegOverridePredefKey(), RegpCopyTree(), RegReplaceKeyW(), RegRestoreKeyW(), RegSaveKeyW(), RegSetKeyValueA(), RegSetKeyValueW(), RemoveDirectoryW(), ReplaceFileW(), ResolveArcNameNtSymLink(), RSetServiceObjectSecurity(), RtlCreateActivationContext(), RtlCreateTimerQueue(), RtlCreateUserSecurityObject(), RtlCreateUserThread(), RtlDefaultNpAcl(), RtlDeleteCriticalSection(), RtlDeleteResource(), RtlDeleteTimer(), RtlDeleteTimerQueueEx(), RtlDeregisterWaitEx(), RtlImpersonateSelf(), RtlInitializeRXact(), RtlNewSecurityGrantedAccess(), RtlpCloseKeyedEvent(), RtlpExecuteIoWorkItem(), RtlpExecuteWorkItem(), RtlpIoWorkerThreadProc(), RtlpIsIoPending(), RtlpStartWorkerThread(), RtlQueryRegistryValues(), RtlQueueWorkItem(), RtlRegisterWait(), RtlReleaseRelativeName(), RtlSetCurrentDirectory_U(), RXactpCommit(), SampRegCloseKey(), SampRegDeleteKey(), SamrSetSecurityObject(), SaveBootSector(), ScmCheckDriver(), ScmConvertToBootPathName(), ScmGetDriverStatus(), SdbCloseDatabase(), SdbDeletePermLayerKeys(), SdbpCloseMemMappedFile(), SdbpGetPermLayersInternal(), SdbpOpenMemMappedFile(), SdbSetPermLayerKeys(), ServerThread(), SetComputerNameToRegistry(), SetDefaultPagefile(), SetFileAttributesW(), SetFileSecurityW(), SetGeoID(), SetInstallPathValue(), SetLocaleInfoW(), SetMountedDeviceValue(), SetRegistryValue(), SetRosSpecificInfo(), SetSocketInformation(), SetupCopyFile(), SetupCreateSingleDirectory(), SetUserGeoID(), SetValueTest1(), SetValueTest2(), SetVolumeLabelW(), SmExecPgm(), SmLookupSubsystem(), SmpAcquirePrivilege(), SmpConfigureObjectDirectories(), SmpCreateDynamicEnvironmentVariables(), SmpCreateVolumeDescriptors(), SmpDeletePagingFile(), SmpDereferenceSubsystem(), SmpExecPgm(), SmpExecuteImage(), SmpExecuteInitialCommand(), SmpGetPagingFileSize(), SmpGetVolumeFreeSpace(), SmpHandleConnectionRequest(), SmpInit(), SmpInitializeDosDevices(), SmpInitializeKnownDllsInternal(), SmpLoadDataFromRegistry(), SmpLoadSubSystem(), SmpProcessFileRenames(), SmpQueryRegistrySosOption(), SmpReleasePrivilege(), SmpSbCreateSession(), SmpTranslateSystemPartitionInformation(), SockCreateOrReferenceAsyncThread(), SpeakerCleanup(), START_TEST(), StartAuthenticationPort(), test1(), test2(), test3(), test5(), test6(), test7(), test9(), Test_ApphelpCheckRunApp(), Test_EmptyFile(), Test_ImageSection(), test_keyed_events(), Test_KeyFullInformation(), Test_KeyNameInformation(), test_mutant(), test_NtOpenKey(), Test_PageFileSection(), Test_recv(), Test_SectionContents(), test_tp_multi_wait(), TestCreateOpen_(), TestSend(), TestSendTo(), TH32CreateSnapshotSectionInitialize(), timer_queue_thread_proc(), UnhandledExceptionFilter(), UnMapFile(), UserpFormatMessages(), VfatFormat(), VfatxFormat(), Wait_thread_proc(), WaitNamedPipeW(), WinExec(), WritePartitions(), WSHIoctl_GetInterfaceList(), WSPAccept(), WSPBind(), WSPCloseSocket(), WSPConnect(), WSPDuplicateSocket(), WSPEnumNetworkEvents(), WSPEventSelect(), WSPGetPeerName(), WSPGetSockName(), WSPListen(), WSPRecv(), WSPRecvFrom(), WSPSelect(), WSPSend(), WSPSendTo(), WSPShutdown(), WSPSocket(), and CEnumNTDirectory::~CEnumNTDirectory().

3394 {
3395  /* Call the internal API */
3397 }
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
NTSTATUS NTAPI ObpCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:1727
_In_ HANDLE Handle
Definition: extypes.h:390
NTSTATUS NTAPI NtDuplicateObject ( IN HANDLE  SourceProcessHandle,
IN HANDLE  SourceHandle,
IN HANDLE TargetProcessHandle  OPTIONAL,
OUT PHANDLE TargetHandle  OPTIONAL,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  HandleAttributes,
IN ULONG  Options 
)

Definition at line 3401 of file obhandle.c.

Referenced by BaseSrvCreatePairWaitHandles(), BaseSrvDestroyPairWaitHandles(), ConSrvAllocateConsole(), ConSrvInheritConsole(), CSR_API(), CsrCreateRemoteThread(), DuplicateHandle(), GRAPHICS_BUFFER_Destroy(), GRAPHICS_BUFFER_Initialize(), GuiApplyUserSettings(), GuiConsoleShowConsoleProperties(), GuiInit(), LsapLogonUser(), RtlpIoWorkerThreadProc(), RtlpIsIoPending(), SmpExecPgm(), SmpExecuteInitialCommand(), SmpLoadSubSystem(), SmpSbCreateSession(), and StuffStdHandle().

3408 {
3409  PEPROCESS SourceProcess, TargetProcess, Target;
3410  HANDLE hTarget;
3412  NTSTATUS Status;
3414  "%s - Duplicating handle: %p for %p into %p.\n",
3415  __FUNCTION__,
3416  SourceHandle,
3417  SourceProcessHandle,
3419 
3420  /* Check if we have a target handle */
3421  if ((TargetHandle) && (PreviousMode != KernelMode))
3422  {
3423  /* Enter SEH */
3424  _SEH2_TRY
3425  {
3426  /* Probe the handle and assume failure */
3428  *TargetHandle = NULL;
3429  }
3431  {
3432  /* Return the exception code */
3434  }
3435  _SEH2_END;
3436  }
3437 
3438  /* Now reference the input handle */
3439  Status = ObReferenceObjectByHandle(SourceProcessHandle,
3441  PsProcessType,
3442  PreviousMode,
3443  (PVOID*)&SourceProcess,
3444  NULL);
3445  if (!NT_SUCCESS(Status)) return Status;
3446 
3447  /* Check if got a target handle */
3448  if (TargetProcessHandle)
3449  {
3450  /* Now reference the output handle */
3453  PsProcessType,
3454  PreviousMode,
3455  (PVOID*)&TargetProcess,
3456  NULL);
3457  if (NT_SUCCESS(Status))
3458  {
3459  /* Use this target process */
3460  Target = TargetProcess;
3461  }
3462  else
3463  {
3464  /* No target process */
3465  Target = NULL;
3466  }
3467  }
3468  else
3469  {
3470  /* No target process */
3471  Status = STATUS_SUCCESS;
3472  Target = NULL;
3473  }
3474 
3475  /* Call the internal routine */
3476  Status = ObDuplicateObject(SourceProcess,
3477  SourceHandle,
3478  Target,
3479  &hTarget,
3480  DesiredAccess,
3482  Options,
3483  PreviousMode);
3484 
3485  /* Check if the caller wanted the return handle */
3486  if (TargetHandle)
3487  {
3488  /* Protect the write to user mode */
3489  _SEH2_TRY
3490  {
3491  /* Write the new handle */
3492  *TargetHandle = hTarget;
3493  }
3495  {
3496  /* Otherwise, get the exception code */
3497  Status = _SEH2_GetExceptionCode();
3498  }
3499  _SEH2_END;
3500  }
3501 
3502  /* Dereference the processes */
3504  "%s - Duplicated handle: %p into %p S %lx\n",
3505  __FUNCTION__,
3506  hTarget,
3508  Status);
3509  if (Target) ObDereferenceObject(Target);
3510  ObDereferenceObject(SourceProcess);
3511  return Status;
3512 }
DWORD *typedef PVOID
Definition: winlogon.h:61
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ HANDLE SourceHandle
Definition: obfuncs.h:429
enum OPTION_FLAGS Options
Definition: stats.c:44
_SEH2_TRY
Definition: create.c:4250
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define PROCESS_DUP_HANDLE
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
_In_ HANDLE _In_opt_ HANDLE TargetProcessHandle
Definition: obfuncs.h:429
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1067
#define OB_HANDLE_DEBUG
Definition: ob.h:17
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
_SEH2_END
Definition: create.c:4424
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
NTSTATUS NTAPI ObDuplicateObject(IN PEPROCESS SourceProcess, IN HANDLE SourceHandle, IN PEPROCESS TargetProcess OPTIONAL, IN PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options, IN KPROCESSOR_MODE PreviousMode)
Definition: obhandle.c:2201
#define __FUNCTION__
Definition: compiler.h:205
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2710
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE TargetHandle
Definition: obfuncs.h:429
POBJECT_TYPE PsProcessType
Definition: process.c:20
VOID NTAPI ObClearProcessHandleTable ( IN PEPROCESS  Process)

Definition at line 2024 of file obhandle.c.

Referenced by NtTerminateProcess(), and PspTerminateProcess().

2025 {
2029  BOOLEAN AttachedToProcess = FALSE;
2030 
2031  ASSERT(Process);
2032 
2033  /* Ensure the handle table doesn't go away while we use it */
2034  HandleTable = ObReferenceProcessHandleTable(Process);
2035  if (!HandleTable) return;
2036 
2037  /* Attach to the current process if needed */
2038  if (PsGetCurrentProcess() != Process)
2039  {
2040  KeStackAttachProcess(&Process->Pcb, &ApcState);
2041  AttachedToProcess = TRUE;
2042  }
2043 
2044  /* Enter a critical region */
2046 
2047  /* Fill out the context */
2048  Context.AccessMode = UserMode;
2049  Context.HandleTable = HandleTable;
2050 
2051  /* Sweep the handle table to close all handles */
2052  ExSweepHandleTable(HandleTable,
2054  &Context);
2055 
2056  /* Leave the critical region */
2058 
2059  /* Detach if needed */
2060  if (AttachedToProcess)
2061  KeUnstackDetachProcess(&ApcState);
2062 
2063  /* Let the handle table go */
2065 }
PHANDLE_TABLE NTAPI ObReferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:29
#define TRUE
Definition: types.h:120
KAPC_STATE
Definition: ketypes.h:1273
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
PHANDLE_TABLE HandleTable
Definition: ob.h:107
#define FALSE
Definition: types.h:117
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
VOID NTAPI ExSweepHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_SWEEP_HANDLE_CALLBACK EnumHandleProcedure, IN PVOID Context)
Definition: handle.c:1196
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
struct tagContext Context
Definition: acpixf.h:1014
BOOLEAN NTAPI ObpCloseHandleCallback(IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN HANDLE Handle, IN PVOID Context)
Definition: obhandle.c:1921
VOID NTAPI ObDereferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:51
KPROCESSOR_MODE AccessMode
Definition: ob.h:108
NTSTATUS NTAPI ObCloseHandle ( IN HANDLE  Handle,
IN KPROCESSOR_MODE  AccessMode 
)

Definition at line 3370 of file obhandle.c.

Referenced by _IRQL_requires_max_(), CheckDirectorySecurity__(), CheckKeySecurity__(), CmpAddToHiveFileList(), CmpLinkKeyToHive(), CmpRemoveFromHiveFileList(), DbgkCreateThread(), DbgkMapViewOfSection(), DbgkpFreeDebugEvent(), DbgkpOpenHandles(), DbgkpPostFakeModuleMessages(), DbgkpPostFakeThreadMessages(), DisplayBootBitmap(), ExitThreadCallback(), ExpCreateSystemRootLink(), ExpCreateWorkerThread(), ExpInitializeWorkerThreads(), ExpInitNls(), InitThreadCallback(), IntCopyRegistryKey(), IntCreateDesktop(), IntCreateNewRegistryPath(), IntResolveDesktop(), IntSetupDeviceSettingsKey(), IoCreateController(), IoCreateDevice(), IoCreateStreamFileObjectEx(), IopDetectResourceConflict(), IopOpenLinkOrRenameTarget(), IopReassignSystemRoot(), IopStoreSystemPartitionInformation(), KernelModeTest(), KmtStartThread(), LpcpCreatePort(), MmCreatePhysicalMemorySection(), NotificationCallback(), NtSecureConnectPort(), NtSetDefaultLocale(), NtSetInformationFile(), NtUserCloseDesktop(), NtUserCloseWindowStation(), NtUserResolveDesktop(), PnpRootCreateDevice(), PspCreateProcess(), PspCreateThread(), PspExitThread(), PspInitPhase0(), RawInputThreadMain(), RunTest(), SepRmCommandServerThread(), SepRmCommandServerThreadInit(), SeRmInitPhase1(), START_TEST(), TestAllInformation(), TestConnect(), TestCreateNamedPipe(), TestDuplicate(), TestIoCreateFile(), TestObRootSecurity(), TestPhysicalMemorySection(), TestReadWrite(), TestRelativeNames(), TestSharedCacheMap(), UserModeTest(), UserSetProcessWindowStation(), and xHalIoAssignDriveLetters().

3372 {
3373  /* Call the internal API */
3374  return ObpCloseHandle(Handle, AccessMode);
3375 }
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
NTSTATUS NTAPI ObpCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:1727
_In_ HANDLE Handle
Definition: extypes.h:390
VOID NTAPI ObDereferenceProcessHandleTable ( IN PEPROCESS  Process)

Definition at line 51 of file obhandle.c.

Referenced by ObClearProcessHandleTable(), ObDuplicateObject(), ObFindHandleForObject(), ObGetProcessHandleCount(), and ObInitProcess().

52 {
53  /* Release the process lock */
54  ExReleaseRundownProtection(&Process->RundownProtect);
55 }
NTKERNELAPI VOID FASTCALL ExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RunRef)
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
NTSTATUS NTAPI ObDuplicateObject ( IN PEPROCESS  SourceProcess,
IN HANDLE  SourceHandle,
IN PEPROCESS TargetProcess  OPTIONAL,
IN PHANDLE TargetHandle  OPTIONAL,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  HandleAttributes,
IN ULONG  Options,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 2201 of file obhandle.c.

Referenced by DbgkpOpenHandles(), and NtDuplicateObject().

2209 {
2210  HANDLE_TABLE_ENTRY NewHandleEntry;
2211  BOOLEAN AttachedToProcess = FALSE;
2212  PVOID SourceObject;
2213  POBJECT_HEADER ObjectHeader;
2215  HANDLE NewHandle;
2217  NTSTATUS Status;
2218  ACCESS_MASK TargetAccess, SourceAccess;
2221  AUX_ACCESS_DATA AuxData;
2224  ULONG AuditMask;
2226 
2227  PAGED_CODE();
2229  "%s - Duplicating handle: %p for %p into %p\n",
2230  __FUNCTION__,
2231  SourceHandle,
2232  SourceProcess,
2233  TargetProcess);
2234 
2235  /* Assume failure */
2236  if (TargetHandle) *TargetHandle = NULL;
2237 
2238  /* Check if we're not duplicating the same access */
2239  if (!(Options & DUPLICATE_SAME_ACCESS))
2240  {
2241  /* Validate the desired access */
2242  Status = STATUS_SUCCESS; //ObpValidateDesiredAccess(DesiredAccess);
2243  if (!NT_SUCCESS(Status)) return Status;
2244  }
2245 
2246  /* Reference the object table */
2247  HandleTable = ObReferenceProcessHandleTable(SourceProcess);
2248  if (!HandleTable) return STATUS_PROCESS_IS_TERMINATING;
2249 
2250  /* Reference the process object */
2252  SourceProcess,
2253  HandleTable,
2254  PreviousMode,
2255  &SourceObject,
2256  &HandleInformation,
2257  &AuditMask);
2258  if (!NT_SUCCESS(Status))
2259  {
2260  /* Fail */
2261  ObDereferenceProcessHandleTable(SourceProcess);
2262  return Status;
2263  }
2264  else
2265  {
2266  /* Check if we have to don't have to audit object close */
2267  if (!(HandleInformation.HandleAttributes & OBJ_AUDIT_OBJECT_CLOSE))
2268  {
2269  /* Then there is no audit mask */
2270  AuditMask = 0;
2271  }
2272  }
2273 
2274  /* Check if there's no target process */
2275  if (!TargetProcess)
2276  {
2277  /* Check if the caller wanted actual duplication */
2279  {
2280  /* Invalid request */
2281  Status = STATUS_INVALID_PARAMETER;
2282  }
2283  else
2284  {
2285  /* Otherwise, do the attach */
2286  KeStackAttachProcess(&SourceProcess->Pcb, &ApcState);
2287 
2288  /* Close the handle and detach */
2290  KeUnstackDetachProcess(&ApcState);
2291  }
2292 
2293  /* Return */
2294  ObDereferenceProcessHandleTable(SourceProcess);
2295  ObDereferenceObject(SourceObject);
2296  return Status;
2297  }
2298 
2299  /* Create a kernel handle if asked, but only in the system process */
2300  if (PreviousMode == KernelMode &&
2302  TargetProcess == PsInitialSystemProcess)
2303  {
2304  KernelHandle = TRUE;
2305  }
2306 
2307  /* Get the target handle table */
2308  HandleTable = ObReferenceProcessHandleTable(TargetProcess);
2309  if (!HandleTable)
2310  {
2311  /* Check if the caller wanted us to close the handle */
2313  {
2314  /* Do the attach */
2315  KeStackAttachProcess(&SourceProcess->Pcb, &ApcState);
2316 
2317  /* Close the handle and detach */
2319  KeUnstackDetachProcess(&ApcState);
2320  }
2321 
2322  /* Return */
2323  ObDereferenceProcessHandleTable(SourceProcess);
2324  ObDereferenceObject(SourceObject);
2326  }
2327 
2328  /* Get the source access */
2329  SourceAccess = HandleInformation.GrantedAccess;
2330 
2331  /* Check if we're not in the target process */
2332  if (TargetProcess != PsGetCurrentProcess())
2333  {
2334  /* Attach to it */
2335  KeStackAttachProcess(&TargetProcess->Pcb, &ApcState);
2336  AttachedToProcess = TRUE;
2337  }
2338 
2339  /* Check if we're duplicating the attributes */
2341  {
2342  /* Duplicate them */
2343  HandleAttributes = HandleInformation.HandleAttributes;
2344  }
2345  else
2346  {
2347  /* Don't allow caller to bypass auditing */
2348  HandleAttributes |= HandleInformation.HandleAttributes &
2350  }
2351 
2352  /* Check if we're duplicating the access */
2353  if (Options & DUPLICATE_SAME_ACCESS) DesiredAccess = SourceAccess;
2354 
2355  /* Get object data */
2356  ObjectHeader = OBJECT_TO_OBJECT_HEADER(SourceObject);
2357  ObjectType = ObjectHeader->Type;
2358 
2359  /* Fill out the entry */
2360  RtlZeroMemory(&NewHandleEntry, sizeof(HANDLE_TABLE_ENTRY));
2361  NewHandleEntry.Object = ObjectHeader;
2362  NewHandleEntry.ObAttributes |= (HandleAttributes & OBJ_HANDLE_ATTRIBUTES);
2363 
2364  /* Check if we're using a generic mask */
2366  {
2367  /* Map it */
2369  &ObjectType->TypeInfo.GenericMapping);
2370  }
2371 
2372  /* Set the target access, always propagate ACCESS_SYSTEM_SECURITY */
2373  TargetAccess = DesiredAccess & (ObjectType->TypeInfo.ValidAccessMask |
2375  NewHandleEntry.GrantedAccess = TargetAccess;
2376 
2377  /* Check if we're asking for new access */
2378  if (TargetAccess & ~SourceAccess)
2379  {
2380  /* We are. We need the security procedure to validate this */
2382  {
2383  /* Use our built-in access state */
2384  PassedAccessState = &AccessState;
2385  Status = SeCreateAccessState(&AccessState,
2386  &AuxData,
2387  TargetAccess,
2388  &ObjectType->TypeInfo.GenericMapping);
2389  }
2390  else
2391  {
2392  /* Otherwise we can't allow this privilege elevation */
2393  Status = STATUS_ACCESS_DENIED;
2394  }
2395  }
2396  else
2397  {
2398  /* We don't need an access state */
2399  Status = STATUS_SUCCESS;
2400  }
2401 
2402  /* Make sure the access state was created OK */
2403  if (NT_SUCCESS(Status))
2404  {
2405  /* Add a new handle */
2406  Status = ObpIncrementHandleCount(SourceObject,
2407  PassedAccessState,
2408  PreviousMode,
2412  }
2413 
2414  /* Check if we were attached */
2415  if (AttachedToProcess)
2416  {
2417  /* We can safely detach now */
2418  KeUnstackDetachProcess(&ApcState);
2419  AttachedToProcess = FALSE;
2420  }
2421 
2422  /* Check if we have to close the source handle */
2424  {
2425  /* Attach and close */
2426  KeStackAttachProcess(&SourceProcess->Pcb, &ApcState);
2428  KeUnstackDetachProcess(&ApcState);
2429  }
2430 
2431  /* Check if we had an access state */
2432  if (PassedAccessState) SeDeleteAccessState(PassedAccessState);
2433 
2434  /* Now check if incrementing actually failed */
2435  if (!NT_SUCCESS(Status))
2436  {
2437  /* Dereference handle tables */
2438  ObDereferenceProcessHandleTable(SourceProcess);
2439  ObDereferenceProcessHandleTable(TargetProcess);
2440 
2441  /* Dereference the source object */
2442  ObDereferenceObject(SourceObject);
2443  return Status;
2444  }
2445 
2446  /* Now create the handle */
2447  NewHandle = ExCreateHandle(HandleTable, &NewHandleEntry);
2448  if (!NewHandle)
2449  {
2450  /* Undo the increment */
2451  ObpDecrementHandleCount(SourceObject,
2452  TargetProcess,
2453  TargetAccess,
2454  ObjectType);
2455 
2456  /* Deference the object and set failure status */
2457  ObDereferenceObject(SourceObject);
2459  }
2460 
2461  /* Mark it as a kernel handle if requested */
2462  if (KernelHandle)
2463  {
2464  NewHandle = ObMarkHandleAsKernelHandle(NewHandle);
2465  }
2466 
2467  /* Return the handle */
2469 
2470  /* Dereference handle tables */
2471  ObDereferenceProcessHandleTable(SourceProcess);
2472  ObDereferenceProcessHandleTable(TargetProcess);
2473 
2474  /* Return status */
2476  "%s - Duplicated handle: %p for %p into %p. Source: %p HC PC %lx %lx\n",
2477  __FUNCTION__,
2478  NewHandle,
2479  SourceProcess,
2480  TargetProcess,
2481  SourceObject,
2482  ObjectHeader->PointerCount,
2483  ObjectHeader->HandleCount);
2484  return Status;
2485 }
DWORD *typedef PVOID
Definition: winlogon.h:61
ObjectType
Definition: metafile.c:80
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
#define DUPLICATE_CLOSE_SOURCE
PHANDLE_TABLE NTAPI ObReferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:29
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI SeCreateAccessState(IN OUT PACCESS_STATE AccessState, IN PAUX_ACCESS_DATA AuxData, IN ACCESS_MASK Access, IN PGENERIC_MAPPING GenericMapping)
Definition: access.c:439
KAPC_STATE
Definition: ketypes.h:1273
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG_PTR HandleCount
Definition: obtypes.h:490
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
HANDLE KernelHandle
Definition: legacy.c:24
ULONG_PTR ObAttributes
Definition: extypes.h:600
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _ACPI_EFI_FILE_HANDLE ** NewHandle
Definition: acefiex.h:335
#define GENERIC_ACCESS
Definition: wlx.c:26
_Inout_opt_ PACCESS_STATE PassedAccessState
Definition: obfuncs.h:71
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ HANDLE SourceHandle
Definition: obfuncs.h:429
enum OPTION_FLAGS Options
Definition: stats.c:44
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:791
#define OBJ_AUDIT_OBJECT_CLOSE
Definition: ob.h:51
#define DUPLICATE_SAME_ACCESS
ACCESS_MASK GrantedAccess
Definition: iotypes.h:158
#define FALSE
Definition: types.h:117
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
#define PsGetCurrentProcess
Definition: psfuncs.h:17
Definition: extypes.h:595
NTSTATUS NTAPI ObpIncrementHandleCount(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN ULONG HandleAttributes, IN PEPROCESS Process, IN OB_OPEN_REASON OpenReason)
Definition: obhandle.c:808
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI ObpDecrementHandleCount(IN PVOID ObjectBody, IN PEPROCESS Process, IN ACCESS_MASK GrantedAccess, IN POBJECT_TYPE ObjectType)
Definition: obhandle.c:527
unsigned char BOOLEAN
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define ObMarkHandleAsKernelHandle(Handle)
Definition: ob.h:75
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3393
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_PROCESS_IS_TERMINATING
Definition: ntstatus.h:488
ULONG GrantedAccess
Definition: extypes.h:606
static OB_SECURITY_METHOD SeDefaultObjectMethod
Definition: ObTypes.c:139
_In_ ACCESS_MASK _In_opt_ POBJECT_TYPE _In_ KPROCESSOR_MODE _Out_ PVOID _Out_opt_ POBJECT_HANDLE_INFORMATION HandleInformation
Definition: obfuncs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
NTSTATUS NTAPI ObpReferenceProcessObjectByHandle(IN HANDLE Handle, IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation, OUT PACCESS_MASK AuditMask)
Definition: obhandle.c:88
#define OB_HANDLE_DEBUG
Definition: ob.h:17
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
OB_SECURITY_METHOD SecurityProcedure
Definition: obtypes.h:371
#define DUPLICATE_SAME_ATTRIBUTES
Definition: obtypes.h:153
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
VOID NTAPI SeDeleteAccessState(IN PACCESS_STATE AccessState)
Definition: access.c:460
LONG_PTR PointerCount
Definition: obtypes.h:487
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PVOID Object
Definition: extypes.h:599
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
#define OBJ_HANDLE_ATTRIBUTES
Definition: ob.h:52
return STATUS_SUCCESS
Definition: btrfs.c:2710
VOID NTAPI ObDereferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:51
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE TargetHandle
Definition: obfuncs.h:429
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlMapGenericMask(PACCESS_MASK AccessMask, PGENERIC_MAPPING GenericMapping)
BOOLEAN NTAPI ObFindHandleForObject ( IN PEPROCESS  Process,
IN PVOID  Object,
IN POBJECT_TYPE  ObjectType,
IN POBJECT_HANDLE_INFORMATION  HandleInformation,
OUT PHANDLE  Handle 
)

Definition at line 2847 of file obhandle.c.

Referenced by IntGetDesktopObjectHandle(), and IntResolveDesktop().

2852 {
2853  OBP_FIND_HANDLE_DATA FindData;
2854  BOOLEAN Result = FALSE;
2855  PVOID ObjectTable;
2856 
2857  /* Make sure we have an object table */
2858  ObjectTable = ObReferenceProcessHandleTable(Process);
2859  if (ObjectTable)
2860  {
2861  /* Check if we have an object */
2862  if (Object)
2863  {
2864  /* Set its header */
2866  }
2867  else
2868  {
2869  /* Otherwise, no object to match*/
2870  FindData.ObjectHeader = NULL;
2871  }
2872 
2873  /* Set other information */
2874  FindData.ObjectType = ObjectType;
2876 
2877  /* Enumerate the handle table */
2878  if (ExEnumHandleTable(Process->ObjectTable,
2880  &FindData,
2881  Handle))
2882  {
2883  /* Set success */
2884  Result = TRUE;
2885  }
2886 
2887  /* Let go of the table */
2889  }
2890 
2891  /* Return the result */
2892  return Result;
2893 }
DWORD *typedef PVOID
Definition: winlogon.h:61
POBJECT_HEADER ObjectHeader
Definition: ob.h:113
ObjectType
Definition: metafile.c:80
PHANDLE_TABLE NTAPI ObReferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:29
#define TRUE
Definition: types.h:120
POBJECT_TYPE ObjectType
Definition: ob.h:114
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
POBJECT_HANDLE_INFORMATION HandleInformation
Definition: ob.h:115
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned char BOOLEAN
BOOLEAN NTAPI ObpEnumFindHandleProcedure(IN PHANDLE_TABLE_ENTRY HandleEntry, IN HANDLE Handle, IN PVOID Context)
Definition: obhandle.c:214
_In_ ACCESS_MASK _In_opt_ POBJECT_TYPE _In_ KPROCESSOR_MODE _Out_ PVOID _Out_opt_ POBJECT_HANDLE_INFORMATION HandleInformation
Definition: obfuncs.h:40
static IUnknown Object
Definition: main.c:512
BOOLEAN NTAPI ExEnumHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure, IN OUT PVOID Context, OUT PHANDLE EnumHandle OPTIONAL)
Definition: handle.c:1235
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
VOID NTAPI ObDereferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:51
ULONG NTAPI ObGetProcessHandleCount ( IN PEPROCESS  Process)

Definition at line 59 of file obhandle.c.

Referenced by NtQueryInformationProcess(), and QSI_DEF().

60 {
61  ULONG HandleCount;
63 
64  ASSERT(Process);
65 
66  /* Ensure the handle table doesn't go away while we use it */
68 
69  if (HandleTable != NULL)
70  {
71  /* Count the number of handles the process has */
72  HandleCount = HandleTable->HandleCount;
73 
74  /* Let the handle table go */
76  }
77  else
78  {
79  /* No handle table, no handles */
80  HandleCount = 0;
81  }
82 
83  return HandleCount;
84 }
PHANDLE_TABLE NTAPI ObReferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:29
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
smooth NULL
Definition: ftsmooth.c:416
LONG HandleCount
Definition: extypes.h:644
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ObDereferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:51
NTSTATUS NTAPI ObInitProcess ( IN PEPROCESS Parent  OPTIONAL,
IN PEPROCESS  Process 
)

Definition at line 2087 of file obhandle.c.

Referenced by PspCreateProcess().

2089 {
2090  PHANDLE_TABLE ParentTable, ObjectTable;
2091 
2092  /* Check for a parent */
2093  if (Parent)
2094  {
2095  /* Reference the parent's table */
2096  ParentTable = ObReferenceProcessHandleTable(Parent);
2097  if (!ParentTable) return STATUS_PROCESS_IS_TERMINATING;
2098 
2099  /* Duplicate it */
2100  ObjectTable = ExDupHandleTable(Process,
2101  ParentTable,
2103  OBJ_INHERIT);
2104  }
2105  else
2106  {
2107  /* Otherwise just create a new table */
2108  ParentTable = NULL;
2109  ObjectTable = ExCreateHandleTable(Process);
2110  }
2111 
2112  /* Make sure we have a table */
2113  if (ObjectTable)
2114  {
2115  /* Associate it */
2116  Process->ObjectTable = ObjectTable;
2117 
2118  /* Check for auditing */
2120  {
2121  /* FIXME: TODO */
2122  DPRINT1("Need auditing!\n");
2123  }
2124 
2125  /* Get rid of the old table now */
2126  if (ParentTable) ObDereferenceProcessHandleTable(Parent);
2127 
2128  /* We are done */
2129  return STATUS_SUCCESS;
2130  }
2131  else
2132  {
2133  /* Fail */
2134  Process->ObjectTable = NULL;
2135  if (ParentTable) ObDereferenceProcessHandleTable(Parent);
2137  }
2138 }
PHANDLE_TABLE NTAPI ObReferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:29
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:718
smooth NULL
Definition: ftsmooth.c:416
PHANDLE_TABLE NTAPI ExDupHandleTable(IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN PEX_DUPLICATE_HANDLE_CALLBACK DupHandleProcedure, IN ULONG_PTR Mask)
Definition: handle.c:1036
#define OBJ_INHERIT
Definition: winternl.h:225
#define STATUS_PROCESS_IS_TERMINATING
Definition: ntstatus.h:488
PHANDLE_TABLE NTAPI ExCreateHandleTable(IN PEPROCESS Process OPTIONAL)
Definition: handle.c:765
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOLEAN NTAPI ObpDuplicateHandleCallback(IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY OldEntry, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: obhandle.c:1957
BOOLEAN NTAPI SeDetailedAuditingWithToken(IN PTOKEN Token)
Definition: audit.c:25
return STATUS_SUCCESS
Definition: btrfs.c:2710
VOID NTAPI ObDereferenceProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:51
NTSTATUS NTAPI ObInsertObject ( IN PVOID  Object,
IN PACCESS_STATE AccessState  OPTIONAL,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  ObjectPointerBias,
OUT PVOID *NewObject  OPTIONAL,
OUT PHANDLE  Handle 
)

Definition at line 2926 of file obhandle.c.

Referenced by _IRQL_requires_max_(), CmpCreateRegistryRoot(), CreateClientPort(), ExCreateCallback(), HalpDmaAllocateChildAdapter(), IntCreateWindowStation(), IoCreateController(), IoCreateDevice(), IoCreateStreamFileObjectEx(), IopCreateDriver(), LpcpCreatePort(), MmCreatePhysicalMemorySection(), NtCreateDebugObject(), NtCreateDirectoryObject(), NtCreateEvent(), NtCreateEventPair(), NtCreateIoCompletion(), NtCreateJobObject(), NtCreateMutant(), NtCreateProfile(), NtCreateSection(), NtCreateSemaphore(), NtCreateSymbolicLinkObject(), NtCreateTimer(), NtDuplicateToken(), NtOpenThreadTokenEx(), NtSecureConnectPort(), ObtCreateObjects(), PspCreateProcess(), PspCreateThread(), SepCreateToken(), SepInitializationPhase1(), and SeSubProcessToken().

2932 {
2933  POBJECT_CREATE_INFORMATION ObjectCreateInfo;
2934  POBJECT_HEADER ObjectHeader;
2937  PVOID InsertObject;
2938  PSECURITY_DESCRIPTOR ParentDescriptor = NULL;
2939  BOOLEAN SdAllocated = FALSE;
2940  POBJECT_HEADER_NAME_INFO ObjectNameInfo;
2942  ACCESS_STATE LocalAccessState;
2943  AUX_ACCESS_DATA AuxData;
2944  OB_OPEN_REASON OpenReason;
2946  NTSTATUS Status = STATUS_SUCCESS, RealStatus;
2947  BOOLEAN IsNewObject;
2948  PAGED_CODE();
2949 
2950  /* Get the Header */
2951  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
2952 
2953  /* Detect invalid insert */
2954  if (!(ObjectHeader->Flags & OB_FLAG_CREATE_INFO))
2955  {
2956  /* Display warning and break into debugger */
2957  DPRINT1("OB: Attempting to insert existing object %p\n", Object);
2958  DbgBreakPoint();
2959 
2960  /* Allow debugger to continue */
2962  return STATUS_INVALID_PARAMETER;
2963  }
2964 
2965  /* Get the create and name info, as well as the object type */
2966  ObjectCreateInfo = ObjectHeader->ObjectCreateInfo;
2967  ObjectNameInfo = ObpReferenceNameInfo(ObjectHeader);
2968  ObjectType = ObjectHeader->Type;
2969  ObjectName = NULL;
2970 
2971  /* Check if this is an named object */
2972  if ((ObjectNameInfo) && (ObjectNameInfo->Name.Buffer))
2973  {
2974  /* Get the object name */
2975  ObjectName = &ObjectNameInfo->Name;
2976  }
2977 
2978  /* Sanity check */
2979  ASSERT((Handle) ||
2980  ((ObjectPointerBias == 0) &&
2981  (ObjectName == NULL) &&
2982  (ObjectType->TypeInfo.SecurityRequired) &&
2983  (NewObject == NULL)));
2984 
2985  /* Check if the object is unnamed and also doesn't have security */
2986  PreviousMode = KeGetPreviousMode();
2987  if (!(ObjectType->TypeInfo.SecurityRequired) && !(ObjectName))
2988  {
2989  /* Assume failure */
2990  *Handle = NULL;
2991  ObjectHeader->ObjectCreateInfo = NULL;
2992 
2993  /* Create the handle */
2994  Status = ObpCreateUnnamedHandle(Object,
2995  DesiredAccess,
2996  ObjectPointerBias + 1,
2997  ObjectCreateInfo->Attributes,
2998  PreviousMode,
2999  NewObject,
3000  Handle);
3001 
3002  /* Free the create information */
3003  ObpFreeObjectCreateInformation(ObjectCreateInfo);
3004 
3005  /* Release the object name information */
3006  ObpDereferenceNameInfo(ObjectNameInfo);
3007 
3008  /* Remove the extra keep-alive reference */
3010 
3011  /* Return */
3013  "%s - returning Object with PC S: %lx %lx\n",
3014  __FUNCTION__,
3015  ObjectHeader->PointerCount,
3016  Status);
3017  return Status;
3018  }
3019 
3020  /* Check if we didn't get an access state */
3021  if (!AccessState)
3022  {
3023  /* Use our built-in access state */
3024  AccessState = &LocalAccessState;
3025  Status = SeCreateAccessState(&LocalAccessState,
3026  &AuxData,
3027  DesiredAccess,
3028  &ObjectType->TypeInfo.GenericMapping);
3029  if (!NT_SUCCESS(Status))
3030  {
3031  /* Fail */
3032  ObpDereferenceNameInfo(ObjectNameInfo);
3034  return Status;
3035  }
3036  }
3037 
3038  /* Save the security descriptor */
3039  AccessState->SecurityDescriptor = ObjectCreateInfo->SecurityDescriptor;
3040 
3041  /* Validate the access mask */
3043  if (!NT_SUCCESS(Status))
3044  {
3045  /* Fail */
3046  ObpDereferenceNameInfo(ObjectNameInfo);
3048  return Status;
3049  }
3050 
3051  /* Setup a lookup context */
3052  ObpInitializeLookupContext(&Context);
3053  InsertObject = Object;
3054  OpenReason = ObCreateHandle;
3055 
3056  /* Check if the object is named */
3057  if (ObjectName)
3058  {
3059  /* Look it up */
3060  Status = ObpLookupObjectName(ObjectCreateInfo->RootDirectory,
3061  ObjectName,
3062  ObjectCreateInfo->Attributes,
3063  ObjectType,
3064  (ObjectHeader->Flags & OB_FLAG_KERNEL_MODE) ?
3065  KernelMode : UserMode,
3066  ObjectCreateInfo->ParseContext,
3067  ObjectCreateInfo->SecurityQos,
3068  Object,
3069  AccessState,
3070  &Context,
3071  &InsertObject);
3072 
3073  /* Check if we found an object that doesn't match the one requested */
3074  if ((NT_SUCCESS(Status)) && (InsertObject) && (Object != InsertObject))
3075  {
3076  /* This means we're opening an object, not creating a new one */
3077  OpenReason = ObOpenHandle;
3078 
3079  /* Make sure the caller said it's OK to do this */
3080  if (ObjectCreateInfo->Attributes & OBJ_OPENIF)
3081  {
3082  /* He did, but did he want this type? */
3083  if (ObjectType != OBJECT_TO_OBJECT_HEADER(InsertObject)->Type)
3084  {
3085  /* Wrong type, so fail */
3086  Status = STATUS_OBJECT_TYPE_MISMATCH;
3087  }
3088  else
3089  {
3090  /* Right type, so warn */
3091  Status = STATUS_OBJECT_NAME_EXISTS;
3092  }
3093  }
3094  else
3095  {
3096  /* Check if this was a symbolic link */
3097  if (OBJECT_TO_OBJECT_HEADER(InsertObject)->Type ==
3099  {
3100  /* Dereference it */
3101  ObDereferenceObject(InsertObject);
3102  }
3103 
3104  /* Caller wanted to create a new object, fail */
3106  }
3107  }
3108 
3109  /* Check if anything until now failed */
3110  if (!NT_SUCCESS(Status))
3111  {
3112  /* Cleanup after lookup */
3113  ObpReleaseLookupContext(&Context);
3114 
3115  /* Remove query reference that we added */
3116  ObpDereferenceNameInfo(ObjectNameInfo);
3117 
3118  /* Dereference the object and delete the access state */
3120  if (AccessState == &LocalAccessState)
3121  {
3122  /* We used a local one; delete it */
3124  }
3125 
3126  /* Return failure code */
3127  return Status;
3128  }
3129  else
3130  {
3131  /* Check if this is a symbolic link */
3132  if (ObjectType == ObpSymbolicLinkObjectType)
3133  {
3134  /* Create the internal name */
3136  }
3137  }
3138  }
3139 
3140  /* Now check if this object is being created */
3141  if (InsertObject == Object)
3142  {
3143  /* Check if it's named or forces security */
3144  if ((ObjectName) || (ObjectType->TypeInfo.SecurityRequired))
3145  {
3146  /* Make sure it's inserted into an object directory */
3147  if ((ObjectNameInfo) && (ObjectNameInfo->Directory))
3148  {
3149  /* Get the current descriptor */
3150  ObGetObjectSecurity(ObjectNameInfo->Directory,
3151  &ParentDescriptor,
3152  &SdAllocated);
3153  }
3154 
3155  /* Now assign it */
3156  Status = ObAssignSecurity(AccessState,
3157  ParentDescriptor,
3158  Object,
3159  ObjectType);
3160 
3161  /* Check if we captured one */
3162  if (ParentDescriptor)
3163  {
3164  /* We did, release it */
3165  ObReleaseObjectSecurity(ParentDescriptor, SdAllocated);
3166  }
3167  else if (NT_SUCCESS(Status))
3168  {
3169  /* Other we didn't, but we were able to use the current SD */
3171  ObjectCreateInfo->ProbeMode,
3172  TRUE);
3173 
3174  /* Clear the current one */
3175  AccessState->SecurityDescriptor =
3176  ObjectCreateInfo->SecurityDescriptor = NULL;
3177  }
3178  }
3179 
3180  /* Check if anything until now failed */
3181  if (!NT_SUCCESS(Status))
3182  {
3183  /* Check if the directory was added */
3184  if (Context.DirectoryLocked)
3185  {
3186  /* Weird case where we need to do a manual delete */
3187  DPRINT1("Unhandled path\n");
3188  ASSERT(FALSE);
3189  }
3190 
3191  /* Cleanup the lookup */
3192  ObpReleaseLookupContext(&Context);
3193 
3194  /* Remove query reference that we added */
3195  ObpDereferenceNameInfo(ObjectNameInfo);
3196 
3197  /* Dereference the object and delete the access state */
3199  if (AccessState == &LocalAccessState)
3200  {
3201  /* We used a local one; delete it */
3203  }
3204 
3205  /* Return failure code */
3206  ASSERT(FALSE);
3207  return Status;
3208  }
3209  }
3210 
3211  /* Save the actual status until here */
3212  RealStatus = Status;
3213 
3214  /* Check if caller wants us to create a handle */
3215  ObjectHeader->ObjectCreateInfo = NULL;
3216  if (Handle)
3217  {
3218  /* Create the handle */
3219  Status = ObpCreateHandle(OpenReason,
3220  InsertObject,
3221  NULL,
3222  AccessState,
3223  ObjectPointerBias + 1,
3224  ObjectCreateInfo->Attributes,
3225  &Context,
3226  PreviousMode,
3227  NewObject,
3228  Handle);
3229  if (!NT_SUCCESS(Status))
3230  {
3231  /* If the object had a name, backout everything */
3232  if (ObjectName) ObpDeleteNameCheck(Object);
3233 
3234  /* Return the status of the failure */
3235  *Handle = NULL;
3236  RealStatus = Status;
3237  }
3238 
3239  /* Remove a query reference */
3240  ObpDereferenceNameInfo(ObjectNameInfo);
3241 
3242  /* Remove the extra keep-alive reference */
3244  }
3245  else
3246  {
3247  /* Otherwise, lock the object */
3248  ObpAcquireObjectLock(ObjectHeader);
3249 
3250  /* And charge quota for the process to make it appear as used */
3251  RealStatus = ObpChargeQuotaForObject(ObjectHeader,
3252  ObjectType,
3253  &IsNewObject);
3254 
3255  /* Release the lock */
3256  ObpReleaseObjectLock(ObjectHeader);
3257 
3258  /* Check if we failed and dereference the object if so */
3259  if (!NT_SUCCESS(RealStatus)) ObDereferenceObject(Object);
3260  }
3261 
3262  /* We can delete the Create Info now */
3263  ObpFreeObjectCreateInformation(ObjectCreateInfo);
3264 
3265  /* Check if we created our own access state and delete it if so */
3266  if (AccessState == &LocalAccessState) SeDeleteAccessState(AccessState);
3267 
3268  /* Return status code */
3270  "%s - returning Object with PC RS/S: %lx %lx %lx\n",
3271  __FUNCTION__,
3272  OBJECT_TO_OBJECT_HEADER(Object)->PointerCount,
3273  RealStatus, Status);
3274  return RealStatus;
3275 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
POBJECT_DIRECTORY Directory
Definition: obtypes.h:432
ObjectType
Definition: metafile.c:80
NTSTATUS NTAPI ObAssignSecurity(IN PACCESS_STATE AccessState, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN PVOID Object, IN POBJECT_TYPE Type)
Definition: obsecure.c:550
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI SeCreateAccessState(IN OUT PACCESS_STATE AccessState, IN PAUX_ACCESS_DATA AuxData, IN ACCESS_MASK Access, IN PGENERIC_MAPPING GenericMapping)
Definition: access.c:439
FORCEINLINE VOID ObpAcquireObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:48
Type
Definition: Type.h:6
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI ObpChargeQuotaForObject(IN POBJECT_HEADER ObjectHeader, IN POBJECT_TYPE ObjectType, OUT PBOOLEAN NewObject)
Definition: obhandle.c:434
FORCEINLINE VOID ObpReleaseObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:84
#define KeGetPreviousMode()
Definition: ketypes.h:1081
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
UNICODE_STRING Name
Definition: obtypes.h:433
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
void DbgBreakPoint()
Definition: mach.c:558
NTSTATUS NTAPI ObpCreateHandle(IN OB_OPEN_REASON OpenReason, IN PVOID Object, IN POBJECT_TYPE Type OPTIONAL, IN PACCESS_STATE AccessState, IN ULONG AdditionalReferences, IN ULONG HandleAttributes, IN POBP_LOOKUP_CONTEXT Context, IN KPROCESSOR_MODE AccessMode, OUT PVOID *ReturnedObject, OUT PHANDLE ReturnedHandle)
Definition: obhandle.c:1494
#define PAGED_CODE()
Definition: video.h:57
KPROCESSOR_MODE ProbeMode
Definition: obtypes.h:340
NTSTATUS NTAPI SeReleaseSecurityDescriptor(IN PSECURITY_DESCRIPTOR CapturedSecurityDescriptor, IN KPROCESSOR_MODE CurrentMode, IN BOOLEAN CaptureIfKernelMode)
Definition: sd.c:766
BOOLEAN DirectoryLocked
Definition: obtypes.h:516
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define OBJ_OPENIF
Definition: winternl.h:229
#define FALSE
Definition: types.h:117
VOID NTAPI ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN MemoryAllocated)
Definition: obsecure.c:709
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID ObpFreeObjectCreateInformation(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
Definition: ob_x.h:392
PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: obtypes.h:344
UCHAR Flags
Definition: obtypes.h:497
NTSTATUS NTAPI ObGetObjectSecurity(IN PVOID Object, OUT PSECURITY_DESCRIPTOR *SecurityDescriptor, OUT PBOOLEAN MemoryAllocated)
Definition: obsecure.c:611
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned char BOOLEAN
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:259
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ObpCreateUnnamedHandle(IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN ULONG AdditionalReferences, IN ULONG HandleAttributes, IN KPROCESSOR_MODE AccessMode, OUT PVOID *ReturnedObject, OUT PHANDLE ReturnedHandle)
Definition: obhandle.c:1309
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI ObpValidateAccessMask(IN PACCESS_STATE AccessState)
Definition: obhandle.c:485
FORCEINLINE POBJECT_HEADER_NAME_INFO ObpReferenceNameInfo(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:102
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
static IUnknown Object
Definition: main.c:512
VOID NTAPI ObpCreateSymbolicLinkName(IN POBJECT_SYMBOLIC_LINK SymbolicLink)
Definition: oblink.c:184
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
#define OB_FLAG_CREATE_INFO
Definition: obtypes.h:97
PSECURITY_QUALITY_OF_SERVICE SecurityQos
Definition: obtypes.h:345
#define OB_HANDLE_DEBUG
Definition: ob.h:17
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
#define OB_FLAG_KERNEL_MODE
Definition: obtypes.h:98
Status
Definition: gdiplustypes.h:24
enum _OB_OPEN_REASON OB_OPEN_REASON
FORCEINLINE VOID ObpReleaseLookupContext(IN POBP_LOOKUP_CONTEXT Context)
Definition: ob_x.h:255
#define ObpSymbolicLinkObjectType
Definition: ObTypes.c:124
FORCEINLINE VOID ObpInitializeLookupContext(IN POBP_LOOKUP_CONTEXT Context)
Definition: ob_x.h:221
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
VOID NTAPI SeDeleteAccessState(IN PACCESS_STATE AccessState)
Definition: access.c:460
LONG_PTR PointerCount
Definition: obtypes.h:487
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1014
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:71
return STATUS_SUCCESS
Definition: btrfs.c:2710
VOID NTAPI ObpDeleteNameCheck(IN PVOID Object)
Definition: obname.c:261
FORCEINLINE VOID ObpDereferenceNameInfo(IN POBJECT_HEADER_NAME_INFO HeaderNameInfo)
Definition: ob_x.h:143
POBJECT_CREATE_INFORMATION ObjectCreateInfo
Definition: obtypes.h:500
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG ObjectPointerBias
Definition: obfuncs.h:71
NTSTATUS NTAPI ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL, IN OUT PUNICODE_STRING ObjectName, IN ULONG Attributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, IN PVOID InsertObject OPTIONAL, IN OUT PACCESS_STATE AccessState, OUT POBP_LOOKUP_CONTEXT LookupContext, OUT PVOID *FoundObject)
Definition: obname.c:358
BOOLEAN NTAPI ObIsKernelHandle ( IN HANDLE  Handle)

Definition at line 3516 of file obhandle.c.

3517 {
3518  /* Use the inlined version. We know we are in kernel mode. */
3520 }
#define ObpIsKernelHandle(Handle, ProcessorMode)
Definition: ob.h:64
_In_ HANDLE Handle
Definition: extypes.h:390
VOID NTAPI ObKillProcess ( IN PEPROCESS  Process)

Definition at line 2157 of file obhandle.c.

Referenced by PspDeleteProcess(), and PspExitThread().

2158 {
2161  BOOLEAN HardErrors;
2162  PAGED_CODE();
2163 
2164  /* Wait for process rundown and then complete it */
2165  ExWaitForRundownProtectionRelease(&Process->RundownProtect);
2166  ExRundownCompleted(&Process->RundownProtect);
2167 
2168  /* Get the object table */
2169  HandleTable = Process->ObjectTable;
2170  if (!HandleTable) return;
2171 
2172  /* Disable hard errors while we close handles */
2173  HardErrors = IoSetThreadHardErrorMode(FALSE);
2174 
2175  /* Enter a critical region */
2177 
2178  /* Fill out the context */
2179  Context.AccessMode = KernelMode;
2180  Context.HandleTable = HandleTable;
2181 
2182  /* Sweep the handle table to close all handles */
2183  ExSweepHandleTable(HandleTable,
2185  &Context);
2186  ASSERT(HandleTable->HandleCount == 0);
2187 
2188  /* Leave the critical region */
2190 
2191  /* Re-enable hard errors */
2192  IoSetThreadHardErrorMode(HardErrors);
2193 
2194  /* Destroy the object table */
2195  Process->ObjectTable = NULL;
2196  ExDestroyHandleTable(HandleTable, NULL);
2197 }
NTKERNELAPI VOID FASTCALL ExRundownCompleted(_Out_ PEX_RUNDOWN_REF RunRef)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID NTAPI ExDestroyHandleTable(IN PHANDLE_TABLE HandleTable, IN PVOID DestroyHandleProcedure OPTIONAL)
Definition: handle.c:927
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
#define PAGED_CODE()
Definition: video.h:57
PHANDLE_TABLE HandleTable
Definition: ob.h:107
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
NTKERNELAPI VOID FASTCALL ExWaitForRundownProtectionRelease(_Inout_ PEX_RUNDOWN_REF RunRef)
LONG HandleCount
Definition: extypes.h:644
unsigned char BOOLEAN
BOOLEAN NTAPI IoSetThreadHardErrorMode(IN BOOLEAN HardErrorEnabled)
Definition: error.c:707
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
VOID NTAPI ExSweepHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_SWEEP_HANDLE_CALLBACK EnumHandleProcedure, IN PVOID Context)
Definition: handle.c:1196
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
struct tagContext Context
Definition: acpixf.h:1014
BOOLEAN NTAPI ObpCloseHandleCallback(IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN HANDLE Handle, IN PVOID Context)
Definition: obhandle.c:1921
KPROCESSOR_MODE AccessMode
Definition: ob.h:108
NTSTATUS NTAPI ObOpenObjectByName ( IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN POBJECT_TYPE  ObjectType,
IN KPROCESSOR_MODE  AccessMode,
IN PACCESS_STATE  PassedAccessState,
IN ACCESS_MASK  DesiredAccess,
IN OUT PVOID  ParseContext,
OUT PHANDLE  Handle 
)

Definition at line 2523 of file obhandle.c.

Referenced by CmLoadKey(), CmpLinkHiveToMaster(), CreateGreenFdo(), ExCreateCallback(), GetObjectType(), IntCreateDesktop(), IntCreateWindowStation(), IntResolveDesktop(), IoFastQueryNetworkAttributes(), IopCreateFile(), IopQueryAttributesFile(), NtCreateKey(), NtDeleteFile(), NtOpenDirectoryObject(), NtOpenEvent(), NtOpenEventPair(), NtOpenIoCompletion(), NtOpenJobObject(), NtOpenKey(), NtOpenMutant(), NtOpenProcess(), NtOpenSection(), NtOpenSemaphore(), NtOpenSymbolicLinkObject(), NtOpenThread(), NtOpenTimer(), NtQueryOpenSubKeys(), NtUnloadKey2(), NtUserOpenDesktop(), NtUserOpenWindowStation(), ObtCreateObjectTypes(), and START_TEST().

2530 {
2531  PVOID Object = NULL;
2533  NTSTATUS Status, Status2;
2534  POBJECT_HEADER ObjectHeader;
2536  OB_OPEN_REASON OpenReason;
2537  POB_TEMP_BUFFER TempBuffer;
2538  PAGED_CODE();
2539 
2540  /* Assume failure */
2541  *Handle = NULL;
2542 
2543  /* Check if we didn't get any Object Attributes */
2544  if (!ObjectAttributes)
2545  {
2546  /* Fail with special status code */
2547  return STATUS_INVALID_PARAMETER;
2548  }
2549 
2550  /* Allocate the temporary buffer */
2551  TempBuffer = ExAllocatePoolWithTag(NonPagedPool,
2552  sizeof(OB_TEMP_BUFFER),
2554  if (!TempBuffer) return STATUS_INSUFFICIENT_RESOURCES;
2555 
2556  /* Capture all the info */
2558  AccessMode,
2559  AccessMode,
2560  TRUE,
2561  &TempBuffer->ObjectCreateInfo,
2562  &ObjectName);
2563  if (!NT_SUCCESS(Status))
2564  {
2565  /* Fail */
2567  return Status;
2568  }
2569 
2570  /* Check if we didn't get an access state */
2571  if (!PassedAccessState)
2572  {
2573  /* Try to get the generic mapping if we can */
2574  if (ObjectType) GenericMapping = &ObjectType->TypeInfo.GenericMapping;
2575 
2576  /* Use our built-in access state */
2577  PassedAccessState = &TempBuffer->LocalAccessState;
2578  Status = SeCreateAccessState(&TempBuffer->LocalAccessState,
2579  &TempBuffer->AuxData,
2580  DesiredAccess,
2581  GenericMapping);
2582  if (!NT_SUCCESS(Status)) goto Quickie;
2583  }
2584 
2585  /* Get the security descriptor */
2586  if (TempBuffer->ObjectCreateInfo.SecurityDescriptor)
2587  {
2588  /* Save it in the access state */
2591  }
2592 
2593  /* Validate the access mask */
2595  if (!NT_SUCCESS(Status))
2596  {
2597  /* Cleanup after lookup */
2598  ObpReleaseLookupContext(&TempBuffer->LookupContext);
2599  goto Cleanup;
2600  }
2601 
2602  /* Now do the lookup */
2603  Status = ObpLookupObjectName(TempBuffer->ObjectCreateInfo.RootDirectory,
2604  &ObjectName,
2605  TempBuffer->ObjectCreateInfo.Attributes,
2606  ObjectType,
2607  AccessMode,
2608  ParseContext,
2609  TempBuffer->ObjectCreateInfo.SecurityQos,
2610  NULL,
2612  &TempBuffer->LookupContext,
2613  &Object);
2614  if (!NT_SUCCESS(Status))
2615  {
2616  /* Cleanup after lookup */
2617  ObpReleaseLookupContext(&TempBuffer->LookupContext);
2618  goto Cleanup;
2619  }
2620 
2621  /* Check if this object has create information */
2622  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
2623  if (ObjectHeader->Flags & OB_FLAG_CREATE_INFO)
2624  {
2625  /* Then we are creating a new handle */
2626  OpenReason = ObCreateHandle;
2627 
2628  /* Check if we still have create info */
2629  if (ObjectHeader->ObjectCreateInfo)
2630  {
2631  /* Free it */
2632  ObpFreeObjectCreateInformation(ObjectHeader->
2633  ObjectCreateInfo);
2634  ObjectHeader->ObjectCreateInfo = NULL;
2635  }
2636  }
2637  else
2638  {
2639  /* Otherwise, we are merely opening it */
2640  OpenReason = ObOpenHandle;
2641  }
2642 
2643  /* Check if we have invalid object attributes */
2644  if (ObjectHeader->Type->TypeInfo.InvalidAttributes &
2645  TempBuffer->ObjectCreateInfo.Attributes)
2646  {
2647  /* Set failure code */
2648  Status = STATUS_INVALID_PARAMETER;
2649 
2650  /* Cleanup after lookup */
2651  ObpReleaseLookupContext(&TempBuffer->LookupContext);
2652 
2653  /* Dereference the object */
2654  ObDereferenceObject(Object);
2655  }
2656  else
2657  {
2658  /* Create the actual handle now */
2659  Status2 = ObpCreateHandle(OpenReason,
2660  Object,
2661  ObjectType,
2663  0,
2664  TempBuffer->ObjectCreateInfo.Attributes,
2665  &TempBuffer->LookupContext,
2666  AccessMode,
2667  NULL,
2668  Handle);
2669  if (!NT_SUCCESS(Status2))
2670  {
2671  ObDereferenceObject(Object);
2672  Status = Status2;
2673  }
2674  }
2675 
2676 Cleanup:
2677  /* Delete the access state */
2678  if (PassedAccessState == &TempBuffer->LocalAccessState)
2679  {
2681  }
2682 
2683 Quickie:
2684  /* Release the object attributes and temporary buffer */
2686  if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName);
2688 
2689  /* Return status */
2691  "%s - returning Object %p with PC S: %lx %lx\n",
2692  __FUNCTION__,
2693  Object,
2694  Object ? OBJECT_TO_OBJECT_HEADER(Object)->PointerCount : -1,
2695  Status);
2696  return Status;
2697 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TAG_OB_TEMP_STORAGE
Definition: ob.h:150
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
ObjectType
Definition: metafile.c:80
PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: setypes.h:207
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI SeCreateAccessState(IN OUT PACCESS_STATE AccessState, IN PAUX_ACCESS_DATA AuxData, IN ACCESS_MASK Access, IN PGENERIC_MAPPING GenericMapping)
Definition: access.c:439
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
OBJECT_CREATE_INFORMATION ObjectCreateInfo
Definition: ob.h:154
VOID NTAPI ObpFreeObjectNameBuffer(IN PUNICODE_STRING Name)
Definition: oblife.c:347
_Inout_opt_ PACCESS_STATE PassedAccessState
Definition: obfuncs.h:71
FORCEINLINE VOID ObpReleaseObjectCreateInformation(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
Definition: ob_x.h:296
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
NTSTATUS NTAPI ObpCreateHandle(IN OB_OPEN_REASON OpenReason, IN PVOID Object, IN POBJECT_TYPE Type OPTIONAL, IN PACCESS_STATE AccessState, IN ULONG AdditionalReferences, IN ULONG HandleAttributes, IN POBP_LOOKUP_CONTEXT Context, IN KPROCESSOR_MODE AccessMode, OUT PVOID *ReturnedObject, OUT PHANDLE ReturnedHandle)
Definition: obhandle.c:1494
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID ObpFreeObjectCreateInformation(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
Definition: ob_x.h:392
PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: obtypes.h:344
UCHAR Flags
Definition: obtypes.h:497
_In_ HANDLE Handle
Definition: extypes.h:390
LONG NTSTATUS
Definition: precomp.h:26
ACCESS_STATE LocalAccessState
Definition: ob.h:153
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI ObpValidateAccessMask(IN PACCESS_STATE AccessState)
Definition: obhandle.c:485
static IUnknown Object
Definition: main.c:512
#define OB_FLAG_CREATE_INFO
Definition: obtypes.h:97
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PSECURITY_QUALITY_OF_SERVICE SecurityQos
Definition: obtypes.h:345
#define OB_HANDLE_DEBUG
Definition: ob.h:17
static const WCHAR Cleanup[]
Definition: register.c:80
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
AUX_ACCESS_DATA AuxData
Definition: ob.h:156
Status
Definition: gdiplustypes.h:24
enum _OB_OPEN_REASON OB_OPEN_REASON
FORCEINLINE VOID ObpReleaseLookupContext(IN POBP_LOOKUP_CONTEXT Context)
Definition: ob_x.h:255
static GENERIC_MAPPING GenericMapping
Definition: SeInheritance.c:11
NTSTATUS NTAPI ObpCaptureObjectCreateInformation(IN POBJECT_ATTRIBUTES ObjectAttributes, IN KPROCESSOR_MODE AccessMode, IN KPROCESSOR_MODE CreatorMode, IN BOOLEAN AllocateFromLookaside, IN POBJECT_CREATE_INFORMATION ObjectCreateInfo, OUT PUNICODE_STRING ObjectName)
Definition: oblife.c:456
OBP_LOOKUP_CONTEXT LookupContext
Definition: ob.h:155
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
VOID NTAPI SeDeleteAccessState(IN PACCESS_STATE AccessState)
Definition: access.c:460
#define __FUNCTION__
Definition: compiler.h:205
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
POBJECT_TYPE Type
Definition: obtypes.h:493
POBJECT_CREATE_INFORMATION ObjectCreateInfo
Definition: obtypes.h:500
NTSTATUS NTAPI ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL, IN OUT PUNICODE_STRING ObjectName, IN ULONG Attributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, IN PVOID InsertObject OPTIONAL, IN OUT PACCESS_STATE AccessState, OUT POBP_LOOKUP_CONTEXT LookupContext, OUT PVOID *FoundObject)
Definition: obname.c:358
NTSTATUS NTAPI ObOpenObjectByPointer ( IN PVOID  Object,
IN ULONG  HandleAttributes,
IN PACCESS_STATE  PassedAccessState,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_TYPE  ObjectType,
IN KPROCESSOR_MODE  AccessMode,
OUT PHANDLE  Handle 
)

Definition at line 2733 of file obhandle.c.

Referenced by AfdBindSocket(), DbgkOpenProcessDebugPort(), DbgkpOpenHandles(), IntGetDesktopObjectHandle(), IntResolveDesktop(), NtOpenProcess(), NtOpenProcessTokenEx(), NtOpenThread(), NtOpenThreadTokenEx(), NtUserOpenInputDesktop(), SerenumDetectLegacyDevice(), SerenumDetectPnpDevice(), SermouseDetectLegacyDevice(), START_TEST(), and WmipOpenGuidObject().

2740 {
2742  NTSTATUS Status;
2744  AUX_ACCESS_DATA AuxData;
2745  PAGED_CODE();
2746 
2747  /* Assume failure */
2748  *Handle = NULL;
2749 
2750  /* Reference the object */
2752  0,
2753  ObjectType,
2754  AccessMode);
2755  if (!NT_SUCCESS(Status)) return Status;
2756 
2757  /* Get the Header Info */
2758  Header = OBJECT_TO_OBJECT_HEADER(Object);
2759 
2760  /* Check if we didn't get an access state */
2761  if (!PassedAccessState)
2762  {
2763  /* Use our built-in access state */
2765  Status = SeCreateAccessState(&AccessState,
2766  &AuxData,
2767  DesiredAccess,
2768  &Header->Type->TypeInfo.GenericMapping);
2769  if (!NT_SUCCESS(Status))
2770  {
2771  /* Fail */
2773  return Status;
2774  }
2775  }
2776 
2777  /* Check if we have invalid object attributes */
2779  {
2780  /* Delete the access state */
2781  if (PassedAccessState == &AccessState)
2782  {
2784  }
2785 
2786  /* Dereference the object */
2788  return STATUS_INVALID_PARAMETER;
2789  }
2790 
2791  /* Create the handle */
2792  Status = ObpCreateHandle(ObOpenHandle,
2793  Object,
2794  ObjectType,
2796  0,
2798  NULL,
2799  AccessMode,
2800  NULL,
2801  Handle);
2802  if (!NT_SUCCESS(Status)) ObDereferenceObject(Object);
2803 
2804  /* Delete the access state */
2805  if (PassedAccessState == &AccessState)
2806  {
2808  }
2809 
2810  /* Return */
2812  "%s - returning Object with PC S: %lx %lx\n",
2813  __FUNCTION__,
2814  OBJECT_TO_OBJECT_HEADER(Object)->PointerCount,
2815  Status);
2816  return Status;
2817 }
ObjectType
Definition: metafile.c:80
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
NTSTATUS NTAPI SeCreateAccessState(IN OUT PACCESS_STATE AccessState, IN PAUX_ACCESS_DATA AuxData, IN ACCESS_MASK Access, IN PGENERIC_MAPPING GenericMapping)
Definition: access.c:439
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Inout_opt_ PACCESS_STATE PassedAccessState
Definition: obfuncs.h:71
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI ObpCreateHandle(IN OB_OPEN_REASON OpenReason, IN PVOID Object, IN POBJECT_TYPE Type OPTIONAL, IN PACCESS_STATE AccessState, IN ULONG AdditionalReferences, IN ULONG HandleAttributes, IN POBP_LOOKUP_CONTEXT Context, IN KPROCESSOR_MODE AccessMode, OUT PVOID *ReturnedObject, OUT PHANDLE ReturnedHandle)
Definition: obhandle.c:1494
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
Definition: Header.h:8
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI ObReferenceObjectByPointer(IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode)
Definition: obref.c:383
_In_ HANDLE Handle
Definition: extypes.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static IUnknown Object
Definition: main.c:512
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
#define OB_HANDLE_DEBUG
Definition: ob.h:17
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
Status
Definition: gdiplustypes.h:24
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
VOID NTAPI SeDeleteAccessState(IN PACCESS_STATE AccessState)
Definition: access.c:460
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
NTSTATUS NTAPI ObpChargeQuotaForObject ( IN POBJECT_HEADER  ObjectHeader,
IN POBJECT_TYPE  ObjectType,
OUT PBOOLEAN  NewObject 
)

Definition at line 434 of file obhandle.c.

Referenced by ObInsertObject(), ObpIncrementHandleCount(), and ObpIncrementUnnamedHandleCount().

437 {
438  POBJECT_HEADER_QUOTA_INFO ObjectQuota;
439  ULONG PagedPoolCharge, NonPagedPoolCharge;
440 
441  /* Get quota information */
442  ObjectQuota = OBJECT_HEADER_TO_QUOTA_INFO(ObjectHeader);
443  *NewObject = FALSE;
444 
445  /* Check if this is a new object */
446  if (ObjectHeader->Flags & OB_FLAG_CREATE_INFO)
447  {
448  /* Remove the flag */
449  ObjectHeader->Flags &= ~ OB_FLAG_CREATE_INFO;
450  if (ObjectQuota)
451  {
452  /* We have a quota, get the charges */
453  PagedPoolCharge = ObjectQuota->PagedPoolCharge;
454  NonPagedPoolCharge = ObjectQuota->NonPagedPoolCharge;
455  }
456  else
457  {
458  /* Get it from the object type */
459  PagedPoolCharge = ObjectType->TypeInfo.DefaultPagedPoolCharge;
460  NonPagedPoolCharge = ObjectType->TypeInfo.DefaultNonPagedPoolCharge;
461  }
462 
463  /* Charge the quota */
464  ObjectHeader->QuotaBlockCharged = (PVOID)1;
465  DPRINT("FIXME: Should charge: %lx %lx\n", PagedPoolCharge, NonPagedPoolCharge);
466 #if 0
467  PsChargeSharedPoolQuota(PsGetCurrentProcess(),
468  PagedPoolCharge,
469  NonPagedPoolCharge);
470 #endif
471 
472  /* Check if we don't have a quota block */
473  if (!ObjectHeader->QuotaBlockCharged) return STATUS_QUOTA_EXCEEDED;
474 
475  /* Now set the flag */
476  *NewObject = TRUE;
477  }
478 
479  /* Return success */
480  return STATUS_SUCCESS;
481 }
DWORD *typedef PVOID
Definition: winlogon.h:61
ObjectType
Definition: metafile.c:80
#define TRUE
Definition: types.h:120
#define STATUS_QUOTA_EXCEEDED
Definition: ntstatus.h:290
#define FALSE
Definition: types.h:117
#define PsGetCurrentProcess
Definition: psfuncs.h:17
void DPRINT(...)
Definition: polytest.cpp:61
#define OBJECT_HEADER_TO_QUOTA_INFO(h)
Definition: obtypes.h:122
#define OB_FLAG_CREATE_INFO
Definition: obtypes.h:97
unsigned int ULONG
Definition: retypes.h:1
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:71
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS NTAPI ObpCloseHandle ( IN HANDLE  Handle,
IN KPROCESSOR_MODE  AccessMode 
)

Definition at line 1727 of file obhandle.c.

Referenced by NtClose(), and ObCloseHandle().

1729 {
1731  BOOLEAN AttachedToProcess = FALSE;
1733  PHANDLE_TABLE_ENTRY HandleTableEntry;
1734  NTSTATUS Status;
1736  PAGED_CODE();
1738  "%s - Closing handle: %p\n", __FUNCTION__, Handle);
1739 
1740  if (AccessMode == KernelMode && Handle == (HANDLE)-1)
1741  return STATUS_INVALID_HANDLE;
1742 
1743  /* Check if we're dealing with a kernel handle */
1745  {
1746  /* Use the kernel table and convert the handle */
1747  HandleTable = ObpKernelHandleTable;
1749 
1750  /* Check if we're not in the system process */
1751  if (Process != PsInitialSystemProcess)
1752  {
1753  /* Attach to the system process */
1755  AttachedToProcess = TRUE;
1756  }
1757  }
1758  else
1759  {
1760  /* Use the process's handle table */
1761  HandleTable = Process->ObjectTable;
1762  }
1763 
1764  /* Enter a critical region to protect handle access */
1766 
1767  /* Get the handle entry */
1768  HandleTableEntry = ExMapHandleToPointer(HandleTable, Handle);
1769  if (HandleTableEntry)
1770  {
1771  /* Now close the entry */
1772  Status = ObpCloseHandleTableEntry(HandleTable,
1773  HandleTableEntry,
1774  Handle,
1775  AccessMode,
1776  FALSE);
1777 
1778  /* We can quit the critical region now */
1780 
1781  /* Detach and return success */
1782  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1783  }
1784  else
1785  {
1786  /* We failed, quit the critical region */
1788 
1789  /* Detach */
1790  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1791 
1792  /* Check if we have a valid handle that's not the process or thread */
1793  if ((Handle) &&
1794  (Handle != NtCurrentProcess()) &&
1795  (Handle != NtCurrentThread()))
1796  {
1797  /* Check if we came from user mode */
1798  if (AccessMode != KernelMode)
1799  {
1800  /* Check if we have no debug port */
1801  if (Process->DebugPort)
1802  {
1803  /* Make sure we're not attached */
1804  if (!KeIsAttachedProcess())
1805  {
1806  /* Raise an exception */
1808  }
1809  }
1810  }
1811  else
1812  {
1813  /* This is kernel mode. Check if we're exiting */
1815  (Process->Peb))
1816  {
1817  /* Check if the debugger is enabled */
1818  if (KdDebuggerEnabled)
1819  {
1820  /* Bugcheck */
1821  KeBugCheckEx(INVALID_KERNEL_HANDLE, (ULONG_PTR)Handle, 1, 0, 0);
1822  }
1823  }
1824  }
1825  }
1826 
1827  /* Set invalid status */
1828  Status = STATUS_INVALID_HANDLE;
1829  }
1830 
1831  /* Return status */
1833  "%s - Closed handle: %p S: %lx\n",
1834  __FUNCTION__, Handle, Status);
1835  return Status;
1836 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
KAPC_STATE
Definition: ketypes.h:1273
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
Definition: handle.c:1010
#define NtCurrentThread()
#define ObpIsKernelHandle(Handle, ProcessorMode)
Definition: ob.h:64
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define FALSE
Definition: types.h:117
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
BOOLEAN NTAPI KeIsAttachedProcess(VOID)
Definition: procobj.c:690
#define PsGetCurrentProcess
Definition: psfuncs.h:17
Definition: extypes.h:595
struct _PEB * Peb
Definition: pstypes.h:1275
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
#define NtCurrentProcess()
Definition: nt_native.h:1657
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ObpCloseHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleEntry, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode, IN BOOLEAN IgnoreHandleProtection)
Definition: obhandle.c:682
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define OB_HANDLE_DEBUG
Definition: ob.h:17
KPROCESS Pcb
Definition: pstypes.h:1193
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI KeRaiseUserException(IN NTSTATUS ExceptionCode)
Definition: except.c:393
PHANDLE_TABLE ObjectTable
Definition: pstypes.h:1217
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
PVOID DebugPort
Definition: pstypes.h:1206
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define __FUNCTION__
Definition: compiler.h:205
#define ObKernelHandleToHandle(Handle)
Definition: ob.h:73
BOOLEAN NTAPI PsIsThreadTerminating(IN PETHREAD Thread)
Definition: thread.c:868
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
PHANDLE_TABLE ObpKernelHandleTable
Definition: obhandle.c:20
BOOLEAN NTAPI ObpCloseHandleCallback ( IN PHANDLE_TABLE_ENTRY  HandleTableEntry,
IN HANDLE  Handle,
IN PVOID  Context 
)

Definition at line 1921 of file obhandle.c.

Referenced by ObClearProcessHandleTable(), and ObKillProcess().

1924 {
1926 
1927  /* Simply decrement the handle count */
1928  ObpCloseHandleTableEntry(CloseContext->HandleTable,
1929  HandleTableEntry,
1930  Handle,
1931  CloseContext->AccessMode,
1932  TRUE);
1933  return TRUE;
1934 }
#define TRUE
Definition: types.h:120
PHANDLE_TABLE HandleTable
Definition: ob.h:107
struct _OBP_CLOSE_HANDLE_CONTEXT * POBP_CLOSE_HANDLE_CONTEXT
_In_ HANDLE Handle
Definition: extypes.h:390
NTSTATUS NTAPI ObpCloseHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleEntry, IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode, IN BOOLEAN IgnoreHandleProtection)
Definition: obhandle.c:682
KPROCESSOR_MODE AccessMode
Definition: ob.h:108
NTSTATUS NTAPI ObpCloseHandleTableEntry ( IN PHANDLE_TABLE  HandleTable,
IN PHANDLE_TABLE_ENTRY  HandleEntry,
IN HANDLE  Handle,
IN KPROCESSOR_MODE  AccessMode,
IN BOOLEAN  IgnoreHandleProtection 
)

Definition at line 682 of file obhandle.c.

Referenced by ObpCloseHandle(), and ObpCloseHandleCallback().

687 {
688  PVOID Body;
690  POBJECT_HEADER ObjectHeader;
692  KIRQL CalloutIrql;
693  PAGED_CODE();
694 
695  /* Get the object data */
696  ObjectHeader = ObpGetHandleObject(HandleEntry);
697  ObjectType = ObjectHeader->Type;
698  Body = &ObjectHeader->Body;
699  GrantedAccess = HandleEntry->GrantedAccess;
701  "%s - Closing handle: %p for %p. HC PC %lx %lx\n",
702  __FUNCTION__,
703  Handle,
704  Body,
705  ObjectHeader->HandleCount,
706  ObjectHeader->PointerCount);
707 
708  /* Check if the object has an Okay To Close procedure */
709  if (ObjectType->TypeInfo.OkayToCloseProcedure)
710  {
711  /* Call it and check if it's not letting us close it */
712  ObpCalloutStart(&CalloutIrql);
714  Body,
715  Handle,
716  AccessMode))
717  {
718  /* Fail */
719  ObpCalloutEnd(CalloutIrql, "NtClose", ObjectType, Body);
722  }
723 
724  /* Success, validate callout retrn */
725  ObpCalloutEnd(CalloutIrql, "NtClose", ObjectType, Body);
726  }
727 
728  /* The callback allowed us to close it, but does the handle itself? */
729  if ((HandleEntry->ObAttributes & OBJ_PROTECT_CLOSE) &&
730  !(IgnoreHandleProtection))
731  {
732  /* It doesn't, are we from user mode? */
733  if (AccessMode != KernelMode)
734  {
735  /* We are! Unlock the entry */
737 
738  /* Make sure we have a debug port */
739  if (PsGetCurrentProcess()->DebugPort)
740  {
741  /* Raise an exception */
743  }
744  else
745  {
746  /* Return the error instead */
748  }
749  }
750  else
751  {
752  /* Otherwise, bugcheck the OS */
753  KeBugCheckEx(INVALID_KERNEL_HANDLE, (ULONG_PTR)Handle, 0, 0, 0);
754  }
755  }
756 
757  /* Destroy and unlock the handle entry */
758  ExDestroyHandle(HandleTable, Handle, HandleEntry);
759 
760  /* Now decrement the handle count */
763  GrantedAccess,
764  ObjectType);
765 
766  /* Dereference the object as well */
767  ObDereferenceObject(Body);
768 
769  /* Return to caller */
771  "%s - Closed handle: %p for %p.\n",
772  __FUNCTION__,
773  Handle,
774  Body);
775  return STATUS_SUCCESS;
776 }
DWORD *typedef PVOID
Definition: winlogon.h:61
ObjectType
Definition: metafile.c:80
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:948
LONG_PTR HandleCount
Definition: obtypes.h:490
OB_OKAYTOCLOSE_METHOD OkayToCloseProcedure
Definition: obtypes.h:373
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:887
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define PsGetCurrentProcess
Definition: psfuncs.h:17
FORCEINLINE VOID ObpCalloutStart(IN PKIRQL CalloutIrql)
Definition: ob_x.h:429
#define ObpGetHandleObject(x)
Definition: ob.h:81
VOID NTAPI ObpDecrementHandleCount(IN PVOID ObjectBody, IN PEPROCESS Process, IN ACCESS_MASK GrantedAccess, IN POBJECT_TYPE ObjectType)
Definition: obhandle.c:527
_In_ HANDLE Handle
Definition: extypes.h:390
FORCEINLINE VOID ObpCalloutEnd(IN KIRQL CalloutIrql, IN PCHAR Procedure, IN POBJECT_TYPE ObjectType, IN PVOID Object)
Definition: ob_x.h:437
#define OB_HANDLE_DEBUG
Definition: ob.h:17
#define STATUS_HANDLE_NOT_CLOSABLE
Definition: ntstatus.h:683
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
#define OBJ_PROTECT_CLOSE
Definition: ob.h:49
NTSTATUS NTAPI KeRaiseUserException(IN NTSTATUS ExceptionCode)
Definition: except.c:393
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
LONG_PTR PointerCount
Definition: obtypes.h:487
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
return STATUS_SUCCESS
Definition: btrfs.c:2710
ULONG ACCESS_MASK
Definition: nt_native.h:40
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
NTSTATUS NTAPI ObpCreateHandle ( IN OB_OPEN_REASON  OpenReason,
IN PVOID  Object,
IN POBJECT_TYPE Type  OPTIONAL,
IN PACCESS_STATE  AccessState,
IN ULONG  AdditionalReferences,
IN ULONG  HandleAttributes,
IN POBP_LOOKUP_CONTEXT  Context,
IN KPROCESSOR_MODE  AccessMode,
OUT PVOID ReturnedObject,
OUT PHANDLE  ReturnedHandle 
)

Definition at line 1494 of file obhandle.c.

Referenced by ObInsertObject(), ObOpenObjectByName(), and ObOpenObjectByPointer().

1504 {
1505  HANDLE_TABLE_ENTRY NewEntry;
1506  POBJECT_HEADER ObjectHeader;
1507  HANDLE Handle;
1509  BOOLEAN AttachedToProcess = FALSE, KernelHandle = FALSE;
1512  NTSTATUS Status;
1514  PAUX_ACCESS_DATA AuxData;
1515  PAGED_CODE();
1516 
1517  /* Get the object header and type */
1518  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
1519  ObjectType = ObjectHeader->Type;
1521  "%s - Creating handle for: %p. Reason: %lx. HC PC %lx %lx\n",
1522  __FUNCTION__,
1523  Object,
1524  OpenReason,
1525  ObjectHeader->HandleCount,
1526  ObjectHeader->PointerCount);
1527 
1528  /* Check if the types match */
1529  if ((Type) && (ObjectType != Type))
1530  {
1531  /* They don't, cleanup */
1534  }
1535 
1536  /* Save the object header */
1537  NewEntry.Object = ObjectHeader;
1538 
1539  /* Check if this is a kernel handle */
1541  {
1542  /* Set the handle table */
1543  HandleTable = ObpKernelHandleTable;
1544  KernelHandle = TRUE;
1545 
1546  /* Check if we're not in the system process */
1548  {
1549  /* Attach to the system process */
1551  AttachedToProcess = TRUE;
1552  }
1553  }
1554  else
1555  {
1556  /* Get the current handle table */
1557  HandleTable = PsGetCurrentProcess()->ObjectTable;
1558  }
1559 
1560  /* Increment the handle count */
1562  AccessState,
1563  AccessMode,
1566  OpenReason);
1567  if (!NT_SUCCESS(Status))
1568  {
1569  /*
1570  * We failed (meaning security failure, according to NT Internals)
1571  * detach and return
1572  */
1574  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1575  return Status;
1576  }
1577 
1578  /* Check if we are doing audits on close */
1579  if (AccessState->GenerateOnClose)
1580  {
1581  /* Force the attribute on */
1583  }
1584 
1585  /* Mask out the internal attributes */
1587 
1588  /* Get the original desired access */
1589  DesiredAccess = AccessState->RemainingDesiredAccess |
1590  AccessState->PreviouslyGrantedAccess;
1591 
1592  /* Remove what's not in the valid access mask */
1593  GrantedAccess = DesiredAccess & (ObjectType->TypeInfo.ValidAccessMask |
1595 
1596  /* Update the value in the access state */
1597  AccessState->PreviouslyGrantedAccess = GrantedAccess;
1598 
1599  /* Get the auxiliary data */
1600  AuxData = AccessState->AuxData;
1601 
1602  /* Handle extra references */
1603  if (AdditionalReferences)
1604  {
1605  /* Add them to the header */
1607  AdditionalReferences);
1608  }
1609 
1610  /* Now we can release the object */
1612 
1613  /* Save the access mask */
1614  NewEntry.GrantedAccess = GrantedAccess;
1615 
1616  /*
1617  * Create the actual handle. We'll need to do this *after* calling
1618  * ObpIncrementHandleCount to make sure that Object Security is valid
1619  * (specified in Gl00my documentation on Ob)
1620  */
1622  "%s - Handle Properties: [%p-%lx-%lx]\n",
1623  __FUNCTION__,
1624  NewEntry.Object, NewEntry.ObAttributes & 3, NewEntry.GrantedAccess);
1625  Handle = ExCreateHandle(HandleTable, &NewEntry);
1626 
1627  /* Make sure we got a handle */
1628  if (Handle)
1629  {
1630  /* Check if this was a kernel handle */
1631  if (KernelHandle) Handle = ObMarkHandleAsKernelHandle(Handle);
1632 
1633  /* Return it */
1634  *ReturnedHandle = Handle;
1635 
1636  /* Check if we need to generate on audit */
1637  if (AccessState->GenerateAudit)
1638  {
1639  /* Audit the handle creation */
1640  //SeAuditHandleCreation(AccessState, Handle);
1641  }
1642 
1643  /* Check if this was a create */
1644  if (OpenReason == ObCreateHandle)
1645  {
1646  /* Check if we need to audit the privileges */
1647  if ((AuxData->PrivilegeSet) &&
1648  (AuxData->PrivilegeSet->PrivilegeCount))
1649  {
1650  /* Do the audit */
1651 #if 0
1653  &AccessState->
1655  GrantedAccess,
1656  AuxData->PrivilegeSet,
1657  TRUE,
1658  ExGetPreviousMode());
1659 #endif
1660  }
1661  }
1662 
1663  /* Return the new object only if caller wanted it biased */
1664  if ((AdditionalReferences) && (ReturnedObject))
1665  {
1666  /* Return it */
1667  *ReturnedObject = Object;
1668  }
1669 
1670  /* Detach if needed */
1671  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1672 
1673  /* Trace and return */
1675  "%s - Returning Handle: %p HC PC %lx %lx\n",
1676  __FUNCTION__,
1677  Handle,
1678  ObjectHeader->HandleCount,
1679  ObjectHeader->PointerCount);
1680  return STATUS_SUCCESS;
1681  }
1682 
1683  /* Decrement the handle count and detach */
1684  ObpDecrementHandleCount(&ObjectHeader->Body,
1686  GrantedAccess,
1687  ObjectType);
1688 
1689  /* Handle extra references */
1690  if (AdditionalReferences)
1691  {
1692  /* Check how many extra references were added */
1693  if (AdditionalReferences > 1)
1694  {
1695  /* Dereference it many times */
1697  -(LONG)(AdditionalReferences - 1));
1698  }
1699 
1700  /* Dereference the object one last time */
1702  }
1703 
1704  /* Detach if necessary and fail */
1705  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1707 }
DWORD *typedef PVOID
Definition: winlogon.h:61
PPRIVILEGE_SET PrivilegeSet
Definition: setypes.h:187
ObjectType
Definition: metafile.c:80
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
#define TRUE
Definition: types.h:120
KAPC_STATE
Definition: ketypes.h:1273
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
LONG_PTR HandleCount
Definition: obtypes.h:490
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
HANDLE KernelHandle
Definition: legacy.c:24
ULONG_PTR ObAttributes
Definition: extypes.h:600
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2927
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:791
#define OBJ_AUDIT_OBJECT_CLOSE
Definition: ob.h:51
#define FALSE
Definition: types.h:117
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
long LONG
Definition: pedump.c:60
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define PsGetCurrentProcess
Definition: psfuncs.h:17
Definition: extypes.h:595
NTSTATUS NTAPI ObpIncrementHandleCount(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN ULONG HandleAttributes, IN PEPROCESS Process, IN OB_OPEN_REASON OpenReason)
Definition: obhandle.c:808
VOID NTAPI ObpDecrementHandleCount(IN PVOID ObjectBody, IN PEPROCESS Process, IN ACCESS_MASK GrantedAccess, IN POBJECT_TYPE ObjectType)
Definition: obhandle.c:527
$ULONG PrivilegeCount
Definition: setypes.h:86
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned char BOOLEAN
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:259
#define ObMarkHandleAsKernelHandle(Handle)
Definition: ob.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ULONG GrantedAccess
Definition: extypes.h:606
static IUnknown Object
Definition: main.c:512
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
#define InterlockedExchangeAddSizeT(a, b)
Definition: interlocked.h:196
#define OB_HANDLE_DEBUG
Definition: ob.h:17
KPROCESS Pcb
Definition: pstypes.h:1193
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
Status
Definition: gdiplustypes.h:24
FORCEINLINE VOID ObpReleaseLookupContext(IN POBP_LOOKUP_CONTEXT Context)
Definition: ob_x.h:255
DWORD *typedef HANDLE
Definition: winlogon.h:61
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
LONG_PTR PointerCount
Definition: obtypes.h:487
VOID NTAPI SePrivilegeObjectAuditAlarm(IN HANDLE Handle, IN PSECURITY_SUBJECT_CONTEXT SubjectContext, IN ACCESS_MASK DesiredAccess, IN PPRIVILEGE_SET Privileges, IN BOOLEAN AccessGranted, IN KPROCESSOR_MODE CurrentMode)
Definition: audit.c:845
PVOID Object
Definition: extypes.h:599
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
#define OBJ_HANDLE_ATTRIBUTES
Definition: ob.h:52
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
ULONG ACCESS_MASK
Definition: nt_native.h:40
PHANDLE_TABLE ObpKernelHandleTable
Definition: obhandle.c:20
_In_ PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext
Definition: sefuncs.h:13
NTSTATUS NTAPI ObpCreateUnnamedHandle ( IN PVOID  Object,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  AdditionalReferences,
IN ULONG  HandleAttributes,
IN KPROCESSOR_MODE  AccessMode,
OUT PVOID ReturnedObject,
OUT PHANDLE  ReturnedHandle 
)

Definition at line 1309 of file obhandle.c.

Referenced by ObInsertObject().

1316 {
1317  HANDLE_TABLE_ENTRY NewEntry;
1318  POBJECT_HEADER ObjectHeader;
1319  HANDLE Handle;
1321  BOOLEAN AttachedToProcess = FALSE, KernelHandle = FALSE;
1323  NTSTATUS Status;
1326  PAGED_CODE();
1327 
1328  /* Get the object header and type */
1329  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
1330  ObjectType = ObjectHeader->Type;
1332  "%s - Creating handle for: %p. UNNAMED. HC PC %lx %lx\n",
1333  __FUNCTION__,
1334  Object,
1335  ObjectHeader->HandleCount,
1336  ObjectHeader->PointerCount);
1337 
1338  /* Save the object header */
1339  NewEntry.Object = ObjectHeader;
1340 
1341  /* Mask out the internal attributes */
1343 
1344  /* Check if this is a kernel handle */
1346  {
1347  /* Set the handle table */
1348  HandleTable = ObpKernelHandleTable;
1349  KernelHandle = TRUE;
1350 
1351  /* Check if we're not in the system process */
1353  {
1354  /* Attach to the system process */
1356  AttachedToProcess = TRUE;
1357  }
1358  }
1359  else
1360  {
1361  /* Get the current handle table */
1362  HandleTable = PsGetCurrentProcess()->ObjectTable;
1363  }
1364 
1365  /* Increment the handle count */
1367  &DesiredAccess,
1368  AccessMode,
1371  if (!NT_SUCCESS(Status))
1372  {
1373  /*
1374  * We failed (meaning security failure, according to NT Internals)
1375  * detach and return
1376  */
1377  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1378  return Status;
1379  }
1380 
1381  /* Remove what's not in the valid access mask */
1382  GrantedAccess = DesiredAccess & (ObjectType->TypeInfo.ValidAccessMask |
1384 
1385  /* Handle extra references */
1386  if (AdditionalReferences)
1387  {
1388  /* Add them to the header */
1390  AdditionalReferences);
1391  }
1392 
1393  /* Save the access mask */
1394  NewEntry.GrantedAccess = GrantedAccess;
1395 
1396  /*
1397  * Create the actual handle. We'll need to do this *after* calling
1398  * ObpIncrementHandleCount to make sure that Object Security is valid
1399  * (specified in Gl00my documentation on Ob)
1400  */
1402  "%s - Handle Properties: [%p-%lx-%lx]\n",
1403  __FUNCTION__,
1404  NewEntry.Object, NewEntry.ObAttributes & 3, NewEntry.GrantedAccess);
1405  Handle = ExCreateHandle(HandleTable, &NewEntry);
1406 
1407  /* Make sure we got a handle */
1408  if (Handle)
1409  {
1410  /* Check if this was a kernel handle */
1411  if (KernelHandle) Handle = ObMarkHandleAsKernelHandle(Handle);
1412 
1413  /* Return handle and object */
1414  *ReturnedHandle = Handle;
1415 
1416  /* Return the new object only if caller wanted it biased */
1417  if ((AdditionalReferences) && (ReturnedObject))
1418  {
1419  /* Return it */
1420  *ReturnedObject = Object;
1421  }
1422 
1423  /* Detach if needed */
1424  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1425 
1426  /* Trace and return */
1428  "%s - Returning Handle: %p HC PC %lx %lx\n",
1429  __FUNCTION__,
1430  Handle,
1431  ObjectHeader->HandleCount,
1432  ObjectHeader->PointerCount);
1433  return STATUS_SUCCESS;
1434  }
1435 
1436  /* Handle extra references */
1437  if (AdditionalReferences)
1438  {
1439  /* Dereference it as many times as required */
1441  -(LONG)AdditionalReferences);
1442  }
1443 
1444  /* Decrement the handle count and detach */
1445  ObpDecrementHandleCount(&ObjectHeader->Body,
1447  GrantedAccess,
1448  ObjectType);
1449 
1450  /* Detach and fail */
1451  if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
1453 }
DWORD *typedef PVOID
Definition: winlogon.h:61
ObjectType
Definition: metafile.c:80
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
#define TRUE
Definition: types.h:120
KAPC_STATE
Definition: ketypes.h:1273
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG_PTR HandleCount
Definition: obtypes.h:490
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
HANDLE KernelHandle
Definition: legacy.c:24
ULONG_PTR ObAttributes
Definition: extypes.h:600
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
NTSTATUS NTAPI ObpIncrementUnnamedHandleCount(IN PVOID Object, IN PACCESS_MASK DesiredAccess, IN KPROCESSOR_MODE AccessMode, IN ULONG HandleAttributes, IN PEPROCESS Process)
Definition: obhandle.c:1087
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:791
#define FALSE
Definition: types.h:117
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
long LONG
Definition: pedump.c:60
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define PsGetCurrentProcess
Definition: psfuncs.h:17
Definition: extypes.h:595
VOID NTAPI ObpDecrementHandleCount(IN PVOID ObjectBody, IN PEPROCESS Process, IN ACCESS_MASK GrantedAccess, IN POBJECT_TYPE ObjectType)
Definition: obhandle.c:527
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned char BOOLEAN
#define ObMarkHandleAsKernelHandle(Handle)
Definition: ob.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ULONG GrantedAccess
Definition: extypes.h:606
static IUnknown Object
Definition: main.c:512
#define InterlockedExchangeAddSizeT(a, b)
Definition: interlocked.h:196
#define OB_HANDLE_DEBUG
Definition: ob.h:17
KPROCESS Pcb
Definition: pstypes.h:1193
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1471
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
LONG_PTR PointerCount
Definition: obtypes.h:487
PVOID Object
Definition: extypes.h:599
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
#define OBJ_HANDLE_ATTRIBUTES
Definition: ob.h:52
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
ULONG ACCESS_MASK
Definition: nt_native.h:40
PHANDLE_TABLE ObpKernelHandleTable
Definition: obhandle.c:20
VOID NTAPI ObpDecrementHandleCount ( IN PVOID  ObjectBody,
IN PEPROCESS  Process,
IN ACCESS_MASK  GrantedAccess,
IN POBJECT_TYPE  ObjectType 
)

Definition at line 527 of file obhandle.c.

Referenced by ObDuplicateObject(), ObpCloseHandleTableEntry(), ObpCreateHandle(), and ObpCreateUnnamedHandle().

531 {
532  POBJECT_HEADER ObjectHeader;
533  LONG SystemHandleCount, ProcessHandleCount;
534  LONG NewCount;
535  KIRQL CalloutIrql;
536  POBJECT_HEADER_HANDLE_INFO HandleInfo;
537  POBJECT_HANDLE_COUNT_ENTRY HandleEntry;
538  POBJECT_HANDLE_COUNT_DATABASE HandleDatabase;
539  ULONG i;
540  PAGED_CODE();
541 
542  /* Get the object type and header */
543  ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
545  "%s - Decrementing count for: %p. HC PC %lx %lx\n",
546  __FUNCTION__,
547  ObjectBody,
548  ObjectHeader->HandleCount,
549  ObjectHeader->PointerCount);
550 
551  /* Lock the object */
552  ObpAcquireObjectLock(ObjectHeader);
553 
554  /* Set default counts */
555  SystemHandleCount = ObjectHeader->HandleCount;
556  ProcessHandleCount = 0;
557 
558  /* Decrement the handle count */
559  NewCount = InterlockedDecrementSizeT(&ObjectHeader->HandleCount);
560 
561  /* Check if we're out of handles and this was an exclusive object */
562  if (!(NewCount) && (ObjectHeader->Flags & OB_FLAG_EXCLUSIVE))
563  {
564  /* Clear the exclusive flag */
565  OBJECT_HEADER_TO_QUOTA_INFO(ObjectHeader)->ExclusiveProcess = NULL;
566  }
567 
568  /* Is the object type keeping track of handles? */
569  if (ObjectType->TypeInfo.MaintainHandleCount)
570  {
571  /* Get handle information */
572  HandleInfo = OBJECT_HEADER_TO_HANDLE_INFO(ObjectHeader);
573 
574  /* Check if there's only a single entry */
575  if (ObjectHeader->Flags & OB_FLAG_SINGLE_PROCESS)
576  {
577  /* It should be us */
578  ASSERT(HandleInfo->SingleEntry.Process == Process);
579  ASSERT(HandleInfo->SingleEntry.HandleCount > 0);
580 
581  /* Get the handle counts */
582  ProcessHandleCount = HandleInfo->SingleEntry.HandleCount--;
583  HandleEntry = &HandleInfo->SingleEntry;
584  }
585  else
586  {
587  /* Otherwise, get the database */
588  HandleDatabase = HandleInfo->HandleCountDatabase;
589  if (HandleDatabase)
590  {
591  /* Get the entries and loop them */
592  i = HandleDatabase->CountEntries;
593  HandleEntry = &HandleDatabase->HandleCountEntries[0];
594  while (i)
595  {
596  /* Check if this is a match */
597  if ((HandleEntry->HandleCount) &&
598  (HandleEntry->Process == Process))
599  {
600  /* Found it, get the process handle count */
601  ProcessHandleCount = HandleEntry->HandleCount--;
602  break;
603  }
604 
605  /* Keep looping */
606  HandleEntry++;
607  i--;
608  }
609  }
610  else
611  {
612  /* No database, so no entry */
613  HandleEntry = NULL;
614  }
615  }
616 
617  /* Check if this is the last handle */
618  if (ProcessHandleCount == 1)
619  {
620  /* Then clear the entry */
621  HandleEntry->Process = NULL;
622  HandleEntry->HandleCount = 0;
623  }
624  }
625 
626  /* Release the lock */
627  ObpReleaseObjectLock(ObjectHeader);
628 
629  /* Check if we have a close procedure */
630  if (ObjectType->TypeInfo.CloseProcedure)
631  {
632  /* Call it */
633  ObpCalloutStart(&CalloutIrql);
634  ObjectType->TypeInfo.CloseProcedure(Process,
635  ObjectBody,
637  ProcessHandleCount,
638  SystemHandleCount);
639  ObpCalloutEnd(CalloutIrql, "Close", ObjectType, ObjectBody);
640  }
641 
642  /* Check if we should delete the object */
643  ObpDeleteNameCheck(ObjectBody);
644 
645  /* Decrease the total number of handles for this type */
646  InterlockedDecrement((PLONG)&ObjectType->TotalNumberOfHandles);
648  "%s - Decremented count for: %p. HC PC %lx %lx\n",
649  __FUNCTION__,
650  ObjectBody,
651  ObjectHeader->HandleCount,
652  ObjectHeader->PointerCount);
653 }
ObjectType
Definition: metafile.c:80
FORCEINLINE VOID ObpAcquireObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:48
LONG_PTR HandleCount
Definition: obtypes.h:490
POBJECT_HANDLE_COUNT_DATABASE HandleCountDatabase
Definition: obtypes.h:458
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define OBJECT_HEADER_TO_HANDLE_INFO(h)
Definition: obtypes.h:118
FORCEINLINE VOID ObpReleaseObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:84
#define OB_FLAG_SINGLE_PROCESS
Definition: obtypes.h:103
#define PAGED_CODE()
Definition: video.h:57
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
FORCEINLINE VOID ObpCalloutStart(IN PKIRQL CalloutIrql)
Definition: ob_x.h:429
smooth NULL
Definition: ftsmooth.c:416
ULONG HandleCount
Definition: obtypes.h:445
UCHAR Flags
Definition: obtypes.h:497
#define OB_FLAG_EXCLUSIVE
Definition: obtypes.h:100
struct _EPROCESS * Process
Definition: obtypes.h:444
#define OBJECT_HEADER_TO_QUOTA_INFO(h)
Definition: obtypes.h:122
OBJECT_HANDLE_COUNT_ENTRY SingleEntry
Definition: obtypes.h:459
FORCEINLINE VOID ObpCalloutEnd(IN KIRQL CalloutIrql, IN PCHAR Procedure, IN POBJECT_TYPE ObjectType, IN PVOID Object)
Definition: ob_x.h:437
#define InterlockedDecrement
Definition: armddk.h:52
#define OB_HANDLE_DEBUG
Definition: ob.h:17
OBJECT_HANDLE_COUNT_ENTRY HandleCountEntries[1]
Definition: obtypes.h:451
Definition: obtypes.h:442
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
LONG_PTR PointerCount
Definition: obtypes.h:487
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: compiler.h:205
#define InterlockedDecrementSizeT(a)
Definition: interlocked.h:153
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
VOID NTAPI ObpDeleteNameCheck(IN PVOID Object)
Definition: obname.c:261
signed int * PLONG
Definition: retypes.h:5
BOOLEAN NTAPI ObpDuplicateHandleCallback ( IN PEPROCESS  Process,
IN PHANDLE_TABLE  HandleTable,
IN PHANDLE_TABLE_ENTRY  OldEntry,
IN PHANDLE_TABLE_ENTRY  HandleTableEntry 
)

Definition at line 1957 of file obhandle.c.

Referenced by ObInitProcess().

1961 {
1962  POBJECT_HEADER ObjectHeader;
1963  BOOLEAN Ret = FALSE;
1965  NTSTATUS Status;
1966  PAGED_CODE();
1967 
1968  /* Make sure that the handle is inheritable */
1969  Ret = (HandleTableEntry->ObAttributes & OBJ_INHERIT) != 0;
1970  if (Ret)
1971  {
1972  /* Get the object header */
1973  ObjectHeader = ObpGetHandleObject(HandleTableEntry);
1974 
1975  /* Increment the pointer count */
1976  InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
1977 
1978  /* Release the handle lock */
1980 
1981  /* Setup the access state */
1982  AccessState.PreviouslyGrantedAccess = HandleTableEntry->GrantedAccess;
1983 
1984  /* Call the shared routine for incrementing handles */
1985  Status = ObpIncrementHandleCount(&ObjectHeader->Body,
1986  &AccessState,
1987  KernelMode,
1988  HandleTableEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES,
1989  Process,
1990  ObInheritHandle);
1991  if (!NT_SUCCESS(Status))
1992  {
1993  /* Return failure */
1994  ObDereferenceObject(&ObjectHeader->Body);
1995  Ret = FALSE;
1996  }
1997  }
1998  else
1999  {
2000  /* Release the handle lock */
2002  }
2003 
2004  /* Return duplication result */
2005  return Ret;
2006 }
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:887
#define PAGED_CODE()
Definition: video.h:57
#define FALSE
Definition: types.h:117
#define InterlockedIncrementSizeT(a)
Definition: interlocked.h:220
NTSTATUS NTAPI ObpIncrementHandleCount(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN ULONG HandleAttributes, IN PEPROCESS Process, IN OB_OPEN_REASON OpenReason)
Definition: obhandle.c:808
#define ObpGetHandleObject(x)
Definition: ob.h:81
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
ACCESS_MASK PreviouslyGrantedAccess
Definition: setypes.h:204
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define OBJ_INHERIT
Definition: winternl.h:225
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
Status
Definition: gdiplustypes.h:24
LONG_PTR PointerCount
Definition: obtypes.h:487
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define OBJ_HANDLE_ATTRIBUTES
Definition: ob.h:52
BOOLEAN NTAPI ObpEnumFindHandleProcedure ( IN PHANDLE_TABLE_ENTRY  HandleEntry,
IN HANDLE  Handle,
IN PVOID  Context 
)

Definition at line 214 of file obhandle.c.

Referenced by ObFindHandleForObject().

217 {
218  POBJECT_HEADER ObjectHeader;
221  POBP_FIND_HANDLE_DATA FindData = Context;
222 
223  /* Get the object header */
224  ObjectHeader = ObpGetHandleObject(HandleEntry);
225 
226  /* Make sure it's valid and matching */
227  if ((FindData->ObjectHeader) && (FindData->ObjectHeader != ObjectHeader))
228  {
229  /* No match, fail */
230  return FALSE;
231  }
232 
233  /* Now attempt to match the object type */
234  if ((FindData->ObjectType) && (FindData->ObjectType != ObjectHeader->Type))
235  {
236  /* No match, fail */
237  return FALSE;
238  }
239 
240  /* Check if we have extra information */
241  if (FindData->HandleInformation)
242  {
243  /* Get the granted access and attributes */
244  GrantedAccess = HandleEntry->GrantedAccess;
245  HandleAttributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
246 
247  /* Attempt to match them */
248  if ((FindData->HandleInformation->HandleAttributes != HandleAttributes) ||
249  (FindData->HandleInformation->GrantedAccess != GrantedAccess))
250  {
251  /* No match, fail */
252  return FALSE;
253  }
254  }
255 
256  /* We have a match */
257  return TRUE;
258 }
POBJECT_HEADER ObjectHeader
Definition: ob.h:113
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
#define TRUE
Definition: types.h:120
POBJECT_TYPE ObjectType
Definition: ob.h:114
ACCESS_MASK GrantedAccess
Definition: iotypes.h:158
#define FALSE
Definition: types.h:117
#define ObpGetHandleObject(x)
Definition: ob.h:81
POBJECT_HANDLE_INFORMATION HandleInformation
Definition: ob.h:115
struct tagContext Context
Definition: acpixf.h:1014
unsigned int ULONG
Definition: retypes.h:1
POBJECT_TYPE Type
Definition: obtypes.h:493
#define OBJ_HANDLE_ATTRIBUTES
Definition: ob.h:52
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSTATUS NTAPI ObpIncrementHandleCount ( IN PVOID  Object,
IN PACCESS_STATE AccessState  OPTIONAL,
IN KPROCESSOR_MODE  AccessMode,
IN ULONG  HandleAttributes,
IN PEPROCESS  Process,
IN OB_OPEN_REASON  OpenReason 
)

Definition at line 808 of file obhandle.c.

Referenced by ObDuplicateObject(), ObpCreateHandle(), and ObpDuplicateHandleCallback().

814 {
815  POBJECT_HEADER ObjectHeader;
819  PEPROCESS ExclusiveProcess;
820  BOOLEAN Exclusive = FALSE, NewObject;
821  POBJECT_HEADER_CREATOR_INFO CreatorInfo;
822  KIRQL CalloutIrql;
824  ULONG Total;
825  POBJECT_HEADER_NAME_INFO NameInfo;
826  PAGED_CODE();
827 
828  /* Get the object header and type */
829  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
830  ObjectType = ObjectHeader->Type;
832  "%s - Incrementing count for: %p. Reason: %lx. HC PC %lx %lx\n",
833  __FUNCTION__,
834  Object,
835  OpenReason,
836  ObjectHeader->HandleCount,
837  ObjectHeader->PointerCount);
838 
839  /* Check if caller is forcing user mode */
841  {
842  /* Force it */
843  ProbeMode = UserMode;
844  }
845  else
846  {
847  /* Keep original setting */
848  ProbeMode = AccessMode;
849  }
850 
851  /* Lock the object */
852  ObpAcquireObjectLock(ObjectHeader);
853 
854  /* Charge quota and remove the creator info flag */
855  Status = ObpChargeQuotaForObject(ObjectHeader, ObjectType, &NewObject);
856  if (!NT_SUCCESS(Status)) return Status;
857 
858  /* Check if the open is exclusive */
860  {
861  /* Check if the object allows this, or if the inherit flag was given */
862  if ((HandleAttributes & OBJ_INHERIT) ||
863  !(ObjectHeader->Flags & OB_FLAG_EXCLUSIVE))
864  {
865  /* Incorrect attempt */
866  Status = STATUS_INVALID_PARAMETER;
867  goto Quickie;
868  }
869 
870  /* Check if we have access to it */
871  ExclusiveProcess = OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(ObjectHeader);
872  if ((!(ExclusiveProcess) && (ObjectHeader->HandleCount)) ||
873  ((ExclusiveProcess) && (ExclusiveProcess != PsGetCurrentProcess())))
874  {
875  /* This isn't the right process */
876  Status = STATUS_ACCESS_DENIED;
877  goto Quickie;
878  }
879 
880  /* Now you got exclusive access */
881  Exclusive = TRUE;
882  }
883  else if ((ObjectHeader->Flags & OB_FLAG_EXCLUSIVE) &&
884  (OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(ObjectHeader)))
885  {
886  /* Caller didn't want exclusive access, but the object is exclusive */
887  Status = STATUS_ACCESS_DENIED;
888  goto Quickie;
889  }
890 
891  /* Check for exclusive kernel object */
892  NameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
893  if ((NameInfo) && (NameInfo->QueryReferences & OB_FLAG_KERNEL_EXCLUSIVE) &&
894  (ProbeMode != KernelMode))
895  {
896  /* Caller is not kernel, but the object is kernel exclusive */
897  Status = STATUS_ACCESS_DENIED;
898  goto Quickie;
899  }
900 
901  /*
902  * Check if this is an object that went from 0 handles back to existence,
903  * but doesn't have an open procedure, only a close procedure. This means
904  * that it will never realize that the object is back alive, so we must
905  * fail the request.
906  */
907  if (!(ObjectHeader->HandleCount) &&
908  !(NewObject) &&
909  (ObjectType->TypeInfo.MaintainHandleCount) &&
910  !(ObjectType->TypeInfo.OpenProcedure) &&
911  (ObjectType->TypeInfo.CloseProcedure))
912  {
913  /* Fail */
914  Status = STATUS_UNSUCCESSFUL;
915  goto Quickie;
916  }
917 
918  /* Check if we're opening an existing handle */
919  if ((OpenReason == ObOpenHandle) ||
920  ((OpenReason == ObDuplicateHandle) && (AccessState)))
921  {
922  /* Validate the caller's access to this object */
924  AccessState,
925  TRUE,
926  ProbeMode,
927  &Status))
928  {
929  /* Access was denied, so fail */
930  goto Quickie;
931  }
932  }
933  else if (OpenReason == ObCreateHandle)
934  {
935  /* Convert MAXIMUM_ALLOWED to GENERIC_ALL */
936  if (AccessState->RemainingDesiredAccess & MAXIMUM_ALLOWED)
937  {
938  /* Mask out MAXIMUM_ALLOWED and stick GENERIC_ALL instead */
939  AccessState->RemainingDesiredAccess &= ~MAXIMUM_ALLOWED;
940  AccessState->RemainingDesiredAccess |= GENERIC_ALL;
941  }
942 
943  /* Check if we have to map the GENERIC mask */
944  if (AccessState->RemainingDesiredAccess & GENERIC_ACCESS)
945  {
946  /* Map it to the correct access masks */
947  RtlMapGenericMask(&AccessState->RemainingDesiredAccess,
948  &ObjectType->TypeInfo.GenericMapping);
949  }
950 
951  /* Check if the caller is trying to access system security */
952  if (AccessState->RemainingDesiredAccess & ACCESS_SYSTEM_SECURITY)
953  {
954  /* FIXME: TODO */
955  DPRINT1("ACCESS_SYSTEM_SECURITY not validated!\n");
956  }
957  }
958 
959  /* Check if this is an exclusive handle */
960  if (Exclusive)
961  {
962  /* Save the owner process */
963  OBJECT_HEADER_TO_QUOTA_INFO(ObjectHeader)->ExclusiveProcess = Process;
964  }
965 
966  /* Increase the handle count */
967  InterlockedIncrementSizeT(&ObjectHeader->HandleCount);
968  ProcessHandleCount = 0;
969 
970  /* Check if we have a handle database */
971  if (ObjectType->TypeInfo.MaintainHandleCount)
972  {
973  /* Increment the handle database */
974  Status = ObpIncrementHandleDataBase(ObjectHeader,
975  Process,
976  &ProcessHandleCount);
977  if (!NT_SUCCESS(Status))
978  {
979  /* FIXME: This should never happen for now */
980  DPRINT1("Unhandled case\n");
981  ASSERT(FALSE);
982  goto Quickie;
983  }
984  }
985 
986  /* Release the lock */
987  ObpReleaseObjectLock(ObjectHeader);
988 
989  /* Check if we have an open procedure */
990  Status = STATUS_SUCCESS;
991  if (ObjectType->TypeInfo.OpenProcedure)
992  {
993  /* Call it */
994  ObpCalloutStart(&CalloutIrql);
995  Status = ObjectType->TypeInfo.OpenProcedure(OpenReason,
996  Process,
997  Object,
998  AccessState ?
999  AccessState->
1001  0,
1002  ProcessHandleCount);
1003  ObpCalloutEnd(CalloutIrql, "Open", ObjectType, Object);
1004 
1005  /* Check if the open procedure failed */
1006  if (!NT_SUCCESS(Status))
1007  {
1008  /* FIXME: This should never happen for now */
1009  DPRINT1("Unhandled case\n");
1010  ASSERT(FALSE);
1011  return Status;
1012  }
1013  }
1014 
1015  /* Check if this is a create operation */
1016  if (OpenReason == ObCreateHandle)
1017  {
1018  /* Check if we have creator info */
1019  CreatorInfo = OBJECT_HEADER_TO_CREATOR_INFO(ObjectHeader);
1020  if (CreatorInfo)
1021  {
1022  /* We do, acquire the lock */
1023  ObpEnterObjectTypeMutex(ObjectType);
1024 
1025  /* Insert us on the list */
1026  InsertTailList(&ObjectType->TypeList, &CreatorInfo->TypeList);
1027 
1028  /* Release the lock */
1029  ObpLeaveObjectTypeMutex(ObjectType);
1030  }
1031  }
1032 
1033  /* Increase total number of handles */
1034  Total = InterlockedIncrement((PLONG)&ObjectType->TotalNumberOfHandles);
1035  if (Total > ObjectType->HighWaterNumberOfHandles)
1036  {
1037  /* Fixup count */
1038  ObjectType->HighWaterNumberOfHandles = Total;
1039  }
1040 
1041  /* Trace call and return */
1043  "%s - Incremented count for: %p. Reason: %lx HC PC %lx %lx\n",
1044  __FUNCTION__,
1045  Object,
1046  OpenReason,
1047  ObjectHeader->HandleCount,
1048  ObjectHeader->PointerCount);
1049  return Status;
1050 
1051 Quickie:
1052  /* Release lock and return */
1053  ObpReleaseObjectLock(ObjectHeader);
1054  return Status;
1055 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
ObjectType
Definition: metafile.c:80
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
#define GENERIC_ALL
Definition: nt_native.h:92
#define TRUE
Definition: types.h:120
FORCEINLINE VOID ObpAcquireObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:48
LONG_PTR HandleCount
Definition: obtypes.h:490
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI ObpChargeQuotaForObject(IN POBJECT_HEADER ObjectHeader, IN POBJECT_TYPE ObjectType, OUT PBOOLEAN NewObject)
Definition: obhandle.c:434
FORCEINLINE VOID ObpReleaseObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:84
#define GENERIC_ACCESS
Definition: wlx.c:26
_Must_inspect_result_ _In_ _In_ ULONG ProbeMode
Definition: mmfuncs.h:562
#define OBJECT_HEADER_TO_NAME_INFO(h)
Definition: obtypes.h:114
#define InsertTailList(ListHead, Entry)
#define PAGED_CODE()
Definition: video.h:57
ULONG TotalNumberOfHandles
Definition: obtypes.h:387
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define OBJ_FORCE_ACCESS_CHECK
Definition: winternl.h:232
#define FALSE
Definition: types.h:117
#define InterlockedIncrementSizeT(a)
Definition: interlocked.h:220
BOOLEAN MaintainHandleCount
Definition: obtypes.h:361
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define PsGetCurrentProcess
Definition: psfuncs.h:17
FORCEINLINE VOID ObpCalloutStart(IN PKIRQL CalloutIrql)
Definition: ob_x.h:429
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
UCHAR Flags
Definition: obtypes.h:497
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
#define OB_FLAG_EXCLUSIVE
Definition: obtypes.h:100
#define OBJECT_HEADER_TO_QUOTA_INFO(h)
Definition: obtypes.h:122
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define OBJ_INHERIT
Definition: winternl.h:225
FORCEINLINE VOID ObpEnterObjectTypeMutex(IN POBJECT_TYPE ObjectType)
Definition: ob_x.h:272
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
static IUnknown Object
Definition: main.c:512
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
FORCEINLINE VOID ObpLeaveObjectTypeMutex(IN POBJECT_TYPE ObjectType)
Definition: ob_x.h:284
FORCEINLINE VOID ObpCalloutEnd(IN KIRQL CalloutIrql, IN PCHAR Procedure, IN POBJECT_TYPE ObjectType, IN PVOID Object)
Definition: ob_x.h:437
OB_OPEN_METHOD OpenProcedure
Definition: obtypes.h:367
NTSTATUS NTAPI ObpIncrementHandleDataBase(IN POBJECT_HEADER ObjectHeader, IN PEPROCESS Process, IN OUT PULONG NewProcessHandleCount)
Definition: obhandle.c:336
#define OB_HANDLE_DEBUG
Definition: ob.h:17
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
ULONG HighWaterNumberOfHandles
Definition: obtypes.h:389
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI ObCheckObjectAccess(IN PVOID Object, IN OUT PACCESS_STATE AccessState, IN BOOLEAN LockHeld, IN KPROCESSOR_MODE AccessMode, OUT PNTSTATUS ReturnedStatus)
Definition: obsecure.c:441
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define InterlockedIncrement
Definition: armddk.h:53
#define OBJECT_HEADER_TO_CREATOR_INFO(h)
Definition: obtypes.h:126
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
LONG_PTR PointerCount
Definition: obtypes.h:487
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK PreviouslyGrantedAccess
Definition: sefuncs.h:13
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:71
#define OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(h)
Definition: obtypes.h:131
LIST_ENTRY TypeList
Definition: obtypes.h:382
return STATUS_SUCCESS
Definition: btrfs.c:2710
signed int * PLONG
Definition: retypes.h:5
#define OB_FLAG_KERNEL_EXCLUSIVE
Definition: obtypes.h:109
NTSYSAPI VOID NTAPI RtlMapGenericMask(PACCESS_MASK AccessMask, PGENERIC_MAPPING GenericMapping)
NTSTATUS NTAPI ObpIncrementHandleDataBase ( IN POBJECT_HEADER  ObjectHeader,
IN PEPROCESS  Process,
IN OUT PULONG  NewProcessHandleCount 
)

Definition at line 336 of file obhandle.c.

Referenced by ObpIncrementHandleCount(), and ObpIncrementUnnamedHandleCount().

339 {
340  POBJECT_HEADER_HANDLE_INFO HandleInfo;
341  POBJECT_HANDLE_COUNT_ENTRY HandleEntry, FreeEntry = NULL;
342  POBJECT_HANDLE_COUNT_DATABASE HandleDatabase;
343  ULONG i;
344  PAGED_CODE();
345 
346  /* Get the handle info and check if we only have one entry */
347  HandleInfo = OBJECT_HEADER_TO_HANDLE_INFO(ObjectHeader);
348  if (ObjectHeader->Flags & OB_FLAG_SINGLE_PROCESS)
349  {
350  /* Check if the entry is free */
351  if (!HandleInfo->SingleEntry.HandleCount)
352  {
353  /* Add ours */
354  HandleInfo->SingleEntry.HandleCount = 1;
355  HandleInfo->SingleEntry.Process = Process;
356 
357  /* Return success and 1 handle */
358  *NewProcessHandleCount = 1;
359  return STATUS_SUCCESS;
360  }
361  else if (HandleInfo->SingleEntry.Process == Process)
362  {
363  /* Busy entry, but same process */
364  *NewProcessHandleCount = ++HandleInfo->SingleEntry.HandleCount;
365  return STATUS_SUCCESS;
366  }
367  else
368  {
369  /* Insert a new entry */
370  FreeEntry = ObpInsertHandleCount(ObjectHeader);
371  if (!FreeEntry) return STATUS_INSUFFICIENT_RESOURCES;
372  ASSERT(!FreeEntry->Process);
373  ASSERT(!FreeEntry->HandleCount);
374 
375  /* Fill it out */
376  FreeEntry->Process = Process;
377  FreeEntry->HandleCount = 1;
378 
379  /* Return success and 1 handle */
380  *NewProcessHandleCount = 1;
381  return STATUS_SUCCESS;
382  }
383  }
384 
385  /* We have a database instead */
386  HandleDatabase = HandleInfo->HandleCountDatabase;
387  if (HandleDatabase)
388  {
389  /* Get the entries and loop them */
390  i = HandleDatabase->CountEntries;
391  HandleEntry = &HandleDatabase->HandleCountEntries[0];
392  while (i)
393  {
394  /* Check if this is a match */
395  if (HandleEntry->Process == Process)
396  {
397  /* Found it, get the process handle count */
398  *NewProcessHandleCount = ++HandleEntry->HandleCount;
399  return STATUS_SUCCESS;
400  }
401  else if (!HandleEntry->HandleCount)
402  {
403  /* Found a free entry */
404  FreeEntry = HandleEntry;
405  }
406 
407  /* Keep looping */
408  HandleEntry++;
409  i--;
410  }
411 
412  /* Check if we couldn't find a free entry */
413  if (!FreeEntry)
414  {
415  /* Allocate one */
416  FreeEntry = ObpInsertHandleCount(ObjectHeader);
417  if (!FreeEntry) return STATUS_INSUFFICIENT_RESOURCES;
418  ASSERT(!FreeEntry->Process);
419  ASSERT(!FreeEntry->HandleCount);
420  }
421 
422  /* Fill out the entry */
423  FreeEntry->Process = Process;
424  FreeEntry->HandleCount = 1;
425  *NewProcessHandleCount = 1;
426  }
427 
428  /* Return success if we got here */
429  return STATUS_SUCCESS;
430 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
POBJECT_HANDLE_COUNT_DATABASE HandleCountDatabase
Definition: obtypes.h:458
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define OBJECT_HEADER_TO_HANDLE_INFO(h)
Definition: obtypes.h:118
#define OB_FLAG_SINGLE_PROCESS
Definition: obtypes.h:103
#define PAGED_CODE()
Definition: video.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
ULONG HandleCount
Definition: obtypes.h:445
struct _EPROCESS * Process
Definition: obtypes.h:444
OBJECT_HANDLE_COUNT_ENTRY SingleEntry
Definition: obtypes.h:459
OBJECT_HANDLE_COUNT_ENTRY HandleCountEntries[1]
Definition: obtypes.h:451
Definition: obtypes.h:442
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2710
POBJECT_HANDLE_COUNT_ENTRY NTAPI ObpInsertHandleCount(IN POBJECT_HEADER ObjectHeader)
Definition: obhandle.c:262
NTSTATUS NTAPI ObpIncrementUnnamedHandleCount ( IN PVOID  Object,
IN PACCESS_MASK  DesiredAccess,
IN KPROCESSOR_MODE  AccessMode,
IN ULONG  HandleAttributes,
IN PEPROCESS  Process 
)

Definition at line 1087 of file obhandle.c.

Referenced by ObpCreateUnnamedHandle().

1092 {
1093  POBJECT_HEADER ObjectHeader;
1096  NTSTATUS Status;
1097  PEPROCESS ExclusiveProcess;
1098  BOOLEAN Exclusive = FALSE, NewObject;
1099  POBJECT_HEADER_CREATOR_INFO CreatorInfo;
1100  KIRQL CalloutIrql;
1101  ULONG Total;
1102 
1103  /* Get the object header and type */
1104  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
1105  ObjectType = ObjectHeader->Type;
1107  "%s - Incrementing count for: %p. UNNAMED. HC PC %lx %lx\n",
1108  __FUNCTION__,
1109  Object,
1110  ObjectHeader->HandleCount,
1111  ObjectHeader->PointerCount);
1112 
1113  /* Lock the object */
1114  ObpAcquireObjectLock(ObjectHeader);
1115 
1116  /* Charge quota and remove the creator info flag */
1117  Status = ObpChargeQuotaForObject(ObjectHeader, ObjectType, &NewObject);
1118  if (!NT_SUCCESS(Status)) return Status;
1119 
1120  /* Check if the open is exclusive */
1122  {
1123  /* Check if the object allows this, or if the inherit flag was given */
1124  if ((HandleAttributes & OBJ_INHERIT) ||
1125  !(ObjectHeader->Flags & OB_FLAG_EXCLUSIVE))
1126  {
1127  /* Incorrect attempt */
1128  Status = STATUS_INVALID_PARAMETER;
1129  goto Quickie;
1130  }
1131 
1132  /* Check if we have access to it */
1133  ExclusiveProcess = OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(ObjectHeader);
1134  if ((!(ExclusiveProcess) && (ObjectHeader->HandleCount)) ||
1135  ((ExclusiveProcess) && (ExclusiveProcess != PsGetCurrentProcess())))
1136  {
1137  /* This isn't the right process */
1138  Status = STATUS_ACCESS_DENIED;
1139  goto Quickie;
1140  }
1141 
1142  /* Now you got exclusive access */
1143  Exclusive = TRUE;
1144  }
1145  else if ((ObjectHeader->Flags & OB_FLAG_EXCLUSIVE) &&
1146  (OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(ObjectHeader)))
1147  {
1148  /* Caller didn't want exclusive access, but the object is exclusive */
1149  Status = STATUS_ACCESS_DENIED;
1150  goto Quickie;
1151  }
1152 
1153  /*
1154  * Check if this is an object that went from 0 handles back to existence,
1155  * but doesn't have an open procedure, only a close procedure. This means
1156  * that it will never realize that the object is back alive, so we must
1157  * fail the request.
1158  */
1159  if (!(ObjectHeader->HandleCount) &&
1160  !(NewObject) &&
1161  (ObjectType->TypeInfo.MaintainHandleCount) &&
1162  !(ObjectType->TypeInfo.OpenProcedure) &&
1163  (ObjectType->TypeInfo.CloseProcedure))
1164  {
1165  /* Fail */
1166  Status = STATUS_UNSUCCESSFUL;
1167  goto Quickie;
1168  }
1169 
1170  /* Convert MAXIMUM_ALLOWED to GENERIC_ALL */
1172  {
1173  /* Mask out MAXIMUM_ALLOWED and stick GENERIC_ALL instead */
1174  *DesiredAccess &= ~MAXIMUM_ALLOWED;
1176  }
1177 
1178  /* Check if we have to map the GENERIC mask */
1180  {
1181  /* Map it to the correct access masks */
1183  &ObjectType->TypeInfo.GenericMapping);
1184  }
1185 
1186  /* Check if this is an exclusive handle */
1187  if (Exclusive)
1188  {
1189  /* Save the owner process */
1190  OBJECT_HEADER_TO_QUOTA_INFO(ObjectHeader)->ExclusiveProcess = Process;
1191  }
1192 
1193  /* Increase the handle count */
1194  InterlockedIncrementSizeT(&ObjectHeader->HandleCount);
1195  ProcessHandleCount = 0;
1196 
1197  /* Check if we have a handle database */
1198  if (ObjectType->TypeInfo.MaintainHandleCount)
1199  {
1200  /* Increment the handle database */
1201  Status = ObpIncrementHandleDataBase(ObjectHeader,
1202  Process,
1203  &ProcessHandleCount);
1204  if (!NT_SUCCESS(Status))
1205  {
1206  /* FIXME: This should never happen for now */
1207  DPRINT1("Unhandled case\n");
1208  ASSERT(FALSE);
1209  goto Quickie;
1210  }
1211  }
1212 
1213  /* Release the lock */
1214  ObpReleaseObjectLock(ObjectHeader);
1215 
1216  /* Check if we have an open procedure */
1217  Status = STATUS_SUCCESS;
1218  if (ObjectType->TypeInfo.OpenProcedure)
1219  {
1220  /* Call it */
1221  ObpCalloutStart(&CalloutIrql);
1222  Status = ObjectType->TypeInfo.OpenProcedure(ObCreateHandle,
1223  Process,
1224  Object,
1225  *DesiredAccess,
1226  ProcessHandleCount);
1227  ObpCalloutEnd(CalloutIrql, "Open", ObjectType, Object);
1228 
1229  /* Check if the open procedure failed */
1230  if (!NT_SUCCESS(Status))
1231  {
1232  /* FIXME: This should never happen for now */
1233  DPRINT1("Unhandled case\n");
1234  ASSERT(FALSE);
1235  return Status;
1236  }
1237  }
1238 
1239  /* Check if we have creator info */
1240  CreatorInfo = OBJECT_HEADER_TO_CREATOR_INFO(ObjectHeader);
1241  if (CreatorInfo)
1242  {
1243  /* We do, acquire the lock */
1244  ObpEnterObjectTypeMutex(ObjectType);
1245 
1246  /* Insert us on the list */
1247  InsertTailList(&ObjectType->TypeList, &CreatorInfo->TypeList);
1248 
1249  /* Release the lock */
1250  ObpLeaveObjectTypeMutex(ObjectType);
1251  }
1252 
1253  /* Increase total number of handles */
1254  Total = InterlockedIncrement((PLONG)&ObjectType->TotalNumberOfHandles);
1255  if (Total > ObjectType->HighWaterNumberOfHandles)
1256  {
1257  /* Fixup count */
1258  ObjectType->HighWaterNumberOfHandles = Total;
1259  }
1260 
1261  /* Trace call and return */
1263  "%s - Incremented count for: %p. UNNAMED HC PC %lx %lx\n",
1264  __FUNCTION__,
1265  Object,
1266  ObjectHeader->HandleCount,
1267  ObjectHeader->PointerCount);
1268  return Status;
1269 
1270 Quickie:
1271  /* Release lock and return */
1272  ObpReleaseObjectLock(ObjectHeader);
1273  return Status;
1274 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
ObjectType
Definition: metafile.c:80
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
#define GENERIC_ALL
Definition: nt_native.h:92
#define TRUE
Definition: types.h:120
FORCEINLINE VOID ObpAcquireObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:48
LONG_PTR HandleCount
Definition: obtypes.h:490
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI ObpChargeQuotaForObject(IN POBJECT_HEADER ObjectHeader, IN POBJECT_TYPE ObjectType, OUT PBOOLEAN NewObject)
Definition: obhandle.c:434
FORCEINLINE VOID ObpReleaseObjectLock(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:84
#define GENERIC_ACCESS
Definition: wlx.c:26
#define InsertTailList(ListHead, Entry)
ULONG TotalNumberOfHandles
Definition: obtypes.h:387
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define InterlockedIncrementSizeT(a)
Definition: interlocked.h:220
BOOLEAN MaintainHandleCount
Definition: obtypes.h:361
#define PsGetCurrentProcess
Definition: psfuncs.h:17
FORCEINLINE VOID ObpCalloutStart(IN PKIRQL CalloutIrql)
Definition: ob_x.h:429
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
UCHAR Flags
Definition: obtypes.h:497
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
#define OB_FLAG_EXCLUSIVE
Definition: obtypes.h:100
#define OBJECT_HEADER_TO_QUOTA_INFO(h)
Definition: obtypes.h:122
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define OBJ_INHERIT
Definition: winternl.h:225
FORCEINLINE VOID ObpEnterObjectTypeMutex(IN POBJECT_TYPE ObjectType)
Definition: ob_x.h:272
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
static IUnknown Object
Definition: main.c:512
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
FORCEINLINE VOID ObpLeaveObjectTypeMutex(IN POBJECT_TYPE ObjectType)
Definition: ob_x.h:284
FORCEINLINE VOID ObpCalloutEnd(IN KIRQL CalloutIrql, IN PCHAR Procedure, IN POBJECT_TYPE ObjectType, IN PVOID Object)
Definition: ob_x.h:437
OB_OPEN_METHOD OpenProcedure
Definition: obtypes.h:367
NTSTATUS NTAPI ObpIncrementHandleDataBase(IN POBJECT_HEADER ObjectHeader, IN PEPROCESS Process, IN OUT PULONG NewProcessHandleCount)
Definition: obhandle.c:336
#define OB_HANDLE_DEBUG
Definition: ob.h:17
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
ULONG HighWaterNumberOfHandles
Definition: obtypes.h:389
Status
Definition: gdiplustypes.h:24
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define InterlockedIncrement
Definition: armddk.h:53
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define OBJECT_HEADER_TO_CREATOR_INFO(h)
Definition: obtypes.h:126
#define OBTRACE(x, fmt,...)
Definition: ob.h:34
LONG_PTR PointerCount
Definition: obtypes.h:487
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: compiler.h:205
POBJECT_TYPE Type
Definition: obtypes.h:493
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:71
#define OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(h)
Definition: obtypes.h:131
LIST_ENTRY TypeList
Definition: obtypes.h:382
return STATUS_SUCCESS
Definition: btrfs.c:2710
signed int * PLONG
Definition: retypes.h:5
NTSYSAPI VOID NTAPI RtlMapGenericMask(PACCESS_MASK AccessMask, PGENERIC_MAPPING GenericMapping)
POBJECT_HANDLE_COUNT_ENTRY NTAPI ObpInsertHandleCount ( IN POBJECT_HEADER  ObjectHeader)

Definition at line 262 of file obhandle.c.

Referenced by ObpIncrementHandleDataBase().

263 {
264  POBJECT_HEADER_HANDLE_INFO HandleInfo;
265  POBJECT_HANDLE_COUNT_ENTRY FreeEntry;
266  POBJECT_HANDLE_COUNT_DATABASE HandleDatabase, OldHandleDatabase;
267  ULONG i;
268  ULONG Size, OldSize;
269  OBJECT_HANDLE_COUNT_DATABASE SingleDatabase;
270  PAGED_CODE();
271 
272  /* Get the handle info */
273  HandleInfo = OBJECT_HEADER_TO_HANDLE_INFO(ObjectHeader);
274  if (!HandleInfo) return NULL;
275 
276  /* Check if we only have one entry */
277  if (ObjectHeader->Flags & OB_FLAG_SINGLE_PROCESS)
278  {
279  /* Fill out the single entry */
280  SingleDatabase.CountEntries = 1;
281  SingleDatabase.HandleCountEntries[0] = HandleInfo->SingleEntry;
282 
283  /* Use this as the old size */
284  OldHandleDatabase = &SingleDatabase;
285  OldSize = sizeof(SingleDatabase);
286 
287  /* Now we'll have two entries, and an entire DB */
288  i = 2;
289  Size = sizeof(OBJECT_HANDLE_COUNT_DATABASE) +
290  ((i - 1) * sizeof(OBJECT_HANDLE_COUNT_ENTRY));
291  }
292  else
293  {
294  /* We already have a DB, get the information from it */
295  OldHandleDatabase = HandleInfo->HandleCountDatabase;
296  i = OldHandleDatabase->CountEntries;
297  OldSize = sizeof(OBJECT_HANDLE_COUNT_DATABASE) +
298  ((i - 1) * sizeof(OBJECT_HANDLE_COUNT_ENTRY));
299 
300  /* Add 4 more entries */
301  i += 4;
302  Size = OldSize + (4 * sizeof(OBJECT_HANDLE_COUNT_ENTRY));
303  }
304 
305  /* Allocate the DB */
306  HandleDatabase = ExAllocatePoolWithTag(PagedPool, Size, TAG_OB_HANDLE);
307  if (!HandleDatabase) return NULL;
308 
309  /* Copy the old database */
310  RtlCopyMemory(HandleDatabase, OldHandleDatabase, OldSize);
311 
312  /* Check if we he had a single entry before */
313  if (ObjectHeader->Flags & OB_FLAG_SINGLE_PROCESS)
314  {
315  /* Now we have more */
316  ObjectHeader->Flags &= ~OB_FLAG_SINGLE_PROCESS;
317  }
318  else
319  {
320  /* Otherwise we had a DB, free it */
321  ExFreePoolWithTag(OldHandleDatabase, TAG_OB_HANDLE);
322  }
323 
324  /* Find the end of the copy and zero out the new data */
325  FreeEntry = (PVOID)((ULONG_PTR)HandleDatabase + OldSize);
326  RtlZeroMemory(FreeEntry, Size - OldSize);
327 
328  /* Set the new information and return the free entry */
329  HandleDatabase->CountEntries = i;
330  HandleInfo->HandleCountDatabase = HandleDatabase;
331  return FreeEntry;
332 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
POBJECT_HANDLE_COUNT_DATABASE HandleCountDatabase
Definition: obtypes.h:458
#define OBJECT_HEADER_TO_HANDLE_INFO(h)
Definition: obtypes.h:118
#define OB_FLAG_SINGLE_PROCESS
Definition: obtypes.h:103
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct _OBJECT_HANDLE_COUNT_ENTRY OBJECT_HANDLE_COUNT_ENTRY
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
UINTN Size
Definition: acefiex.h:555
OBJECT_HANDLE_COUNT_ENTRY SingleEntry
Definition: obtypes.h:459
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
OBJECT_HANDLE_COUNT_ENTRY HandleCountEntries[1]
Definition: obtypes.h:451
Definition: obtypes.h:442
#define TAG_OB_HANDLE
Definition: obhandle.c:23
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _OBJECT_HANDLE_COUNT_DATABASE OBJECT_HANDLE_COUNT_DATABASE
NTSTATUS NTAPI ObpReferenceProcessObjectByHandle ( IN HANDLE  Handle,
IN PEPROCESS  Process,
IN PHANDLE_TABLE  HandleTable,
IN KPROCESSOR_MODE  AccessMode,
OUT PVOID Object,
OUT POBJECT_HANDLE_INFORMATION  HandleInformation,
OUT PACCESS_MASK  AuditMask 
)

Definition at line 88 of file obhandle.c.

Referenced by ObDuplicateObject().

95 {
96  PHANDLE_TABLE_ENTRY HandleEntry;
97  POBJECT_HEADER ObjectHeader;
102 
103  /* Assume failure */
104  *Object = NULL;
105 
106  /* Check if this is a special handle */
107  if (HandleToLong(Handle) < 0)
108  {
109  /* Check if the caller wants the current process */
110  if (Handle == NtCurrentProcess())
111  {
112  /* Return handle info */
113  HandleInformation->HandleAttributes = 0;
114  HandleInformation->GrantedAccess = Process->GrantedAccess;
115 
116  /* No audit mask */
117  *AuditMask = 0;
118 
119  /* Reference ourselves */
120  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Process);
121  InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
122 
123  /* Return the pointer */
124  *Object = Process;
125  ASSERT(*Object != NULL);
126  return STATUS_SUCCESS;
127  }
128 
129  /* Check if the caller wants the current thread */
130  if (Handle == NtCurrentThread())
131  {
132  /* Return handle information */
133  HandleInformation->HandleAttributes = 0;
134  HandleInformation->GrantedAccess = Thread->GrantedAccess;
135 
136  /* Reference ourselves */
137  ObjectHeader = OBJECT_TO_OBJECT_HEADER(Thread);
138  InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
139 
140  /* No audit mask */
141  *AuditMask = 0;
142 
143  /* Return the pointer */
144  *Object = Thread;
145  ASSERT(*Object != NULL);
146  return STATUS_SUCCESS;
147  }
148 
149  /* This is a kernel handle... do we have access? */
150  if (AccessMode == KernelMode)
151  {
152  /* Use the kernel handle table and get the actual handle value */
155  }
156  else
157  {
158  /* This is an illegal attempt to access a kernel handle */
159  return STATUS_INVALID_HANDLE;
160  }
161  }
162 
163  /* Enter a critical region while we touch the handle table */
164  ASSERT(HandleTable != NULL);
166 
167  /* Get the handle entry */