1 /* $Id: signal.c,v 1.7 2000/09/05 21:44:54 davem Exp $
2 * signal.c: Signal emulation for Solaris
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 #include <linux/types.h>
8 #include <linux/smp_lock.h>
9 #include <linux/errno.h>
11 #include <asm/uaccess.h>
13 #include <asm/string.h>
18 #define _S(nr) (1L<<((nr)-1))
20 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
22 long linux_to_solaris_signals[] = {
24 SOLARIS_SIGHUP, SOLARIS_SIGINT,
25 SOLARIS_SIGQUIT, SOLARIS_SIGILL,
26 SOLARIS_SIGTRAP, SOLARIS_SIGIOT,
27 SOLARIS_SIGEMT, SOLARIS_SIGFPE,
28 SOLARIS_SIGKILL, SOLARIS_SIGBUS,
29 SOLARIS_SIGSEGV, SOLARIS_SIGSYS,
30 SOLARIS_SIGPIPE, SOLARIS_SIGALRM,
31 SOLARIS_SIGTERM, SOLARIS_SIGURG,
32 SOLARIS_SIGSTOP, SOLARIS_SIGTSTP,
33 SOLARIS_SIGCONT, SOLARIS_SIGCLD,
34 SOLARIS_SIGTTIN, SOLARIS_SIGTTOU,
35 SOLARIS_SIGPOLL, SOLARIS_SIGXCPU,
36 SOLARIS_SIGXFSZ, SOLARIS_SIGVTALRM,
37 SOLARIS_SIGPROF, SOLARIS_SIGWINCH,
38 SOLARIS_SIGUSR1, SOLARIS_SIGUSR1,
42 long solaris_to_linux_signals[] = {
44 SIGHUP, SIGINT, SIGQUIT, SIGILL,
45 SIGTRAP, SIGIOT, SIGEMT, SIGFPE,
46 SIGKILL, SIGBUS, SIGSEGV, SIGSYS,
47 SIGPIPE, SIGALRM, SIGTERM, SIGUSR1,
48 SIGUSR2, SIGCHLD, -1, SIGWINCH,
49 SIGURG, SIGPOLL, SIGSTOP, SIGTSTP,
50 SIGCONT, SIGTTIN, SIGTTOU, SIGVTALRM,
51 SIGPROF, SIGXCPU, SIGXFSZ, -1,
57 static inline long mapsig(long sig)
59 if ((unsigned long)sig > SOLARIS_NSIGNALS)
61 return solaris_to_linux_signals[sig];
64 asmlinkage int solaris_kill(int pid, int sig)
66 int (*sys_kill)(int,int) =
67 (int (*)(int,int))SYS(kill);
71 return sys_kill(pid, s);
74 static long sig_handler(int sig, u32 arg, int one_shot)
76 struct sigaction sa, old;
78 mm_segment_t old_fs = get_fs();
79 int (*sys_sigaction)(int,struct sigaction *,struct sigaction *) =
80 (int (*)(int,struct sigaction *,struct sigaction *))SYS(sigaction);
82 sigemptyset(&sa.sa_mask);
83 sa.sa_restorer = NULL;
84 sa.sa_handler = (__sighandler_t)A(arg);
86 if (one_shot) sa.sa_flags = SA_ONESHOT | SA_NOMASK;
88 ret = sys_sigaction(sig, &sa, &old);
90 if (ret < 0) return ret;
91 return (u32)(long)old.sa_handler;
94 static inline long solaris_signal(int sig, u32 arg)
96 return sig_handler (sig, arg, 1);
99 static long solaris_sigset(int sig, u32 arg)
101 if (arg != 2) /* HOLD */ {
102 spin_lock_irq(¤t->sighand->siglock);
103 sigdelsetmask(¤t->blocked, _S(sig));
105 spin_unlock_irq(¤t->sighand->siglock);
106 return sig_handler (sig, arg, 0);
108 spin_lock_irq(¤t->sighand->siglock);
109 sigaddsetmask(¤t->blocked, (_S(sig) & ~_BLOCKABLE));
111 spin_unlock_irq(¤t->sighand->siglock);
116 static inline long solaris_sighold(int sig)
118 return solaris_sigset(sig, 2);
121 static inline long solaris_sigrelse(int sig)
123 spin_lock_irq(¤t->sighand->siglock);
124 sigdelsetmask(¤t->blocked, _S(sig));
126 spin_unlock_irq(¤t->sighand->siglock);
130 static inline long solaris_sigignore(int sig)
132 return sig_handler (sig, (u32)SIG_IGN, 0);
135 static inline long solaris_sigpause(int sig)
137 printk ("Need to support solaris sigpause\n");
141 asmlinkage long solaris_sigfunc(int sig, u32 arg)
143 int func = sig & ~0xff;
145 sig = mapsig(sig & 0xff);
146 if (sig < 0) return sig;
148 case 0: return solaris_signal(sig, arg);
149 case 0x100: return solaris_sigset(sig, arg);
150 case 0x200: return solaris_sighold(sig);
151 case 0x400: return solaris_sigrelse(sig);
152 case 0x800: return solaris_sigignore(sig);
153 case 0x1000: return solaris_sigpause(sig);
162 static inline int mapin(u32 *p, sigset_t *q)
170 for (i = 1; i <= SOLARIS_NSIGNALS; i++) {
172 sig = solaris_to_linux_signals[i];
175 sigaddsetmask(q, (1L << (sig - 1)));
184 static inline int mapout(sigset_t *q, u32 *p)
191 for (i = 1; i <= 32; i++) {
192 if (sigismember(q, sigmask(i))) {
193 sig = linux_to_solaris_signals[i];
197 p[1] |= 1L << (sig - 33);
199 p[0] |= 1L << (sig - 1);
205 asmlinkage int solaris_sigprocmask(int how, u32 in, u32 out)
207 sigset_t in_s, *ins, out_s, *outs;
208 mm_segment_t old_fs = get_fs();
210 int (*sys_sigprocmask)(int,sigset_t *,sigset_t *) =
211 (int (*)(int,sigset_t *,sigset_t *))SYS(sigprocmask);
213 ins = NULL; outs = NULL;
217 if (copy_from_user (tmp, (sol_sigset_t *)A(in), 2*sizeof(u32)))
220 if (mapin (tmp, ins)) return -EINVAL;
222 if (out) outs = &out_s;
224 ret = sys_sigprocmask((how == 3) ? SIG_SETMASK : how, ins, outs);
230 tmp[2] = 0; tmp[3] = 0;
231 if (mapout (outs, tmp)) return -EINVAL;
232 if (copy_to_user((sol_sigset_t *)A(out), tmp, 4*sizeof(u32)))
238 asmlinkage long do_sol_sigsuspend(u32 mask)
243 if (copy_from_user (tmp, (sol_sigset_t *)A(mask), 2*sizeof(u32)))
245 if (mapin (tmp, &s)) return -EINVAL;
246 return (long)s.sig[0];
249 struct sol_sigaction {
256 asmlinkage int solaris_sigaction(int sig, u32 act, u32 old)
259 struct sigaction s, s2;
261 mm_segment_t old_fs = get_fs();
262 int (*sys_sigaction)(int,struct sigaction *,struct sigaction *) =
263 (int (*)(int,struct sigaction *,struct sigaction *))SYS(sigaction);
267 /* We cheat a little bit for Solaris only signals */
268 if (old && clear_user((struct sol_sigaction *)A(old), sizeof(struct sol_sigaction)))
273 if (get_user (tmp, &((struct sol_sigaction *)A(act))->sa_flags))
276 if (tmp & SOLARIS_SA_ONSTACK) s.sa_flags |= SA_STACK;
277 if (tmp & SOLARIS_SA_RESTART) s.sa_flags |= SA_RESTART;
278 if (tmp & SOLARIS_SA_NODEFER) s.sa_flags |= SA_NOMASK;
279 if (tmp & SOLARIS_SA_RESETHAND) s.sa_flags |= SA_ONESHOT;
280 if (tmp & SOLARIS_SA_NOCLDSTOP) s.sa_flags |= SA_NOCLDSTOP;
281 if (get_user (tmp, &((struct sol_sigaction *)A(act))->sa_handler) ||
282 copy_from_user (tmp2, &((struct sol_sigaction *)A(act))->sa_mask, 2*sizeof(u32)))
284 s.sa_handler = (__sighandler_t)A(tmp);
285 if (mapin (tmp2, &s.sa_mask)) return -EINVAL;
289 ret = sys_sigaction(sig, act ? &s : NULL, old ? &s2 : NULL);
293 if (mapout (&s2.sa_mask, tmp2)) return -EINVAL;
294 tmp = 0; tmp2[2] = 0; tmp2[3] = 0;
295 if (s2.sa_flags & SA_STACK) tmp |= SOLARIS_SA_ONSTACK;
296 if (s2.sa_flags & SA_RESTART) tmp |= SOLARIS_SA_RESTART;
297 if (s2.sa_flags & SA_NOMASK) tmp |= SOLARIS_SA_NODEFER;
298 if (s2.sa_flags & SA_ONESHOT) tmp |= SOLARIS_SA_RESETHAND;
299 if (s2.sa_flags & SA_NOCLDSTOP) tmp |= SOLARIS_SA_NOCLDSTOP;
300 if (put_user (tmp, &((struct sol_sigaction *)A(old))->sa_flags) ||
301 __put_user ((u32)(long)s2.sa_handler, &((struct sol_sigaction *)A(old))->sa_handler) ||
302 copy_to_user (&((struct sol_sigaction *)A(old))->sa_mask, tmp2, 4*sizeof(u32)))
308 asmlinkage int solaris_sigpending(int which, u32 set)
313 case 1: /* sigpending */
314 spin_lock_irq(¤t->sighand->siglock);
315 sigandsets(&s, ¤t->blocked, ¤t->pending.signal);
317 spin_unlock_irq(¤t->sighand->siglock);
319 case 2: /* sigfillset - I just set signals which have linux equivalents */
322 default: return -EINVAL;
324 if (mapout (&s, tmp)) return -EINVAL;
325 tmp[2] = 0; tmp[3] = 0;
326 if (copy_to_user ((u32 *)A(set), tmp, sizeof(tmp)))
331 asmlinkage int solaris_wait(u32 stat_loc)
333 int (*sys_wait4)(pid_t,unsigned int *, int, struct rusage *) =
334 (int (*)(pid_t,unsigned int *, int, struct rusage *))SYS(wait4);
337 ret = sys_wait4(-1, (unsigned int *)A(stat_loc), WUNTRACED, NULL);
338 if (ret >= 0 && stat_loc) {
339 if (get_user (status, (unsigned int *)A(stat_loc)))
341 if (((status - 1) & 0xffff) < 0xff)
342 status = linux_to_solaris_signals[status & 0x7f] & 0x7f;
343 else if ((status & 0xff) == 0x7f)
344 status = (linux_to_solaris_signals[(status >> 8) & 0xff] << 8) | 0x7f;
345 if (__put_user (status, (unsigned int *)A(stat_loc)))
351 asmlinkage int solaris_waitid(int idtype, s32 pid, u32 info, int options)
353 int (*sys_wait4)(pid_t,unsigned int *, int, struct rusage *) =
354 (int (*)(pid_t,unsigned int *, int, struct rusage *))SYS(wait4);
355 int opts, status, ret;
358 case 0: /* P_PID */ break;
359 case 1: /* P_PGID */ pid = -pid; break;
360 case 7: /* P_ALL */ pid = -1; break;
361 default: return -EINVAL;
364 if (options & SOLARIS_WUNTRACED) opts |= WUNTRACED;
365 if (options & SOLARIS_WNOHANG) opts |= WNOHANG;
366 current->state = TASK_RUNNING;
367 ret = sys_wait4(pid, (unsigned int *)A(info), opts, NULL);
368 if (ret < 0) return ret;
370 struct sol_siginfo *s = (struct sol_siginfo *)A(info);
372 if (get_user (status, (unsigned int *)A(info)))
375 if (__put_user (SOLARIS_SIGCLD, &s->si_signo) ||
376 __put_user (ret, &s->_data._proc._pid))
379 switch (status & 0xff) {
380 case 0: ret = SOLARIS_CLD_EXITED;
381 status = (status >> 8) & 0xff;
384 status = (status >> 8) & 0xff;
387 case SIGTSTP: ret = SOLARIS_CLD_STOPPED;
388 default: ret = SOLARIS_CLD_EXITED;
390 status = linux_to_solaris_signals[status];
393 if (status & 0x80) ret = SOLARIS_CLD_DUMPED;
394 else ret = SOLARIS_CLD_KILLED;
395 status = linux_to_solaris_signals[status & 0x7f];
399 if (__put_user (ret, &s->si_code) ||
400 __put_user (status, &s->_data._proc._pdata._cld._status))
406 extern int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs);
407 extern int svr4_getcontext(svr4_ucontext_t *c, struct pt_regs *regs);
409 asmlinkage int solaris_context(struct pt_regs *regs)
411 switch ((unsigned)regs->u_regs[UREG_I0]) {
412 case 0: /* getcontext */
413 return svr4_getcontext((svr4_ucontext_t *)(long)(u32)regs->u_regs[UREG_I1], regs);
414 case 1: /* setcontext */
415 return svr4_setcontext((svr4_ucontext_t *)(long)(u32)regs->u_regs[UREG_I1], regs);
422 asmlinkage int solaris_sigaltstack(u32 ss, u32 oss)
424 /* XXX Implement this soon */