ReactOS 0.4.16-dev-1264-g92ff994
NtQuerySection.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Test for NtQuerySection
5 * COPYRIGHT: Copyright 2025 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#include "precomp.h"
9
10static
13{
17
18 MaximumSize.QuadPart = Size;
21 NULL, // ObjectAttributes
23 Protection,
25 hFile);
27 return hSection;
28}
29
30static
31VOID
33{
36
39 SectionInfo,
40 sizeof(*SectionInfo),
43 ok_eq_hex(ReturnLength, sizeof(*SectionInfo));
44}
45
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}
154
156{
158}
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
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
static HANDLE CreateSection(ULONG Size, ULONG Protection, ULONG Attributes, HANDLE hFile)
static VOID QuerySbi(SECTION_BASIC_INFORMATION *SectionInfo, HANDLE hSection)
void Test_SectionBasicInformation(void)
#define ok_eq_pointer(value, expected)
Definition: apitest.h:40
#define ok_eq_hex(value, expected)
Definition: apitest.h:58
#define ok_eq_hex64(value, expected)
Definition: apitest.h:70
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define NULL
Definition: types.h:112
#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
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 SEC_COMMIT
Definition: mmtypes.h:100
#define SEC_IMAGE
Definition: mmtypes.h:97
#define SEC_FILE
Definition: mmtypes.h:96
@ SectionBasicInformation
Definition: mmtypes.h:195
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#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
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
#define STATUS_SUCCESS
Definition: shellext.h:65
LARGE_INTEGER Size
Definition: mmtypes.h:336
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONGLONG QuadPart
Definition: typedefs.h:114
_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
char CHAR
Definition: xmlstorage.h:175