[Com0com-cvs] com0com trace.c,1.2,1.3
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2005-02-28 12:10:19
|
Update of /cvsroot/com0com/com0com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14743 Modified Files: trace.c Log Message: Log skipped lines to trace file (was to syslog) Fixed missing trace file close Index: trace.c =================================================================== RCS file: /cvsroot/com0com/com0com/trace.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** trace.c 1 Feb 2005 16:39:35 -0000 1.2 --- trace.c 28 Feb 2005 12:10:08 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.3 2005/02/28 12:10:08 vfrolov + * Log skipped lines to trace file (was to syslog) + * Fixed missing trace file close + * * Revision 1.2 2005/02/01 16:39:35 vfrolov * Added AnsiStrCopyCommStatus() *************** *** 59,62 **** --- 63,67 ---- static KSPIN_LOCK bufsLock; static TRACE_BUFFER traceBufs[TRACE_BUFS_NUM]; + static LONG skippedTraces; /********************************************************************/ #define TRACE_FILE_OK (traceFileName.Buffer != NULL) *************** *** 190,194 **** if (!pBuf) ! SysLog(pDrvObj, STATUS_INSUFFICIENT_RESOURCES, L"AllocTraceBuf traceBufs busy"); return pBuf; --- 195,199 ---- if (!pBuf) ! InterlockedIncrement(&skippedTraces); return pBuf; *************** *** 638,642 **** (long)pCommStatus->AmountInInQueue); } - /********************************************************************/ --- 643,646 ---- *************** *** 676,689 **** (unsigned)pTimeFields->Milliseconds); } NTSTATUS TraceWrite( IN PVOID pIoObject, IN HANDLE handle, ! IN PCHAR pStr, ! IN USHORT len) { NTSTATUS status; IO_STATUS_BLOCK ioStatusBlock; status = ZwWriteFile( handle, --- 680,696 ---- (unsigned)pTimeFields->Milliseconds); } + /********************************************************************/ NTSTATUS TraceWrite( IN PVOID pIoObject, IN HANDLE handle, ! IN PCHAR pStr) { NTSTATUS status; + ANSI_STRING str; IO_STATUS_BLOCK ioStatusBlock; + RtlInitAnsiString(&str, pStr); + status = ZwWriteFile( handle, *************** *** 692,697 **** NULL, &ioStatusBlock, ! pStr, ! len, NULL, NULL); --- 699,704 ---- NULL, &ioStatusBlock, ! str.Buffer, ! str.Length, NULL, NULL); *************** *** 770,813 **** if (NT_SUCCESS(status)) { PTRACE_BUFFER pBuf; - ANSI_STRING str; - PCHAR pDestStr; - SIZE_T size; pBuf = AllocTraceBuf(); - if (!pBuf) - return; - size = TRACE_BUF_SIZE; - pDestStr = pBuf->buf; ! while (InterlockedExchangeAdd(&strOldFreeInd, 0)) { ! SIZE_T lenBuf; ! KIRQL oldIrql; ! KeAcquireSpinLock(&strOldLock, &oldIrql); ! lenBuf = strOldFreeInd - strOldBusyInd; ! if (lenBuf) { ! if (lenBuf > size - 1) ! lenBuf = size - 1; ! RtlCopyMemory(pDestStr, &strOld[strOldBusyInd], lenBuf); ! pDestStr[lenBuf] = 0; ! strOldBusyInd += lenBuf; ! ASSERT(strOldBusyInd <= strOldFreeInd); ! if (strOldBusyInd == strOldFreeInd) ! InterlockedExchange(&strOldFreeInd, strOldBusyInd = 0); } - KeReleaseSpinLock(&strOldLock, oldIrql); ! if (lenBuf) { ! RtlInitAnsiString(&str, pBuf->buf); ! TraceWrite(pIoObject, handle, str.Buffer, str.Length); } - } ! pDestStr = AnsiStrCopyTimeFields(pDestStr, &size, &timeFields); ! pDestStr = AnsiStrFormat(pDestStr, &size, " %s\r\n", pStr); ! RtlInitAnsiString(&str, pBuf->buf); ! TraceWrite(pIoObject, handle, str.Buffer, str.Length); ! FreeTraceBuf(pBuf); status = ZwClose(handle); --- 777,829 ---- if (NT_SUCCESS(status)) { PTRACE_BUFFER pBuf; pBuf = AllocTraceBuf(); ! if (pBuf) { ! PCHAR pDestStr; ! SIZE_T size; ! LONG skipped; ! size = TRACE_BUF_SIZE; ! pDestStr = pBuf->buf; ! ! while (InterlockedExchangeAdd(&strOldFreeInd, 0)) { ! SIZE_T lenBuf; ! KIRQL oldIrql; ! ! KeAcquireSpinLock(&strOldLock, &oldIrql); ! lenBuf = strOldFreeInd - strOldBusyInd; ! if (lenBuf) { ! if (lenBuf > size - 1) ! lenBuf = size - 1; ! RtlCopyMemory(pDestStr, &strOld[strOldBusyInd], lenBuf); ! pDestStr[lenBuf] = 0; ! strOldBusyInd += lenBuf; ! ASSERT(strOldBusyInd <= strOldFreeInd); ! if (strOldBusyInd == strOldFreeInd) ! InterlockedExchange(&strOldFreeInd, strOldBusyInd = 0); ! } ! KeReleaseSpinLock(&strOldLock, oldIrql); ! ! if (lenBuf) ! TraceWrite(pIoObject, handle, pBuf->buf); } ! skipped = InterlockedExchange(&skippedTraces, 0); ! ! if (skipped) { ! SIZE_T tmp_size = size; ! ! AnsiStrFormat(pDestStr, &tmp_size, "*** skipped %lu lines ***\r\n", skipped); ! TraceWrite(pIoObject, handle, pBuf->buf); } ! pDestStr = AnsiStrCopyTimeFields(pDestStr, &size, &timeFields); ! pDestStr = AnsiStrFormat(pDestStr, &size, " %s\r\n", pStr); ! TraceWrite(pIoObject, handle, pBuf->buf); ! ! FreeTraceBuf(pBuf); ! } status = ZwClose(handle); *************** *** 858,861 **** --- 874,878 ---- KeInitializeSpinLock(&strOldLock); KeInitializeSpinLock(&bufsLock); + skippedTraces = 0; RtlZeroMemory(traceBufs, sizeof(traceBufs)); |