VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/os2/assert-r0drv-os2.cpp@ 2555

Last change on this file since 2555 was 1206, checked in by vboxsync, 18 years ago

use the mscount member of the GIS for system monotonic time source on OS/2.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/* $Id: assert-r0drv-os2.cpp 1206 2007-03-05 00:58:31Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Assertion Workers, Ring-0 Drivers, OS/2.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/assert.h>
36#include <iprt/log.h>
37#include <iprt/string.h>
38#include <iprt/stdarg.h>
39
40#include <VBox/log.h>
41
42
43/*******************************************************************************
44* Global Variables *
45*******************************************************************************/
46/** The last assert message. (in DATA16) */
47extern char g_szRTAssertMsg[2048];
48/** The length of the last assert message. (in DATA16) */
49extern size_t g_cchRTAssertMsg;
50
51/*******************************************************************************
52* Internal Functions *
53*******************************************************************************/
54static DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars);
55
56
57/**
58 * The 1st part of an assert message.
59 *
60 * @param pszExpr Expression. Can be NULL.
61 * @param uLine Location line number.
62 * @param pszFile Location file name.
63 * @param pszFunction Location function name.
64 * @remark This API exists in HC Ring-3 and GC.
65 */
66RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
67{
68#ifdef IN_GUEST_R0
69 RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
70 "Expression: %s\n"
71 "Location : %s(%d) %s\n",
72 pszExpr, pszFile, uLine, pszFunction);
73#endif
74
75#if defined(DEBUG_bird)
76 RTLogComPrintf("\n!!Assertion Failed!!\n"
77 "Expression: %s\n"
78 "Location : %s(%d) %s\n",
79 pszExpr, pszFile, uLine, pszFunction);
80#endif
81
82 g_cchRTAssertMsg = RTStrPrintf(g_szRTAssertMsg, sizeof(g_szRTAssertMsg),
83 "\r\n!!Assertion Failed!!\r\n"
84 "Expression: %s\r\n"
85 "Location : %s(%d) %s\r\n",
86 pszExpr, pszFile, uLine, pszFunction);
87}
88
89
90/**
91 * The 2nd (optional) part of an assert message.
92 *
93 * @param pszFormat Printf like format string.
94 * @param ... Arguments to that string.
95 * @remark This API exists in HC Ring-3 and GC.
96 */
97RTDECL(void) AssertMsg2(const char *pszFormat, ...)
98{
99 va_list va;
100
101#ifdef IN_GUEST_R0
102 va_start(va, pszFormat);
103 RTLogBackdoorPrintfV(pszFormat, va);
104 va_end(va);
105#endif
106
107#if defined(DEBUG_bird)
108 va_start(va, pszFormat);
109 RTLogComPrintfV(pszFormat, va);
110 va_end(va);
111#endif
112
113 va_start(va, pszFormat);
114 size_t cch = g_cchRTAssertMsg;
115 char *pch = &g_szRTAssertMsg[cch];
116 cch += RTStrFormatV(rtR0Os2AssertOutputCB, &pch, NULL, NULL, pszFormat, va);
117 g_cchRTAssertMsg = cch;
118 va_end(va);
119}
120
121
122/**
123 * Output callback.
124 *
125 * @returns number of bytes written.
126 * @param pvArg Pointer to a char pointer with the current output position.
127 * @param pachChars Pointer to an array of utf-8 characters.
128 * @param cbChars Number of bytes in the character array pointed to by pachChars.
129 */
130static DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars)
131{
132 char **ppch = (char **)pvArg;
133 char *pch = *ppch;
134
135 while (cbChars-- > 0)
136 {
137 const char ch = *pachChars++;
138 if (ch == '\r')
139 continue;
140 if (ch == '\n')
141 {
142 if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
143 break;
144 *pch++ = '\r';
145 }
146 if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
147 break;
148 *pch++ = ch;
149 }
150 *pch = '\0';
151
152 size_t cbWritten = pch - *ppch;
153 *ppch = pch;
154 return cbWritten;
155}
156
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette