VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/nocrt-fatal-write-win.cpp@ 96388

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

IPRT/nocrt: Introduced an internal rtNoCrtFatalMsg/Write API to be used instead of RTMsgError and RTAssertMsg2 to report no-CRT init and runtime issues. The other two drags in hundreds of KBs of unnecessary code. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: nocrt-fatal-write-win.cpp 96388 2022-08-20 23:08:15Z vboxsync $ */
2/** @file
3 * IPRT - No-CRT - Fatal Message Writing Primitives, Windows.
4 */
5
6/*
7 * Copyright (C) 2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/nocrt.h"
32
33#include <iprt/win/windows.h>
34#include <iprt/string.h>
35
36
37/** @todo invent some kind of weak linking with the debug and release
38 * loggers, e.g. theset some innocent function we can call to do
39 * logging and we'll call it if it isn't NULL. */
40
41void rtNoCrtFatalWrite(const char *pchMsg, size_t cchMsg)
42{
43 DWORD cbIgn;
44 WriteFile(GetStdHandle(STD_ERROR_HANDLE ), pchMsg, (DWORD)cchMsg, &cbIgn, NULL);
45}
46
47
48void rtNoCrtFatalWriteBegin(const char *pchMsg, size_t cchMsg)
49{
50 rtNoCrtFatalWrite(pchMsg, cchMsg);
51}
52
53
54void rtNoCrtFatalWriteEnd(const char *pchMsg, size_t cchMsg)
55{
56 rtNoCrtFatalWrite(pchMsg, cchMsg);
57}
58
59
60void rtNoCrtFatalWritePtr(void const *pv)
61{
62 char szValue[128];
63#if ARCH_BITS == 64
64 ssize_t cchValue = RTStrFormatU64(szValue, sizeof(szValue), (uintptr_t)pv, 16, 16, 16, RTSTR_F_WIDTH | RTSTR_F_64BIT);
65#elif ARCH_BITS == 32
66 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), (uintptr_t)pv, 16, 8, 8, RTSTR_F_WIDTH | RTSTR_F_32BIT);
67#else
68# error ARCH_BITS
69#endif
70 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
71}
72
73
74void rtNoCrtFatalWriteX64(uint64_t uValue)
75{
76 char szValue[128];
77 ssize_t cchValue = RTStrFormatU64(szValue, sizeof(szValue), uValue, 16, 0, 0, RTSTR_F_SPECIAL | RTSTR_F_64BIT);
78 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
79}
80
81
82void rtNoCrtFatalWriteX32(uint32_t uValue)
83{
84 char szValue[128];
85 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), uValue, 16, 0, 0, RTSTR_F_SPECIAL | RTSTR_F_32BIT);
86 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
87}
88
89
90void rtNoCrtFatalWriteRc(int rc)
91{
92 char szValue[128];
93 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), rc, 10, 0, 0, RTSTR_F_32BIT | RTSTR_F_VALSIGNED);
94 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
95}
96
97void rtNoCrtFatalWriteWinRc(uint32_t rc)
98{
99 char szValue[168];
100 ssize_t cchValue = RTStrFormatU32(szValue, sizeof(szValue), rc, 10, 0, 0, RTSTR_F_32BIT);
101 szValue[cchValue++] = ' ';
102 szValue[cchValue++] = '(';
103 cchValue += RTStrFormatU32(&szValue[cchValue], sizeof(szValue) - cchValue, rc, 16, 0, 0, RTSTR_F_32BIT | RTSTR_F_SPECIAL);
104 szValue[cchValue++] = ')';
105 rtNoCrtFatalWrite(szValue, (size_t)cchValue);
106}
107
108
109void rtNoCrtFatalWriteStr(const char *pszString)
110{
111 if (RT_VALID_PTR(pszString))
112 {
113 size_t cch = 0;
114 while (pszString[cch] != '\0')
115 cch++;
116 rtNoCrtFatalWrite(pszString, cch);
117 }
118 else
119 {
120 rtNoCrtFatalWrite(RT_STR_TUPLE("<pszString="));
121 rtNoCrtFatalWritePtr(pszString);
122 rtNoCrtFatalWrite(RT_STR_TUPLE(">"));
123 }
124}
125
126
127void rtNoCrtFatalMsg(const char *pchMsg, size_t cchMsg)
128{
129 rtNoCrtFatalWriteBegin(pchMsg, cchMsg);
130 rtNoCrtFatalWriteEnd(RT_STR_TUPLE(""));
131}
132
133
134void rtNoCrtFatalMsgWithRc(const char *pchMsg, size_t cchMsg, int rc)
135{
136 rtNoCrtFatalWriteBegin(pchMsg, cchMsg);
137 rtNoCrtFatalWriteRc(rc);
138 rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
139}
140
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