ReactOS  0.4.14-dev-583-g2a1ba2c
util.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for util.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI RtlpGetStackLimits (PULONG_PTR StackBase, PULONG_PTR StackLimit)
 
NTSTATUS NTAPI IoComputeDesiredAccessFileObject (IN PFILE_OBJECT FileObject, IN PACCESS_MASK DesiredAccess)
 
VOID NTAPI IoAcquireCancelSpinLock (OUT PKIRQL Irql)
 
PVOID NTAPI IoGetInitialStack (VOID)
 
VOID NTAPI IoGetStackLimits (OUT PULONG_PTR LowLimit, OUT PULONG_PTR HighLimit)
 
BOOLEAN NTAPI IoIsSystemThread (IN PETHREAD Thread)
 
BOOLEAN NTAPI IoIsWdmVersionAvailable (IN UCHAR MajorVersion, IN UCHAR MinorVersion)
 
PEPROCESS NTAPI IoGetCurrentProcess (VOID)
 
VOID NTAPI IoReleaseCancelSpinLock (IN KIRQL Irql)
 
PEPROCESS NTAPI IoThreadToProcess (IN PETHREAD Thread)
 
NTSTATUS NTAPI IoCheckDesiredAccess (IN OUT PACCESS_MASK DesiredAccess, IN ACCESS_MASK GrantedAccess)
 
NTSTATUS NTAPI IoCheckEaBufferValidity (IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
 
NTSTATUS NTAPI IoCheckFunctionAccess (IN ACCESS_MASK GrantedAccess, IN UCHAR MajorFunction, IN UCHAR MinorFunction, IN ULONG IoControlCode, IN PVOID ExtraData OPTIONAL, IN PVOID ExtraData2 OPTIONAL)
 
NTSTATUS NTAPI IoValidateDeviceIoControlAccess (IN PIRP Irp, IN ULONG RequiredAccess)
 
VOID NTAPI IoSetDeviceToVerify (IN PETHREAD Thread, IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IoSetHardErrorOrVerifyDevice (IN PIRP Irp, IN PDEVICE_OBJECT DeviceObject)
 
PDEVICE_OBJECT NTAPI IoGetDeviceToVerify (IN PETHREAD Thread)
 
NTSTATUS NTAPI IoCheckQuerySetVolumeInformation (IN FS_INFORMATION_CLASS FsInformationClass, IN ULONG Length, IN BOOLEAN SetOperation)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file util.c.

Function Documentation

◆ IoAcquireCancelSpinLock()

VOID NTAPI IoAcquireCancelSpinLock ( OUT PKIRQL  Irql)

Definition at line 56 of file util.c.

57 {
58  /* Just acquire the internal lock */
60 }
_Out_ PKIRQL Irql
Definition: csq.h:179
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108

Referenced by BeepCleanup(), BeepStartIo(), DispPrepareIrpForCancel(), FsRtlAcknowledgeOplockBreak(), FsRtlNotifySetCancelRoutine(), FsRtlOplockBreakToII(), FsRtlOplockBreakToNone(), FsRtlOplockCleanup(), FsRtlRemoveAndCompleteIrp(), FsRtlRemoveAndCompleteWaitIrp(), FsRtlRequestExclusiveOplock(), FsRtlRequestOplockII(), FsRtlUninitializeOplock(), FsRtlWaitOnIrp(), HandleReadIrp(), IoCancelIrp(), IopStartNextPacket(), IopStartNextPacketByKey(), IoStartPacket(), IRPFinish(), KsAddIrpToCancelableQueue(), KsCancelIo(), KsMoveIrpsOnCancelableQueue(), KsReleaseIrpOnCancelableQueue(), KsRemoveIrpFromCancelableQueue(), MountMgrChangeNotify(), MountMgrCleanup(), MountMgrNotify(), NduDispatchRead(), QueueUserModeIrp(), RxCompleteRequest_Real(), RxFsdCommonDispatch(), USBH_CheckHubIdle(), USBH_FdoCleanup(), USBH_FdoIdleNotificationCallback(), USBH_FdoIdleNotificationRequestComplete(), USBH_FdoSubmitIdleRequestIrp(), USBH_FdoSubmitWaitWakeIrp(), USBH_FdoWWIrpIoCompletion(), USBH_HubQueuePortIdleIrps(), USBH_HubQueuePortWakeIrps(), USBH_PdoRemoveDevice(), USBH_PortIdleNotificationRequest(), USBPORT_DoneTransfer(), USBPORT_FlushCancelList(), USBSTOR_QueueAddIrp(), and USBSTOR_StartIo().

◆ IoCheckDesiredAccess()

NTSTATUS NTAPI IoCheckDesiredAccess ( IN OUT PACCESS_MASK  DesiredAccess,
IN ACCESS_MASK  GrantedAccess 
)

Definition at line 172 of file util.c.

174 {
175  PAGED_CODE();
176 
177  /* Map the generic mask */
180 
181  /* Fail if the access masks don't grant full access */
183  return STATUS_SUCCESS;
184 }
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
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
_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:2938
NTSYSAPI VOID NTAPI RtlMapGenericMask(PACCESS_MASK AccessMask, PGENERIC_MAPPING GenericMapping)

◆ IoCheckEaBufferValidity()

NTSTATUS NTAPI IoCheckEaBufferValidity ( IN PFILE_FULL_EA_INFORMATION  EaBuffer,
IN ULONG  EaLength,
OUT PULONG  ErrorOffset 
)

Definition at line 191 of file util.c.

194 {
195  ULONG NextEntryOffset;
196  UCHAR EaNameLength;
197  ULONG ComputedLength;
199 
200  PAGED_CODE();
201 
202  /* We will browse all the entries */
203  for (Current = EaBuffer; ; Current = (PFILE_FULL_EA_INFORMATION)((ULONG_PTR)Current + NextEntryOffset))
204  {
205  /* Check that we have enough bits left for the current entry */
207  {
208  goto FailPath;
209  }
210 
211  EaNameLength = Current->EaNameLength;
212  ComputedLength = Current->EaValueLength + EaNameLength + FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName) + 1;
213  /* Check that we have enough bits left for storing the name and its value */
214  if (EaLength < ComputedLength)
215  {
216  goto FailPath;
217  }
218 
219  /* Make sure the name is null terminated */
220  if (Current->EaName[EaNameLength] != ANSI_NULL)
221  {
222  goto FailPath;
223  }
224 
225  /* Get the next entry offset */
226  NextEntryOffset = Current->NextEntryOffset;
227  /* If it's 0, it's a termination case */
228  if (NextEntryOffset == 0)
229  {
230  /* If we don't overflow! */
231  if ((LONG)(EaLength - ComputedLength) < 0)
232  {
233  goto FailPath;
234  }
235 
236  break;
237  }
238 
239  /* Compare the next offset we computed with the provided one, they must match */
240  if (ALIGN_UP_BY(ComputedLength, sizeof(ULONG)) != NextEntryOffset)
241  {
242  goto FailPath;
243  }
244 
245  /* Check next entry offset value is positive */
246  if ((LONG)NextEntryOffset < 0)
247  {
248  goto FailPath;
249  }
250 
251  /* Compute the remaining bits */
252  EaLength -= NextEntryOffset;
253  /* We must have bits left */
254  if ((LONG)EaLength < 0)
255  {
256  goto FailPath;
257  }
258 
259  /* Move to the next entry */
260  }
261 
262  /* If we end here, everything went OK */
263  return STATUS_SUCCESS;
264 
265 FailPath:
266  /* If we end here, we failed, set failed offset */
267  *ErrorOffset = (ULONG_PTR)Current - (ULONG_PTR)EaBuffer;
269 }
struct _FILE_FULL_EA_INFORMATION * PFILE_FULL_EA_INFORMATION
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID EaBuffer
Definition: iofuncs.h:835
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define ANSI_NULL
long LONG
Definition: pedump.c:60
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
unsigned char UCHAR
Definition: xmlstorage.h:181
#define STATUS_EA_LIST_INCONSISTENT
Definition: IoEaTest.cpp:21
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define ALIGN_UP_BY(size, align)
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by _Dispatch_type_(), _tmain(), Ext2OverwriteEa(), Ext2SetEa(), FatCommonSetEa(), file_create(), fsctl_set_xattr(), get_ea_len(), IopCreateFile(), nfs41_SetEaInformation(), open_fcb(), and open_file2().

◆ IoCheckFunctionAccess()

NTSTATUS NTAPI IoCheckFunctionAccess ( IN ACCESS_MASK  GrantedAccess,
IN UCHAR  MajorFunction,
IN UCHAR  MinorFunction,
IN ULONG  IoControlCode,
IN PVOID ExtraData  OPTIONAL,
IN PVOID ExtraData2  OPTIONAL 
)

Definition at line 276 of file util.c.

282 {
284  return STATUS_NOT_IMPLEMENTED;
285 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by UDFCommonFileInfo(), UDFCommonQueryVolInfo(), and UDFCommonSetVolInfo().

◆ IoCheckQuerySetVolumeInformation()

NTSTATUS NTAPI IoCheckQuerySetVolumeInformation ( IN FS_INFORMATION_CLASS  FsInformationClass,
IN ULONG  Length,
IN BOOLEAN  SetOperation 
)

Definition at line 347 of file util.c.

350 {
352  return STATUS_NOT_IMPLEMENTED;
353 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

◆ IoComputeDesiredAccessFileObject()

NTSTATUS NTAPI IoComputeDesiredAccessFileObject ( IN PFILE_OBJECT  FileObject,
IN PACCESS_MASK  DesiredAccess 
)

Definition at line 26 of file util.c.

28 {
29  /* Assume failure */
30  *DesiredAccess = 0;
31 
32  /* First check we really have a FileObject */
34  {
36  }
37 
38  /* Then compute desired access:
39  * Check if the handle has either FILE_WRITE_DATA or FILE_APPEND_DATA was
40  * granted. However, if this is a named pipe, make sure we don't ask for
41  * FILE_APPEND_DATA as it interferes with the FILE_CREATE_PIPE_INSTANCE
42  * access right!
43  */
45 
46  return STATUS_SUCCESS;
47 }
Type
Definition: Type.h:6
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define FO_NAMED_PIPE
Definition: iotypes.h:1739
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:259
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
_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
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ObReferenceFileObjectForWrite().

◆ IoGetCurrentProcess()

PEPROCESS NTAPI IoGetCurrentProcess ( VOID  )

◆ IoGetDeviceToVerify()

PDEVICE_OBJECT NTAPI IoGetDeviceToVerify ( IN PETHREAD  Thread)

Definition at line 336 of file util.c.

337 {
338  /* Return the pointer that was set with IoSetDeviceToVerify */
339  return Thread->DeviceToVerify;
340 }
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PDEVICE_OBJECT DeviceToVerify
Definition: pstypes.h:1077

Referenced by _Requires_lock_held_(), Ext2ExceptionHandler(), FFSExceptionHandler(), RfsdExceptionHandler(), UDFExceptionHandler(), verify_vcb(), VfatBlockDeviceIoControl(), VfatReadDisk(), VfatReadDiskPartial(), VfatWriteDisk(), and VfatWriteDiskPartial().

◆ IoGetInitialStack()

PVOID NTAPI IoGetInitialStack ( VOID  )

Definition at line 67 of file util.c.

68 {
69  /* Return the initial stack from the TCB */
70  return PsGetCurrentThread()->Tcb.InitialStack;
71 }
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81

◆ IoGetStackLimits()

VOID NTAPI IoGetStackLimits ( OUT PULONG_PTR  LowLimit,
OUT PULONG_PTR  HighLimit 
)

Definition at line 78 of file util.c.

80 {
81  PKPRCB Prcb = KeGetCurrentPrcb();
82  ULONG_PTR DpcStack = (ULONG_PTR)(Prcb->DpcStack);
83  volatile ULONG_PTR StackAddress;
84 
85  /* Save our stack address so we always know it's valid */
86  StackAddress = (ULONG_PTR)(&StackAddress);
87 
88  /* Get stack values */
89  RtlpGetStackLimits(LowLimit, HighLimit);
90 
91  /* Check if we're outside the stack */
92  if ((StackAddress < *LowLimit) || (StackAddress > *HighLimit))
93  {
94  /* Check if we may be in a DPC */
96  {
97  /* Check if we really are in a DPC */
98  if ((Prcb->DpcRoutineActive) &&
99  (StackAddress <= DpcStack) &&
100  (StackAddress >= DpcStack - KERNEL_STACK_SIZE))
101  {
102  /* Use the DPC stack limits */
103  *HighLimit = DpcStack;
104  *LowLimit = DpcStack - KERNEL_STACK_SIZE;
105  }
106  }
107  }
108 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_Out_ PULONG_PTR HighLimit
Definition: iofuncs.h:2837
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define KERNEL_STACK_SIZE
UCHAR DpcRoutineActive
Definition: ketypes.h:688
VOID NTAPI RtlpGetStackLimits(PULONG_PTR StackBase, PULONG_PTR StackLimit)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PVOID DpcStack
Definition: ketypes.h:677
#define ULONG_PTR
Definition: config.h:101

Referenced by _IRQL_requires_max_(), CdSetThreadContext(), FatFreeStringBuffer(), RxIsThisAnRdbssTopLevelContext(), and RxSetupNetFileObject().

◆ IoIsSystemThread()

BOOLEAN NTAPI IoIsSystemThread ( IN PETHREAD  Thread)

Definition at line 115 of file util.c.

116 {
117  /* Call the Ps Function */
118  return PsIsSystemThread(Thread);
119 }
BOOLEAN NTAPI PsIsSystemThread(IN PETHREAD Thread)
Definition: thread.c:878
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653

Referenced by _Requires_lock_held_(), do_read(), FatUpdateDiskStats(), and write_file().

◆ IoIsWdmVersionAvailable()

BOOLEAN NTAPI IoIsWdmVersionAvailable ( IN UCHAR  MajorVersion,
IN UCHAR  MinorVersion 
)

Definition at line 126 of file util.c.

128 {
129  /* Return support for WDM 1.30 (Windows Server 2003) */
130  if (MajorVersion <= 1 && MinorVersion <= 0x30) return TRUE;
131  return FALSE;
132 }
#define TRUE
Definition: types.h:120
ULONG MinorVersion
Definition: ros_glue.cpp:5
ULONG MajorVersion
Definition: ros_glue.cpp:4

Referenced by DriverEntry(), FreeBT_AddDevice(), StartDevice(), and CMiniportWaveCMI::validateFormat().

◆ IoReleaseCancelSpinLock()

VOID NTAPI IoReleaseCancelSpinLock ( IN KIRQL  Irql)

Definition at line 150 of file util.c.

151 {
152  /* Release the internal lock */
154 }
_Out_ PKIRQL Irql
Definition: csq.h:179
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154

Referenced by _Function_class_(), AfdCancelHandler(), BeepCancel(), BeepCleanup(), BeepStartIo(), CancelQueued(), CancelRoutine(), ClassCancelRoutine(), DispCancelListenRequest(), DispCancelRequest(), DispPrepareIrpForCancel(), FsRtlAcknowledgeOplockBreak(), FsRtlCancelExclusiveIrp(), FsRtlCancelNotify(), FsRtlCancelOplockIIIrp(), FsRtlCancelWaitIrp(), FsRtlNotifySetCancelRoutine(), FsRtlOplockBreakToII(), FsRtlOplockBreakToNone(), FsRtlOplockCleanup(), FsRtlRemoveAndCompleteIrp(), FsRtlRemoveAndCompleteWaitIrp(), FsRtlRequestExclusiveOplock(), FsRtlRequestOplockII(), FsRtlUninitializeOplock(), FsRtlWaitOnIrp(), HandleReadIrp(), IoCancelIrp(), IopStartNextPacket(), IopStartNextPacketByKey(), IoStartPacket(), IRPFinish(), KsCancelRoutine(), KsMoveIrpsOnCancelableQueue(), KsRemoveIrpFromCancelableQueue(), MountMgrCancel(), MountMgrChangeNotify(), MountMgrCleanup(), MountMgrNotify(), NduDispatchRead(), NpCancelDataQueueIrp(), NpCancelListeningQueueIrp(), NpCancelWaitQueueIrp(), QueueUserModeIrp(), ReadIrpCancel(), RxCancelRoutine(), RxCompleteRequest_Real(), RxFsdCommonDispatch(), USBH_CheckHubIdle(), USBH_FdoCleanup(), USBH_FdoIdleNotificationCallback(), USBH_FdoIdleNotificationRequestComplete(), USBH_FdoSubmitIdleRequestIrp(), USBH_FdoSubmitWaitWakeIrp(), USBH_FdoWWIrpIoCompletion(), USBH_HubQueuePortIdleIrps(), USBH_HubQueuePortWakeIrps(), USBH_PdoRemoveDevice(), USBH_PortIdleNotificationCancelRoutine(), USBH_PortIdleNotificationRequest(), USBPORT_CancelActiveTransferIrp(), USBPORT_CancelPendingTransferIrp(), USBPORT_CancelPendingWakeIrp(), USBPORT_DoneTransfer(), USBPORT_FlushCancelList(), USBSTOR_Cancel(), USBSTOR_CancelIo(), USBSTOR_QueueAddIrp(), USBSTOR_StartIo(), and WmipNotificationIrpCancel().

◆ IoSetDeviceToVerify()

VOID NTAPI IoSetDeviceToVerify ( IN PETHREAD  Thread,
IN PDEVICE_OBJECT  DeviceObject 
)

Definition at line 304 of file util.c.

306 {
307  /* Set the pointer in the thread */
309 }
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PDEVICE_OBJECT DeviceToVerify
Definition: pstypes.h:1077
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by _Requires_lock_held_(), Ext2ExceptionHandler(), FFSExceptionHandler(), RfsdExceptionHandler(), UDFExceptionHandler(), verify_vcb(), VfatBlockDeviceIoControl(), VfatReadDisk(), VfatReadDiskPartial(), VfatWriteDisk(), and VfatWriteDiskPartial().

◆ IoSetHardErrorOrVerifyDevice()

VOID NTAPI IoSetHardErrorOrVerifyDevice ( IN PIRP  Irp,
IN PDEVICE_OBJECT  DeviceObject 
)

◆ IoThreadToProcess()

PEPROCESS NTAPI IoThreadToProcess ( IN PETHREAD  Thread)

Definition at line 161 of file util.c.

162 {
163  /* Return the thread's process */
164  return Thread->ThreadsProcess;
165 }
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653

Referenced by NpCreateClientEnd().

◆ IoValidateDeviceIoControlAccess()

NTSTATUS NTAPI IoValidateDeviceIoControlAccess ( IN PIRP  Irp,
IN ULONG  RequiredAccess 
)

Definition at line 292 of file util.c.

294 {
296  return STATUS_NOT_IMPLEMENTED;
297 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

◆ RtlpGetStackLimits()

VOID NTAPI RtlpGetStackLimits ( PULONG_PTR  StackBase,
PULONG_PTR  StackLimit 
)