assert-r0drv-os2.cpp revision 88774d64402bfd32254fcc5a81bda121c68300e6
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/* $Id$ */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Assertion Workers, Ring-0 Drivers, OS/2.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync/*
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync *
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * Permission is hereby granted, free of charge, to any person
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * obtaining a copy of this software and associated documentation
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * files (the "Software"), to deal in the Software without
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * restriction, including without limitation the rights to use,
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * copies of the Software, and to permit persons to whom the
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * Software is furnished to do so, subject to the following
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * conditions:
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync *
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * The above copyright notice and this permission notice shall be
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * included in all copies or substantial portions of the Software.
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync *
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync * OTHER DEALINGS IN THE SOFTWARE.
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync */
e86794d5ed13ea3053cb8f12be80630236ef2943vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Header Files *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/assert.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/log.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/string.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/stdarg.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <VBox/log.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync#include "internal/assert.h"
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Global Variables *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** The last assert message. (in DATA16) */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncextern char g_szRTAssertMsg[2048];
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** The length of the last assert message. (in DATA16) */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncextern size_t g_cchRTAssertMsg;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Internal Functions *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsyncvoid rtR0AssertNativeMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#if defined(DEBUG_bird)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RTLogComPrintf("\n!!Assertion Failed!!\n"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync "Expression: %s\n"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync "Location : %s(%d) %s\n",
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pszExpr, pszFile, uLine, pszFunction);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#endif
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync g_cchRTAssertMsg = RTStrPrintf(g_szRTAssertMsg, sizeof(g_szRTAssertMsg),
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync "\r\n!!Assertion Failed!!\r\n"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync "Expression: %s\r\n"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync "Location : %s(%d) %s\r\n",
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pszExpr, pszFile, uLine, pszFunction);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsyncvoid rtR0AssertNativeMsg2V(const char *pszFormat, va_list va)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#if defined(DEBUG_bird)
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync va_list vaCopy;
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync va_copy(vaCopy, va);
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync RTLogComPrintfV(pszFormat, vaCopy);
a7aa94e0115a73841f34ebbfa00f63fa1904e51fvboxsync va_end(vaCopy);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#endif
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync size_t cch = g_cchRTAssertMsg;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync char *pch = &g_szRTAssertMsg[cch];
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync cch += RTStrFormatV(rtR0Os2AssertOutputCB, &pch, NULL, NULL, pszFormat, va);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync g_cchRTAssertMsg = cch;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Output callback.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @returns number of bytes written.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pvArg Pointer to a char pointer with the current output position.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pachChars Pointer to an array of utf-8 characters.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param cbChars Number of bytes in the character array pointed to by pachChars.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync char **ppch = (char **)pvArg;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync char *pch = *ppch;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync while (cbChars-- > 0)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync const char ch = *pachChars++;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (ch == '\r')
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync continue;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (ch == '\n')
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync break;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *pch++ = '\r';
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync break;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *pch++ = ch;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *pch = '\0';
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync size_t cbWritten = pch - *ppch;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *ppch = pch;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return cbWritten;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
88774d64402bfd32254fcc5a81bda121c68300e6vboxsync
88774d64402bfd32254fcc5a81bda121c68300e6vboxsync/* RTR0AssertPanicSystem is implemented in RTR0AssertPanicSystem-r0drv-os2.asm */
88774d64402bfd32254fcc5a81bda121c68300e6vboxsync