xref: /openbmc/qemu/linux-user/signal-common.h (revision 5242ef88)
1 /*
2  *  Emulation of Linux signals
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, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef SIGNAL_COMMON_H
21 #define SIGNAL_COMMON_H
22 
23 #include "special-errno.h"
24 
25 /* Fallback addresses into sigtramp page. */
26 extern abi_ulong default_sigreturn;
27 extern abi_ulong default_rt_sigreturn;
28 
29 void setup_sigtramp(abi_ulong tramp_page);
30 
31 int on_sig_stack(unsigned long sp);
32 int sas_ss_flags(unsigned long sp);
33 abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka);
34 void target_save_altstack(target_stack_t *uss, CPUArchState *env);
35 abi_long target_restore_altstack(target_stack_t *uss, CPUArchState *env);
36 
37 static inline void target_sigemptyset(target_sigset_t *set)
38 {
39     memset(set, 0, sizeof(*set));
40 }
41 
42 void host_to_target_sigset_internal(target_sigset_t *d,
43                                     const sigset_t *s);
44 void target_to_host_sigset_internal(sigset_t *d,
45                                     const target_sigset_t *s);
46 void tswap_siginfo(target_siginfo_t *tinfo,
47                    const target_siginfo_t *info);
48 void set_sigmask(const sigset_t *set);
49 void force_sig(int sig);
50 void force_sigsegv(int oldsig);
51 void force_sig_fault(int sig, int code, abi_ulong addr);
52 #if defined(TARGET_ARCH_HAS_SETUP_FRAME)
53 void setup_frame(int sig, struct target_sigaction *ka,
54                  target_sigset_t *set, CPUArchState *env);
55 #endif
56 void setup_rt_frame(int sig, struct target_sigaction *ka,
57                     target_siginfo_t *info,
58                     target_sigset_t *set, CPUArchState *env);
59 
60 void process_pending_signals(CPUArchState *cpu_env);
61 void signal_init(void);
62 void queue_signal(CPUArchState *env, int sig, int si_type,
63                   target_siginfo_t *info);
64 void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
65 void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
66 int target_to_host_signal(int sig);
67 int host_to_target_signal(int sig);
68 long do_sigreturn(CPUArchState *env);
69 long do_rt_sigreturn(CPUArchState *env);
70 abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr,
71                         CPUArchState *env);
72 int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
73 abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx,
74                         abi_ulong unew_ctx, abi_long ctx_size);
75 /**
76  * block_signals: block all signals while handling this guest syscall
77  *
78  * Block all signals, and arrange that the signal mask is returned to
79  * its correct value for the guest before we resume execution of guest code.
80  * If this function returns non-zero, then the caller should immediately
81  * return -QEMU_ERESTARTSYS to the main loop, which will take the pending
82  * signal and restart execution of the syscall.
83  * If block_signals() returns zero, then the caller can continue with
84  * emulation of the system call knowing that no signals can be taken
85  * (and therefore that no race conditions will result).
86  * This should only be called once, because if it is called a second time
87  * it will always return non-zero. (Think of it like a mutex that can't
88  * be recursively locked.)
89  * Signals will be unblocked again by process_pending_signals().
90  *
91  * Return value: non-zero if there was a pending signal, zero if not.
92  */
93 int block_signals(void); /* Returns non zero if signal pending */
94 
95 /**
96  * process_sigsuspend_mask: read and apply syscall-local signal mask
97  *
98  * Read the guest signal mask from @sigset, length @sigsize.
99  * Convert that to a host signal mask and save it to sigpending_mask.
100  *
101  * Return value: negative target errno, or zero;
102  *               store &sigpending_mask into *pset on success.
103  */
104 int process_sigsuspend_mask(sigset_t **pset, target_ulong sigset,
105                             target_ulong sigsize);
106 
107 /**
108  * finish_sigsuspend_mask: finish a sigsuspend-like syscall
109  *
110  * Set in_sigsuspend if we need to use the modified sigset
111  * during process_pending_signals.
112  */
113 static inline void finish_sigsuspend_mask(int ret)
114 {
115     if (ret != -QEMU_ERESTARTSYS) {
116         TaskState *ts = (TaskState *)thread_cpu->opaque;
117         ts->in_sigsuspend = 1;
118     }
119 }
120 
121 #endif
122