VirtualBox

source: vbox/trunk/src/VBox/Runtime/generic/RTProcSignalName-generic.cpp@ 97646

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

IPRT: Added RTProcSignalName and a generic implementation of it.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: RTProcSignalName-generic.cpp 97646 2022-11-22 01:02:48Z vboxsync $ */
2/** @file
3 * IPRT - RTProcSignalName, generic implementation.
4 */
5
6/*
7 * Copyright (C) 2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/process.h>
42#include "internal/iprt.h"
43
44#include <iprt/asm.h>
45#include <iprt/string.h>
46
47#include <signal.h>
48
49
50RTDECL(const char *) RTProcSignalName(int iSignal)
51{
52 switch (iSignal)
53 {
54 /*
55 * Typical bsd/xnu ones:
56 */
57#ifdef SIGHUP
58 RT_CASE_RET_STR(SIGHUP);
59#endif
60#ifdef SIGINT
61 RT_CASE_RET_STR(SIGINT);
62#endif
63#ifdef SIGQUIT
64 RT_CASE_RET_STR(SIGQUIT);
65#endif
66#ifdef SIGILL
67 RT_CASE_RET_STR(SIGILL);
68#endif
69#ifdef SIGTRAP
70 RT_CASE_RET_STR(SIGTRAP);
71#endif
72#ifdef SIGABRT
73 RT_CASE_RET_STR(SIGABRT);
74#endif
75#ifdef SIGEMT
76 RT_CASE_RET_STR(SIGEMT);
77#endif
78#ifdef SIGPOLL
79 RT_CASE_RET_STR(SIGPOLL);
80#endif
81#ifdef SIGFPE
82 RT_CASE_RET_STR(SIGFPE);
83#endif
84#ifdef SIGKILL
85 RT_CASE_RET_STR(SIGKILL);
86#endif
87#ifdef SIGBUS
88 RT_CASE_RET_STR(SIGBUS);
89#endif
90#ifdef SIGSEGV
91 RT_CASE_RET_STR(SIGSEGV);
92#endif
93#ifdef SIGSYS
94 RT_CASE_RET_STR(SIGSYS);
95#endif
96#ifdef SIGPIPE
97 RT_CASE_RET_STR(SIGPIPE);
98#endif
99#ifdef SIGALRM
100 RT_CASE_RET_STR(SIGALRM);
101#endif
102#ifdef SIGTERM
103 RT_CASE_RET_STR(SIGTERM);
104#endif
105#ifdef SIGURG
106 RT_CASE_RET_STR(SIGURG);
107#endif
108#ifdef SIGSTOP
109 RT_CASE_RET_STR(SIGSTOP);
110#endif
111#ifdef SIGTSTP
112 RT_CASE_RET_STR(SIGTSTP);
113#endif
114#ifdef SIGCONT
115 RT_CASE_RET_STR(SIGCONT);
116#endif
117#ifdef SIGCHLD
118 RT_CASE_RET_STR(SIGCHLD);
119#endif
120#ifdef SIGTTIN
121 RT_CASE_RET_STR(SIGTTIN);
122#endif
123#ifdef SIGTTOU
124 RT_CASE_RET_STR(SIGTTOU);
125#endif
126#ifdef SIGIO
127# if !defined(SIGPOLL) || (SIGPOLL+0) != SIGIO
128 RT_CASE_RET_STR(SIGIO);
129# endif
130#endif
131#ifdef SIGXCPU
132 RT_CASE_RET_STR(SIGXCPU);
133#endif
134#ifdef SIGXFSZ
135 RT_CASE_RET_STR(SIGXFSZ);
136#endif
137#ifdef SIGVTALRM
138 RT_CASE_RET_STR(SIGVTALRM);
139#endif
140#ifdef SIGPROF
141 RT_CASE_RET_STR(SIGPROF);
142#endif
143#ifdef SIGWINCH
144 RT_CASE_RET_STR(SIGWINCH);
145#endif
146#ifdef SIGINFO
147 RT_CASE_RET_STR(SIGINFO);
148#endif
149#ifdef SIGUSR1
150 RT_CASE_RET_STR(SIGUSR1);
151#endif
152#ifdef SIGUSR2
153 RT_CASE_RET_STR(SIGUSR2);
154#endif
155#ifdef SIGTHR
156 RT_CASE_RET_STR(SIGTHR);
157#endif
158#ifdef SIGLIBRT
159 RT_CASE_RET_STR(SIGLIBRT);
160#endif
161
162 /*
163 * Additional linux ones:
164 */
165#ifdef SIGIOT
166# if !defined(SIGABRT) || (SIGABRT+0) != SIGIOT
167 RT_CASE_RET_STR(SIGIOT);
168# endif
169#endif
170#ifdef SIGSTKFLT
171 RT_CASE_RET_STR(SIGSTKFLT);
172#endif
173#ifdef SIGLOST
174 RT_CASE_RET_STR(SIGLOST);
175#endif
176#ifdef SIGPWR
177 RT_CASE_RET_STR(SIGPWR);
178#endif
179#ifdef SIGUNUSED
180 RT_CASE_RET_STR(SIGUNUSED);
181#endif
182 }
183
184#if defined(SIGRTMIN) && defined(SIGRTMAX)
185 /*
186 * Real time signals.
187 *
188 * This cannot be done in the switch/case setup because glibc maps SIGRTMIN
189 * and SIGRTMAX to internal libc calls that dynamically resolves their values.
190 */
191 static char const s_szSigRt[] =
192 "SIGRT00\0" "SIGRT01\0" "SIGRT02\0" "SIGRT03\0" "SIGRT04\0" "SIGRT05\0" "SIGRT06\0" "SIGRT07\0" "SIGRT08\0" "SIGRT09\0"
193 "SIGRT10\0" "SIGRT11\0" "SIGRT12\0" "SIGRT13\0" "SIGRT14\0" "SIGRT15\0" "SIGRT16\0" "SIGRT17\0" "SIGRT18\0" "SIGRT19\0"
194 "SIGRT20\0" "SIGRT21\0" "SIGRT22\0" "SIGRT23\0" "SIGRT24\0" "SIGRT25\0" "SIGRT26\0" "SIGRT27\0" "SIGRT28\0" "SIGRT29\0"
195 "SIGRT30\0" "SIGRT31\0" "SIGRT32\0" "SIGRT33\0" "SIGRT34\0" "SIGRT35\0" "SIGRT36\0" "SIGRT37\0" "SIGRT38\0" "SIGRT39\0"
196 "SIGRT40\0" "SIGRT41\0" "SIGRT42\0" "SIGRT43\0" "SIGRT44\0" "SIGRT45\0" "SIGRT46\0" "SIGRT47\0" "SIGRT48\0" "SIGRT49\0"
197 "SIGRT50\0" "SIGRT51\0" "SIGRT52\0" "SIGRT53\0" "SIGRT54\0" "SIGRT55\0" "SIGRT56\0" "SIGRT57\0" "SIGRT58\0" "SIGRT59\0"
198 "SIGRT60\0" "SIGRT61\0" "SIGRT62\0" "SIGRT63\0" "SIGRT64\0";
199 int const iSigRtMin = SIGRTMIN;
200 if (iSignal >= iSigRtMin && iSignal <= SIGRTMAX)
201 {
202 unsigned uRtSig = (unsigned)(iSignal - iSigRtMin);
203 if (uRtSig < (sizeof(s_szSigRt) - 1) / sizeof("SIGRT00"))
204 return &s_szSigRt[uRtSig * sizeof("SIGRT00")];
205 }
206#endif /* SIGRTMIN */
207
208 /*
209 * Do fallback: SIG+nnnn.
210 */
211 static struct { char sz[16]; } s_aFallback[16];
212 static uint32_t volatile s_iFallback = 0;
213 uint32_t const iFallback = ASMAtomicIncU32(&s_iFallback) % RT_ELEMENTS(s_aFallback);
214 s_aFallback[iFallback].sz[0] = 'S';
215 s_aFallback[iFallback].sz[1] = 'I';
216 s_aFallback[iFallback].sz[2] = 'G';
217 RTStrFormatU32(&s_aFallback[iFallback].sz[3], sizeof(s_aFallback[iFallback].sz) - 3, iSignal,
218 10, 0, 0, RTSTR_F_PLUS | RTSTR_F_VALSIGNED);
219 return s_aFallback[iFallback].sz;
220}
221RT_EXPORT_SYMBOL(RTProcSignalName);
222
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