ReactOS 0.4.16-dev-1276-g70732b0
NtQuerySection.c File Reference
#include "precomp.h"
Include dependency graph for NtQuerySection.c:

Go to the source code of this file.

Functions

static HANDLE CreateSection (ULONG Size, ULONG Protection, ULONG Attributes, HANDLE hFile)
 
static VOID QuerySbi (SECTION_BASIC_INFORMATION *SectionInfo, HANDLE hSection)
 
void Test_SectionBasicInformation (void)
 
 START_TEST (NtQuerySection)
 

Function Documentation

◆ CreateSection()

static HANDLE CreateSection ( ULONG  Size,
ULONG  Protection,
ULONG  Attributes,
HANDLE  hFile 
)
static

Definition at line 12 of file NtQuerySection.c.

13{
17
18 MaximumSize.QuadPart = Size;
21 NULL, // ObjectAttributes
23 Protection,
25 hFile);
27 return hSection;
28}
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3076
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:362
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3239

Referenced by Test_SectionBasicInformation().

◆ QuerySbi()

static VOID QuerySbi ( SECTION_BASIC_INFORMATION SectionInfo,
HANDLE  hSection 
)
static

Definition at line 32 of file NtQuerySection.c.

33{
36
39 SectionInfo,
40 sizeof(*SectionInfo),
43 ok_eq_hex(ReturnLength, sizeof(*SectionInfo));
44}
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
#define ok_eq_hex(value, expected)
Definition: apitest.h:58
@ SectionBasicInformation
Definition: mmtypes.h:195
NTSTATUS NTAPI NtQuerySection(_In_ HANDLE SectionHandle, _In_ SECTION_INFORMATION_CLASS SectionInformationClass, _Out_ PVOID SectionInformation, _In_ SIZE_T SectionInformationLength, _Out_opt_ PSIZE_T ResultLength)
Definition: section.c:3781
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by Test_SectionBasicInformation().

◆ START_TEST()

START_TEST ( NtQuerySection  )

Definition at line 155 of file NtQuerySection.c.

156{
158}
void Test_SectionBasicInformation(void)

◆ Test_SectionBasicInformation()

void Test_SectionBasicInformation ( void  )

Definition at line 46 of file NtQuerySection.c.

47{
50 SECTION_BASIC_INFORMATION SectionInfo;
52
53 // Create a section with SEC_COMMIT
55 ok(hSection != NULL, "hSection is NULL\n");
56
57 // Call NtQuerySection with SectionBasicInformation and a NULL handle
60 &SectionInfo,
61 sizeof(SectionInfo),
64
65 // Call NtQuerySection with SectionBasicInformation and a NULL buffer
68 NULL,
69 sizeof(SectionInfo),
72
73 // Call NtQuerySection with SectionBasicInformation and a too small buffer
76 &SectionInfo,
77 sizeof(SectionInfo) - 1,
80
81 // Call NtQuerySection with SectionBasicInformation and proper parameters
84 &SectionInfo,
85 sizeof(SectionInfo),
88 ok_eq_hex(ReturnLength, sizeof(SectionInfo));
89 ok_eq_pointer(SectionInfo.BaseAddress, NULL);
90 ok_eq_hex(SectionInfo.Attributes, SEC_COMMIT);
91 ok_eq_hex64(SectionInfo.Size.QuadPart, PAGE_SIZE);
93
94 // Section with SEC_RESERVE
96 ok(hSection != NULL, "hSection is NULL\n");
97 QuerySbi(&SectionInfo, hSection);
98 ok_eq_pointer(SectionInfo.BaseAddress, NULL);
99 ok_eq_hex(SectionInfo.Attributes, SEC_RESERVE);
100 ok_eq_hex64(SectionInfo.Size.QuadPart, 2 * PAGE_SIZE);
102
103 // Section with SEC_BASED
105 ok(hSection != NULL, "hSection is NULL\n");
106 QuerySbi(&SectionInfo, hSection);
107 ok(SectionInfo.BaseAddress != NULL, "BaseAddress is NULL\n");
109 ok_eq_hex64(SectionInfo.Size.QuadPart, 0x20000);
111
112 // Open this executable file
113 CHAR TestExecutableName[MAX_PATH];
114 GetModuleFileNameA(NULL, TestExecutableName, sizeof(TestExecutableName));
115 hFile = CreateFileA(TestExecutableName,
118 NULL,
121 NULL);
122 ok(hFile != INVALID_HANDLE_VALUE, "Failed to open file %s\n", TestExecutableName);
123
124 // Section with SEC_IMAGE and 0 size
126 ok(hSection != NULL, "hSection is NULL\n");
127 QuerySbi(&SectionInfo, hSection);
128 ok_eq_pointer(SectionInfo.BaseAddress, NULL);
129 ok_eq_hex(SectionInfo.Attributes, SEC_FILE | SEC_IMAGE);
130 ok(SectionInfo.Size.QuadPart >= 3 * PAGE_SIZE, "Unexpected size:%I64x\n", SectionInfo.Size.QuadPart);
132
133 // Section with SEC_IMAGE and specific size
135 ok(hSection != NULL, "hSection is NULL\n");
136 QuerySbi(&SectionInfo, hSection);
137 ok_eq_pointer(SectionInfo.BaseAddress, NULL);
138 ok_eq_hex(SectionInfo.Attributes, SEC_FILE | SEC_IMAGE);
139 ok_eq_hex64(SectionInfo.Size.QuadPart, 42);
141
142 // File backed section with SEC_RESERVE (ignored)
144 ok(hSection != NULL, "hSection is NULL\n");
145 QuerySbi(&SectionInfo, hSection);
146 ok_eq_pointer(SectionInfo.BaseAddress, NULL);
147 ok_eq_hex(SectionInfo.Attributes, SEC_FILE);
148 ok_eq_hex64(SectionInfo.Size.QuadPart, 1);
150
151 // Close the file handle
152 NtClose(hFile);
153}
static HANDLE CreateSection(ULONG Size, ULONG Protection, ULONG Attributes, HANDLE hFile)
static VOID QuerySbi(SECTION_BASIC_INFORMATION *SectionInfo, HANDLE hSection)
#define ok_eq_pointer(value, expected)
Definition: apitest.h:40
#define ok_eq_hex64(value, expected)
Definition: apitest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define PAGE_READONLY
Definition: compat.h:138
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SEC_COMMIT
Definition: mmtypes.h:100
#define SEC_IMAGE
Definition: mmtypes.h:97
#define SEC_FILE
Definition: mmtypes.h:96
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define SEC_RESERVE
Definition: nt_native.h:1323
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define SEC_BASED
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
LARGE_INTEGER Size
Definition: mmtypes.h:336
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONGLONG QuadPart
Definition: typedefs.h:114
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().