diff --git a/reactos/include/ntdll/trace.h b/reactos/include/ntdll/trace.h new file mode 100644 index 00000000000..54f4d0d9370 --- /dev/null +++ b/reactos/include/ntdll/trace.h @@ -0,0 +1,18 @@ +#ifndef __INCLUDE_NTDLL_TRACE_H +#define __INCLUDE_NTDLL_TRACE_H + +typedef struct _NTDLL_TRACE_TABLE +{ + CHAR Flags[4096]; +} NTDLL_TABLE_TABLE, *PNTDLL_TABLE_TRACE; + +#define TRACE_NTDLL (1) +#define TRACE_KERNEL32 (2) +#define TRACE_CRTDLL (3) + +VOID +RtlPrintTrace(ULONG Flag, PCH Format, ...); + +#define TPRINTF(F, X...) RtlPrintTrace(F, ## X) + +#endif /* __INCLUDE_NTDLL_TRACE_H */ diff --git a/reactos/lib/ntdll/rtl/trace.c b/reactos/lib/ntdll/rtl/trace.c new file mode 100644 index 00000000000..3c8ca79ccda --- /dev/null +++ b/reactos/lib/ntdll/rtl/trace.c @@ -0,0 +1,127 @@ +/* + * ReactOS kernel + * Copyright (C) 2000 David Welch + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/* $Id: trace.c,v 1.1 2001/04/10 18:15:22 dwelch Exp $ + * + * PROJECT: ReactOS kernel + * PURPOSE: Tracing library calls + * FILE: lib/ntdll/rtl/trace.c + * PROGRAMER: David Welch + */ + +/* INCLUDES *****************************************************************/ + +#include +#include +#include +#include + +#include + +/* GLOBALS *******************************************************************/ + +static NTDLL_TRACE_TABLE TraceTable; +static BOOLEAN TraceTableValid = FALSE; + +/* FUNCTIONS *****************************************************************/ + +NTSTATUS +RtlpInitTrace(VOID) +{ + HANDLE SectionHandle; + UNICODE_STRING SectionName; + OBJECT_ATTRIBUTES ObjectAttributes; + CHAR Buffer[4096]; + NTSTATUS Status; + PROCESS_BASIC_INFORMATION Pbi; + ULONG ReturnedSize; + PVOID BaseAddress; + LARGE_INTEGER Offset; + ULONG ViewSize; + + Status = NtQueryInformationProcess(NtCurrentProcess(), + ProcessBasicInformation, + (PVOID)&Pbi, + sizeof(Pbi), + &ReturnedSize); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + sprintf(Buffer, "\\??\\TraceSection%d", Pbi.UniqueProcessId); + + InitializeObjectAttributes(&ObjectAttributes, + &SectionName, + 0, + NULL, + NULL); + Status = NtOpenSection(&SectionHandle, + SECTION_MAP_READ, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + BaseAddress = 0; + Offset.QuadPart = 0; + ViewSize = 0; + Status = NtMapViewOfSection(SectionHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + sizeof(NTDLL_TRACE_TABLE), + &Offset, + &ViewSize, + ViewUnmap, + 0, + PAGE_READONLY); + if (!NT_SUCCESS(Status)) + { + NtClose(SectionHandle); + return(Status); + } + NtClose(SectionHandle); + + memcpy(&TraceTable, BaseAddress, sizeof(TraceTable)); + TraceTableValid = TRUE; + + Status = NtUnmapViewOfSection(NtCurrentProcess(), BaseAddress); + + return(STATUS_SUCCESS); +} + +VOID +RtlPrintTrace(ULONG Flag, PCH Format, ...) +{ + va_list ap; + CHAR FString[4096]; + + if (!TraceTableValid) + { + return; + } + if (TraceTable.Flags[Flag / BITS_IN_CHAR] & (1 << (Flag % BITS_IN_CHAR))) + { + va_start(ap, Format); + vsprintf(FString, Format, ap); + DbgPrint(FString); + va_end(ap); + } +}