1 | /* $Id: assert-r0drv-os2.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Assertion Workers, Ring-0 Drivers, OS/2.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Contributed by knut st. osmundsen.
|
---|
8 | *
|
---|
9 | * Copyright (C) 2007-2020 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * The contents of this file may alternatively be used under the terms
|
---|
20 | * of the Common Development and Distribution License Version 1.0
|
---|
21 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
22 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
23 | * CDDL are applicable instead of those of the GPL.
|
---|
24 | *
|
---|
25 | * You may elect to license modified versions of this file under the
|
---|
26 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
27 | * --------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * This code is based on:
|
---|
30 | *
|
---|
31 | * Copyright (c) 2007 knut st. osmundsen <[email protected]>
|
---|
32 | *
|
---|
33 | * Permission is hereby granted, free of charge, to any person
|
---|
34 | * obtaining a copy of this software and associated documentation
|
---|
35 | * files (the "Software"), to deal in the Software without
|
---|
36 | * restriction, including without limitation the rights to use,
|
---|
37 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
38 | * copies of the Software, and to permit persons to whom the
|
---|
39 | * Software is furnished to do so, subject to the following
|
---|
40 | * conditions:
|
---|
41 | *
|
---|
42 | * The above copyright notice and this permission notice shall be
|
---|
43 | * included in all copies or substantial portions of the Software.
|
---|
44 | *
|
---|
45 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
46 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
47 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
48 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
49 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
50 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
51 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
52 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
53 | */
|
---|
54 |
|
---|
55 |
|
---|
56 | /*********************************************************************************************************************************
|
---|
57 | * Header Files *
|
---|
58 | *********************************************************************************************************************************/
|
---|
59 | #include <iprt/assert.h>
|
---|
60 | #include <iprt/log.h>
|
---|
61 | #include <iprt/string.h>
|
---|
62 | #include <iprt/stdarg.h>
|
---|
63 |
|
---|
64 | #include <VBox/log.h>
|
---|
65 |
|
---|
66 | #include "internal/assert.h"
|
---|
67 |
|
---|
68 |
|
---|
69 | /*********************************************************************************************************************************
|
---|
70 | * Global Variables *
|
---|
71 | *********************************************************************************************************************************/
|
---|
72 | RT_C_DECLS_BEGIN /* for watcom */
|
---|
73 | /** The last assert message. (in DATA16) */
|
---|
74 | extern char g_szRTAssertMsg[2048];
|
---|
75 | /** The length of the last assert message. (in DATA16) */
|
---|
76 | extern size_t g_cchRTAssertMsg;
|
---|
77 | RT_C_DECLS_END
|
---|
78 |
|
---|
79 |
|
---|
80 | /*********************************************************************************************************************************
|
---|
81 | * Internal Functions *
|
---|
82 | *********************************************************************************************************************************/
|
---|
83 | static DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars);
|
---|
84 |
|
---|
85 |
|
---|
86 | DECLHIDDEN(void) rtR0AssertNativeMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
|
---|
87 | {
|
---|
88 | #if defined(DEBUG_bird)
|
---|
89 | RTLogComPrintf("\n!!Assertion Failed!!\n"
|
---|
90 | "Expression: %s\n"
|
---|
91 | "Location : %s(%d) %s\n",
|
---|
92 | pszExpr, pszFile, uLine, pszFunction);
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | g_cchRTAssertMsg = RTStrPrintf(g_szRTAssertMsg, sizeof(g_szRTAssertMsg),
|
---|
96 | "\r\n!!Assertion Failed!!\r\n"
|
---|
97 | "Expression: %s\r\n"
|
---|
98 | "Location : %s(%d) %s\r\n",
|
---|
99 | pszExpr, pszFile, uLine, pszFunction);
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | DECLHIDDEN(void) rtR0AssertNativeMsg2V(bool fInitial, const char *pszFormat, va_list va)
|
---|
104 | {
|
---|
105 | #if defined(DEBUG_bird)
|
---|
106 | va_list vaCopy;
|
---|
107 | va_copy(vaCopy, va);
|
---|
108 | RTLogComPrintfV(pszFormat, vaCopy);
|
---|
109 | va_end(vaCopy);
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | size_t cch = g_cchRTAssertMsg;
|
---|
113 | char *pch = &g_szRTAssertMsg[cch];
|
---|
114 | cch += RTStrFormatV(rtR0Os2AssertOutputCB, &pch, NULL, NULL, pszFormat, va);
|
---|
115 | g_cchRTAssertMsg = cch;
|
---|
116 |
|
---|
117 | NOREF(fInitial);
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Output callback.
|
---|
123 | *
|
---|
124 | * @returns number of bytes written.
|
---|
125 | * @param pvArg Pointer to a char pointer with the current output position.
|
---|
126 | * @param pachChars Pointer to an array of utf-8 characters.
|
---|
127 | * @param cbChars Number of bytes in the character array pointed to by pachChars.
|
---|
128 | */
|
---|
129 | static DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars)
|
---|
130 | {
|
---|
131 | char **ppch = (char **)pvArg;
|
---|
132 | char *pch = *ppch;
|
---|
133 |
|
---|
134 | while (cbChars-- > 0)
|
---|
135 | {
|
---|
136 | const char ch = *pachChars++;
|
---|
137 | if (ch == '\r')
|
---|
138 | continue;
|
---|
139 | if (ch == '\n')
|
---|
140 | {
|
---|
141 | if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
|
---|
142 | break;
|
---|
143 | *pch++ = '\r';
|
---|
144 | }
|
---|
145 | if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
|
---|
146 | break;
|
---|
147 | *pch++ = ch;
|
---|
148 | }
|
---|
149 | *pch = '\0';
|
---|
150 |
|
---|
151 | size_t cbWritten = pch - *ppch;
|
---|
152 | *ppch = pch;
|
---|
153 | return cbWritten;
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | /* RTR0AssertPanicSystem is implemented in RTR0AssertPanicSystem-r0drv-os2.asm */
|
---|
158 |
|
---|