From: Thomas Bluemel Date: Mon, 10 Oct 2005 13:03:55 +0000 (+0000) Subject: convert DefaultSetInfoBufferCheck and DefaultQueryInfoBufferCheck to inlined functions X-Git-Tag: ReactOS-0.2.8~33 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=eb03a7e427bca6977ed7901331f648090d732fee convert DefaultSetInfoBufferCheck and DefaultQueryInfoBufferCheck to inlined functions svn path=/trunk/; revision=18394 --- diff --git a/reactos/ntoskrnl/ex/event.c b/reactos/ntoskrnl/ex/event.c index 7fbfb3790a8..2eb0ac1e82b 100644 --- a/reactos/ntoskrnl/ex/event.c +++ b/reactos/ntoskrnl/ex/event.c @@ -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 */ diff --git a/reactos/ntoskrnl/ex/mutant.c b/reactos/ntoskrnl/ex/mutant.c index 62391e44f1b..b2c0f88a07f 100644 --- a/reactos/ntoskrnl/ex/mutant.c +++ b/reactos/ntoskrnl/ex/mutant.c @@ -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); diff --git a/reactos/ntoskrnl/ex/sem.c b/reactos/ntoskrnl/ex/sem.c index bb4614ea593..427f4d57051 100644 --- a/reactos/ntoskrnl/ex/sem.c +++ b/reactos/ntoskrnl/ex/sem.c @@ -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 */ diff --git a/reactos/ntoskrnl/ex/timer.c b/reactos/ntoskrnl/ex/timer.c index 7fa52006702..d89cc50f8df 100644 --- a/reactos/ntoskrnl/ex/timer.c +++ b/reactos/ntoskrnl/ex/timer.c @@ -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); diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index 0d2c38ac06a..dcec0c87625 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -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 diff --git a/reactos/ntoskrnl/include/internal/ob.h b/reactos/ntoskrnl/include/internal/ob.h index ae3c5a7f3d6..c05fd9b57d6 100644 --- a/reactos/ntoskrnl/include/internal/ob.h +++ b/reactos/ntoskrnl/include/internal/ob.h @@ -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 */ diff --git a/reactos/ntoskrnl/io/iocomp.c b/reactos/ntoskrnl/io/iocomp.c index 7e3c810f965..946dfb46549 100644 --- a/reactos/ntoskrnl/io/iocomp.c +++ b/reactos/ntoskrnl/io/iocomp.c @@ -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); diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index d0eec8fc8c7..373d351cc92 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -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)) { diff --git a/reactos/ntoskrnl/ps/query.c b/reactos/ntoskrnl/ps/query.c index f32c0175879..9641831b4b3 100644 --- a/reactos/ntoskrnl/ps/query.c +++ b/reactos/ntoskrnl/ps/query.c @@ -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); diff --git a/reactos/ntoskrnl/se/token.c b/reactos/ntoskrnl/se/token.c index fd2066a07e1..009fa985294 100644 --- a/reactos/ntoskrnl/se/token.c +++ b/reactos/ntoskrnl/se/token.c @@ -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)) {