Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004 PathScale, Inc |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 3 | * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Licensed under the GPL |
| 5 | */ |
| 6 | |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 7 | #include <stdlib.h> |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 8 | #include <stdarg.h> |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <signal.h> |
| 11 | #include <strings.h> |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 12 | #include "as-layout.h" |
Jeff Dike | edea138 | 2008-02-04 22:30:46 -0800 | [diff] [blame] | 13 | #include "kern_util.h" |
Gennady Sharapov | cff65c4 | 2006-01-18 17:42:42 -0800 | [diff] [blame] | 14 | #include "os.h" |
Jeff Dike | fe2cc53 | 2008-05-12 14:02:00 -0700 | [diff] [blame^] | 15 | #include "process.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 16 | #include "sysdep/barrier.h" |
| 17 | #include "sysdep/sigcontext.h" |
| 18 | #include "user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 20 | /* Copied from linux/compiler-gcc.h since we can't include it directly */ |
| 21 | #define barrier() __asm__ __volatile__("": : :"memory") |
| 22 | |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 23 | void (*sig_info[NSIG])(int, struct uml_pt_regs *) = { |
| 24 | [SIGTRAP] = relay_signal, |
| 25 | [SIGFPE] = relay_signal, |
| 26 | [SIGILL] = relay_signal, |
| 27 | [SIGWINCH] = winch, |
| 28 | [SIGBUS] = bus_handler, |
| 29 | [SIGSEGV] = segv_handler, |
| 30 | [SIGIO] = sigio_handler, |
| 31 | [SIGVTALRM] = timer_handler }; |
| 32 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 33 | static void sig_handler_common(int sig, struct sigcontext *sc) |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 34 | { |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 35 | struct uml_pt_regs r; |
| 36 | int save_errno = errno; |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 37 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 38 | r.is_user = 0; |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 39 | if (sig == SIGSEGV) { |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 40 | /* For segfaults, we want the data from the sigcontext. */ |
| 41 | copy_sc(&r, sc); |
| 42 | GET_FAULTINFO_FROM_SC(r.faultinfo, sc); |
| 43 | } |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 44 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 45 | /* enable signals if sig isn't IRQ signal */ |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 46 | if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM)) |
| 47 | unblock_signals(); |
| 48 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 49 | (*sig_info[sig])(sig, &r); |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 50 | |
| 51 | errno = save_errno; |
Jeff Dike | 75ada8f | 2008-02-04 22:31:12 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 54 | /* |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 55 | * These are the asynchronous signals. SIGPROF is excluded because we want to |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 56 | * be able to profile all of UML, not just the non-critical sections. If |
| 57 | * profiling is not thread-safe, then that is not my problem. We can disable |
| 58 | * profiling when SMP is enabled in that case. |
| 59 | */ |
| 60 | #define SIGIO_BIT 0 |
| 61 | #define SIGIO_MASK (1 << SIGIO_BIT) |
| 62 | |
| 63 | #define SIGVTALRM_BIT 1 |
| 64 | #define SIGVTALRM_MASK (1 << SIGVTALRM_BIT) |
| 65 | |
Jeff Dike | fce8c41 | 2008-02-04 22:31:09 -0800 | [diff] [blame] | 66 | static int signals_enabled; |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 67 | static unsigned int signals_pending; |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 68 | |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 69 | void sig_handler(int sig, struct sigcontext *sc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 71 | int enabled; |
| 72 | |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 73 | enabled = signals_enabled; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 74 | if (!enabled && (sig == SIGIO)) { |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 75 | signals_pending |= SIGIO_MASK; |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 76 | return; |
| 77 | } |
| 78 | |
| 79 | block_signals(); |
| 80 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 81 | sig_handler_common(sig, sc); |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 82 | |
| 83 | set_signals(enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 86 | static void real_alarm_handler(struct sigcontext *sc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 88 | struct uml_pt_regs regs; |
Jeff Dike | 2ea5bc5 | 2007-05-10 22:22:32 -0700 | [diff] [blame] | 89 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 90 | if (sc != NULL) |
Jeff Dike | 2ea5bc5 | 2007-05-10 22:22:32 -0700 | [diff] [blame] | 91 | copy_sc(®s, sc); |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 92 | regs.is_user = 0; |
Jeff Dike | 2ea5bc5 | 2007-05-10 22:22:32 -0700 | [diff] [blame] | 93 | unblock_signals(); |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 94 | timer_handler(SIGVTALRM, ®s); |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 97 | void alarm_handler(int sig, struct sigcontext *sc) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 98 | { |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 99 | int enabled; |
| 100 | |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 101 | enabled = signals_enabled; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 102 | if (!signals_enabled) { |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 103 | signals_pending |= SIGVTALRM_MASK; |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 104 | return; |
| 105 | } |
| 106 | |
| 107 | block_signals(); |
| 108 | |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 109 | real_alarm_handler(sc); |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 110 | set_signals(enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Jeff Dike | 78a26e2 | 2007-10-16 01:27:23 -0700 | [diff] [blame] | 113 | void timer_init(void) |
| 114 | { |
| 115 | set_handler(SIGVTALRM, (__sighandler_t) alarm_handler, |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 116 | SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, -1); |
Jeff Dike | 78a26e2 | 2007-10-16 01:27:23 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 119 | void set_sigstack(void *sig_stack, int size) |
| 120 | { |
| 121 | stack_t stack = ((stack_t) { .ss_flags = 0, |
| 122 | .ss_sp = (__ptr_t) sig_stack, |
| 123 | .ss_size = size - sizeof(void *) }); |
| 124 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 125 | if (sigaltstack(&stack, NULL) != 0) |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 126 | panic("enabling signal stack failed, errno = %d\n", errno); |
| 127 | } |
| 128 | |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 129 | void (*handlers[_NSIG])(int sig, struct sigcontext *sc); |
| 130 | |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 131 | void handle_signal(int sig, struct sigcontext *sc) |
| 132 | { |
Jeff Dike | 508a927 | 2007-09-18 22:46:49 -0700 | [diff] [blame] | 133 | unsigned long pending = 1UL << sig; |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 134 | |
| 135 | do { |
| 136 | int nested, bail; |
| 137 | |
| 138 | /* |
| 139 | * pending comes back with one bit set for each |
| 140 | * interrupt that arrived while setting up the stack, |
| 141 | * plus a bit for this interrupt, plus the zero bit is |
| 142 | * set if this is a nested interrupt. |
| 143 | * If bail is true, then we interrupted another |
| 144 | * handler setting up the stack. In this case, we |
| 145 | * have to return, and the upper handler will deal |
| 146 | * with this interrupt. |
| 147 | */ |
Jeff Dike | 508a927 | 2007-09-18 22:46:49 -0700 | [diff] [blame] | 148 | bail = to_irq_stack(&pending); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 149 | if (bail) |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 150 | return; |
| 151 | |
| 152 | nested = pending & 1; |
| 153 | pending &= ~1; |
| 154 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 155 | while ((sig = ffs(pending)) != 0){ |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 156 | sig--; |
| 157 | pending &= ~(1 << sig); |
| 158 | (*handlers[sig])(sig, sc); |
| 159 | } |
| 160 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 161 | /* |
| 162 | * Again, pending comes back with a mask of signals |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 163 | * that arrived while tearing down the stack. If this |
| 164 | * is non-zero, we just go back, set up the stack |
| 165 | * again, and handle the new interrupts. |
| 166 | */ |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 167 | if (!nested) |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 168 | pending = from_irq_stack(nested); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 169 | } while (pending); |
Jeff Dike | c14b849 | 2007-05-10 22:22:34 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 172 | extern void hard_handler(int sig); |
| 173 | |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 174 | void set_handler(int sig, void (*handler)(int), int flags, ...) |
| 175 | { |
| 176 | struct sigaction action; |
| 177 | va_list ap; |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 178 | sigset_t sig_mask; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 179 | int mask; |
| 180 | |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 181 | handlers[sig] = (void (*)(int, struct sigcontext *)) handler; |
| 182 | action.sa_handler = hard_handler; |
| 183 | |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 184 | sigemptyset(&action.sa_mask); |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 185 | |
| 186 | va_start(ap, flags); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 187 | while ((mask = va_arg(ap, int)) != -1) |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 188 | sigaddset(&action.sa_mask, mask); |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 189 | va_end(ap); |
Jeff Dike | 4b84c69 | 2006-09-25 23:33:04 -0700 | [diff] [blame] | 190 | |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 191 | if (sig == SIGSEGV) |
| 192 | flags |= SA_NODEFER; |
| 193 | |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 194 | action.sa_flags = flags; |
| 195 | action.sa_restorer = NULL; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 196 | if (sigaction(sig, &action, NULL) < 0) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 197 | panic("sigaction failed - errno = %d\n", errno); |
| 198 | |
| 199 | sigemptyset(&sig_mask); |
| 200 | sigaddset(&sig_mask, sig); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 201 | if (sigprocmask(SIG_UNBLOCK, &sig_mask, NULL) < 0) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 202 | panic("sigprocmask failed - errno = %d\n", errno); |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | int change_sig(int signal, int on) |
| 206 | { |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 207 | sigset_t sigset; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 208 | |
| 209 | sigemptyset(&sigset); |
| 210 | sigaddset(&sigset, signal); |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 211 | if (sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, NULL) < 0) |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 212 | return -errno; |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 213 | |
| 214 | return 0; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 217 | void block_signals(void) |
| 218 | { |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 219 | signals_enabled = 0; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 220 | /* |
| 221 | * This must return with signals disabled, so this barrier |
Jeff Dike | 53b1733 | 2006-11-02 22:07:22 -0800 | [diff] [blame] | 222 | * ensures that writes are flushed out before the return. |
| 223 | * This might matter if gcc figures out how to inline this and |
| 224 | * decides to shuffle this code into the caller. |
| 225 | */ |
Jeff Dike | fce8c41 | 2008-02-04 22:31:09 -0800 | [diff] [blame] | 226 | barrier(); |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void unblock_signals(void) |
| 230 | { |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 231 | int save_pending; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 232 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 233 | if (signals_enabled == 1) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 234 | return; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 235 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 236 | /* |
| 237 | * We loop because the IRQ handler returns with interrupts off. So, |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 238 | * interrupts may have arrived and we need to re-enable them and |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 239 | * recheck signals_pending. |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 240 | */ |
Jeff Dike | 5134d8f | 2008-02-08 04:22:08 -0800 | [diff] [blame] | 241 | while (1) { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 242 | /* |
| 243 | * Save and reset save_pending after enabling signals. This |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 244 | * way, signals_pending won't be changed while we're reading it. |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 245 | */ |
| 246 | signals_enabled = 1; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 247 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 248 | /* |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 249 | * Setting signals_enabled and reading signals_pending must |
Jeff Dike | 53b1733 | 2006-11-02 22:07:22 -0800 | [diff] [blame] | 250 | * happen in this order. |
| 251 | */ |
Jeff Dike | fce8c41 | 2008-02-04 22:31:09 -0800 | [diff] [blame] | 252 | barrier(); |
Jeff Dike | 53b1733 | 2006-11-02 22:07:22 -0800 | [diff] [blame] | 253 | |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 254 | save_pending = signals_pending; |
Jeff Dike | fce8c41 | 2008-02-04 22:31:09 -0800 | [diff] [blame] | 255 | if (save_pending == 0) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 256 | return; |
| 257 | |
Jeff Dike | cfef8f3 | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 258 | signals_pending = 0; |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 259 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 260 | /* |
| 261 | * We have pending interrupts, so disable signals, as the |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 262 | * handlers expect them off when they are called. They will |
| 263 | * be enabled again above. |
| 264 | */ |
| 265 | |
| 266 | signals_enabled = 0; |
| 267 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 268 | /* |
| 269 | * Deal with SIGIO first because the alarm handler might |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 270 | * schedule, leaving the pending SIGIO stranded until we come |
| 271 | * back here. |
| 272 | */ |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 273 | if (save_pending & SIGIO_MASK) |
Jeff Dike | e6a2d1f | 2008-02-04 22:31:13 -0800 | [diff] [blame] | 274 | sig_handler_common(SIGIO, NULL); |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 275 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 276 | if (save_pending & SIGVTALRM_MASK) |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 277 | real_alarm_handler(NULL); |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 278 | } |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | int get_signals(void) |
| 282 | { |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 283 | return signals_enabled; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | int set_signals(int enable) |
| 287 | { |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 288 | int ret; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 289 | if (signals_enabled == enable) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 290 | return enable; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 291 | |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 292 | ret = signals_enabled; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 293 | if (enable) |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 294 | unblock_signals(); |
| 295 | else block_signals(); |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 296 | |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 297 | return ret; |
Gennady Sharapov | 0805d89 | 2006-01-08 01:01:29 -0800 | [diff] [blame] | 298 | } |