linux_signal.c revision 1.36 1 /* $NetBSD: linux_signal.c,v 1.36 2002/03/22 17:14:19 christos Exp $ */
2 /*-
3 * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Frank van der Linden and Eric Haszlakiewicz.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37 /*
38 * heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
39 */
40
41 /*
42 * Functions in multiarch:
43 * linux_sys_signal : linux_sig_notalpha.c
44 * linux_sys_siggetmask : linux_sig_notalpha.c
45 * linux_sys_sigsetmask : linux_sig_notalpha.c
46 * linux_sys_pause : linux_sig_notalpha.c
47 * linux_sys_sigaction : linux_sigaction.c
48 *
49 */
50
51 /*
52 * Unimplemented:
53 * linux_sys_rt_sigtimedwait : sigsuspend w/timeout.
54 */
55
56 #include <sys/cdefs.h>
57 __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.36 2002/03/22 17:14:19 christos Exp $");
58
59 #define COMPAT_LINUX 1
60
61 #include <sys/param.h>
62 #include <sys/systm.h>
63 #include <sys/namei.h>
64 #include <sys/proc.h>
65 #include <sys/filedesc.h>
66 #include <sys/ioctl.h>
67 #include <sys/mount.h>
68 #include <sys/kernel.h>
69 #include <sys/signal.h>
70 #include <sys/signalvar.h>
71 #include <sys/malloc.h>
72
73 #include <sys/syscallargs.h>
74
75 #include <compat/linux/common/linux_types.h>
76 #include <compat/linux/common/linux_signal.h>
77 #include <compat/linux/common/linux_siginfo.h>
78 #include <compat/linux/common/linux_util.h>
79
80 #include <compat/linux/linux_syscallargs.h>
81
82 /* Locally used defines (in bsd<->linux conversion functions): */
83 #define linux_sigemptyset(s) memset((s), 0, sizeof(*(s)))
84 #define linux_sigismember(s, n) ((s)->sig[((n) - 1) / LINUX__NSIG_BPW] \
85 & (1 << ((n) - 1) % LINUX__NSIG_BPW))
86 #define linux_sigaddset(s, n) ((s)->sig[((n) - 1) / LINUX__NSIG_BPW] \
87 |= (1 << ((n) - 1) % LINUX__NSIG_BPW))
88
89 #ifdef DEBUG_LINUX
90 #define DPRINTF(a) uprintf a
91 #else
92 #define DPRINTF(a)
93 #endif
94
95 #ifndef LINUX_SIGINFO
96 #define LINUX_SIGINFO 0
97 #endif
98 #ifndef LINUX_SIGEMT
99 #define LINUX_SIGEMT 0
100 #endif
101 /* Note: linux_to_native_sig[] is in <arch>/linux_sigarray.c */
102 const int native_to_linux_sig[] = {
103 0, /* 0 */
104 LINUX_SIGHUP, /* 1 */
105 LINUX_SIGINT, /* 2 */
106 LINUX_SIGQUIT, /* 3 */
107 LINUX_SIGILL, /* 4 */
108 LINUX_SIGTRAP, /* 5 */
109 LINUX_SIGABRT, /* 6 */
110 LINUX_SIGEMT, /* 7 */
111 LINUX_SIGFPE, /* 8 */
112 LINUX_SIGKILL, /* 9 */
113 LINUX_SIGBUS, /* 10 */
114 LINUX_SIGSEGV, /* 11 */
115 LINUX_SIGSYS, /* 12 */
116 LINUX_SIGPIPE, /* 13 */
117 LINUX_SIGALRM, /* 14 */
118 LINUX_SIGTERM, /* 15 */
119 LINUX_SIGURG, /* 16 */
120 LINUX_SIGSTOP, /* 17 */
121 LINUX_SIGTSTP, /* 18 */
122 LINUX_SIGCONT, /* 19 */
123 LINUX_SIGCHLD, /* 20 */
124 LINUX_SIGTTIN, /* 21 */
125 LINUX_SIGTTOU, /* 22 */
126 LINUX_SIGIO, /* 23 */
127 LINUX_SIGXCPU, /* 24 */
128 LINUX_SIGXFSZ, /* 25 */
129 LINUX_SIGVTALRM, /* 26 */
130 LINUX_SIGPROF, /* 27 */
131 LINUX_SIGWINCH, /* 28 */
132 LINUX_SIGINFO, /* 29 */
133 LINUX_SIGUSR1, /* 30 */
134 LINUX_SIGUSR2, /* 31 */
135 LINUX_SIGPWR, /* 32 */
136 LINUX_SIGRTMIN + 0, /* 33 */
137 LINUX_SIGRTMIN + 1, /* 34 */
138 LINUX_SIGRTMIN + 2, /* 35 */
139 LINUX_SIGRTMIN + 3, /* 36 */
140 LINUX_SIGRTMIN + 4, /* 37 */
141 LINUX_SIGRTMIN + 5, /* 38 */
142 LINUX_SIGRTMIN + 6, /* 39 */
143 LINUX_SIGRTMIN + 7, /* 40 */
144 LINUX_SIGRTMIN + 8, /* 41 */
145 LINUX_SIGRTMIN + 9, /* 42 */
146 LINUX_SIGRTMIN + 10, /* 43 */
147 LINUX_SIGRTMIN + 11, /* 44 */
148 LINUX_SIGRTMIN + 12, /* 45 */
149 LINUX_SIGRTMIN + 13, /* 46 */
150 LINUX_SIGRTMIN + 14, /* 47 */
151 LINUX_SIGRTMIN + 15, /* 48 */
152 LINUX_SIGRTMIN + 16, /* 49 */
153 LINUX_SIGRTMIN + 17, /* 50 */
154 LINUX_SIGRTMIN + 18, /* 51 */
155 LINUX_SIGRTMIN + 19, /* 52 */
156 LINUX_SIGRTMIN + 20, /* 53 */
157 LINUX_SIGRTMIN + 21, /* 54 */
158 LINUX_SIGRTMIN + 22, /* 55 */
159 LINUX_SIGRTMIN + 23, /* 56 */
160 LINUX_SIGRTMIN + 24, /* 57 */
161 LINUX_SIGRTMIN + 25, /* 58 */
162 LINUX_SIGRTMIN + 26, /* 59 */
163 LINUX_SIGRTMIN + 27, /* 60 */
164 LINUX_SIGRTMIN + 28, /* 61 */
165 LINUX_SIGRTMIN + 29, /* 62 */
166 LINUX_SIGRTMIN + 30, /* 63 */
167
168 };
169
170 /*
171 * Convert between Linux and BSD signal sets.
172 */
173 #if LINUX__NSIG_WORDS > 1
174 void
175 linux_old_extra_to_native_sigset(bss, lss, extra)
176 sigset_t *bss;
177 const linux_old_sigset_t *lss;
178 const unsigned long *extra;
179 {
180 linux_sigset_t lsnew;
181
182 /* convert old sigset to new sigset */
183 linux_sigemptyset(&lsnew);
184 lsnew.sig[0] = *lss;
185 if (extra)
186 memcpy(&lsnew.sig[1], extra,
187 sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
188
189 linux_to_native_sigset(bss, &lsnew);
190 }
191
192 void
193 native_to_linux_old_extra_sigset(lss, extra, bss)
194 linux_old_sigset_t *lss;
195 unsigned long *extra;
196 const sigset_t *bss;
197 {
198 linux_sigset_t lsnew;
199
200 native_to_linux_sigset(&lsnew, bss);
201
202 /* convert new sigset to old sigset */
203 *lss = lsnew.sig[0];
204 if (extra)
205 memcpy(extra, &lsnew.sig[1],
206 sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
207 }
208 #endif
209
210 void
211 linux_to_native_sigset(bss, lss)
212 sigset_t *bss;
213 const linux_sigset_t *lss;
214 {
215 int i, newsig;
216
217 sigemptyset(bss);
218 for (i = 1; i < LINUX__NSIG; i++) {
219 if (linux_sigismember(lss, i)) {
220 newsig = linux_to_native_sig[i];
221 if (newsig)
222 sigaddset(bss, newsig);
223 }
224 }
225 }
226
227 void
228 native_to_linux_sigset(lss, bss)
229 linux_sigset_t *lss;
230 const sigset_t *bss;
231 {
232 int i, newsig;
233
234 linux_sigemptyset(lss);
235 for (i = 1; i < NSIG; i++) {
236 if (sigismember(bss, i)) {
237 newsig = native_to_linux_sig[i];
238 if (newsig)
239 linux_sigaddset(lss, newsig);
240 }
241 }
242 }
243
244 unsigned int
245 native_to_linux_sigflags(bsf)
246 const int bsf;
247 {
248 unsigned int lsf = 0;
249 if ((bsf & SA_NOCLDSTOP) != 0)
250 lsf |= LINUX_SA_NOCLDSTOP;
251 if ((bsf & SA_NOCLDWAIT) != 0)
252 lsf |= LINUX_SA_NOCLDWAIT;
253 if ((bsf & SA_ONSTACK) != 0)
254 lsf |= LINUX_SA_ONSTACK;
255 if ((bsf & SA_RESTART) != 0)
256 lsf |= LINUX_SA_RESTART;
257 if ((bsf & SA_NODEFER) != 0)
258 lsf |= LINUX_SA_NOMASK;
259 if ((bsf & SA_RESETHAND) != 0)
260 lsf |= LINUX_SA_ONESHOT;
261 if ((bsf & SA_SIGINFO) != 0)
262 lsf |= LINUX_SA_SIGINFO;
263 return lsf;
264 }
265
266 int
267 linux_to_native_sigflags(lsf)
268 const unsigned long lsf;
269 {
270 int bsf = 0;
271 if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
272 bsf |= SA_NOCLDSTOP;
273 if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
274 bsf |= SA_NOCLDWAIT;
275 if ((lsf & LINUX_SA_ONSTACK) != 0)
276 bsf |= SA_ONSTACK;
277 if ((lsf & LINUX_SA_RESTART) != 0)
278 bsf |= SA_RESTART;
279 if ((lsf & LINUX_SA_ONESHOT) != 0)
280 bsf |= SA_RESETHAND;
281 if ((lsf & LINUX_SA_NOMASK) != 0)
282 bsf |= SA_NODEFER;
283 if ((lsf & LINUX_SA_SIGINFO) != 0)
284 bsf |= SA_SIGINFO;
285 if ((lsf & ~LINUX_SA_ALLBITS) != 0)
286 DPRINTF(("linux_old_to_native_sigflags: "
287 "%lx extra bits ignored\n", lsf));
288 return bsf;
289 }
290
291 /*
292 * Convert between Linux and BSD sigaction structures. Linux sometimes
293 * has one extra field (sa_restorer) which we don't support.
294 */
295 void
296 linux_old_to_native_sigaction(bsa, lsa)
297 struct sigaction *bsa;
298 const struct linux_old_sigaction *lsa;
299 {
300 bsa->sa_handler = lsa->sa_handler;
301 linux_old_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
302 bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
303 #ifndef __alpha__
304 /*
305 * XXX: On the alpha sa_restorer is elsewhere.
306 */
307 if (lsa->sa_restorer != NULL)
308 DPRINTF(("linux_old_to_native_sigaction: "
309 "sa_restorer ignored\n"));
310 #endif
311 }
312
313 void
314 native_to_linux_old_sigaction(lsa, bsa)
315 struct linux_old_sigaction *lsa;
316 const struct sigaction *bsa;
317 {
318 lsa->sa_handler = bsa->sa_handler;
319 native_to_linux_old_sigset(&lsa->sa_mask, &bsa->sa_mask);
320 lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
321 #ifndef __alpha__
322 lsa->sa_restorer = NULL;
323 #endif
324 }
325
326 /* ...and the new sigaction conversion funcs. */
327 void
328 linux_to_native_sigaction(bsa, lsa)
329 struct sigaction *bsa;
330 const struct linux_sigaction *lsa;
331 {
332 bsa->sa_handler = lsa->sa_handler;
333 linux_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
334 bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
335 #ifndef __alpha__
336 if (lsa->sa_restorer != 0)
337 DPRINTF(("linux_to_native_sigaction: sa_restorer ignored\n"));
338 #endif
339 }
340
341 void
342 native_to_linux_sigaction(lsa, bsa)
343 struct linux_sigaction *lsa;
344 const struct sigaction *bsa;
345 {
346 lsa->sa_handler = bsa->sa_handler;
347 native_to_linux_sigset(&lsa->sa_mask, &bsa->sa_mask);
348 lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
349 #ifndef __alpha__
350 lsa->sa_restorer = NULL;
351 #endif
352 }
353
354 /* ----------------------------------------------------------------------- */
355
356 /*
357 * The Linux sigaction() system call. Do the usual conversions,
358 * and just call sigaction(). Some flags and values are silently
359 * ignored (see above).
360 */
361 int
362 linux_sys_rt_sigaction(p, v, retval)
363 struct proc *p;
364 void *v;
365 register_t *retval;
366 {
367 struct linux_sys_rt_sigaction_args /* {
368 syscallarg(int) signum;
369 syscallarg(const struct linux_sigaction *) nsa;
370 syscallarg(struct linux_sigaction *) osa;
371 syscallarg(size_t) sigsetsize;
372 } */ *uap = v;
373 struct linux_sigaction nlsa, olsa;
374 struct sigaction nbsa, obsa;
375 int error, sig;
376
377 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
378 return (EINVAL);
379
380 if (SCARG(uap, nsa)) {
381 error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
382 if (error)
383 return (error);
384 linux_to_native_sigaction(&nbsa, &nlsa);
385 }
386 sig = SCARG(uap, signum);
387 if (sig < 0 || sig >= LINUX__NSIG)
388 return (EINVAL);
389 if (sig > 0 && !linux_to_native_sig[sig]) {
390 /* Pretend that we did something useful for unknown signals. */
391 obsa.sa_handler = SIG_IGN;
392 sigemptyset(&obsa.sa_mask);
393 obsa.sa_flags = 0;
394 } else {
395 error = sigaction1(p, linux_to_native_sig[sig],
396 SCARG(uap, nsa) ? &nbsa : NULL, SCARG(uap, osa) ? &obsa : NULL);
397 if (error)
398 return (error);
399 }
400 if (SCARG(uap, osa)) {
401 native_to_linux_sigaction(&olsa, &obsa);
402 error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
403 if (error)
404 return (error);
405 }
406 return (0);
407 }
408
409 int
410 linux_sigprocmask1(p, how, set, oset)
411 struct proc *p;
412 int how;
413 const linux_old_sigset_t *set;
414 linux_old_sigset_t *oset;
415 {
416 linux_old_sigset_t nlss, olss;
417 sigset_t nbss, obss;
418 int error;
419
420 switch (how) {
421 case LINUX_SIG_BLOCK:
422 how = SIG_BLOCK;
423 break;
424 case LINUX_SIG_UNBLOCK:
425 how = SIG_UNBLOCK;
426 break;
427 case LINUX_SIG_SETMASK:
428 how = SIG_SETMASK;
429 break;
430 default:
431 return (EINVAL);
432 }
433
434 if (set) {
435 error = copyin(set, &nlss, sizeof(nlss));
436 if (error)
437 return (error);
438 linux_old_to_native_sigset(&nbss, &nlss);
439 }
440 error = sigprocmask1(p, how,
441 set ? &nbss : NULL, oset ? &obss : NULL);
442 if (error)
443 return (error);
444 if (oset) {
445 native_to_linux_old_sigset(&olss, &obss);
446 error = copyout(&olss, oset, sizeof(olss));
447 if (error)
448 return (error);
449 }
450 return (error);
451 }
452
453 int
454 linux_sys_rt_sigprocmask(p, v, retval)
455 struct proc *p;
456 void *v;
457 register_t *retval;
458 {
459 struct linux_sys_rt_sigprocmask_args /* {
460 syscallarg(int) how;
461 syscallarg(const linux_sigset_t *) set;
462 syscallarg(linux_sigset_t *) oset;
463 syscallarg(size_t) sigsetsize;
464 } */ *uap = v;
465
466 linux_sigset_t nlss, olss, *oset;
467 const linux_sigset_t *set;
468 sigset_t nbss, obss;
469 int error, how;
470
471 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
472 return (EINVAL);
473
474 switch (SCARG(uap, how)) {
475 case LINUX_SIG_BLOCK:
476 how = SIG_BLOCK;
477 break;
478 case LINUX_SIG_UNBLOCK:
479 how = SIG_UNBLOCK;
480 break;
481 case LINUX_SIG_SETMASK:
482 how = SIG_SETMASK;
483 break;
484 default:
485 return (EINVAL);
486 }
487
488 set = SCARG(uap, set);
489 oset = SCARG(uap, oset);
490
491 if (set) {
492 error = copyin(set, &nlss, sizeof(nlss));
493 if (error)
494 return (error);
495 linux_to_native_sigset(&nbss, &nlss);
496 }
497 error = sigprocmask1(p, how,
498 set ? &nbss : NULL, oset ? &obss : NULL);
499 if (!error && oset) {
500 native_to_linux_sigset(&olss, &obss);
501 error = copyout(&olss, oset, sizeof(olss));
502 }
503 return (error);
504 }
505
506 int
507 linux_sys_rt_sigpending(p, v, retval)
508 struct proc *p;
509 void *v;
510 register_t *retval;
511 {
512 struct linux_sys_rt_sigpending_args /* {
513 syscallarg(linux_sigset_t *) set;
514 syscallarg(size_t) sigsetsize;
515 } */ *uap = v;
516 sigset_t bss;
517 linux_sigset_t lss;
518
519 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
520 return (EINVAL);
521
522 sigpending1(p, &bss);
523 native_to_linux_sigset(&lss, &bss);
524 return copyout(&lss, SCARG(uap, set), sizeof(lss));
525 }
526
527 int
528 linux_sys_sigpending(p, v, retval)
529 struct proc *p;
530 void *v;
531 register_t *retval;
532 {
533 struct linux_sys_sigpending_args /* {
534 syscallarg(linux_old_sigset_t *) mask;
535 } */ *uap = v;
536 sigset_t bss;
537 linux_old_sigset_t lss;
538
539 sigpending1(p, &bss);
540 native_to_linux_old_sigset(&lss, &bss);
541 return copyout(&lss, SCARG(uap, set), sizeof(lss));
542 }
543
544 int
545 linux_sys_sigsuspend(p, v, retval)
546 struct proc *p;
547 void *v;
548 register_t *retval;
549 {
550 struct linux_sys_sigsuspend_args /* {
551 syscallarg(caddr_t) restart;
552 syscallarg(int) oldmask;
553 syscallarg(int) mask;
554 } */ *uap = v;
555 linux_old_sigset_t lss;
556 sigset_t bss;
557
558 lss = SCARG(uap, mask);
559 linux_old_to_native_sigset(&bss, &lss);
560 return (sigsuspend1(p, &bss));
561 }
562 int
563 linux_sys_rt_sigsuspend(p, v, retval)
564 struct proc *p;
565 void *v;
566 register_t *retval;
567 {
568 struct linux_sys_rt_sigsuspend_args /* {
569 syscallarg(linux_sigset_t *) unewset;
570 syscallarg(size_t) sigsetsize;
571 } */ *uap = v;
572 linux_sigset_t lss;
573 sigset_t bss;
574 int error;
575
576 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
577 return (EINVAL);
578
579 error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
580 if (error)
581 return (error);
582
583 linux_to_native_sigset(&bss, &lss);
584
585 return (sigsuspend1(p, &bss));
586 }
587
588 /*
589 * Once more: only a signal conversion is needed.
590 * Note: also used as sys_rt_queueinfo. The info field is ignored.
591 */
592 int
593 linux_sys_rt_queueinfo(p, v, retval)
594 struct proc *p;
595 void *v;
596 register_t *retval;
597 {
598 /* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
599 #if 0
600 struct linux_sys_rt_queueinfo_args /* {
601 syscallarg(int) pid;
602 syscallarg(int) signum;
603 syscallarg(siginfo_t *) uinfo;
604 } */ *uap = v;
605 #endif
606
607 /* XXX To really implement this we need to */
608 /* XXX keep a list of queued signals somewhere. */
609 return (linux_sys_kill(p, v, retval));
610 }
611
612 int
613 linux_sys_kill(p, v, retval)
614 struct proc *p;
615 void *v;
616 register_t *retval;
617 {
618 struct linux_sys_kill_args /* {
619 syscallarg(int) pid;
620 syscallarg(int) signum;
621 } */ *uap = v;
622 struct sys_kill_args ka;
623 int sig;
624
625 SCARG(&ka, pid) = SCARG(uap, pid);
626 sig = SCARG(uap, signum);
627 if (sig < 0 || sig >= LINUX__NSIG)
628 return (EINVAL);
629 SCARG(&ka, signum) = linux_to_native_sig[sig];
630 return sys_kill(p, &ka, retval);
631 }
632
633 #ifdef LINUX_SS_ONSTACK
634 static void linux_to_native_sigaltstack __P((struct sigaltstack *,
635 const struct linux_sigaltstack *));
636 static void native_to_linux_sigaltstack __P((struct linux_sigaltstack *,
637 const struct sigaltstack *));
638
639 static void
640 linux_to_native_sigaltstack(bss, lss)
641 struct sigaltstack *bss;
642 const struct linux_sigaltstack *lss;
643 {
644 bss->ss_sp = lss->ss_sp;
645 bss->ss_size = lss->ss_size;
646 if (lss->ss_flags & LINUX_SS_ONSTACK)
647 bss->ss_flags = SS_ONSTACK;
648 else if (lss->ss_flags & LINUX_SS_DISABLE)
649 bss->ss_flags = SS_DISABLE;
650 else
651 bss->ss_flags = 0;
652 }
653
654 static void
655 native_to_linux_sigaltstack(lss, bss)
656 struct linux_sigaltstack *lss;
657 const struct sigaltstack *bss;
658 {
659 lss->ss_sp = bss->ss_sp;
660 lss->ss_size = bss->ss_size;
661 if (bss->ss_flags & SS_ONSTACK)
662 lss->ss_flags = LINUX_SS_ONSTACK;
663 else if (bss->ss_flags & SS_DISABLE)
664 lss->ss_flags = LINUX_SS_DISABLE;
665 else
666 lss->ss_flags = 0;
667 }
668
669 int
670 linux_sys_sigaltstack(p, v, retval)
671 struct proc *p;
672 void *v;
673 register_t *retval;
674 {
675 struct linux_sys_sigaltstack_args /* {
676 syscallarg(const struct linux_sigaltstack *) ss;
677 syscallarg(struct linux_sigaltstack *) oss;
678 } */ *uap = v;
679 struct linux_sigaltstack ss;
680 struct sigaltstack nss, oss;
681 int error;
682
683 if (SCARG(uap, ss) != NULL) {
684 if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
685 return error;
686 linux_to_native_sigaltstack(&nss, &ss);
687 }
688
689 error = sigaltstack1(p,
690 SCARG(uap, ss) ? &nss : NULL, SCARG(uap, oss) ? &oss : NULL);
691 if (error)
692 return error;
693
694 if (SCARG(uap, oss) != NULL) {
695 native_to_linux_sigaltstack(&ss, &oss);
696 if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
697 return error;
698 }
699 return 0;
700 }
701 #endif
702