Use free Windows DDK and compile with latest MinGW releases.
[reactos.git] / reactos / lib / ntdll / rtl / trace.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: trace.c,v 1.2 2002/09/07 15:12:41 chorns Exp $
20 *
21 * PROJECT: ReactOS kernel
22 * PURPOSE: Tracing library calls
23 * FILE: lib/ntdll/rtl/trace.c
24 * PROGRAMER: David Welch <welch@cwcom.net>
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #define NTOS_USER_MODE
30 #include <ntos.h>
31 #include <string.h>
32 #include <stdarg.h>
33
34 #define NDEBUG
35 #include <debug.h>
36
37 /* GLOBALS *******************************************************************/
38
39 static NTDLL_TRACE_TABLE TraceTable;
40 static BOOLEAN TraceTableValid = FALSE;
41
42 /* FUNCTIONS *****************************************************************/
43
44 NTSTATUS
45 RtlpInitTrace(VOID)
46 {
47 HANDLE SectionHandle;
48 UNICODE_STRING SectionName;
49 OBJECT_ATTRIBUTES ObjectAttributes;
50 CHAR Buffer[4096];
51 NTSTATUS Status;
52 PROCESS_BASIC_INFORMATION Pbi;
53 ULONG ReturnedSize;
54 PVOID BaseAddress;
55 LARGE_INTEGER Offset;
56 ULONG ViewSize;
57
58 Status = NtQueryInformationProcess(NtCurrentProcess(),
59 ProcessBasicInformation,
60 (PVOID)&Pbi,
61 sizeof(Pbi),
62 &ReturnedSize);
63 if (!NT_SUCCESS(Status))
64 {
65 return(Status);
66 }
67
68 sprintf(Buffer, "\\??\\TraceSection%d", Pbi.UniqueProcessId);
69
70 InitializeObjectAttributes(&ObjectAttributes,
71 &SectionName,
72 0,
73 NULL,
74 NULL);
75 Status = NtOpenSection(&SectionHandle,
76 SECTION_MAP_READ,
77 &ObjectAttributes);
78 if (!NT_SUCCESS(Status))
79 {
80 return(Status);
81 }
82
83 BaseAddress = 0;
84 Offset.QuadPart = 0;
85 ViewSize = 0;
86 Status = NtMapViewOfSection(SectionHandle,
87 NtCurrentProcess(),
88 &BaseAddress,
89 0,
90 sizeof(NTDLL_TRACE_TABLE),
91 &Offset,
92 &ViewSize,
93 ViewUnmap,
94 0,
95 PAGE_READONLY);
96 if (!NT_SUCCESS(Status))
97 {
98 NtClose(SectionHandle);
99 return(Status);
100 }
101 NtClose(SectionHandle);
102
103 memcpy(&TraceTable, BaseAddress, sizeof(TraceTable));
104 TraceTableValid = TRUE;
105
106 Status = NtUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
107
108 return(STATUS_SUCCESS);
109 }
110
111 VOID
112 RtlPrintTrace(ULONG Flag, PCH Format, ...)
113 {
114 va_list ap;
115 CHAR FString[4096];
116
117 if (!TraceTableValid)
118 {
119 return;
120 }
121 if (TraceTable.Flags[Flag / BITS_IN_CHAR] & (1 << (Flag % BITS_IN_CHAR)))
122 {
123 va_start(ap, Format);
124 vsprintf(FString, Format, ap);
125 DbgPrint(FString);
126 va_end(ap);
127 }
128 }