Exemplo n.º 1
0
static void DebugPrintFuncSerial(const char *format, ...)
{
    char buf[TEMP_BUFFER_SIZE];
    NTSTATUS status;
    size_t len;
    va_list list;
    va_start(list, format);
    status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);
    if (status == STATUS_SUCCESS)
    {
        len = strlen(buf);
    }
    else
    {
        len = 2;
        buf[0] = 'O';
        buf[1] = '\n';
    }
    if (len)
    {
        WRITE_PORT_BUFFER_UCHAR(RHEL_DEBUG_PORT, (PUCHAR)buf, len);
        WRITE_PORT_UCHAR(RHEL_DEBUG_PORT, '\r');
    }
    va_end(list);
}
Exemplo n.º 2
0
void logDebug(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 debugLevel, const char *pStr, va_list marker)
{
    VOS_TRACE_LEVEL  vosDebugLevel;
    VOS_MODULE_ID    vosModuleId;
    char             logBuffer[LOG_SIZE];

    vosDebugLevel = getVosDebugLevel(debugLevel);
    vosModuleId = getVosModuleId(modId);

#ifdef ANI_OS_TYPE_ANDROID
    vsnprintf(logBuffer, LOG_SIZE - 1, pStr, marker);
#else

#ifdef WINDOWS_DT
    RtlStringCbVPrintfA( &logBuffer[ 0 ], LOG_SIZE - 1, pStr, marker );
#else
    _vsnprintf(logBuffer, LOG_SIZE - 1, (char *)pStr, marker);
#endif

#endif
    VOS_TRACE(vosModuleId, vosDebugLevel, "%s", logBuffer);

    // The caller must check loglevel
    VOS_ASSERT( ( debugLevel <= pMac->utils.gLogDbgLevel[LOG_INDEX_FOR_MODULE( modId )] ) && ( LOGP != debugLevel ) );
} /*** end logDebug() ***/
//common case, except Win2K
static void DebugPrint(const char *fmt, ...)
{
	va_list list;
	va_start(list, fmt);
	PrintProcedure(DPFLTR_DEFAULT_ID, 9 | DPFLTR_MASK, fmt, list);
#if defined(VIRTIO_DBG_USE_IOPORT)
	{
		NTSTATUS status;
		// use this way of output only for DISPATCH_LEVEL,
		// higher requires more protection
		if (KeGetCurrentIrql() <= DISPATCH_LEVEL)
		{
			char buf[256];
			size_t len, i;
			buf[0] = 0;
			status = RtlStringCbVPrintfA(buf, sizeof(buf), fmt, list);
			if (status == STATUS_SUCCESS) len = strlen(buf);
			else if (status == STATUS_BUFFER_OVERFLOW) len = sizeof(buf);
			else { memcpy(buf, "Can't print", 11); len = 11; }
			NdisAcquireSpinLock(&CrashLock);
			for (i = 0; i < len; ++i)
			{
				NdisRawWritePortUchar(VIRTIO_DBG_USE_IOPORT, buf[i]);
			}
			NdisRawWritePortUchar(VIRTIO_DBG_USE_IOPORT, '\n');
			NdisReleaseSpinLock(&CrashLock);
		}
	}
#endif
}
Exemplo n.º 4
0
int vcos_vsnprintf( char *buf, size_t buflen, const char *fmt, va_list ap )
{
#ifdef WIN32_KERN
    return RtlStringCbVPrintfA( buf, buflen, fmt, ap );
#else
    return vsnprintf(buf, buflen, fmt, ap);
#endif
}
Exemplo n.º 5
0
///////////////////////////////////////////////////////////////////////////////////////////////////
//  testdrvDebugPrint
//      Debug messages output routine.
//
//  Arguments:
//      IN  Area
//              Debug area (DBG_PNP, DBG_POWER, etc..)
//
//      IN  Level
//              Debug Level (DBG_ERR, DBG_INFO, etc..)
//
//      IN  Format
//              Debug Message Format
//
//  Return Value:
//      None.
//
VOID testdrvDebugPrint(
    IN ULONG    Area,
    IN ULONG    Level,
    IN PCCHAR   Format,
    IN          ...
    )
{
    ULONG i;
    va_list vaList;

    va_start(vaList, Format);

    // check mask for debug area and debug level
    if ((g_DebugArea & Area) && (Level <= g_DebugLevel))
    {
        // find a free buffer
        for (i = 0; i < NUMBER_DEBUG_BUFFERS; ++i)
        {
            if (InterlockedCompareExchange(&g_DebugBufferBusy[i], 1, 0) == 0)
            {
                NTSTATUS status;

                status = RtlStringCbVPrintfA(
                            g_DebugBuffer[i], 
                            sizeof(g_DebugBuffer[i]),
                            Format,
                            vaList
                            );

                if (Level == DBG_ERR)
                {
                    DbgPrint("TESTDRV(IRQL %2.2d): ERROR %s !!!!!\n", KeGetCurrentIrql(), g_DebugBuffer[i]); 
                }
                else if (Level == DBG_WARN)
                {
                    DbgPrint("TESTDRV(IRQL %2.2d): WARNING %s\n", KeGetCurrentIrql(), g_DebugBuffer[i]); 
                }
                else if (Level == DBG_INFO)
                {
                    DbgPrint("TESTDRV(IRQL %2.2d):     %s\n", KeGetCurrentIrql(), g_DebugBuffer[i]); 
                }
                else
                {
                    DbgPrint("TESTDRV(IRQL %2.2d): %s\n", KeGetCurrentIrql(), g_DebugBuffer[i]); 
                }

                InterlockedExchange(&g_DebugBufferBusy[i], 0);
                break;
            }
        }
    }

    va_end(vaList);
}
Exemplo n.º 6
0
int vcos_snprintf(char *buf, size_t buflen, const char *fmt, ...)
{
   int ret;
   va_list ap;
   va_start(ap,fmt);
#ifdef WIN32_KERN
   ret = RtlStringCbVPrintfA(buf, buflen, fmt, ap);
#else
   ret = vsnprintf(buf, buflen, fmt, ap);
#endif
   va_end(ap);
   return ret;
}
Exemplo n.º 7
0
Arquivo: out.c Projeto: 61--/zm
void __DbgOut(const char* format, ...)
{
	char buf[OUT_BUFFER_SIZE] = { 0 };
	NTSTATUS status;
	va_list list;
	size_t len;
	va_start(list, format);
	
	status = RtlStringCbVPrintfA(
		buf, sizeof(buf), format, list);
		
	if (status == STATUS_SUCCESS){
		len = strlen(buf);
		if (len < OUT_BUFFER_SIZE - 1){
			buf[len] = '\n';
		}
		DbgPrint(buf);
	}
	else{
		DbgPrint("DbgOut format string error %d", status);
	}
	va_end(list);
}
Exemplo n.º 8
0
VOID
TraceEvents (
    _In_ ULONG DebugPrintLevel,
    _In_ ULONG DebugPrintFlag,
    _Printf_format_string_
    _In_ PCSTR DebugMessage,
    ...
    )

/*++

Routine Description:

    Debug print for the sample driver.

Arguments:

    TraceEventsLevel - print level between 0 and 3, with 3 the most verbose

Return Value:

    None.

 --*/
 {
#if DBG
#define     TEMP_BUFFER_SIZE        1024
    va_list    list;
    CHAR       debugMessageBuffer[TEMP_BUFFER_SIZE];
    NTSTATUS   status;

    va_start(list, DebugMessage);

    if (DebugMessage) {

        //
        // Using new safe string functions instead of _vsnprintf.
        // This function takes care of NULL terminating if the message
        // is longer than the buffer.
        //
        status = RtlStringCbVPrintfA( debugMessageBuffer,
                                      sizeof(debugMessageBuffer),
                                      DebugMessage,
                                      list );
        if(!NT_SUCCESS(status)) {

            DbgPrint (_DRIVER_NAME_": RtlStringCbVPrintfA failed 0x%x\n", status);
            return;
        }
        if (DebugPrintLevel <= TRACE_LEVEL_ERROR ||
            (DebugPrintLevel <= DebugLevel &&
             ((DebugPrintFlag & DebugFlag) == DebugPrintFlag))) {
            DbgPrint("%s %s", _DRIVER_NAME_, debugMessageBuffer);
        }
    }
    va_end(list);

    return;
#else
    UNREFERENCED_PARAMETER(DebugPrintLevel);
    UNREFERENCED_PARAMETER(DebugPrintFlag);
    UNREFERENCED_PARAMETER(DebugMessage);
#endif
}
Exemplo n.º 9
0
/**	-----------------------------------------------------------------------
	\brief	debug message output routine

	\param	
		IN  Level
				Debug Level (DBG_ERR, DBG_INFO, etc..)
				
		IN  Format
				Debug Message Format

	\return			
		NONE
	\code	
	\endcode		
-------------------------------------------------------------------------*/
VOID DrvDebugPrint(IN DWORD Level, IN const char* Function,IN const char* Format, IN ...)
{
	CHAR ProcName[NT_PROCNAMELEN]={0};
    ULONG i=0;
    va_list vaList;
    va_start(vaList, Format);

    // check mask for debug area and debug level
	//
    if (Level <= g_DebugLevel)
    {
        // find a free buffer
		//
        for (i = 0; i < NUMBER_DEBUG_BUFFERS; ++i)
        {
            if (InterlockedCompareExchange((LONG*)&g_DebugBufferBusy[i], 1, 0) == 0)
            {
                __try
				{
					if (TRUE != NT_SUCCESS( RtlStringCbVPrintfA(
										            g_DebugBuffer[i], 
										            sizeof(g_DebugBuffer[i]),
										            Format,
										            vaList
										            )))
					{
						return;
					}
				}
				__except(EXCEPTION_EXECUTE_HANDLER)
				{
                    return;
				}


				get_process_name(PsGetCurrentProcess(), ProcName);
								
                if (DPFLTR_ERROR_LEVEL == Level)
                {
                    DbgPrintEx(
						DPFLTR_IHVDRIVER_ID, 
						DPFLTR_ERROR_LEVEL, 
						DRIVERNAME"(IRQL %2.2d): %-16s(%04u:%04u) : [ERR ] %s(), %s\n", 
						KeGetCurrentIrql(), 
						ProcName, 
						PsGetCurrentProcessId(), PsGetCurrentThreadId(),
						Function, 
                        g_DebugBuffer[i]
                        ); 
                }
                else if (DPFLTR_WARNING_LEVEL == Level)
                {
                    DbgPrintEx(
						DPFLTR_IHVDRIVER_ID, 
						DPFLTR_WARNING_LEVEL | DPFLTR_MASK,
						DRIVERNAME"(IRQL %2.2d): %-16s(%04u:%04u) : [WARN] %s(), %s\n", 
						KeGetCurrentIrql(), 
						ProcName, 
						PsGetCurrentProcessId(), PsGetCurrentThreadId(),
						Function,                         
                        g_DebugBuffer[i]
                    );
                }
				//else if (DPFLTR_TRACE_LEVEL == Level)
				//{
				//	DbgPrintEx(
				//		DPFLTR_IHVDRIVER_ID, 
				//		DPFLTR_TRACE_LEVEL | DPFLTR_MASK,
				//		DRIVERNAME"(IRQL %2.2d): [TRCE] %s(), %s\n", 
				//		KeGetCurrentIrql(), 
				//		Function,                         
				//		g_DebugBuffer[i]
				//	);					
				//}
                else
                {
                    DbgPrintEx(
						DPFLTR_IHVDRIVER_ID, 
						DPFLTR_INFO_LEVEL |  DPFLTR_MASK, 
						DRIVERNAME"(IRQL %2.2d): %-16s(%04u:%04u) : [INFO] %s(), %s\n", 
                        KeGetCurrentIrql(), 
						ProcName,
						PsGetCurrentProcessId(), PsGetCurrentThreadId(),
						Function,                         
                        g_DebugBuffer[i]
                        );
                }

                InterlockedExchange((LONG*)&g_DebugBufferBusy[i], 0);
                break;
            }
        }
    }
Exemplo n.º 10
0
NTSTATUS
AFSDbgLogMsg( IN ULONG Subsystem,
              IN ULONG Level,
              IN PCCH Format,
              ...)
{

    NTSTATUS ntStatus = STATUS_SUCCESS;
    va_list va_args;
    ULONG ulBytesWritten = 0;
    BOOLEAN bReleaseLock = FALSE;
    char    *pCurrentTrace = NULL;

    __Enter
    {

        if( AFSDbgBuffer == NULL)
        {

            try_return( ntStatus = STATUS_DEVICE_NOT_READY);
        }

        if( Subsystem > 0 &&
            (Subsystem & AFSTraceComponent) == 0)
        {

            //
            // Not tracing this subsystem
            //

            try_return( ntStatus);
        }

        if( Level > 0 &&
            Level > AFSTraceLevel)
        {

            //
            // Not tracing this level
            //

            try_return( ntStatus);
        }

        AFSAcquireExcl( &AFSDbgLogLock,
                        TRUE);

        bReleaseLock = TRUE;

        //
        // Check again under lock
        //

        if( AFSDbgBuffer == NULL)
        {

            try_return( ntStatus = STATUS_DEVICE_NOT_READY);
        }

        if( AFSDbgLogRemainingLength < 255)
        {

            AFSDbgLogRemainingLength = AFSDbgBufferLength;

            AFSDbgCurrentBuffer = AFSDbgBuffer;

            SetFlag( AFSDbgLogFlags, AFS_DBG_LOG_WRAPPED);
        }

        pCurrentTrace = AFSDbgCurrentBuffer;

        RtlStringCchPrintfA( AFSDbgCurrentBuffer,
                             10,
                             "%08lX:",
                             AFSDbgLogCounter++);

        AFSDbgCurrentBuffer += 9;

        AFSDbgLogRemainingLength -= 9;

        va_start( va_args, Format);

        ntStatus = RtlStringCbVPrintfA( AFSDbgCurrentBuffer,
                                        AFSDbgLogRemainingLength,
                                        Format,
                                        va_args);

        if( ntStatus == STATUS_BUFFER_OVERFLOW)
        {

            RtlZeroMemory( AFSDbgCurrentBuffer,
                           AFSDbgLogRemainingLength);

            AFSDbgLogRemainingLength = AFSDbgBufferLength;

            AFSDbgCurrentBuffer = AFSDbgBuffer;

            SetFlag( AFSDbgLogFlags, AFS_DBG_LOG_WRAPPED);

            pCurrentTrace = AFSDbgCurrentBuffer;

            RtlStringCchPrintfA( AFSDbgCurrentBuffer,
                                 10,
                                 "%08lX:",
                                 AFSDbgLogCounter++);

            AFSDbgCurrentBuffer += 9;

            AFSDbgLogRemainingLength -= 9;

            ntStatus = RtlStringCbVPrintfA( AFSDbgCurrentBuffer,
                                            AFSDbgLogRemainingLength,
                                            Format,
                                            va_args);
        }

        if( NT_SUCCESS( ntStatus))
        {

            RtlStringCbLengthA( AFSDbgCurrentBuffer,
                                AFSDbgLogRemainingLength,
                                (size_t *)&ulBytesWritten);

            AFSDbgCurrentBuffer += ulBytesWritten;

            AFSDbgLogRemainingLength -= ulBytesWritten;
        }

        va_end( va_args);

        if( BooleanFlagOn( AFSDebugFlags, AFS_DBG_TRACE_TO_DEBUGGER) &&
            pCurrentTrace != NULL)
        {

            DbgPrint( pCurrentTrace);
        }

try_exit:

        if( bReleaseLock)
        {

            AFSReleaseResource( &AFSDbgLogLock);
        }
    }

    return ntStatus;
}
Exemplo n.º 11
0
VOID
TraceEvents    (
    IN TRACEHANDLE TraceEventsLevel,
    IN ULONG   TraceEventsFlag,
    IN PCCHAR  DebugMessage,
    ...
    )

/*++

Routine Description:

    Debug print for the sample driver.

Arguments:

    TraceEventsLevel - print level between 0 and 3, with 3 the most verbose

Return Value:

    None.

 --*/
 {
#if DEBUG

#define     TEMP_BUFFER_SIZE        1024

    va_list    list;
    CHAR      debugMessageBuffer [TEMP_BUFFER_SIZE];
    NTSTATUS   status;

    va_start(list, DebugMessage);

    if (DebugMessage) {

        //
        // Using new safe string functions instead of _vsnprintf.
        // This function takes care of NULL terminating if the message
        // is longer than the buffer.
        //
        status = RtlStringCbVPrintfA( debugMessageBuffer,
                                      sizeof(debugMessageBuffer),
                                      DebugMessage,
                                      list );
        if(!NT_SUCCESS(status)) {

            KdPrint((_DRIVER_NAME_": RtlStringCbVPrintfA failed %x\n", status));
            return;
        }
        if (TraceEventsLevel < TRACE_LEVEL_INFORMATION ||
            (TraceEventsLevel <= DebugLevel &&
             ((TraceEventsFlag & DebugFlag) == TraceEventsFlag))) {

            KdPrint((debugMessageBuffer));
        }
    }
    va_end(list);

    return;

#else

    UNREFERENCED_PARAMETER(TraceEventsLevel);
    UNREFERENCED_PARAMETER(TraceEventsFlag);
    UNREFERENCED_PARAMETER(DebugMessage);
#endif
}