1 /* $NetBSD: kern_50.c,v 1.1 2014/04/04 18:17:36 njoly Exp $ */ 2 3 /*- 4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 #include <sys/cdefs.h> 32 __KERNEL_RCSID(0, "$NetBSD: kern_50.c,v 1.1 2014/04/04 18:17:36 njoly Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/lwp.h> 36 #include <sys/proc.h> 37 #include <sys/syscallargs.h> 38 39 #include <compat/sys/resource.h> 40 #include <compat/sys/time.h> 41 42 int 43 compat_50_sys__lwp_park(struct lwp *l, 44 const struct compat_50_sys__lwp_park_args *uap, register_t *retval) 45 { 46 /* { 47 syscallarg(const struct timespec50 *) ts; 48 syscallarg(lwpid_t) unpark; 49 syscallarg(const void *) hint; 50 syscallarg(const void *) unparkhint; 51 } */ 52 struct timespec ts, *tsp; 53 struct timespec50 ts50; 54 int error; 55 56 if (SCARG(uap, ts) == NULL) 57 tsp = NULL; 58 else { 59 error = copyin(SCARG(uap, ts), &ts50, sizeof(ts50)); 60 if (error != 0) 61 return error; 62 timespec50_to_timespec(&ts50, &ts); 63 tsp = &ts; 64 } 65 66 if (SCARG(uap, unpark) != 0) { 67 error = lwp_unpark(SCARG(uap, unpark), SCARG(uap, unparkhint)); 68 if (error != 0) 69 return error; 70 } 71 72 return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp, SCARG(uap, hint)); 73 } 74 75 static int 76 tscopyin(const void *u, void *s, size_t len) 77 { 78 struct timespec50 ts50; 79 int error; 80 81 KASSERT(len == sizeof(struct timespec)); 82 error = copyin(u, &ts50, sizeof(ts50)); 83 if (error) 84 return error; 85 timespec50_to_timespec(&ts50, s); 86 return 0; 87 } 88 89 static int 90 tscopyout(const void *s, void *u, size_t len) 91 { 92 struct timespec50 ts50; 93 94 KASSERT(len == sizeof(struct timespec)); 95 timespec_to_timespec50(s, &ts50); 96 return copyout(&ts50, u, sizeof(ts50)); 97 } 98 99 int 100 compat_50_sys___sigtimedwait(struct lwp *l, 101 const struct compat_50_sys___sigtimedwait_args *uap, register_t *retval) 102 { 103 int res; 104 105 res = sigtimedwait1(l, 106 (const struct sys_____sigtimedwait50_args *)uap, retval, copyin, 107 copyout, tscopyin, tscopyout); 108 if (!res) 109 *retval = 0; /* XXX NetBSD<=5 was not POSIX compliant */ 110 return res; 111 } 112 113 int 114 compat_50_sys_wait4(struct lwp *l, const struct compat_50_sys_wait4_args *uap, 115 register_t *retval) 116 { 117 /* { 118 syscallarg(int) pid; 119 syscallarg(int *) status; 120 syscallarg(int) options; 121 syscallarg(struct rusage50 *) rusage; 122 } */ 123 int status, error, pid = SCARG(uap, pid); 124 struct rusage50 ru50; 125 struct rusage ru; 126 127 error = do_sys_wait(&pid, &status, SCARG(uap, options), 128 SCARG(uap, rusage) != NULL ? &ru : NULL); 129 130 retval[0] = pid; 131 if (pid == 0) 132 return error; 133 134 if (SCARG(uap, rusage)) { 135 rusage_to_rusage50(&ru, &ru50); 136 error = copyout(&ru50, SCARG(uap, rusage), sizeof(ru50)); 137 } 138 139 if (error == 0 && SCARG(uap, status)) 140 error = copyout(&status, SCARG(uap, status), sizeof(status)); 141 142 return error; 143 } 144