diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index 75fdddb203b7..11836e93d71c 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -1,1328 +1,1167 @@ /* $NetBSD: linux_futex.c,v 1.7 2006/07/24 19:01:49 manu Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 2009-2016 Dmitry Chagin * Copyright (c) 2005 Emmanuel Dreyfus * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Emmanuel Dreyfus * 4. The name of the author may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #if 0 __KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.7 2006/07/24 19:01:49 manu Exp $"); #endif #include "opt_compat.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef COMPAT_LINUX32 #include #include #else #include #include #endif #include #include #include #include #include /* DTrace init */ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); /** * Futex part for the special DTrace module "locks". */ LIN_SDT_PROBE_DEFINE1(locks, futex_mtx, locked, "struct mtx *"); LIN_SDT_PROBE_DEFINE1(locks, futex_mtx, unlock, "struct mtx *"); /** * Per futex probes. */ LIN_SDT_PROBE_DEFINE1(futex, futex, create, "struct sx *"); LIN_SDT_PROBE_DEFINE1(futex, futex, destroy, "struct sx *"); /** * DTrace probes in this module. */ -LIN_SDT_PROBE_DEFINE2(futex, futex_put, entry, "struct futex *", - "struct waiting_proc *"); LIN_SDT_PROBE_DEFINE3(futex, futex_put, destroy, "uint32_t *", "uint32_t", "int"); LIN_SDT_PROBE_DEFINE3(futex, futex_put, unlock, "uint32_t *", "uint32_t", "int"); -LIN_SDT_PROBE_DEFINE0(futex, futex_put, return); -LIN_SDT_PROBE_DEFINE3(futex, futex_get0, entry, "uint32_t *", "struct futex **", - "uint32_t"); LIN_SDT_PROBE_DEFINE1(futex, futex_get0, umtx_key_get_error, "int"); LIN_SDT_PROBE_DEFINE3(futex, futex_get0, shared, "uint32_t *", "uint32_t", "int"); LIN_SDT_PROBE_DEFINE1(futex, futex_get0, null, "uint32_t *"); LIN_SDT_PROBE_DEFINE3(futex, futex_get0, new, "uint32_t *", "uint32_t", "int"); -LIN_SDT_PROBE_DEFINE1(futex, futex_get0, return, "int"); -LIN_SDT_PROBE_DEFINE3(futex, futex_get, entry, "uint32_t *", - "struct waiting_proc **", "struct futex **"); LIN_SDT_PROBE_DEFINE0(futex, futex_get, error); -LIN_SDT_PROBE_DEFINE1(futex, futex_get, return, "int"); -LIN_SDT_PROBE_DEFINE3(futex, futex_sleep, entry, "struct futex *", - "struct waiting_proc **", "struct timespec *"); LIN_SDT_PROBE_DEFINE5(futex, futex_sleep, requeue_error, "int", "uint32_t *", "struct waiting_proc *", "uint32_t *", "uint32_t"); LIN_SDT_PROBE_DEFINE3(futex, futex_sleep, sleep_error, "int", "uint32_t *", "struct waiting_proc *"); -LIN_SDT_PROBE_DEFINE1(futex, futex_sleep, return, "int"); -LIN_SDT_PROBE_DEFINE3(futex, futex_wake, entry, "struct futex *", "int", - "uint32_t"); LIN_SDT_PROBE_DEFINE3(futex, futex_wake, iterate, "uint32_t", "struct waiting_proc *", "uint32_t"); LIN_SDT_PROBE_DEFINE1(futex, futex_wake, wakeup, "struct waiting_proc *"); -LIN_SDT_PROBE_DEFINE1(futex, futex_wake, return, "int"); -LIN_SDT_PROBE_DEFINE4(futex, futex_requeue, entry, "struct futex *", "int", - "struct futex *", "int"); LIN_SDT_PROBE_DEFINE1(futex, futex_requeue, wakeup, "struct waiting_proc *"); LIN_SDT_PROBE_DEFINE3(futex, futex_requeue, requeue, "uint32_t *", "struct waiting_proc *", "uint32_t"); -LIN_SDT_PROBE_DEFINE1(futex, futex_requeue, return, "int"); -LIN_SDT_PROBE_DEFINE4(futex, futex_wait, entry, "struct futex *", - "struct waiting_proc **", "struct timespec *", "uint32_t"); LIN_SDT_PROBE_DEFINE1(futex, futex_wait, sleep_error, "int"); -LIN_SDT_PROBE_DEFINE1(futex, futex_wait, return, "int"); -LIN_SDT_PROBE_DEFINE3(futex, futex_atomic_op, entry, "struct thread *", - "int", "uint32_t"); LIN_SDT_PROBE_DEFINE4(futex, futex_atomic_op, decoded_op, "int", "int", "int", "int"); LIN_SDT_PROBE_DEFINE0(futex, futex_atomic_op, missing_access_check); LIN_SDT_PROBE_DEFINE1(futex, futex_atomic_op, unimplemented_op, "int"); LIN_SDT_PROBE_DEFINE1(futex, futex_atomic_op, unimplemented_cmp, "int"); -LIN_SDT_PROBE_DEFINE1(futex, futex_atomic_op, return, "int"); -LIN_SDT_PROBE_DEFINE2(futex, linux_sys_futex, entry, "struct thread *", - "struct linux_sys_futex_args *"); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_clockswitch); LIN_SDT_PROBE_DEFINE1(futex, linux_sys_futex, copyin_error, "int"); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, invalid_cmp_requeue_use); LIN_SDT_PROBE_DEFINE3(futex, linux_sys_futex, debug_wait, "uint32_t *", "uint32_t", "uint32_t"); LIN_SDT_PROBE_DEFINE4(futex, linux_sys_futex, debug_wait_value_neq, "uint32_t *", "uint32_t", "int", "uint32_t"); LIN_SDT_PROBE_DEFINE3(futex, linux_sys_futex, debug_wake, "uint32_t *", "uint32_t", "uint32_t"); LIN_SDT_PROBE_DEFINE5(futex, linux_sys_futex, debug_cmp_requeue, "uint32_t *", "uint32_t", "uint32_t", "uint32_t *", "struct l_timespec *"); LIN_SDT_PROBE_DEFINE2(futex, linux_sys_futex, debug_cmp_requeue_value_neq, "uint32_t", "int"); LIN_SDT_PROBE_DEFINE5(futex, linux_sys_futex, debug_wake_op, "uint32_t *", "int", "uint32_t", "uint32_t *", "uint32_t"); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unhandled_efault); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_lock_pi); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_unlock_pi); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_trylock_pi); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, deprecated_requeue); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_wait_requeue_pi); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_cmp_requeue_pi); LIN_SDT_PROBE_DEFINE1(futex, linux_sys_futex, unknown_operation, "int"); -LIN_SDT_PROBE_DEFINE1(futex, linux_sys_futex, return, "int"); -LIN_SDT_PROBE_DEFINE2(futex, linux_set_robust_list, entry, "struct thread *", - "struct linux_set_robust_list_args *"); LIN_SDT_PROBE_DEFINE0(futex, linux_set_robust_list, size_error); -LIN_SDT_PROBE_DEFINE1(futex, linux_set_robust_list, return, "int"); -LIN_SDT_PROBE_DEFINE2(futex, linux_get_robust_list, entry, "struct thread *", - "struct linux_get_robust_list_args *"); LIN_SDT_PROBE_DEFINE1(futex, linux_get_robust_list, copyout_error, "int"); -LIN_SDT_PROBE_DEFINE1(futex, linux_get_robust_list, return, "int"); -LIN_SDT_PROBE_DEFINE3(futex, handle_futex_death, entry, - "struct linux_emuldata *", "uint32_t *", "unsigned int"); LIN_SDT_PROBE_DEFINE1(futex, handle_futex_death, copyin_error, "int"); -LIN_SDT_PROBE_DEFINE1(futex, handle_futex_death, return, "int"); -LIN_SDT_PROBE_DEFINE3(futex, fetch_robust_entry, entry, - "struct linux_robust_list **", "struct linux_robust_list **", - "unsigned int *"); LIN_SDT_PROBE_DEFINE1(futex, fetch_robust_entry, copyin_error, "int"); -LIN_SDT_PROBE_DEFINE1(futex, fetch_robust_entry, return, "int"); -LIN_SDT_PROBE_DEFINE2(futex, release_futexes, entry, "struct thread *", - "struct linux_emuldata *"); LIN_SDT_PROBE_DEFINE1(futex, release_futexes, copyin_error, "int"); -LIN_SDT_PROBE_DEFINE0(futex, release_futexes, return); struct futex; struct waiting_proc { uint32_t wp_flags; struct futex *wp_futex; TAILQ_ENTRY(waiting_proc) wp_list; }; struct futex { struct mtx f_lck; uint32_t *f_uaddr; /* user-supplied value, for debug */ struct umtx_key f_key; uint32_t f_refcount; uint32_t f_bitset; LIST_ENTRY(futex) f_list; TAILQ_HEAD(lf_waiting_proc, waiting_proc) f_waiting_proc; }; #define FUTEX_LOCK(f) mtx_lock(&(f)->f_lck) #define FUTEX_LOCKED(f) mtx_owned(&(f)->f_lck) #define FUTEX_UNLOCK(f) mtx_unlock(&(f)->f_lck) #define FUTEX_INIT(f) do { \ mtx_init(&(f)->f_lck, "ftlk", NULL, \ MTX_DUPOK); \ LIN_SDT_PROBE1(futex, futex, create, \ &(f)->f_lck); \ } while (0) #define FUTEX_DESTROY(f) do { \ LIN_SDT_PROBE1(futex, futex, destroy, \ &(f)->f_lck); \ mtx_destroy(&(f)->f_lck); \ } while (0) #define FUTEX_ASSERT_LOCKED(f) mtx_assert(&(f)->f_lck, MA_OWNED) #define FUTEX_ASSERT_UNLOCKED(f) mtx_assert(&(f)->f_lck, MA_NOTOWNED) #define FUTEXES_LOCK do { \ mtx_lock(&futex_mtx); \ LIN_SDT_PROBE1(locks, futex_mtx, \ locked, &futex_mtx); \ } while (0) #define FUTEXES_UNLOCK do { \ LIN_SDT_PROBE1(locks, futex_mtx, \ unlock, &futex_mtx); \ mtx_unlock(&futex_mtx); \ } while (0) /* flags for futex_get() */ #define FUTEX_CREATE_WP 0x1 /* create waiting_proc */ #define FUTEX_DONTCREATE 0x2 /* don't create futex if not exists */ #define FUTEX_DONTEXISTS 0x4 /* return EINVAL if futex exists */ #define FUTEX_SHARED 0x8 /* shared futex */ #define FUTEX_DONTLOCK 0x10 /* don't lock futex */ /* wp_flags */ #define FUTEX_WP_REQUEUED 0x1 /* wp requeued - wp moved from wp_list * of futex where thread sleep to wp_list * of another futex. */ #define FUTEX_WP_REMOVED 0x2 /* wp is woken up and removed from futex * wp_list to prevent double wakeup. */ static void futex_put(struct futex *, struct waiting_proc *); static int futex_get0(uint32_t *, struct futex **f, uint32_t); static int futex_get(uint32_t *, struct waiting_proc **, struct futex **, uint32_t); static int futex_sleep(struct futex *, struct waiting_proc *, struct timespec *); static int futex_wake(struct futex *, int, uint32_t); static int futex_requeue(struct futex *, int, struct futex *, int); static int futex_copyin_timeout(int, struct l_timespec *, int, struct timespec *); static int futex_wait(struct futex *, struct waiting_proc *, struct timespec *, uint32_t); static void futex_lock(struct futex *); static void futex_unlock(struct futex *); static int futex_atomic_op(struct thread *, int, uint32_t *); static int handle_futex_death(struct linux_emuldata *, uint32_t *, unsigned int); static int fetch_robust_entry(struct linux_robust_list **, struct linux_robust_list **, unsigned int *); static int futex_copyin_timeout(int op, struct l_timespec *luts, int clockrt, struct timespec *ts) { struct l_timespec lts; struct timespec kts; int error; error = copyin(luts, <s, sizeof(lts)); if (error) return (error); error = linux_to_native_timespec(ts, <s); if (error) return (error); if (clockrt) { nanotime(&kts); timespecsub(ts, &kts, ts); } else if (op == LINUX_FUTEX_WAIT_BITSET) { nanouptime(&kts); timespecsub(ts, &kts, ts); } return (error); } static void futex_put(struct futex *f, struct waiting_proc *wp) { - LIN_SDT_PROBE2(futex, futex_put, entry, f, wp); if (wp != NULL) { if ((wp->wp_flags & FUTEX_WP_REMOVED) == 0) TAILQ_REMOVE(&f->f_waiting_proc, wp, wp_list); free(wp, M_FUTEX_WP); } FUTEXES_LOCK; if (--f->f_refcount == 0) { LIST_REMOVE(f, f_list); FUTEXES_UNLOCK; if (FUTEX_LOCKED(f)) futex_unlock(f); LIN_SDT_PROBE3(futex, futex_put, destroy, f->f_uaddr, f->f_refcount, f->f_key.shared); LINUX_CTR3(sys_futex, "futex_put destroy uaddr %p ref %d " "shared %d", f->f_uaddr, f->f_refcount, f->f_key.shared); umtx_key_release(&f->f_key); FUTEX_DESTROY(f); free(f, M_FUTEX); - - LIN_SDT_PROBE0(futex, futex_put, return); return; } LIN_SDT_PROBE3(futex, futex_put, unlock, f->f_uaddr, f->f_refcount, f->f_key.shared); LINUX_CTR3(sys_futex, "futex_put uaddr %p ref %d shared %d", f->f_uaddr, f->f_refcount, f->f_key.shared); if (FUTEX_LOCKED(f)) futex_unlock(f); FUTEXES_UNLOCK; - - LIN_SDT_PROBE0(futex, futex_put, return); } static int futex_get0(uint32_t *uaddr, struct futex **newf, uint32_t flags) { struct futex *f, *tmpf; struct umtx_key key; int error; - LIN_SDT_PROBE3(futex, futex_get0, entry, uaddr, newf, flags); - *newf = tmpf = NULL; error = umtx_key_get(uaddr, TYPE_FUTEX, (flags & FUTEX_SHARED) ? AUTO_SHARE : THREAD_SHARE, &key); if (error) { LIN_SDT_PROBE1(futex, futex_get0, umtx_key_get_error, error); - LIN_SDT_PROBE1(futex, futex_get0, return, error); return (error); } retry: FUTEXES_LOCK; LIST_FOREACH(f, &futex_list, f_list) { if (umtx_key_match(&f->f_key, &key)) { if (tmpf != NULL) { if (FUTEX_LOCKED(tmpf)) futex_unlock(tmpf); FUTEX_DESTROY(tmpf); free(tmpf, M_FUTEX); } if (flags & FUTEX_DONTEXISTS) { FUTEXES_UNLOCK; umtx_key_release(&key); - LIN_SDT_PROBE1(futex, futex_get0, return, - EINVAL); return (EINVAL); } /* * Increment refcount of the found futex to * prevent it from deallocation before FUTEX_LOCK() */ ++f->f_refcount; FUTEXES_UNLOCK; umtx_key_release(&key); if ((flags & FUTEX_DONTLOCK) == 0) futex_lock(f); *newf = f; LIN_SDT_PROBE3(futex, futex_get0, shared, uaddr, f->f_refcount, f->f_key.shared); LINUX_CTR3(sys_futex, "futex_get uaddr %p ref %d shared %d", uaddr, f->f_refcount, f->f_key.shared); - LIN_SDT_PROBE1(futex, futex_get0, return, 0); return (0); } } if (flags & FUTEX_DONTCREATE) { FUTEXES_UNLOCK; umtx_key_release(&key); LIN_SDT_PROBE1(futex, futex_get0, null, uaddr); LINUX_CTR1(sys_futex, "futex_get uaddr %p null", uaddr); - LIN_SDT_PROBE1(futex, futex_get0, return, 0); return (0); } if (tmpf == NULL) { FUTEXES_UNLOCK; tmpf = malloc(sizeof(*tmpf), M_FUTEX, M_WAITOK | M_ZERO); tmpf->f_uaddr = uaddr; tmpf->f_key = key; tmpf->f_refcount = 1; tmpf->f_bitset = FUTEX_BITSET_MATCH_ANY; FUTEX_INIT(tmpf); TAILQ_INIT(&tmpf->f_waiting_proc); /* * Lock the new futex before an insert into the futex_list * to prevent futex usage by other. */ if ((flags & FUTEX_DONTLOCK) == 0) futex_lock(tmpf); goto retry; } LIST_INSERT_HEAD(&futex_list, tmpf, f_list); FUTEXES_UNLOCK; LIN_SDT_PROBE3(futex, futex_get0, new, uaddr, tmpf->f_refcount, tmpf->f_key.shared); LINUX_CTR3(sys_futex, "futex_get uaddr %p ref %d shared %d new", uaddr, tmpf->f_refcount, tmpf->f_key.shared); *newf = tmpf; - LIN_SDT_PROBE1(futex, futex_get0, return, 0); return (0); } static int futex_get(uint32_t *uaddr, struct waiting_proc **wp, struct futex **f, uint32_t flags) { int error; - LIN_SDT_PROBE3(futex, futex_get, entry, uaddr, wp, f); - if (flags & FUTEX_CREATE_WP) { *wp = malloc(sizeof(struct waiting_proc), M_FUTEX_WP, M_WAITOK); (*wp)->wp_flags = 0; } error = futex_get0(uaddr, f, flags); if (error) { LIN_SDT_PROBE0(futex, futex_get, error); if (flags & FUTEX_CREATE_WP) free(*wp, M_FUTEX_WP); - LIN_SDT_PROBE1(futex, futex_get, return, error); return (error); } if (flags & FUTEX_CREATE_WP) { TAILQ_INSERT_HEAD(&(*f)->f_waiting_proc, *wp, wp_list); (*wp)->wp_futex = *f; } - LIN_SDT_PROBE1(futex, futex_get, return, error); return (error); } static inline void futex_lock(struct futex *f) { LINUX_CTR3(sys_futex, "futex_lock uaddr %p ref %d shared %d", f->f_uaddr, f->f_refcount, f->f_key.shared); FUTEX_ASSERT_UNLOCKED(f); FUTEX_LOCK(f); } static inline void futex_unlock(struct futex *f) { LINUX_CTR3(sys_futex, "futex_unlock uaddr %p ref %d shared %d", f->f_uaddr, f->f_refcount, f->f_key.shared); FUTEX_ASSERT_LOCKED(f); FUTEX_UNLOCK(f); } static int futex_sleep(struct futex *f, struct waiting_proc *wp, struct timespec *ts) { struct timespec uts; sbintime_t sbt, prec, tmp; time_t over; int error; FUTEX_ASSERT_LOCKED(f); if (ts != NULL) { uts = *ts; if (uts.tv_sec > INT32_MAX / 2) { over = uts.tv_sec - INT32_MAX / 2; uts.tv_sec -= over; } tmp = tstosbt(uts); if (TIMESEL(&sbt, tmp)) sbt += tc_tick_sbt; sbt += tmp; prec = tmp; prec >>= tc_precexp; } else { sbt = 0; prec = 0; } - LIN_SDT_PROBE3(futex, futex_sleep, entry, f, wp, sbt); LINUX_CTR4(sys_futex, "futex_sleep enter uaddr %p wp %p timo %ld ref %d", f->f_uaddr, wp, sbt, f->f_refcount); error = msleep_sbt(wp, &f->f_lck, PCATCH, "futex", sbt, prec, C_ABSOLUTE); if (wp->wp_flags & FUTEX_WP_REQUEUED) { KASSERT(f != wp->wp_futex, ("futex != wp_futex")); if (error) { LIN_SDT_PROBE5(futex, futex_sleep, requeue_error, error, f->f_uaddr, wp, wp->wp_futex->f_uaddr, wp->wp_futex->f_refcount); } LINUX_CTR5(sys_futex, "futex_sleep out error %d uaddr %p wp" " %p requeued uaddr %p ref %d", error, f->f_uaddr, wp, wp->wp_futex->f_uaddr, wp->wp_futex->f_refcount); futex_put(f, NULL); f = wp->wp_futex; futex_lock(f); } else { if (error) { LIN_SDT_PROBE3(futex, futex_sleep, sleep_error, error, f->f_uaddr, wp); } LINUX_CTR3(sys_futex, "futex_sleep out error %d uaddr %p wp %p", error, f->f_uaddr, wp); } futex_put(f, wp); - LIN_SDT_PROBE1(futex, futex_sleep, return, error); return (error); } static int futex_wake(struct futex *f, int n, uint32_t bitset) { struct waiting_proc *wp, *wpt; int count = 0; - LIN_SDT_PROBE3(futex, futex_wake, entry, f, n, bitset); - - if (bitset == 0) { - LIN_SDT_PROBE1(futex, futex_wake, return, EINVAL); + if (bitset == 0) return (EINVAL); - } FUTEX_ASSERT_LOCKED(f); TAILQ_FOREACH_SAFE(wp, &f->f_waiting_proc, wp_list, wpt) { LIN_SDT_PROBE3(futex, futex_wake, iterate, f->f_uaddr, wp, f->f_refcount); LINUX_CTR3(sys_futex, "futex_wake uaddr %p wp %p ref %d", f->f_uaddr, wp, f->f_refcount); /* * Unless we find a matching bit in * the bitset, continue searching. */ if (!(wp->wp_futex->f_bitset & bitset)) continue; wp->wp_flags |= FUTEX_WP_REMOVED; TAILQ_REMOVE(&f->f_waiting_proc, wp, wp_list); LIN_SDT_PROBE1(futex, futex_wake, wakeup, wp); wakeup_one(wp); if (++count == n) break; } - LIN_SDT_PROBE1(futex, futex_wake, return, count); return (count); } static int futex_requeue(struct futex *f, int nrwake, struct futex *f2, int nrrequeue) { struct waiting_proc *wp, *wpt; int count = 0; - LIN_SDT_PROBE4(futex, futex_requeue, entry, f, nrwake, f2, nrrequeue); - FUTEX_ASSERT_LOCKED(f); FUTEX_ASSERT_LOCKED(f2); TAILQ_FOREACH_SAFE(wp, &f->f_waiting_proc, wp_list, wpt) { if (++count <= nrwake) { LINUX_CTR2(sys_futex, "futex_req_wake uaddr %p wp %p", f->f_uaddr, wp); wp->wp_flags |= FUTEX_WP_REMOVED; TAILQ_REMOVE(&f->f_waiting_proc, wp, wp_list); LIN_SDT_PROBE1(futex, futex_requeue, wakeup, wp); wakeup_one(wp); } else { LIN_SDT_PROBE3(futex, futex_requeue, requeue, f->f_uaddr, wp, f2->f_uaddr); LINUX_CTR3(sys_futex, "futex_requeue uaddr %p wp %p to %p", f->f_uaddr, wp, f2->f_uaddr); wp->wp_flags |= FUTEX_WP_REQUEUED; /* Move wp to wp_list of f2 futex */ TAILQ_REMOVE(&f->f_waiting_proc, wp, wp_list); TAILQ_INSERT_HEAD(&f2->f_waiting_proc, wp, wp_list); /* * Thread which sleeps on wp after waking should * acquire f2 lock, so increment refcount of f2 to * prevent it from premature deallocation. */ wp->wp_futex = f2; FUTEXES_LOCK; ++f2->f_refcount; FUTEXES_UNLOCK; if (count - nrwake >= nrrequeue) break; } } - LIN_SDT_PROBE1(futex, futex_requeue, return, count); return (count); } static int futex_wait(struct futex *f, struct waiting_proc *wp, struct timespec *ts, uint32_t bitset) { int error; - LIN_SDT_PROBE4(futex, futex_wait, entry, f, wp, ts, bitset); - if (bitset == 0) { - LIN_SDT_PROBE1(futex, futex_wait, return, EINVAL); futex_put(f, wp); return (EINVAL); } f->f_bitset = bitset; error = futex_sleep(f, wp, ts); if (error) LIN_SDT_PROBE1(futex, futex_wait, sleep_error, error); if (error == EWOULDBLOCK) error = ETIMEDOUT; - LIN_SDT_PROBE1(futex, futex_wait, return, error); return (error); } static int futex_atomic_op(struct thread *td, int encoded_op, uint32_t *uaddr) { int op = (encoded_op >> 28) & 7; int cmp = (encoded_op >> 24) & 15; int oparg = (encoded_op << 8) >> 20; int cmparg = (encoded_op << 20) >> 20; int oldval = 0, ret; - LIN_SDT_PROBE3(futex, futex_atomic_op, entry, td, encoded_op, uaddr); - if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) oparg = 1 << oparg; LIN_SDT_PROBE4(futex, futex_atomic_op, decoded_op, op, cmp, oparg, cmparg); /* XXX: Linux verifies access here and returns EFAULT */ LIN_SDT_PROBE0(futex, futex_atomic_op, missing_access_check); switch (op) { case FUTEX_OP_SET: ret = futex_xchgl(oparg, uaddr, &oldval); break; case FUTEX_OP_ADD: ret = futex_addl(oparg, uaddr, &oldval); break; case FUTEX_OP_OR: ret = futex_orl(oparg, uaddr, &oldval); break; case FUTEX_OP_ANDN: ret = futex_andl(~oparg, uaddr, &oldval); break; case FUTEX_OP_XOR: ret = futex_xorl(oparg, uaddr, &oldval); break; default: LIN_SDT_PROBE1(futex, futex_atomic_op, unimplemented_op, op); ret = -ENOSYS; break; } - if (ret) { - LIN_SDT_PROBE1(futex, futex_atomic_op, return, ret); + if (ret) return (ret); - } switch (cmp) { case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break; case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break; case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break; case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break; case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break; case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break; default: LIN_SDT_PROBE1(futex, futex_atomic_op, unimplemented_cmp, cmp); ret = -ENOSYS; } - LIN_SDT_PROBE1(futex, futex_atomic_op, return, ret); return (ret); } int linux_sys_futex(struct thread *td, struct linux_sys_futex_args *args) { int clockrt, nrwake, nrrequeue, op_ret, ret; struct linux_pemuldata *pem; struct waiting_proc *wp; struct futex *f, *f2; struct timespec uts, *ts; int error, save; uint32_t flags, val; - LIN_SDT_PROBE2(futex, linux_sys_futex, entry, td, args); - if (args->op & LINUX_FUTEX_PRIVATE_FLAG) { flags = 0; args->op &= ~LINUX_FUTEX_PRIVATE_FLAG; } else flags = FUTEX_SHARED; /* * Currently support for switching between CLOCK_MONOTONIC and * CLOCK_REALTIME is not present. However Linux forbids the use of * FUTEX_CLOCK_REALTIME with any op except FUTEX_WAIT_BITSET and * FUTEX_WAIT_REQUEUE_PI. */ clockrt = args->op & LINUX_FUTEX_CLOCK_REALTIME; args->op = args->op & ~LINUX_FUTEX_CLOCK_REALTIME; if (clockrt && args->op != LINUX_FUTEX_WAIT_BITSET && args->op != LINUX_FUTEX_WAIT_REQUEUE_PI) { LIN_SDT_PROBE0(futex, linux_sys_futex, unimplemented_clockswitch); - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); } error = 0; f = f2 = NULL; switch (args->op) { case LINUX_FUTEX_WAIT: args->val3 = FUTEX_BITSET_MATCH_ANY; /* FALLTHROUGH */ case LINUX_FUTEX_WAIT_BITSET: LIN_SDT_PROBE3(futex, linux_sys_futex, debug_wait, args->uaddr, args->val, args->val3); LINUX_CTR3(sys_futex, "WAIT uaddr %p val 0x%x bitset 0x%x", args->uaddr, args->val, args->val3); if (args->timeout != NULL) { error = futex_copyin_timeout(args->op, args->timeout, clockrt, &uts); if (error) { LIN_SDT_PROBE1(futex, linux_sys_futex, copyin_error, error); - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } ts = &uts; } else ts = NULL; retry0: error = futex_get(args->uaddr, &wp, &f, flags | FUTEX_CREATE_WP); - if (error) { - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); + if (error) return (error); - } error = copyin_nofault(args->uaddr, &val, sizeof(val)); if (error) { futex_put(f, wp); error = copyin(args->uaddr, &val, sizeof(val)); if (error == 0) goto retry0; LIN_SDT_PROBE1(futex, linux_sys_futex, copyin_error, error); LINUX_CTR1(sys_futex, "WAIT copyin failed %d", error); - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } if (val != args->val) { LIN_SDT_PROBE4(futex, linux_sys_futex, debug_wait_value_neq, args->uaddr, args->val, val, args->val3); LINUX_CTR3(sys_futex, "WAIT uaddr %p val 0x%x != uval 0x%x", args->uaddr, args->val, val); futex_put(f, wp); - - LIN_SDT_PROBE1(futex, linux_sys_futex, return, - EWOULDBLOCK); return (EWOULDBLOCK); } error = futex_wait(f, wp, ts, args->val3); break; case LINUX_FUTEX_WAKE: args->val3 = FUTEX_BITSET_MATCH_ANY; /* FALLTHROUGH */ case LINUX_FUTEX_WAKE_BITSET: LIN_SDT_PROBE3(futex, linux_sys_futex, debug_wake, args->uaddr, args->val, args->val3); LINUX_CTR3(sys_futex, "WAKE uaddr %p nrwake 0x%x bitset 0x%x", args->uaddr, args->val, args->val3); error = futex_get(args->uaddr, NULL, &f, flags | FUTEX_DONTCREATE); - if (error) { - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); + if (error) return (error); - } if (f == NULL) { td->td_retval[0] = 0; - - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } td->td_retval[0] = futex_wake(f, args->val, args->val3); futex_put(f, NULL); break; case LINUX_FUTEX_CMP_REQUEUE: LIN_SDT_PROBE5(futex, linux_sys_futex, debug_cmp_requeue, args->uaddr, args->val, args->val3, args->uaddr2, args->timeout); LINUX_CTR5(sys_futex, "CMP_REQUEUE uaddr %p " "nrwake 0x%x uval 0x%x uaddr2 %p nrequeue 0x%x", args->uaddr, args->val, args->val3, args->uaddr2, args->timeout); /* * Linux allows this, we would not, it is an incorrect * usage of declared ABI, so return EINVAL. */ if (args->uaddr == args->uaddr2) { LIN_SDT_PROBE0(futex, linux_sys_futex, invalid_cmp_requeue_use); - LIN_SDT_PROBE1(futex, linux_sys_futex, return, EINVAL); return (EINVAL); } nrrequeue = (int)(unsigned long)args->timeout; nrwake = args->val; /* * Sanity check to prevent signed integer overflow, * see Linux CVE-2018-6927 */ if (nrwake < 0 || nrrequeue < 0) return (EINVAL); retry1: error = futex_get(args->uaddr, NULL, &f, flags | FUTEX_DONTLOCK); - if (error) { - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); + if (error) return (error); - } /* * To avoid deadlocks return EINVAL if second futex * exists at this time. * * Glibc fall back to FUTEX_WAKE in case of any error * returned by FUTEX_CMP_REQUEUE. */ error = futex_get(args->uaddr2, NULL, &f2, flags | FUTEX_DONTEXISTS | FUTEX_DONTLOCK); if (error) { futex_put(f, NULL); - - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } futex_lock(f); futex_lock(f2); error = copyin_nofault(args->uaddr, &val, sizeof(val)); if (error) { futex_put(f2, NULL); futex_put(f, NULL); error = copyin(args->uaddr, &val, sizeof(val)); if (error == 0) goto retry1; LIN_SDT_PROBE1(futex, linux_sys_futex, copyin_error, error); LINUX_CTR1(sys_futex, "CMP_REQUEUE copyin failed %d", error); - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } if (val != args->val3) { LIN_SDT_PROBE2(futex, linux_sys_futex, debug_cmp_requeue_value_neq, args->val, val); LINUX_CTR2(sys_futex, "CMP_REQUEUE val 0x%x != uval 0x%x", args->val, val); futex_put(f2, NULL); futex_put(f, NULL); - - LIN_SDT_PROBE1(futex, linux_sys_futex, return, EAGAIN); return (EAGAIN); } td->td_retval[0] = futex_requeue(f, nrwake, f2, nrrequeue); futex_put(f2, NULL); futex_put(f, NULL); break; case LINUX_FUTEX_WAKE_OP: LIN_SDT_PROBE5(futex, linux_sys_futex, debug_wake_op, args->uaddr, args->op, args->val, args->uaddr2, args->val3); LINUX_CTR5(sys_futex, "WAKE_OP " "uaddr %p nrwake 0x%x uaddr2 %p op 0x%x nrwake2 0x%x", args->uaddr, args->val, args->uaddr2, args->val3, args->timeout); - if (args->uaddr == args->uaddr2) { - LIN_SDT_PROBE1(futex, linux_sys_futex, return, EINVAL); + if (args->uaddr == args->uaddr2) return (EINVAL); - } retry2: error = futex_get(args->uaddr, NULL, &f, flags | FUTEX_DONTLOCK); - if (error) { - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); + if (error) return (error); - } error = futex_get(args->uaddr2, NULL, &f2, flags | FUTEX_DONTLOCK); if (error) { futex_put(f, NULL); - - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } futex_lock(f); futex_lock(f2); /* * This function returns positive number as results and * negative as errors */ save = vm_fault_disable_pagefaults(); op_ret = futex_atomic_op(td, args->val3, args->uaddr2); vm_fault_enable_pagefaults(save); LINUX_CTR2(sys_futex, "WAKE_OP atomic_op uaddr %p ret 0x%x", args->uaddr, op_ret); if (op_ret < 0) { if (f2 != NULL) futex_put(f2, NULL); futex_put(f, NULL); error = copyin(args->uaddr2, &val, sizeof(val)); if (error == 0) goto retry2; - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } ret = futex_wake(f, args->val, args->val3); if (op_ret > 0) { op_ret = 0; nrwake = (int)(unsigned long)args->timeout; if (f2 != NULL) op_ret += futex_wake(f2, nrwake, args->val3); else op_ret += futex_wake(f, nrwake, args->val3); ret += op_ret; } if (f2 != NULL) futex_put(f2, NULL); futex_put(f, NULL); td->td_retval[0] = ret; break; case LINUX_FUTEX_LOCK_PI: /* not yet implemented */ pem = pem_find(td->td_proc); if ((pem->flags & LINUX_XUNSUP_FUTEXPIOP) == 0) { linux_msg(td, "unsupported FUTEX_LOCK_PI"); pem->flags |= LINUX_XUNSUP_FUTEXPIOP; LIN_SDT_PROBE0(futex, linux_sys_futex, unimplemented_lock_pi); } - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); case LINUX_FUTEX_UNLOCK_PI: /* not yet implemented */ pem = pem_find(td->td_proc); if ((pem->flags & LINUX_XUNSUP_FUTEXPIOP) == 0) { linux_msg(td, "unsupported FUTEX_UNLOCK_PI"); pem->flags |= LINUX_XUNSUP_FUTEXPIOP; LIN_SDT_PROBE0(futex, linux_sys_futex, unimplemented_unlock_pi); } - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); case LINUX_FUTEX_TRYLOCK_PI: /* not yet implemented */ pem = pem_find(td->td_proc); if ((pem->flags & LINUX_XUNSUP_FUTEXPIOP) == 0) { linux_msg(td, "unsupported FUTEX_TRYLOCK_PI"); pem->flags |= LINUX_XUNSUP_FUTEXPIOP; LIN_SDT_PROBE0(futex, linux_sys_futex, unimplemented_trylock_pi); } - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); case LINUX_FUTEX_REQUEUE: /* * Glibc does not use this operation since version 2.3.3, * as it is racy and replaced by FUTEX_CMP_REQUEUE operation. * Glibc versions prior to 2.3.3 fall back to FUTEX_WAKE when * FUTEX_REQUEUE returned EINVAL. */ pem = pem_find(td->td_proc); if ((pem->flags & LINUX_XDEPR_REQUEUEOP) == 0) { linux_msg(td, "unsupported FUTEX_REQUEUE"); pem->flags |= LINUX_XDEPR_REQUEUEOP; LIN_SDT_PROBE0(futex, linux_sys_futex, deprecated_requeue); } - - LIN_SDT_PROBE1(futex, linux_sys_futex, return, EINVAL); return (EINVAL); case LINUX_FUTEX_WAIT_REQUEUE_PI: /* not yet implemented */ pem = pem_find(td->td_proc); if ((pem->flags & LINUX_XUNSUP_FUTEXPIOP) == 0) { linux_msg(td, "unsupported FUTEX_WAIT_REQUEUE_PI"); pem->flags |= LINUX_XUNSUP_FUTEXPIOP; LIN_SDT_PROBE0(futex, linux_sys_futex, unimplemented_wait_requeue_pi); } - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); case LINUX_FUTEX_CMP_REQUEUE_PI: /* not yet implemented */ pem = pem_find(td->td_proc); if ((pem->flags & LINUX_XUNSUP_FUTEXPIOP) == 0) { linux_msg(td, "unsupported FUTEX_CMP_REQUEUE_PI"); pem->flags |= LINUX_XUNSUP_FUTEXPIOP; LIN_SDT_PROBE0(futex, linux_sys_futex, unimplemented_cmp_requeue_pi); } - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); default: linux_msg(td, "unsupported futex op %d", args->op); LIN_SDT_PROBE1(futex, linux_sys_futex, unknown_operation, args->op); - LIN_SDT_PROBE1(futex, linux_sys_futex, return, ENOSYS); return (ENOSYS); } - LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); return (error); } int linux_set_robust_list(struct thread *td, struct linux_set_robust_list_args *args) { struct linux_emuldata *em; - LIN_SDT_PROBE2(futex, linux_set_robust_list, entry, td, args); - if (args->len != sizeof(struct linux_robust_list_head)) { LIN_SDT_PROBE0(futex, linux_set_robust_list, size_error); - LIN_SDT_PROBE1(futex, linux_set_robust_list, return, EINVAL); return (EINVAL); } em = em_find(td); em->robust_futexes = args->head; - LIN_SDT_PROBE1(futex, linux_set_robust_list, return, 0); return (0); } int linux_get_robust_list(struct thread *td, struct linux_get_robust_list_args *args) { struct linux_emuldata *em; struct linux_robust_list_head *head; l_size_t len = sizeof(struct linux_robust_list_head); struct thread *td2; int error = 0; - LIN_SDT_PROBE2(futex, linux_get_robust_list, entry, td, args); - if (!args->pid) { em = em_find(td); KASSERT(em != NULL, ("get_robust_list: emuldata notfound.\n")); head = em->robust_futexes; } else { td2 = tdfind(args->pid, -1); - if (td2 == NULL) { - LIN_SDT_PROBE1(futex, linux_get_robust_list, return, - ESRCH); + if (td2 == NULL) return (ESRCH); - } if (SV_PROC_ABI(td2->td_proc) != SV_ABI_LINUX) { - LIN_SDT_PROBE1(futex, linux_get_robust_list, return, - EPERM); PROC_UNLOCK(td2->td_proc); return (EPERM); } em = em_find(td2); KASSERT(em != NULL, ("get_robust_list: emuldata notfound.\n")); /* XXX: ptrace? */ if (priv_check(td, PRIV_CRED_SETUID) || priv_check(td, PRIV_CRED_SETEUID) || p_candebug(td, td2->td_proc)) { PROC_UNLOCK(td2->td_proc); - - LIN_SDT_PROBE1(futex, linux_get_robust_list, return, - EPERM); return (EPERM); } head = em->robust_futexes; PROC_UNLOCK(td2->td_proc); } error = copyout(&len, args->len, sizeof(l_size_t)); if (error) { LIN_SDT_PROBE1(futex, linux_get_robust_list, copyout_error, error); - LIN_SDT_PROBE1(futex, linux_get_robust_list, return, EFAULT); return (EFAULT); } error = copyout(&head, args->head, sizeof(head)); if (error) { LIN_SDT_PROBE1(futex, linux_get_robust_list, copyout_error, error); } - LIN_SDT_PROBE1(futex, linux_get_robust_list, return, error); return (error); } static int handle_futex_death(struct linux_emuldata *em, uint32_t *uaddr, unsigned int pi) { uint32_t uval, nval, mval; struct futex *f; int error; - LIN_SDT_PROBE3(futex, handle_futex_death, entry, em, uaddr, pi); - retry: error = copyin(uaddr, &uval, 4); if (error) { LIN_SDT_PROBE1(futex, handle_futex_death, copyin_error, error); - LIN_SDT_PROBE1(futex, handle_futex_death, return, EFAULT); return (EFAULT); } if ((uval & FUTEX_TID_MASK) == em->em_tid) { mval = (uval & FUTEX_WAITERS) | FUTEX_OWNER_DIED; nval = casuword32(uaddr, uval, mval); - if (nval == -1) { - LIN_SDT_PROBE1(futex, handle_futex_death, return, - EFAULT); + if (nval == -1) return (EFAULT); - } if (nval != uval) goto retry; if (!pi && (uval & FUTEX_WAITERS)) { error = futex_get(uaddr, NULL, &f, FUTEX_DONTCREATE | FUTEX_SHARED); - if (error) { - LIN_SDT_PROBE1(futex, handle_futex_death, - return, error); + if (error) return (error); - } if (f != NULL) { futex_wake(f, 1, FUTEX_BITSET_MATCH_ANY); futex_put(f, NULL); } } } - LIN_SDT_PROBE1(futex, handle_futex_death, return, 0); return (0); } static int fetch_robust_entry(struct linux_robust_list **entry, struct linux_robust_list **head, unsigned int *pi) { l_ulong uentry; int error; - LIN_SDT_PROBE3(futex, fetch_robust_entry, entry, entry, head, pi); - error = copyin((const void *)head, &uentry, sizeof(l_ulong)); if (error) { LIN_SDT_PROBE1(futex, fetch_robust_entry, copyin_error, error); - LIN_SDT_PROBE1(futex, fetch_robust_entry, return, EFAULT); return (EFAULT); } *entry = (void *)(uentry & ~1UL); *pi = uentry & 1; - LIN_SDT_PROBE1(futex, fetch_robust_entry, return, 0); return (0); } /* This walks the list of robust futexes releasing them. */ void release_futexes(struct thread *td, struct linux_emuldata *em) { struct linux_robust_list_head *head = NULL; struct linux_robust_list *entry, *next_entry, *pending; unsigned int limit = 2048, pi, next_pi, pip; l_long futex_offset; int rc, error; - LIN_SDT_PROBE2(futex, release_futexes, entry, td, em); - head = em->robust_futexes; - if (head == NULL) { - LIN_SDT_PROBE0(futex, release_futexes, return); + if (head == NULL) return; - } - if (fetch_robust_entry(&entry, PTRIN(&head->list.next), &pi)) { - LIN_SDT_PROBE0(futex, release_futexes, return); + if (fetch_robust_entry(&entry, PTRIN(&head->list.next), &pi)) return; - } error = copyin(&head->futex_offset, &futex_offset, sizeof(futex_offset)); if (error) { LIN_SDT_PROBE1(futex, release_futexes, copyin_error, error); - LIN_SDT_PROBE0(futex, release_futexes, return); return; } - if (fetch_robust_entry(&pending, PTRIN(&head->pending_list), &pip)) { - LIN_SDT_PROBE0(futex, release_futexes, return); + if (fetch_robust_entry(&pending, PTRIN(&head->pending_list), &pip)) return; - } while (entry != &head->list) { rc = fetch_robust_entry(&next_entry, PTRIN(&entry->next), &next_pi); if (entry != pending) if (handle_futex_death(em, (uint32_t *)((caddr_t)entry + futex_offset), pi)) { - LIN_SDT_PROBE0(futex, release_futexes, return); return; } - if (rc) { - LIN_SDT_PROBE0(futex, release_futexes, return); + if (rc) return; - } entry = next_entry; pi = next_pi; if (!--limit) break; sched_relinquish(curthread); } if (pending) handle_futex_death(em, (uint32_t *)((caddr_t)pending + futex_offset), pip); - - LIN_SDT_PROBE0(futex, release_futexes, return); } diff --git a/sys/compat/linux/linux_sysctl.c b/sys/compat/linux/linux_sysctl.c index 76d04164a807..e722280a2bbf 100644 --- a/sys/compat/linux/linux_sysctl.c +++ b/sys/compat/linux/linux_sysctl.c @@ -1,195 +1,176 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2001 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_compat.h" #include #include #include #include #include #include #include #include #include #include #ifdef COMPAT_LINUX32 #include #include #else #include #include #endif #include #include #include #define LINUX_CTL_KERN 1 #define LINUX_CTL_VM 2 #define LINUX_CTL_NET 3 #define LINUX_CTL_PROC 4 #define LINUX_CTL_FS 5 #define LINUX_CTL_DEBUG 6 #define LINUX_CTL_DEV 7 #define LINUX_CTL_BUS 8 /* CTL_KERN names */ #define LINUX_KERN_OSTYPE 1 #define LINUX_KERN_OSRELEASE 2 #define LINUX_KERN_OSREV 3 #define LINUX_KERN_VERSION 4 /* DTrace init */ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); /** * DTrace probes in this module. */ -LIN_SDT_PROBE_DEFINE2(sysctl, handle_string, entry, "struct l___sysctl_args *", - "char *"); LIN_SDT_PROBE_DEFINE1(sysctl, handle_string, copyout_error, "int"); -LIN_SDT_PROBE_DEFINE1(sysctl, handle_string, return, "int"); -LIN_SDT_PROBE_DEFINE2(sysctl, linux_sysctl, entry, "struct l___sysctl_args *", - "struct thread *"); LIN_SDT_PROBE_DEFINE1(sysctl, linux_sysctl, copyin_error, "int"); LIN_SDT_PROBE_DEFINE2(sysctl, linux_sysctl, wrong_length, "int", "int"); LIN_SDT_PROBE_DEFINE1(sysctl, linux_sysctl, unsupported_sysctl, "char *"); -LIN_SDT_PROBE_DEFINE1(sysctl, linux_sysctl, return, "int"); #ifdef LINUX_LEGACY_SYSCALLS static int handle_string(struct l___sysctl_args *la, char *value) { int error; - LIN_SDT_PROBE2(sysctl, handle_string, entry, la, value); - if (la->oldval != 0) { l_int len = strlen(value); error = copyout(value, PTRIN(la->oldval), len + 1); if (!error && la->oldlenp != 0) error = copyout(&len, PTRIN(la->oldlenp), sizeof(len)); if (error) { LIN_SDT_PROBE1(sysctl, handle_string, copyout_error, error); - LIN_SDT_PROBE1(sysctl, handle_string, return, error); return (error); } } - if (la->newval != 0) { - LIN_SDT_PROBE1(sysctl, handle_string, return, ENOTDIR); + if (la->newval != 0) return (ENOTDIR); - } - LIN_SDT_PROBE1(sysctl, handle_string, return, 0); return (0); } int linux_sysctl(struct thread *td, struct linux_sysctl_args *args) { struct l___sysctl_args la; struct sbuf *sb; l_int *mib; char *sysctl_string; int error, i; - LIN_SDT_PROBE2(sysctl, linux_sysctl, entry, td, args->args); - error = copyin(args->args, &la, sizeof(la)); if (error) { LIN_SDT_PROBE1(sysctl, linux_sysctl, copyin_error, error); - LIN_SDT_PROBE1(sysctl, linux_sysctl, return, error); return (error); } if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME) { LIN_SDT_PROBE2(sysctl, linux_sysctl, wrong_length, la.nlen, LINUX_CTL_MAXNAME); - LIN_SDT_PROBE1(sysctl, linux_sysctl, return, ENOTDIR); return (ENOTDIR); } mib = malloc(la.nlen * sizeof(l_int), M_LINUX, M_WAITOK); error = copyin(PTRIN(la.name), mib, la.nlen * sizeof(l_int)); if (error) { LIN_SDT_PROBE1(sysctl, linux_sysctl, copyin_error, error); - LIN_SDT_PROBE1(sysctl, linux_sysctl, return, error); free(mib, M_LINUX); return (error); } switch (mib[0]) { case LINUX_CTL_KERN: if (la.nlen < 2) break; switch (mib[1]) { case LINUX_KERN_VERSION: error = handle_string(&la, version); free(mib, M_LINUX); - LIN_SDT_PROBE1(sysctl, linux_sysctl, return, error); return (error); default: break; } break; default: break; } sb = sbuf_new(NULL, NULL, 20 + la.nlen * 5, SBUF_AUTOEXTEND); if (sb == NULL) { linux_msg(td, "sysctl is not implemented"); LIN_SDT_PROBE1(sysctl, linux_sysctl, unsupported_sysctl, "unknown sysctl, ENOMEM during lookup"); } else { sbuf_printf(sb, "sysctl "); for (i = 0; i < la.nlen; i++) sbuf_printf(sb, "%c%d", (i) ? ',' : '{', mib[i]); sbuf_printf(sb, "} is not implemented"); sbuf_finish(sb); sysctl_string = sbuf_data(sb); linux_msg(td, "%s", sbuf_data(sb)); LIN_SDT_PROBE1(sysctl, linux_sysctl, unsupported_sysctl, sysctl_string); sbuf_delete(sb); } free(mib, M_LINUX); - LIN_SDT_PROBE1(sysctl, linux_sysctl, return, ENOTDIR); return (ENOTDIR); } #endif diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c index 6f1ef36a9114..1d7dcc869159 100644 --- a/sys/compat/linux/linux_time.c +++ b/sys/compat/linux/linux_time.c @@ -1,655 +1,586 @@ /* $NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2001 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #if 0 __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $"); #endif #include "opt_compat.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef COMPAT_LINUX32 #include #include #else #include #include #endif #include #include #include #include /* DTrace init */ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); /** * DTrace probes in this module. */ -LIN_SDT_PROBE_DEFINE2(time, native_to_linux_timespec, entry, - "struct l_timespec *", "struct timespec *"); -LIN_SDT_PROBE_DEFINE0(time, native_to_linux_timespec, return); -LIN_SDT_PROBE_DEFINE2(time, linux_to_native_timespec, entry, - "struct timespec *", "struct l_timespec *"); -LIN_SDT_PROBE_DEFINE1(time, linux_to_native_timespec, return, "int"); -LIN_SDT_PROBE_DEFINE2(time, linux_to_native_clockid, entry, "clockid_t *", - "clockid_t"); LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unsupported_clockid, "clockid_t"); LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, unknown_clockid, "clockid_t"); -LIN_SDT_PROBE_DEFINE1(time, linux_to_native_clockid, return, "int"); -LIN_SDT_PROBE_DEFINE2(time, linux_clock_gettime, entry, "clockid_t", - "struct l_timespec *"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, conversion_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, gettime_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, copyout_error, "int"); -LIN_SDT_PROBE_DEFINE1(time, linux_clock_gettime, return, "int"); -LIN_SDT_PROBE_DEFINE2(time, linux_clock_settime, entry, "clockid_t", - "struct l_timespec *"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, conversion_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, settime_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, copyin_error, "int"); -LIN_SDT_PROBE_DEFINE1(time, linux_clock_settime, return, "int"); -LIN_SDT_PROBE_DEFINE2(time, linux_clock_getres, entry, "clockid_t", - "struct l_timespec *"); LIN_SDT_PROBE_DEFINE0(time, linux_clock_getres, nullcall); LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, conversion_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, getres_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, copyout_error, "int"); -LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, return, "int"); -LIN_SDT_PROBE_DEFINE2(time, linux_nanosleep, entry, "const struct l_timespec *", - "struct l_timespec *"); LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, conversion_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyout_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyin_error, "int"); -LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, return, "int"); -LIN_SDT_PROBE_DEFINE4(time, linux_clock_nanosleep, entry, "clockid_t", "int", - "struct l_timespec *", "struct l_timespec *"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, conversion_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyout_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyin_error, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_flags, "int"); LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_clockid, "int"); -LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, return, "int"); int native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp) { - LIN_SDT_PROBE2(time, native_to_linux_timespec, entry, ltp, ntp); #ifdef COMPAT_LINUX32 if (ntp->tv_sec > INT_MAX || ntp->tv_sec < INT_MIN) return (EOVERFLOW); #endif ltp->tv_sec = ntp->tv_sec; ltp->tv_nsec = ntp->tv_nsec; - LIN_SDT_PROBE0(time, native_to_linux_timespec, return); return (0); } int linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp) { - LIN_SDT_PROBE2(time, linux_to_native_timespec, entry, ntp, ltp); - - if (ltp->tv_sec < 0 || ltp->tv_nsec < 0 || ltp->tv_nsec > 999999999) { - LIN_SDT_PROBE1(time, linux_to_native_timespec, return, EINVAL); + if (ltp->tv_sec < 0 || ltp->tv_nsec < 0 || ltp->tv_nsec > 999999999) return (EINVAL); - } ntp->tv_sec = ltp->tv_sec; ntp->tv_nsec = ltp->tv_nsec; - LIN_SDT_PROBE1(time, linux_to_native_timespec, return, 0); return (0); } int native_to_linux_itimerspec(struct l_itimerspec *ltp, struct itimerspec *ntp) { int error; error = native_to_linux_timespec(<p->it_interval, &ntp->it_interval); if (error == 0) error = native_to_linux_timespec(<p->it_value, &ntp->it_interval); return (error); } int linux_to_native_itimerspec(struct itimerspec *ntp, struct l_itimerspec *ltp) { int error; error = linux_to_native_timespec(&ntp->it_interval, <p->it_interval); if (error == 0) error = linux_to_native_timespec(&ntp->it_value, <p->it_value); return (error); } int linux_to_native_clockid(clockid_t *n, clockid_t l) { - LIN_SDT_PROBE2(time, linux_to_native_clockid, entry, n, l); - if (l < 0) { /* cpu-clock */ if ((l & LINUX_CLOCKFD_MASK) == LINUX_CLOCKFD) return (EINVAL); if (LINUX_CPUCLOCK_WHICH(l) >= LINUX_CPUCLOCK_MAX) return (EINVAL); if (LINUX_CPUCLOCK_PERTHREAD(l)) *n = CLOCK_THREAD_CPUTIME_ID; else *n = CLOCK_PROCESS_CPUTIME_ID; return (0); } switch (l) { case LINUX_CLOCK_REALTIME: *n = CLOCK_REALTIME; break; case LINUX_CLOCK_MONOTONIC: *n = CLOCK_MONOTONIC; break; case LINUX_CLOCK_PROCESS_CPUTIME_ID: *n = CLOCK_PROCESS_CPUTIME_ID; break; case LINUX_CLOCK_THREAD_CPUTIME_ID: *n = CLOCK_THREAD_CPUTIME_ID; break; case LINUX_CLOCK_REALTIME_COARSE: *n = CLOCK_REALTIME_FAST; break; case LINUX_CLOCK_MONOTONIC_COARSE: case LINUX_CLOCK_MONOTONIC_RAW: *n = CLOCK_MONOTONIC_FAST; break; case LINUX_CLOCK_BOOTTIME: *n = CLOCK_UPTIME; break; case LINUX_CLOCK_REALTIME_ALARM: case LINUX_CLOCK_BOOTTIME_ALARM: case LINUX_CLOCK_SGI_CYCLE: case LINUX_CLOCK_TAI: LIN_SDT_PROBE1(time, linux_to_native_clockid, unsupported_clockid, l); - LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL); return (EINVAL); default: LIN_SDT_PROBE1(time, linux_to_native_clockid, unknown_clockid, l); - LIN_SDT_PROBE1(time, linux_to_native_clockid, return, EINVAL); return (EINVAL); } - LIN_SDT_PROBE1(time, linux_to_native_clockid, return, 0); return (0); } int linux_to_native_timerflags(int *nflags, int flags) { if (flags & ~LINUX_TIMER_ABSTIME) return (EINVAL); *nflags = 0; if (flags & LINUX_TIMER_ABSTIME) *nflags |= TIMER_ABSTIME; return (0); } int linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args) { struct l_timespec lts; struct timespec tp; struct rusage ru; struct thread *targettd; struct proc *p; int error, clockwhich; clockid_t nwhich; pid_t pid; lwpid_t tid; - LIN_SDT_PROBE2(time, linux_clock_gettime, entry, args->which, args->tp); - error = linux_to_native_clockid(&nwhich, args->which); if (error != 0) { linux_msg(curthread, "unsupported clock_gettime clockid %d", args->which); LIN_SDT_PROBE1(time, linux_clock_gettime, conversion_error, error); - LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); return (error); } switch (nwhich) { case CLOCK_PROCESS_CPUTIME_ID: if (args->which < 0) { clockwhich = LINUX_CPUCLOCK_WHICH(args->which); pid = LINUX_CPUCLOCK_ID(args->which); } else { clockwhich = LINUX_CPUCLOCK_SCHED; pid = 0; } if (pid == 0) { p = td->td_proc; PROC_LOCK(p); } else { error = pget(pid, PGET_CANSEE, &p); if (error != 0) return (EINVAL); } switch (clockwhich) { case LINUX_CPUCLOCK_PROF: PROC_STATLOCK(p); calcru(p, &ru.ru_utime, &ru.ru_stime); PROC_STATUNLOCK(p); PROC_UNLOCK(p); timevaladd(&ru.ru_utime, &ru.ru_stime); TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp); break; case LINUX_CPUCLOCK_VIRT: PROC_STATLOCK(p); calcru(p, &ru.ru_utime, &ru.ru_stime); PROC_STATUNLOCK(p); PROC_UNLOCK(p); TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp); break; case LINUX_CPUCLOCK_SCHED: kern_process_cputime(p, &tp); PROC_UNLOCK(p); break; default: PROC_UNLOCK(p); return (EINVAL); } break; case CLOCK_THREAD_CPUTIME_ID: if (args->which < 0) { clockwhich = LINUX_CPUCLOCK_WHICH(args->which); tid = LINUX_CPUCLOCK_ID(args->which); } else { clockwhich = LINUX_CPUCLOCK_SCHED; tid = 0; } p = td->td_proc; if (tid == 0) { targettd = td; PROC_LOCK(p); } else { targettd = linux_tdfind(td, tid, p->p_pid); if (targettd == NULL) return (EINVAL); } switch (clockwhich) { case LINUX_CPUCLOCK_PROF: PROC_STATLOCK(p); thread_lock(targettd); rufetchtd(targettd, &ru); thread_unlock(targettd); PROC_STATUNLOCK(p); PROC_UNLOCK(p); timevaladd(&ru.ru_utime, &ru.ru_stime); TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp); break; case LINUX_CPUCLOCK_VIRT: PROC_STATLOCK(p); thread_lock(targettd); rufetchtd(targettd, &ru); thread_unlock(targettd); PROC_STATUNLOCK(p); PROC_UNLOCK(p); TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &tp); break; case LINUX_CPUCLOCK_SCHED: if (td == targettd) targettd = NULL; kern_thread_cputime(targettd, &tp); PROC_UNLOCK(p); break; default: PROC_UNLOCK(p); return (EINVAL); } break; default: error = kern_clock_gettime(td, nwhich, &tp); break; } if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_gettime, gettime_error, error); - LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); return (error); } error = native_to_linux_timespec(<s, &tp); if (error != 0) return (error); error = copyout(<s, args->tp, sizeof lts); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error); - LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); return (error); } int linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args) { struct timespec ts; struct l_timespec lts; int error; clockid_t nwhich; - LIN_SDT_PROBE2(time, linux_clock_settime, entry, args->which, args->tp); - error = linux_to_native_clockid(&nwhich, args->which); if (error != 0) { linux_msg(curthread, "unsupported clock_settime clockid %d", args->which); LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error, error); - LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); } error = copyin(args->tp, <s, sizeof lts); if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_settime, copyin_error, error); - LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); } error = linux_to_native_timespec(&ts, <s); if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error, error); - LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); } error = kern_clock_settime(td, nwhich, &ts); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_settime, settime_error, error); - LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); } int linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args) { struct proc *p; struct timespec ts; struct l_timespec lts; int error, clockwhich; clockid_t nwhich; pid_t pid; lwpid_t tid; - LIN_SDT_PROBE2(time, linux_clock_getres, entry, args->which, args->tp); - error = linux_to_native_clockid(&nwhich, args->which); if (error != 0) { linux_msg(curthread, "unsupported clock_getres clockid %d", args->which); LIN_SDT_PROBE1(time, linux_clock_getres, conversion_error, error); - LIN_SDT_PROBE1(time, linux_clock_getres, return, error); return (error); } /* * Check user supplied clock id in case of per-process * or thread-specific cpu-time clock. */ if (args->which < 0) { switch (nwhich) { case CLOCK_THREAD_CPUTIME_ID: tid = LINUX_CPUCLOCK_ID(args->which); if (tid != 0) { p = td->td_proc; if (linux_tdfind(td, tid, p->p_pid) == NULL) return (EINVAL); PROC_UNLOCK(p); } break; case CLOCK_PROCESS_CPUTIME_ID: pid = LINUX_CPUCLOCK_ID(args->which); if (pid != 0) { error = pget(pid, PGET_CANSEE, &p); if (error != 0) return (EINVAL); PROC_UNLOCK(p); } break; } } if (args->tp == NULL) { LIN_SDT_PROBE0(time, linux_clock_getres, nullcall); - LIN_SDT_PROBE1(time, linux_clock_getres, return, 0); return (0); } switch (nwhich) { case CLOCK_THREAD_CPUTIME_ID: case CLOCK_PROCESS_CPUTIME_ID: clockwhich = LINUX_CPUCLOCK_WHICH(args->which); /* * In both cases (when the clock id obtained by a call to * clock_getcpuclockid() or using the clock * ID CLOCK_PROCESS_CPUTIME_ID Linux hardcodes precision * of clock. The same for the CLOCK_THREAD_CPUTIME_ID clock. * * See Linux posix_cpu_clock_getres() implementation. */ if (args->which > 0 || clockwhich == LINUX_CPUCLOCK_SCHED) { ts.tv_sec = 0; ts.tv_nsec = 1; goto out; } switch (clockwhich) { case LINUX_CPUCLOCK_PROF: nwhich = CLOCK_PROF; break; case LINUX_CPUCLOCK_VIRT: nwhich = CLOCK_VIRTUAL; break; default: return (EINVAL); } break; default: break; } error = kern_clock_getres(td, nwhich, &ts); if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_getres, getres_error, error); - LIN_SDT_PROBE1(time, linux_clock_getres, return, error); return (error); } out: error = native_to_linux_timespec(<s, &ts); if (error != 0) return (error); error = copyout(<s, args->tp, sizeof lts); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error); - LIN_SDT_PROBE1(time, linux_clock_getres, return, error); return (error); } int linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args) { struct timespec *rmtp; struct l_timespec lrqts, lrmts; struct timespec rqts, rmts; int error, error2; - LIN_SDT_PROBE2(time, linux_nanosleep, entry, args->rqtp, args->rmtp); - error = copyin(args->rqtp, &lrqts, sizeof lrqts); if (error != 0) { LIN_SDT_PROBE1(time, linux_nanosleep, copyin_error, error); - LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); } if (args->rmtp != NULL) rmtp = &rmts; else rmtp = NULL; error = linux_to_native_timespec(&rqts, &lrqts); if (error != 0) { LIN_SDT_PROBE1(time, linux_nanosleep, conversion_error, error); - LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); } error = kern_nanosleep(td, &rqts, rmtp); if (error == EINTR && args->rmtp != NULL) { error2 = native_to_linux_timespec(&lrmts, rmtp); if (error2 != 0) return (error2); error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error, error2); - LIN_SDT_PROBE1(time, linux_nanosleep, return, error2); return (error2); } } - LIN_SDT_PROBE1(time, linux_nanosleep, return, error); return (error); } int linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args) { struct timespec *rmtp; struct l_timespec lrqts, lrmts; struct timespec rqts, rmts; int error, error2, flags; clockid_t clockid; - LIN_SDT_PROBE4(time, linux_clock_nanosleep, entry, args->which, - args->flags, args->rqtp, args->rmtp); - error = linux_to_native_timerflags(&flags, args->flags); if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_flags, args->flags); - LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); } error = linux_to_native_clockid(&clockid, args->which); if (error != 0) { linux_msg(curthread, "unsupported clock_nanosleep clockid %d", args->which); LIN_SDT_PROBE1(time, linux_clock_nanosleep, unsupported_clockid, args->which); - LIN_SDT_PROBE1(time, linux_clock_settime, return, error); return (error); } error = copyin(args->rqtp, &lrqts, sizeof(lrqts)); if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyin_error, error); - LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); } if (args->rmtp != NULL) rmtp = &rmts; else rmtp = NULL; error = linux_to_native_timespec(&rqts, &lrqts); if (error != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep, conversion_error, error); - LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); } error = kern_clock_nanosleep(td, clockid, flags, &rqts, rmtp); if (error == EINTR && (flags & TIMER_ABSTIME) == 0 && args->rmtp != NULL) { error2 = native_to_linux_timespec(&lrmts, rmtp); if (error2 != 0) return (error2); error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyout_error, error2); - LIN_SDT_PROBE1(time, linux_clock_nanosleep, - return, error2); return (error2); } } - LIN_SDT_PROBE1(time, linux_clock_nanosleep, return, error); return (error); } diff --git a/sys/compat/linux/linux_uid16.c b/sys/compat/linux/linux_uid16.c index 0d1e782b7efa..5d0bfdde083c 100644 --- a/sys/compat/linux/linux_uid16.c +++ b/sys/compat/linux/linux_uid16.c @@ -1,439 +1,353 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2001 The FreeBSD Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_compat.h" #include #include #include #include #include #include #include #include #include #include #include #include #ifdef COMPAT_LINUX32 #include #include #else #include #include #endif #include #include /* DTrace init */ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); /** * DTrace probes in this module. */ -LIN_SDT_PROBE_DEFINE3(uid16, linux_chown16, entry, "char *", "l_uid16_t", - "l_gid16_t"); LIN_SDT_PROBE_DEFINE1(uid16, linux_chown16, conv_path, "char *"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_chown16, return, "int"); -LIN_SDT_PROBE_DEFINE3(uid16, linux_lchown16, entry, "char *", "l_uid16_t", - "l_gid16_t"); LIN_SDT_PROBE_DEFINE1(uid16, linux_lchown16, conv_path, "char *"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_lchown16, return, "int"); -LIN_SDT_PROBE_DEFINE2(uid16, linux_setgroups16, entry, "l_uint", "l_gid16_t *"); LIN_SDT_PROBE_DEFINE1(uid16, linux_setgroups16, copyin_error, "int"); LIN_SDT_PROBE_DEFINE1(uid16, linux_setgroups16, priv_check_cred_error, "int"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setgroups16, return, "int"); -LIN_SDT_PROBE_DEFINE2(uid16, linux_getgroups16, entry, "l_uint", "l_gid16_t *"); LIN_SDT_PROBE_DEFINE1(uid16, linux_getgroups16, copyout_error, "int"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_getgroups16, return, "int"); -LIN_SDT_PROBE_DEFINE0(uid16, linux_getgid16, entry); -LIN_SDT_PROBE_DEFINE1(uid16, linux_getgid16, return, "int"); -LIN_SDT_PROBE_DEFINE0(uid16, linux_getuid16, entry); -LIN_SDT_PROBE_DEFINE1(uid16, linux_getuid16, return, "int"); -LIN_SDT_PROBE_DEFINE0(uid16, linux_getegid16, entry); -LIN_SDT_PROBE_DEFINE1(uid16, linux_getegid16, return, "int"); -LIN_SDT_PROBE_DEFINE0(uid16, linux_geteuid16, entry); -LIN_SDT_PROBE_DEFINE1(uid16, linux_geteuid16, return, "int"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setgid16, entry, "l_gid16_t"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setgid16, return, "int"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setuid16, entry, "l_uid16_t"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setuid16, return, "int"); -LIN_SDT_PROBE_DEFINE2(uid16, linux_setregid16, entry, "l_gid16_t", "l_gid16_t"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setregid16, return, "int"); -LIN_SDT_PROBE_DEFINE2(uid16, linux_setreuid16, entry, "l_uid16_t", "l_uid16_t"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setreuid16, return, "int"); -LIN_SDT_PROBE_DEFINE3(uid16, linux_setresgid16, entry, "l_gid16_t", "l_gid16_t", - "l_gid16_t"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setresgid16, return, "int"); -LIN_SDT_PROBE_DEFINE3(uid16, linux_setresuid16, entry, "l_uid16_t", "l_uid16_t", - "l_uid16_t"); -LIN_SDT_PROBE_DEFINE1(uid16, linux_setresuid16, return, "int"); DUMMY(setfsuid16); DUMMY(setfsgid16); DUMMY(getresuid16); DUMMY(getresgid16); #define CAST_NOCHG(x) ((x == 0xFFFF) ? -1 : x) int linux_chown16(struct thread *td, struct linux_chown16_args *args) { char *path; int error; if (!LUSECONVPATH(td) && !SDT_PROBES_ENABLED()) { error = kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0); } else { LCONVPATHEXIST(td, args->path, &path); /* * The DTrace probes have to be after the LCONVPATHEXIST, as * LCONVPATHEXIST may return on its own and we do not want to * have a stray entry without the corresponding return. */ - LIN_SDT_PROBE3(uid16, linux_chown16, entry, args->path, args->uid, - args->gid); LIN_SDT_PROBE1(uid16, linux_chown16, conv_path, path); error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0); LFREEPATH(path); - LIN_SDT_PROBE1(uid16, linux_chown16, return, error); } return (error); } int linux_lchown16(struct thread *td, struct linux_lchown16_args *args) { char *path; int error; if (!LUSECONVPATH(td) && !SDT_PROBES_ENABLED()) { error = kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW); } else { LCONVPATHEXIST(td, args->path, &path); /* * The DTrace probes have to be after the LCONVPATHEXIST, as * LCONVPATHEXIST may return on its own and we do not want to * have a stray entry without the corresponding return. */ - LIN_SDT_PROBE3(uid16, linux_lchown16, entry, args->path, args->uid, - args->gid); LIN_SDT_PROBE1(uid16, linux_lchown16, conv_path, path); error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW); LFREEPATH(path); - LIN_SDT_PROBE1(uid16, linux_lchown16, return, error); } return (error); } int linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args) { struct ucred *newcred, *oldcred; l_gid16_t *linux_gidset; gid_t *bsd_gidset; int ngrp, error; struct proc *p; - LIN_SDT_PROBE2(uid16, linux_setgroups16, entry, args->gidsetsize, - args->gidset); - ngrp = args->gidsetsize; - if (ngrp < 0 || ngrp >= ngroups_max + 1) { - LIN_SDT_PROBE1(uid16, linux_setgroups16, return, EINVAL); + if (ngrp < 0 || ngrp >= ngroups_max + 1) return (EINVAL); - } linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t)); if (error) { LIN_SDT_PROBE1(uid16, linux_setgroups16, copyin_error, error); - LIN_SDT_PROBE1(uid16, linux_setgroups16, return, error); free(linux_gidset, M_LINUX); return (error); } newcred = crget(); p = td->td_proc; PROC_LOCK(p); oldcred = crcopysafe(p, newcred); /* * cr_groups[0] holds egid. Setting the whole set from * the supplied set will cause egid to be changed too. * Keep cr_groups[0] unchanged to prevent that. */ if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS)) != 0) { PROC_UNLOCK(p); crfree(newcred); LIN_SDT_PROBE1(uid16, linux_setgroups16, priv_check_cred_error, error); goto out; } if (ngrp > 0) { newcred->cr_ngroups = ngrp + 1; bsd_gidset = newcred->cr_groups; ngrp--; while (ngrp >= 0) { bsd_gidset[ngrp + 1] = linux_gidset[ngrp]; ngrp--; } } else newcred->cr_ngroups = 1; setsugid(td->td_proc); proc_set_cred(p, newcred); PROC_UNLOCK(p); crfree(oldcred); error = 0; out: free(linux_gidset, M_LINUX); - LIN_SDT_PROBE1(uid16, linux_setgroups16, return, error); return (error); } int linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args) { struct ucred *cred; l_gid16_t *linux_gidset; gid_t *bsd_gidset; int bsd_gidsetsz, ngrp, error; - LIN_SDT_PROBE2(uid16, linux_getgroups16, entry, args->gidsetsize, - args->gidset); - cred = td->td_ucred; bsd_gidset = cred->cr_groups; bsd_gidsetsz = cred->cr_ngroups - 1; /* * cr_groups[0] holds egid. Returning the whole set * here will cause a duplicate. Exclude cr_groups[0] * to prevent that. */ if ((ngrp = args->gidsetsize) == 0) { td->td_retval[0] = bsd_gidsetsz; - - LIN_SDT_PROBE1(uid16, linux_getgroups16, return, 0); return (0); } - if (ngrp < bsd_gidsetsz) { - LIN_SDT_PROBE1(uid16, linux_getgroups16, return, EINVAL); + if (ngrp < bsd_gidsetsz) return (EINVAL); - } ngrp = 0; linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset), M_LINUX, M_WAITOK); while (ngrp < bsd_gidsetsz) { linux_gidset[ngrp] = bsd_gidset[ngrp + 1]; ngrp++; } error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t)); free(linux_gidset, M_LINUX); if (error) { LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error); - LIN_SDT_PROBE1(uid16, linux_getgroups16, return, error); return (error); } td->td_retval[0] = ngrp; - LIN_SDT_PROBE1(uid16, linux_getgroups16, return, 0); return (0); } int linux_getgid16(struct thread *td, struct linux_getgid16_args *args) { - LIN_SDT_PROBE0(uid16, linux_getgid16, entry); - td->td_retval[0] = td->td_ucred->cr_rgid; - LIN_SDT_PROBE1(uid16, linux_getgid16, return, 0); return (0); } int linux_getuid16(struct thread *td, struct linux_getuid16_args *args) { - LIN_SDT_PROBE0(uid16, linux_getuid16, entry); - td->td_retval[0] = td->td_ucred->cr_ruid; - LIN_SDT_PROBE1(uid16, linux_getuid16, return, 0); return (0); } int linux_getegid16(struct thread *td, struct linux_getegid16_args *args) { struct getegid_args bsd; int error; - LIN_SDT_PROBE0(uid16, linux_getegid16, entry); - error = sys_getegid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_getegid16, return, error); return (error); } int linux_geteuid16(struct thread *td, struct linux_geteuid16_args *args) { struct geteuid_args bsd; int error; - LIN_SDT_PROBE0(uid16, linux_geteuid16, entry); - error = sys_geteuid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_geteuid16, return, error); return (error); } int linux_setgid16(struct thread *td, struct linux_setgid16_args *args) { struct setgid_args bsd; int error; - LIN_SDT_PROBE1(uid16, linux_setgid16, entry, args->gid); - bsd.gid = args->gid; error = sys_setgid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_setgid16, return, error); return (error); } int linux_setuid16(struct thread *td, struct linux_setuid16_args *args) { struct setuid_args bsd; int error; - LIN_SDT_PROBE1(uid16, linux_setuid16, entry, args->uid); - bsd.uid = args->uid; error = sys_setuid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_setuid16, return, error); return (error); } int linux_setregid16(struct thread *td, struct linux_setregid16_args *args) { struct setregid_args bsd; int error; - LIN_SDT_PROBE2(uid16, linux_setregid16, entry, args->rgid, args->egid); - bsd.rgid = CAST_NOCHG(args->rgid); bsd.egid = CAST_NOCHG(args->egid); error = sys_setregid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_setregid16, return, error); return (error); } int linux_setreuid16(struct thread *td, struct linux_setreuid16_args *args) { struct setreuid_args bsd; int error; - LIN_SDT_PROBE2(uid16, linux_setreuid16, entry, args->ruid, args->euid); - bsd.ruid = CAST_NOCHG(args->ruid); bsd.euid = CAST_NOCHG(args->euid); error = sys_setreuid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_setreuid16, return, error); return (error); } int linux_setresgid16(struct thread *td, struct linux_setresgid16_args *args) { struct setresgid_args bsd; int error; - LIN_SDT_PROBE3(uid16, linux_setresgid16, entry, args->rgid, args->egid, - args->sgid); - bsd.rgid = CAST_NOCHG(args->rgid); bsd.egid = CAST_NOCHG(args->egid); bsd.sgid = CAST_NOCHG(args->sgid); error = sys_setresgid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_setresgid16, return, error); return (error); } int linux_setresuid16(struct thread *td, struct linux_setresuid16_args *args) { struct setresuid_args bsd; int error; - LIN_SDT_PROBE3(uid16, linux_setresuid16, entry, args->ruid, args->euid, - args->suid); - bsd.ruid = CAST_NOCHG(args->ruid); bsd.euid = CAST_NOCHG(args->euid); bsd.suid = CAST_NOCHG(args->suid); error = sys_setresuid(td, &bsd); - LIN_SDT_PROBE1(uid16, linux_setresuid16, return, error); return (error); } diff --git a/sys/compat/linux/linux_util.h b/sys/compat/linux/linux_util.h index 681c03c625e4..2350e62c7270 100644 --- a/sys/compat/linux/linux_util.h +++ b/sys/compat/linux/linux_util.h @@ -1,196 +1,191 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1994 Christos Zoulas * Copyright (c) 1995 Frank van der Linden * Copyright (c) 1995 Scott Bartram * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * from: svr4_util.h,v 1.5 1994/11/18 02:54:31 christos Exp * from: linux_util.h,v 1.2 1995/03/05 23:23:50 fvdl Exp * $FreeBSD$ */ #ifndef _LINUX_UTIL_H_ #define _LINUX_UTIL_H_ #include #include #include #include #include #include #include #include MALLOC_DECLARE(M_LINUX); MALLOC_DECLARE(M_EPOLL); MALLOC_DECLARE(M_FUTEX); MALLOC_DECLARE(M_FUTEX_WP); extern char linux_emul_path[]; extern int linux_use_emul_path; int linux_emul_convpath(struct thread *, const char *, enum uio_seg, char **, int, int); #define LUSECONVPATH(td) atomic_load_int(&linux_use_emul_path) #define LCONVPATH_AT(td, upath, pathp, i, dfd) \ do { \ int _error; \ \ _error = linux_emul_convpath(td, upath, UIO_USERSPACE, \ pathp, i, dfd); \ if (*(pathp) == NULL) \ return (_error); \ } while (0) #define LCONVPATH(td, upath, pathp, i) \ LCONVPATH_AT(td, upath, pathp, i, AT_FDCWD) #define LCONVPATHEXIST(td, upath, pathp) LCONVPATH(td, upath, pathp, 0) #define LCONVPATHEXIST_AT(td, upath, pathp, dfd) LCONVPATH_AT(td, upath, pathp, 0, dfd) #define LCONVPATHCREAT(td, upath, pathp) LCONVPATH(td, upath, pathp, 1) #define LCONVPATHCREAT_AT(td, upath, pathp, dfd) LCONVPATH_AT(td, upath, pathp, 1, dfd) #define LFREEPATH(path) free(path, M_TEMP) #define DUMMY(s) \ -LIN_SDT_PROBE_DEFINE0(dummy, s, entry); \ LIN_SDT_PROBE_DEFINE0(dummy, s, not_implemented); \ -LIN_SDT_PROBE_DEFINE1(dummy, s, return, "int"); \ int \ linux_ ## s(struct thread *td, struct linux_ ## s ## _args *args) \ { \ static pid_t pid; \ \ - LIN_SDT_PROBE0(dummy, s, entry); \ - \ if (pid != td->td_proc->p_pid) { \ linux_msg(td, "syscall %s not implemented", #s); \ LIN_SDT_PROBE0(dummy, s, not_implemented); \ pid = td->td_proc->p_pid; \ }; \ \ - LIN_SDT_PROBE1(dummy, s, return, ENOSYS); \ return (ENOSYS); \ } \ struct __hack /* * This is for the syscalls that are not even yet implemented in Linux. * * They're marked as UNIMPL in syscall.master so it will * have nosys record in linux_sysent[]. */ #define UNIMPLEMENTED(s) void linux_msg(const struct thread *td, const char *fmt, ...) __printflike(2, 3); struct linux_device_handler { char *bsd_driver_name; char *linux_driver_name; char *bsd_device_name; char *linux_device_name; int linux_major; int linux_minor; int linux_char_device; }; int linux_device_register_handler(struct linux_device_handler *h); int linux_device_unregister_handler(struct linux_device_handler *h); char *linux_driver_get_name_dev(device_t dev); int linux_driver_get_major_minor(const char *node, int *major, int *minor); int linux_vn_get_major_minor(const struct vnode *vn, int *major, int *minor); char *linux_get_char_devices(void); void linux_free_get_char_devices(char *string); /* * Criteria for interface name translation */ #define IFP_IS_ETH(ifp) ((ifp)->if_type == IFT_ETHER) #define IFP_IS_LOOP(ifp) ((ifp)->if_type == IFT_LOOP) struct ifnet; bool linux_use_real_ifname(const struct ifnet *ifp); #if defined(KTR) #define KTR_LINUX KTR_SUBSYS #define LINUX_CTRFMT(nm, fmt) #nm"("fmt")" #define LINUX_CTR6(f, m, p1, p2, p3, p4, p5, p6) do { \ CTR6(KTR_LINUX, LINUX_CTRFMT(f, m), \ p1, p2, p3, p4, p5, p6); \ } while (0) #define LINUX_CTR(f) LINUX_CTR6(f, "", 0, 0, 0, 0, 0, 0) #define LINUX_CTR0(f, m) LINUX_CTR6(f, m, 0, 0, 0, 0, 0, 0) #define LINUX_CTR1(f, m, p1) LINUX_CTR6(f, m, p1, 0, 0, 0, 0, 0) #define LINUX_CTR2(f, m, p1, p2) LINUX_CTR6(f, m, p1, p2, 0, 0, 0, 0) #define LINUX_CTR3(f, m, p1, p2, p3) LINUX_CTR6(f, m, p1, p2, p3, 0, 0, 0) #define LINUX_CTR4(f, m, p1, p2, p3, p4) LINUX_CTR6(f, m, p1, p2, p3, p4, 0, 0) #define LINUX_CTR5(f, m, p1, p2, p3, p4, p5) LINUX_CTR6(f, m, p1, p2, p3, p4, p5, 0) #else #define LINUX_CTR(f) #define LINUX_CTR0(f, m) #define LINUX_CTR1(f, m, p1) #define LINUX_CTR2(f, m, p1, p2) #define LINUX_CTR3(f, m, p1, p2, p3) #define LINUX_CTR4(f, m, p1, p2, p3, p4) #define LINUX_CTR5(f, m, p1, p2, p3, p4, p5) #define LINUX_CTR6(f, m, p1, p2, p3, p4, p5, p6) #endif /* * Some macros for rate limiting messages: * - noisy if compat.linux.debug = 1 * - print only once if compat.linux.debug > 1 */ #define LINUX_RATELIMIT_MSG_NOTTESTED(_what) \ do { \ static int seen = 0; \ \ if (seen == 0 && linux_debug >= 2) { \ linux_msg(curthread, "%s is not tested, please report on emulation@FreeBSD.org how it works", _what); \ \ if (linux_debug < 3) \ seen = 1; \ } \ } while (0) #define LINUX_RATELIMIT_MSG_OPT1(_message, _opt1) \ do { \ static int seen = 0; \ \ if (seen == 0) { \ linux_msg(curthread, _message, _opt1); \ \ if (linux_debug < 3) \ seen = 1; \ } \ } while (0) #endif /* ! _LINUX_UTIL_H_ */