Skip to content

Commit 128a067

Browse files
committed
signal.c compiles (...?)
1 parent 930dcd2 commit 128a067

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

darwin-user/qemu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/* This is the size of the host kernel's sigset_t, needed where we make
2222
* direct system calls that take a sigset_t pointer and a size.
2323
*/
24-
#define SIGSET_T_SIZE (_NSIG / 8)
24+
#define SIGSET_T_SIZE (NSIG / 8)
2525

2626
/* This struct is used to hold certain information about the image.
2727
* Basically, it replicates in user space what would be certain

darwin-user/signal.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/ucontext.h>
2222
#include <sys/resource.h>
2323
#include <sys/syscall.h>
24+
#include <sys/signal.h>
2425

2526
#include "qemu.h"
2627
#include "qemu-common.h"
@@ -38,7 +39,7 @@ static struct target_sigaction sigact_table[TARGET_NSIG];
3839
static void host_signal_handler(int host_signum, siginfo_t *info,
3940
void *puc);
4041

41-
static uint8_t host_to_target_signal_table[_NSIG] = {
42+
static uint8_t host_to_target_signal_table[NSIG] = {
4243
[SIGHUP] = TARGET_SIGHUP,
4344
[SIGINT] = TARGET_SIGINT,
4445
[SIGQUIT] = TARGET_SIGQUIT,
@@ -71,18 +72,32 @@ static uint8_t host_to_target_signal_table[_NSIG] = {
7172
[SIGPROF] = TARGET_SIGPROF,
7273
[SIGWINCH] = TARGET_SIGWINCH,
7374
[SIGIO] = TARGET_SIGIO,
75+
#ifdef SIGPWR
7476
[SIGPWR] = TARGET_SIGPWR,
77+
#endif
7578
[SIGSYS] = TARGET_SIGSYS,
7679
/* next signals stay the same */
7780
/* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with
7881
host libpthread signals. This assumes no one actually uses SIGRTMAX :-/
7982
To fix this properly we need to do manual signal delivery multiplexed
8083
over a single host signal. */
84+
#if defined(__SIGRTMIN) && defined(__SIGRTMAX)
8185
[__SIGRTMIN] = __SIGRTMAX,
8286
[__SIGRTMAX] = __SIGRTMIN,
87+
#endif
8388
};
8489
static uint8_t target_to_host_signal_table[TARGET_NSIG];
8590

91+
/** `sigorset` is a Linux specific function in `signal.h` that provides the union (logical OR)
92+
* of two `sigset_t`s. Since macOS `sigset_t` is a u32, this is simple to shim.
93+
* http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/baselib-sigorset.html
94+
*/
95+
static int inline sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right) {
96+
*dest = *left | *right;
97+
98+
return 0;
99+
}
100+
86101
static inline int on_sig_stack(unsigned long sp)
87102
{
88103
return (sp - target_sigaltstack_used.ss_sp
@@ -97,7 +112,7 @@ static inline int sas_ss_flags(unsigned long sp)
97112

98113
int host_to_target_signal(int sig)
99114
{
100-
if (sig < 0 || sig >= _NSIG)
115+
if (sig < 0 || sig >= NSIG)
101116
return sig;
102117
return host_to_target_signal_table[sig];
103118
}
@@ -137,7 +152,7 @@ static void host_to_target_sigset_internal(target_sigset_t *d,
137152
{
138153
int i;
139154
target_sigemptyset(d);
140-
for (i = 1; i <= _NSIG; i++) {
155+
for (i = 1; i <= NSIG; i++) {
141156
if (sigismember(s, i)) {
142157
target_sigaddset(d, host_to_target_signal(i));
143158
}
@@ -319,8 +334,8 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
319334

320335
switch (si_code) {
321336
case SI_USER:
322-
case SI_TKILL:
323-
case SI_KERNEL:
337+
// case SI_TKILL:
338+
//case SI_KERNEL:
324339
/* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
325340
* These are the only unspoofable si_code values.
326341
*/
@@ -338,13 +353,13 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
338353
#endif
339354
tinfo->_sifields._sigchld._status
340355
= host_to_target_waitstatus(info->si_status);
341-
tinfo->_sifields._sigchld._utime = info->si_utime;
342-
tinfo->_sifields._sigchld._stime = info->si_stime;
356+
// tinfo->_sifields._sigchld._utime = info->si_utime;
357+
// tinfo->_sifields._sigchld._stime = info->si_stime;
343358
si_type = QEMU_SI_CHLD;
344359
break;
345360
case TARGET_SIGIO:
346361
tinfo->_sifields._sigpoll._band = info->si_band;
347-
tinfo->_sifields._sigpoll._fd = info->si_fd;
362+
//tinfo->_sifields._sigpoll._fd = info->si_fd;
348363
si_type = QEMU_SI_POLL;
349364
break;
350365
default:
@@ -495,11 +510,11 @@ void signal_init(CPUArchState *env)
495510
int host_sig;
496511

497512
/* generate signal conversion tables */
498-
for(i = 1; i < _NSIG; i++) {
513+
for(i = 1; i < NSIG; i++) {
499514
if (host_to_target_signal_table[i] == 0)
500515
host_to_target_signal_table[i] = i;
501516
}
502-
for(i = 1; i < _NSIG; i++) {
517+
for(i = 1; i < NSIG; i++) {
503518
j = host_to_target_signal_table[i];
504519
if (j < TARGET_NSIG)
505520
target_to_host_signal_table[j] = i;
@@ -579,6 +594,7 @@ static void QEMU_NORETURN dump_core_and_abort(CPUArchState *env, int target_sig)
579594
struct sigaction act;
580595

581596
host_sig = target_to_host_signal(target_sig);
597+
// TODO: why isn't this function defined anywhere? macro?
582598
trace_user_force_sig(env, target_sig, host_sig);
583599
gdb_signalled(env, target_sig);
584600

@@ -631,6 +647,7 @@ int queue_signal(CPUArchState *env, int sig, int si_type,
631647
CPUState *cpu = ENV_GET_CPU(env);
632648
TaskState *ts = cpu->opaque;
633649

650+
/* is this a real function? */
634651
trace_user_queue_signal(env, sig);
635652

636653
info->si_code = deposit32(info->si_code, 16, 16, si_type);

0 commit comments

Comments
 (0)