55b62e2b8f415663094b571065132f7c19b17773
2 * Copyright (C) 2004 PathScale, Inc
3 * Licensed under the GPL
14 #include "user_util.h"
16 #include "signal_kern.h"
17 #include "sysdep/sigcontext.h"
18 #include "sigcontext.h"
22 /* These are the asynchronous signals. SIGVTALRM and SIGARLM are handled
23 * together under SIGVTALRM_BIT. SIGPROF is excluded because we want to
24 * be able to profile all of UML, not just the non-critical sections. If
25 * profiling is not thread-safe, then that is not my problem. We can disable
26 * profiling when SMP is enabled in that case.
29 #define SIGIO_MASK (1 << SIGIO_BIT)
31 #define SIGVTALRM_BIT 1
32 #define SIGVTALRM_MASK (1 << SIGVTALRM_BIT)
35 #define SIGALRM_MASK (1 << SIGALRM_BIT)
37 static int signals_enabled
= 1;
38 static int pending
= 0;
40 void sig_handler(int sig
, struct sigcontext
*sc
)
44 enabled
= signals_enabled
;
45 if(!enabled
&& (sig
== SIGIO
)){
46 pending
|= SIGIO_MASK
;
52 CHOOSE_MODE_PROC(sig_handler_common_tt
, sig_handler_common_skas
,
58 extern int timer_irq_inited
;
60 static void real_alarm_handler(int sig
, struct sigcontext
*sc
)
62 if(!timer_irq_inited
){
70 CHOOSE_MODE_PROC(sig_handler_common_tt
, sig_handler_common_skas
,
78 void alarm_handler(int sig
, struct sigcontext
*sc
)
82 enabled
= signals_enabled
;
85 pending
|= SIGVTALRM_MASK
;
86 else pending
|= SIGALRM_MASK
;
93 real_alarm_handler(sig
, sc
);
97 void set_sigstack(void *sig_stack
, int size
)
99 stack_t stack
= ((stack_t
) { .ss_flags
= 0,
100 .ss_sp
= (__ptr_t
) sig_stack
,
101 .ss_size
= size
- sizeof(void *) });
103 if(sigaltstack(&stack
, NULL
) != 0)
104 panic("enabling signal stack failed, errno = %d\n", errno
);
107 void remove_sigstack(void)
109 stack_t stack
= ((stack_t
) { .ss_flags
= SS_DISABLE
,
113 if(sigaltstack(&stack
, NULL
) != 0)
114 panic("disabling signal stack failed, errno = %d\n", errno
);
117 void (*handlers
[_NSIG
])(int sig
, struct sigcontext
*sc
);
119 extern void hard_handler(int sig
);
121 void set_handler(int sig
, void (*handler
)(int), int flags
, ...)
123 struct sigaction action
;
128 handlers
[sig
] = (void (*)(int, struct sigcontext
*)) handler
;
129 action
.sa_handler
= hard_handler
;
131 sigemptyset(&action
.sa_mask
);
134 while((mask
= va_arg(ap
, int)) != -1)
135 sigaddset(&action
.sa_mask
, mask
);
138 action
.sa_flags
= flags
;
139 action
.sa_restorer
= NULL
;
140 if(sigaction(sig
, &action
, NULL
) < 0)
141 panic("sigaction failed - errno = %d\n", errno
);
143 sigemptyset(&sig_mask
);
144 sigaddset(&sig_mask
, sig
);
145 if(sigprocmask(SIG_UNBLOCK
, &sig_mask
, NULL
) < 0)
146 panic("sigprocmask failed - errno = %d\n", errno
);
149 int change_sig(int signal
, int on
)
151 sigset_t sigset
, old
;
153 sigemptyset(&sigset
);
154 sigaddset(&sigset
, signal
);
155 sigprocmask(on
? SIG_UNBLOCK
: SIG_BLOCK
, &sigset
, &old
);
156 return(!sigismember(&old
, signal
));
159 void block_signals(void)
164 void unblock_signals(void)
168 if(signals_enabled
== 1)
171 /* We loop because the IRQ handler returns with interrupts off. So,
172 * interrupts may have arrived and we need to re-enable them and
176 /* Save and reset save_pending after enabling signals. This
177 * way, pending won't be changed while we're reading it.
181 save_pending
= pending
;
182 if(save_pending
== 0)
187 /* We have pending interrupts, so disable signals, as the
188 * handlers expect them off when they are called. They will
189 * be enabled again above.
194 /* Deal with SIGIO first because the alarm handler might
195 * schedule, leaving the pending SIGIO stranded until we come
198 if(save_pending
& SIGIO_MASK
)
199 CHOOSE_MODE_PROC(sig_handler_common_tt
,
200 sig_handler_common_skas
, SIGIO
, NULL
);
202 if(save_pending
& SIGALRM_MASK
)
203 real_alarm_handler(SIGALRM
, NULL
);
205 if(save_pending
& SIGVTALRM_MASK
)
206 real_alarm_handler(SIGVTALRM
, NULL
);
210 int get_signals(void)
212 return signals_enabled
;
215 int set_signals(int enable
)
218 if(signals_enabled
== enable
)
221 ret
= signals_enabled
;
224 else block_signals();
229 void os_usr1_signal(int on
)
231 change_sig(SIGUSR1
, on
);
This page took 0.036937 seconds and 4 git commands to generate.