Statistics
| Branch: | Revision:

root / linux-user / signal.c @ 31e31b8a

History | View | Annotate | Download (2.5 kB)

1
/*
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

    
29
struct emulated_sigaction {
30
    struct target_sigaction sa;
31
    int nb_pending;
32
    struct target_siginfo info;
33
};
34

    
35
struct emulated_sigaction sigact_table[NSIG];
36
int signal_pending;
37

    
38
static inline int host_to_target_signal(int sig)
39
{
40
    return sig;
41
}
42

    
43
static inline int target_to_host_signal(int sig)
44
{
45
    return sig;
46
}
47

    
48
void 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

    
64
static 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

    
79
void 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
}
106