blob: 2e0d5995531492fe51d66095723aa3e0fec26d84 [file] [log] [blame]
bellard31e31b82003-02-18 22:55:36 +00001/*
2 * Emulation of Linux signal handling
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
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.
10 *
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.
15 *
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.
19 */
20#include <stdlib.h>
21#include <stdio.h>
22#include <stdarg.h>
23#include <signal.h>
24#include <sys/ucontext.h>
25
26/* Algorithm strongly inspired from em86 : we queue the signals so
27 that we can handle them at precise points in the emulated code. */
28
29struct emulated_sigaction {
30 struct target_sigaction sa;
31 int nb_pending;
32 struct target_siginfo info;
33};
34
35struct emulated_sigaction sigact_table[NSIG];
36int signal_pending;
37
38static inline int host_to_target_signal(int sig)
39{
40 return sig;
41}
42
43static inline int target_to_host_signal(int sig)
44{
45 return sig;
46}
47
48void signal_init(void)
49{
50 struct sigaction act;
51 int i;
52
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);
59 }
60
61 memset(sigact_table, 0, sizeof(sigact_table));
62}
63
64static void host_signal_handler(int host_signum, siginfo_t *info,
65 void *puc)
66{
67 struct ucontext *uc = puc;
68 int signum;
69 /* get target signal number */
70 signum = host_to_target(host_signum);
71 if (signum >= TARGET_NSIG)
72 return;
73 /* we save the old mask */
74
75
76}
77
78
79void process_pending_signals(void)
80{
81 int signum;
82 target_ulong _sa_handler;
83
84 struct emulated_sigaction *esig;
85
86 if (!signal_pending)
87 return;
88
89 esig = sigact_table;
90 for(signum = 1; signum < TARGET_NSIG; signum++) {
91 if (esig->nb_pending != 0)
92 goto handle_signal;
93 esig++;
94 }
95 /* if no signal is pending, just return */
96 signal_pending = 0;
97 return;
98 handle_signal:
99 _sa_handler = esig->sa._sa_handler;
100 if (_sa_handler == TARGET_SIG_DFL) {
101 /* default handling
102 }
103
104
105}