X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=os_win32.cpp;h=587503c41553fa7cd013cf5ad28862fa34f938a7;hb=45e094f2f82ec00291615aa055fb08f6efffe838;hp=04c03438f28243e9b36782e0520700441f817b08;hpb=6d633a935232de1f4e19467ce331b6e5290a378e;p=apitrace diff --git a/os_win32.cpp b/os_win32.cpp old mode 100755 new mode 100644 index 04c0343..587503c --- a/os_win32.cpp +++ b/os_win32.cpp @@ -24,7 +24,10 @@ **************************************************************************/ #include +#include +#include #include +#include #include "os.hpp" @@ -69,7 +72,7 @@ GetProcessName(char *str, size_t size) lpProcessExt = strrchr(lpProcessName, '.'); if (lpProcessExt) { - *lpProcessExt = '\0'; + *lpProcessExt = '\0'; } strncpy(str, lpProcessName, size); @@ -77,11 +80,95 @@ GetProcessName(char *str, size_t size) return true; } +bool +GetCurrentDir(char *str, size_t size) +{ + DWORD ret; + ret = GetCurrentDirectoryA(size, str); + str[size - 1] = 0; + return ret == 0 ? false : true; +} + +void +DebugMessage(const char *format, ...) +{ + char buf[4096]; + + va_list ap; + va_start(ap, format); + fflush(stdout); + vsnprintf(buf, sizeof buf, format, ap); + va_end(ap); + + OutputDebugStringA(buf); + + /* + * Also write the message to stderr, when a debugger is not present (to + * avoid duplicate messages in command line debuggers). + */ +#if _WIN32_WINNT > 0x0400 + if (!IsDebuggerPresent()) { + fflush(stdout); + fputs(buf, stderr); + fflush(stderr); + } +#endif +} + +long long GetTime(void) +{ + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + if (!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + return counter.QuadPart*1000000LL/frequency.QuadPart; +} void Abort(void) { +#ifndef NDEBUG + DebugBreak(); +#else ExitProcess(0); +#endif +} + + +static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter = NULL; +static void (*gCallback)(void) = NULL; + +static LONG WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo) +{ + if (gCallback) { + gCallback(); + } + + if (prevExceptionFilter) { + return prevExceptionFilter(pExceptionInfo); + } else { + return EXCEPTION_CONTINUE_SEARCH; + } +} + +void +SetExceptionCallback(void (*callback)(void)) +{ + assert(!gCallback); + + if (!gCallback) { + gCallback = callback; + + assert(!prevExceptionFilter); + prevExceptionFilter = SetUnhandledExceptionFilter(UnhandledExceptionFilter); + } +} + +void +ResetExceptionCallback(void) +{ + gCallback = NULL; }