2 * Emulation of Linux signal handling
4 * Copyright (c) 2003 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sys/ucontext.h>
26 /* Algorithm strongly inspired from em86 : we queue the signals so
27 that we can handle them at precise points in the emulated code. */
29 struct emulated_sigaction {
30 struct target_sigaction sa;
32 struct target_siginfo info;
35 struct emulated_sigaction sigact_table[NSIG];
38 static inline int host_to_target_signal(int sig)
43 static inline int target_to_host_signal(int sig)
48 void signal_init(void)
53 /* set all host signal handlers */
54 sigemptyset(&act.sa_mask);
55 act.sa_flags = SA_SIGINFO;
56 act.sa_sigaction = host_signal_handler;
57 for(i = 1; i < NSIG; i++) {
58 sigaction(i, &sa, NULL);
61 memset(sigact_table, 0, sizeof(sigact_table));
64 static void host_signal_handler(int host_signum, siginfo_t *info,
67 struct ucontext *uc = puc;
69 /* get target signal number */
70 signum = host_to_target(host_signum);
71 if (signum >= TARGET_NSIG)
73 /* we save the old mask */
79 void process_pending_signals(void)
82 target_ulong _sa_handler;
84 struct emulated_sigaction *esig;
90 for(signum = 1; signum < TARGET_NSIG; signum++) {
91 if (esig->nb_pending != 0)
95 /* if no signal is pending, just return */
99 _sa_handler = esig->sa._sa_handler;
100 if (_sa_handler == TARGET_SIG_DFL) {