-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathEventLog.c
106 lines (86 loc) · 4.6 KB
/
EventLog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/***************************************************************************
* PPJoy Virtual Joystick for Microsoft Windows *
* Copyright (C) 2011 Deon van der Westhuysen *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/***************************************************************************/
/** **/
/** Parallel port joystick driver, (C) Deon van der Westhuysen 2002 **/
/** **/
/** EventLog.c Routine to send messages to the Windows Event Log. **/
/** **/
/** **/
/** **/
/** **/
/** **/
/** **/
/***************************************************************************/
#include "PPortJoy.h"
#include <wchar.h>
#define DWORD ULONG
/**************************************************************************/
/* Declare the code segments into which each routine will be placed */
/* Used to declare pagable and initialisation code. */
/**************************************************************************/
#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE,PPortJoy_WriteEventLog)
#endif
/**************************************************************************/
/* Routine synchronously send an IRP to the driver indicated by the */
/* DeviceObject parameter. Once the routine returns the lower level */
/* drivers will have processed the IRP. If CopyStack is set then this */
/* routine will copy the current stack location for the next driver, */
/* else the caller should set up the next stack themselves. */
/**************************************************************************/
void PPortJoy_WriteEventLog (NTSTATUS ErrorMessageCode, PVOID DumpData, USHORT DumpSize, PCWSTR Message)
{
PIO_ERROR_LOG_PACKET LogPacket;
PUCHAR StrPtr;
USHORT MsgLen;
PAGED_CODE();
if (!Message)
Message= L"";
MsgLen= (wcslen(Message)+1)*sizeof(WCHAR);
DumpSize= (DumpSize+1) & 0xFC;
if (!DumpData)
DumpSize= 0;
LogPacket= IoAllocateErrorLogEntry (Globals.DriverObject,(UCHAR)(sizeof(IO_ERROR_LOG_PACKET)+DumpSize+MsgLen));
if (!LogPacket)
{
PPJOY_DBGPRINT (FILE_EVENTLOG|PPJOY_ERROR, ("Cannot allocate LogEntry packet!!") );
return;
}
StrPtr= ((PUCHAR)LogPacket->DumpData)+DumpSize;
LogPacket->MajorFunctionCode= 0;
LogPacket->RetryCount= 0;
LogPacket->DumpDataSize= DumpSize;
LogPacket->NumberOfStrings= (*Message)?1:0;
LogPacket->StringOffset= (USHORT) (StrPtr-(PUCHAR)LogPacket);
// LogPacket->EventCategory= 0;
LogPacket->ErrorCode= ErrorMessageCode;
LogPacket->UniqueErrorValue= 0;
LogPacket->FinalStatus= STATUS_SUCCESS;
LogPacket->SequenceNumber= 0;
if (DumpData)
RtlCopyMemory(LogPacket->DumpData,DumpData,DumpSize);
if (*Message)
{
RtlCopyMemory(StrPtr,Message,MsgLen);
StrPtr+= MsgLen;
}
PPJOY_DBGPRINT (FILE_EVENTLOG|PPJOY_BABBLE, ("Writing EventLog entry 0x%p",LogPacket) );
IoWriteErrorLogEntry (LogPacket);
}