ReactOS 0.4.15-dev-8102-g108db8f
ntoskrnl.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test to validate section flags in ntoskrnl
5 * PROGRAMMER: Mark Jansen
6 */
7
8#include <apitest.h>
9#include <strsafe.h>
10
11typedef struct KnownSections
12{
13 const char* Name;
17
18static struct KnownSections g_Sections[] = {
19 {
20 ".text",
23 },
24 {
25 ".data",
28 },
29 {
30 ".rsrc",
33 },
34 {
35 ".rdata",
38 },
39 {
40 ".reloc",
42 0
43 },
44 {
45 "INIT",
47 0
48 },
49 { NULL, 0 },
50};
51
52static char* Chr2Str(DWORD value)
53{
54 static char buf[512];
55 buf[0] = '\0';
56#define IFX(x) if( value & IMAGE_SCN_##x )\
57 {\
58 if(buf[0]) { StringCchCatA(buf, _countof(buf), "|" ); }\
59 StringCchCatA(buf, _countof(buf), #x );\
60 value &= ~(IMAGE_SCN_##x);\
61 }
62 IFX(TYPE_NO_PAD);
63 IFX(CNT_CODE);
64 IFX(CNT_INITIALIZED_DATA);
65 IFX(CNT_UNINITIALIZED_DATA);
66 IFX(LNK_OTHER);
67 IFX(LNK_INFO);
68 IFX(LNK_REMOVE);
69 IFX(LNK_COMDAT);
70 //IFX(NO_DEFER_SPEC_EXC);
71 //IFX(GPREL);
72 IFX(MEM_FARDATA);
73 IFX(MEM_PURGEABLE);
74 IFX(MEM_16BIT);
75 IFX(MEM_LOCKED);
76 IFX(MEM_PRELOAD);
77 IFX(ALIGN_1BYTES);
78 IFX(ALIGN_2BYTES);
79 IFX(ALIGN_4BYTES);
80 IFX(ALIGN_8BYTES);
81 IFX(ALIGN_16BYTES);
82 IFX(ALIGN_32BYTES);
83 IFX(ALIGN_64BYTES);
84 //IFX(ALIGN_128BYTES);
85 //IFX(ALIGN_256BYTES);
86 //IFX(ALIGN_512BYTES);
87 //IFX(ALIGN_1024BYTES);
88 //IFX(ALIGN_2048BYTES);
89 //IFX(ALIGN_4096BYTES);
90 //IFX(ALIGN_8192BYTES);
91 IFX(LNK_NRELOC_OVFL);
92 IFX(MEM_DISCARDABLE);
93 IFX(MEM_NOT_CACHED);
94 IFX(MEM_NOT_PAGED);
95 IFX(MEM_SHARED);
96 IFX(MEM_EXECUTE);
99 if( value )
100 {
102 }
103 return buf;
104}
105
106
107START_TEST(ntoskrnl_SectionFlags)
108{
109 char buf[MAX_PATH];
110 HMODULE mod;
112 StringCchCatA(buf, _countof(buf), "\\ntoskrnl.exe");
113
115 if( mod != NULL )
116 {
117 // we have to take into account that a datafile is not returned at the exact address it's loaded at.
118 PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)(((size_t)mod) & (~0xf));
120 PIMAGE_SECTION_HEADER firstSection;
121 WORD numSections, n;
122
124 {
125 skip("Couldn't find ntoskrnl.exe dos header\n");
127 return;
128 }
131 {
132 skip("Couldn't find ntoskrnl.exe nt header\n");
134 return;
135 }
136 firstSection = IMAGE_FIRST_SECTION(nt);
137 numSections = nt->FileHeader.NumberOfSections;
138 for( n = 0; n < numSections; ++n )
139 {
140 PIMAGE_SECTION_HEADER section = firstSection + n;
141 char name[9] = {0};
142 size_t i;
144
145 for( i = 0; g_Sections[i].Name; ++i )
146 {
147 if( !_strnicmp(name, g_Sections[i].Name, 8) )
148 {
149 if( g_Sections[i].Required )
150 {
151 DWORD Flags = g_Sections[i].Required & section->Characteristics;
153 "Missing required Characteristics on %s: %s\n",
155 }
156 if( g_Sections[i].Disallowed )
157 {
158 DWORD Flags = g_Sections[i].Disallowed & section->Characteristics;
159 ok(!Flags, "Disallowed section Characteristics on %s: %s\n",
160 name, Chr2Str(section->Characteristics));
161 }
162 break;
163 }
164 }
165 }
167 }
168 else
169 {
170 skip("Couldn't load ntoskrnl.exe as datafile\n");
171 }
172}
173
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define FreeLibrary(x)
Definition: compat.h:748
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
#define MAX_PATH
Definition: compat.h:34
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:159
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
unsigned long DWORD
Definition: ntddk_ex.h:95
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
unsigned short WORD
Definition: ntddk_ex.h:93
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int mod
Definition: i386-dis.c:1288
static struct KnownSections g_Sections[]
Definition: ntoskrnl.c:18
#define IFX(x)
static char * Chr2Str(DWORD value)
Definition: ntoskrnl.c:52
IMAGE_NT_HEADERS nt
Definition: module.c:50
IMAGE_DOS_HEADER dos
Definition: module.c:49
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN _Inout_ PMM_REQUIRED_RESOURCES Required
Definition: newmm.h:210
#define IMAGE_SCN_MEM_WRITE
Definition: ntimage.h:241
#define IMAGE_SCN_MEM_NOT_PAGED
Definition: ntimage.h:237
#define IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: ntimage.h:231
#define IMAGE_SCN_CNT_CODE
Definition: ntimage.h:230
#define IMAGE_SCN_MEM_EXECUTE
Definition: ntimage.h:239
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
#define IMAGE_SCN_MEM_DISCARDABLE
Definition: ntimage.h:235
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240
BYTE * PBYTE
Definition: pedump.c:66
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:320
STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:230
STRSAFEAPI StringCchPrintfA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:520
DWORD Required
Definition: ntoskrnl.c:14
const char * Name
Definition: ntoskrnl.c:13
DWORD Disallowed
Definition: ntoskrnl.c:15
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
Definition: name.c:39
Definition: parser.c:56
const char * PCSTR
Definition: typedefs.h:52
Definition: pdh_main.c:94
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
#define MEM_READ
Definition: ws2san.h:35
#define MEM_WRITE
Definition: ws2san.h:36
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170