kern_sig_13.c revision 1.2
1/* $NetBSD: kern_sig_13.c,v 1.2 1997/11/29 18:39:46 kleink Exp $ */ 2 3/*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Klaus Klein. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/param.h> 40#include <sys/proc.h> 41#include <sys/signal.h> 42#include <sys/systm.h> 43 44#include <sys/mount.h> 45#include <sys/syscallargs.h> 46 47#include <machine/limits.h> 48 49#include <compat/common/compat_util.h> 50 51 52int 53compat_13_sys_sigaltstack(p, v, retval) 54 struct proc *p; 55 void *v; 56 register_t *retval; 57{ 58 struct sys___sigaltstack14_args ua; 59 struct compat_13_sys_sigaltstack_args /* { 60 syscallarg(const struct sigaltstack13 *) nss; 61 syscallarg(struct sigaltstack13 *) oss; 62 } */ *uap = v; 63 struct sigaltstack13 tmp13; 64 struct sigaltstack tmp, *nssp, *ossp; 65 caddr_t sg; 66 int error; 67 68 sg = stackgap_init(p->p_emul); 69 70 71 if (SCARG(uap, nss) != NULL) { 72 error = copyin(SCARG(uap, nss), &tmp13, 73 sizeof(struct sigaltstack13)); 74 if (error != 0) 75 return (error); 76 77 tmp.ss_sp = tmp13.ss_sp; 78 tmp.ss_size = tmp13.ss_size; 79 tmp.ss_flags = tmp13.ss_flags; 80 81 nssp = stackgap_alloc(&sg, sizeof(struct sigaltstack)); 82 error = copyout(&tmp, nssp, sizeof(struct sigaltstack)); 83 if (error != 0) 84 return (error); 85 } else 86 nssp = NULL; 87 88 if (SCARG(uap, oss) != NULL) 89 ossp = stackgap_alloc(&sg, sizeof(struct sigaltstack)); 90 else 91 ossp = NULL; 92 93 SCARG(&ua, nss) = nssp; 94 SCARG(&ua, oss) = ossp; 95 96 error = sys___sigaltstack14(p, &ua, retval); 97 if (error != 0) 98 return (error); 99 100 if (SCARG(uap, oss) != NULL) { 101 error = copyin(SCARG(&ua, oss), &tmp, 102 sizeof(struct sigaltstack)); 103 if (error != 0) 104 return (error); 105 106 tmp13.ss_sp = tmp.ss_sp; 107 if (tmp.ss_size > INT_MAX) 108 tmp13.ss_size = INT_MAX; 109 else 110 tmp13.ss_size = tmp.ss_size; 111 tmp13.ss_flags = tmp.ss_flags; 112 113 error = copyout(&tmp13, SCARG(uap, oss), 114 sizeof(struct sigaltstack13)); 115 if (error != 0) 116 return (error); 117 } 118 119 return (0); 120} 121