5d6246a4ce0751a95b0f52c4caca8c46ad6cefc8
[reactos.git] / reactos / ntoskrnl / rtl / debug.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/rtl/dbgprint.c
5 * PURPOSE: Debug output
6 *
7 * PROGRAMMERS: Eric Kohl (ekohl@abo.rhein-zeitung.de)
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ntoskrnl.h>
13 #include <internal/debug.h>
14
15 /* FUNCTIONS ****************************************************************/
16
17 /*
18 * Note: DON'T CHANGE THIS FUNCTION!!!
19 * DON'T CALL HalDisplayString OR SOMETING ELSE!!!
20 * You'll only break the serial/bochs debugging feature!!!
21 */
22
23 /*
24 * @implemented
25 */
26 ULONG
27 DbgPrint(PCH Format, ...)
28 {
29 ANSI_STRING DebugString;
30 CHAR Buffer[1024];
31 va_list ap;
32 #ifdef SERIALIZE_DBGPRINT
33 # define MESSAGETABLE_SIZE 16
34 LONG MyTableIndex;
35 static LONG Lock = 0;
36 static LONG TableWriteIndex = 0, TableReadIndex = 0;
37 static CHAR MessageTable[MESSAGETABLE_SIZE][sizeof(Buffer)] = { { '\0' } };
38 #endif /* SERIALIZE_DBGPRINT */
39
40 /* init ansi string */
41 DebugString.Buffer = Buffer;
42 DebugString.MaximumLength = sizeof(Buffer);
43
44 va_start (ap, Format);
45 DebugString.Length = _vsnprintf (Buffer, sizeof( Buffer ), Format, ap);
46 va_end (ap);
47
48 #ifdef SERIALIZE_DBGPRINT
49 /* check if we are already running */
50 if (InterlockedCompareExchange(&Lock, 1, 0) == 1)
51 {
52 MyTableIndex = InterlockedIncrement(&TableWriteIndex) - 1;
53 InterlockedCompareExchange(&TableWriteIndex, 0, MESSAGETABLE_SIZE);
54 MyTableIndex %= MESSAGETABLE_SIZE;
55
56 if (MessageTable[MyTableIndex][0] != '\0') /* table is full */
57 {
58 DebugString.Buffer = "CRITICAL ERROR: DbgPrint Table is FULL!";
59 DebugString.Length = 39;
60 KdpPrintString(&DebugString);
61 for (;;);
62 }
63 else
64 {
65 /*DebugString.Buffer = "ยตยตยต";
66 DebugString.Length = 3;
67 KdpPrintString(&DebugString);*/
68 memcpy(MessageTable[MyTableIndex], DebugString.Buffer, DebugString.Length);
69 MessageTable[MyTableIndex][DebugString.Length] = '\0';
70 }
71 }
72 else
73 {
74 #endif /* SERIALIZE_DBGPRINT */
75 KdpPrintString (&DebugString);
76 #ifdef SERIALIZE_DBGPRINT
77 MyTableIndex = TableReadIndex;
78 while (MessageTable[MyTableIndex][0] != '\0')
79 {
80 /*DebugString.Buffer = "$$$";
81 DebugString.Length = 3;
82 KdpPrintString(&DebugString);*/
83
84 DebugString.Buffer = MessageTable[MyTableIndex];
85 DebugString.Length = strlen(DebugString.Buffer);
86 DebugString.MaximumLength = DebugString.Length + 1;
87
88 KdpPrintString(&DebugString);
89 MessageTable[MyTableIndex][0] = '\0';
90
91 MyTableIndex = InterlockedIncrement(&TableReadIndex);
92 InterlockedCompareExchange(&TableReadIndex, 0, MESSAGETABLE_SIZE);
93 MyTableIndex %= MESSAGETABLE_SIZE;
94 }
95 InterlockedDecrement(&Lock);
96 }
97 # undef MESSAGETABLE_SIZE
98 #endif /* SERIALIZE_DBGPRINT */
99
100 return (ULONG)DebugString.Length;
101 }
102
103 /*
104 * @unimplemented
105 */
106 ULONG
107 __cdecl
108 DbgPrintEx(IN ULONG ComponentId,
109 IN ULONG Level,
110 IN PCH Format,
111 ...)
112 {
113 UNIMPLEMENTED;
114 return 0;
115 }
116
117 /*
118 * @unimplemented
119 */
120 ULONG
121 __cdecl
122 DbgPrintReturnControlC(PCH Format,
123 ...)
124 {
125 UNIMPLEMENTED;
126 return 0;
127 }
128
129 /*
130 * @unimplemented
131 */
132 VOID
133 STDCALL
134 DbgPrompt(PCH OutputString,
135 PCH InputString,
136 USHORT InputSize)
137 {
138 ANSI_STRING Output;
139 ANSI_STRING Input;
140
141 Input.Length = 0;
142 Input.MaximumLength = InputSize;
143 Input.Buffer = InputString;
144
145 Output.Length = strlen (OutputString);
146 Output.MaximumLength = Output.Length + 1;
147 Output.Buffer = OutputString;
148
149 /* FIXME: Not implemented yet!
150 KdpPromptString (&Output, &Input); */
151 }
152
153 /*
154 * @unimplemented
155 */
156 NTSTATUS
157 STDCALL
158 DbgQueryDebugFilterState(IN ULONG ComponentId,
159 IN ULONG Level)
160 {
161 UNIMPLEMENTED;
162 return STATUS_NOT_IMPLEMENTED;
163 }
164
165 /*
166 * @unimplemented
167 */
168 NTSTATUS
169 STDCALL
170 DbgSetDebugFilterState(IN ULONG ComponentId,
171 IN ULONG Level,
172 IN BOOLEAN State)
173 {
174 UNIMPLEMENTED;
175 return STATUS_NOT_IMPLEMENTED;
176 }
177
178 /*
179 * @unimplemented
180 */
181 NTSTATUS
182 STDCALL
183 DbgLoadImageSymbols(IN PUNICODE_STRING Name,
184 IN ULONG Base,
185 IN ULONG Unknown3)
186 {
187 UNIMPLEMENTED;
188 return STATUS_NOT_IMPLEMENTED;
189 }
190 /* EOF */