2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
14 #include "user_util.h"
15 #include "kern_util.h"
17 #include "signal_user.h"
18 #include "signal_kern.h"
19 #include "sysdep/sigcontext.h"
20 #include "sigcontext.h"
22 void set_sigstack(void *sig_stack
, int size
)
24 stack_t stack
= ((stack_t
) { .ss_flags
= 0,
25 .ss_sp
= (__ptr_t
) sig_stack
,
26 .ss_size
= size
- sizeof(void *) });
28 if(sigaltstack(&stack
, NULL
) != 0)
29 panic("enabling signal stack failed, errno = %d\n", errno
);
32 void set_handler(int sig
, void (*handler
)(int), int flags
, ...)
34 struct sigaction action
;
39 action
.sa_handler
= handler
;
40 sigemptyset(&action
.sa_mask
);
41 while((mask
= va_arg(ap
, int)) != -1){
42 sigaddset(&action
.sa_mask
, mask
);
45 action
.sa_flags
= flags
;
46 action
.sa_restorer
= NULL
;
47 if(sigaction(sig
, &action
, NULL
) < 0)
48 panic("sigaction failed");
51 int change_sig(int signal
, int on
)
56 sigaddset(&sigset
, signal
);
57 sigprocmask(on
? SIG_UNBLOCK
: SIG_BLOCK
, &sigset
, &old
);
58 return(!sigismember(&old
, signal
));
61 /* Both here and in set/get_signal we don't touch SIGPROF, because we must not
62 * disable profiling; it's safe because the profiling code does not interact
63 * with the kernel code at all.*/
65 static void change_signals(int type
)
70 sigaddset(&mask
, SIGVTALRM
);
71 sigaddset(&mask
, SIGALRM
);
72 sigaddset(&mask
, SIGIO
);
73 if(sigprocmask(type
, &mask
, NULL
) < 0)
74 panic("Failed to change signal mask - errno = %d", errno
);
77 void block_signals(void)
79 change_signals(SIG_BLOCK
);
82 void unblock_signals(void)
84 change_signals(SIG_UNBLOCK
);
87 /* These are the asynchronous signals. SIGVTALRM and SIGARLM are handled
88 * together under SIGVTALRM_BIT. SIGPROF is excluded because we want to
89 * be able to profile all of UML, not just the non-critical sections. If
90 * profiling is not thread-safe, then that is not my problem. We can disable
91 * profiling when SMP is enabled in that case.
94 #define SIGVTALRM_BIT 1
96 static int enable_mask(sigset_t
*mask
)
100 sigs
= sigismember(mask
, SIGIO
) ? 0 : 1 << SIGIO_BIT
;
101 sigs
|= sigismember(mask
, SIGVTALRM
) ? 0 : 1 << SIGVTALRM_BIT
;
102 sigs
|= sigismember(mask
, SIGALRM
) ? 0 : 1 << SIGVTALRM_BIT
;
106 int get_signals(void)
110 if(sigprocmask(SIG_SETMASK
, NULL
, &mask
) < 0)
111 panic("Failed to get signal mask");
112 return(enable_mask(&mask
));
115 int set_signals(int enable
)
121 if(enable
& (1 << SIGIO_BIT
))
122 sigaddset(&mask
, SIGIO
);
123 if(enable
& (1 << SIGVTALRM_BIT
)){
124 sigaddset(&mask
, SIGVTALRM
);
125 sigaddset(&mask
, SIGALRM
);
128 /* This is safe - sigprocmask is guaranteed to copy locally the
129 * value of new_set, do his work and then, at the end, write to
132 if(sigprocmask(SIG_UNBLOCK
, &mask
, &mask
) < 0)
133 panic("Failed to enable signals");
134 ret
= enable_mask(&mask
);
136 if((enable
& (1 << SIGIO_BIT
)) == 0)
137 sigaddset(&mask
, SIGIO
);
138 if((enable
& (1 << SIGVTALRM_BIT
)) == 0){
139 sigaddset(&mask
, SIGVTALRM
);
140 sigaddset(&mask
, SIGALRM
);
142 if(sigprocmask(SIG_BLOCK
, &mask
, NULL
) < 0)
143 panic("Failed to block signals");
149 * Overrides for Emacs so that we follow Linus's tabbing style.
150 * Emacs will notice this stuff at the end of the file and automatically
151 * adjust the settings for this buffer only. This must remain at the end
153 * ---------------------------------------------------------------------------
155 * c-file-style: "linux"