HyperPlatform Programmer's Reference
Classes | Macros | Functions | Variables
log.cpp File Reference

Implements logging functions. More...

#include "log.h"
#include <ntstrsafe.h>
Include dependency graph for log.cpp:

Go to the source code of this file.

Classes

struct  LogBufferInfo
 

Macros

#define NTSTRSAFE_NO_CB_FUNCTIONS
 

Functions

NTKERNELAPI UCHAR *NTAPI PsGetProcessImageFileName (_In_ PEPROCESS process)
 
static NTSTATUS LogpInitializeBufferInfo (_In_ const wchar_t *log_file_path, _Inout_ LogBufferInfo *info)
 
static NTSTATUS LogpInitializeLogFile (_Inout_ LogBufferInfo *info)
 
static void LogpFinalizeBufferInfo (_In_ LogBufferInfo *info)
 
static NTSTATUS LogpMakePrefix (_In_ ULONG level, _In_z_ const char *function_name, _In_z_ const char *log_message, _Out_ char *log_buffer, _In_ SIZE_T log_buffer_length)
 
static const char * LogpFindBaseFunctionName (_In_z_ const char *function_name)
 
static NTSTATUS LogpPut (_In_z_ char *message, _In_ ULONG attribute)
 
static NTSTATUS LogpFlushLogBuffer (_Inout_ LogBufferInfo *info)
 
static NTSTATUS LogpWriteMessageToFile (_In_z_ const char *message, _In_ const LogBufferInfo &info)
 
static NTSTATUS LogpBufferMessage (_In_z_ const char *message, _Inout_ LogBufferInfo *info)
 
static void LogpDoDbgPrint (_In_z_ char *message)
 
static bool LogpIsLogFileEnabled (_In_ const LogBufferInfo &info)
 
static bool LogpIsLogFileActivated (_In_ const LogBufferInfo &info)
 
static bool LogpIsLogNeeded (_In_ ULONG level)
 
static bool LogpIsDbgPrintNeeded ()
 
static NTSTATUS LogpSleep (_In_ LONG millisecond)
 
static void LogpSetPrintedBit (_In_z_ char *message, _In_ bool on)
 
static bool LogpIsPrinted (_In_z_ char *message)
 
static void LogpDbgBreak ()
 
NTSTATUS LogInitialization (ULONG flag, const wchar_t *log_file_path)
 
static NTSTATUS LogpInitializeBufferInfo (const wchar_t *log_file_path, LogBufferInfo *info)
 
static NTSTATUS LogpInitializeLogFile (LogBufferInfo *info)
 
void LogRegisterReinitialization (PDRIVER_OBJECT driver_object)
 
static VOID LogpReinitializationRoutine (_DRIVER_OBJECT *driver_object, PVOID context, ULONG count)
 
void LogIrpShutdownHandler ()
 Terminates the log system. Should be called from an IRP_MJ_SHUTDOWN handler. More...
 
void LogTermination ()
 Terminates the log system. Should be called from a DriverUnload routine. More...
 
static void LogpFinalizeBufferInfo (LogBufferInfo *info)
 
NTSTATUS LogpPrint (ULONG level, const char *function_name, const char *format,...)
 
static NTSTATUS LogpMakePrefix (ULONG level, const char *function_name, const char *log_message, char *log_buffer, SIZE_T log_buffer_length)
 
static const char * LogpFindBaseFunctionName (const char *function_name)
 
static NTSTATUS LogpPut (char *message, ULONG attribute)
 
static NTSTATUS LogpFlushLogBuffer (LogBufferInfo *info)
 
static NTSTATUS LogpWriteMessageToFile (const char *message, const LogBufferInfo &info)
 
static NTSTATUS LogpBufferMessage (const char *message, LogBufferInfo *info)
 
static void LogpDoDbgPrint (char *message)
 
static bool LogpIsLogFileEnabled (const LogBufferInfo &info)
 
static bool LogpIsLogFileActivated (const LogBufferInfo &info)
 
static bool LogpIsLogNeeded (ULONG level)
 
static VOID LogpBufferFlushThreadRoutine (void *start_context)
 
static NTSTATUS LogpSleep (LONG millisecond)
 
static void LogpSetPrintedBit (char *message, bool on)
 
static bool LogpIsPrinted (char *message)
 
_Check_return_opt_ int __cdecl __stdio_common_vsprintf (_In_ unsigned __int64 _Options, _Out_writes_opt_z_(_BufferCount) char *_Buffer, _In_ size_t _BufferCount, _In_z_ _Printf_format_string_params_(2) char const *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList)
 
_Check_return_opt_ int __cdecl __stdio_common_vswprintf (_In_ unsigned __int64 _Options, _Out_writes_opt_z_(_BufferCount) wchar_t *_Buffer, _In_ size_t _BufferCount, _In_z_ _Printf_format_string_params_(2) wchar_t const *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList)
 

Variables

static const auto kLogpBufferSizeInPages = 16ul
 
static const auto kLogpBufferSize = PAGE_SIZE * kLogpBufferSizeInPages
 
static const auto kLogpBufferUsableSize = kLogpBufferSize - 1
 
static const auto kLogpLogFlushIntervalMsec = 50
 
static const ULONG kLogpPoolTag = ' gol'
 
static DRIVER_REINITIALIZE LogpReinitializationRoutine
 
static KSTART_ROUTINE LogpBufferFlushThreadRoutine
 
static auto g_logp_debug_flag = kLogPutLevelDisable
 
static LogBufferInfo g_logp_log_buffer_info = {}
 

Detailed Description

Implements logging functions.

Definition in file log.cpp.

Macro Definition Documentation

◆ NTSTRSAFE_NO_CB_FUNCTIONS

#define NTSTRSAFE_NO_CB_FUNCTIONS

Definition at line 9 of file log.cpp.

Function Documentation

◆ __stdio_common_vsprintf()

_Check_return_opt_ int __cdecl __stdio_common_vsprintf ( _In_ unsigned __int64  _Options,
_Out_writes_opt_z_(_BufferCount) char *  _Buffer,
_In_ size_t  _BufferCount,
_In_z_ _Printf_format_string_params_(2) char const *  _Format,
_In_opt_ _locale_t  _Locale,
va_list  _ArgList 
)

Definition at line 810 of file log.cpp.

◆ __stdio_common_vswprintf()

_Check_return_opt_ int __cdecl __stdio_common_vswprintf ( _In_ unsigned __int64  _Options,
_Out_writes_opt_z_(_BufferCount) wchar_t *  _Buffer,
_In_ size_t  _BufferCount,
_In_z_ _Printf_format_string_params_(2) wchar_t const *  _Format,
_In_opt_ _locale_t  _Locale,
va_list  _ArgList 
)

Definition at line 832 of file log.cpp.

◆ LogInitialization()

NTSTATUS LogInitialization ( ULONG  flag,
const wchar_t *  log_file_path 
)

Definition at line 159 of file log.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogIrpShutdownHandler()

void LogIrpShutdownHandler ( )

Terminates the log system. Should be called from an IRP_MJ_SHUTDOWN handler.

Definition at line 331 of file log.cpp.

Here is the call graph for this function:

◆ LogpBufferFlushThreadRoutine()

static VOID LogpBufferFlushThreadRoutine ( void *  start_context)
static

Definition at line 753 of file log.cpp.

Here is the call graph for this function:

◆ LogpBufferMessage() [1/2]

static NTSTATUS LogpBufferMessage ( _In_z_ const char *  message,
_Inout_ LogBufferInfo info 
)
static
Here is the caller graph for this function:

◆ LogpBufferMessage() [2/2]

static NTSTATUS LogpBufferMessage ( const char *  message,
LogBufferInfo info 
)
static

Definition at line 660 of file log.cpp.

◆ LogpDbgBreak()

static void LogpDbgBreak ( )
static

Definition at line 802 of file log.cpp.

Here is the caller graph for this function:

◆ LogpDoDbgPrint() [1/2]

static void LogpDoDbgPrint ( _In_z_ char *  message)
static
Here is the caller graph for this function:

◆ LogpDoDbgPrint() [2/2]

static void LogpDoDbgPrint ( char *  message)
static

Definition at line 702 of file log.cpp.

Here is the call graph for this function:

◆ LogpFinalizeBufferInfo() [1/2]

static void LogpFinalizeBufferInfo ( _In_ LogBufferInfo info)
static
Here is the caller graph for this function:

◆ LogpFinalizeBufferInfo() [2/2]

static void LogpFinalizeBufferInfo ( LogBufferInfo info)
static

Definition at line 360 of file log.cpp.

Here is the call graph for this function:

◆ LogpFindBaseFunctionName() [1/2]

static const char* LogpFindBaseFunctionName ( _In_z_ const char *  function_name)
static
Here is the caller graph for this function:

◆ LogpFindBaseFunctionName() [2/2]

static const char* LogpFindBaseFunctionName ( const char *  function_name)
static

Definition at line 527 of file log.cpp.

◆ LogpFlushLogBuffer() [1/2]

static NTSTATUS LogpFlushLogBuffer ( _Inout_ LogBufferInfo info)
static
Here is the caller graph for this function:

◆ LogpFlushLogBuffer() [2/2]

static NTSTATUS LogpFlushLogBuffer ( LogBufferInfo info)
static

Definition at line 585 of file log.cpp.

Here is the call graph for this function:

◆ LogpInitializeBufferInfo() [1/2]

static NTSTATUS LogpInitializeBufferInfo ( _In_ const wchar_t *  log_file_path,
_Inout_ LogBufferInfo info 
)
static
Here is the caller graph for this function:

◆ LogpInitializeBufferInfo() [2/2]

static NTSTATUS LogpInitializeBufferInfo ( const wchar_t *  log_file_path,
LogBufferInfo info 
)
static

Definition at line 198 of file log.cpp.

Here is the call graph for this function:

◆ LogpInitializeLogFile() [1/2]

static NTSTATUS LogpInitializeLogFile ( _Inout_ LogBufferInfo info)
static
Here is the caller graph for this function:

◆ LogpInitializeLogFile() [2/2]

static NTSTATUS LogpInitializeLogFile ( LogBufferInfo info)
static

Definition at line 259 of file log.cpp.

Here is the call graph for this function:

◆ LogpIsDbgPrintNeeded()

static bool LogpIsDbgPrintNeeded ( )
static

Definition at line 747 of file log.cpp.

Here is the caller graph for this function:

◆ LogpIsLogFileActivated() [1/2]

static bool LogpIsLogFileActivated ( _In_ const LogBufferInfo info)
static
Here is the caller graph for this function:

◆ LogpIsLogFileActivated() [2/2]

static bool LogpIsLogFileActivated ( const LogBufferInfo info)
static

Definition at line 728 of file log.cpp.

◆ LogpIsLogFileEnabled() [1/2]

static bool LogpIsLogFileEnabled ( _In_ const LogBufferInfo info)
static
Here is the caller graph for this function:

◆ LogpIsLogFileEnabled() [2/2]

static bool LogpIsLogFileEnabled ( const LogBufferInfo info)
static

Definition at line 713 of file log.cpp.

◆ LogpIsLogNeeded() [1/2]

static bool LogpIsLogNeeded ( _In_ ULONG  level)
static
Here is the caller graph for this function:

◆ LogpIsLogNeeded() [2/2]

static bool LogpIsLogNeeded ( ULONG  level)
static

Definition at line 742 of file log.cpp.

◆ LogpIsPrinted() [1/2]

static bool LogpIsPrinted ( _In_z_ char *  message)
static
Here is the caller graph for this function:

◆ LogpIsPrinted() [2/2]

static bool LogpIsPrinted ( char *  message)
static

Definition at line 797 of file log.cpp.

◆ LogpMakePrefix() [1/2]

static NTSTATUS LogpMakePrefix ( _In_ ULONG  level,
_In_z_ const char *  function_name,
_In_z_ const char *  log_message,
_Out_ char *  log_buffer,
_In_ SIZE_T  log_buffer_length 
)
static
Here is the caller graph for this function:

◆ LogpMakePrefix() [2/2]

static NTSTATUS LogpMakePrefix ( ULONG  level,
const char *  function_name,
const char *  log_message,
char *  log_buffer,
SIZE_T  log_buffer_length 
)
static

Definition at line 445 of file log.cpp.

Here is the call graph for this function:

◆ LogpPrint()

NTSTATUS LogpPrint ( ULONG  level,
const char *  function_name,
const char *  format,
  ... 
)

Definition at line 397 of file log.cpp.

Here is the call graph for this function:

◆ LogpPut() [1/2]

static NTSTATUS LogpPut ( _In_z_ char *  message,
_In_ ULONG  attribute 
)
static
Here is the caller graph for this function:

◆ LogpPut() [2/2]

static NTSTATUS LogpPut ( char *  message,
ULONG  attribute 
)
static

Definition at line 544 of file log.cpp.

Here is the call graph for this function:

◆ LogpReinitializationRoutine()

static VOID LogpReinitializationRoutine ( _DRIVER_OBJECT *  driver_object,
PVOID  context,
ULONG  count 
)
static

Definition at line 314 of file log.cpp.

Here is the call graph for this function:

◆ LogpSetPrintedBit() [1/2]

static void LogpSetPrintedBit ( _In_z_ char *  message,
_In_ bool  on 
)
static
Here is the caller graph for this function:

◆ LogpSetPrintedBit() [2/2]

static void LogpSetPrintedBit ( char *  message,
bool  on 
)
static

Definition at line 788 of file log.cpp.

◆ LogpSleep() [1/2]

static NTSTATUS LogpSleep ( _In_ LONG  millisecond)
static
Here is the caller graph for this function:

◆ LogpSleep() [2/2]

static NTSTATUS LogpSleep ( LONG  millisecond)
static

Definition at line 778 of file log.cpp.

◆ LogpWriteMessageToFile() [1/2]

static NTSTATUS LogpWriteMessageToFile ( _In_z_ const char *  message,
_In_ const LogBufferInfo info 
)
static
Here is the caller graph for this function:

◆ LogpWriteMessageToFile() [2/2]

static NTSTATUS LogpWriteMessageToFile ( const char *  message,
const LogBufferInfo info 
)
static

Definition at line 640 of file log.cpp.

Here is the call graph for this function:

◆ LogRegisterReinitialization()

void LogRegisterReinitialization ( PDRIVER_OBJECT  driver_object)

Definition at line 305 of file log.cpp.

Here is the caller graph for this function:

◆ LogTermination()

void LogTermination ( )

Terminates the log system. Should be called from a DriverUnload routine.

Definition at line 348 of file log.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PsGetProcessImageFileName()

NTKERNELAPI UCHAR* NTAPI PsGetProcessImageFileName ( _In_ PEPROCESS  process)
Here is the caller graph for this function:

Variable Documentation

◆ g_logp_debug_flag

auto g_logp_debug_flag = kLogPutLevelDisable
static

Definition at line 150 of file log.cpp.

◆ g_logp_log_buffer_info

LogBufferInfo g_logp_log_buffer_info = {}
static

Definition at line 151 of file log.cpp.

◆ kLogpBufferSize

const auto kLogpBufferSize = PAGE_SIZE * kLogpBufferSizeInPages
static

Definition at line 32 of file log.cpp.

◆ kLogpBufferSizeInPages

const auto kLogpBufferSizeInPages = 16ul
static

Definition at line 29 of file log.cpp.

◆ kLogpBufferUsableSize

const auto kLogpBufferUsableSize = kLogpBufferSize - 1
static

Definition at line 36 of file log.cpp.

◆ kLogpLogFlushIntervalMsec

const auto kLogpLogFlushIntervalMsec = 50
static

Definition at line 39 of file log.cpp.

◆ kLogpPoolTag

const ULONG kLogpPoolTag = ' gol'
static

Definition at line 41 of file log.cpp.

◆ LogpBufferFlushThreadRoutine

KSTART_ROUTINE LogpBufferFlushThreadRoutine
static

Definition at line 121 of file log.cpp.

◆ LogpReinitializationRoutine

DRIVER_REINITIALIZE LogpReinitializationRoutine
static

Definition at line 86 of file log.cpp.