VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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