mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
convert DefaultSetInfoBufferCheck and DefaultQueryInfoBufferCheck to inlined functions
svn path=/trunk/; revision=18394
This commit is contained in:
parent
e0191cfd2a
commit
eb03a7e427
10 changed files with 200 additions and 229 deletions
|
@ -311,13 +311,13 @@ NtQueryEvent(IN HANDLE EventHandle,
|
|||
DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
|
||||
|
||||
/* Check buffers and class validity */
|
||||
DefaultQueryInfoBufferCheck(EventInformationClass,
|
||||
ExEventInfoClass,
|
||||
EventInformation,
|
||||
EventInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(EventInformationClass,
|
||||
ExEventInfoClass,
|
||||
sizeof(ExEventInfoClass) / sizeof(ExEventInfoClass[0]),
|
||||
EventInformation,
|
||||
EventInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status)) {
|
||||
|
||||
/* Invalid buffers */
|
||||
|
|
|
@ -227,13 +227,13 @@ NtQueryMutant(IN HANDLE MutantHandle,
|
|||
PAGED_CODE();
|
||||
|
||||
/* Check buffers and parameters */
|
||||
DefaultQueryInfoBufferCheck(MutantInformationClass,
|
||||
ExMutantInfoClass,
|
||||
MutantInformation,
|
||||
MutantInformationLength,
|
||||
ResultLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(MutantInformationClass,
|
||||
ExMutantInfoClass,
|
||||
sizeof(ExMutantInfoClass) / sizeof(ExMutantInfoClass[0]),
|
||||
MutantInformation,
|
||||
MutantInformationLength,
|
||||
ResultLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status)) {
|
||||
|
||||
DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);
|
||||
|
|
|
@ -215,13 +215,13 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle,
|
|||
PAGED_CODE();
|
||||
|
||||
/* Check buffers and class validity */
|
||||
DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
|
||||
ExSemaphoreInfoClass,
|
||||
SemaphoreInformation,
|
||||
SemaphoreInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
|
||||
ExSemaphoreInfoClass,
|
||||
sizeof(ExSemaphoreInfoClass) / sizeof(ExSemaphoreInfoClass[0]),
|
||||
SemaphoreInformation,
|
||||
SemaphoreInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Invalid buffers */
|
||||
|
|
|
@ -545,13 +545,13 @@ NtQueryTimer(IN HANDLE TimerHandle,
|
|||
DPRINT("NtQueryTimer(TimerHandle: 0x%p, Class: %d)\n", TimerHandle, TimerInformationClass);
|
||||
|
||||
/* Check Validity */
|
||||
DefaultQueryInfoBufferCheck(TimerInformationClass,
|
||||
ExTimerInfoClass,
|
||||
TimerInformation,
|
||||
TimerInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(TimerInformationClass,
|
||||
ExTimerInfoClass,
|
||||
sizeof(ExTimerInfoClass) / sizeof(ExTimerInfoClass[0]),
|
||||
TimerInformation,
|
||||
TimerInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("NtQueryTimer() failed, Status: 0x%x\n", Status);
|
||||
|
|
|
@ -207,6 +207,138 @@ ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString,
|
|||
#define ProbeForReadLargeInteger(Ptr) ((LARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, LONGLONG, 0))
|
||||
#define ProbeForReadUlargeInteger(Ptr) ((ULARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, ULONGLONG, 0))
|
||||
|
||||
/*
|
||||
* generic information class probing code
|
||||
*/
|
||||
|
||||
#define ICIF_QUERY 0x1
|
||||
#define ICIF_SET 0x2
|
||||
#define ICIF_QUERY_SIZE_VARIABLE 0x4
|
||||
#define ICIF_SET_SIZE_VARIABLE 0x8
|
||||
#define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
|
||||
|
||||
typedef struct _INFORMATION_CLASS_INFO
|
||||
{
|
||||
ULONG RequiredSizeQUERY;
|
||||
ULONG RequiredSizeSET;
|
||||
ULONG AlignmentSET;
|
||||
ULONG AlignmentQUERY;
|
||||
ULONG Flags;
|
||||
} INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
|
||||
|
||||
#define ICI_SQ_SAME(Size, Alignment, Flags) \
|
||||
{ Size, Size, Alignment, Alignment, Flags }
|
||||
|
||||
#define ICI_SQ(SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags) \
|
||||
{ SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags }
|
||||
|
||||
static inline NTSTATUS
|
||||
DefaultSetInfoBufferCheck(UINT Class,
|
||||
const INFORMATION_CLASS_INFO *ClassList,
|
||||
UINT ClassListEntries,
|
||||
PVOID Buffer,
|
||||
ULONG BufferLength,
|
||||
KPROCESSOR_MODE PreviousMode)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
if (Class >= 0 && Class < ClassListEntries)
|
||||
{
|
||||
if (!(ClassList[Class].Flags & ICIF_SET))
|
||||
{
|
||||
Status = STATUS_INVALID_INFO_CLASS;
|
||||
}
|
||||
else if (ClassList[Class].RequiredSizeSET > 0 &&
|
||||
BufferLength != ClassList[Class].RequiredSizeSET)
|
||||
{
|
||||
if (!(ClassList[Class].Flags & ICIF_SET_SIZE_VARIABLE))
|
||||
{
|
||||
Status = STATUS_INFO_LENGTH_MISMATCH;
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
if (PreviousMode != KernelMode)
|
||||
{
|
||||
_SEH_TRY
|
||||
{
|
||||
ProbeForRead(Buffer,
|
||||
BufferLength,
|
||||
ClassList[Class].AlignmentSET);
|
||||
}
|
||||
_SEH_HANDLE
|
||||
{
|
||||
Status = _SEH_GetExceptionCode();
|
||||
}
|
||||
_SEH_END;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Status = STATUS_INVALID_INFO_CLASS;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
static inline NTSTATUS
|
||||
DefaultQueryInfoBufferCheck(UINT Class,
|
||||
const INFORMATION_CLASS_INFO *ClassList,
|
||||
UINT ClassListEntries,
|
||||
PVOID Buffer,
|
||||
ULONG BufferLength,
|
||||
PULONG ReturnLength,
|
||||
KPROCESSOR_MODE PreviousMode)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
if (Class >= 0 && Class < ClassListEntries)
|
||||
{
|
||||
if (!(ClassList[Class].Flags & ICIF_QUERY))
|
||||
{
|
||||
Status = STATUS_INVALID_INFO_CLASS;
|
||||
}
|
||||
else if (ClassList[Class].RequiredSizeQUERY > 0 &&
|
||||
BufferLength != ClassList[Class].RequiredSizeQUERY)
|
||||
{
|
||||
if (!(ClassList[Class].Flags & ICIF_QUERY_SIZE_VARIABLE))
|
||||
{
|
||||
Status = STATUS_INFO_LENGTH_MISMATCH;
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
if (PreviousMode != KernelMode)
|
||||
{
|
||||
_SEH_TRY
|
||||
{
|
||||
if (Buffer != NULL)
|
||||
{
|
||||
ProbeForWrite(Buffer,
|
||||
BufferLength,
|
||||
ClassList[Class].AlignmentQUERY);
|
||||
}
|
||||
|
||||
if (ReturnLength != NULL)
|
||||
{
|
||||
ProbeForWriteUlong(ReturnLength);
|
||||
}
|
||||
}
|
||||
_SEH_HANDLE
|
||||
{
|
||||
Status = _SEH_GetExceptionCode();
|
||||
}
|
||||
_SEH_END;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Status = STATUS_INVALID_INFO_CLASS;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use IsPointerOffset to test whether a pointer should be interpreted as an offset
|
||||
* or as a pointer
|
||||
|
|
|
@ -11,12 +11,6 @@
|
|||
|
||||
struct _EPROCESS;
|
||||
|
||||
#define ICIF_QUERY 0x1
|
||||
#define ICIF_SET 0x2
|
||||
#define ICIF_QUERY_SIZE_VARIABLE 0x4
|
||||
#define ICIF_SET_SIZE_VARIABLE 0x8
|
||||
#define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
|
||||
|
||||
typedef struct _DIRECTORY_OBJECT
|
||||
{
|
||||
CSHORT Type;
|
||||
|
@ -37,15 +31,6 @@ typedef struct _SYMLINK_OBJECT
|
|||
LARGE_INTEGER CreateTime;
|
||||
} SYMLINK_OBJECT, *PSYMLINK_OBJECT;
|
||||
|
||||
typedef struct _INFORMATION_CLASS_INFO
|
||||
{
|
||||
ULONG RequiredSizeQUERY;
|
||||
ULONG RequiredSizeSET;
|
||||
ULONG AlignmentSET;
|
||||
ULONG AlignmentQUERY;
|
||||
ULONG Flags;
|
||||
} INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
|
||||
|
||||
#define BODY_TO_HEADER(objbdy) \
|
||||
CONTAINING_RECORD((objbdy), OBJECT_HEADER, Body)
|
||||
|
||||
|
@ -251,152 +236,6 @@ ObpReleaseCapturedAttributes(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo);
|
|||
|
||||
/* object information classes */
|
||||
|
||||
#define ICI_SQ_SAME(Size, Alignment, Flags) \
|
||||
{ Size, Size, Alignment, Alignment, Flags }
|
||||
|
||||
#define ICI_SQ(SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags) \
|
||||
{ SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags }
|
||||
|
||||
#define CheckInfoClass(Class, BufferLen, ClassList, StatusVar, Mode) \
|
||||
do { \
|
||||
if((Class) >= 0 && (Class) < sizeof(ClassList) / sizeof(ClassList[0])) \
|
||||
{ \
|
||||
if(!(ClassList[Class].Flags & ICIF_##Mode)) \
|
||||
{ \
|
||||
*(StatusVar) = STATUS_INVALID_INFO_CLASS; \
|
||||
} \
|
||||
else if(ClassList[Class].RequiredSize##Mode > 0 && \
|
||||
(BufferLen) != ClassList[Class].RequiredSize##Mode) \
|
||||
{ \
|
||||
if(!(ClassList[Class].Flags & ICIF_##Mode##_SIZE_VARIABLE) && \
|
||||
(BufferLen) != ClassList[Class].RequiredSize##Mode) \
|
||||
{ \
|
||||
*(StatusVar) = STATUS_INFO_LENGTH_MISMATCH; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
*(StatusVar) = STATUS_INVALID_INFO_CLASS; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define GetInfoClassAlignment(Class, ClassList, AlignmentVar, Mode) \
|
||||
do { \
|
||||
if((Class) >= 0 && (Class) < sizeof(ClassList) / sizeof(ClassList[0])) \
|
||||
{ \
|
||||
*(AlignmentVar) = ClassList[Class].Alignment##Mode; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
*(AlignmentVar) = sizeof(ULONG); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ProbeQueryInfoBuffer(Buffer, BufferLen, Alignment, RetLen, PrevMode, StatusVar) \
|
||||
do { \
|
||||
if(PrevMode != KernelMode) \
|
||||
{ \
|
||||
_SEH_TRY \
|
||||
{ \
|
||||
ProbeForWrite(Buffer, \
|
||||
BufferLen, \
|
||||
Alignment); \
|
||||
if(RetLen != NULL) \
|
||||
{ \
|
||||
ProbeForWrite(RetLen, \
|
||||
sizeof(ULONG), \
|
||||
1); \
|
||||
} \
|
||||
} \
|
||||
_SEH_HANDLE \
|
||||
{ \
|
||||
*(StatusVar) = _SEH_GetExceptionCode(); \
|
||||
} \
|
||||
_SEH_END; \
|
||||
\
|
||||
if(!NT_SUCCESS(*(StatusVar))) \
|
||||
{ \
|
||||
DPRINT1("ProbeQueryInfoBuffer failed: 0x%x\n", *(StatusVar)); \
|
||||
return *(StatusVar); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ProbeSetInfoBuffer(Buffer, BufferLen, Alignment, PrevMode, StatusVar) \
|
||||
do { \
|
||||
if(PrevMode != KernelMode) \
|
||||
{ \
|
||||
_SEH_TRY \
|
||||
{ \
|
||||
ProbeForRead(Buffer, \
|
||||
BufferLen, \
|
||||
Alignment); \
|
||||
} \
|
||||
_SEH_HANDLE \
|
||||
{ \
|
||||
*(StatusVar) = _SEH_GetExceptionCode(); \
|
||||
} \
|
||||
_SEH_END; \
|
||||
\
|
||||
if(!NT_SUCCESS(*(StatusVar))) \
|
||||
{ \
|
||||
DPRINT1("ProbeAllInfoBuffer failed: 0x%x\n", *(StatusVar)); \
|
||||
return *(StatusVar); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define DefaultSetInfoBufferCheck(Class, ClassList, Buffer, BufferLen, PrevMode, StatusVar) \
|
||||
do { \
|
||||
ULONG _Alignment; \
|
||||
/* get the preferred alignment for the information class or return */ \
|
||||
/* default alignment in case the class doesn't exist */ \
|
||||
GetInfoClassAlignment(Class, \
|
||||
ClassList, \
|
||||
&_Alignment, \
|
||||
SET); \
|
||||
\
|
||||
/* probe the ENTIRE buffers and return on failure */ \
|
||||
ProbeSetInfoBuffer(Buffer, \
|
||||
BufferLen, \
|
||||
_Alignment, \
|
||||
PrevMode, \
|
||||
StatusVar); \
|
||||
\
|
||||
/* validate information class index and check buffer size */ \
|
||||
CheckInfoClass(Class, \
|
||||
BufferLen, \
|
||||
ClassList, \
|
||||
StatusVar, \
|
||||
SET); \
|
||||
} while(0)
|
||||
|
||||
#define DefaultQueryInfoBufferCheck(Class, ClassList, Buffer, BufferLen, RetLen, PrevMode, StatusVar) \
|
||||
do { \
|
||||
ULONG _Alignment; \
|
||||
/* get the preferred alignment for the information class or return */ \
|
||||
/* alignment in case the class doesn't exist */ \
|
||||
GetInfoClassAlignment(Class, \
|
||||
ClassList, \
|
||||
&_Alignment, \
|
||||
QUERY); \
|
||||
\
|
||||
/* probe the ENTIRE buffers and return on failure */ \
|
||||
ProbeQueryInfoBuffer(Buffer, \
|
||||
BufferLen, \
|
||||
_Alignment, \
|
||||
RetLen, \
|
||||
PrevMode, \
|
||||
StatusVar); \
|
||||
\
|
||||
/* validate information class index and check buffer size */ \
|
||||
CheckInfoClass(Class, \
|
||||
BufferLen, \
|
||||
ClassList, \
|
||||
StatusVar, \
|
||||
QUERY); \
|
||||
} while(0)
|
||||
|
||||
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */
|
||||
|
|
|
@ -359,13 +359,13 @@ NtQueryIoCompletion(IN HANDLE IoCompletionHandle,
|
|||
PAGED_CODE();
|
||||
|
||||
/* Check buffers and parameters */
|
||||
DefaultQueryInfoBufferCheck(IoCompletionInformationClass,
|
||||
IoCompletionInfoClass,
|
||||
IoCompletionInformation,
|
||||
IoCompletionInformationLength,
|
||||
ResultLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(IoCompletionInformationClass,
|
||||
IoCompletionInfoClass,
|
||||
sizeof(IoCompletionInfoClass) / sizeof(IoCompletionInfoClass[0]),
|
||||
IoCompletionInformation,
|
||||
IoCompletionInformationLength,
|
||||
ResultLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status)) {
|
||||
|
||||
DPRINT1("NtQueryMutant() failed, Status: 0x%x\n", Status);
|
||||
|
|
|
@ -4012,13 +4012,13 @@ NtQuerySection(IN HANDLE SectionHandle,
|
|||
|
||||
PreviousMode = ExGetPreviousMode();
|
||||
|
||||
DefaultQueryInfoBufferCheck(SectionInformationClass,
|
||||
ExSectionInfoClass,
|
||||
SectionInformation,
|
||||
SectionInformationLength,
|
||||
ResultLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(SectionInformationClass,
|
||||
ExSectionInfoClass,
|
||||
sizeof(ExSectionInfoClass) / sizeof(ExSectionInfoClass[0]),
|
||||
SectionInformation,
|
||||
SectionInformationLength,
|
||||
ResultLength,
|
||||
PreviousMode);
|
||||
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
|
|
|
@ -143,13 +143,13 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
|
|||
|
||||
PreviousMode = ExGetPreviousMode();
|
||||
|
||||
DefaultQueryInfoBufferCheck(ProcessInformationClass,
|
||||
PsProcessInfoClass,
|
||||
ProcessInformation,
|
||||
ProcessInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(ProcessInformationClass,
|
||||
PsProcessInfoClass,
|
||||
sizeof(PsProcessInfoClass) / sizeof(PsProcessInfoClass[0]),
|
||||
ProcessInformation,
|
||||
ProcessInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("NtQueryInformationProcess() failed, Status: 0x%x\n", Status);
|
||||
|
@ -654,12 +654,12 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
|
|||
|
||||
PreviousMode = ExGetPreviousMode();
|
||||
|
||||
DefaultSetInfoBufferCheck(ProcessInformationClass,
|
||||
PsProcessInfoClass,
|
||||
ProcessInformation,
|
||||
ProcessInformationLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultSetInfoBufferCheck(ProcessInformationClass,
|
||||
PsProcessInfoClass,
|
||||
sizeof(PsProcessInfoClass) / sizeof(PsProcessInfoClass[0]),
|
||||
ProcessInformation,
|
||||
ProcessInformationLength,
|
||||
PreviousMode);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("NtSetInformationProcess() %d %x %x called\n", ProcessInformationClass, ProcessInformation, ProcessInformationLength);
|
||||
|
|
|
@ -615,13 +615,13 @@ NtQueryInformationToken(IN HANDLE TokenHandle,
|
|||
PreviousMode = ExGetPreviousMode();
|
||||
|
||||
/* Check buffers and class validity */
|
||||
DefaultQueryInfoBufferCheck(TokenInformationClass,
|
||||
SeTokenInformationClass,
|
||||
TokenInformation,
|
||||
TokenInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultQueryInfoBufferCheck(TokenInformationClass,
|
||||
SeTokenInformationClass,
|
||||
sizeof(SeTokenInformationClass) / sizeof(SeTokenInformationClass[0]),
|
||||
TokenInformation,
|
||||
TokenInformationLength,
|
||||
ReturnLength,
|
||||
PreviousMode);
|
||||
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
|
@ -1198,12 +1198,12 @@ NtSetInformationToken(IN HANDLE TokenHandle,
|
|||
|
||||
PreviousMode = ExGetPreviousMode();
|
||||
|
||||
DefaultSetInfoBufferCheck(TokenInformationClass,
|
||||
SeTokenInformationClass,
|
||||
TokenInformation,
|
||||
TokenInformationLength,
|
||||
PreviousMode,
|
||||
&Status);
|
||||
Status = DefaultSetInfoBufferCheck(TokenInformationClass,
|
||||
SeTokenInformationClass,
|
||||
sizeof(SeTokenInformationClass) / sizeof(SeTokenInformationClass[0]),
|
||||
TokenInformation,
|
||||
TokenInformationLength,
|
||||
PreviousMode);
|
||||
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue