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