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