1 1.1 thorpej /* $NetBSD: netbsd32_futex.c,v 1.1 2020/04/26 18:53:33 thorpej Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.1 thorpej * Copyright (c) 2019 The NetBSD Foundation. 5 1.1 thorpej * All rights reserved. 6 1.1 thorpej * 7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.1 thorpej * by Taylor R. Campbell and Jason R. Thorpe. 9 1.1 thorpej * 10 1.1 thorpej * Redistribution and use in source and binary forms, with or without 11 1.1 thorpej * modification, are permitted provided that the following conditions 12 1.1 thorpej * are met: 13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.1 thorpej * notice, this list of conditions and the following disclaimer. 15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.1 thorpej * documentation and/or other materials provided with the distribution. 18 1.1 thorpej * 19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 thorpej */ 31 1.1 thorpej 32 1.1 thorpej #include <sys/cdefs.h> 33 1.1 thorpej __KERNEL_RCSID(0, "$NetBSD: netbsd32_futex.c,v 1.1 2020/04/26 18:53:33 thorpej Exp $"); 34 1.1 thorpej 35 1.1 thorpej #include <sys/types.h> 36 1.1 thorpej #include <sys/param.h> 37 1.1 thorpej #include <sys/systm.h> 38 1.1 thorpej #include <sys/proc.h> 39 1.1 thorpej #include <sys/lwp.h> 40 1.1 thorpej #include <sys/syscallargs.h> 41 1.1 thorpej #include <sys/futex.h> 42 1.1 thorpej 43 1.1 thorpej #include <compat/netbsd32/netbsd32.h> 44 1.1 thorpej #include <compat/netbsd32/netbsd32_syscallargs.h> 45 1.1 thorpej #include <compat/netbsd32/netbsd32_conv.h> 46 1.1 thorpej 47 1.1 thorpej /* Sycalls conversion */ 48 1.1 thorpej 49 1.1 thorpej int 50 1.1 thorpej netbsd32___futex(struct lwp *l, const struct netbsd32___futex_args *uap, 51 1.1 thorpej register_t *retval) 52 1.1 thorpej { 53 1.1 thorpej /* { 54 1.1 thorpej syscallarg(netbsd32_intp) uaddr; 55 1.1 thorpej syscallarg(int) op; 56 1.1 thorpej syscallarg(int) val; 57 1.1 thorpej syscallarg(netbsd32_timespecp_t) timeout; 58 1.1 thorpej syscallarg(netbsd32_intp) uaddr2; 59 1.1 thorpej syscallarg(int) val2; 60 1.1 thorpej syscallarg(int) val3; 61 1.1 thorpej } */ 62 1.1 thorpej struct netbsd32_timespec ts32; 63 1.1 thorpej struct timespec ts, *tsp; 64 1.1 thorpej int error; 65 1.1 thorpej 66 1.1 thorpej /* 67 1.1 thorpej * Copy in the timeout argument, if specified. 68 1.1 thorpej */ 69 1.1 thorpej if (SCARG_P32(uap, timeout)) { 70 1.1 thorpej error = copyin(SCARG_P32(uap, timeout), &ts32, sizeof(ts32)); 71 1.1 thorpej if (error) 72 1.1 thorpej return error; 73 1.1 thorpej netbsd32_to_timespec(&ts32, &ts); 74 1.1 thorpej tsp = &ts; 75 1.1 thorpej } else { 76 1.1 thorpej tsp = NULL; 77 1.1 thorpej } 78 1.1 thorpej 79 1.1 thorpej return do_futex(SCARG_P32(uap, uaddr), SCARG(uap, op), 80 1.1 thorpej SCARG(uap, val), tsp, SCARG_P32(uap, uaddr2), SCARG(uap, val2), 81 1.1 thorpej SCARG(uap, val3), retval); 82 1.1 thorpej } 83 1.1 thorpej 84 1.1 thorpej int 85 1.1 thorpej netbsd32___futex_set_robust_list(struct lwp *l, 86 1.1 thorpej const struct netbsd32___futex_set_robust_list_args *uap, register_t *retval) 87 1.1 thorpej { 88 1.1 thorpej /* { 89 1.1 thorpej syscallarg(netbsd32_voidp) head; 90 1.1 thorpej syscallarg(netbsd32_size_t) len; 91 1.1 thorpej } */ 92 1.1 thorpej void *head = SCARG_P32(uap, head); 93 1.1 thorpej 94 1.1 thorpej if (SCARG(uap, len) != _FUTEX_ROBUST_HEAD_SIZE32) 95 1.1 thorpej return EINVAL; 96 1.1 thorpej if ((uintptr_t)head % sizeof(uint32_t)) 97 1.1 thorpej return EINVAL; 98 1.1 thorpej 99 1.1 thorpej l->l_robust_head = (uintptr_t)head; 100 1.1 thorpej 101 1.1 thorpej return 0; 102 1.1 thorpej } 103 1.1 thorpej 104 1.1 thorpej int 105 1.1 thorpej netbsd32___futex_get_robust_list(struct lwp *l, 106 1.1 thorpej const struct netbsd32___futex_get_robust_list_args *uap, register_t *retval) 107 1.1 thorpej { 108 1.1 thorpej /* { 109 1.1 thorpej syscallarg(lwpid_t) lwpid; 110 1.1 thorpej syscallarg(netbsd32_voidp) headp; 111 1.1 thorpej syscallarg(netbsd32_size_tp) lenp; 112 1.1 thorpej } */ 113 1.1 thorpej void *head; 114 1.1 thorpej const netbsd32_size_t len = _FUTEX_ROBUST_HEAD_SIZE32; 115 1.1 thorpej netbsd32_voidp head32; 116 1.1 thorpej int error; 117 1.1 thorpej 118 1.1 thorpej error = futex_robust_head_lookup(l, SCARG(uap, lwpid), &head); 119 1.1 thorpej if (error) 120 1.1 thorpej return error; 121 1.1 thorpej 122 1.1 thorpej head32.i32 = (uintptr_t)head; 123 1.1 thorpej if (NETBSD32PTR64(head32) != head) 124 1.1 thorpej return EFAULT; 125 1.1 thorpej 126 1.1 thorpej /* Copy out the head pointer and the head structure length. */ 127 1.1 thorpej /* (N.B.: "headp" is actually a "void **". */ 128 1.1 thorpej error = copyout(&head32, SCARG_P32(uap, headp), sizeof(head32)); 129 1.1 thorpej if (__predict_true(error == 0)) { 130 1.1 thorpej error = copyout(&len, SCARG_P32(uap, lenp), sizeof(len)); 131 1.1 thorpej } 132 1.1 thorpej 133 1.1 thorpej return error; 134 1.1 thorpej } 135