ReactOS 0.4.17-dev-218-g5635d24
bootlog.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for bootlog.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID IopInitBootLog (BOOLEAN StartBootLog)
 
VOID IopStartBootLog (VOID)
 
VOID IopStopBootLog (VOID)
 
VOID IopBootLog (PUNICODE_STRING DriverName, BOOLEAN Success)
 
static NTSTATUS IopWriteLogFile (PWSTR LogText)
 
static NTSTATUS IopCreateLogFile (VOID)
 
VOID IopSaveBootLogToFile (VOID)
 

Variables

static BOOLEAN IopBootLogCreate = FALSE
 
static BOOLEAN IopBootLogEnabled = FALSE
 
static BOOLEAN IopLogFileEnabled = FALSE
 
static ULONG IopLogEntryCount = 0
 
static ERESOURCE IopBootLogResource
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file bootlog.c.

Function Documentation

◆ IopBootLog()

VOID IopBootLog ( PUNICODE_STRING  DriverName,
BOOLEAN  Success 
)

Definition at line 53 of file bootlog.c.

55{
57 WCHAR Buffer[256];
58 WCHAR ValueNameBuffer[8];
61 HANDLE ControlSetKey;
62 HANDLE BootLogKey;
64
66 return;
67
69
70 DPRINT("Boot log: %wS %wZ\n",
71 Success ? L"Loaded driver" : L"Did not load driver",
72 DriverName);
73
75 L"%ws %wZ",
76 Success ? L"Loaded driver" : L"Did not load driver",
77 DriverName);
78
79 _swprintf(ValueNameBuffer, L"%lu", IopLogEntryCount);
80
82 L"\\Registry\\Machine\\System\\CurrentControlSet");
84 &KeyName,
86 NULL,
87 NULL);
88 Status = ZwOpenKey(&ControlSetKey,
91 if (!NT_SUCCESS(Status))
92 {
93 DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status);
95 return;
96 }
97
98 RtlInitUnicodeString(&KeyName, L"BootLog");
100 &KeyName,
102 ControlSetKey,
103 NULL);
104 Status = ZwCreateKey(&BootLogKey,
107 0,
108 NULL,
110 NULL);
111 if (!NT_SUCCESS(Status))
112 {
113 DPRINT1("ZwCreateKey() failed (Status %lx)\n", Status);
114 ZwClose(ControlSetKey);
116 return;
117 }
118
119 RtlInitUnicodeString(&ValueName, ValueNameBuffer);
120 Status = ZwSetValueKey(BootLogKey,
121 &ValueName,
122 0,
123 REG_SZ,
124 (PVOID)Buffer,
125 (ULONG)(wcslen(Buffer) + 1) * sizeof(WCHAR));
126 ZwClose(BootLogKey);
127 ZwClose(ControlSetKey);
128
129 if (!NT_SUCCESS(Status))
130 {
131 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
132 }
133 else
134 {
136 }
137
139}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static ULONG IopLogEntryCount
Definition: bootlog.c:21
static ERESOURCE IopBootLogResource
Definition: bootlog.c:22
static BOOLEAN IopBootLogEnabled
Definition: bootlog.c:19
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define L(x)
Definition: resources.c:13
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
@ Success
Definition: eventcreate.c:712
Status
Definition: gdiplustypes.h:24
#define REG_SZ
Definition: layer.c:22
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
short WCHAR
Definition: pedump.c:58
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define DPRINT
Definition: sndvol32.h:73
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

◆ IopCreateLogFile()

static NTSTATUS IopCreateLogFile ( VOID  )
static

Definition at line 223 of file bootlog.c.

224{
232
233 DPRINT("IopSaveBootLogToFile() called\n");
234
236
238 L"\\SystemRoot\\rosboot.log");
240 &FileName,
242 NULL,
243 NULL);
244
245 Status = ZwCreateFile(&FileHandle,
249 NULL,
250 0,
251 0,
254 NULL,
255 0);
256 if (!NT_SUCCESS(Status))
257 {
258 DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status);
259 return Status;
260 }
261
262 ByteOffset.QuadPart = (LONGLONG)0;
263
264 Signature = 0xFEFF;
265 Status = ZwWriteFile(FileHandle,
266 NULL,
267 NULL,
268 NULL,
271 sizeof(WCHAR),
272 &ByteOffset,
273 NULL);
274 if (!NT_SUCCESS(Status))
275 {
276 DPRINT1("ZwWriteKey() failed (Status %lx)\n", Status);
277 }
278
280
281 return Status;
282}
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
static const WCHAR Signature[]
Definition: parser.c:141
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:732
struct _FileName FileName
Definition: fatprocs.h:897
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:100
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by IopSaveBootLogToFile().

◆ IopInitBootLog()

VOID IopInitBootLog ( BOOLEAN  StartBootLog)

Definition at line 29 of file bootlog.c.

30{
32 if (StartBootLog) IopStartBootLog();
33}
VOID IopStartBootLog(VOID)
Definition: bootlog.c:38
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641

◆ IopSaveBootLogToFile()

VOID IopSaveBootLogToFile ( VOID  )

Definition at line 286 of file bootlog.c.

287{
289 WCHAR ValueNameBuffer[8];
296 ULONG i;
298
299 if (IopBootLogCreate == FALSE)
300 return;
301
302 DPRINT("IopSaveBootLogToFile() called\n");
303
305
307 if (!NT_SUCCESS(Status))
308 {
309 DPRINT1("IopCreateLogFile() failed (Status %lx)\n", Status);
311 return;
312 }
313
314 //Status = IopWriteLogFile(L"ReactOS "KERNEL_VERSION_STR);
315
316 if (!NT_SUCCESS(Status))
317 {
318 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
320 return;
321 }
322
324 if (!NT_SUCCESS(Status))
325 {
326 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
328 return;
329 }
330
331
332 BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 256 * sizeof(WCHAR);
333 KeyInfo = ExAllocatePool(PagedPool,
334 BufferSize);
335 if (KeyInfo == NULL)
336 {
338 return;
339 }
340
342 L"\\Registry\\Machine\\System\\CurrentControlSet\\BootLog");
344 &KeyName,
346 NULL,
347 NULL);
348 Status = ZwOpenKey(&KeyHandle,
351 if (!NT_SUCCESS(Status))
352 {
353 ExFreePool(KeyInfo);
355 return;
356 }
357
358 for (i = 0; ; i++)
359 {
360 _swprintf(ValueNameBuffer, L"%lu", i);
361
363 ValueNameBuffer);
364
365 Status = ZwQueryValueKey(KeyHandle,
366 &ValueName,
368 KeyInfo,
370 &ResultLength);
372 {
373 break;
374 }
375
376 if (!NT_SUCCESS(Status))
377 {
379 ExFreePool(KeyInfo);
381 return;
382 }
383
384 Status = IopWriteLogFile((PWSTR)&KeyInfo->Data);
385 if (!NT_SUCCESS(Status))
386 {
388 ExFreePool(KeyInfo);
390 return;
391 }
392
393 /* Delete keys */
395 &ValueName);
396 }
397
399
400 ExFreePool(KeyInfo);
401
404
405 DPRINT("IopSaveBootLogToFile() done\n");
406}
static NTSTATUS IopCreateLogFile(VOID)
Definition: bootlog.c:223
static NTSTATUS IopWriteLogFile(PWSTR LogText)
Definition: bootlog.c:144
static BOOLEAN IopLogFileEnabled
Definition: bootlog.c:20
static BOOLEAN IopBootLogCreate
Definition: bootlog.c:18
#define BufferSize
Definition: mmc.h:75
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
NTSYSAPI NTSTATUS NTAPI ZwDeleteValueKey(__in IN HANDLE Key, __in IN PUNICODE_STRING ValueName)
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
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
@ KeyValuePartialInformation
Definition: nt_native.h:1185
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
uint16_t * PWSTR
Definition: typedefs.h:56
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

◆ IopStartBootLog()

VOID IopStartBootLog ( VOID  )

Definition at line 38 of file bootlog.c.

Referenced by IopInitBootLog().

◆ IopStopBootLog()

VOID IopStopBootLog ( VOID  )

Definition at line 46 of file bootlog.c.

47{
49}

◆ IopWriteLogFile()

static NTSTATUS IopWriteLogFile ( PWSTR  LogText)
static

Definition at line 144 of file bootlog.c.

145{
150 PWSTR CrLf = L"\r\n";
152
153 DPRINT("IopWriteLogFile() called\n");
154
156 L"\\SystemRoot\\rosboot.log");
158 &FileName,
160 NULL,
161 NULL);
162
163 Status = ZwCreateFile(&FileHandle,
167 NULL,
168 0,
169 0,
170 FILE_OPEN,
172 NULL,
173 0);
174 if (!NT_SUCCESS(Status))
175 {
176 DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status);
177 return Status;
178 }
179
180 if (LogText != NULL)
181 {
182 Status = ZwWriteFile(FileHandle,
183 NULL,
184 NULL,
185 NULL,
187 LogText,
188 (ULONG)wcslen(LogText) * sizeof(WCHAR),
189 NULL,
190 NULL);
191 if (!NT_SUCCESS(Status))
192 {
193 DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
195 return Status;
196 }
197 }
198
199 /* L"\r\n" */
200 Status = ZwWriteFile(FileHandle,
201 NULL,
202 NULL,
203 NULL,
205 (PVOID)CrLf,
206 2 * sizeof(WCHAR),
207 NULL,
208 NULL);
209
211
212 if (!NT_SUCCESS(Status))
213 {
214 DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
215 }
216
217 return Status;
218}
#define FILE_OPEN
Definition: from_kernel.h:54
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_APPEND_DATA
Definition: nt_native.h:634

Referenced by IopSaveBootLogToFile().

Variable Documentation

◆ IopBootLogCreate

BOOLEAN IopBootLogCreate = FALSE
static

Definition at line 18 of file bootlog.c.

Referenced by IopSaveBootLogToFile(), and IopStartBootLog().

◆ IopBootLogEnabled

BOOLEAN IopBootLogEnabled = FALSE
static

Definition at line 19 of file bootlog.c.

Referenced by IopBootLog(), IopStartBootLog(), and IopStopBootLog().

◆ IopBootLogResource

ERESOURCE IopBootLogResource
static

Definition at line 22 of file bootlog.c.

Referenced by IopBootLog(), IopCreateLogFile(), IopInitBootLog(), and IopSaveBootLogToFile().

◆ IopLogEntryCount

ULONG IopLogEntryCount = 0
static

Definition at line 21 of file bootlog.c.

Referenced by IopBootLog().

◆ IopLogFileEnabled

BOOLEAN IopLogFileEnabled = FALSE
static

Definition at line 20 of file bootlog.c.

Referenced by IopSaveBootLogToFile().