From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79F5CC982D7 for ; Sat, 19 Sep 2026 16:52:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7yFt-0003mR-3R; Sat, 19 Sep 2026 12:49:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7yFc-0003Hu-If for qemu-devel@nongnu.org; Sat, 19 Sep 2026 12:49:20 -0400 Received: from mail-oo2-x2a.google.com ([2607:f8b0:4864:31::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7yFa-0008Mc-Ao for qemu-devel@nongnu.org; Sat, 19 Sep 2026 12:49:20 -0400 Received: by mail-oo2-x2a.google.com with SMTP id 006d021491bc7-6c901f4bfffso1001066eaf.2 for ; Sat, 19 Sep 2026 09:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1789836557; x=1790441357; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=7dinv1Ids7MzQ5PXZfjAquIevvBnoK8Z7rCrc5mpfYI=; b=zpi1JDZoszCLuVDvLBrUU0KeaIC0w6Md4MrhcuWcUJXJkeQFkjoQ/RukLbR8Am/GrB PSuubn+VRTd0AXUS6nAHNcxLNZQ53u2q8d5Huqvh+oSJhXVvk0VWQR1emYl/OxntTsvu a9egc80DL2TwW7P/9CfDqcN25AC1Go07qvTnqBxpqJC6o0W2w21aPHyWVFzH3H+E4UC/ Iyn9vFgCs3+SPNUF0dK58KWL4kvfphEKPvwJss0zTuGgiu6YFoIJ+iS8Zu4UHJ3XSfc2 KtCNloxkNOoM59twb5UMI9LfBWmHjqxdXZJW5/QkfEJZtr7xe0y3QeEwptr7bSv5jDB6 0u3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789836557; x=1790441357; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7dinv1Ids7MzQ5PXZfjAquIevvBnoK8Z7rCrc5mpfYI=; b=UBxdYkFKyC5B4C+LE6mGf/Pgzp/PqfdbvEpF897JmOxGaKTOTqP5Qnu08arxdDqk7A ltZwS6oWpnxZKuC1oToDcYn2yjViyOiAdtxvnEwnYjd+6gdfi48A7Mp1YaHNL6bvfr8e 3IKNYNn7b4zTaiKJj2xmpDsKMVi362jOi9bybAgeH0M3/qFJK1pAzMab7q7AL2yGHESX QI614wAaxhLRdOIsEEJeYY+jd9o4mB/gYlbAvWqbtUdP1pYksYqsrwf8MfL9vcjYHWPX Fn29jq2NMJaCpcX6PT66bEO0sblMkYdVvny9P/I8ALYhNI2S5zN+dVHz7jiRhc9Gt0nq ZnAQ== X-Gm-Message-State: AFuF++ma3woV44tFU1GeDbTN2nwK6i8QDS/hqcglLaYzYaKyKITovNtU y965IQ7qTt7XsDKzhxc5FAtR094JMviQzGBOYmQemUDXwYUM8R6/qgsl6gTkrLASCFN4gJbB7s1 9eQ1UU1M= X-Gm-Gg: AYBFou3NZi1hqsn3Ek57+s6ZNUYWu/e0Uzx1dLci2CfqNexDMyZYNGqyDNF5w/+u6QY hhm7u3L0aKGD9R9SD8EpQFcckbELWvDo8TCd4gt3OJ7E3J+iYAGGHtp9b1TkoVXaHP9N9lGBYXl vnHyZ+ZKfBv9i7EVmbMUR6upaBTpXrvB+siUCsiOPAKotRB8wopJTZRrnQHa1B2ON0+F4fmBOQp /Goj8eNYKw6PDc0vEf+jjK9MyuvvXwU5HQQBuLku+urp5t9HTZP3UM/VxmnG1QbZQcCfaqLUVMY vkQT2d2qnZaD6J5n0tASebKGUk1AgOSN5qrnMO/4PU2Zloz6YDq9QIOqI3xuV7q+6m6ezEz3yLy /X9n97lZw8dVIg/nrOiAxEMQfWxJIZgVyobdDiH/pEHkEULROWJL8aGufaZqSCUA7f4CRftkytH qRWvn+vFwtv7pLwpzAYxjo9KIiiQwx8i3IFCFzYWzMsq4MFKSBwxKplsAWw3398MjTIlj+mg== X-Received: by 2002:a05:6820:c90:b0:6ca:453c:affd with SMTP id 006d021491bc7-6ca9d44ad06mr5353439eaf.57.1789836557288; Sat, 19 Sep 2026 09:49:17 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6cd35712c0csm3281927eaf.11.2026.09.19.09.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2026 09:49:15 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Warner Losh , Kyle Evans , Stacey Son , =?UTF-8?q?Mika=C3=ABl=20Urankar?= , Sean Bruno , Kyle Evans , Richard Henderson Subject: [PULL 25/41] bsd-user: Add kqueue and kevent functions to os-time.h Date: Sat, 19 Sep 2026 10:47:53 -0600 Message-ID: <20260919164810.70151-26-imp@bsdimp.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260919164810.70151-1-imp@bsdimp.com> References: <20260919164810.70151-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=2607:f8b0:4864:31::2a; envelope-from=imp@bsdimp.com; helo=mail-oo2-x2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add event notification system call shims: kqueue, freebsd11_kevent (legacy 32-bit data field), and kevent (with 64-bit ext fields). Signed-off-by: Stacey Son Signed-off-by: Mikaƫl Urankar Signed-off-by: Sean Bruno Signed-off-by: Kyle Evans Assisted-by: Claude Opus 4.6 (1M context) Acked-by: Richard Henderson Signed-off-by: Warner Losh --- bsd-user/freebsd/os-time.h | 173 +++++++++++++++++++++++++++++++++++++ bsd-user/syscall_defs.h | 22 +++++ 2 files changed, 195 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 5f537fac40..302872dd8e 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -635,5 +635,178 @@ static inline abi_long do_freebsd_ppoll(CPUArchState *env, abi_long arg1, } /* kqueue(2) */ +static inline abi_long do_freebsd_kqueue(void) +{ + + return get_errno(kqueue()); +} + +/* kevent(2) */ +/* XXX Maybe some day, consolidate these two... */ +static inline abi_long do_freebsd_freebsd11_kevent(abi_long arg1, + abi_ulong arg2, abi_long arg3, abi_ulong arg4, abi_long arg5, abi_long arg6) +{ + abi_long ret; + struct kevent *changelist = NULL, *eventlist = NULL; + struct target_freebsd11_kevent *target_changelist, *target_eventlist; + struct timespec ts; + int i; + + if (arg3 != 0) { + target_changelist = lock_user(VERIFY_READ, arg2, + sizeof(*target_changelist) * arg3, 1); + if (target_changelist == NULL) { + return -TARGET_EFAULT; + } + + changelist = alloca(sizeof(struct kevent) * arg3); + memset(changelist, '\0', sizeof(struct kevent) * arg3); + for (i = 0; i < arg3; i++) { + __get_user(changelist[i].ident, &target_changelist[i].ident); + __get_user(changelist[i].filter, &target_changelist[i].filter); + __get_user(changelist[i].flags, &target_changelist[i].flags); + __get_user(changelist[i].fflags, &target_changelist[i].fflags); + __get_user(changelist[i].data, &target_changelist[i].data); + /* __get_user(changelist[i].udata, &target_changelist[i].udata); */ +#if TARGET_ABI_BITS == 32 + changelist[i].udata = (void *)(uintptr_t)target_changelist[i].udata; + tswap32s((uint32_t *)&changelist[i].udata); +#else + changelist[i].udata = (void *)(uintptr_t)target_changelist[i].udata; + tswap64s((uint64_t *)&changelist[i].udata); +#endif + } + unlock_user(target_changelist, arg2, 0); + } + + if (arg5 != 0) { + eventlist = alloca(sizeof(struct kevent) * arg5); + } + if (arg6 != 0) { + if (t2h_freebsd_timespec(&ts, arg6)) { + return -TARGET_EFAULT; + } + } + ret = get_errno(safe_kevent(arg1, changelist, arg3, eventlist, arg5, + arg6 != 0 ? &ts : NULL)); + + if (arg5 == 0) { + return ret; + } + + if (!is_error(ret)) { + target_eventlist = lock_user(VERIFY_WRITE, arg4, + sizeof(*target_eventlist) * arg5, 0); + if (target_eventlist == NULL) { + return -TARGET_EFAULT; + } + for (i = 0; i < ret; i++) { + __put_user(eventlist[i].ident, &target_eventlist[i].ident); + __put_user(eventlist[i].filter, &target_eventlist[i].filter); + __put_user(eventlist[i].flags, &target_eventlist[i].flags); + __put_user(eventlist[i].fflags, &target_eventlist[i].fflags); + __put_user(eventlist[i].data, &target_eventlist[i].data); + /* __put_user(eventlist[i].udata, &target_eventlist[i].udata);*/ +#if TARGET_ABI_BITS == 32 + tswap32s((uint32_t *)&eventlist[i].udata); + target_eventlist[i].udata = (uintptr_t)eventlist[i].udata; +#else + tswap64s((uint64_t *)&eventlist[i].udata); + target_eventlist[i].udata = (uintptr_t)eventlist[i].udata; +#endif + } + unlock_user(target_eventlist, arg4, + sizeof(*target_eventlist) * ret); + } + return ret; +} + +/* kevent(2) */ +static inline abi_long do_freebsd_kevent(abi_long arg1, abi_ulong arg2, + abi_long arg3, abi_ulong arg4, abi_long arg5, abi_long arg6) +{ + abi_long ret; + struct kevent *changelist = NULL, *eventlist = NULL; + struct target_freebsd_kevent *target_changelist, *target_eventlist; + struct timespec ts; + int i; + + if (arg3 != 0) { + target_changelist = lock_user(VERIFY_READ, arg2, + sizeof(struct target_freebsd_kevent) * arg3, 1); + if (target_changelist == NULL) { + return -TARGET_EFAULT; + } + + changelist = alloca(sizeof(struct kevent) * arg3); + for (i = 0; i < arg3; i++) { + __get_user(changelist[i].ident, &target_changelist[i].ident); + __get_user(changelist[i].filter, &target_changelist[i].filter); + __get_user(changelist[i].flags, &target_changelist[i].flags); + __get_user(changelist[i].fflags, &target_changelist[i].fflags); + __get_user(changelist[i].data, &target_changelist[i].data); + /* __get_user(changelist[i].udata, &target_changelist[i].udata); */ +#if TARGET_ABI_BITS == 32 + changelist[i].udata = (void *)(uintptr_t)target_changelist[i].udata; + tswap32s((uint32_t *)&changelist[i].udata); +#else + changelist[i].udata = (void *)(uintptr_t)target_changelist[i].udata; + tswap64s((uint64_t *)&changelist[i].udata); +#endif + __get_user(changelist[i].ext[0], &target_changelist[i].ext[0]); + __get_user(changelist[i].ext[1], &target_changelist[i].ext[1]); + __get_user(changelist[i].ext[2], &target_changelist[i].ext[2]); + __get_user(changelist[i].ext[3], &target_changelist[i].ext[3]); + } + unlock_user(target_changelist, arg2, 0); + } + + if (arg5 != 0) { + eventlist = alloca(sizeof(struct kevent) * arg5); + } + if (arg6 != 0) { + if (t2h_freebsd_timespec(&ts, arg6)) { + return -TARGET_EFAULT; + } + } + ret = get_errno(safe_kevent(arg1, changelist, arg3, eventlist, arg5, + arg6 != 0 ? &ts : NULL)); + + if (arg5 == 0) { + return ret; + } + + if (!is_error(ret)) { + target_eventlist = lock_user(VERIFY_WRITE, arg4, + sizeof(struct target_freebsd_kevent) * arg5, 0); + if (target_eventlist == NULL) { + return -TARGET_EFAULT; + } + for (i = 0; i < ret; i++) { + __put_user(eventlist[i].ident, &target_eventlist[i].ident); + __put_user(eventlist[i].filter, &target_eventlist[i].filter); + __put_user(eventlist[i].flags, &target_eventlist[i].flags); + __put_user(eventlist[i].fflags, &target_eventlist[i].fflags); + __put_user(eventlist[i].data, &target_eventlist[i].data); + /* __put_user(eventlist[i].udata, &target_eventlist[i].udata);*/ +#if TARGET_ABI_BITS == 32 + tswap32s((uint32_t *)&eventlist[i].udata); + target_eventlist[i].udata = (uintptr_t)eventlist[i].udata; +#else + tswap64s((uint64_t *)&eventlist[i].udata); + target_eventlist[i].udata = (uintptr_t)eventlist[i].udata; +#endif + __put_user(eventlist[i].ext[0], &target_eventlist[i].ext[0]); + __put_user(eventlist[i].ext[1], &target_eventlist[i].ext[1]); + __put_user(eventlist[i].ext[2], &target_eventlist[i].ext[2]); + __put_user(eventlist[i].ext[3], &target_eventlist[i].ext[3]); + } + unlock_user(target_eventlist, arg4, + sizeof(struct target_freebsd_kevent) * ret); + } + return ret; +} + +/* sigtimedwait(2) */ #endif /* FREEBSD_OS_TIME_H */ diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 0d7002312f..f4bb687388 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -155,6 +155,28 @@ struct target_freebsd_timeval { #endif }; +/* + * sys/event.h + */ +struct target_freebsd11_kevent { + abi_ulong ident; + int16_t filter; + uint16_t flags; + uint32_t fflags; + abi_long data; + abi_ulong udata; +}; + +struct target_freebsd_kevent { + abi_ulong ident; + int16_t filter; + uint16_t flags; + uint32_t fflags; + int64_t data; + abi_ulong udata; + uint64_t ext[4]; +}; + /* * sys/resource.h */ -- 2.55.0