From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139715; cv=none; d=zohomail.com; s=zohoarc; b=UFLDZH8lQxcoa4AIx9n5+6YpEN+w8LCmu7aUhYIK2VmC6k9qc6/NQA55J8hIHFXC0Q9rcRcXLHisiBPMP45dNrPPpgeWNcKTsyg7QbiO5k0SOVWRDz8jWZo9JPfxjQ+M1yp+YQVhmgHZbj8tcSIRevJCLj1IKaHfP+u+lNCBS7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139715; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CenKEzTcPoLDRcBcEsTcXvijDJrJ/9k/bqUajU10YlI=; b=NPtfLj1XXqujhtxVB6o1MUvWaazkdgbyO67ciiPLCaTazdd4iv01mIO7yxmNSnvFTPcRe8ZVz9rzvlByeDT6vhfyFrgG67wlrsBaNTLKFGUVqhY26vFLizp2shyMOTOhnZHhQ6WZDPSskmllHCFfzvY5njcX/MbMnRynFk8GeyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139715002249.72556516562668; Mon, 18 May 2026 14:28:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VF-0000Kw-R8; Mon, 18 May 2026 17:27:57 -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 1wP5VE-0000KL-Ae for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:56 -0400 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VC-0000Pi-3I for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:56 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7e4de538f83so1675786a34.1 for ; Mon, 18 May 2026 14:27:53 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139672; x=1779744472; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CenKEzTcPoLDRcBcEsTcXvijDJrJ/9k/bqUajU10YlI=; b=fxdVL/DC4xWDOg45mtc2tAztM5RW5duU8YbOjkJ4o+KMuErdIM72d4Tk1JPos8POVE Vkk0jdxVL7doHk2VsytN6a/7p9gqpkYU1ihvXjq87jNojPAJQSSnbb/8Y/yd7abQ7t2P kaCErEIk2V1H5ql7o4ts1fyuWurBsPDarsLi43W7ZXhvCXr4zq0ccZTYEAKKkN6B2c5X wFmUh6d87J7JKyaRkKeVBl9Sr52AAsl2XSX0KI6iNFYttD4Qc/mPVnzpyXJvGlfDtY/E 5hTR9CwxX2ry45Y+eSLT5uygj+JC2L1zHnR1xY/+fP1ALrMAa4OIcjXez1SRIcoWylHI SbOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139672; x=1779744472; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=CenKEzTcPoLDRcBcEsTcXvijDJrJ/9k/bqUajU10YlI=; b=lpbc9iM2+p/31qskvztDSwH2JVyxPTgvLOLQ2/Wc6C+4iNfzR4uupRLurYKaG18c+B bj+uLPeDky/6nONLgQ9urKud7hKJ3/70c+wOuNDxJ67NqooODSINQ7lD+snutf0A+UWQ dF3UtI6kye42UiiL134SK0jDFQpFfdnqVVtWdhWLqCCmtmx48FeQiMbvHwf1aB2MmhDI mClBnLqXJnIVaN+yCp/KUgDsilc6FaLTRa9xS9nHYtd2K6bWd2r6e+GBi6DwzODEMvSC hlg/hiUh8VeV3OBdU0QAjEcsXjVkxup2TjpYuHl3BRRHIh/Z+BNV0YfVhZ0UQsJiS7VN lHrQ== X-Gm-Message-State: AOJu0Yw2S3FvH43R5Q42B0ldYYsaVDsMUBThdr4JosRA+Er5/AWQ+a2J GITJ1FLN7f8e1wiaoBRAzwm4TzfgDEXuftnSLK5RegwLn3VFALxO3HwrohPEIkbC3JdCrL3m9gE BqnFrvXk= X-Gm-Gg: Acq92OHQ2uCjVPWA8RS3NXDjmqgCloNcxKknh7IwryQUaJfE73NqQsv4JRQ5jpJ46Xh SjlJMuGrzbAv9s+R/uffnwHJztDhrOl7MfvLpPOl3d3EIaNcKQAKUOynCHOhl/HhEKg6iofB6sd 1N7TXFGnPlBj3QVH6BU93UvzghTZ81iVsvCtuMNBhfOQihNGP7yon2XH+MmewqT1fRBiJoHjRy8 LfarEfrSSGAOI4AVj8aeni5R0DF/RTXrNdWbRhj0dZsDshguPZU2IGuVIIWPFUom15zMdmdLPLv J9PKSi4oJtMUS2SBlVV4xTkDg7o+fbPWk/uTv7qs9pQH+quhhejrCOHDBEWodVDAOtMAKspb8MQ iKeHeJdjtMWagjcRxv9ftMTPC1NxOepZdX8j5uSawZo8IXntoKPMrzvfIVyaJNuvHlUgkpwhmj3 PrCItMvukPXw== X-Received: by 2002:a05:6830:6312:b0:7dc:e6e8:62b with SMTP id 46e09a7af769-7e4f2b416bemr11453676a34.13.1779139672426; Mon, 18 May 2026 14:27:52 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:19 -0600 Subject: [PATCH v2 01/37] bsd-user: catchup to locking / mapping routines in bsd-misc. MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-1-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1492; i=imp@bsdimp.com; h=from:subject:message-id; bh=pDBL7W85bLOqj4gx3AV175aLRI3QACypNGsgVG8xCQ4=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RFmz7WMtNKf+AQ5+jDdG+T9ly1ToUZU/Q6a RCgZzC/76eJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERQAKCRBsHNEofbAR AEFEEADadISO28kkSdi3DQWi8v/ketUx1Uwrz1b/LJE7BOlmvC6Svv4xTuWp3UdMqrqnaIt6aTt kZtHyPQczOQ/6In3NzuiRCIedluFuK3pIwHn3jVvZ6mZopWFPLrg0kzuvSgtVvEyzYdagYuOUSc zB0qpoPbzhWupGXMYKpeOsakuRrcvkolIxFWTncRW4nXhzUdbpH7JO0pkpkiQaxvDA0CygqIOED UXb6pJ114Sfvh2IPIVmIR2Uk52DBdA04c5W/5XEkt0Hjsy6JMcoWloLdfogwJ6t20ehOwYyBRe7 2RMmC5CNDnhSdTPc8pqcPWDEpoiYEoH4WsmsrEUSqgKgTiRP1/qY508E4VIvB2dvLK0sUL5eli5 TEzJS4zEkKNszNHCM7hnLchOWXLvyoqyXC8S85LlxJFToKAMoj0eDTbpd7iNcnCWyTMPkma+CxV W4EeuenEoQF/6FuA06snOteKUBJ9zLlINy2iXbTWLbGCLQipxguloG/L6BtkSinUe2UCfxsA4PS J8bjVfcjG4F0L11wjqN5ZD4AvCwTy1YSWB/2uJOt2J6EebADVdGIhvtcMb9soRfG6e4dz+Q2fiv DzjNc5whWh8mkS9Td63kv/eu+8KP7ZctwcQjMIHcvr0+N19pywwKfpGGA9jlNAUqxZqUxrRzAhh pRgJ2Iquiq+VgbA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::335; envelope-from=imp@bsdimp.com; helo=mail-ot1-x335.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139716167154100 These were added to bsd-misc.c in a prior series. The declarations logically belong here, but aren't strictly needed with the current structure of the code due to include contamination. Signed-off-by: Warner Losh Reviewed-by: Pierrick Bouvier --- bsd-user/qemu-bsd.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h index 756425d18e..f7c8338213 100644 --- a/bsd-user/qemu-bsd.h +++ b/bsd-user/qemu-bsd.h @@ -32,6 +32,24 @@ int host_to_target_waitstatus(int status); void h2g_rusage(const struct rusage *rusage, struct target_freebsd_rusage *target_rusage); =20 +/* bsd-misc.c */ +abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid= ); + +abi_long target_to_host_semarray(int semid, unsigned short **host_array, + abi_ulong target_addr); +abi_long host_to_target_semarray(int semid, abi_ulong target_addr, + unsigned short **host_array); + +abi_long target_to_host_semid_ds(struct semid_ds *host_sd, + abi_ulong target_addr); +abi_long host_to_target_semid_ds(abi_ulong target_addr, + struct semid_ds *host_sd); + +abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, + abi_ulong target_addr); +abi_long host_to_target_msqid_ds(abi_ulong target_addr, + struct msqid_ds *host_md); + /* bsd-mem.c */ void target_to_host_ipc_perm__locked(struct ipc_perm *host_ip, struct target_ipc_perm *target_ip); --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139756; cv=none; d=zohomail.com; s=zohoarc; b=cZ6Mt9a7F5nmZkjpZMfbiFNAI4w2tea5u2VQSqB/g5sUOy+xnX0Q9DUNhKXY3tO9s/5+kgt/zw5NxMp6KmXA6Q82suhcrgk1wCL1nGGdIrVpyPuhYRZuD76E4hFh6dv/Vy+ms+Wwpc2SJDOS5wCuoQ03570LL68tGpbzxTW3DvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139756; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TVNKhC47htsCXR+j7O3XY1Fkg9FzU8BawJBWpAqG91k=; b=OMg9KrBvolwMVCeJcOKJubFEx0ZTB8S+jf50ZkUSWieqIYuDi3Fm8pfAnLLuXGGQnIxq88Vf5aUf9iK/XuoA2YXafz2GQeQ1gsPp0zwVVq4B2PuaYqdpsQ98GMCmGVKXCZQlJIPjy3pZo4E1bG6TnpMvjpW9JxIMlbH8mnqJY3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139755968889.2926204850136; Mon, 18 May 2026 14:29:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VJ-0000Ma-AY; Mon, 18 May 2026 17:28:01 -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 1wP5VH-0000LR-85 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:59 -0400 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VC-0000Po-Sc for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:58 -0400 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-7dd73b7c757so1437492a34.0 for ; Mon, 18 May 2026 14:27:54 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139673; x=1779744473; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TVNKhC47htsCXR+j7O3XY1Fkg9FzU8BawJBWpAqG91k=; b=zUfgjyWxjWusJRvBKnYpYcodXi0lWeUTpglmsku5+8XrrnoIEJERQC6k5612hqjl58 L2vmOxmeKj3t7e2L60HwtmU3JuBwlhXYXl/Oy+PqgY1nY+mZQOwUk+LIksSuOWE8/quu Ygnq5OcvrVPgrxj7GgLGn43Qhh/vPTTmOo/S3y5zBmk7vBp8MyrpEq2ULhrJMBCUhf0s DW1diDebUcQIoyLPOPVvOxGmvmeEIl9Cfb/qH4v+iKPQSsessnNBZ5rYxiz2dJ/maczb c+6xYSO2FaB8h2slDdBqaXr0QCovcCJt8+KVccC+sEYveKv19tDjnK42DM8fEgt+nw8z K6YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139673; x=1779744473; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=TVNKhC47htsCXR+j7O3XY1Fkg9FzU8BawJBWpAqG91k=; b=rYXDH7eE3enOedGljUGz3zQ0o6fA2qo80U/lO8pqmUWRdzGI4K6TF9wR0+K9A5ZdvH lUACjJuy/ct3Crpp92NoFOFRkYBs8V7PxNsn3XCTRBVze9Y1HgtljKr6JpZifuNPBINX i7pDn0drul4pDxjdqqa0OjHknaFLjwbaBkIfFgHXZSggox+xlShVxAzZ1jHI7jmh2a10 uvtrBfH66rUyZ8VrwmkOgweRxM24naFgg3NzhaufE5S3XhxCjY6JBzSiRxpDJpCuZvBg Vhxot7d1J6AOb6gE8UdskQ2ivWKtDd5+xfIHtts84RodxFS5ZSY24/hE4/hEfkrHw1vL fLtQ== X-Gm-Message-State: AOJu0YzYixZ8wh6tmAiE0WNwPiAhKzugFKXmQDJg6a3vlnNOaTfd0LW3 s2wtHVL1RNXB2fbIwuqGk04qkbPsl2wH5/r+JXRtjDmVsFravzWjtyroT7IlifbsoZE= X-Gm-Gg: Acq92OEhxvnglBP0Bn0DWKjVsC/fXefB0Nomq/AQIrNONKPP0yQPUUm8pSUr4k11BWw 1Hqtow+whjMEcCtQ6SQ9Q6GYWtVSu/78D5inv9i0aH/BkLHlGlye6ZD24LwqieA+KL3rUOVstP1 Bq8/eW3GN5wSltuwAl5ihCTYIYnFgkqwrUwElD1KH5UhVZWvtjIcxUPDM7A0dlk3NNB76AkFXW2 dpyllex5aStoBuw//84Q6/r+Yy6QW6ZrwWh4uoOgMA7xduDF286+CNi8Ulb4qIZaltAJzmVRIEv 0ButcwpwQNxIykVd4znaaH1GL7SSdlO/MgTK4/U343jAhA0uTBYgl0tBsWJBrHAoBDhrKmEsYc9 3TtxoZEpmhSvT1iig5iGFW4ICYqX+Dl56LgkykZu0BKqqSAV6GXmFCdN5Hj/v5m4xsr3ZpvCxnY 51+dttWpz2gg== X-Received: by 2002:a05:6830:6405:b0:7dc:da80:42b4 with SMTP id 46e09a7af769-7e4fa0bdadfmr11428484a34.24.1779139673478; Mon, 18 May 2026 14:27:53 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:20 -0600 Subject: [PATCH v2 02/37] bsd-user: Rename cpu_env to env throughout bsd-user MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-2-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=23320; i=imp@bsdimp.com; h=from:subject:message-id; bh=z63KTGSsDuey0mWLBqZLlCemXH4jAVebG5j/pT3Mwmo=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGuPRARzxmYnzFfTRGm7XgE+ESOUIwexTK8 GD8G2XDryKJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AJqJEADB5UPnrcudjS6mejMaZmXh4Wi2A1bk6IeaNvMy6z9Jeme+MNP5mYRffqPyEo+Ix4KnLPQ YQktVk61SvNJ+oPPe/gMtBzsEhW3yhsTTv7z47He6CeS1EjIwGmSCQIgkpBtJgQ7ll1qDFyeeeG mM/q24Ak/5k06CCd/V3YdmMq2WynsOWeb+PO+Fi8pTsWSPnQflEVUIUjSMan42iczOUNLMPbrEB spwbjATcK5iQlYO2f5WhTWD7Xu7WjINRcSVG6gbQLxx3Zl2E141bFu0uYq5hFBZv/m1qMSHAxdL AG5tUC87Ws3j9BiUaWsARy2rAqgVpBi9tc5HBLdn1dHGutsBV2KaJAy5zTbYvnh1P2VvNjnwHpV qk0HfSBiLLTfbNRo51PaRGp+5PZsNO+BP47sqF/59ooe1Mq4YR4O887YK3h6Ldf9tg8bSf6jwjy aAeX+JaAUvlfZbH2SCH+sbEGhXkPJ6QSmgTJNKC8/Xt3E84yQGbCET7yEgkWKKbv3bK+gM5QSWM 1gphusAMoyeUBQh9bOWOe/fptyncM2qcXqU3TWb6xqXVv//nWWGmIn5JJYr168raTa9xNJYUeVr fSEULtj+QMzk8XcQlKq7qQVt21mU7Zvu9u89ZZ/tf/RAIS3mO2jz/YJgKdGWRkmey8EjGubrW3B BGLtON5k7+Y4zSg== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32e; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32e.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139758789154100 Replace 'void *cpu_env' parameters with 'CPUArchState *env' across all bsd-user source files. This improves type safety and aligns with the convention used in the rest of the codebase. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/aarch64/target.h | 2 +- bsd-user/arm/target.h | 2 +- bsd-user/bsd-file.h | 28 +++++++++++++-------------- bsd-user/bsd-mem.h | 4 ++-- bsd-user/bsd-proc.h | 6 +++--- bsd-user/freebsd/os-proc.c | 4 ++-- bsd-user/freebsd/os-proc.h | 26 ++++++++++++------------- bsd-user/freebsd/os-sys.c | 4 ++-- bsd-user/freebsd/os-syscall.c | 44 +++++++++++++++++++++------------------= ---- bsd-user/i386/target.h | 2 +- bsd-user/qemu.h | 6 +++--- bsd-user/riscv/target.h | 2 +- bsd-user/x86_64/target.h | 2 +- 13 files changed, 66 insertions(+), 66 deletions(-) diff --git a/bsd-user/aarch64/target.h b/bsd-user/aarch64/target.h index 702aeb7fc5..37b9817fe1 100644 --- a/bsd-user/aarch64/target.h +++ b/bsd-user/aarch64/target.h @@ -12,7 +12,7 @@ /* * aaarch64 ABI does not 'lump' the registers for 64-bit args. */ -static inline bool regpairs_aligned(void *cpu_env) +static inline bool regpairs_aligned(CPUArchState *env) { return false; } diff --git a/bsd-user/arm/target.h b/bsd-user/arm/target.h index 7c423ec575..cf131f29fb 100644 --- a/bsd-user/arm/target.h +++ b/bsd-user/arm/target.h @@ -12,7 +12,7 @@ /* * arm EABI 'lumps' the registers for 64-bit args. */ -static inline bool regpairs_aligned(void *cpu_env) +static inline bool regpairs_aligned(CPUArchState *env) { return true; } diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h index dca1518cb1..dec59bd80b 100644 --- a/bsd-user/bsd-file.h +++ b/bsd-user/bsd-file.h @@ -72,7 +72,7 @@ static abi_long do_bsd_read(abi_long arg1, abi_long arg2,= abi_long arg3) } =20 /* pread(2) */ -static abi_long do_bsd_pread(void *cpu_env, abi_long arg1, +static abi_long do_bsd_pread(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) { abi_long ret; @@ -82,7 +82,7 @@ static abi_long do_bsd_pread(void *cpu_env, abi_long arg1, if (p =3D=3D NULL) { return -TARGET_EFAULT; } - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg4 =3D arg5; arg5 =3D arg6; } @@ -109,14 +109,14 @@ static abi_long do_bsd_readv(abi_long arg1, abi_long = arg2, abi_long arg3) } =20 /* preadv(2) */ -static abi_long do_bsd_preadv(void *cpu_env, abi_long arg1, +static abi_long do_bsd_preadv(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) { abi_long ret; struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 1); =20 if (vec !=3D NULL) { - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg4 =3D arg5; arg5 =3D arg6; } @@ -151,7 +151,7 @@ static abi_long do_bsd_write(abi_long arg1, abi_long ar= g2, abi_long arg3) } =20 /* pwrite(2) */ -static abi_long do_bsd_pwrite(void *cpu_env, abi_long arg1, +static abi_long do_bsd_pwrite(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) { abi_long ret; @@ -161,7 +161,7 @@ static abi_long do_bsd_pwrite(void *cpu_env, abi_long a= rg1, if (p =3D=3D NULL) { return -TARGET_EFAULT; } - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg4 =3D arg5; arg5 =3D arg6; } @@ -188,14 +188,14 @@ static abi_long do_bsd_writev(abi_long arg1, abi_long= arg2, abi_long arg3) } =20 /* pwritev(2) */ -static abi_long do_bsd_pwritev(void *cpu_env, abi_long arg1, +static abi_long do_bsd_pwritev(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) { abi_long ret; struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); =20 if (vec !=3D NULL) { - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg4 =3D arg5; arg5 =3D arg6; } @@ -484,14 +484,14 @@ static abi_long do_bsd_dup2(abi_long arg1, abi_long a= rg2) } =20 /* truncate(2) */ -static abi_long do_bsd_truncate(void *cpu_env, abi_long arg1, +static abi_long do_bsd_truncate(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4) { abi_long ret; void *p; =20 LOCK_PATH(p, arg1); - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg2 =3D arg3; arg3 =3D arg4; } @@ -502,10 +502,10 @@ static abi_long do_bsd_truncate(void *cpu_env, abi_lo= ng arg1, } =20 /* ftruncate(2) */ -static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1, +static abi_long do_bsd_ftruncate(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4) { - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg2 =3D arg3; arg3 =3D arg4; } @@ -735,7 +735,7 @@ static abi_long do_bsd_freebsd11_mknodat(abi_long arg1,= abi_long arg2, } =20 /* post-ino64 mknodat(2) */ -static abi_long do_bsd_mknodat(void *cpu_env, abi_long arg1, +static abi_long do_bsd_mknodat(CPUArchState *env, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) { @@ -744,7 +744,7 @@ static abi_long do_bsd_mknodat(void *cpu_env, abi_long = arg1, =20 LOCK_PATH(p, arg2); /* 32-bit arch's use two 32 registers for 64 bit return value */ - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { ret =3D get_errno(mknodat(arg1, p, arg3, target_arg64(arg5, arg6))= ); } else { ret =3D get_errno(mknodat(arg1, p, arg3, target_arg64(arg4, arg5))= ); diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h index 9d7b60d3c3..3086143d40 100644 --- a/bsd-user/bsd-mem.h +++ b/bsd-user/bsd-mem.h @@ -51,11 +51,11 @@ extern abi_ulong target_brk; extern abi_ulong initial_target_brk; =20 /* mmap(2) */ -static inline abi_long do_bsd_mmap(void *cpu_env, abi_long arg1, abi_long = arg2, +static inline abi_long do_bsd_mmap(CPUArchState *env, abi_long arg1, abi_l= ong arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long a= rg7, abi_long arg8) { - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { arg6 =3D arg7; arg7 =3D arg8; } diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index b1d4446ff1..62052c70b9 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -6,8 +6,8 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 -#ifndef BSD_PROC_H_ -#define BSD_PROC_H_ +#ifndef BSD_PROC_H +#define BSD_PROC_H =20 #include =20 @@ -19,7 +19,7 @@ extern int _getlogin(char*, int); int bsd_get_ncpu(void); =20 /* exit(2) */ -static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) +static inline abi_long do_bsd_exit(CPUArchState *env, abi_long arg1) { gdb_exit(arg1); qemu_plugin_user_exit(); diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c index 0309036178..0a0cea5bb2 100644 --- a/bsd-user/freebsd/os-proc.c +++ b/bsd-user/freebsd/os-proc.c @@ -238,7 +238,7 @@ h2t_procctl_reaper_pidinfo(struct procctl_reaper_pidinf= o *host_pi, } =20 abi_long -do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong arg2, abi_ulong ar= g3, +do_freebsd_procctl(CPUArchState *env, int idtype, abi_ulong arg2, abi_ulon= g arg3, abi_ulong arg4, abi_ulong arg5, abi_ulong arg6) { abi_long error =3D 0, target_rp_pids; @@ -257,7 +257,7 @@ do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong= arg2, abi_ulong arg3, =20 #if TARGET_ABI_BITS =3D=3D 32 /* See if we need to align the register pairs. */ - if (regpairs_aligned(cpu_env)) { + if (regpairs_aligned(env)) { id =3D (id_t)target_arg64(arg3, arg4); target_cmd =3D (int)arg5; target_arg =3D arg6; diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index 72ccf23e17..fef6c03319 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -67,7 +67,7 @@ static inline abi_long do_freebsd_wait4(abi_long arg1, ab= i_ulong target_status, } =20 /* wait6(2) */ -static inline abi_long do_freebsd_wait6(void *cpu_env, abi_long idtype, +static inline abi_long do_freebsd_wait6(CPUArchState *env, abi_long idtype, abi_long id1, abi_long id2, abi_ulong target_status, abi_long options, abi_ulong target_wrusage, abi_ulong target_infop, abi_ulong pad1) @@ -78,7 +78,7 @@ static inline abi_long do_freebsd_wait6(void *cpu_env, ab= i_long idtype, siginfo_t info; void *p; =20 - if (regpairs_aligned(cpu_env) !=3D 0) { + if (regpairs_aligned(env) !=3D 0) { /* printf("shifting args\n"); */ /* 64-bit id is aligned, so shift all the arguments over by one */ id1 =3D id2; @@ -172,7 +172,7 @@ static inline abi_long do_freebsd___setugid(abi_long ar= g1) } =20 /* fork(2) */ -static inline abi_long do_freebsd_fork(void *cpu_env) +static inline abi_long do_freebsd_fork(CPUArchState *env) { abi_long ret; abi_ulong child_flag; @@ -182,7 +182,7 @@ static inline abi_long do_freebsd_fork(void *cpu_env) if (ret =3D=3D 0) { /* child */ child_flag =3D 1; - target_cpu_clone_regs(cpu_env, 0); + target_cpu_clone_regs(env, 0); } else { /* parent */ child_flag =3D 0; @@ -192,7 +192,7 @@ static inline abi_long do_freebsd_fork(void *cpu_env) * The fork system call sets a child flag in the second return * value: 0 for parent process, 1 for child process. */ - set_second_rval(cpu_env, child_flag); + set_second_rval(env, child_flag); =20 fork_end(ret); =20 @@ -200,13 +200,13 @@ static inline abi_long do_freebsd_fork(void *cpu_env) } =20 /* vfork(2) */ -static inline abi_long do_freebsd_vfork(void *cpu_env) +static inline abi_long do_freebsd_vfork(CPUArchState *env) { - return do_freebsd_fork(cpu_env); + return do_freebsd_fork(env); } =20 /* rfork(2) */ -static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) +static inline abi_long do_freebsd_rfork(CPUArchState *env, abi_long flags) { abi_long ret; abi_ulong child_flag; @@ -227,7 +227,7 @@ static inline abi_long do_freebsd_rfork(void *cpu_env, = abi_long flags) if (ret =3D=3D 0) { /* child */ child_flag =3D 1; - target_cpu_clone_regs(cpu_env, 0); + target_cpu_clone_regs(env, 0); } else { /* parent */ child_flag =3D 0; @@ -237,7 +237,7 @@ static inline abi_long do_freebsd_rfork(void *cpu_env, = abi_long flags) * The fork system call sets a child flag in the second return * value: 0 for parent process, 1 for child process. */ - set_second_rval(cpu_env, child_flag); + set_second_rval(env, child_flag); fork_end(ret); =20 return ret; @@ -245,7 +245,7 @@ static inline abi_long do_freebsd_rfork(void *cpu_env, = abi_long flags) } =20 /* pdfork(2) */ -static inline abi_long do_freebsd_pdfork(void *cpu_env, abi_ulong target_f= dp, +static inline abi_long do_freebsd_pdfork(CPUArchState *env, abi_ulong targ= et_fdp, abi_long flags) { abi_long ret; @@ -257,7 +257,7 @@ static inline abi_long do_freebsd_pdfork(void *cpu_env,= abi_ulong target_fdp, if (ret =3D=3D 0) { /* child */ child_flag =3D 1; - target_cpu_clone_regs(cpu_env, 0); + target_cpu_clone_regs(env, 0); } else { /* parent */ child_flag =3D 0; @@ -270,7 +270,7 @@ static inline abi_long do_freebsd_pdfork(void *cpu_env,= abi_ulong target_fdp, * The fork system call sets a child flag in the second return * value: 0 for parent process, 1 for child process. */ - set_second_rval(cpu_env, child_flag); + set_second_rval(env, child_flag); fork_end(ret); =20 return ret; diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index df31706558..d6f7c92420 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -593,7 +593,7 @@ out: } =20 /* sysarch() is architecture dependent. */ -abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) +abi_long do_freebsd_sysarch(CPUArchState *env, abi_long arg1, abi_long arg= 2) { - return do_freebsd_arch_sysarch(cpu_env, arg1, arg2); + return do_freebsd_arch_sysarch(env, arg1, arg2); } diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 90ef1bd916..d402c64726 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -215,7 +215,7 @@ void unlock_iovec(struct iovec *vec, abi_ulong target_a= ddr, /* * All errnos that freebsd_syscall() returns must be -TARGET_. */ -static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, +static abi_long freebsd_syscall(CPUArchState *env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg= 4, abi_long arg5, abi_long arg6, abi_long arg= 7, abi_long arg8) @@ -227,19 +227,19 @@ static abi_long freebsd_syscall(void *cpu_env, int nu= m, abi_long arg1, * process system calls */ case TARGET_FREEBSD_NR_fork: /* fork(2) */ - ret =3D do_freebsd_fork(cpu_env); + ret =3D do_freebsd_fork(env); break; =20 case TARGET_FREEBSD_NR_vfork: /* vfork(2) */ - ret =3D do_freebsd_vfork(cpu_env); + ret =3D do_freebsd_vfork(env); break; =20 case TARGET_FREEBSD_NR_rfork: /* rfork(2) */ - ret =3D do_freebsd_rfork(cpu_env, arg1); + ret =3D do_freebsd_rfork(env, arg1); break; =20 case TARGET_FREEBSD_NR_pdfork: /* pdfork(2) */ - ret =3D do_freebsd_pdfork(cpu_env, arg1, arg2); + ret =3D do_freebsd_pdfork(env, arg1, arg2); break; =20 case TARGET_FREEBSD_NR_execve: /* execve(2) */ @@ -255,12 +255,12 @@ static abi_long freebsd_syscall(void *cpu_env, int nu= m, abi_long arg1, break; =20 case TARGET_FREEBSD_NR_wait6: /* wait6(2) */ - ret =3D do_freebsd_wait6(cpu_env, arg1, arg2, arg3, + ret =3D do_freebsd_wait6(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); break; =20 case TARGET_FREEBSD_NR_exit: /* exit(2) */ - ret =3D do_bsd_exit(cpu_env, arg1); + ret =3D do_bsd_exit(env, arg1); break; =20 case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */ @@ -424,7 +424,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_procctl: /* procctl(2) */ - ret =3D do_freebsd_procctl(cpu_env, arg1, arg2, arg3, arg4, arg5, = arg6); + ret =3D do_freebsd_procctl(env, arg1, arg2, arg3, arg4, arg5, arg6= ); break; =20 /* @@ -435,7 +435,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_pread: /* pread(2) */ - ret =3D do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + ret =3D do_bsd_pread(env, arg1, arg2, arg3, arg4, arg5, arg6); break; =20 case TARGET_FREEBSD_NR_readv: /* readv(2) */ @@ -443,7 +443,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_preadv: /* preadv(2) */ - ret =3D do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + ret =3D do_bsd_preadv(env, arg1, arg2, arg3, arg4, arg5, arg6); break; =20 case TARGET_FREEBSD_NR_write: /* write(2) */ @@ -451,7 +451,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */ - ret =3D do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + ret =3D do_bsd_pwrite(env, arg1, arg2, arg3, arg4, arg5, arg6); break; =20 case TARGET_FREEBSD_NR_writev: /* writev(2) */ @@ -459,7 +459,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */ - ret =3D do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6= ); + ret =3D do_bsd_pwritev(env, arg1, arg2, arg3, arg4, arg5, arg6); break; =20 case TARGET_FREEBSD_NR_open: /* open(2) */ @@ -559,11 +559,11 @@ static abi_long freebsd_syscall(void *cpu_env, int nu= m, abi_long arg1, break; =20 case TARGET_FREEBSD_NR_truncate: /* truncate(2) */ - ret =3D do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4); + ret =3D do_bsd_truncate(env, arg1, arg2, arg3, arg4); break; =20 case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */ - ret =3D do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4); + ret =3D do_bsd_ftruncate(env, arg1, arg2, arg3, arg4); break; =20 case TARGET_FREEBSD_NR_acct: /* acct(2) */ @@ -595,7 +595,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_readlink: /* readlink(2) */ - ret =3D do_bsd_readlink(cpu_env, arg1, arg2, arg3); + ret =3D do_bsd_readlink(env, arg1, arg2, arg3); break; =20 case TARGET_FREEBSD_NR_readlinkat: /* readlinkat(2) */ @@ -627,7 +627,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, break; =20 case TARGET_FREEBSD_NR_mknodat: /* mknodat(2) */ - ret =3D do_bsd_mknodat(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6= ); + ret =3D do_bsd_mknodat(env, arg1, arg2, arg3, arg4, arg5, arg6); break; =20 case TARGET_FREEBSD_NR_chown: /* chown(2) */ @@ -807,7 +807,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, * Memory management system calls. */ case TARGET_FREEBSD_NR_mmap: /* mmap(2) */ - ret =3D do_bsd_mmap(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6, a= rg7, + ret =3D do_bsd_mmap(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); break; =20 @@ -953,15 +953,15 @@ static abi_long freebsd_syscall(void *cpu_env, int nu= m, abi_long arg1, * sys{ctl, arch, call} */ case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */ - ret =3D do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, a= rg6); + ret =3D do_freebsd_sysctl(env, arg1, arg2, arg3, arg4, arg5, arg6); break; =20 case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ - ret =3D do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, a= rg5, arg6); + ret =3D do_freebsd_sysctlbyname(env, arg1, arg2, arg3, arg4, arg5,= arg6); break; =20 case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ - ret =3D do_freebsd_sysarch(cpu_env, arg1, arg2); + ret =3D do_freebsd_sysarch(env, arg1, arg2); break; =20 default: @@ -979,7 +979,7 @@ static abi_long freebsd_syscall(void *cpu_env, int num,= abi_long arg1, * as a wrapper around freebsd_syscall() so that actually happens. Since * that is a singleton, modern compilers will inline it anyway... */ -abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, +abi_long do_freebsd_syscall(CPUArchState *env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, abi_long arg8) @@ -990,7 +990,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi= _long arg1, print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); } =20 - ret =3D freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, ar= g6, + ret =3D freebsd_syscall(env, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); if (do_strace) { print_freebsd_syscall_ret(num, ret); diff --git a/bsd-user/i386/target.h b/bsd-user/i386/target.h index ddd3b8ec08..9cd158fc11 100644 --- a/bsd-user/i386/target.h +++ b/bsd-user/i386/target.h @@ -12,7 +12,7 @@ /* * i386 doesn't 'lump' the registers for 64-bit args. */ -static inline bool regpairs_aligned(void *cpu_env) +static inline bool regpairs_aligned(CPUArchState *env) { return false; } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index b0b2c249fb..60d1adf560 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -176,7 +176,7 @@ abi_long memcpy_to_target(abi_ulong dest, const void *s= rc, void target_set_brk(abi_ulong new_brk); abi_long do_brk(abi_ulong new_brk); void syscall_init(void); -abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, +abi_long do_freebsd_syscall(CPUArchState *env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, abi_long arg8); @@ -238,7 +238,7 @@ int host_to_target_errno(int err); /* os-proc.c */ abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, abi_ulong guest_envp, int do_fexec); -abi_long do_freebsd_procctl(void *cpu_env, int idtype, abi_ulong arg2, +abi_long do_freebsd_procctl(CPUArchState *env, int idtype, abi_ulong arg2, abi_ulong arg3, abi_ulong arg4, abi_ulong arg5, abi_ulong arg6); =20 /* os-sys.c */ @@ -247,7 +247,7 @@ abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong= namep, int32_t namelen, abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); -abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2); +abi_long do_freebsd_sysarch(CPUArchState *env, abi_long arg1, abi_long arg= 2); =20 /* user access */ =20 diff --git a/bsd-user/riscv/target.h b/bsd-user/riscv/target.h index 036ddd185e..dc3e0be795 100644 --- a/bsd-user/riscv/target.h +++ b/bsd-user/riscv/target.h @@ -12,7 +12,7 @@ /* * riscv64 ABI does not 'lump' the registers for 64-bit args. */ -static inline bool regpairs_aligned(void *cpu_env) +static inline bool regpairs_aligned(CPUArchState *env) { return false; } diff --git a/bsd-user/x86_64/target.h b/bsd-user/x86_64/target.h index 0cf0e2a14a..fccfc593bd 100644 --- a/bsd-user/x86_64/target.h +++ b/bsd-user/x86_64/target.h @@ -12,7 +12,7 @@ /* * x86 doesn't 'lump' the registers for 64-bit args, all args are 64 bits. */ -static inline bool regpairs_aligned(void *cpu_env) +static inline bool regpairs_aligned(CPUArchState *env) { return false; } --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139713; cv=none; d=zohomail.com; s=zohoarc; b=jdTDwwMsI1TjgdkmzMbFGD0UcMLphzrezi+1oYYPbJXOAWAAqtXe2MKxRFtisKPhkYCCiDofXA+N4SrCiB8JrPevfKFCgG3utwdlwvW6bsbn980cFUleXwn5by4f58U7R3SrsgXY+dOVibb6Zf74KJ9aLEI2V49nDx0jYZ27dM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139713; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=doZWlcvFs6yrl3gyf9KMB/0Q6Da4SHxguQNEvyrWiV0=; b=oIp5g+rCkiQbg5H87CXZhGYFQLcz9R5ihoEDzNdojV1t6W+JYthn4YLvnCIhqUsPkWNCzkJBl/2xuH7V5clhvGhMVF0eY5325r1ylWQk5c5O29npidC57VssoyJcK5DqKXHzqpkqzd1oGGHeppJGzp19fZimauvy3UEaENISflU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139713497208.35147871497713; Mon, 18 May 2026 14:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VI-0000MV-08; Mon, 18 May 2026 17:28:00 -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 1wP5VG-0000Kx-0b for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:58 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VD-0000Pu-NN for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:57 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7dcdaf06498so1876579a34.2 for ; Mon, 18 May 2026 14:27:55 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139674; x=1779744474; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=doZWlcvFs6yrl3gyf9KMB/0Q6Da4SHxguQNEvyrWiV0=; b=evPBn6aTqxRSndkHi3jNgq3lQYYroiS3Ms+yek70Xi8ifEPJjyLAghvfvurQqluv+y x+ryvheIFvbzOesUeONy6XHSLBFVevNc4NgCukaXKQ08eQ6QjZlNAUWVyvTSS0Soqocj ujZ+UPCs20/ljr/qosi0Ujb2icIRzyFTq7jhu2J2C5L9ws1pa9Ck+n6m9q3qkrYuoP2p phlWaeLJY9RCH/8vodHoqZAsgBYOUJC3S0MUMctl5I0l24sWabf/inAiTAhTLLbctN22 kt+eS+5ocYtBPsRw/33XOBrt4pCtp/nWnDyC8mrvYp1YnQHTZYrHAMXoRb3t3qkcizhM A7fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139674; x=1779744474; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=doZWlcvFs6yrl3gyf9KMB/0Q6Da4SHxguQNEvyrWiV0=; b=XO7Eerf7PnixSKbwkpMpZKeJzRlETzsWex2wsExDO9WtMP+hKRj2tOkGKPYQSHDo1A spuDwm/wtpeKAcyQjOwADL62byWLST1DKmR6S+XXD8xECgJG14408d/J0bBpf8G9dXJo pJwgx3qR1H8dHsnNluhttD4La2yuEaa59+MC8hHXeTHLwIvk9oUurwRy5BYUt8Y+DU+m XTVlkNd1U/BA4xbHOW1JarczMXZPAaOIGuoHoiwzGyJkI+is8dGpzDAa/jpbnfcWkSBy 1eFDKhm0EEQWXLT56ahSBS7/4GWBi+zr5vkrIr4yGJPyzMQoFNMkW0n+i5qEVmaV0b/r MBoQ== X-Gm-Message-State: AOJu0Ywx8OxKRJumLrHUflPYxJ/rLjv4dxdgtXgBMzH4pyC7kRIHH5/N ulbP8PBMcyWAVcBVECYP9MzF+NVa2WP/6vggVfNSLGhS6UJeIWI/nrXVqrbLWqksp68= X-Gm-Gg: Acq92OE6zmJvUQS5BW/b5FGPenm/fe0AmmZZRrQGcKAW2vVzQHJUI6WPE3iUnW4hW2R QrbEXnPV9u3CFJ2H3ifP+qDoCdNFfz9cAe80wyjIx1KvrClMYf/6H3yxn/qVVZwSAEECcE1s8qG i8OqtX4eK9cFVw+4TxBFtwNu8RabWaBf2GNu48AUd60ktrXnuGT09EJBxelZJhwsopZvnZa7/qK IafVn7YG+s0JFntn8yx/uOY6HfV9nQkJuoVEnKwsQaoO3At7Hidn1iHq58ejzexbgdc+gYsI8Cm YM0HBL0WPlRIBsGE1N/qQk9K4UPovH1XNGrJ3CDgV1dzlni6QKRON6LyK2SYPoGawLzd1BIoSsY WdyZQ5/CBQ7U8hfhIn+5BKPWlc9MC5FSj1zjGSO6jBAMQTMZ4RKcxKL+tWZTqXSNapWiMssAGt2 X9n4olZ7L7XA== X-Received: by 2002:a05:6830:3c0e:b0:7dc:dd91:b5b1 with SMTP id 46e09a7af769-7e4ea032147mr11177962a34.5.1779139674589; Mon, 18 May 2026 14:27:54 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:21 -0600 Subject: [PATCH v2 03/37] bsd-user: Add bsd-signal.h with sigaction through sigreturn MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-3-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans , Jessica Clarke , =?utf-8?q?Mika=C3=ABl_Urankar?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=9451; i=imp@bsdimp.com; h=from:subject:message-id; bh=4+ns6JSAZOiGSFUyi3un+hWlDWcb4wxEsybCSx7hGBU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGagXnnjvd/GB4JEH4Z+aKe0o99SziCu4oJ ehujFoF7hGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR ANf/D/4rs/kHHpI2v91/FX6TQI8nZjwkIAv7KtVR4CKCrCULPy1hSM8AAOLPbd0AyscG7KUbNj+ a7nE3QySMqLc0IEM5+WawiA1lJ+iiiFrLBhWkYAN2qBQ2FUKEQy0OHuWAQdFuOs4vcR0ESPhC4C /pjoJSh3A690/e8U9LnXzhcdq0KmzdxoEDKfobrc62D+wIiJc4xLxkPHgiPwe0x0WE4opA+1GGB +OwU7kRULmkFttjQW973o5Uk/2VK2ex2shm/pU8noD8XpnngGbbnVnZ+jrGuawpYvM57MbWZzHW Ay6csWvpvzgVKcHbPmWsTJvGmwHQT7hrO4aM6cz2xLpuSWUZOCx1hSrX9EfEflTKwbmR1Vn3FwX /miCCt2XnBzEKl11HiP5MrPIQvFV+C/Refs5j64Nf5NlgYEZFB65juFHffdEqvNhhd6aCZscjED PVk1JWWW7/f8dl2tsCzEzegRdoGkDPBBWK6jR46H0obmmCetOBCz+vKY6azlZtCyLHxi9TAJSO1 /C6+6ujUqfXW0SGnIKOT1/gaMOELSg2LIdeMqXZPlSWY0kBYejoUhrEHM8gvsu0gA0aHdRqmv5+ QwrGUxYuVxMwE0yXEbY0JNoxrlJdYyrSUh2pdySG/y34hvyxEhs3b/jKgVvUlAYqieGgkQ7j4FA 082L4WzsRtaj0Rg== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32f; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32f.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139715651158500 Add the first set of signal-related system call shims: sigaction, sigprocmask, sigpending, sigsuspend, and sigreturn. Also add the do_sigprocmask and target_to_host_sigevent helper functions to signal.c and their declarations to signal-common.h. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Jessica Clarke Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/bsd-signal.h | 151 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 1 + bsd-user/signal-common.h | 4 ++ bsd-user/signal.c | 67 +++++++++++++++++++ 4 files changed, 223 insertions(+) diff --git a/bsd-user/bsd-signal.h b/bsd-user/bsd-signal.h new file mode 100644 index 0000000000..49e58d7436 --- /dev/null +++ b/bsd-user/bsd-signal.h @@ -0,0 +1,151 @@ +/* + * signal related system call shims + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef BSD_SIGNAL_H +#define BSD_SIGNAL_H + +#include + +/* sigaction(2) */ +static inline abi_long do_bsd_sigaction(abi_long arg1, abi_long arg2, + abi_long arg3) +{ + abi_long ret; + struct target_sigaction *old_act, act, oact, *pact; + + if (arg2) { + if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) { + return -TARGET_EFAULT; + } + act._sa_handler =3D old_act->_sa_handler; + act.sa_flags =3D old_act->sa_flags; + memcpy(&act.sa_mask, &old_act->sa_mask, sizeof(target_sigset_t)); + unlock_user_struct(old_act, arg2, 0); + pact =3D &act; + } else { + pact =3D NULL; + } + ret =3D get_errno(do_sigaction(arg1, pact, &oact)); + if (!is_error(ret) && arg3) { + if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) { + return -TARGET_EFAULT; + } + old_act->_sa_handler =3D oact._sa_handler; + old_act->sa_flags =3D oact.sa_flags; + memcpy(&old_act->sa_mask, &oact.sa_mask, sizeof(target_sigset_t)); + unlock_user_struct(old_act, arg3, 1); + } + return ret; +} + + +/* sigprocmask(2) */ +static inline abi_long do_bsd_sigprocmask(abi_long arg1, abi_ulong arg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + sigset_t set, oldset, *set_ptr; + int how; + + ret =3D 0; + if (arg2) { + p =3D lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&set, p); + unlock_user(p, arg2, 0); + set_ptr =3D &set; + switch (arg1) { + case TARGET_SIG_BLOCK: + how =3D SIG_BLOCK; + break; + case TARGET_SIG_UNBLOCK: + how =3D SIG_UNBLOCK; + break; + case TARGET_SIG_SETMASK: + how =3D SIG_SETMASK; + break; + default: + return -TARGET_EINVAL; + } + } else { + how =3D 0; + set_ptr =3D NULL; + } + ret =3D do_sigprocmask(how, set_ptr, &oldset); + if (!is_error(ret) && arg3) { + p =3D lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + host_to_target_sigset(p, &oldset); + unlock_user(p, arg3, sizeof(target_sigset_t)); + } + return ret; +} + +/* sigpending(2) */ +static inline abi_long do_bsd_sigpending(abi_long arg1) +{ + abi_long ret; + void *p; + sigset_t set; + + ret =3D get_errno(sigpending(&set)); + if (!is_error(ret)) { + p =3D lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + host_to_target_sigset(p, &set); + unlock_user(p, arg1, sizeof(target_sigset_t)); + } + return ret; +} + +/* sigsuspend(2) */ +static inline abi_long do_bsd_sigsuspend(CPUArchState *env, abi_long arg1, + abi_long arg2) +{ + CPUState *cpu =3D env_cpu(env); + TaskState *ts =3D cpu->opaque; + void *p; + abi_long ret; + + p =3D lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&ts->sigsuspend_mask, p); + unlock_user(p, arg1, 0); + + ret =3D get_errno(sigsuspend(&ts->sigsuspend_mask)); + /* XXX Trivially true until safe_syscall */ + if (ret !=3D -TARGET_ERESTART) { + ts->in_sigsuspend =3D true; + } + + return ret; +} + +/* sigreturn(2) */ +static inline abi_long do_bsd_sigreturn(CPUArchState *env, abi_long arg1) +{ + if (block_signals()) { + return -TARGET_ERESTART; + } + return do_sigreturn(env, arg1); +} + +/* sigvec(2) - not defined */ +/* sigblock(2) - not defined */ +/* sigsetmask(2) - not defined */ +/* sigstack(2) - not defined */ + +#endif /* BSD_SIGNAL_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index d402c64726..7fefdb569f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -38,6 +38,7 @@ #include "bsd-mem.h" #include "bsd-proc.h" #include "bsd-misc.h" +#include "bsd-signal.h" =20 /* BSD dependent syscall shims */ #include "os-stat.h" diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index 4e634e04a3..9071757873 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -32,6 +32,7 @@ int block_signals(void); /* Returns non zero if signal pe= nding */ long do_rt_sigreturn(CPUArchState *env); int do_sigaction(int sig, const struct target_sigaction *act, struct target_sigaction *oact); +int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset); abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong= sp); long do_sigreturn(CPUArchState *env, abi_ulong addr); void force_sig_fault(int sig, int code, abi_ulong addr); @@ -42,6 +43,9 @@ void process_pending_signals(CPUArchState *env); void queue_signal(CPUArchState *env, int sig, int si_type, target_siginfo_t *info); void signal_init(void); +abi_long target_to_host_sigevent(struct sigevent *host_sevp, + abi_ulong target_addr); +int target_to_host_signal(int sig); void target_to_host_sigset(sigset_t *d, const target_sigset_t *s); =20 /* diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 3e5e41e1b1..3f2f823051 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -346,6 +346,33 @@ int block_signals(void) return qatomic_xchg(&ts->signal_pending, 1); } =20 +abi_long target_to_host_sigevent(struct sigevent *host_sevp, + abi_ulong target_addr) +{ + struct target_sigevent *target_sevp; + + if (!lock_user_struct(VERIFY_READ, target_sevp, target_addr, 1)) { + return -TARGET_EFAULT; + } + + /* + * This union is awkward on 64 bit systems because it has a 32 bit + * integer and a pointer in it; we follow the conversion approach + * used for handling sigval types in signal.c so the guest should get + * the correct value back even if we did a 64 bit byteswap and it's + * using the 32 bit integer. + */ + host_sevp->sigev_value.sival_ptr =3D + (void *)(uintptr_t)target_sevp->sigev_value.sival_ptr; + host_sevp->sigev_signo =3D + target_to_host_signal(tswap32(target_sevp->sigev_signo)); + host_sevp->sigev_notify =3D tswap32(target_sevp->sigev_notify); + host_sevp->_sigev_un._threadid =3D tswap32(target_sevp->_sigev_un._thr= eadid); + + unlock_user_struct(target_sevp, target_addr, 0); + return 0; +} + /* Returns 1 if given signal should dump core if not handled. */ static int core_dump_signal(int sig) { @@ -725,6 +752,46 @@ int do_sigaction(int sig, const struct target_sigactio= n *act, return ret; } =20 +int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) +{ + TaskState *ts =3D get_task_state(thread_cpu); + + if (oldset) { + *oldset =3D ts->signal_mask; + } + + if (set) { + int i; + + if (block_signals()) { + return -TARGET_ERESTART; + } + + switch (how) { + case SIG_BLOCK: + sigorset(&ts->signal_mask, &ts->signal_mask, set); + break; + case SIG_UNBLOCK: + for (i =3D 1; i <=3D NSIG; ++i) { + if (sigismember(set, i)) { + sigdelset(&ts->signal_mask, i); + } + } + break; + case SIG_SETMASK: + ts->signal_mask =3D *set; + break; + default: + g_assert_not_reached(); + } + + /* Silently ignore attempts to change blocking status of KILL or S= TOP */ + sigdelset(&ts->signal_mask, SIGKILL); + sigdelset(&ts->signal_mask, SIGSTOP); + } + return 0; +} + static inline abi_ulong get_sigframe(struct target_sigaction *ka, CPUArchState *env, size_t frame_size) { --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139830; cv=none; d=zohomail.com; s=zohoarc; b=jH18tdY6KyDlrIt7RZwCGPee1b1DKrY24Fl1AeaT8kvAYtw7pPT8dVCgYeEw2Es3UUCnIbWcNCd0qOrof+EHD8aSRbIGztn5ra1AXghv4J6fYgbP1Lmitso75vPuqI0pBvPrL9/SWqeEBoMSK1OSlTlzm1Fh1GzwTPiQZlLcBao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139830; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UcX93/bsPzSGtEWzCQDxEM4bepZUbVT03Usa9qIq4yg=; b=FoA/v+NMlVAoXBd1QpxUnUYv3SGVjlktlszFEGAyBscKPUfUgN1OBT37n5MVS6LqIu2U4aup30EUc0IB/5p4asIsRMyMseAS9agufza7FkuGdJiBvNbv4+aqaezOWE0lIsheK6fQDhA5eZF29dyYxDw5ENx/JlkzjnFS7IplUHg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139830608280.3523759399244; Mon, 18 May 2026 14:30:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VJ-0000Mc-FH; Mon, 18 May 2026 17:28:01 -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 1wP5VH-0000LZ-Au for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:59 -0400 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VF-0000Q5-Db for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:59 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7df05fc49e5so2995760a34.3 for ; Mon, 18 May 2026 14:27:57 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139675; x=1779744475; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UcX93/bsPzSGtEWzCQDxEM4bepZUbVT03Usa9qIq4yg=; b=CbxuMFXslcvp8mMx+PGAZmr9DMfEfU0Na5N/WDEUyOXbt4qc0krUo5sUCsX8VWJgqz zR/NDSv1ZOcHBMon7fS0UNZwcoABIEyz65CxHEIxhCplupJMfubtYpbGiR/cX6fc6Tnv PH5XrvfCRBabKVRcix33taY0s/rTfzbLV1rG4oX5IAtt7BYQEnfp8mOT6GM4hsBf6A1N vj6EsLfnZpHWQ5g3Q7hqiKHJTqtTNIvmIPsz4N92FwLiFGij3nSkxAyjUfnPmCrhiXpH /ePXsKrfXVqFR7XD6OBqTWiH/fiW5AernjtV/rwSE/rnVVeFX1yHBVOh3Bg8FVCIeE5/ kyQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139675; x=1779744475; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=UcX93/bsPzSGtEWzCQDxEM4bepZUbVT03Usa9qIq4yg=; b=AgfZiKM52x7lJsf6BkDSDR9c8CJDRNpBDEVBsaNJhbOpIkG0tqIwMIbDafVBSsd1ec weSkoKJj5Azox//ssLHaa0JSE0eZ8yneRgJ4P6LqHshKdhPOXvxvOral0IZBO/OTjpxI rS2O5PbJ4euTn8wn8r5tZm+KTjqXHMQGhLNJcSGFvddbLxhOZTleavhsywzPzv9NSSLj 6e2mEM/JUTTBJD+Z3U5tZcvgxC4WDW9WRU/mIrLGlufnMbaHTNZ7h2CCDPUL/TBt8acV 2OLKdAX2pbV8FXta5KEQTvqaLir1d7WNWBGgFBdVgPZPYPzDscn5UYjS1ut3QECtEsSL 84Sw== X-Gm-Message-State: AOJu0YzBdxr9Un+fZeNefZK2gF+PKwD3tuym5PXoBZWdEHuyW/bGONEj M9dThVBH07eIct8i+IJlG2ZIPwL2x4v4Gf+KRll4XlqhqchM+fDdje0hOmMmY6Ypw2k= X-Gm-Gg: Acq92OHZv3UOo5MtbKPLGUXEKbYj+8YtvfZUrjNgx8LIEDM011JaMU6Wjt1FHwXHaBF yjdKIIrDs3zgN/hfk6f8n5uiU10TIBELD/LWd4HUkSdABG9tdIAldJBkzx1EQU51Qrm9ChQ2zHd B5/2cOuiS7spVWCafs8ovqyUb6dkcuSohn8HB6CFfDnu0397806iHy0cc505aPxCdLwx6B35H7+ dAjWbi+WwBk5i38XJG0cs3SKOFhU7Enql5belQZyRlX1Pvt8nhAsHhQAkli0mqJGXAL3w6NitK6 QiDrvnZgkxZxBbvlWn5d3a5l/lDpoqy7gCU2iHhKkdZL8worRGNSEtq7Q9o/yyLppX+KZ0m2gzN L7XUWwVEmD7FSAiOM+vupkCYpYiknkkwLCDItDu3HMtpQnnOoWejHbH5S3pJIyfQ/jJh2Rr3Y/R eKDoYzVYbCHg== X-Received: by 2002:a05:6830:82ec:b0:7dc:5899:c711 with SMTP id 46e09a7af769-7e4ea06e807mr12552515a34.3.1779139675580; Mon, 18 May 2026 14:27:55 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:22 -0600 Subject: [PATCH v2 04/37] bsd-user: Add signal shims sigwait through kill and os-signal.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-4-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3843; i=imp@bsdimp.com; h=from:subject:message-id; bh=N1BQ+ZOiFjKjIFi+9oZiikyUY80Tcc3sfec9pgHMLJc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGhXbsCm06+k/ykljUHlkaUFVcb8P1iF0jL x4yO/XImoyJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AJQJD/wLPtpV2fXNpBVKj4kMaE6iAwNAA97SqVihoulelAybWHGkS1SUu+/F5FdGcrm/cS+laJt SSyq8gnsbMB76kvGw211kou+r+XJFHObWzlJogWEj/985LqnmTYBYiaPzwA2R4KGsFSVvPNg5ph tK9o8OBllma1SgMDj6ZIcI/w2YMbgUQbwUbQthitxrZ4Rgd879CsrmA3EsalGaM+A8hwsrd7ueW iwp98AgqqtmPflTn3a00kqlLRugMDlhvniabUuuIN+UDezRJKXlIoUzDdAxWBmb9a4HXb+2jwOr qZyYtMnCH16VQuW3Xo4OO2rHdq7wIkDzAMa6RhW390jgTaCNeJ7kN9kE8eLJTfkVwaqW/JurL8v 2wWZkx2Lo7PEk/4MlO3YlVT/BVsgQubgp0ZTrAPlae2NELKWLXYf3HUQwVxZYJQa1ZatbsapPIJ wKyrha9PAqjw3U67W3TzpWy7EeJ6tAYwia4sA6s1omAQz4aNm5SSXTp1/UE0hCj+nTjamH6Ck5K RwSKBtkdBoshivvIa7x4Rh8DK7I4SxZ9cCZKqXRXec3aQu69rjP72/Fet110BVjnvdyglQJq2vF 4XoMLkhPTUmhB5ha3M522LrBHCnaNwwLTxnviVSdcjXmbAjLNQZEFwIjox4cHdgdPv58ODy8t1C KWg/CyAzfzYeOyw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32a; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32a.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139831893158500 Complete bsd-signal.h with sigwait, sigwaitinfo, sigqueue, sigaltstack, kill, and killpg. Add FreeBSD-specific os-signal.h with pdkill. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/bsd-signal.h | 80 ++++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-signal.h | 20 +++++++++++ 2 files changed, 100 insertions(+) diff --git a/bsd-user/bsd-signal.h b/bsd-user/bsd-signal.h index 49e58d7436..09c5b30913 100644 --- a/bsd-user/bsd-signal.h +++ b/bsd-user/bsd-signal.h @@ -148,4 +148,84 @@ static inline abi_long do_bsd_sigreturn(CPUArchState *= env, abi_long arg1) /* sigsetmask(2) - not defined */ /* sigstack(2) - not defined */ =20 +/* sigwait(2) */ +static inline abi_long do_bsd_sigwait(abi_ulong arg1, abi_ulong arg2, + abi_long arg3) +{ + abi_long ret; + void *p; + sigset_t set; + int sig; + + p =3D lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&set, p); + unlock_user(p, arg1, 0); + ret =3D get_errno(sigwait(&set, &sig)); + if (!is_error(ret) && arg2) { + ret =3D put_user_s32(sig, arg2); + } + return ret; +} + +/* sigwaitinfo(2) */ +static inline abi_long do_bsd_sigwaitinfo(abi_ulong arg1, abi_ulong arg2) +{ + abi_long ret; + void *p; + sigset_t set; + siginfo_t uinfo; + + p =3D lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&set, p); + unlock_user(p, arg1, 0); + ret =3D get_errno(sigwaitinfo(&set, &uinfo)); + if (!is_error(ret) && arg2) { + p =3D lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t), 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + host_to_target_siginfo(p, &uinfo); + unlock_user(p, arg2, sizeof(target_siginfo_t)); + } + return ret; +} + +/* sigqueue(2) */ +static inline abi_long do_bsd_sigqueue(abi_long arg1, abi_long arg2, + abi_ulong arg3) +{ + union sigval value; + target_sigval_t *tvalue =3D (target_sigval_t *)&arg3; + abi_ulong sival_ptr; + + __get_user(sival_ptr, &tvalue->sival_ptr); + value.sival_ptr =3D (void *)(uintptr_t)sival_ptr; + return get_errno(sigqueue(arg1, target_to_host_signal(arg2), value)); +} + +/* sigaltstck(2) */ +static inline abi_long do_bsd_sigaltstack(CPUArchState *env, abi_ulong arg= 1, + abi_ulong arg2) +{ + return do_sigaltstack(arg1, arg2, get_sp_from_cpustate(env)); +} + +/* kill(2) */ +static inline abi_long do_bsd_kill(abi_long pid, abi_long sig) +{ + return get_errno(kill(pid, target_to_host_signal(sig))); +} + +/* killpg(2) */ +static inline abi_long do_bsd_killpg(abi_long pg, abi_long sig) +{ + return get_errno(killpg(pg, target_to_host_signal(sig))); +} + #endif /* BSD_SIGNAL_H */ diff --git a/bsd-user/freebsd/os-signal.h b/bsd-user/freebsd/os-signal.h new file mode 100644 index 0000000000..fe102c33e4 --- /dev/null +++ b/bsd-user/freebsd/os-signal.h @@ -0,0 +1,20 @@ +/* + * FreeBSD signal system call shims + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef FREEBSD_OS_SIGNAL_H +#define FREEBSD_OS_SIGNAL_H + +#include + +/* pdkill(2) */ +static inline abi_long do_freebsd_pdkill(abi_long arg1, abi_long arg2) +{ + + return get_errno(pdkill(arg1, target_to_host_signal(arg2))); +} + +#endif /* FREEBSD_OS_SIGNAL_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139735; cv=none; d=zohomail.com; s=zohoarc; b=dZEjETVzTHyZGokjAD8RqElZNby10PidKAb+8EBwNoCpCZSaY1krnzx0fJAniLwnUgLnnnANBsihTZFdPW0ssYXgEHR/wv9PUJ5hrfjinO0Vj+okfjJpAXFMSf3gZMFVf6ccfkbbiJtv328n475f+zLcFrL1omj1F/hhbwZfTMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139735; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cVEDxJOr7kvxcvFimTX8HDuVyK0o5vQxB8bQI0dGqCI=; b=El3T6e2N4EJkSJkAPGWflywe8HEZOdCYjudbaLkaRVGULQzEbPKunNb/H71l0pJhjqxAxxoj/bsnPZHeFa1/AOmmICGBBeevWNrpFVw5etShEOzklXzZVYc8wF5gW4Q3wbKqaX/Gc5w0JSaVgAV6s815134mpqmnr40RDrWqfA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139735853361.2782427070772; Mon, 18 May 2026 14:28:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VM-0000OM-B8; Mon, 18 May 2026 17:28:04 -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 1wP5VH-0000Le-Dy for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:59 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VF-0000Qc-Uw for qemu-devel@nongnu.org; Mon, 18 May 2026 17:27:59 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7d4c383f2fcso2793362a34.0 for ; Mon, 18 May 2026 14:27:57 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139677; x=1779744477; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cVEDxJOr7kvxcvFimTX8HDuVyK0o5vQxB8bQI0dGqCI=; b=mbkBHW/gm0juVP4P6ssRFaWDFYC/inFTvYWVrL0RO8Oxh3BrMVvU58TzcGpjdD3/xg fWfCjUkRed1GrjGwOP1PwHAF+W2ncsxvxyWxUNC9TVVZrHWCPPyVpErdA8igFSvvYPAG h9gom46AuVdhv/kHG2ag67+VLt/4sWdalA55Fsxs0+3rdAed76gn1j1tp4SkEGJ64ZUq 9Tkq6E1XkbPwV6Bgn4xAFzsI1YDP/cdrDmMjmKkVpCIBuztvrB0woEa9q6be66fdOMsr nMbIEparz15VGss7zeonBnekcfr2wI0+kbikHolzVQBji2ZUjuauW4R2uhgOTOKy5GEF 8I7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139677; x=1779744477; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=cVEDxJOr7kvxcvFimTX8HDuVyK0o5vQxB8bQI0dGqCI=; b=dBrsrctnNPN5xLZdwNACZrlm7tU05fqc2I3BX7cPqdnG4SeGamH/pCT7fVpWvoGtAW w7teLRxn2XJQS9U9cUcbtc+qACqQQQv4DiTPOYvYsJjHUITPkfBLrCdkEQTJhJiUHHM4 V6bmGdJzHB23vxtv/5OULfDe/bUPCw/hHLHcfy+fZpn2UvvOBa4EaE+zcP0jn0/hqEwU zX7DyXfOjr9RYOrcUkcaDvCJ7geWji2s2/ux0pI23X5N533P6dCK7fl37ERjY6u19q4v 4CKTDs1qg72hop0p4DI9Oppu6xGp0zfz01+nM0LCP2d8VCEHuEKYC2SRJEeYIaBqZ1Yn nSBw== X-Gm-Message-State: AOJu0YxoVCQ7wJR6NHPrSfLCHnf3dHcPz64lMTw13JCzw/ld7F27Me/+ 6pPBrsQAkfWQ33eoldG+RUqgb7UCwAC8d1MO3mHOfSdWg1bu+CDxmBSXhgVO9tnQ0BQ= X-Gm-Gg: Acq92OGJvVtY3SeooRkss9FH1fzeRg4b3Xz6mWJ7Luroukf9lgeZE6dfmRKd0ad+tYg XfwNy0z0VtL5OI6Mux9Gb9Xxhtbl6s3T47aeCMGpH/I3mAn/vNtTFs/zdOQIwpVcbUOYswCCBDx 3ngzzD3b2XgbMvs223or7C7Hl3Ay58tbtta6PhGguRuJZDlYehR3g8m17srCK7MxPZ8Wmez+6kE /i/2J9AvZC16P6zXfk38fEaBDOoGAVMXw3aqKmTdXj3MDGJKuRR3ITVZ9/CcvUO1LzXqa2U/F2R +adzhSXTtztJc2969qRFviKVHbu/JgupVst1+FxS2LekwgGM3RPor3CLxlVsOTXYYig19CkfFBF qL5h99ZQqu0hWVHn19eelXwdWqQeRxhHeD2S6dNngE4j5MrkZedNXfFhT37wviR5t6EB9oxXWTo ewjl9l/T3Mdg== X-Received: by 2002:a05:6830:6515:b0:7dc:d2ad:fb29 with SMTP id 46e09a7af769-7e4fa057c32mr11434429a34.24.1779139676779; Mon, 18 May 2026 14:27:56 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:23 -0600 Subject: [PATCH v2 05/37] bsd-user: Add signal system call dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-5-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2548; i=imp@bsdimp.com; h=from:subject:message-id; bh=kb4jsRODtuqp7BLyHoI4sYGmHuDVkUj+ukniTVK6Zrg=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGpR0i4uLSHQRkaq0XOGd13s9s1f529QQcD lcNl1NVmlOJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR ALXGEACJbJ6lsyNoogXF1bLLzHQD3fpob7Ef7OdJVivIcFxg+csV/FXkYmfjojLvVm6z9x+xntT MF1llzEGV/Ye6NQU8BIJqlNf33ooNnB97X4SRHnOaNkt3VxKMtnWIOUUnbHmAyfBLFuy2X5hfgO Xs2s8RuQGjyiWwLSAnTaFEd/wRKNmVLtMOLwWSRxEMhDTzu9DJmzqDMMFcSE6fTal69xXjiIXq5 pKxiSSMKDHqj1Ujb9T5r2YbbM9baNjxHb/p3caOVLs1KEIfDr4E19U/uJOOIIQ2yIz3EuF+7yBj PPNzHPAq/YpGo5V9cY3NxyK3iy7JxHVE/ncUKwA1Ks0FV4tiaWRL4me1an+ZQ6hmyYYbAr2l2fg s4E838S6iDRN6vEDGtVBLXxiBSWsQezGKkVPnpYqbpIWH5EBy6JO2szobtxb/TsgfzhBP+5IxR+ T2FVkC11WfE+4omGz62kpxauSTEqpuYQZ8A6X4G5DOdb59moTBXjEurCBDw+JfRVMzaStsKqNeM VKaFjz+TnEejPmxSvVrR9jeyLqWQhGjltBBrKDc+wbOukHLqAkipJNPcwJG0Ww1tqe9ZOs4yftQ QDchz+JuByOKm7iOYUJBd4anWxhs7HQHnsEB9yLOGJxaYerzVoadftxP4luSWrzzEhkAJMg2TlE 9tJcGgX5HEYlydA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32f; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32f.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139737163158500 Wire up the signal-related system calls in the FreeBSD syscall dispatcher: sigaction, sigprocmask, sigpending, sigsuspend, sigreturn, sigwait, sigwaitinfo, sigqueue, sigaltstack, kill, and pdkill. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-syscall.c | 48 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 48 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7fefdb569f..06148fe3ce 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -43,6 +43,7 @@ /* BSD dependent syscall shims */ #include "os-stat.h" #include "os-proc.h" +#include "os-signal.h" #include "os-misc.h" =20 /* I/O */ @@ -950,6 +951,53 @@ static abi_long freebsd_syscall(CPUArchState *env, int= num, abi_long arg1, ret =3D do_bsd_getdtablesize(); break; =20 + /* + * signal system calls + */ + case TARGET_FREEBSD_NR_sigaction: /* sigaction(2) */ + ret =3D do_bsd_sigaction(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_sigprocmask: /* sigprocmask(2) */ + ret =3D do_bsd_sigprocmask(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_sigpending: /* sigpending(2) */ + ret =3D do_bsd_sigpending(arg1); + break; + + case TARGET_FREEBSD_NR_sigsuspend: /* sigsuspend(2) */ + ret =3D do_bsd_sigsuspend(env, arg1, arg2); + break; + + case TARGET_FREEBSD_NR_sigreturn: /* sigreturn(2) */ + ret =3D do_bsd_sigreturn(env, arg1); + break; + + case TARGET_FREEBSD_NR_sigwait: /* sigwait(2) */ + ret =3D do_bsd_sigwait(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_sigwaitinfo: /* sigwaitinfo(2) */ + ret =3D do_bsd_sigwaitinfo(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_sigqueue: /* sigqueue(2) */ + ret =3D do_bsd_sigqueue(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_sigaltstack: /* sigaltstack(2) */ + ret =3D do_bsd_sigaltstack(env, arg1, arg2); + break; + + case TARGET_FREEBSD_NR_kill: /* kill(2) */ + ret =3D do_bsd_kill(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_pdkill: /* pdkill(2) */ + ret =3D do_freebsd_pdkill(arg1, arg2); + break; + /* * sys{ctl, arch, call} */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139896; cv=none; d=zohomail.com; s=zohoarc; b=hJBwx59nO2ri60U8a8YIDpIOuFssQINl+YbsN7iAVGpMAway/BGJNVqAJfg5/lQZhaOXxf4y5/vbujZXsaplbmncuTncBLyN/dU94CVZRIXCmUCiel/mzZ68HBFOTDKEXlxz6QQhom58BLNNJfDdIs4v1SYZVq0hdkQTkiuf/dY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139896; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GZJKrvGvmoh3Z0h4Tj8bSMp6OmJceu4fQaKo2fvtPoU=; b=jLn7BFahldtfEwyVbJkQUkpNFXc6Gxt/f6YIJ0VEG6cH3xzyxjayjZ41hn9kC+7RFKmi64Tkdh1IjNZGp5llBKv6hmvnbT87Iy5N3blVQEBOJxvWgIrDlZjYMdXvBg9varmVkY5kha/1lLM7Bq/MpiJdejyEzBSw9boaMattOoI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139896746499.86719598191155; Mon, 18 May 2026 14:31:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VK-0000NO-Rt; Mon, 18 May 2026 17:28:02 -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 1wP5VK-0000ND-5T for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:02 -0400 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VH-0000Qv-6d for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:01 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7dcd17e19b6so1523156a34.1 for ; Mon, 18 May 2026 14:27:58 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139678; x=1779744478; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=GZJKrvGvmoh3Z0h4Tj8bSMp6OmJceu4fQaKo2fvtPoU=; b=Kno3lZUWMVmsPAnZQ9bmj0pnqx7d+2j6dWzKcRgdLvCAhHWIJOclDoe/C8TzFzQN5b itedT+V8jc9oqjdV3nvs0LW6du6R1jqe5z1Q/sxOOOUYaHIDWPQhvh+XOMpMpVlAwwwU Gl+TbJQdTE04mIuVRzpw1OiSnZ+6s4kV4dXsT2DhzNwpmPkJS5W+Zy195h64JD1hxhGz lAIS6+Lv0fOY7TNyUOsNwRIQRZYPlvB3+nHzChS59R9JhoUDLMTEXZYLqnHjTigEbKII Y66IexnqE2t+cwblEHxN4wbQ0ja2OLwAyhinQni7FlDE85klBugXKbd2Nvu1HcUS+hC0 n/5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139678; x=1779744478; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=GZJKrvGvmoh3Z0h4Tj8bSMp6OmJceu4fQaKo2fvtPoU=; b=eQhoERsA9PGRK7Wt/L0h1dlcpkMfwA56BaICUHpSql2DIAs+JEBk+5ytEEoe//2JCC /NWmLjSXm5+wJsRNHyEL6hiH2MZfMrNdn3UqQK2FzmbAKvnxCMQcgTMndjDiWBXEORTe j/5o6am7E6nLIxHbHeQvZ+3FnBw5sSe6XEVn4+o77KEk9Lrna9+PXwsMRsP4epk+fJ6O 1TCEVjwjfgbnowSpvnvlUYws9eQabVko2GqiOymXVdeeJ+QYDxhyOKq0aygu6aw3du0v 1mjL/9MmFAgjrazhqZQeRMu/CgTxEV0r7XfEOcaqgq9WlF83rQ/53RRVV3HHusPYBqMx yHRg== X-Gm-Message-State: AOJu0Yy4ObbJXPFOLHkxNv3KYMilFhw+HEJnQrPrM6L30+VgFxd3oSCU NZE9xgwZkeMUOpelwZ9pt/YftX/HzvXbU8IGQUosO3F/QWUAvETPHAF+wA0yh8h/EW8= X-Gm-Gg: Acq92OFhyIycWByiuAQgK7fNv/NeMyGzoY84iuH5Pc/vGeI0kYhLLhV/TyWkJeesaiH E+5DAWelQEiq2btXBXc7idroJwa0AQpwsyyFZSlil2WnkTV3EKM6VjMK60YzDJypukUfRTlCzOE DABoyiPjoeURqMq7kXHDKA0qFGdYy8OfeIfDE3lIbMx4E9SbOCt0KwCSmEbSqiE3TdsTQXkhwY6 BOUvD0AlwQKa+di4zXH0ui9ls5pTjVbyQnhJOfD3/32zcnbygNd/ZZnNtGCnN6whjawY3JU7D/x zmnbc4r2jmqR7DmOvDKijlFvcXWjbqQhx2F5Op6e/+FsjI31o3uFTaUe0raXNGpgBIt2wnuYAr4 XF/DOWClp+GvgJ+6Kt8F4DtgQ+ykNc51h8B9G/W52So3LAymr98lpIHcVEg71tqJF+XjgbVWUoZ mBTXh4GHSBFDlFPJT90RGnSoD9/TywWpA= X-Received: by 2002:a05:6830:2b10:b0:7dc:dd58:50c7 with SMTP id 46e09a7af769-7e4fa05515bmr12117707a34.18.1779139677825; Mon, 18 May 2026 14:27:57 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:24 -0600 Subject: [PATCH v2 06/37] bsd-user: Add poll, lseek, pipe, and swap system call shims MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-6-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=22776; i=imp@bsdimp.com; h=from:subject:message-id; bh=hUNdFuSlQwlBNp0LTbIKejA8PoWYPc3Mrxw5hMM4IAg=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGreuBr3G3DJg3z9usZ+c/V1/sPLnhVYpQf Mq5QXEVAumJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AGYQEADfriQG5bQwzpw5PqSGa0bq0LXaSTXw9cZazVuUs/mMuHoFhMdlrYaThXib5MWCLyhRTEE akmJ1XftWe8mLDifC0oqqK+NospVm3GYHkpfA/W7d+wJDSSYdNNrbyzIBWsQxIlE1GXvnzawUVg ny1Tz5EGpPafZCXYrRzTTwOEsTHMn3pF3foIkcHOzIBCbVAcd0rgvnQjtLlIcHLyFkRombJq/Gl ogIg1JQ9GU5BAiRqUE0InCIymt43mdsunp6bJx4NNrlmXJQbjIGTrub8sw6f85Uj0W0eyYSqiyb v283mpm/9Bfpz3oND3/lQbTsaVYMxvQNNhq7cjCUN4rkmU7OGibhzqanOYrzF1cdjxwTpZGQ1wn MJEGu5AsHJKsq+hhNg6Fldey710Bq9/aw+zdWAcgDacCevtFIy6DWWrWZd3b6MwJJbrprd5GCw0 ZRM/QHr0ijxynwhHalTIeY01DKo9LZ/PXA/INMqkYv6E0n8k6Qn9GqT8w+HsGWMC9HwWbXZu1Wu HiS4JxKyK1+m8e6aV+fTCfQ4Ehh0fvXJ398uWj7ZwL9IqZZnc2A7wH/VE4Zx5vRfKLfA2QK/mP2 tTVj72JlGCUBrtkqv5Y7wQzOHnTyuBy+YkL84p2yEFcWGzg+McuLL0OrSz4tbeVhJ0hgkiICEBU B32VqiJWIx0C8Bw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::331; envelope-from=imp@bsdimp.com; helo=mail-ot1-x331.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139897484154100 Add do_bsd_poll, do_bsd_lseek, do_bsd_pipe, do_bsd_swapon, do_freebsd13_swapoff, and do_bsd_swapoff to bsd-file.h. Also add target_pollfd structure to syscall_defs.h and include poll.h in os-syscall.c. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/bsd-file.h | 136 +++++++++++++ bsd-user/freebsd/os-syscall.c | 1 + bsd-user/syscall_defs.h | 458 ++++++++++++++++++++++++++++++++++++--= ---- 3 files changed, 534 insertions(+), 61 deletions(-) diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h index dec59bd80b..c5636aff6f 100644 --- a/bsd-user/bsd-file.h +++ b/bsd-user/bsd-file.h @@ -55,6 +55,10 @@ ssize_t safe_pwrite(int fd, void *buf, size_t nbytes, of= f_t offset); ssize_t safe_writev(int fd, const struct iovec *iov, int iovcnt); ssize_t safe_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t of= fset); =20 +int safe_ppoll(struct pollfd *fds, nfds_t nfds, + const struct timespec *restrict timeout, + const sigset_t *restrict newsigmask); + /* read(2) */ static abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) { @@ -925,4 +929,136 @@ static abi_long do_bsd_undelete(abi_long arg1) return ret; } =20 +/* poll(2) */ +static abi_long do_bsd_poll(abi_long arg1, abi_long arg2, abi_long arg3) +{ + abi_long ret; + nfds_t i, nfds =3D arg2; + int timeout =3D arg3; + struct pollfd *pfd; + struct target_pollfd *target_pfd; + struct timespec ts, *pts =3D NULL; + + target_pfd =3D lock_user(VERIFY_WRITE, arg1, + sizeof(struct target_pollfd) * nfds, 1); + if (!target_pfd) { + return -TARGET_EFAULT; + } + pfd =3D alloca(sizeof(struct pollfd) * nfds); + for (i =3D 0; i < nfds; i++) { + pfd[i].fd =3D tswap32(target_pfd[i].fd); + pfd[i].events =3D tswap16(target_pfd[i].events); + } + + if (timeout !=3D INFTIM) { + ts.tv_sec =3D timeout / 1000; + ts.tv_nsec =3D (timeout % 1000) * 1000000; + pts =3D &ts; + } + + ret =3D get_errno(safe_ppoll(pfd, nfds, pts, NULL)); + + if (!is_error(ret)) { + for (i =3D 0; i < nfds; i++) { + target_pfd[i].revents =3D tswap16(pfd[i].revents); + } + } + unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds); + + return ret; +} + +/* lseek(2) */ +static abi_long do_bsd_lseek(CPUArchState *env, abi_long arg1, abi_long ar= g2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + abi_long ret; +#if TARGET_ABI_BITS =3D=3D 32 + int64_t res; + + /* 32-bit arch's use two 32 registers for 64 bit return value */ + if (regpairs_aligned(env) !=3D 0) { + res =3D lseek(arg1, target_arg64(arg3, arg4), arg5); + } else { + res =3D lseek(arg1, target_arg64(arg2, arg3), arg4); + } + if (res =3D=3D -1) { + ret =3D get_errno(res); + set_second_rval(env, 0xFFFFFFFF); + } else { +#ifdef TARGET_BIG_ENDIAN + ret =3D ((res >> 32) & 0xFFFFFFFF); + set_second_rval(env, res & 0xFFFFFFFF); +#else + ret =3D res & 0xFFFFFFFF; + set_second_rval(env, (res >> 32) & 0xFFFFFFFF); +#endif + } +#else + ret =3D get_errno(lseek(arg1, arg2, arg3)); +#endif + return ret; +} + +/* pipe(2) */ +static abi_long do_bsd_pipe(CPUArchState *env, abi_ulong pipedes) +{ + abi_long ret; + int host_pipe[2]; + int host_ret =3D pipe(host_pipe); + + if (host_ret !=3D -1) { + set_second_rval(env, host_pipe[1]); + ret =3D host_pipe[0]; + } else { + ret =3D get_errno(host_ret); + } + return ret; +} + +/* swapon(2) */ +static abi_long do_bsd_swapon(abi_long arg1) +{ + abi_long ret; + void *p; + + LOCK_PATH(p, arg1); + ret =3D get_errno(swapon(path(p))); + UNLOCK_PATH(p, arg1); + + return ret; +} + +#ifdef TARGET_FREEBSD_NR_freebsd13_swapoff +/* swapoff(2) */ +static abi_long do_freebsd13_swapoff(abi_long arg1) +{ + abi_long ret; + void *p; + + LOCK_PATH(p, arg1); + ret =3D get_errno(swapoff(path(p), 0)); + UNLOCK_PATH(p, arg1); + + return ret; +} +#endif + +/* swapoff(2) */ +static abi_long do_bsd_swapoff(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + + LOCK_PATH(p, arg1); +#ifdef TARGET_FREEBSD_NR_freebsd13_swapoff + ret =3D get_errno(swapoff(path(p), arg2)); +#else + ret =3D get_errno(swapoff(path(p))); +#endif + UNLOCK_PATH(p, arg1); + + return ret; +} + #endif /* BSD_FILE_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 06148fe3ce..fc6273a780 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -26,6 +26,7 @@ #include #include #include +#include =20 #include "include/gdbstub/syscalls.h" =20 diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 0612be8bbb..833c7509e3 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -42,26 +42,6 @@ struct target_ipc_perm { #define TARGET_IPC_SET 1 /* set options */ #define TARGET_IPC_STAT 2 /* get options */ =20 -/* - * sys/shm.h - */ -struct target_shmid_ds { - struct target_ipc_perm shm_perm; /* peration permission structure */ - abi_ulong shm_segsz; /* size of segment in bytes */ - int32_t shm_lpid; /* process ID of last shared memory op */ - int32_t shm_cpid; /* process ID of creator */ - int32_t shm_nattch; /* number of current attaches */ - target_time_t shm_atime; /* time of last shmat() */ - target_time_t shm_dtime; /* time of last shmdt() */ - target_time_t shm_ctime; /* time of last change by shmctl() */ -}; - -#define N_BSD_SHM_REGIONS 32 -struct bsd_shm_regions { - abi_long start; - abi_long size; -}; - /* * sys/sem.h */ @@ -93,6 +73,26 @@ struct target_semid_ds { target_time_t sem_ctime; /* times measured in secs */ }; =20 +/* + * sys/shm.h + */ +struct target_shmid_ds { + struct target_ipc_perm shm_perm; /* peration permission structure */ + abi_ulong shm_segsz; /* size of segment in bytes */ + int32_t shm_lpid; /* process ID of last shared memory op */ + int32_t shm_cpid; /* process ID of creator */ + int32_t shm_nattch; /* number of current attaches */ + target_time_t shm_atime; /* time of last shmat() */ + target_time_t shm_dtime; /* time of last shmdt() */ + target_time_t shm_ctime; /* time of last change by shmctl() */ +}; + +#define N_BSD_SHM_REGIONS 32 +struct bsd_shm_regions { + abi_long start; + abi_long size; +}; + /* * sys/msg.h */ @@ -118,23 +118,26 @@ struct target_msgbuf { char mtext[1]; /* body of message */ }; =20 +/* + * sched.h + */ +struct target_sched_param { + int32_t sched_priority; +}; + /* * sys/mman.h */ #define TARGET_MADV_DONTNEED 4 /* dont need these pages */ =20 -#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplement= ed */ - /* MAP_INHERIT */ -#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemente= d */ - /* MAP_NOEXTEND */ -#define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like= a */ - /* stack */ -#define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync= */ - /* underlying file */ +#define MAP_TYPE 0xf =20 +/* XXX These are needed by mmap.c until it is updated to match blitz */ +#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 +#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 +#define TARGET_FREEBSD_MAP_STACK 0x0400 +#define TARGET_FREEBSD_MAP_NOSYNC 0x0800 #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7 - -/* XXX */ #define TARGET_BSD_MAP_FLAGMASK 0x3ff7 =20 /* @@ -142,8 +145,6 @@ struct target_msgbuf { * sys/timex.h */ =20 -typedef abi_long target_freebsd_suseconds_t; - /* compare to sys/timespec.h */ struct target_freebsd_timespec { target_time_t tv_sec; /* seconds */ @@ -165,12 +166,75 @@ struct target_freebsd__umtx_time { =20 struct target_freebsd_timeval { target_time_t tv_sec; /* seconds */ - target_freebsd_suseconds_t tv_usec;/* and microseconds */ + target_suseconds_t tv_usec;/* and microseconds */ #if !defined(TARGET_I386) && TARGET_ABI_BITS =3D=3D 32 abi_long _pad; #endif }; =20 +/* compare to sys/timex.h */ +struct target_freebsd_ntptimeval { + struct target_freebsd_timespec time; + abi_long maxerror; + abi_long esterror; + abi_long tai; + int32_t time_state; +}; + +struct target_freebsd_itimerspec { + struct target_freebsd_timespec it_interval; + struct target_freebsd_timespec it_value; +}; + +struct target_freebsd_timex { + uint32_t modes; + abi_long offset; + abi_long freq; + abi_long maxerror; + abi_long esterror; + int32_t status; + abi_long constant; + abi_long precision; + abi_long tolerance; + + abi_long ppsfreq; + abi_long jitter; + int32_t shift; + abi_long stabil; + abi_long jitcnt; + abi_long calcnt; + abi_long errcnt; + abi_long stbcnt; +}; + +/* Maxiumum of 32 active POSIX timers allowed at any one time. */ +extern int g_posix_timers[32]; + +#define TIMER_MAGIC 0x0caf0000 +#define TIMER_MAGIC_MASK 0xffff0000 + +/* + * 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 */ @@ -219,6 +283,154 @@ struct target_freebsd__wrusage { struct target_freebsd_rusage wru_children; }; =20 +/* + * sys/socket.h + */ + +/* + * Types + */ +#define TARGET_SOCK_STREAM 1 /* stream socket */ +#define TARGET_SOCK_DGRAM 2 /* datagram socket */ +#define TARGET_SOCK_RAW 3 /* raw-protocol interface */ +#define TARGET_SOCK_RDM 4 /* reliably-delivered message */ +#define TARGET_SOCK_SEQPACKET 5 /* sequenced packet stream */ + + +/* + * Option flags per-socket. + */ + +#define TARGET_SO_DEBUG 0x0001 /* turn on debugging info recordin= g */ +#define TARGET_SO_ACCEPTCONN 0x0002 /* socket has had listen() */ +#define TARGET_SO_REUSEADDR 0x0004 /* allow local address reuse */ +#define TARGET_SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define TARGET_SO_DONTROUTE 0x0010 /* just use interface addresses */ +#define TARGET_SO_BROADCAST 0x0020 /* permit sending of broadcast msg= s */ +#define TARGET_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ +#define TARGET_SO_LINGER 0x0080 /* linger on close if data present= */ +#define TARGET_SO_OOBINLINE 0x0100 /* leave received OOB data in line= */ +#define TARGET_SO_REUSEPORT 0x0200 /* allow local address & port reus= e */ +#define TARGET_SO_TIMESTAMP 0x0400 /* timestamp received dgram traffi= c */ +#define TARGET_SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */ +#define TARGET_SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ +#define TARGET_SO_BINTIME 0x2000 /* timestamp received dgram traffi= c */ +#define TARGET_SO_NO_OFFLOAD 0x4000 /* socket cannot be offloaded */ +#define TARGET_SO_NO_DDP 0x8000 /* disable direct data placement */ + +/* + * Additional options, not kept in so_options. + */ +#define TARGET_SO_SNDBUF 0x1001 /* send buffer size */ +#define TARGET_SO_RCVBUF 0x1002 /* receive buffer size */ +#define TARGET_SO_SNDLOWAT 0x1003 /* send low-water mark */ +#define TARGET_SO_RCVLOWAT 0x1004 /* receive low-water mark */ +#define TARGET_SO_SNDTIMEO 0x1005 /* send timeout */ +#define TARGET_SO_RCVTIMEO 0x1006 /* receive timeout */ +#define TARGET_SO_ERROR 0x1007 /* get error status and clear */ +#define TARGET_SO_TYPE 0x1008 /* get socket type */ +#define TARGET_SO_LABEL 0x1009 /* socket's MAC label */ +#define TARGET_SO_PEERLABEL 0x1010 /* socket's peer's MAC label */ +#define TARGET_SO_LISTENQLIMIT 0x1011 /* socket's backlog limit */ +#define TARGET_SO_LISTENQLEN 0x1012 /* socket's complete queue length = */ +#define TARGET_SO_LISTENINCQLEN 0x1013 /* socket's incomplete queue lengt= h */ +#define TARGET_SO_SETFIB 0x1014 /* use this FIB to route */ +#define TARGET_SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */ +#define TARGET_SO_PROTOCOL 0x1016 /* get socket protocol (Linux name= ) */ + +/* alias for SO_PROTOCOL (SunOS name) */ +#define TARGET_SO_PROTOTYPE TARGET_SO_PROTOCOL + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define TARGET_SOL_SOCKET 0xffff /* options for socket level */ + +#ifndef CMSG_ALIGN +#define CMSG_ALIGN(len) (((len) + sizeof(long) - 1) & ~(sizeof(long) - 1)) +#endif + +/* + * sys/socket.h + */ +struct target_msghdr { + abi_long msg_name; /* Socket name */ + int32_t msg_namelen; /* Length of name */ + abi_long msg_iov; /* Data blocks */ + int32_t msg_iovlen; /* Number of blocks */ + abi_long msg_control; /* Per protocol magic (eg BSD fd passing) = */ + int32_t msg_controllen; /* Length of cmsg list */ + int32_t msg_flags; /* flags on received message */ +}; + +struct target_sockaddr { + uint8_t sa_len; + uint8_t sa_family; + uint8_t sa_data[14]; +} QEMU_PACKED; + +struct target_in_addr { + uint32_t s_addr; /* big endian */ +}; + +struct target_cmsghdr { + uint32_t cmsg_len; + int32_t cmsg_level; + int32_t cmsg_type; +}; + +/* + * mips32 is the exception to the general rule of long-alignment; it + * unconditionally uses 64-bit alignment instead. + */ +#if defined(TARGET_MIPS) && TARGET_ABI_BITS =3D=3D 32 +#define TARGET_ALIGNBYTES (sizeof(abi_llong) - 1) +#else +#define TARGET_ALIGNBYTES (sizeof(abi_long) - 1) +#endif + +#define TARGET_CMSG_NXTHDR(mhdr, cmsg, cmsg_start) \ + __target_cmsg_nxthdr(mhdr, cmsg, cmsg_start) +#define TARGET_CMSG_ALIGN(len) (((len) + TARGET_ALIGNBYTES) \ + & (size_t) ~TARGET_ALIGNBYTES) +#define TARGET_CMSG_DATA(cmsg) \ + ((unsigned char *)(cmsg) + TARGET_CMSG_ALIGN(sizeof(struct target_cmsg= hdr))) +#define TARGET_CMSG_SPACE(len) \ + (TARGET_CMSG_ALIGN(sizeof(struct target_cmsghdr)) + TARGET_CMSG_ALIGN(= len)) +#define TARGET_CMSG_LEN(len) \ + (TARGET_CMSG_ALIGN(sizeof(struct target_cmsghdr)) + (len)) + +static inline struct target_cmsghdr * +__target_cmsg_nxthdr(struct target_msghdr *__mhdr, + struct target_cmsghdr *__cmsg, + struct target_cmsghdr *__cmsg_start) +{ + struct target_cmsghdr *__ptr; + + __ptr =3D (struct target_cmsghdr *)((unsigned char *) __cmsg + + TARGET_CMSG_ALIGN(tswap32(__cmsg->cmsg_len))); + if ((unsigned long)((char *)(__ptr + 1) - (char *)__cmsg_start) > + tswap32(__mhdr->msg_controllen)) { + /* No more entries. */ + return (struct target_cmsghdr *)0; + } + return __ptr; +} + +/* + * netinet/in.h + */ +struct target_ip_mreq { + struct target_in_addr imr_multiaddr; + struct target_in_addr imr_interface; +}; + +struct target_ip_mreqn { + struct target_in_addr imr_multiaddr; + struct target_in_addr imr_address; + int32_t imr_ifindex; +}; + /* * sys/stat.h */ @@ -434,6 +646,152 @@ struct target_freebsd_flock { /* user: vfork(2) semantics, clear signals */ #define TARGET_RFSPAWN (1U << 31) =20 +/* sys/specialfd.h */ +enum target_specialfd_type { + TARGET_SPECIALFD_EVENT =3D 1, +}; + +struct target_specialfd_eventfd { + unsigned int initval; + int flags; +}; + +/* + * FreeBSD thread and user mutex support. + */ + +/* sys/thr.h */ +#define TARGET_THR_SUSPENDED 0x0001 +#define TARGET_THR_SYSTEM_SCOPE 0x0002 + +struct target_freebsd_thr_param { + abi_ulong start_func; /* thread entry function. */ + abi_ulong arg; /* argument for entry function. */ + abi_ulong stack_base; /* stack base address. */ + abi_ulong stack_size; /* stack size. */ + abi_ulong tls_base; /* tls base address. */ + abi_ulong tls_size; /* tls size. */ + abi_ulong child_tid; /* address to store new TID. */ + abi_ulong parent_tid; /* parent access the new TID here. */ + int32_t flags; /* thread flags. */ + abi_ulong rtp; /* Real-time scheduling priority. */ + abi_ulong spare[3]; /* spares. */ +}; + +/* sys/rtprio.h */ +struct target_freebsd_rtprio { + uint16_t type; + uint16_t prio; +}; + +typedef struct { + CPUArchState *env; + long parent_tid; + pthread_mutex_t mutex; + pthread_cond_t cond; + pthread_t thread; + sigset_t sigmask; + struct target_freebsd_thr_param param; +} new_freebsd_thread_info_t; + +/* sys/utmx.h */ +/* op code for _umtx_op */ +#define TARGET_UMTX_OP_LOCK 0 +#define TARGET_UMTX_OP_UNLOCK 1 +#define TARGET_UMTX_OP_WAIT 2 +#define TARGET_UMTX_OP_WAKE 3 +#define TARGET_UMTX_OP_MUTEX_TRYLOCK 4 +#define TARGET_UMTX_OP_MUTEX_LOCK 5 +#define TARGET_UMTX_OP_MUTEX_UNLOCK 6 +#define TARGET_UMTX_OP_SET_CEILING 7 +#define TARGET_UMTX_OP_CV_WAIT 8 +#define TARGET_UMTX_OP_CV_SIGNAL 9 +#define TARGET_UMTX_OP_CV_BROADCAST 10 +#define TARGET_UMTX_OP_WAIT_UINT 11 +#define TARGET_UMTX_OP_RW_RDLOCK 12 +#define TARGET_UMTX_OP_RW_WRLOCK 13 +#define TARGET_UMTX_OP_RW_UNLOCK 14 +#define TARGET_UMTX_OP_WAIT_UINT_PRIVATE 15 +#define TARGET_UMTX_OP_WAKE_PRIVATE 16 +#define TARGET_UMTX_OP_MUTEX_WAIT 17 +#define TARGET_UMTX_OP_MUTEX_WAKE 18 +#define TARGET_UMTX_OP_SEM_WAIT 19 +#define TARGET_UMTX_OP_SEM_WAKE 20 +#define TARGET_UMTX_OP_NWAKE_PRIVATE 21 +#define TARGET_UMTX_OP_MUTEX_WAKE2 22 +#define TARGET_UMTX_OP_SEM2_WAIT 23 +#define TARGET_UMTX_OP_SEM2_WAKE 24 +#define TARGET_UMTX_OP_SHM 25 +#define TARGET_UMTX_OP_ROBUST_LISTS 26 + +/* flags for UMTX_OP_CV_WAIT */ +#define TARGET_CVWAIT_CHECK_UNPARKING 0x01 +#define TARGET_CVWAIT_ABSTIME 0x02 +#define TARGET_CVWAIT_CLOCKID 0x04 + +#define TARGET_UMTX_UNOWNED 0x0 +#define TARGET_UMUTEX_UNOWNED 0x0 +#define TARGET_UMTX_CONTESTED (abi_ulong)(-1) +#define TARGET_UMUTEX_CONTESTED 0x80000000U + +/* flags for umutex */ +#define TARGET_UMUTEX_ERROR_CHECK 0x0002 /* Error-checking mutex */ +#define TARGET_UMUTEX_PRIO_INHERIT 0x0004 /* Priority inherited mutex */ +#define TARGET_UMUTEX_PRIO_PROTECT 0x0008 /* Priority protect mutex */ + +#define TARGET_UMUTEX_TRY 1 +#define TARGET_UMUTEX_WAIT 2 + +/* urwlock flags */ +#define TARGET_URWLOCK_PREFER_READER 0x0002 +#define TARGET_URWLOCK_WRITE_OWNER 0x80000000U +#define TARGET_URWLOCK_WRITE_WAITERS 0x40000000U +#define TARGET_URWLOCK_READ_WAITERS 0x20000000U +#define TARGET_URWLOCK_MAX_READERS 0x1fffffffU +#define TARGET_URWLOCK_READER_COUNT(c) ((c) & TARGET_URWLOCK_MAX_READERS) + +/* + * sys/acl.h + */ +#define TARGET_FREEBSD_ACL_MAX_ENTRIES 254 + +/* vaild acl_type_t arguments */ +#define TARGET_FREEBSD_ACL_TYPE_ACCESS_OLD 0x00000000 +#define TARGET_FREEBSD_ACL_TYPE_DEFAULT_OLD 0x00000001 +#define TARGET_FREEBSD_ACL_TYPE_ACCESS 0x00000002 +#define TARGET_FREEBSD_ACL_TYPE_DEFAULT 0x00000003 +#define TARGET_FREEBSD_ACL_TYPE_NFS4 0x00000004 + +struct target_freebsd_acl_entry { + uint32_t ae_tag; + uint32_t ae_id; + uint32_t ae_perm; + uint16_t ae_entry_type; + uint16_t ae_flags; +}; + +struct target_freebsd_acl { + uint32_t acl_maxcnt; + uint32_t acl_cnt; + int32_t acl_spare[4]; + struct target_freebsd_acl_entry acl_entry[TARGET_FREEBSD_ACL_MAX_ENTR= IES]; +}; + +/* + * sys/uuid.h + */ + +#define TARGET_UUID_NODE_LEN 6 + +struct target_uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[TARGET_UUID_NODE_LEN]; +}; + /* * from sys/procctl.h */ @@ -475,21 +833,6 @@ struct target_procctl_reaper_kill { uint32_t rk_pad0[15]; }; =20 -/* - * sys/uuid.h - */ -#define TARGET_UUID_NODE_LEN 6 - -struct target_uuid { - uint32_t time_low; - uint16_t time_mid; - uint16_t time_hi_and_version; - uint8_t clock_seq_hi_and_reserved; - uint8_t clock_seq_low; - uint8_t node[TARGET_UUID_NODE_LEN]; -}; - - #define safe_syscall0(type, name) \ type safe_##name(void) \ { \ @@ -537,22 +880,15 @@ type safe_##name(type1 arg1, type2 arg2, type3 arg3, = type4 arg4, \ return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \ } =20 -/* - * sys/socket.h - */ -struct target_sockaddr { - uint8_t sa_len; - uint8_t sa_family; - uint8_t sa_data[14]; -} QEMU_PACKED; - -struct target_in_addr { - uint32_t s_addr; /* big endian */ -}; - #define safe_ioctl(...) safe_syscall(SYS_ioctl, __VA_ARGS__) #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__) =20 +struct target_pollfd { + int32_t fd; /* file descriptor */ + int16_t events; /* requested events */ + int16_t revents; /* returned events */ +}; + /* So far all target and host bitmasks are the same */ #undef target_to_host_bitmask #define target_to_host_bitmask(x, tbl) (x) --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139713; cv=none; d=zohomail.com; s=zohoarc; b=KAb/wc6DXfNwwzep0ryf9JHYzo2gPX7hf9VNXm2RxmgO1pDPf3fWZsCkN0vW9oaCtd50NlPVlnIgXHDPWcrSM+ESjZbwqdI42A35MfWRmvEFrYvoHEB1SfIzjeugZy1FhLhoEvWf13gDlBZyhbesS9918vYHh1kn517L66cwWjY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139713; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=enfB29ZT++A6esf/xt68p8+6rURzXiv6x7129bGT2E8=; b=n1n46I1qVtzWoocBaBa5k0yt2xas0U1zvcdKkH451suha5yiW62ERFWQoBF8b93pSScugAnnNYNfRZOHdbBT6p4Oxev0YVWltnCrqcED9vbwV575HIWFjOOfWdnUKregRi5BYGLH/m+bbWnWHSQMzPiaYF8rw6oxtzEtlNdZGks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139713304560.1783451555209; Mon, 18 May 2026 14:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VL-0000Nr-UJ; Mon, 18 May 2026 17:28:03 -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 1wP5VJ-0000N5-Rn for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:01 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VI-0000RR-6U for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:01 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7de46b8e432so3023516a34.1 for ; Mon, 18 May 2026 14:27:59 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139679; x=1779744479; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=enfB29ZT++A6esf/xt68p8+6rURzXiv6x7129bGT2E8=; b=R9QTpCqzRajqK7zwItB/FObMrkFgrd0cjNub/v9mE0SkaP13M+pLOCH+yNd6Ms10QC y/TqkBnqYVS4wiSQS+3Fzyxwe4xEF9ymz3T2WZ/xa/RmxS9VEt0PgpizOSPMycutowCf EppVw2LyHXytxUxXRZQKXtR08AKxEOx8UZGgaJoq3qkA7FIcA0AgMu7ztMgjMSJ6nsBn f+mfAEHLMDdN6U/9YLDrmgvPSqf4/7B0xDEv9iAr965Pe6/DTJMqsljCi9EUfS5qNCxt sWT2jULPP9G3/0GIzO8sLh7vAdzBqZjme+mFDBeboBXFi2cXPMLp8bDhPnvsUhLTvP7N aEKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139679; x=1779744479; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=enfB29ZT++A6esf/xt68p8+6rURzXiv6x7129bGT2E8=; b=mjAHhXrTRUFihP10nhUP6C4CA83vKYXcol7ps7eyVCNRHjQqt9+Z5ltbCkkF/fUWAn tOjvzubqQvHvvlGGvXYRTQrcE7h2sweNk2vvC7g6KNsfni1C88qqeQXovnm5neurPwJZ Y2JrOaIHWmsTkx5D5LHxAz5yPCo0rMjBeytPm5ChTa4Ywuqo32615/8EJoKxkysf4tRh XwQ32fynyznZ3yKqMtslAQA0y2ujeXNyDBkgku3vof4z70ArzecxO1GgsJDMf3AINAvI 4UtRgAVoW5kHDJVvl0e6GdzZHwgj3n3vqcGlzgw7WreCbxatPdD3odH8q5blp+elfhKx o9Uw== X-Gm-Message-State: AOJu0Ywxa95iwOl/f+fiMffZAg70CwxfEi9J3zs4Ojdqdrt+p6QRl3oy q3S97yXiLUMiHrhZ3sWIQnrHTWOZR/MgnXameV3qOJWFv8vk5qOtl/HO7gOCwBruKTs= X-Gm-Gg: Acq92OF7fF+AXE3EnzJQQfc2zt0zHwH59iZvo7vNqjQRfh7TFFbB3CDkGG/4HQ6gY95 pkMrjxRTxYjVsIbAKbBwpBQ0Jc71vr8ITKBmUCzERn8CEq+LMgndcgV94nNZIBESorhl1rOYSsB hwt/rx/5BvmP8Hbh4e/52iwnJHyck74MTKkjGiApZIrb/re+dyshmJks/+hA7jwzrnZXXIdkayk UFVoZ5q4VnMHO3IYmwYGIvJ3IYH0ZKNfeqgLvdPxGNEgksaErZUNijqF7At7AFs4pfcE22Bho9d xxk3SIZqQfKNDDVpK7YLSBodFXlfs3G/zmoElpS3FX5iFZKS97bRltsBUYZuBzaZvL6ykClOdKw kmTJQSEpOI/C/cM3O/58XS5HGKidJTqdpvOI4akX4qy084aCUswZ/JKN0z5Q/728Ejy3kpIQEQx jZmA1O+0+T+g== X-Received: by 2002:a05:6830:3491:b0:7dc:d2ad:fb17 with SMTP id 46e09a7af769-7e4f2badcfbmr11158504a34.20.1779139678870; Mon, 18 May 2026 14:27:58 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:25 -0600 Subject: [PATCH v2 07/37] bsd-user: Add os-file.h with pipe2, chflagsat, close_range, and more MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-7-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5320; i=imp@bsdimp.com; h=from:subject:message-id; bh=Ozt5eWI3K63GhGf+oDsW6s0bMNMzgP0Gg1AeLwpTn9U=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGKfvaPLObdPFwn3rFrp73epRUZR4KMJYVA CTGPfYrxR2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AJ0DD/95LW4NmHTXhy3BbB6n0CZWMuecq2jOdAtaRy2arUuR1wTp+ovzMWLjOrYcQtkVIlq21Am /kcAi6yNvPqNXKtPqYw7jLvM3QceWobtJQ6N+Ece2hxf+NP+EFwxtkxkUM2XCJjdPs9umv6AJOF MxEndTiozzbBiDMNvKoUtHS6BEjmna61UFUemvZscCGkH5Mjr/CpkIIZfvtJ0OJuygV2Ciq3Bgz I/m0ODpOoe/TcJyGx68UpEJksYI9xmPLg4DA8XBaYRLlG1SmEJhVLj34iOmP4y9pXGlWwuOnAs1 /g08rpR7cqGmuUPvo6KvhJGnKOiAxRX+Fv3M7g2JUZ8bQoosR4VHtxM0bB2RInAfdQFe/LhyNGo v3Ix1qe0pen0Rnc6OJAmm6V1btXc88tiDuLrc7tLVVdbNH5qoLu+pgdjlOJ+IQsCPRJtHg8x/rn zGVDI0KIuXflTfq0MtMNfDnywItg7PI/e9K/mbPWyx1OYGY8V01GjOEkArOJ4jb0ocV+JWKBVvg bunx0QpjboYQ/haPIxuzXcp17JnulgbUM6HJ3/ahTgRrwqqZpFuhYEE+5UtJxbdJ2ktI/4t+SMV LZyfWeSJ7BNW7iOWlw79+Kxm4SPr53punC59sT88g+1B71jgWXSGidf5idlAiA3qpmb5zw3Tn6w N4AqVo2Sqjod7mw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::333; envelope-from=imp@bsdimp.com; helo=mail-ot1-x333.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139716244154100 Add FreeBSD-specific file operation shims: pipe2, chflagsat, close_range, copy_file_range, and __specialfd. Also add the safe_copy_file_range and safe_ppoll syscall wrappers and the target_specialfd_eventfd type definitions. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-file.h | 129 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 7 +++ 2 files changed, 136 insertions(+) diff --git a/bsd-user/freebsd/os-file.h b/bsd-user/freebsd/os-file.h new file mode 100644 index 0000000000..c1da52789a --- /dev/null +++ b/bsd-user/freebsd/os-file.h @@ -0,0 +1,129 @@ +/* + * FreeBSD file related system call shims and definitions + * + * Copyright (c) 2014 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef FREEBSD_OS_FILE_H +#define FREEBSD_OS_FILE_H + +#include + +/* + * Asynchronous I/O. + */ + +/* pipe2(2) */ +static abi_long do_bsd_pipe2(CPUArchState *env, abi_ulong pipedes, int fla= gs) +{ + int host_pipe[2]; + int host_ret =3D pipe2(host_pipe, flags); + /* XXXss - flags should be translated from target to host. */ + + if (host_ret =3D=3D -1) { + return get_errno(host_ret); + } + + /* + * pipe2() returns it's second FD by copying it back to userspace and = not in + * a second register like pipe(2): set_second_rval(env, host_pipe[1]); + * + * Copy the FD's back to userspace: + */ + if (put_user_s32(host_pipe[0], pipedes) || + put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0]))) { + close(host_pipe[0]); + close(host_pipe[1]); + return -TARGET_EFAULT; + } + return 0; +} + +/* chflagsat(2) */ +static inline abi_long do_bsd_chflagsat(int fd, abi_ulong path, + abi_ulong flags, int atflags) +{ + abi_long ret; + void *p; + + LOCK_PATH(p, path); + ret =3D get_errno(chflagsat(fd, p, flags, atflags)); /* XXX path(p)? */ + UNLOCK_PATH(p, path); + + return ret; +} + +/* close_range(2) */ +static inline abi_long do_freebsd_close_range(unsigned int lowfd, + unsigned int highfd, int flags) +{ + + return get_errno(close_range(lowfd, highfd, flags)); +} + +ssize_t safe_copy_file_range(int, off_t *, int, off_t *, size_t, unsigned = int); + +/* copy_file_range(2) */ +static inline abi_long do_freebsd_copy_file_range(int infd, + abi_ulong inofftp, int outfd, abi_ulong outofftp, size_t len, + unsigned int flags) +{ + off_t inoff, outoff, *inp, *outp; + abi_long ret; + + inp =3D outp =3D NULL; + if (inofftp !=3D 0 && !access_ok(VERIFY_WRITE, inofftp, sizeof(off_t))= ) { + return -TARGET_EFAULT; + } else if (inofftp !=3D 0) { + inoff =3D tswap64(*(off_t *)g2h_untagged(inofftp)); + inp =3D &inoff; + } + if (outofftp !=3D 0 && !access_ok(VERIFY_WRITE, outofftp, sizeof(off_t= ))) { + return -TARGET_EFAULT; + } else if (outofftp !=3D 0) { + outoff =3D tswap64(*(off_t *)g2h_untagged(outofftp)); + outp =3D &outoff; + } + + ret =3D get_errno(safe_copy_file_range(infd, inp, outfd, outp, len, + flags)); + + if (!is_error(ret)) { + if (inofftp !=3D 0) { + *(off_t *)g2h_untagged(inofftp) =3D tswap64(inoff); + } + if (outofftp !=3D 0) { + *(off_t *)g2h_untagged(outofftp) =3D tswap64(outoff); + } + } + return ret; +} + +static inline abi_long do_freebsd___specialfd(int type, abi_ulong req, + size_t len) +{ + abi_long ret; + + ret =3D -TARGET_EINVAL; + switch (type) { + case TARGET_SPECIALFD_EVENT: { + struct specialfd_eventfd evfd; + struct target_specialfd_eventfd *target_eventfd; + + if (!lock_user_struct(VERIFY_READ, target_eventfd, req, 1)) { + return -TARGET_EFAULT; + } + + evfd.initval =3D tswap32(target_eventfd->initval); + evfd.flags =3D tswap32(target_eventfd->flags); + ret =3D get_errno(syscall(SYS___specialfd, type, &evfd, sizeof(evf= d))); + unlock_user_struct(target_eventfd, req, 0); + break; + } + } + + return ret; +} + +#endif /* FREEBSD_OS_FILE_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index fc6273a780..8a25be4ac7 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -45,6 +45,7 @@ #include "os-stat.h" #include "os-proc.h" #include "os-signal.h" +#include "os-file.h" #include "os-misc.h" =20 /* I/O */ @@ -66,6 +67,12 @@ safe_syscall3(ssize_t, writev, int, fd, const struct iov= ec *, iov, int, iovcnt); safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, i= ovcnt, off_t, offset); =20 +safe_syscall4(int, ppoll, struct pollfd *, fds, nfds_t, nfds, + const struct timespec *, restrict_timeout, const sigset_t *, + restrict_newsigmask); +safe_syscall6(ssize_t, copy_file_range, int, infd, off_t *, inoffp, int, o= utfd, + off_t *, outoffp, size_t, len, unsigned int, flags); + /* used in os-proc */ safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, struct rusage *, rusage); --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139896; cv=none; d=zohomail.com; s=zohoarc; b=HJ78TTnKjdU2HX2bqVf2P8GXTz4m8j8MK+Ay6+2JR7eoxoTZMantUcrqhGmOec5J2t7PibaRPNZGPlNHtnYIgA8csoizUW2NiNP0QIcWdlwXxwGNM7iTp0ypYvbznGKw8/fq7qYHHa32c63gwVjyij9kv1fYulMda2ysLl13+ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139896; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=t8+v/EjXETKRTwyWebZC5HE0qPUNEGr0KvGN264bUy8=; b=a3cYElp0tS/JgyDs1cm1y80ib5FCChShNtiJcVKFC1gmROdbEUierJmMrV/3fD0dhkf7GkjLSPViQ4f7DUC0wqUqgbX6ZEkvEvSYfx+CYSJ0HM5vi4aSGubPOVRT7NoIhyCXiyS3JYOEDLWVrnUlOKKeZ0mehnATeU9zRRH1CkE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139896409986.1189809987328; Mon, 18 May 2026 14:31:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VM-0000Of-PN; Mon, 18 May 2026 17:28:04 -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 1wP5VL-0000Nf-6c for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:03 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VI-0000Rb-KQ for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:02 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7dbccf6a23dso2406224a34.2 for ; Mon, 18 May 2026 14:28:00 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:27:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139679; x=1779744479; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=t8+v/EjXETKRTwyWebZC5HE0qPUNEGr0KvGN264bUy8=; b=H+xbyhUytBSIUPYnAsXlJWPyM5SEndBVu1Rhoy41L9kPM7s1eCA7sbTx33P3rJBGB4 n+66c6VJEdVWjI2vDXGrsluKidvtP2gd0bhCchwb+jwj/jS1W4a/a+Ze8UbWBgYOwQ0f Y25q8ifRvbbnU+dWdGAIsDhr5l8RpUSlo3vV6/wtcE8zgNMEBnjTd/O0w/k6G57KGo77 O1OgqHLGM3LjjSz64g4zFHGVj81CdNRxY5AuI/ATAHUMuhYD+ngJNfLESrRQyqrxkZwM XXRG7PqgqJxnOC0ZJF/cjDqJNE7ZvMuB6lxoxL6Rfc7AAJnnS4kpMzm+GrFU7PKKyfpB 287Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139679; x=1779744479; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=t8+v/EjXETKRTwyWebZC5HE0qPUNEGr0KvGN264bUy8=; b=maCwehj+OMROgljVU16OUdY4Cv91N7ozizdAlVG7xGMscGuWW4TykoO88oGmtPfRhi c3occaUmdD3lsRDGeIoPCUKANEoZOM852CXrw3swk972p1ARYiqkjvzO04KiqN0/JbkK 96+u5mGBzN2x4jW0iRS7ld/mHolT6iYMT9vEaL+6ekHJUhdp5ayaW9RT6qpMvfEUUsgE uGjtWFvuxnji9S2AnQPTAckfjmmeDEagdoCJHXG+Y+bzBWDj86kJyUd7aYg6hwh8tXd5 RaJG7U8JEG3I9E+lOBvQR34qxD2Rv4icVz5t2ckkOtCKHKT3UvYe/zP+g37nRIkTfS9y Kb4g== X-Gm-Message-State: AOJu0Yzn1xZU46UeB89p3veKoSnKQHWrOyH9P10KqYTZd7V78kVYxxfZ mE0X/iDXODIu721yaCwuSz3pfADqHwQRJ7TCZUtTtB4+fwdsnyJ7qOyxB7mY2jyidIQeFJdLACo egm71Smw= X-Gm-Gg: Acq92OEJO6mGOwwyeUuo+IT3d+9sVIm4j+6kiN8W2zHjJ39TtvUGXFFzqDtx1+0Tj4W xWwcTnWzsNknvvVtdMPuHMBpYBInE8grExZp09DQBPuB5HtPseT8vkUE2nRC3iBqZTY/5PkDfFA Dzst4zqnEi6lNXxxUS2EpRHViJt+JjtT6BP1E8huiE2jzGHyR/g3ejcLD5LuQVdkmkr/qKhkCfE 3ml8hnfvZzLE1M7kX4N3Ckx2NcBzlI5FRQGu0cz2u54A+3PzzdHPkIkZrGTD9iyKbTO848eTI1X BGtNM/SBHfKqqRq+GKINAzMIy00TZzN+ys64IM4k3VDBBE6XutxaCVTG6HZ3jCdQCMq9+3cRY1K 8tRIRaoYOaV1XcGgSyFHnSSwlEyKIsmPUoU0s8nGvQqqq9QvjFQOsK8SP0tbxKKNKw5tLuTIVMp 3FZTG4ILDwrQ== X-Received: by 2002:a05:6830:6602:b0:7d7:c985:3a30 with SMTP id 46e09a7af769-7e4f2a30195mr13830425a34.11.1779139679648; Mon, 18 May 2026 14:27:59 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:26 -0600 Subject: [PATCH v2 08/37] bsd-user: Add file operation system call dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-8-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3697; i=imp@bsdimp.com; h=from:subject:message-id; bh=p3uvcx4gphk1awyIPaOzO4oRtM8CLnIjjebf6/6Tgk4=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RG6vVfdCP0XMTlMboozbEd9BfucP0bnEanb E7/0SrAlyCJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AFC1D/43ghBcwaidSO7Qc53BWTtjVh1rar172HL4pMBKGgrVgOw0RwQ0z3h4/Szx8VELFpxBVg1 gh1rwaxgagnaOgYAv5SPpzz7SKlca8bnALiEu9hsGWx9ABltjVemSzHYCjmfH+/5KnHeneoxTxb kvfhTQwgcUiLU/eumiBt48iKSyzXgZ4jZz7V6Hpqj+VeWlTL2u3c8kf69EtcBp4MGOm22wANJN3 y8UWsA+cPSIAICPzL9b9um3xmX+hMYUGxZlH1l2gDE6RB5X8A10albG1z6yN1GEyGXymzt1ye2F Xor1SCOMD6J45c5a0jYBJiZCe0aQ9NS9oVSspQpjUjBJsN4pVukRmN1rxjEBpA4ypme3/IyAyZi Rxq7faKxDRxf+uztc7CJfuxfERagCc1/2VIXIBD4Ef8xJ95fr0kdPxXCBZedVpNzxF82hH3NcG+ GR9G+Jm4FkC1S9nSdw/X98Z4z2wwArWSH1n8geDWsMGA8evdQj2DVQSPf8oKALMx41T9Gb+cJFa iVEl3esdT7haPPaJk5MOkcITedVP9HIfANRRdnDEpRdngfLmJJuE0QoQv3iTzj1s+YkCmaz3ohI IaD2bFq7zd/zQI3IpPgdIu4/FU62Veecv1ytJTnbZ11jMwG2V7uoJtjQPmZMarDBgq1iaMQW3HJ 7MHDAVrDMndn0Pw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::333; envelope-from=imp@bsdimp.com; helo=mail-ot1-x333.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139897402154100 Wire up additional file-related system calls: poll, lseek, pipe, pipe2, swapon, swapoff, chflagsat, close_range, __realpathat, copy_file_range, and __specialfd. Also fix __realpathat to use __sys___realpathat on FreeBSD >=3D 15.0. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-stat.h | 8 +------ bsd-user/freebsd/os-syscall.c | 51 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/bsd-user/freebsd/os-stat.h b/bsd-user/freebsd/os-stat.h index ea95aa6344..4e5fc30de4 100644 --- a/bsd-user/freebsd/os-stat.h +++ b/bsd-user/freebsd/os-stat.h @@ -622,11 +622,6 @@ static inline abi_long do_freebsd_fcntl(abi_long arg1,= abi_long arg2, return ret; } =20 -#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1300080 -extern int __realpathat(int fd, const char *path, char *buf, size_t size, - int flags); -/* https://svnweb.freebsd.org/base?view=3Drevision&revision=3D358172 */ -/* no man page */ static inline abi_long do_freebsd_realpathat(abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { @@ -640,12 +635,11 @@ static inline abi_long do_freebsd_realpathat(abi_long= arg1, abi_long arg2, return -TARGET_EFAULT; } =20 - ret =3D get_errno(__realpathat(arg1, p, b, arg4, arg5)); + ret =3D get_errno(syscall(SYS___realpathat, arg1, p, b, arg4, arg5)); UNLOCK_PATH(p, arg2); unlock_user(b, arg3, ret); =20 return ret; } -#endif =20 #endif /* BSD_USER_FREEBSD_OS_STAT_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 8a25be4ac7..228daed4c4 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -700,6 +700,57 @@ static abi_long freebsd_syscall(CPUArchState *env, int= num, abi_long arg1, ret =3D do_bsd_undelete(arg1); break; =20 + case TARGET_FREEBSD_NR_poll: /* poll(2) */ + ret =3D do_bsd_poll(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_lseek: /* lseek(2) */ + ret =3D do_bsd_lseek(env, arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_freebsd10_pipe: /* pipe(2) */ + ret =3D do_bsd_pipe(env, arg1); + break; + + case TARGET_FREEBSD_NR_pipe2: /* pipe2(2) */ + ret =3D do_bsd_pipe2(env, arg1, arg2); + break; + + case TARGET_FREEBSD_NR_swapon: /* swapon(2) */ + ret =3D do_bsd_swapon(arg1); + break; + +#if TARGET_FREEBSD_NR_freebsd13_swapoff + case TARGET_FREEBSD_NR_freebsd13_swapoff: /* freebsd13_swapoff(2) */ + ret =3D do_freebsd13_swapoff(arg1); + break; +#endif + + case TARGET_FREEBSD_NR_swapoff: /* swapoff(2) */ + ret =3D do_bsd_swapoff(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_chflagsat: /* chflagsat(2) */ + ret =3D do_bsd_chflagsat(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_close_range: /* close_range(2) */ + ret =3D do_freebsd_close_range(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___realpathat: + /* __realpathat(2) (XXX no realpathat()) */ + ret =3D do_freebsd_realpathat(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_copy_file_range: + ret =3D do_freebsd_copy_file_range(arg1, arg2, arg3, arg4, arg5, a= rg6); + break; + + case TARGET_FREEBSD_NR___specialfd: + ret =3D do_freebsd___specialfd(arg1, arg2, arg3); + break; + /* * ioctl(2) */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139798; cv=none; d=zohomail.com; s=zohoarc; b=SfuEjC4ZY521cSvb1EuauU5dHiyOnMtx0eY6uKHgjVUBDFAAus10tJbKLn4JVq+FsEnC0JTMnXkIatXMl1PTY3Ytgwa8a250mg/5ohVU76X56xB6hhu1dac0K/uoegqN0E3p0qzVftFAD3TftNtFUG89v7bLUERArFJa4nTL5Ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139798; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X139v/fq6kIlZd7LLSuaNP39cVFCILWMkztN9EqyH7E=; b=MqOOCMOtec4/Y9lGi7EvvTjbYbUydYX39FMXP2h0aQMTuLZXa4FtjU1h+44k7ScIW700wBX3YK7bM4OCgd2RFjT1/hX/P4sS0zGafPnN1as3cBbOAcduULJeHw6HfnVfGXzw4BMphuXNEtALKEp9AURYAYLPtGUG36RIK9b0wXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139798897542.7091792473506; Mon, 18 May 2026 14:29:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VN-0000Om-6P; Mon, 18 May 2026 17:28:05 -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 1wP5VM-0000Nt-03 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:04 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VK-0000Ri-2r for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:03 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7dcd9061b1aso2714638a34.2 for ; Mon, 18 May 2026 14:28:01 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139681; x=1779744481; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=X139v/fq6kIlZd7LLSuaNP39cVFCILWMkztN9EqyH7E=; b=ReCidHy/jDbtRVYUPUTmuvduggPQAd7wgk3sBfeGhZ9JTMLnrsbuA/JAQ+oQDxrOif 3KgJf4Fwc7f+CkTBshlKtqJAUQpS6sfyRP8JPdYr7jPTTf2PcGsYP35Vp7Tf95pSP4wr Z1B2DgYJybrHHB+J4VclBCkdF8NWTkLpeC5/klCzGlzUFQemMnHw+f9eJAOboZhCs/mq H92BZClq0z+Yl+jw4LcWFjijbpeTDYkCy0oZRiuE9e+ixCxKppX3qJ35/yKv8R78AV9m VRys6KSxKl4aAYTb7VT4nT9k9C+4UBwm482q81xg36AR4qlxUqW4SQFFLCp5DRD+LzHy VDwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139681; x=1779744481; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=X139v/fq6kIlZd7LLSuaNP39cVFCILWMkztN9EqyH7E=; b=T+lmJ1IeDR1zXeydnUZvoPAPyID4kjslO44i5wxl26yWwYvyFRXDA/hYyEhFwTP4Jj 4rR1awdLoiDek20AQRPHKihIlz/KnUmLEp9I4vdNl42pS1fEbYT1x90wzP+6hSDfVCTx luo627lm8eVvwz8CO99VdOI6ajc/xxQ2tEmwxe9E4kLEltDmpNyo3kz7I6r8P0hqSAgn shZlXL/9dNx29UhQWn+7I8zlVzcSVl1c1m6YMbMzKybsRHkeMAt0aO+GeD1RwU3NuUYV 8vQnO6Q8Xg7n+m76HnftleFdttKaTxM8oeevq6xzhZ0TTA0wY+mGkz0PYqFu2DIe4bM5 p9BQ== X-Gm-Message-State: AOJu0Yx0tQ9CN/WbT/LLxm8T4c5QOiNGZXx85TTAMDcEPxrIlcSudzAF GkpqWmBjx+uM4OLqoOdKU7b9/J9SV+tl+khetOzmTgOULjHAZjhsCs+FQDJg0trBxgv0N0AREdF nDAk6rvg= X-Gm-Gg: Acq92OFhVtEuMFKsTJVBKtky4t10yOTY3uiFHw06Mya8BbHtk5t5BSGj/c5bXysbqoc D5EtS2OwoBBoak7VHMr9csERLjURE60wELYG3i+gLDxbS/hKLVf02iyiHJdzoOUW1qEqRUrf3XO uySETq2e6I/ZlSAlRW1o2fdvNEwT0FacEFQJ81DacIMYsIw55E+5S9BJqU1Fbt/YfJt2CTgvj3y ThHf9qp09/Y1h6CviLkWqtnwINE5/bIF30HQzGnQq201rDCH9hsb0/QHSk9RJLFgAw0NBAw3E0v Wty27uBWb89oX09sS88jyyV6EY0A76D1hn52c+vg1UvSIR63OV5IQR4Vd9qdLXBDe15NNMRmgC0 kzkPuAT6ipluZ1rvWVtyvd0OldM2wBTr/xWWTYITY5ePhq0+2Mlz2Xdh/VfvTd4hiPV1MaetkLi uwldOPpk0hqg== X-Received: by 2002:a05:6830:349e:b0:7d9:f50f:9691 with SMTP id 46e09a7af769-7e4de6b026fmr11827528a34.0.1779139680895; Mon, 18 May 2026 14:28:00 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:27 -0600 Subject: [PATCH v2 09/37] bsd-user: Add bsd-socket.h with bind through getsockname MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-9-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7095; i=imp@bsdimp.com; h=from:subject:message-id; bh=r4P6eqFpteuxxeqRzsUj7FYwHABI/v6ZFvzXHh1X9Fk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGqKuWaGO+P/UGAlD0L4z1OhcTt5i6gFRQF X44I9CwOMOJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AHaXEADKIGGvCc11N3NhBhNBzrWQUsLhcvyd0HZiMsH52U1QskU7O+u+yaBq36ExrPLbl/Xai2v QcTZw0eZCXC4+CwUT8DsIuzEtJCJikmxEJl+IuoBYT/1vrgDVbFRF8EVU7Mw0nHn2jtTTAi7WUl jpL1H/SK0EITHdt+N0AlEVKCz+FXBaUajQfOgjbEmvQAfjpabu2Rf/4OQc9GvIppBTg8eRB0p1f zEZGNID+3IaWwo7HTqf7jBfUso3D1ApbWknwF6tv0yzCGJ1Ak+A4h6K+fWmTKAAnqZ2ldLeWFMB OtZXDCWOrFKDphDTN433gVpFSbb9ARPQAoPb9Qhbbop7KM+HgjFuoaYWhRdlF5vFMXmiahPdoWL WxFPELcoKrza2BENZ6aWMlAo0iUesbH2ZLl0lMmlKzbdrSuW+PW979AsoKmDAzi6azg2oUJGpCv owEvmt/Ifw/5P/V8usMSfJhAYNo1MqDteOoaNVqQK3N+67WVv0a5mvbXplhB1A9DhYLJeWpTlF6 srAep60FzGlNtEANlOTwTUDCxtWiRZo2Ocu9OmyG3+Pvo+BUetPa83fG+GGGWLpH/oMM6Aj+td3 NmOo2hkAb1WuG/fIHqpMzqCyGz2LSSPgZ0feEvUsm7R3URIMDCItmUh2S1V5igQdiXcA6xMaRYK TQizpvaxINCKlkg== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32b; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32b.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139801380154100 Add the first set of socket system call shims: bind, connect, accept, getpeername, and getsockname. Also add safe_syscall wrappers for sendto, recvfrom, select, pselect, recvmsg, and sendmsg. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/bsd-socket.h | 167 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 15 ++++ 2 files changed, 182 insertions(+) diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h new file mode 100644 index 0000000000..c786d6717a --- /dev/null +++ b/bsd-user/bsd-socket.h @@ -0,0 +1,167 @@ +/* + * socket related system call shims + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef BSD_SOCKET_H +#define BSD_SOCKET_H + +#include +#include +#include +#include + +#include "qemu-bsd.h" + +ssize_t safe_recvfrom(int s, void *buf, size_t len, int flags, + struct sockaddr *restrict from, socklen_t *restrict fromlen); +ssize_t safe_sendto(int s, const void *buf, size_t len, int flags, + const struct sockaddr *to, socklen_t tolen); +int safe_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *except= fds, + struct timeval *timeout); +int safe_pselect(int nfds, fd_set *restrict readfds, + fd_set *restrict writefds, fd_set *restrict exceptfds, + const struct timespec *restrict timeout, + const sigset_t *restrict newsigmask); + +/* bind(2) */ +static inline abi_long do_bsd_bind(int sockfd, abi_ulong target_addr, + socklen_t addrlen) +{ + abi_long ret; + void *addr; + + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + + addr =3D alloca(addrlen + 1); + ret =3D target_to_host_sockaddr(addr, target_addr, addrlen); + if (is_error(ret)) { + return ret; + } + + return get_errno(bind(sockfd, addr, addrlen)); +} + +/* connect(2) */ +static inline abi_long do_bsd_connect(int sockfd, abi_ulong target_addr, + socklen_t addrlen) +{ + abi_long ret; + void *addr; + + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + addr =3D alloca(addrlen + 1); + + ret =3D target_to_host_sockaddr(addr, target_addr, addrlen); + + if (is_error(ret)) { + return ret; + } + + return get_errno(connect(sockfd, addr, addrlen)); +} + +/* accept(2) */ +static inline abi_long do_bsd_accept(int fd, abi_ulong target_addr, + abi_ulong target_addrlen_addr) +{ + socklen_t addrlen; + void *addr; + abi_long ret; + + if (target_addr =3D=3D 0) { + return get_errno(accept(fd, NULL, NULL)); + } + /* return EINVAL if addrlen pointer is invalid */ + if (get_user_u32(addrlen, target_addrlen_addr)) { + return -TARGET_EINVAL; + } + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) { + return -TARGET_EINVAL; + } + addr =3D alloca(addrlen); + + ret =3D get_errno(accept(fd, addr, &addrlen)); + if (!is_error(ret)) { + if (is_error(host_to_target_sockaddr(target_addr, addr, addrlen)))= { + close(ret); + ret =3D -TARGET_EFAULT; + } else if (put_user_u32(addrlen, target_addrlen_addr)) { + close(ret); + ret =3D -TARGET_EFAULT; + } + } + return ret; +} + +/* getpeername(2) */ +static inline abi_long do_bsd_getpeername(int fd, abi_ulong target_addr, + abi_ulong target_addrlen_addr) +{ + socklen_t addrlen; + void *addr; + abi_long ret; + + if (get_user_u32(addrlen, target_addrlen_addr)) { + return -TARGET_EFAULT; + } + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) { + return -TARGET_EFAULT; + } + addr =3D alloca(addrlen); + ret =3D get_errno(getpeername(fd, addr, &addrlen)); + if (!is_error(ret)) { + ret =3D host_to_target_sockaddr(target_addr, addr, addrlen); + if (is_error(ret)) { + ret =3D -TARGET_EFAULT; + } else if (put_user_u32(addrlen, target_addrlen_addr)) { + ret =3D -TARGET_EFAULT; + } + } + return ret; +} + +/* getsockname(2) */ +static inline abi_long do_bsd_getsockname(int fd, abi_ulong target_addr, + abi_ulong target_addrlen_addr) +{ + socklen_t addrlen; + void *addr; + abi_long ret; + + if (get_user_u32(addrlen, target_addrlen_addr)) { + return -TARGET_EFAULT; + } + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) { + return -TARGET_EFAULT; + } + addr =3D alloca(addrlen); + + ret =3D get_errno(getsockname(fd, addr, &addrlen)); + if (!is_error(ret)) { + ret =3D host_to_target_sockaddr(target_addr, addr, addrlen); + if (is_error(ret)) { + ret =3D -TARGET_EFAULT; + } else if (put_user_u32(addrlen, target_addrlen_addr)) { + ret =3D -TARGET_EFAULT; + } + } + return ret; +} + +#endif /* BSD_SOCKET_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 228daed4c4..737de36514 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -40,6 +40,7 @@ #include "bsd-proc.h" #include "bsd-misc.h" #include "bsd-signal.h" +#include "bsd-socket.h" =20 /* BSD dependent syscall shims */ #include "os-stat.h" @@ -73,6 +74,20 @@ safe_syscall4(int, ppoll, struct pollfd *, fds, nfds_t, = nfds, safe_syscall6(ssize_t, copy_file_range, int, infd, off_t *, inoffp, int, o= utfd, off_t *, outoffp, size_t, len, unsigned int, flags); =20 +/* used in bsd-socket */ +safe_syscall5(int, select, int, nfds, fd_set *, readfs, fd_set *, writefds, + fd_set *, exceptfds, struct timeval *, timeout); +safe_syscall6(int, pselect, int, nfds, fd_set *restrict, readfs, + fd_set *restrict, writefds, fd_set *restrict, exceptfds, + const struct timespec *restrict, timeout, const sigset_t *restrict, + newsigmask); +safe_syscall6(ssize_t, recvfrom, int, fd, void *, buf, size_t, len, int, f= lags, + struct sockaddr *restrict, from, socklen_t *restrict, fromlen); +safe_syscall6(ssize_t, sendto, int, fd, const void *, buf, size_t, len, in= t, + flags, const struct sockaddr *, to, socklen_t, tolen); +safe_syscall3(ssize_t, recvmsg, int, s, struct msghdr *, msg, int, flags); +safe_syscall3(ssize_t, sendmsg, int, s, const struct msghdr *, msg, int, f= lags); + /* used in os-proc */ safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, struct rusage *, rusage); --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139786; cv=none; d=zohomail.com; s=zohoarc; b=XIcxYJPBoV7wiV8xbl7cEheY5/vvT1Cri2sISIbtkeDiMYOzl/dJdeKlKs9JX5rhPCl86W/bO0mG0xTcP5RVygzTLwJ8wMWanHmgA4A/tYuqZxz9qWkzKEjXg8rb24uPBCRddYPxCM9gh7Q4KwoQx3uzgDfg4YAC37qqNzRyQbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139786; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZJ7v//PQurI3QUAyO+HvdctCbJ9hSdibdnByYDaydXY=; b=hw1X9DKqjXDu2FBJ1kvUYqhsGenUF5lT7sVUy7sNDo2ukdaMmc2ZdiYBVUOt+JM1BUWmldkp+KWrwjiA5Vt4qqODyykxnxCAiMgoT2g4piqjOIuQm9ANXyVOf2BOhQl9yHil7EFYQI0cG85OrtSU7JsJaEjfYTA8D4bnxAH+sbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139786215226.01696101194113; Mon, 18 May 2026 14:29:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VO-0000PY-LG; Mon, 18 May 2026 17:28:06 -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 1wP5VM-0000OP-GY for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:04 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VK-0000S4-VP for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:04 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7dcdd1b492eso2947826a34.1 for ; Mon, 18 May 2026 14:28:02 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139682; x=1779744482; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZJ7v//PQurI3QUAyO+HvdctCbJ9hSdibdnByYDaydXY=; b=Z2hZ0UJyx4kmXotMBe6m/pW6WBlx+rvdZehWEkHqjnsei3G72p93qpjDdOzYhKU3HJ KV6fJ6/GATxhBxp5ktFp+rO68QBGk3q0xbfgyjfp0JRqrbLMKguOAxceNkwhK0sWEmZS eI4Y9d4StJW6pcnZcS7Z+F6U1z9YpQeFwgQByU3KzmX7ivkuL0acb059XeI9eUQNrb4S KbcJBvL6B0U7uo2cSYAWN9p4y13k9xwHGIdDzN7BSkvHNK8fqmvTtCfxEEE1x9xqLr5l LjeNjjXHWhRGz012PTg4gO2HqpjcLg7YTRsvy9DyTLl7q9YD9oYwNHS1h8DjtvKNyLIx s0pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139682; x=1779744482; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ZJ7v//PQurI3QUAyO+HvdctCbJ9hSdibdnByYDaydXY=; b=Gu8QzX9vfXB410l2ywQ9zPVPWd6lYtWIiBOFbzjKXX3Xb6f/Ru7MwWn1NOnzrwo5xu VL1M5JrvusKDNA+Iyg0O2aOSyjlWj0Dimw09zdn4chuSnz/SU3m8gW4XRsEUxuS6EFGP p8pgTiSC1JYDFQIIhd8XJ/Pz1zgMPrWHbQKGwt1iheBfY8ZgpbfhGXujpjaFNq/5mRES 127W3GOwmTXbKeK3xD4QLRYGO/PfSeNfyoe5rJFGxtP1InHAHAfLeCa9fPP3HXT66e54 k/JZwE1Z8m3AJP5cJDqIQ14Y1JbKx+WSX5jQmsFnEIwA8Fi2I3Ctk972WQYCKk8/tR2v FZNg== X-Gm-Message-State: AOJu0YzCGKyjFaYkQ1y5qnoSEDtuTH2j7XUvArrL7asS0VRSbNuu2NG2 zju+tyVaBnGCAopieN2Fvh2NG1hna4ZZP0v3rOTvxIH9LujNCVNxUh3Z2L4BYpRd22I= X-Gm-Gg: Acq92OERPiseIMod71DGN7viW58HcYM8mGs3Ov/PDd5nkqOhMwMLDSwK07nBZq8Nr+f c0N5+9gn2s1gWakXe5IBLDe5F+ChNp8X5QdKZTK+iSyisiULtZ/0o68rxCVNVwzCTz/uzvivuGa 2+jJipRfEbHsPfp9cfCi01Lz+iIEXWsAqDW60hc0wsea8QrOAktJQwX4Y14qU8FCRmXJL0Hqe8p jXSfmCBfebSsXLRfaHW1Vdx0R19qkO9RdB5JLsQm1Nu1RxogfrUGdCe/9Z6fSG6S+RkorvsfcUT FfDybHizZydI/1GNB31Lslsoojlld+tHyGP+MXPp+/+iO7kWwKH/RSfxV7Sq+A/4HSCaXybDbYN dFUN+XXAfa82RgFM3mMm8t1k0Wlx8aWTrxLd9tcAL3R1RJVymopJezjTHBlsZ7HrFsbhJpeF6cj GDmEIHb6XC1MPWZGg+kS8G X-Received: by 2002:a9d:4f15:0:b0:7dc:e43f:4b31 with SMTP id 46e09a7af769-7e3f14c8d19mr8791428a34.12.1779139681847; Mon, 18 May 2026 14:28:01 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:28 -0600 Subject: [PATCH v2 10/37] bsd-user: Add socket shims socketpair through shutdown MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-10-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4286; i=imp@bsdimp.com; h=from:subject:message-id; bh=p+SdwfCAmHsiJep/Ad8iRM9GDkukh3wykvHxywkpLCc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGevPBMDjfezN8f/kRACf1wC1Ui7bxbwKVS maB5iM38YyJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AIXvD/9wEm0S86iRvI1aDfm6rRe/v/ux+WwKC65AvFJi860rDhDZ2BVbX3r5rQBYgu+S4mUJod9 exCHllGAR8pdpdoYk+j95ahQ2yAb6GIeCgwSs8K1jZFzy1fz0ONPX5wsSRg7uKIVIyXbx6grg9i JeWmmmLn/LM2h2pGshGxhWnHIOxlugnZVHBZ8nBL+WbjxDiP5jpoj/Vt8Phdq1YU5Av6IrhYJdS Zx/tBs5CTIB/i31nrE/51nSY0McqoWDWF4i1yw7IMHruDTmTFxe33RwD2i0BNwj3etTnKWSunrL Ui0L8HGIecnN0e/20kl2dVwfWI3HNED8X5wpcwUq9d8/5jR+V9E5E9NzUhKzbOUIFr0lKv0cSR2 x6KQtwupbG3QZkRT1tt+pO+CXx2H4gwgba9Q5vCHjnJx7ZQSZ6ij8T9ib5rQpPHRoAV4CM9GjkS BrmHq1gDaI9T9d7XomnsvJJ+9RaUlf0rf88l2WWQkY3S9/ZzeNVEKEQXAbPsWrDMJMNklOvHW4N fcm16YyQ4TJls2G7FkrEYI6DQD99KQxhe4Ux5AOzv870g0F512UXMX/qieT3PUi6Nmy9LaQG1g5 P6P9x4q68imf8Ym0r7QmOuVFEX5GVtftTtZvfPEaakIv6A2DtizReSC+aZ4EUHoWk91b3vK/1h4 9kvdJobqXaMnx7A== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32b; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32b.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139789115154100 Complete bsd-socket.h with socketpair, sendto, recvfrom, socket, and shutdown system call shims. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/bsd-socket.h | 116 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 116 insertions(+) diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h index c786d6717a..c87ba195dc 100644 --- a/bsd-user/bsd-socket.h +++ b/bsd-user/bsd-socket.h @@ -164,4 +164,120 @@ static inline abi_long do_bsd_getsockname(int fd, abi= _ulong target_addr, return ret; } =20 +/* socketpair(2) */ +static inline abi_long do_bsd_socketpair(int domain, int type, int protoco= l, + abi_ulong target_tab_addr) +{ + int tab[2]; + abi_long ret; + + if (!access_ok(VERIFY_WRITE, target_tab_addr, sizeof(tab[0]) * 2)) { + return -TARGET_EFAULT; + } + ret =3D get_errno(socketpair(domain, type, protocol, tab)); + if (!is_error(ret)) { + if (put_user_s32(tab[0], target_tab_addr) || + put_user_s32(tab[1], target_tab_addr + sizeof(tab[0]))) { + ret =3D -TARGET_EFAULT; + } + } + return ret; +} + +/* sendto(2) */ +static inline abi_long do_bsd_sendto(int fd, abi_ulong msg, size_t len, + int flags, abi_ulong target_addr, + socklen_t addrlen) +{ + struct sockaddr *saddr; + void *host_msg; + abi_long ret; + + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + if (len !=3D 0) { + host_msg =3D lock_user(VERIFY_READ, msg, len, 1); + if (!host_msg) { + return -TARGET_EFAULT; + } + } else { + host_msg =3D NULL; + } + if (target_addr) { + saddr =3D alloca(addrlen + 1); + ret =3D target_to_host_sockaddr(saddr, target_addr, addrlen); + if (is_error(ret)) { + unlock_user(host_msg, msg, 0); + return ret; + } + ret =3D get_errno(safe_sendto(fd, host_msg, len, flags, saddr, add= rlen)); + } else { + ret =3D get_errno(send(fd, host_msg, len, flags)); + } + unlock_user(host_msg, msg, 0); + return ret; +} + +/* recvfrom(2) */ +static inline abi_long do_bsd_recvfrom(int fd, abi_ulong msg, size_t len, + int flags, abi_ulong target_addr, + abi_ulong target_addrlen) +{ + socklen_t addrlen; + struct sockaddr *saddr; + void *host_msg; + abi_long ret; + + host_msg =3D lock_user(VERIFY_WRITE, msg, len, 0); + if (!host_msg) { + return -TARGET_EFAULT; + } + if (target_addr) { + if (get_user_u32(addrlen, target_addrlen)) { + ret =3D -TARGET_EFAULT; + goto fail; + } + if ((int)addrlen < 0) { + ret =3D -TARGET_EINVAL; + goto fail; + } + saddr =3D alloca(addrlen + 1); + ret =3D get_errno(safe_recvfrom(fd, host_msg, len, flags, saddr, + &addrlen)); + } else { + saddr =3D NULL; /* To keep compiler quiet. */ + ret =3D get_errno(recv(fd, host_msg, len, flags)); + } + if (!is_error(ret)) { + if (target_addr) { + if (is_error(host_to_target_sockaddr(target_addr, saddr, addrl= en))) { + ret =3D -TARGET_EFAULT; + goto fail; + } else if (put_user_u32(addrlen, target_addrlen)) { + ret =3D -TARGET_EFAULT; + goto fail; + } + } + unlock_user(host_msg, msg, len); + } else { +fail: + unlock_user(host_msg, msg, 0); + } + return ret; +} + +/* socket(2) */ +static inline abi_long do_bsd_socket(abi_long domain, abi_long type, + abi_long protocol) +{ + return get_errno(socket(domain, type, protocol)); +} + +/* shutdown(2) */ +static inline abi_long do_bsd_shutdown(abi_long s, abi_long how) +{ + return get_errno(shutdown(s, how)); +} + #endif /* BSD_SOCKET_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139821; cv=none; d=zohomail.com; s=zohoarc; b=dTV/nniev13KpR96I9+3TVgJLeBCU1xaF/vgoaFqxpP4Osd9/meTMJ9FClG8MU/gSH5KB4A5HkS5HZkhq6+o2FJhuhyKav89yUhMQIPINw4Sv10sQGBVLQGaCR9pLIO889fjLwLJc54BOXj6jhLjLGAuoe8d9uWvEGvza5dMDd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139821; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=73NLJsALVR7wgtLvwEyY7coBbyzbT922pF86YJa6DFs=; b=fdHZjODKf10YZ1+lCw6bEAFpWVaZ1HYBH9pL4vr0PlbVTq1XmnQlG8Ejt7kWuCXoaTgcskPMqzzLoTWDMCJ2vlpOuaD2NEGIG5OuHut2QI8nDZzc/pRu4Dnn2w8P3CrFmHZf9QFtSW2wrujjXz9p+lfcqy7WxqiYgvESVt1wzoc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139821442880.8965451647355; Mon, 18 May 2026 14:30:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VP-0000Pe-2P; Mon, 18 May 2026 17:28:07 -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 1wP5VO-0000PO-1y for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:06 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VM-0000SH-2m for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:05 -0400 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7e582b3bcaaso2128751a34.3 for ; Mon, 18 May 2026 14:28:03 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139683; x=1779744483; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=73NLJsALVR7wgtLvwEyY7coBbyzbT922pF86YJa6DFs=; b=0ZmpF2obx2iRP89QKl16gxOUdxFHHD14GGP/mJL7Z7dLsrz2u0KANF6TIClXxfvSFK w+1VA0xkKohDREw1a6YY5Brw7StpjCSc0dIXo/c1K+9ASPWSq8dUSjKEzJJf5lBpefeo 0HOWy2HdE/HxDGN6+DbkTlmq++0WV6Na9H8fx+9vifnvVLkrmPb8VShb8x9KznQTZtUn eDe9YsugT6rpOcyvsGl1/8pCWigDKBJLBFOwAGlJkM5JXyb4Y82GY3SC0QTnWddip4c7 OEfimAvWxEEMCGEVNdft0C2Cmv7Ga9Hc4MHOLGUYbfbuphDbNE1JfRmzn0l9bi8H4bGj lifw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139683; x=1779744483; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=73NLJsALVR7wgtLvwEyY7coBbyzbT922pF86YJa6DFs=; b=gvOU+F/k2EDVSYasV5PVOTs08F56IVlglNur8h9b726W1DKJUrWjVGROKatruLARts d6oDJeFHtbQdmdrYHo5sKMCFLyX42NKLyvT9CpR1uIDTDchBBSFdB7Y1AIHi7GsWuj/8 SAlYhgScsfBOufuHIxNpvZi3n2B0bGdDTnuMkZfsxVZP54LpXUzG3E2658NosanOpdQQ dvv3RUynKm0y8L/5LOw7GwgauOTJY85LYEM5dZ9/EdSV8DxRex91DfKIAUHxQ6qNFdRt cnxYOURf1UCI95nfYeHZtSTI8c+TzoL64zRIYDp9cTJxTX8okuvVp1GEB+1nYn7T+je1 j8Ww== X-Gm-Message-State: AOJu0Yw8+Uy9+wn/rOvoMl2X57vjFgkmUoq+TSMARjtgpppjSBnSMF5+ xVDFDvS/+dyyyzcvAdjuN6xOFMmid9+7SluBT/hmdbumt0QsyC0pbErGudhgLA6unc8= X-Gm-Gg: Acq92OE28P8MtrzLQorIzz6/k/iEG8MJQxHDWzR3W3aJrTaILL91+VPlltCBJVcwRXq XJr0vT59qbwT1L//cSYHqv49IVol+vIXl9MOwFaoxE05l4NPKtYcnucTVuqF9XvaE+xIkDyqtBz km4y6vv5WdghZBJ+/ua7ivTAqtRPoGRTDGfpN+0/L9qqbqWEz+AZdRa7NPr029DxvIvGPJyDRwd fptCq67Kw2I3ugQfRm6DKUWb7nckYPveWYnaODph4qQaXzzS6Ofmq3o3tCqg+3iXiWiMCuCVuZB imIUK2uBp1IUyjiYRi5QDzLt+zLUYUbIyMQ4LgQuNs4gg7TtFy07U/mr6pWcxd+Mg2wwvc6UT+x E/u90ILvsfg7T5qFn5xybixzA5zWy46xPd9+DL/dax1P91LgkCp151OsQ83o+tD4TkO5dakTUFq zoZctK6oQKjw== X-Received: by 2002:a05:6830:3591:b0:7d7:e59c:80e6 with SMTP id 46e09a7af769-7e4f2b24530mr11346780a34.12.1779139683003; Mon, 18 May 2026 14:28:03 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:29 -0600 Subject: [PATCH v2 11/37] bsd-user: Add os-socket.h with sendrecvmsg and message structures MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-11-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5633; i=imp@bsdimp.com; h=from:subject:message-id; bh=dlzoPbvTwfzSlndR4y6PsCvuZS9DmNaeKGJhZVcl21Q=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RGwt8Ax2frI9dH1y/Jlp2+1AgJlmmDzaZUe B8vVVV7KAqJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERgAKCRBsHNEofbAR AAM6EADaDQR/D3YMhvq68JuLoIRN8yAmIEJ2IaHzTEzuSLKLyVaS1mGsBtcME+HpPtq5+Resscc NDKkQXkCsJ5xmCO4wDwHKqthRv6iYOEpLQax7KtiR9eLqoF5bzwW4OYPK5zvBIFrZw9Il7F5iWD r1kVgZvbggMpw7MpivcANBFJKGqZHbF8jJX7aKYISBQX2d1kmpuP7mVc0wkhT9ZuNJwg28b3yGx r12R6cKTqdbfsFVP2HMiOyWdQfE2TRuNgWTwHNBo4AKqfHL2VvJhX0utB/0l7exIIoPwllSfexc IP3QCaOgxf00j4Ru82H3LOArBNFW33tQoNmJ4M4jscrxjjJInJi4TAy2TXHdO/QGr4a38vOTJpd dvUlC3+fwI+hyCnY2BF3cnB45E8V5IlTVGWhZem1+dDEurbxnTlBXi4DDZwZjynMJrT+kYsA6Uz Xp1+wH0xaJxbqSEHwVThU05G+wFspPX9pXMI9JVhiboHuyvsGCKcz2DyTcaHideky3YSUUIeebX qKq1I7i6+WKcoTLkUY+7wBJ9jvJ2T+8/UdAStuMEe6O/PbTpE12K+uL2EpM+twFwc+F6VZfN30Q 9hp3bp7gCLXo7xJl4unCccGPjCXmvoknJNUbOT/Gz3pfG3Du+Qs6++n1yB9cpZKNMgkJOFj5735 9US7tXma2ZBJJag== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32d; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32d.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139821895158501 Add the first part of FreeBSD socket support: do_sendrecvmsg_locked and do_sendrecvmsg functions. Also add target_msghdr, target_cmsghdr, CMSG macros, target_ip_mreq, and target_ip_mreqn structures to syscall_defs.h. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-socket.h | 142 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 1 + 2 files changed, 143 insertions(+) diff --git a/bsd-user/freebsd/os-socket.h b/bsd-user/freebsd/os-socket.h new file mode 100644 index 0000000000..279157dd05 --- /dev/null +++ b/bsd-user/freebsd/os-socket.h @@ -0,0 +1,142 @@ +/* + * FreeBSD socket related system call shims + * + * Copyright (c) 2013-2014 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef BSD_USER_FREEBSD_OS_SOCKET_H +#define BSD_USER_FREEBSD_OS_SOCKET_H + +#include +#include +#include +#include + +#include "qemu-os.h" + +ssize_t safe_recvmsg(int s, struct msghdr *msg, int flags); +ssize_t safe_sendmsg(int s, const struct msghdr *msg, int flags); + +/* do_sendrecvmsg_locked() Must return target values and target errnos. */ +static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, + int flags, int send) +{ + abi_long ret, len; + struct msghdr msg; + abi_ulong count; + struct iovec *vec; + abi_ulong target_vec; + + if (msgp->msg_name) { + msg.msg_namelen =3D tswap32(msgp->msg_namelen); + msg.msg_name =3D alloca(msg.msg_namelen + 1); + ret =3D target_to_host_sockaddr(msg.msg_name, + tswapal(msgp->msg_name), + msg.msg_namelen); + if (ret =3D=3D -TARGET_EFAULT) { + /* + * For connected sockets msg_name and msg_namelen must be igno= red, + * so returning EFAULT immediately is wrong. Instead, pass a = bad + * msg_name to the host kernel, and let it decide whether to r= eturn + * EFAULT or not. + */ + msg.msg_name =3D (void *)-1; + } else if (ret) { + goto out2; + } + } else { + msg.msg_name =3D NULL; + msg.msg_namelen =3D 0; + } + msg.msg_controllen =3D 2 * tswap32(msgp->msg_controllen); + if (msgp->msg_control) { + msg.msg_control =3D alloca(msg.msg_controllen); + memset(msg.msg_control, 0, msg.msg_controllen); + } else { + msg.msg_control =3D NULL; + } + + msg.msg_flags =3D tswap32(msgp->msg_flags); + + count =3D tswap32(msgp->msg_iovlen); + target_vec =3D tswapal(msgp->msg_iov); + + if (count > IOV_MAX) { + /* + * sendrcvmsg returns a different errno for this condition than + * readv/writev, so we must catch it here before lock_iovec() does. + */ + ret =3D -TARGET_EMSGSIZE; + goto out2; + } + + vec =3D lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, + target_vec, count, send); + if (vec =3D=3D NULL) { + ret =3D -host_to_target_errno(errno); + goto out2; + } + msg.msg_iovlen =3D count; + msg.msg_iov =3D vec; + + if (send) { + if (msg.msg_control !=3D NULL) { + ret =3D t2h_freebsd_cmsg(&msg, msgp); + } else { + ret =3D 0; + } + if (ret =3D=3D 0) { + ret =3D get_errno(safe_sendmsg(fd, &msg, flags)); + } + } else { + ret =3D get_errno(safe_recvmsg(fd, &msg, flags)); + if (!is_error(ret)) { + len =3D ret; + if (msg.msg_control !=3D NULL) { + ret =3D h2t_freebsd_cmsg(msgp, &msg); + } else { + ret =3D 0; + } + if (!is_error(ret)) { + msgp->msg_namelen =3D tswap32(msg.msg_namelen); + msgp->msg_flags =3D tswap32(msg.msg_flags); + if (msg.msg_name !=3D NULL && msg.msg_name !=3D (void *)-1= ) { + ret =3D host_to_target_sockaddr(tswapal(msgp->msg_name= ), + msg.msg_name, msg.msg_namelen); + if (ret) { + goto out; + } + } + + ret =3D len; + } + } + } + +out: + unlock_iovec(vec, target_vec, count, !send); +out2: + return ret; +} + + +static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, + int flags, int send) +{ + abi_long ret; + struct target_msghdr *msgp; + + if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE, + msgp, + target_msg, + send ? 1 : 0)) { + return -TARGET_EFAULT; + } + ret =3D do_sendrecvmsg_locked(fd, msgp, flags, send); + unlock_user_struct(msgp, target_msg, send ? 0 : 1); + return ret; +} + + +#endif /* BSD_USER_FREEBSD_OS_SOCKET_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 737de36514..46fee46336 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -47,6 +47,7 @@ #include "os-proc.h" #include "os-signal.h" #include "os-file.h" +#include "os-socket.h" #include "os-misc.h" =20 /* I/O */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139900; cv=none; d=zohomail.com; s=zohoarc; b=Q/H4+J7JVC+agfxDY0sSxI4jeYITlg7XrKhbwZnjPnbAZKBckUaozTfK9YLeSH/Za3Kjgw4/0hO2KPVx+LkGM0uJw2no7Hipq3TWoHh0y85IkaGwibek9I+b4fLnWcolR4570x99r/q3HDV6mUmP/j46OjCcBRhgrbTKqLM9STA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139900; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mm2q91Iz2qpAj0cOr1D4/1HfcCh46UzWrvusR45KGyU=; b=Zbfg7ykZeTp0zmHVyAxKhj3icsZArXgs7oHVqcCBHKpTQAmaMrpOS8qdDXhRsIP9xZ7KLGtGFbTGGe1X3Z+aQ0eTGiajJsYQ20hitEBWc4MQv1kZ7+fQzonNtIUoSAO9cGwAgjls+RpyEicQgctj2YKbYkRpwP2b+lJCYhqZ26U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139900923778.0909918486929; Mon, 18 May 2026 14:31:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VQ-0000R9-DN; Mon, 18 May 2026 17:28:08 -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 1wP5VP-0000Pl-Bh for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:07 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VN-0000SX-BS for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:07 -0400 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-484df1dce93so1114468b6e.2 for ; Mon, 18 May 2026 14:28:05 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139684; x=1779744484; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mm2q91Iz2qpAj0cOr1D4/1HfcCh46UzWrvusR45KGyU=; b=nwOE7WLJY84oXXKch2mVbOTXa8vZrlab57O5oM6s0e5dJ7ABc/vtgCSrZCcOnvwUV6 CzH4qILp40jDMFLJRrpJJewRzZrDrt2XgeBaYc/zn2GO6lePraum0o3gaZXYo0QFQ1ug U5Xbg6c9oDP7x6aooLOR42S26w3NthiuzFRx7SMi5iVJIJU80pjsExNJ0ZrRw4iUhZrc Z2D22EI8D83DrL8vStaQdpR63CBeAafBtfpaTU26u8icONsw2Eqr7ePfAIqDvgKuA9LD x0GjhTNcKBUAzlxFycmFqzys5QSMztUy2Iiwk6xMEgNBhd1xDPtRTT45ariv4gf8knPp GAKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139684; x=1779744484; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=mm2q91Iz2qpAj0cOr1D4/1HfcCh46UzWrvusR45KGyU=; b=PwK7I4WdKt3uEZKng80a6ecorVs8J1dUwsK7jUI6Hcpw5k4ZL365bQiA/zAGsW4D3S 4bSWlA19/ROjPsvzvvAErFF8fgvbkE6/wXLUfqsqNcih+z6w6/53llKeQAEJBq0XECEJ dKJbADU5XESBKo/sekOxf5c2OOhPHOHSlduafhYKbUNwwu52xVKDgPoEZrymj2896rRJ p5ITx9mLibrNTo5q18zabQaQ698sdKwFmR9aHICm6TOoo7FxE0+sSFnMra3j9Z09omkw CGXfI+SOB6QUH0dh5CFX5XP05OY4KWJsT10UNYiAghUAlS4mvwATHixWAvLcvtSiWjNh sPmQ== X-Gm-Message-State: AOJu0YyZmFCahNWdwnPAYdFCLJsaZDRc/kMu7YZqqTUMT7CfYafc/m7I EjcHzoyzIove016fjLt6TwWCT9fEzDL/DJSn1v5CndVR2DlPsRTPkmCHyD5z0aWOlpI= X-Gm-Gg: Acq92OGRYmabUGxDERkqQ1XxkyAsso/hdoYNy3SM3dhBBVK+kfqwQG6BLVrIcKJkXQX NuncTAUw4tN5AaCuJC+ROxwNUhmpHLNM4UckzLqYliUvVLRX+4GvanKylfXXJn1nFl+pn+Me96X ZBuBOA1ah7XhvHlVuUdCVvMDKZVtjkE9eHfAgCPWKSMQ9DS92YQU7qWbf65lDaPGUQ/rzeSrCQb I9YxZbnGW7g7f+SqdMVsyV+pWY6eJmc6GM+KjGJQQ3HpuH43prqKjFivKxLotKsjS6qy17FQe3P bC7/X/qbKOy22++ylv5PXAIZu/i27Z9qkG7L0ZOLPfAeRG1mhak3rinEZu/vsz5rtNrGRnVE9FT iKqoZe4ugYLlumk4UHfsT2F/czXVht8Z3HrBV34EFqEYb6FHNFef+QUI6RUybZkN0h+K+RjlXsX ZQfVjr6Zh7mPf8f4j1570c X-Received: by 2002:a05:6808:14d0:b0:47b:d505:d84 with SMTP id 5614622812f47-482e576317fmr10571930b6e.33.1779139683896; Mon, 18 May 2026 14:28:03 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:30 -0600 Subject: [PATCH v2 12/37] bsd-user: Add do_bsd_setsockopt and socket option definitions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-12-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Jessica Clarke , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10944; i=imp@bsdimp.com; h=from:subject:message-id; bh=HFUKZ0KW+q4ANQLfrca+alp3qDZmSuVh3eAS8iwM+Zo=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RH0Q2IiP94aNVYQ1OdrNUydOOewv7IDAADV g9HzwtVvbuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AAeyD/oCCN47uQq7TT1foTD5SEtL3/J+NNJneBqMBTIYY2VLHDhzKg3Xy7oKRK/8OePHJfz1WXV j2pQFfpOwPXtRv7Dg6m+410fiqpzvI16FhdWUvnZk9mfGBZEK/+G4mkM/Och+EFl4/FAUL9SfL1 EHUFSP64bmJsYhniFYspkk7z+5g4DQd/6n1pS1iWQJlPly5yXn6p/ld3xqtaRYD5E556gwMqz0q dN/cCU2AhVf1FtOZ27/JeJED+yVLHzbYQo4A/c3JtSvJzrE+Uh+1IZcdOFeRZjT6AcYOirRvzrb 9mD+Dw+lP9MZAR/OYEQTWmvqdUgePlub+N7DNk/fb+QdXdn8zwTzTR5vw/3B6iMhiq0LrrXg/Zs KlziWMMXj1SmQBNnUDs3dHuxWpv2+SjVktEE/pE44DVsGe5MG/MdImEiZyxVY4abQiEhE+NMNj4 Dp2Q7xpi+50udcERwiwe3v1SewAoGAYiYCWkP+N2m3xEZsp0+Lpb5K4e8h/bVYrDOZ0cFBOvikY zqf+OpapgujLWRtQTZlKmCk9pyBqoKWzEzEaFs//Sp2lhGZAnyLTkRn1Fhhcio68P7e28c2QA8u SOy1x++5O4GOKzvE6uxR9JRI/79kDU0GIeD7o9J5vl4FR40EIMigwevJBT7TqwA91tc/BseCsZb DwvYz9Svke+YJNA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::235; envelope-from=imp@bsdimp.com; helo=mail-oi1-x235.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139903349154100 Add the setsockopt(2) implementation handling IPPROTO_TCP, IPPROTO_IP, IPPROTO_IPV6, and SOL_SOCKET levels. Also add the TARGET_SO_* socket option definitions and TARGET_SOL_SOCKET to syscall_defs.h. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Jessica Clarke Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-socket.h | 261 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 261 insertions(+) diff --git a/bsd-user/freebsd/os-socket.h b/bsd-user/freebsd/os-socket.h index 279157dd05..897a1f4d2f 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -138,5 +138,266 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong targ= et_msg, return ret; } =20 +/* setsockopt(2) */ +static inline abi_long do_bsd_setsockopt(int sockfd, int level, int optnam= e, + abi_ulong optval_addr, socklen_t optlen) +{ + abi_long ret; + int val; + struct ip_mreqn *ip_mreq; + void *p; + + switch (level) { + case IPPROTO_TCP: + /* TCP options all take an 'int' value. */ + if (optlen < sizeof(uint32_t)) { + return -TARGET_EINVAL; + } + if (get_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + ret =3D get_errno(setsockopt(sockfd, level, optname, &val, sizeof(= val))); + break; + + case IPPROTO_IP: + switch (optname) { + case IP_OPTIONS: + p =3D lock_user(VERIFY_READ, optval_addr, optlen, 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(setsockopt(sockfd, level, optname, p, optlen= )); + unlock_user(p, optval_addr, 0); + break; + case IP_HDRINCL:/* int; header is included with data */ + case IP_TOS: /* int; IP type of service and preced. */ + case IP_TTL: /* int; IP time to live */ + case IP_RECVOPTS: /* bool; receive all IP opts w/dgram */ + case IP_RECVRETOPTS: /* bool; receive IP opts for response */ + case IP_RECVDSTADDR: /* bool; receive IP dst addr w/dgram */ + case IP_MULTICAST_IF:/* u_char; set/get IP multicast i/f */ + case IP_MULTICAST_TTL:/* u_char; set/get IP multicast ttl */ + case IP_MULTICAST_LOOP:/*u_char;set/get IP multicast loopback */ + case IP_PORTRANGE: /* int; range to choose for unspec port */ + case IP_RECVIF: /* bool; receive reception if w/dgram */ + case IP_IPSEC_POLICY: /* int; set/get security policy */ + case IP_RECVTTL: /* bool; receive reception TTL w/dgram */ + val =3D 0; + if (optlen >=3D sizeof(uint32_t)) { + if (get_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + } else if (optlen >=3D 1) { + if (get_user_u8(val, optval_addr)) { + return -TARGET_EFAULT; + } + } + ret =3D get_errno(setsockopt(sockfd, level, optname, &val, + sizeof(val))); + break; + + case IP_ADD_MEMBERSHIP: /*ip_mreq; add an IP group membership */ + case IP_DROP_MEMBERSHIP:/*ip_mreq; drop an IP group membership*/ + if (optlen < sizeof(struct target_ip_mreq) || + optlen > sizeof(struct target_ip_mreqn)) { + return -TARGET_EINVAL; + } + ip_mreq =3D (struct ip_mreqn *) alloca(optlen); + ret =3D target_to_host_ip_mreq(ip_mreq, optval_addr, optlen); + if (is_error(ret)) { + return -TARGET_EFAULT; + } + ret =3D get_errno(setsockopt(sockfd, level, optname, ip_mreq, + optlen)); + break; + + default: + goto unimplemented; + } + break; + + case IPPROTO_IPV6: + switch (optname) { + case IPV6_UNICAST_HOPS: /* int; IP6 hops */ + case IPV6_MULTICAST_IF: /* u_int; set/get IP6 multicast i/f */ + case IPV6_MULTICAST_HOPS: /* int; set/get IP6 multicast hops */ + case IPV6_MULTICAST_LOOP: /* u_int; set/get IP6 multicast loopba= ck */ + case IPV6_PORTRANGE: /* int; range to choose for unspec por= t */ + case IPV6_CHECKSUM: /* int; checksum offset for raw socket= */ + case IPV6_V6ONLY: /* bool; make AF_INET6 sockets v6 only= */ + case IPV6_RECVPKTINFO: /* bool; recv if, dst addr */ + case IPV6_RECVHOPLIMIT: /* bool; recv hop limit */ + case IPV6_RECVRTHDR: /* bool; recv routing header */ + case IPV6_RECVHOPOPTS: /* bool; recv hop-by-hop option */ + case IPV6_RECVDSTOPTS: /* bool; recv dst option after rthdr */ + case IPV6_USE_MIN_MTU: /* bool; send packets at the minimum M= TU */ + case IPV6_RECVPATHMTU: /* bool; notify an according MTU */ + case IPV6_HOPLIMIT: /* int; send hop limit */ + case IPV6_RECVTCLASS: /* bool; recv traffic class values */ + case IPV6_AUTOFLOWLABEL: /* bool; attach flowlabel automagicall= y */ + case IPV6_TCLASS: /* int; send traffic class value */ + case IPV6_DONTFRAG: /* bool; disable IPv6 fragmentation */ + case IPV6_PREFER_TEMPADDR: /* int; prefer temporary addresses */ + case IPV6_BINDANY: /* bool: allow bind to any address */ +#ifdef IPV6_BINDMULTI + case IPV6_BINDMULTI: /* bool; allow multibind to same addr/= port*/ +#endif /* IPV6_BINDMULTI */ +#ifdef IPV6_RSS_LISTEN_BUCKET + case IPV6_RSS_LISTEN_BUCKET: /* int; set RSS listen bucket */ +#endif /* IPV6_RSS_LISTEN_BUCKET */ +#ifdef IPV6_FLOWID + case IPV6_FLOWID: /* int; flowid of given socket */ +#endif /* IPV6_FLOWID */ +#ifdef IPV6_FLOWTYPE + case IPV6_FLOWTYPE: /* int; flowtype of given socket */ +#endif /* IPV6_FLOWTYPE */ +#ifdef IPV6_RSSBUCKETID + case IPV6_RSSBUCKETID: /* int; RSS bucket ID of given socket = */ +#endif /* IPV6_RSSBUCKETID */ + val =3D 0; + if (optlen >=3D sizeof(uint32_t)) { + if (get_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + } else if (optlen >=3D 1) { + if (get_user_u8(val, optval_addr)) { + return -TARGET_EFAULT; + } + } + ret =3D get_errno(setsockopt(sockfd, level, optname, &val, + sizeof(val))); + break; + + case IPV6_JOIN_GROUP: /* ipv6_mreq; join a group membership */ + case IPV6_LEAVE_GROUP: /* ipv6_mreq; leave a group membership */ + case ICMP6_FILTER: /* icmp6_filter; icmp6 filter */ + case IPV6_IPSEC_POLICY: /* struct; get/set security policy */ + case IPV6_FW_ADD: /* add a firewall rule to chain */ + case IPV6_FW_DEL: /* delete a firewall rule from chain */ + case IPV6_FW_FLUSH: /* flush firewall rule chain */ + case IPV6_FW_ZERO: /* clear single/all firewall counter(s) */ + case IPV6_FW_GET: /* get entire firewall rule chain */ + case IPV6_RTHDRDSTOPTS: /* ip6_dest; send dst option before rthdr = */ + case IPV6_PATHMTU: /* mtuinfo; get the current path MTU */ + case IPV6_PKTINFO: /* in6_pktinfo; send if, src addr */ + case IPV6_NEXTHOP: /* sockaddr; next hop addr */ + case IPV6_HOPOPTS: /* ip6_hbh; send hop-by-hop option */ + case IPV6_DSTOPTS: /* ip6_dest; send dst option befor rthdr */ + case IPV6_RTHDR: /* ip6_rthdr; send routing header */ + case IPV6_MSFILTER: /* struct __msfilterreq; */ + default: + goto unimplemented; + } + break; + + case TARGET_SOL_SOCKET: + switch (optname) { + /* Options with 'int' argument. */ + case TARGET_SO_DEBUG: + optname =3D SO_DEBUG; + break; + + case TARGET_SO_REUSEADDR: + optname =3D SO_REUSEADDR; + break; + + case TARGET_SO_REUSEPORT: + optname =3D SO_REUSEPORT; + break; + + case TARGET_SO_KEEPALIVE: + optname =3D SO_KEEPALIVE; + break; + + case TARGET_SO_DONTROUTE: + optname =3D SO_DONTROUTE; + break; + + case TARGET_SO_LINGER: + optname =3D SO_LINGER; + break; + + case TARGET_SO_BROADCAST: + optname =3D SO_BROADCAST; + break; + + case TARGET_SO_OOBINLINE: + optname =3D SO_OOBINLINE; + break; + + case TARGET_SO_SNDBUF: + optname =3D SO_SNDBUF; + break; + + case TARGET_SO_RCVBUF: + optname =3D SO_RCVBUF; + break; + + case TARGET_SO_SNDLOWAT: + optname =3D SO_RCVLOWAT; + break; + + case TARGET_SO_RCVLOWAT: + optname =3D SO_RCVLOWAT; + break; + + case TARGET_SO_SNDTIMEO: + optname =3D SO_SNDTIMEO; + break; + + case TARGET_SO_RCVTIMEO: + optname =3D SO_RCVTIMEO; + break; + + case TARGET_SO_ACCEPTFILTER: + goto unimplemented; + + case TARGET_SO_NOSIGPIPE: + optname =3D SO_NOSIGPIPE; + break; + + case TARGET_SO_TIMESTAMP: + optname =3D SO_TIMESTAMP; + break; + + case TARGET_SO_BINTIME: + optname =3D SO_BINTIME; + break; + + case TARGET_SO_ERROR: + optname =3D SO_ERROR; + break; + + case TARGET_SO_SETFIB: + optname =3D SO_SETFIB; + break; + +#ifdef SO_USER_COOKIE + case TARGET_SO_USER_COOKIE: + optname =3D SO_USER_COOKIE; + break; +#endif + default: + goto unimplemented; + } + if (optlen < sizeof(uint32_t)) { + return -TARGET_EINVAL; + } + if (get_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + ret =3D get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, + sizeof(val))); + break; + default: +unimplemented: + gemu_log("Unsupported setsockopt level=3D%d optname=3D%d\n", + level, optname); + ret =3D -TARGET_ENOPROTOOPT; + } + + return ret; +} + =20 #endif /* BSD_USER_FREEBSD_OS_SOCKET_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139771; cv=none; d=zohomail.com; s=zohoarc; b=WWNIPOL9+RnDBr28NeTlXrC9NY3srDsVrLvIwh1ssW6XZYkwYkOVmYyGAG2UMxvghpPOGvyayZgbcZfjrhTkesgVnGm1NnuIQtZ+Q/yUi+1Fpt73DHm17gDWDyUf5BhvmWX7SWpCQcPydSSVQWCuuo6JAvRTrPypYCv3bD9fYnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139771; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ffGWOGouYH/3qhNFMBbsUWZO8GGJWXnR9Uk1mAQ4d2A=; b=ZACDZX2GU92r/qZuZzz48w7+E3sOZ1KTW2IBT74gBV/D3OPziISpMuYpLXI4UGlD6dAWsd+yGAzPweZXLH+wUugeu4mk/iUDQ5ZzW0p+mset1nOPwEaZYGgzOr+w6q4QEKoZqahY4CR45f9W81ojfzftWnU5z1+rq1hBUX8FeUI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177913977129571.46401869791111; Mon, 18 May 2026 14:29:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VQ-0000RB-Tf; Mon, 18 May 2026 17:28:08 -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 1wP5VP-0000QN-Rx for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:07 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VN-0000Sb-RD for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:07 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-479d5ff103aso1516327b6e.0 for ; Mon, 18 May 2026 14:28:05 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139685; x=1779744485; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ffGWOGouYH/3qhNFMBbsUWZO8GGJWXnR9Uk1mAQ4d2A=; b=D40rycjwQzFKsxjHGzt9uYvXS2rQfBCwR8UFBy29aDawNf0jEcv8A+UklRUdcQjeia UriVut+S2dFEWNmuiUpR7R5GssDa+lrkPTdV8VJfPAZuwpQ+gayhvfuZnhMhW4XT7oR5 pWi8KOSvEVh/hFgOvO2FC/aoSunyV8ULe9GweLVcdQ/nUYtPug+OqQG4WPC/XPSuKQXH iJsxj/COc/DzMZJAi1PPdRH1Mql8s9ThJ7Dxz5rPF4MtnSB7I1Qocu/1gbm98OZwISZS 6GWokN+PrmhD5uwUwQHN5FtjVt1XRHJSkkilbmdkijvzSGdajDdTTebxGE691Kw2jG7k xgXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139685; x=1779744485; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ffGWOGouYH/3qhNFMBbsUWZO8GGJWXnR9Uk1mAQ4d2A=; b=XfKpH+15LM303Z4wqj1YhsDzvkJyUcZcD/WZRXiDxGZ79gzafIxXcW53uawq0QnGSz kIVef9ZNGVcPOqAGquB1Pd/UDnhNQCKhrLJxijfFEEkfLSb5D+O4YotdXb47uEnoUg5Y Mp5dnu6Rfwdnlvdg1mralm/0AHBYfWSf+N1/9pzsH7PqPmQUyToHobkLTQa917Z2U0E5 MNdimla0FpXf0i0XaP04cHBawTd5AECZik9V8hb2jb9Tg5Ag9EIpaZuCnkiZLOBlKMvr NuWRXL/pQ5B81dIiFmY//9L7TSXn32GhB6fcbb56uyjbweKq0JL0w7K/3zDk6/k2JJLv 4uOg== X-Gm-Message-State: AOJu0YwMjKuixpATCogwpI1W9UUh0qgZ2LnjGwOgFPxjW41LKZYulBXT 0tDXlpsE8xR2pAv0IYtPBmOqQCB8o14FIwSkVLILMr2ZWFBncsXUJSkB+d9BpWEEhgM= X-Gm-Gg: Acq92OHTR4vKedR7MpP0SWdFexSM/BLdWsScljjwngjaFUuEwpc7RtVgn1Qy6Ockf3D yz03XYb+ZwUszSIt2vE/B+m/dxyLE5jDaGrV0pBA0rwydI1tzOlKz6ckolBkQ16+sNqrYLApl2B iocNtmIcsXNUkg9o1RGayIvLm18rLogXviHwvrtEyVNlFFTFvXnJbatHEqB+jWMw6D+VY4ACkDC c+lyp+XcBUvSIbyaJSYCSKhttZSr9pdBvBY2LUE5cQ7Z92zdscbrGHMPR3HKf/syqCXxGg8zBJl GCzzicqpifbo9cdPCdiIVHKB8HZZXqiN4fqiulm2HWPr6a/+3m0BSsoVRgOqC90AQ9U9jU0oBMv s5iQm4rKcgtm9gC31k+csv31cUmltnzDzUMVbDV+shKFuZ+yBstDjAWckppTb6PNfP8AHwP1PCf JlHAWGYn/DTw== X-Received: by 2002:a05:6808:6f87:b0:471:f036:7926 with SMTP id 5614622812f47-482e572bbcamr11156185b6e.28.1779139684744; Mon, 18 May 2026 14:28:04 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:31 -0600 Subject: [PATCH v2 13/37] bsd-user: Add do_bsd_getsockopt MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-13-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10985; i=imp@bsdimp.com; h=from:subject:message-id; bh=ZroN70mzMZjT1PVArrNmYN1/jgU1sbqaHOJX9r8bxU8=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RH4k4/puELGgP5AAg4Br+Ir32zvXrcvgQmG oFqJ7+JaNyJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AIF2D/wJdwzw106FrCLJNK9J9o9a0rcMq5cqeznREM3av+KsLZIrMJRPAaJoCLnJ2vI09R1jULR A1CozHaSGzQY+3ePNEkqQ/O5wiv74PhFFj7RA1L+RLiJGEncG0J42RHgVYKww9OBgZBG++RBk2i Xp8tLGu1g3JD6nE+mz5WjwCBK2QrsXaTalBksfKv2KbNKbC9tXJeY/ugr15pJCVZ2nSM6xd9G9y i2pRatDulxyR6AGl9LQeeZVSCXPXvBHWkjCNd0KRBoEH51KD0TL+0T3c8BcpXHfwzPiY/7qaiiV iN59fpEhIBai+mg4aqfAFpj+7C3H4XI5yzfIxedN+zot06WBdIqXsU1WGQ8oww67Lm04fK7LdXi qQ8jewvjcaFoVxZGnWAd0bzar66FC79WocCH94bcmmWNASezPKzIU/hHh5187lraqiY9AlM6iFx bm44eLfVWxdniXwv2XEH/EgCkjV6A9/+eRUCFICJShNdEvBd0/9LXO33cGgoB4qxDLZw84k+aOd Nqe8Z5D3Z16AQFn4ULi2xKvSWQm9+sNdAt3aOBF6XzuxE5OtuRD7CP+nrffMiwI+xawUdkORLg0 mqwG4Ch1OKaIKzMbQeOGOZcNr/dpzvP3+l8ApBlPaAManctU2NIIk9jKuFAmNIG7mKPN7n2EvA9 WBTEztNTB7vvlCw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::22a; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22a.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139773205154100 Add the getsockopt(2) implementation handling SOL_SOCKET, IPPROTO_TCP, IPPROTO_IP, and IPPROTO_IPV6 levels with proper target-to-host option name translation. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-socket.h | 284 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 284 insertions(+) diff --git a/bsd-user/freebsd/os-socket.h b/bsd-user/freebsd/os-socket.h index 897a1f4d2f..f8521780c1 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -399,5 +399,289 @@ unimplemented: return ret; } =20 +/* getsockopt(2) */ +static inline abi_long do_bsd_getsockopt(int sockfd, int level, int optnam= e, + abi_ulong optval_addr, abi_ulong optlen) +{ + abi_long ret; + int len, val; + socklen_t lv; + void *p; + + switch (level) { + case TARGET_SOL_SOCKET: + level =3D SOL_SOCKET; + switch (optname) { + + /* These don't just return a single integer */ + case TARGET_SO_LINGER: + case TARGET_SO_RCVTIMEO: + case TARGET_SO_SNDTIMEO: + case TARGET_SO_ACCEPTFILTER: + goto unimplemented; + + /* Options with 'int' argument. */ + case TARGET_SO_DEBUG: + optname =3D SO_DEBUG; + goto int_case; + + case TARGET_SO_REUSEADDR: + optname =3D SO_REUSEADDR; + goto int_case; + + case TARGET_SO_REUSEPORT: + optname =3D SO_REUSEPORT; + goto int_case; + + case TARGET_SO_TYPE: + optname =3D SO_TYPE; + goto int_case; + + case TARGET_SO_ERROR: + optname =3D SO_ERROR; + goto int_case; + + case TARGET_SO_DONTROUTE: + optname =3D SO_DONTROUTE; + goto int_case; + + case TARGET_SO_BROADCAST: + optname =3D SO_BROADCAST; + goto int_case; + + case TARGET_SO_SNDBUF: + optname =3D SO_SNDBUF; + goto int_case; + + case TARGET_SO_RCVBUF: + optname =3D SO_RCVBUF; + goto int_case; + + case TARGET_SO_KEEPALIVE: + optname =3D SO_KEEPALIVE; + goto int_case; + + case TARGET_SO_OOBINLINE: + optname =3D SO_OOBINLINE; + goto int_case; + + case TARGET_SO_TIMESTAMP: + optname =3D SO_TIMESTAMP; + goto int_case; + + case TARGET_SO_RCVLOWAT: + optname =3D SO_RCVLOWAT; + goto int_case; + + case TARGET_SO_LISTENINCQLEN: + optname =3D SO_LISTENINCQLEN; + goto int_case; + + default: +int_case: + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + lv =3D sizeof(lv); + ret =3D get_errno(getsockopt(sockfd, level, optname, &val, &lv= )); + if (ret < 0) { + return ret; + } + if (len > lv) { + len =3D lv; + } + if (len =3D=3D 4) { + if (put_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + } else { + if (put_user_u8(val, optval_addr)) { + return -TARGET_EFAULT; + } + } + if (put_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + break; + + } + break; + + case IPPROTO_TCP: + /* TCP options all take an 'int' value. */ + goto int_case; + + case IPPROTO_IP: + switch (optname) { + case IP_OPTIONS: + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + lv =3D (socklen_t)len; + p =3D lock_user(VERIFY_WRITE, optval_addr, len, 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(getsockopt(sockfd, level, optname, p, &lv)); + unlock_user(p, optval_addr, len); + if (put_user_u32(lv, optlen)) { + return -TARGET_EFAULT; + } + break; + case IP_HDRINCL: + case IP_TOS: + case IP_TTL: + case IP_RECVOPTS: + case IP_RECVRETOPTS: + case IP_RECVDSTADDR: + + case IP_RETOPTS: +#if defined(IP_RECVTOS) + case IP_RECVTOS: +#endif + case IP_MULTICAST_TTL: + case IP_MULTICAST_LOOP: + case IP_PORTRANGE: + case IP_IPSEC_POLICY: + case IP_ONESBCAST: + case IP_BINDANY: + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + lv =3D sizeof(lv); + ret =3D get_errno(getsockopt(sockfd, level, optname, + &val, &lv)); + if (ret < 0) { + return ret; + } + if (len < sizeof(int) && len > 0 && val >=3D 0 && + val < 255) { + len =3D 1; + if (put_user_u32(len, optlen) || + put_user_u8(val, optval_addr)) { + return -TARGET_EFAULT; + } + } else { + if (len > sizeof(int)) { + len =3D sizeof(int); + } + if (put_user_u32(len, optlen) || + put_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + } + break; + + default: + goto unimplemented; + } + break; + + case IPPROTO_IPV6: + switch (optname) { + case IPV6_UNICAST_HOPS: /* int; IP6 hops */ + case IPV6_MULTICAST_IF: /* u_int; set/get IP6 multicast i/f */ + case IPV6_MULTICAST_HOPS: /* int; set/get IP6 multicast hops */ + case IPV6_MULTICAST_LOOP: /* u_int; set/get IP6 multicast loopba= ck */ + case IPV6_PORTRANGE: /* int; range to choose for unspec por= t */ + case IPV6_CHECKSUM: /* int; checksum offset for raw socket= */ + case IPV6_V6ONLY: /* bool; make AF_INET6 sockets v6 only= */ + case IPV6_RECVPKTINFO: /* bool; recv if, dst addr */ + case IPV6_RECVHOPLIMIT: /* bool; recv hop limit */ + case IPV6_RECVRTHDR: /* bool; recv routing header */ + case IPV6_RECVHOPOPTS: /* bool; recv hop-by-hop option */ + case IPV6_RECVDSTOPTS: /* bool; recv dst option after rthdr */ + case IPV6_USE_MIN_MTU: /* bool; send packets at the minimum M= TU */ + case IPV6_RECVPATHMTU: /* bool; notify an according MTU */ + case IPV6_HOPLIMIT: /* int; send hop limit */ + case IPV6_RECVTCLASS: /* bool; recv traffic class values */ + case IPV6_AUTOFLOWLABEL: /* bool; attach flowlabel automagicall= y */ + case IPV6_TCLASS: /* int; send traffic class value */ + case IPV6_DONTFRAG: /* bool; disable IPv6 fragmentation */ + case IPV6_PREFER_TEMPADDR: /* int; prefer temporary addresses */ + case IPV6_BINDANY: /* bool: allow bind to any address */ +#ifdef IPV6_BINDMULTI + case IPV6_BINDMULTI: /* bool; allow multibind to same addr/= port*/ +#endif /* IPV6_BINDMULTI */ +#ifdef IPV6_RSS_LISTEN_BUCKET + case IPV6_RSS_LISTEN_BUCKET: /* int; set RSS listen bucket */ +#endif /* IPV6_RSS_LISTEN_BUCKET */ +#ifdef IPV6_FLOWID + case IPV6_FLOWID: /* int; flowid of given socket */ +#endif /* IPV6_FLOWID */ +#ifdef IPV6_FLOWTYPE + case IPV6_FLOWTYPE: /* int; flowtype of given socket */ +#endif /* IPV6_FLOWTYPE */ +#ifdef IPV6_RSSBUCKETID + case IPV6_RSSBUCKETID: /* int; RSS bucket ID of given socket = */ +#endif /* IPV6_RSSBUCKETID */ + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + lv =3D sizeof(lv); + ret =3D get_errno(getsockopt(sockfd, level, optname, + &val, &lv)); + if (ret < 0) { + return ret; + } + if (len < sizeof(int) && len > 0 && val >=3D 0 && + val < 255) { + len =3D 1; + if (put_user_u32(len, optlen) || + put_user_u8(val, optval_addr)) { + return -TARGET_EFAULT; + } + } else { + if (len > sizeof(int)) { + len =3D sizeof(int); + } + if (put_user_u32(len, optlen) || + put_user_u32(val, optval_addr)) { + return -TARGET_EFAULT; + } + } + break; + + case IPV6_JOIN_GROUP: /* ipv6_mreq; join a group membership */ + case IPV6_LEAVE_GROUP: /* ipv6_mreq; leave a group membership */ + case ICMP6_FILTER: /* icmp6_filter; icmp6 filter */ + case IPV6_IPSEC_POLICY: /* struct; get/set security policy */ + case IPV6_FW_ADD: /* add a firewall rule to chain */ + case IPV6_FW_DEL: /* delete a firewall rule from chain */ + case IPV6_FW_FLUSH: /* flush firewall rule chain */ + case IPV6_FW_ZERO: /* clear single/all firewall counter(s) */ + case IPV6_FW_GET: /* get entire firewall rule chain */ + case IPV6_RTHDRDSTOPTS: /* ip6_dest; send dst option before rthdr = */ + case IPV6_PATHMTU: /* mtuinfo; get the current path MTU */ + case IPV6_PKTINFO: /* in6_pktinfo; send if, src addr */ + case IPV6_NEXTHOP: /* sockaddr; next hop addr */ + case IPV6_HOPOPTS: /* ip6_hbh; send hop-by-hop option */ + case IPV6_DSTOPTS: /* ip6_dest; send dst option befor rthdr */ + case IPV6_RTHDR: /* ip6_rthdr; send routing header */ + case IPV6_MSFILTER: /* struct __msfilterreq; */ + default: + goto unimplemented; + } + break; + + default: +unimplemented: + gemu_log("getsockopt level=3D%d optname=3D%d not yet supported\n", + level, optname); + ret =3D -TARGET_EOPNOTSUPP; + break; + } + return ret; +} + =20 #endif /* BSD_USER_FREEBSD_OS_SOCKET_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139713; cv=none; d=zohomail.com; s=zohoarc; b=JZPs0spO6jbqU0oFuSH754Fi7UcfQDw8ObIGr1MIOJobktKaheTSEy4JezzckztPqrYcWuvqXF7f0WyEzVmKNoT/HVbhot1EBBq1QsqOgnp03U3Yma+5FmkJpfD5RVaOqTxLKKpfFIcXGFAcvv5UoQHHwwaEsCFpLm8r70TljXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139713; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ektwjMp/LzL17TfgstxC86tlwuXgCikFmtXF+htjc5I=; b=Fv9r7QHW1em2I+uCrOCkVD6cifo7ptKd15KJ/EebNYXnYaG5zLEmmNf/itS07BVD7oWVm5Vhy9ev1yoHH6BjJuqvIwIGe9UYcv+g+FetQq4JCybf0zd+ACzCD0A2at9qdTMr7yYEEByhiREKmxZSwU6IWaV0+OSXdvQaMEoB5bI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139713331873.982501144667; Mon, 18 May 2026 14:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VR-0000S0-Q5; Mon, 18 May 2026 17:28:09 -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 1wP5VQ-0000RA-QT for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:08 -0400 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VO-0000Sq-PT for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:08 -0400 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-7dccb8644c4so1606626a34.0 for ; Mon, 18 May 2026 14:28:06 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139686; x=1779744486; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ektwjMp/LzL17TfgstxC86tlwuXgCikFmtXF+htjc5I=; b=yp7Hwu8ee0Y4ct9FgUeYBLdUmuEK4Oiu+dh9jXJZRLCTRszpiWAMmJMRNbW9eqkjEq eLaEWYcCUnbr+8/2z7ObKX9hIbeKdo8Y04uZZmEyFlM5YKruktIg0uPw23lQPUO8eNQ5 rA5d1fb8VpVHhNghmNwwdiVH8io1DcknjOA8qBr26Xw3Hdojvg3jmUnEjLoaeL9D+v+W zrF3ehN7CFYz2xs6lo9fUGRW/f4+gQKylSsGC4dFWyL/gYzkPsf8FEqqhvNDpbCKn+mc okgFVB5oMPzReVBZIVsfsvQKjWCjVLarmVtDAheENiG1EJBCRg4FO0W6X1eAVSa65+YN 5/RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139686; x=1779744486; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ektwjMp/LzL17TfgstxC86tlwuXgCikFmtXF+htjc5I=; b=ggp94EohVrJJ1KNzDx3/zpjz1rQmp8VURDG7sulMK/49EYivtjN0DtPjBdjt/H5XOm BZQn8DHXgNnsDfQUPE5gGxC1ScjFC9KZS4OjTBwi06+XSwZ5mt3/VgXvYzl9VKeYr/JU H+KjKr3z+no8XQ0YjaAQoL1n1730S/x+9be/OapvCnV7BzkeoOSRrzI0UN3J9UFmplTU aJ/5YUHoZpsDBJDiH/hthc8BwL8fZYucrw3qBFfFMBt+jIDC7L/FyfwVmBVv5PVnWilV U+/obLLsW+eV7um70Jwqgs34kLUmum7k0vssgFgPIeRGsPKFKFbekYkpfi7CRErhnT1n ad1g== X-Gm-Message-State: AOJu0YzfvNLEqDwVNCwXu1k/8zDzLvjH9diIb7Lmyje1PtHqio/zKhZ4 hjXc8hIJFT+oosE/dXixwPoT5S5QiVQqX20Izgm+8T29SMdzgNJ4UkMjSP7EnDRxlxA= X-Gm-Gg: Acq92OHSTWK20+Yd1iI7SVOsGbBaTYSfP9u84wi7fRHULNQSpfRhCtN/0nHyMT/Sxuc FMoRKgYmu10kSOBEDTnKoxjPLn+0RlwhlF70XhXve4psnronQYZRmPaZbYGnWWy6UiC/7G+RgxD dc/zaU8jBJWC2M7YvKywYaewIarq40V39jdJbFsqDzMLZJZ6644N7JHwe++rYWXA3xYowsNwFA2 +DGP1i6db0BG3KyJjbzaL+F/CHKO3cm/BHuQ+seEX+08g3svN5kXm6pktQuviTtSct4edp0btBh HWWOxIjKhhgULyZJyNdTqC59fLzsSgFSpWLzTuUjv+4t82J/weiABW3tJmlEjGNfFi5ShWvhCVh D34UT8Upuva+esZYPiBBedFsWrxfe5y83dXAKoK1vox+gFvv4yIt+omq3/WC9HDVvKWJjC/ruIw JarKqbqY66jS/sWfF1I4p0 X-Received: by 2002:a05:6830:6312:b0:7d7:4639:43ee with SMTP id 46e09a7af769-7e4ea071964mr12327579a34.3.1779139685724; Mon, 18 May 2026 14:28:05 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:32 -0600 Subject: [PATCH v2 14/37] bsd-user: Add FreeBSD socket helpers and sockaddr conversion MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-14-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7613; i=imp@bsdimp.com; h=from:subject:message-id; bh=ZjsmeB1iV30iXnseqbtwzWbLnO3Hvy7F3LvgR6/oqVc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RHCNN/hgReJz/LeFlqJLwnJo8y/fwPImFuA zc6ZE4TIcOJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AIgzD/0W2gCqk61qbEzakU6EXAeazlWhlZ13o6ZgXase6/8kNf3MDOPUnaIB0YWanbYw9Ulpmeq jdn7GruYbunptqxiUSrzvkoRifI77tXH+0Cvv8iUdTLqS57mPYlVmjqDV8+2YeXU0lRZn3YHsdq wU8h46N0R3zGYaamkMdVmVEPkbHpY6dLRTwlJj407VBjnsNnOrCAiYD9ybIa7hyYfmaQANQBW3c 9BO5I0Yz84KmMF566QLibn8CUV8gaqlLhRWgcBAoykxYUpCS5p6Idxw+iMnBfzOmxBEkP4WtNS6 7p6PXOiFfHjQP8/6Lh7HT2w5j6DBtLPa72mYTTyMaeij7Zfz/qghq9QG91vXJyw6Fl2VChKL0zt kzq7rHhj/FEk62SNUIOHGkyAQr1/EE1VRoIuzFyiTj5PEvShyOmBybAQvmgW6FW5DnFID6LYvHS g3xvApzUX+5iWSbuu8zjbrwv/Y3g+KZC6E4BRLDeEbq3f9sMZds/Di+j0U2FHRv1wA1PbCUhk89 1JKtKBj7W/++xr7wz5EoluG/mri3XM7QbG5CI5o14uWgc0YA9p+N9ZpVtU9A3+PUIGdMDnJbUS/ WwNxeyHsmuKsl68FNeB/Pkob2lEPkxuUli2CsKtGeAeP80X6I+g3WzPiAuiMcVkuw+pfEKM3Y9p wi8MHUC4eYTLn6w== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::329; envelope-from=imp@bsdimp.com; helo=mail-ot1-x329.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139716154154100 Complete os-socket.h with setfib, bindat, connectat, and accept4. Add bsd-socket.c with target_to_host_sockaddr, host_to_target_sockaddr, and target_to_host_ip_mreq helper functions, and add it to the build. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/bsd-socket.c | 98 ++++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-socket.h | 85 +++++++++++++++++++++++++++++++++++++- bsd-user/meson.build | 1 + bsd-user/qemu-bsd.h | 8 ++++ 4 files changed, 191 insertions(+), 1 deletion(-) diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 0000000000..cc45400e4c --- /dev/null +++ b/bsd-user/bsd-socket.c @@ -0,0 +1,98 @@ +/* + * BSD socket system call related helpers + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" + +#include +#include +#include +#include + +#include "qemu.h" +#include "qemu-bsd.h" + +/* + * socket conversion + */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_a= ddr, + socklen_t len) +{ + const socklen_t unix_maxlen =3D sizeof(struct sockaddr_un); + sa_family_t sa_family; + struct target_sockaddr *target_saddr; + + target_saddr =3D lock_user(VERIFY_READ, target_addr, len, 1); + if (target_saddr =3D=3D 0) { + return -TARGET_EFAULT; + } + + sa_family =3D target_saddr->sa_family; + + /* + * Oops. The caller might send a incomplete sun_path; sun_path + * must be terminated by \0 (see the manual page), but unfortunately + * it is quite common to specify sockaddr_un length as + * "strlen(x->sun_path)" while it should be "strlen(...) + 1". We will + * fix that here if needed. + */ + if (target_saddr->sa_family =3D=3D AF_UNIX) { + if (len < unix_maxlen && len > 0) { + char *cp =3D (char *)target_saddr; + + if (cp[len - 1] && !cp[len]) { + len++; + } + } + if (len > unix_maxlen) { + len =3D unix_maxlen; + } + } + + memcpy(addr, target_saddr, len); + addr->sa_family =3D sa_family; /* type uint8_t */ + addr->sa_len =3D target_saddr->sa_len; /* type uint8_t */ + unlock_user(target_saddr, target_addr, 0); + + return 0; +} + +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *a= ddr, + socklen_t len) +{ + struct target_sockaddr *target_saddr; + + target_saddr =3D lock_user(VERIFY_WRITE, target_addr, len, 0); + if (target_saddr =3D=3D 0) { + return -TARGET_EFAULT; + } + memcpy(target_saddr, addr, len); + target_saddr->sa_family =3D addr->sa_family; /* type uint8_t */ + target_saddr->sa_len =3D addr->sa_len; /* type uint8_t */ + unlock_user(target_saddr, target_addr, len); + + return 0; +} + +abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, abi_ulong target_a= ddr, + socklen_t len) +{ + struct target_ip_mreqn *target_smreqn; + + target_smreqn =3D lock_user(VERIFY_READ, target_addr, len, 1); + if (target_smreqn =3D=3D 0) { + return -TARGET_EFAULT; + } + mreqn->imr_multiaddr.s_addr =3D target_smreqn->imr_multiaddr.s_addr; + mreqn->imr_address.s_addr =3D target_smreqn->imr_address.s_addr; + if (len =3D=3D sizeof(struct target_ip_mreqn)) { + mreqn->imr_ifindex =3D tswap32(target_smreqn->imr_ifindex); + } + unlock_user(target_smreqn, target_addr, 0); + + return 0; +} + diff --git a/bsd-user/freebsd/os-socket.h b/bsd-user/freebsd/os-socket.h index f8521780c1..6ad16f73b5 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -334,7 +334,7 @@ static inline abi_long do_bsd_setsockopt(int sockfd, in= t level, int optname, break; =20 case TARGET_SO_SNDLOWAT: - optname =3D SO_RCVLOWAT; + optname =3D SO_SNDLOWAT; break; =20 case TARGET_SO_RCVLOWAT: @@ -683,5 +683,88 @@ unimplemented: return ret; } =20 +/* setfib(2) */ +static inline abi_long do_freebsd_setfib(abi_long fib) +{ + + return get_errno(setfib(fib)); +} + +/* bindat(2) */ +static inline abi_long do_freebsd_bindat(int fd, int sockfd, + abi_ulong target_addr, socklen_t addrlen) +{ + abi_long ret; + void *addr; + + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + + addr =3D alloca(addrlen + 1); + ret =3D target_to_host_sockaddr(addr, target_addr, addrlen); + if (is_error(ret)) { + return ret; + } + + return get_errno(bindat(fd, sockfd, addr, addrlen)); +} + +/* connectat(2) */ +static inline abi_long do_freebsd_connectat(int fd, int sockfd, + abi_ulong target_addr, socklen_t addrlen) +{ + abi_long ret; + void *addr; + + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + addr =3D alloca(addrlen); + + ret =3D target_to_host_sockaddr(addr, target_addr, addrlen); + + if (is_error(ret)) { + return ret; + } + + return get_errno(connectat(fd, sockfd, addr, addrlen)); +} + +/* accept4(2) */ +static inline abi_long do_freebsd_accept4(int fd, abi_ulong target_addr, + abi_ulong target_addrlen_addr, int flags) +{ + socklen_t addrlen; + void *addr; + abi_long ret; + + if (target_addr =3D=3D 0) { + return get_errno(accept(fd, NULL, NULL)); + } + /* return EINVAL if addrlen pointer is invalid */ + if (get_user_u32(addrlen, target_addrlen_addr)) { + return -TARGET_EINVAL; + } + if ((int)addrlen < 0) { + return -TARGET_EINVAL; + } + if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) { + return -TARGET_EINVAL; + } + addr =3D alloca(addrlen); + + ret =3D get_errno(accept4(fd, addr, &addrlen, flags)); + if (!is_error(ret)) { + if (is_error(host_to_target_sockaddr(target_addr, addr, addrlen)))= { + close(ret); + ret =3D -TARGET_EFAULT; + } else if (put_user_u32(addrlen, target_addrlen_addr)) { + close(ret); + ret =3D -TARGET_EFAULT; + } + } + return ret; +} =20 #endif /* BSD_USER_FREEBSD_OS_SOCKET_H */ diff --git a/bsd-user/meson.build b/bsd-user/meson.build index 2abcae5122..ab6ddf2e9f 100644 --- a/bsd-user/meson.build +++ b/bsd-user/meson.build @@ -11,6 +11,7 @@ bsd_user_ss.add(files( 'bsd-mem.c', 'bsd-misc.c', 'bsd-proc.c', + 'bsd-socket.c', 'bsdload.c', 'elfload.c', 'main.c', diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h index f7c8338213..b4ca8268c9 100644 --- a/bsd-user/qemu-bsd.h +++ b/bsd-user/qemu-bsd.h @@ -32,6 +32,14 @@ int host_to_target_waitstatus(int status); void h2g_rusage(const struct rusage *rusage, struct target_freebsd_rusage *target_rusage); =20 +/* bsd-socket.c */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_a= ddr, + socklen_t len); +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *a= ddr, + socklen_t len); +abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, abi_ulong target_a= ddr, + socklen_t len); + /* bsd-misc.c */ abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid= ); =20 --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139762; cv=none; d=zohomail.com; s=zohoarc; b=W/fqkSGNrfCRuRG7MOm8HB/7YhvQPyHHW8iFHYvVfaC/dgpJBCtgF+ukWks1NqSvDbtvc+YhmIhc34+rLCJcWgxrdpK85llEpzGo25X4fmxmhZBNUCcutl9nDWiBwjflQlqqItO/qKAJSLlf3KXy/FhwkwnImizyqNIyIkjx2R8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139762; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FbApW7rZI6sL6Z/Hr+ekwEC9JyWrh50/L7jk7LMyAm4=; b=N9QpX+9WL6WDZYmNytN301rYaarUELhz9pPK70qxq3oxMmulGLDHp5MpZBg8dFKtbPe4FeQaDzULvS6DfMVDG9N+Cp9PY8wI22OK9OSN13bGKHDBodwx2BnW1OtjZL1aXgvv8T+gR5kAc3xTxqlJmvSeDC3/jVMzAPAVB9tmkLM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139762312315.47020106961895; Mon, 18 May 2026 14:29:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VU-0000T0-H7; Mon, 18 May 2026 17:28:13 -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 1wP5VR-0000S6-Pw for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:09 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VP-0000Sx-JK for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:09 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7de431da8fbso2619104a34.1 for ; Mon, 18 May 2026 14:28:07 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139686; x=1779744486; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FbApW7rZI6sL6Z/Hr+ekwEC9JyWrh50/L7jk7LMyAm4=; b=KHC5iFxe+7LVXGZZzKJPFPMaOg1L98Ovmoz7qDCesoGpy/8sV3+0brn2OlzgF/Yk2z k3vaKLTv7fEv7ZPvB5TljuHsJWmi9a9osj0z8tHKcSODyzPciFREzAIh3kBpy9xNIsC0 H/qhMol6z/ABQtqjEfMeJItMaOZrPZbTnVCh/MYU/ZNQ1I7+ltsWXPWmt91HYbZv70SC BXZL5QDZWUMQ7yNor1xDdTskdzowfnL0eVRfMuY+GWNWUIcV4h2FWqdJbiO7MyFBqO+x DSzxgAykl9qMf+VWQhmX8knmtjVbF3PFezS0FHEK5Pl9BRlAfvNNLeSX4Czwj0phhqhQ x3rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139686; x=1779744486; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=FbApW7rZI6sL6Z/Hr+ekwEC9JyWrh50/L7jk7LMyAm4=; b=IhGomYYsO08tJEDuyEtKhp16vjUFfDgLg07qJEEvybATGLUgS+er7Rm/xZ34CwxlFb mQg4LSzxw6jmh2z1gWqZaFT7jQBK1W7F2riUAsCdI68Uu6vmqR3VW05Co2RjTvxYD+A8 i99AsLjcecL0UP4ZetsT2skPyFoaF2U5F+ebYeF7gktMlBdXhKj2aaoHyDZdIPLciwTp 79HtFuYjKMecsB+r552rJn4rj+MZfV0elHNTzxnf6yJFj55K2+qpcgLp1k92i8Iqu9Nn zaVv+B8VYSpNkYc9UaMCTH9KtL9NyRN/u6KAThuV6LAd0hexde7ZWZ97h4knyhj9L1V4 w7Cg== X-Gm-Message-State: AOJu0Yx7j74rZk5NiIQT4g/TJeTimfeRY78MnhTh7E0phNlDFSpAUlwY exHWoNfrsH/TP9JB+dJbav6CW98owkf0JdY3bO5XDgWLMGRYmfzcMwA/AxxFYl/FMjc= X-Gm-Gg: Acq92OEik8/tuKhouU2E92OYwZZOpIqsPhimWvNbgiAwvDJ6lRaQUgMMuL/tqq/CX+W cGXK9nYZgWTBSDpTavn0qiIRzGHbD2PJx16zfPzvUzOQi9vJ4cKJaoOPmt+Py016JJPYw7YCUaU vT++K8dcxyjE6ErIoDJ6lCDEhnUZx0g61rzgu9A7j7ITeuLHLCy6yO2X/XJZUKTlowXbB+ZCzaP KV4tj3R31OtXtF6dNjbnS9Iuu5Pcflw79RP90EFtqTJ4MkvevGyE3g8l98zrnh28eb0AvGcoii5 goF0RXUf4pPcYf2pXmtQOZUDNdzysddwzPwvjBa26EDDlqxFuN0aK72VUicBXcvlT7gNzBhHJkp xJ5eIvWX8Yo/c+EC2ZljtHanBK8frrp+kZZu8+M+HEnVjoky3FotNtIDQK/PU7tFJ2653TLwjVZ yMCSWiZhXKLg== X-Received: by 2002:a05:6830:6315:b0:7dc:e2fc:53f5 with SMTP id 46e09a7af769-7e4f2a39a1emr11195664a34.9.1779139686612; Mon, 18 May 2026 14:28:06 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:33 -0600 Subject: [PATCH v2 15/37] bsd-user: Add os-socket.c with cmsg conversion functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-15-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans , Michal Meloun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10178; i=imp@bsdimp.com; h=from:subject:message-id; bh=JqmPhzahuDeg5rc6BZHHnP/NICMAIXOd7HLZVHZaNGM=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RHKoB+2vxLSuj6WkKxWdKCmfSOdgcfjUylg WVkOPY8CrqJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR ALUWD/0a5aNp/ZlDIKAUYmLBGuTxFcedglsERX0ts5gffuhPa+eUc8g8ZZMQXY2nm7TNZNwQ2hZ X9lHSLbVDDj01eeowx0YonBC1Ga8O28s2L7AzKp451iP+SX0Q9JzytUMIQ8FMBliEHUgKcC3jPW Dnxer+HRigaxOvkg8VYKEh0za3Gw97VWJ8VnUwUNyEi/qHZbV948biq7jme2dcdI6BFzx3c7ODS WvFDRWyFgo5086Ujdf8FE+h9yTLIaovOFuQRicKPaDP5HdsBWmMwAY2wB7i80UvT6vYpTEjh+Ux v8e/MBk8DipNv7cSCuRr7h9/QVG3Jl8KL+ddN1oavREgmsPlApXPhSq6hwpfYPl/SM9gW0rkB4X p9Pm0lbdgiAC/6Tkkh4/8tawksKwJUtiziB5AmFLxjSiZUbkYhD092GSehwxMF+6bhNQe8acVoO 4tCvzYhsfFCIBKbeUCVnZjx5p6GivTp3KxbaYL+LMIZDlGgXvoTUbE51M88j33SoAxZn9bJ/jKn MGIehl6mL9/MQU6fZNXT8eTFtlR6nGrR99Ckbm6D/UFABNuEIKOwIGuRG2qLPauD0m+T6/zAXBm 2YFa5/dBpBNJhsxhm8lT8d3D1hNiyFG6p+ktdi8m4WSHkRrVZdJJJFlzItSF5fi72f8JU/pOADX sTZ64lWeN8p0f2Q== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32f; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32f.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139764820154100 Add target-to-host and host-to-target control message conversion functions (t2h_freebsd_cmsg and h2t_freebsd_cmsg) for sendmsg/recvmsg support, and add os-socket.c to the FreeBSD build. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Michal Meloun Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/meson.build | 8 +- bsd-user/freebsd/os-socket.c | 234 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 240 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/meson.build b/bsd-user/freebsd/meson.build index 38f2debf7e..0fc779749d 100644 --- a/bsd-user/freebsd/meson.build +++ b/bsd-user/freebsd/meson.build @@ -4,9 +4,13 @@ bsd_syscall_nr =3D custom_target('bsd-syscall-h', command: [sh, meson.current_source_dir() / 'scripts/syscallhdr.sh', '@= INPUT@', '@OUTPUT@', 'FREEBSD']) =20 bsd_user_ss.add(files( - 'os-stat.c', + 'os-extattr.c', 'os-proc.c', + 'os-socket.c', + 'os-stat.c', 'os-sys.c', - 'os-syscall.c'), + 'os-syscall.c', + 'os-thread.c', + 'os-time.c'), bsd_syscall_nr ) diff --git a/bsd-user/freebsd/os-socket.c b/bsd-user/freebsd/os-socket.c new file mode 100644 index 0000000000..8eb728240d --- /dev/null +++ b/bsd-user/freebsd/os-socket.c @@ -0,0 +1,234 @@ +/* + * FreeBSD socket related system call helpers + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" + +#include +#include +#include + +#include "qemu.h" +#include "qemu-os.h" + +abi_long t2h_freebsd_cmsg(struct msghdr *msgh, + struct target_msghdr *target_msgh) +{ + struct cmsghdr *cmsg =3D CMSG_FIRSTHDR(msgh); + socklen_t msg_controllen; + abi_ulong target_cmsg_addr; + struct target_cmsghdr *target_cmsg, *target_cmsg_start; + socklen_t space =3D 0; + + msg_controllen =3D tswap32(target_msgh->msg_controllen); + if (msg_controllen < sizeof(struct target_cmsghdr)) { + goto the_end; + } + target_cmsg_addr =3D tswapal(target_msgh->msg_control); + target_cmsg =3D lock_user(VERIFY_READ, target_cmsg_addr, msg_controlle= n, 1); + target_cmsg_start =3D target_cmsg; + if (!target_cmsg) { + return -TARGET_EFAULT; + } + + while (cmsg && target_cmsg) { + void *data =3D CMSG_DATA(cmsg); + void *target_data =3D TARGET_CMSG_DATA(target_cmsg); + int len =3D (unsigned char *)(target_cmsg) + + tswap32(target_cmsg->cmsg_len) - (unsigned char *)target_data; + + space +=3D CMSG_SPACE(len); + if (space > msgh->msg_controllen) { + space -=3D CMSG_SPACE(len); + /* + * This is a QEMU bug, since we allocated the payload area our= selves + * (unlike overflow in host-to-target conversion, which is jus= t the + * guest giving us a buffer that's too small). It can't happen= for + * the payload types we currently support; if it becomes an is= sue in + * future we would need to improve our allocation strategy to + * something more intelligent than "twice the size of the targ= et + * buffer we're reading from". + */ + gemu_log("Host cmsg overflow\n"); + break; + } + + if (tswap32(target_cmsg->cmsg_level) =3D=3D TARGET_SOL_SOCKET) { + cmsg->cmsg_level =3D SOL_SOCKET; + } else { + cmsg->cmsg_level =3D tswap32(target_cmsg->cmsg_level); + } + cmsg->cmsg_type =3D tswap32(target_cmsg->cmsg_type); + cmsg->cmsg_len =3D CMSG_LEN(len); + + if (cmsg->cmsg_level =3D=3D SOL_SOCKET && cmsg->cmsg_type =3D=3D S= CM_RIGHTS) { + int *fd =3D (int *)data; + int *target_fd =3D (int *)target_data; + int i, numfds =3D len / sizeof(int); + + for (i =3D 0; i < numfds; i++) { + __get_user(fd[i], target_fd + i); + } + } else if ((cmsg->cmsg_level =3D=3D SOL_SOCKET) && + (cmsg->cmsg_type =3D=3D SCM_TIMESTAMP) && + (len =3D=3D sizeof(struct target_freebsd_timeval))) { + /* copy struct timeval to host */ + struct timeval *tv =3D (struct timeval *)data; + struct target_freebsd_timeval *target_tv =3D + (struct target_freebsd_timeval *)target_data; + __get_user(tv->tv_sec, &target_tv->tv_sec); + __get_user(tv->tv_usec, &target_tv->tv_usec); + } else { + gemu_log("Unsupported target ancillary data: %d/%d\n", + cmsg->cmsg_level, cmsg->cmsg_type); + memcpy(data, target_data, len); + } + + cmsg =3D CMSG_NXTHDR(msgh, cmsg); + target_cmsg =3D TARGET_CMSG_NXTHDR(target_msgh, target_cmsg, + target_cmsg_start); + } + unlock_user(target_cmsg_start, target_cmsg_addr, 0); +the_end: + msgh->msg_controllen =3D space; + return 0; +} + +abi_long h2t_freebsd_cmsg(struct target_msghdr *target_msgh, + struct msghdr *msgh) +{ + struct cmsghdr *cmsg =3D CMSG_FIRSTHDR(msgh); + socklen_t msg_controllen; + abi_ulong target_cmsg_addr; + struct target_cmsghdr *target_cmsg, *target_cmsg_start; + socklen_t space =3D 0; + + msg_controllen =3D tswap32(target_msgh->msg_controllen); + if (msg_controllen < sizeof(struct target_cmsghdr)) { + goto the_end; + } + target_cmsg_addr =3D tswapal(target_msgh->msg_control); + target_cmsg =3D lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controll= en, 0); + target_cmsg_start =3D target_cmsg; + if (!target_cmsg) { + return -TARGET_EFAULT; + } + + while (cmsg && target_cmsg) { + void *data =3D CMSG_DATA(cmsg); + void *target_data =3D TARGET_CMSG_DATA(target_cmsg); + int len =3D (unsigned char *)(cmsg) + cmsg->cmsg_len - + (unsigned char *)data; + + int tgt_len, tgt_space; + + /* + * We never copy a half-header but may copy half-data; this is Lin= ux's + * behaviour in put_cmsg(). Note that truncation here is a guest p= roblem + * (which we report to the guest via the CTRUNC bit), unlike trunc= ation + * in target_to_host_cmsg, which is a QEMU bug. + */ + if (msg_controllen < sizeof(struct target_cmsghdr)) { + target_msgh->msg_flags |=3D tswap32(MSG_CTRUNC); + break; + } + + if (cmsg->cmsg_level =3D=3D SOL_SOCKET) { + target_cmsg->cmsg_level =3D tswap32(TARGET_SOL_SOCKET); + } else { + target_cmsg->cmsg_level =3D tswap32(cmsg->cmsg_level); + } + target_cmsg->cmsg_type =3D tswap32(cmsg->cmsg_type); + + /* + * Payload types which need a different size of payload on the tar= get + * must adjust tgt_len here. + */ + tgt_len =3D len; + switch (cmsg->cmsg_level) { + case SOL_SOCKET: + switch (cmsg->cmsg_type) { + case SCM_TIMESTAMP: + tgt_len =3D sizeof(struct target_freebsd_timeval); + break; + default: + break; + } + break; + default: + break; + } + + if (msg_controllen < TARGET_CMSG_LEN(tgt_len)) { + target_msgh->msg_flags |=3D tswap32(MSG_CTRUNC); + tgt_len =3D msg_controllen - sizeof(struct target_cmsghdr); + } + + /* + * We must now copy-and-convert len bytes of payload into tgt_len = bytes + * of destination space. Bear in mind that in both source and + * destination we may be dealing with a truncated value! + */ + switch (cmsg->cmsg_level) { + case SOL_SOCKET: + switch (cmsg->cmsg_type) { + case SCM_RIGHTS: + { + int *fd =3D (int *)data; + int *target_fd =3D (int *)target_data; + int i, numfds =3D tgt_len / sizeof(int); + + for (i =3D 0; i < numfds; i++) { + __put_user(fd[i], target_fd + i); + } + break; + } + case SCM_TIMESTAMP: + { + struct timeval *tv =3D (struct timeval *)data; + struct target_freebsd_timeval *target_tv =3D + (struct target_freebsd_timeval *)target_data; + + if (len !=3D sizeof(struct timeval) || + tgt_len !=3D sizeof(struct target_freebsd_timeval)) { + goto unimplemented; + } + + /* copy struct timeval to target */ + __put_user(tv->tv_sec, &target_tv->tv_sec); + __put_user(tv->tv_usec, &target_tv->tv_usec); + break; + } + default: + goto unimplemented; + } + break; + default: + unimplemented: + gemu_log("Unsupported host ancillary data: %d/%d\n", + cmsg->cmsg_level, cmsg->cmsg_type); + memcpy(target_data, data, MIN(len, tgt_len)); + if (tgt_len > len) { + memset(target_data + len, 0, tgt_len - len); + } + } + + target_cmsg->cmsg_len =3D tswap32(TARGET_CMSG_LEN(tgt_len)); + tgt_space =3D TARGET_CMSG_SPACE(tgt_len); + if (msg_controllen < tgt_space) { + tgt_space =3D msg_controllen; + } + msg_controllen -=3D tgt_space; + space +=3D tgt_space; + cmsg =3D CMSG_NXTHDR(msgh, cmsg); + target_cmsg =3D TARGET_CMSG_NXTHDR(target_msgh, target_cmsg, + target_cmsg_start); + } + unlock_user(target_cmsg_start, target_cmsg_addr, space); +the_end: + target_msgh->msg_controllen =3D tswap32(space); + return 0; +} --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139762; cv=none; d=zohomail.com; s=zohoarc; b=SDDod04ElbG+A6YtdcvHxgH1QtzLzvmf8ZntLr97G2KcnVpO8nHDiI9I7z+H7LuYaYMqjic9j4KP3PvqMJPKIG/AuM6YwsS05/RLx3Bj8X444RVvqi8+vaTZBSM2g6+ehCxLFWTDqCab7enwXzCVR0i8bHANJC1XPK153i+zjkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139762; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BIZZ3MoLaByazBW5BUbMYe7Y/3osI58B02Q2ofvFBtk=; b=E9x651Rk3/QJwTvFrHzRNqAGWlZhPO2cbr9+mtfeSwJZBxgeGecASdrCjy8pfUf6vv/8mqFfOWq5DrcrzCsgJDTJkhAp/oackJTaDfatOHTGKbHIE/yc8SfIzH3bi1pWjMnr/BGa9lJDfRnJ/d7YEATXAH7xJPDcujrK1jpJtYA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139762677930.065119668391; Mon, 18 May 2026 14:29:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VV-0000T2-DB; Mon, 18 May 2026 17:28:13 -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 1wP5VT-0000SX-M6 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:11 -0400 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VR-0000TG-8Z for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:10 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7dcc9b506d9so3022604a34.1 for ; Mon, 18 May 2026 14:28:08 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139688; x=1779744488; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BIZZ3MoLaByazBW5BUbMYe7Y/3osI58B02Q2ofvFBtk=; b=CdKG89BcY1bv6IUO+WS1Y9Biwy9eWBoixCkh8wQ0YJZFc7QLixD2OB+1aHPt00CwVg R+fBwMxihwWA7cDJe/T/f/YYs26/WII1gnGD1c+e4O77KEq9TvXA8ExJRqgAnYGlAbkg xHp9/G9oi35RomO4tVsFTSo51Q9Xxoyvu21G1P/G7Wx/twhNcemd/RUmPkWitGk67i87 8Bu5qRysbK2Cho4ioAsJFlpCYLMSsspdLFQRpbB/wmx9vnbGM3X36B/OVI4Ec8ddKbTX ZLOinR40qAyQmv3ILV6Syat5+DVKsdgJRCX5Is/nycGpo7I2e5PDLgi4jtFnRE5rbMaS /KHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139688; x=1779744488; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=BIZZ3MoLaByazBW5BUbMYe7Y/3osI58B02Q2ofvFBtk=; b=CMU7TtlihOFxw2/XQG5pbvtkCAYM5U96MuHg8DNvOx7AmOLbPVpuiWZkMOXUvu+foE KWrQekaGYzhJKpRikjUoajr3wFgQptNZrieC7PB4qc26vnO8Np8qLW0xUdD6WyoktzRh 8XWQc0wSZgwlB/brgmGrmpkwzTX5mcSRstVyFhPbgklsm9Nyt+nxf1tBrkXatMvx2w+5 QlsdbDBuKx67efN5gwi3PlQrx0nCFnzXqjAPLpm3nvpQWs4zmoNoG4bvm9u8P49IFR4c Z68guRxv8TWL66JrkLR84xF9QqS8EbB3PAFa0di3Ys/JHinQW5krOulEv2WRj+KcwOYt R/Yg== X-Gm-Message-State: AOJu0YwDiTUu3eiDj38mL+Cx7/iZlE9ys4y9gShATwDoTJOXC9pyje0C jCLUPPWLKsHohslpcmi9aeCWF8/RS7p8baak+/uuA9gPb3VgHJ841JWx408nBy6zF2I= X-Gm-Gg: Acq92OHq0kA9c/zADuGlnFH/2B8AEkiudxuBFKBSHbUybYtFkFFaUnWwdtq7mOwzt3C rObYJUkM57qk3FFkey81/F9TD0PTHq/zNWKqdeEHb8yR2Lqo/+TODrAtgMWwba8P/vsvvaH3Gde 4Y9lIo/AE4xHjgsc2PqIe+i2Wnx3WOrZq9J8FFbaWbnLKXmAxrIH3gPRNj7X7Gdq+VXECQi5aIo +aj+HRzl5dKkD5F5ecWnD7acipycNz2Icuv2uUZnu7YDTslKuj2fepfZIP9WgxKqE+plCZj6scx I6Qd4LWftQmXUybKeHCPTFH1AAuGBTq6UNu8ed0ZnZ98WsNd2PADsltP6eHTPvsZ4Mm6yRyStPO Ft0S1T9IckmyPDI9i8BKmKP0kDypmf46qwUFDsbPGMdkYIAun2rkISmPPykrgNPeMM/Tnddby3c gM/extZfoMa5xPRQSqd8Fr X-Received: by 2002:a05:6830:3902:b0:7dc:cd0b:58ac with SMTP id 46e09a7af769-7e4f2a448a3mr11846523a34.9.1779139688069; Mon, 18 May 2026 14:28:08 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:34 -0600 Subject: [PATCH v2 16/37] bsd-user: Add socket system call dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-16-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3563; i=imp@bsdimp.com; h=from:subject:message-id; bh=TZhqz7LKdkYXM01TJu9w2X05NnhTh/MQLP6Gzmk/xUk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RH3/4buRW2HOb8yg9TUO/UuVrTcoDpg2CSA zcNFPUpghaJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AE/FEAChm0qy3FHZZEzRgjPT+LggpycTGOsaQSYn2QBNmkcc6xBflPnC29ojYFLo7f2aBMJ+16J gW8rNz7Q9yLf1ZZNOR+/JEeosJGLSBF0PLYsj7cXZ7F1YSbRJEKbKTCraDpQjsxv3P2LmtMbn5p VZ7swUvHaXXVoUBU5wHp9gqq2eSFDg7hW4ED0fREtfCPKuD5cFud608J/kURQDvR66c8fypKU5F Yhjp/sJfMsIF7gd1VtxEBs+PTbYE73BaxhHfaUb15TTminU8E4k5PJlxAud+zGpt/A27h4DMuyQ tKJ23KS7lhVRr8ge2FxaZU0XBJYdfYwSd01/sRtbZG50BPcnZojMexCH5PbDB/kgD8julkXJOXG TRnW09qLsXz3whAZAgldFF47MBOmIwdF97IEzHAi+xtmNetHSor1pLBVe0BlVR3ZPf6LXkl+V9W 9U3NrOhgKZm5Q6+GugKOUWUISjbkzrD4i3oGgpagspvoWd5scTRoIvAuJ4MdTrBSkesPmznAFAo 7A9w+ThROeV9p/RhYTAVp3oYvld0Nos/E1KttD8Mq8jMsNbtbwWcVCRCsW0ApgFvvqQUW+cN+LZ 2riDInSvjhAvUhsVgOnLy9Sn6lGR3yGArAqWHyMq4tJtWCzzaDBci4TB5vEtjmO3ayIRZZ6ntdn 8y/Ety/5L7vqW5g== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::335; envelope-from=imp@bsdimp.com; helo=mail-ot1-x335.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139763310158500 Wire up socket-related system calls in the FreeBSD syscall dispatcher: accept, accept4, bind, bindat, connect, connectat, getpeername, getsockname, getsockopt, setsockopt, listen, recvfrom, recvmsg, sendmsg, sendto, socket, socketpair, shutdown, and setfib. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-syscall.c | 79 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 79 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 46fee46336..5d3a66e360 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -1073,6 +1073,85 @@ static abi_long freebsd_syscall(CPUArchState *env, i= nt num, abi_long arg1, ret =3D do_freebsd_pdkill(arg1, arg2); break; =20 + /* + * socket related system calls + */ + case TARGET_FREEBSD_NR_accept: /* accept(2) */ + ret =3D do_bsd_accept(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_accept4: /* accept4(2) */ + ret =3D do_freebsd_accept4(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_bind: /* bind(2) */ + ret =3D do_bsd_bind(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_bindat: /* bindat(2) */ + ret =3D do_freebsd_bindat(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_connect: /* connect(2) */ + ret =3D do_bsd_connect(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_connectat: /* connectat(2) */ + ret =3D do_freebsd_connectat(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_getpeername: /* getpeername(2) */ + ret =3D do_bsd_getpeername(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getsockname: /* getsockname(2) */ + ret =3D do_bsd_getsockname(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getsockopt: /* getsockopt(2) */ + ret =3D do_bsd_getsockopt(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_setsockopt: /* setsockopt(2) */ + ret =3D do_bsd_setsockopt(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_listen: /* listen(2) */ + ret =3D get_errno(listen(arg1, arg2)); + break; + + case TARGET_FREEBSD_NR_recvfrom: /* recvfrom(2) */ + ret =3D do_bsd_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6); + break; + + case TARGET_FREEBSD_NR_recvmsg: /* recvmsg(2) */ + ret =3D do_sendrecvmsg(arg1, arg2, arg3, 0); + break; + + case TARGET_FREEBSD_NR_sendmsg: /* sendmsg(2) */ + ret =3D do_sendrecvmsg(arg1, arg2, arg3, 1); + break; + + case TARGET_FREEBSD_NR_sendto: /* sendto(2) */ + ret =3D do_bsd_sendto(arg1, arg2, arg3, arg4, arg5, arg6); + break; + + case TARGET_FREEBSD_NR_socket: /* socket(2) */ + ret =3D do_bsd_socket(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_socketpair: /* socketpair(2) */ + ret =3D do_bsd_socketpair(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_shutdown: /* shutdown(2) */ + ret =3D do_bsd_shutdown(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_setfib: /* setfib(2) */ + ret =3D do_freebsd_setfib(arg1); + break; + /* * sys{ctl, arch, call} */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139907; cv=none; d=zohomail.com; s=zohoarc; b=Y8cZXHgD07YdgrarXoBLC3XI/4pvEcUpuSzl1+8iHt/9MHxyki7xAL2oRwq74TewIA48uYnt2v1YUHLR+Og6OHmXzC6jGWcteAABb6EmQI1ppobZletoFTQx+GqR6AX1MzqCow4U5sDJfEznNmZJpbEsMGQMw7X/3qUcxSfvVdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139907; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=81DVU7JcCo7Uv+OZ8nvEUHmEh8rFjVkk4TGoU8OO4S4=; b=UWEna8I8jZv4/tcg4bgbdsatdzRg6ZN98IZl08/RJniMIdRyW38JYT7PdngMYat62apGvg8rKj6GUbjGCQUZvyuQ2KtbzV4oiiSe1URySP4UICNz79CV6B6NhRHP7cvNnCf3Yty/GdEYXCEygdDZfGnq1YUkFD8toSWwTPJ30BE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139907691357.41864291830086; Mon, 18 May 2026 14:31:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VZ-0000Tm-La; Mon, 18 May 2026 17:28:18 -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 1wP5VX-0000TT-DK for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:15 -0400 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VT-0000UT-FO for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:13 -0400 Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-47cacb4ed99so1829934b6e.1 for ; Mon, 18 May 2026 14:28:09 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139689; x=1779744489; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=81DVU7JcCo7Uv+OZ8nvEUHmEh8rFjVkk4TGoU8OO4S4=; b=O8sdcEpnzuBZ8HClotxSlsdrVqg9ZDgPSVP6DxckCKJKPo/K7I9OXJ0qM+voy4Y02c +gJppe5F7dBXU1FDuy3Vm47snBdKKCaOEJ8PIg28Y8WnaKOWncycL+KsCNdfGN9SmHmr MdOTRU6eKMsGuNiQ0o17x6YrlVG28ziKZZpkHdg/r/9lYxvupQMeEyaF3/N6GVimoZU5 Aky8oMtnRhCqYw0+90OGYLe8+TM+NrKIFL/VyePokjte0IvsZnfCralUH26vcUVrMLV4 pOADkkW4hB+fDNx2Kkinwzx1YNxS60B1ejn3ezDc5S22opXyu5iNRJbXAMl/IEFa2x/X PHGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139689; x=1779744489; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=81DVU7JcCo7Uv+OZ8nvEUHmEh8rFjVkk4TGoU8OO4S4=; b=Yg7HPDgA4f4lbdb/RqCp3zmmBOXo8F/xb+nLgRDO+dq83gzpEVdrgMXnDmxJTk5rcW 4GRAybVyxSgAXTijIRiZ2QMDFI/+Pj4d7fCzB7WUrF3DB1059RGMeF6I/Xl7n/lo/Ekq M7xbGTz8szY69jj7C/UjOf+E4As3RKV9dJbQ+vc0eQngG5RKZwv6azESMH5bXBgQswFR eW5/RMT7kkI31tM/uob92JFb85rwQU6vkFKErd9b1znYfrImZcK8A755btG8q1vIViC4 COE8C+7iWjuNYxdoJeXkxQicEpnnzhon9+MrUdp/r7gQlFhjURBXSNqfKZ1s15hk3wmL XjbA== X-Gm-Message-State: AOJu0YzEvb1Z6pXix23T1NraLxwxydzrtilPl2MT/2ledQix+klxoD9J 7y29+jS8O1tNMt1Ubfe2JWsSWv5eKz53GYzQUWJObDPImG662xg/va7XLX4zie4xIlg= X-Gm-Gg: Acq92OEsEAXhx7o6VUQRJTiOd5XNmBQqLqKMd6BwOG4BtzeU42fQ0YUQEx3Np369zei /gRwNnHTWRgWaJsYARv5PXUnDygvk4gILjbGBbGFctAuNFK5WZpf4HOQ0fTBes1DYSH1aXjSbdS snHu9em9sQa7x0FI6wiYtwMEJ15h6/GJgoGHqXvmPP6iMpsegM1Twar6oZunkhefgEWqsQe+ahh 9aPZa8yNI4W6tuP445VJ7BiqZXhxl22y1FFOWNRS4qClnstJeqJ6u3enceIf6odTGIqeSnwAkhi rbqXEw7rV/ymfxR2pe7eAl3uLHHoVafovz0M+ZIzLwF9KpKxDfuw+kwMaDBRax2Cd13nC41bEyQ Pbfa43rDjf5pF6ze/kcI3XsYjSOnP6h97I9k+lg0dA2Ex/OBidcmvmpzgUKufbjqiH6VgiS2lKt e7L3/djJMqHguJnTxReRvW X-Received: by 2002:a05:6808:4fc8:b0:463:efb4:f9a2 with SMTP id 5614622812f47-482e59468bbmr11112428b6e.28.1779139688948; Mon, 18 May 2026 14:28:08 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:35 -0600 Subject: [PATCH v2 17/37] bsd-user: Add os-time.h with clock and time-of-day functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-17-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Sean Bruno , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7793; i=imp@bsdimp.com; h=from:subject:message-id; bh=m//p52qNBouEG3rg+3PIxl6T03rB5SiqGv+OBONuHk8=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RHphMMt6sZI7C/TmASTYIc+6tPRsR4B+DnL IYoZHYtQsWJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR ALPvD/4xgQGamKqw5qVasshVJtrp6GZIzXor6ntLNJFvKqmI0peQdzdSEWqHkSuvZLZzTFIdyZP P9Jd+B4dXuNBLEPROdOnfp3C9Dam/k3m5AS7F9jzCn63M0tE0K9sc0bWQyUC8maWZSsG5GR3Ktc dFzOsZNGPNpKx6izMnyI2mLUrF+qUs4MlCYNBwFlFzF7tJyMLNXfhvpakYo/piuWqnRVUzsCDsq 7G6nfLlxJyrWPifR0RAWzW5pJj2W70jlHKWv/VCL5M9KBUkqgeL8hGra4MlRZC14BLGC1eUvjbz d+YZmxEGSB0TeMSa6i1/JEcnp6vlAoiwJy6TGQvmAjSYS6lCqESWWViPf5cgK2+D1k7kXlNqMC1 psiGeFxyL73n3LF6zyRKLJ3KfGBSJXpB6fZVqJiqHUkUaug51qqR6W7Max0wvdZvRwTvb5RxScS pesOZPyG7sXmZEVdQofY2gmjagHfrrnDxN3470fpdDrRg02NDiRp0RfvMLrHxiwEoSr5iP5zAiy BkO/l7uz8/Pj8Yjb3nkjvhlbnPhblzsZ3OM3roH8/w0RL4XRlNm93ay+F9KxMAIEmaiymD0FTTK 12rWMef+7rHUHYvA4OckUV/ASKx9ELqEg4ix4fkEXQ1plo7sPs9M/8QrbOh5JFwsKSZWmxPBxLh s7mAgiWxm99nesw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::232; envelope-from=imp@bsdimp.com; helo=mail-oi1-x232.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139909612154100 Add the first part of FreeBSD time support: nanosleep, clock_nanosleep, clock_gettime, clock_settime, clock_getres, gettimeofday, settimeofday, adjtime, ntp_adjtime, and ntp_gettime. Also add safe_syscall wrappers for nanosleep, clock_nanosleep, and kevent. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Sean Bruno Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-syscall.c | 9 ++ bsd-user/freebsd/os-time.h | 221 ++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 230 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 5d3a66e360..6fbd2da261 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -89,6 +89,15 @@ safe_syscall6(ssize_t, sendto, int, fd, const void *, bu= f, size_t, len, int, safe_syscall3(ssize_t, recvmsg, int, s, struct msghdr *, msg, int, flags); safe_syscall3(ssize_t, sendmsg, int, s, const struct msghdr *, msg, int, f= lags); =20 +/* used in os-time */ +safe_syscall2(int, nanosleep, const struct timespec *, rqtp, struct timesp= ec *, + rmtp); +safe_syscall4(int, clock_nanosleep, clockid_t, clock_id, int, flags, + const struct timespec *, rqtp, struct timespec *, rmtp); +safe_syscall6(int, kevent, int, kq, const struct kevent *, changelist, + int, nchanges, struct kevent *, eventlist, int, nevents, + const struct timespec *, timeout); + /* used in os-proc */ safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, struct rusage *, rusage); diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h new file mode 100644 index 0000000000..16b71e6234 --- /dev/null +++ b/bsd-user/freebsd/os-time.h @@ -0,0 +1,221 @@ +/* + * FreeBSD time related system call shims + * + * Copyright (c) 2013-2015 Stacey Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef FREEBSD_OS_TIME_H +#define FREEBSD_OS_TIME_H + +#include +#include +#include +#include +#include +#include +#include + +#include "qemu.h" +#include "qemu-os.h" + +#include "bsd-socket.h" + +int safe_clock_nanosleep(clockid_t clock_id, int flags, + const struct timespec *rqtp, struct timespec *rmtp); +int safe_nanosleep(const struct timespec *rqtp, struct timespec *rmtp); +int safe_kevent(int, const struct kevent *, int, struct kevent *, int, + const struct timespec *); + +int __sys_ktimer_create(clockid_t, struct sigevent *restrict, + int *restrict); +int __sys_ktimer_gettime(int, struct itimerspec *); +int __sys_ktimer_settime(int, int, const struct itimerspec *restrict, + struct itimerspec *restrict); +int __sys_ktimer_delete(int); + +/* nanosleep(2) */ +static inline abi_long do_freebsd_nanosleep(abi_long arg1, abi_long arg2) +{ + abi_long ret; + struct timespec req, rem; + + ret =3D t2h_freebsd_timespec(&req, arg1); + if (!is_error(ret)) { + ret =3D get_errno(safe_nanosleep(&req, &rem)); + if (ret =3D=3D -TARGET_EINTR && arg2) { + ret =3D h2t_freebsd_timespec(arg2, &rem); + } + } + + return ret; +} + +/* clock_nanosleep(2) */ +static inline abi_long do_freebsd_clock_nanosleep(abi_long arg1, abi_long = arg2, + abi_long arg3, abi_long arg4) +{ + struct timespec req, rem; + abi_long ret; + int clkid, flags; + + clkid =3D arg1; + /* XXX Translate? */ + flags =3D arg2; + ret =3D t2h_freebsd_timespec(&req, arg3); + if (!is_error(ret)) { + ret =3D get_errno(safe_clock_nanosleep(clkid, flags, &req, &rem)); + if (ret =3D=3D -TARGET_EINTR && arg4) { + h2t_freebsd_timespec(arg4, &rem); + } + } + + return ret; +} + +/* clock_gettime(2) */ +static inline abi_long do_freebsd_clock_gettime(abi_long arg1, abi_long ar= g2) +{ + abi_long ret; + struct timespec ts; + + ret =3D get_errno(clock_gettime(arg1, &ts)); + if (!is_error(ret)) { + if (h2t_freebsd_timespec(arg2, &ts)) { + return -TARGET_EFAULT; + } + } + + return ret; +} + +/* clock_settime(2) */ +static inline abi_long do_freebsd_clock_settime(abi_long arg1, abi_long ar= g2) +{ + struct timespec ts; + + if (t2h_freebsd_timespec(&ts, arg2) !=3D 0) { + return -TARGET_EFAULT; + } + + return get_errno(clock_settime(arg1, &ts)); +} + +/* clock_getres(2) */ +static inline abi_long do_freebsd_clock_getres(abi_long arg1, abi_long arg= 2) +{ + abi_long ret; + struct timespec ts; + + ret =3D get_errno(clock_getres(arg1, &ts)); + if (!is_error(ret)) { + if (h2t_freebsd_timespec(arg2, &ts)) { + return -TARGET_EFAULT; + } + } + + return ret; +} + +/* gettimeofday(2) */ +static inline abi_long do_freebsd_gettimeofday(abi_ulong arg1, abi_ulong a= rg2) +{ + abi_long ret; + struct timeval tv; + struct timezone tz, *target_tz; /* XXX */ + + if (arg2 !=3D 0) { + if (!lock_user_struct(VERIFY_READ, target_tz, arg2, 0)) { + return -TARGET_EFAULT; + } + __get_user(tz.tz_minuteswest, &target_tz->tz_minuteswest); + __get_user(tz.tz_dsttime, &target_tz->tz_dsttime); + unlock_user_struct(target_tz, arg2, 1); + } + ret =3D get_errno(gettimeofday(&tv, arg2 !=3D 0 ? &tz : NULL)); + if (!is_error(ret)) { + if (h2t_freebsd_timeval(&tv, arg1)) { + return -TARGET_EFAULT; + } + } + + return ret; +} + +/* settimeofday(2) */ +static inline abi_long do_freebsd_settimeofday(abi_long arg1, abi_long arg= 2) +{ + struct timeval tv; + struct timezone tz, *target_tz; /* XXX */ + + if (arg2 !=3D 0) { + if (!lock_user_struct(VERIFY_READ, target_tz, arg2, 0)) { + return -TARGET_EFAULT; + } + __get_user(tz.tz_minuteswest, &target_tz->tz_minuteswest); + __get_user(tz.tz_dsttime, &target_tz->tz_dsttime); + unlock_user_struct(target_tz, arg2, 1); + } + if (t2h_freebsd_timeval(&tv, arg1)) { + return -TARGET_EFAULT; + } + + return get_errno(settimeofday(&tv, arg2 !=3D 0 ? &tz : NULL)); +} + +/* adjtime(2) */ +static inline abi_long do_freebsd_adjtime(abi_ulong target_delta_addr, + abi_ulong target_old_addr) +{ + abi_long ret; + struct timeval host_delta, host_old; + + ret =3D t2h_freebsd_timeval(&host_delta, target_delta_addr); + if (is_error(ret)) { + return ret; + } + + if (target_old_addr) { + ret =3D get_errno(adjtime(&host_delta, &host_old)); + if (is_error(ret)) { + return ret; + } + ret =3D h2t_freebsd_timeval(&host_old, target_old_addr); + } else { + ret =3D get_errno(adjtime(&host_delta, NULL)); + } + + return ret; +} + +/* ntp_adjtime(2) */ +static inline abi_long do_freebsd_ntp_adjtime(abi_ulong target_tx_addr) +{ + abi_long ret; + struct timex host_tx; + + ret =3D t2h_freebsd_timex(&host_tx, target_tx_addr); + if (ret =3D=3D 0) { + ret =3D get_errno(ntp_adjtime(&host_tx)); + } + + return ret; +} + +/* ntp_gettime(2) */ +static inline abi_long do_freebsd_ntp_gettime(abi_ulong target_ntv_addr) +{ + abi_long ret; + struct ntptimeval host_ntv; + + ret =3D get_errno(ntp_gettime(&host_ntv)); + if (!is_error(ret)) { + ret =3D h2t_freebsd_ntptimeval(target_ntv_addr, &host_ntv); + } + + return ret; +} + + + +#endif /* FREEBSD_OS_TIME_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139907; cv=none; d=zohomail.com; s=zohoarc; b=UvZ+fmmL1bAcJFxYFO+qEu77e8H1cm1cOCrYB7dYCHuUlUdF8TXWljl70Tx8F86uZ3uLIRdc/JPcAejjkaT+Z0L4R7R32MrHXmkIG847xVptIO6BYk+rThVGxizHUmb7RaN2oswDT4aUOYte11TqbOQcqaWWABiJK/Ry5S6a2b0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139907; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+9XmWQulmeQTxV7cz+ITMN9VZZhvuiCJswwX1H8U88A=; b=XECYcU5UnnfMqdpDLjx62MTVTpQ2eB8tsuAOJy35coeVufJJTaUnS1CEqAeTmU61iZIQfPM5JHvYxPYjN3UjzOw+/pRbzSv2TRWUKUdwe8/csvVA3lrpGu+rNY7r/Njb121ZHoHqOS2yzcZXUL6Pcwi9hAIP5hcBACLkx8AoqPo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139907843601.8336610530192; Mon, 18 May 2026 14:31:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5VZ-0000Tk-K6; Mon, 18 May 2026 17:28:17 -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 1wP5VX-0000TS-DC for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:15 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VT-0000Uv-Fg for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:14 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7dca00c1591so735871a34.3 for ; Mon, 18 May 2026 14:28:10 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139690; x=1779744490; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+9XmWQulmeQTxV7cz+ITMN9VZZhvuiCJswwX1H8U88A=; b=EEtzBWFn1dKNpC4+eab9pMZUhBfGppEI7RVgOVZ3ZoO4k9q5F0tknyydUkYFgIlK2P fFYSCqNwrbWOPa4NvLv1y7LxMCnF0k/PV3fl6W51EoZjZp6SVCnsKib+SlXhJZYswy4S Mj7b6nFiMthIcsZa9ReP55hgqMzF3h+P2dYpKseTXNNs4grjxPEjhmz1O5vxU+4ErABy CneJlaUPyk8vv18VOv3oeuFLpK+hIDLkWPdNh6Qg2hb9T6YnzxOWOYltOAojEfL4b4rz EGqfiJkNY7cstqjwoGs8u+O2EMtY+aSXJjydVKLCIdqhON1bLjNHfzd4LKfkaVAjjI8t cePg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139690; x=1779744490; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=+9XmWQulmeQTxV7cz+ITMN9VZZhvuiCJswwX1H8U88A=; b=PqJXLxlqEAiCG9TR9Ad5gfGLAHLgueFdZIdjassHG5cPKoFP6Cz5uRf0tlE2169920 /eTQsHfOag0IfpoIft9jB2x9clE8wb/KU0bkj4To1u8Law1WrY8ILl+6kFonC/MNyaHe uitOH4Y22t8tbu12k8VvcAeZ3KJ9UjiNBl2mBaDhN0mNXa2Q8PExbn6Xg7qVUmijgPXk lvKBif05hXjOu306XgG2Hij8eI2BqDT7MLObyiwu6keISzEoa7F1250Fjne/GHkVhC2w 0QjGOA9ZgUtARkOXLqECjp4XTYmtYS86DEL5SEiA9nz1WkAC5DNUuVGUXJCbyL16dmBQ nMpw== X-Gm-Message-State: AOJu0Ywp6X/Z8wm0O52GjojfobuIVdh47XzKaTa1G/Gc9gM9ryBMTluj AlcFgrvoU1WfkRhzFVZ+X3KzuQSeqdufttbO/BPKUDB5Fnf0SgCWRAd/FTR1o9Djpvo= X-Gm-Gg: Acq92OGGNSnFBVHlwjhw6gksPZ+kG9eEuE/0eD4DWeL3RBh5Z0qRsm9Pu+glqfiIoX5 yZvxM7y6MYo+jJnXdXzPgvST75NXEGiF5jLUW5AOzwRKjLSf7OPSUxt/sD2cuYQyMqHlYhgGYSm GOPk6tva/PFar8vv7Bp0Mx4XYbiUs6FujLG5qd2lnytLr1mKCbp+yweLl0mxj52Cvxvz8k/qqeS TtcI8PTRJVyFhOvK+nWygzURy2URAlxMbXxvMhy2qXJGs7E0tQUUUbz4JobODjG+wSG6FvprbuR vUzGq3OSCOXZXiOHIG9ZYZNDFksxJa4jzuHVkIjxWndONeGQOr2etlvnnbB9PJ3CsTDP0uDCw7D x1u7KleRP88j/2F3afmEPBzm0HLvHO67WcuPlyFeAiU1JUjaKpY6nFOzRNfAJn7HXL+4chmuIH6 q4uRPnQDvxRq9obPEgsQEI X-Received: by 2002:a05:6830:6010:b0:7dc:e37b:b5d2 with SMTP id 46e09a7af769-7e4ea185c16mr11930302a34.8.1779139690145; Mon, 18 May 2026 14:28:10 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:36 -0600 Subject: [PATCH v2 18/37] bsd-user: Add utimes, futimes, and ktimer functions to os-time.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-18-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6472; i=imp@bsdimp.com; h=from:subject:message-id; bh=GzpJa4xVkJQoXZiJ9eFNVqoa5W4JZ3qBXY89UUHqa70=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RHL7KDv6KXIZe0eaUO8jZPjojyFmd+tVVMR Uc5YRQcWbSJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AC6HEAC8usGRenx+nFXcapYGePwTBSxyBFHhVs0f6XManZ+5GVrhgzYd+/xMbPu+pTH1BLjdYwl l3qh0J3AOqJ5TTQtBqCCZfZsUokTLwrkPKprRP3wKaLe5MJ9H/4H0qNlfKFMvFiK+Iyh5LS6PPH DbLcxVYxIHCBZ7/WFXBS3aFHFNMKHoXqee29GtowOsM1Cr2pji4IoZOmnBGZEHLvP0hJxq1b2r0 GFlXS34I1yIALr3gDV0usBf7bxZQ1w+Zdf9xH5NNomoNc4UeBiPN9zw9m/957u+9XcjERrJRSm2 LDBfsIBxNPzfzOn0+GsM4WwvmnzB3h/2vSm0ulZtceFY3FOjGlmpRTE2jAM8PRTfliXIj3NTzYp Wv07s+tsomFe7a1CYllGctbhY8KTmtPh8gVVMVJmfIlw0o64JjP/dUR+NAEfUs24FR4zx62hxu5 KEBl/ix0JenfVmF3HUIMXV2DrUGzy87E/zPxCxeTsCsKJh8HMruQXIV7frSzBOvGnsFs8XOCPkR OZtXyWwaQcbqxrDl0t/dl7/d9Aiz6107pUZ/iyxe5uuK9PnSuLgdvL2j8wPZUPuReLUXjyKEX5r qOZXKoEpfR0uWnU8r3KSjg9NmzTavfSnVadv05m2+zTM+YHfsOMVocsAbXunkWQ2sFIPF4dcdID SjdvO3iTiPGNWnw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::332; envelope-from=imp@bsdimp.com; helo=mail-ot1-x332.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139909543154100 Add time-related system call shims: utimes, lutimes, futimes, futimesat, ktimer_create, ktimer_delete, ktimer_settime, and ktimer_gettime. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-time.h | 210 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 210 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 16b71e6234..05fa043442 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -217,5 +217,215 @@ static inline abi_long do_freebsd_ntp_gettime(abi_ulo= ng target_ntv_addr) } =20 =20 +/* utimes(2) */ +static inline abi_long do_freebsd_utimes(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + struct timeval *tvp, tv[2]; + + if (arg2 !=3D 0) { + if (t2h_freebsd_timeval(&tv[0], arg2) || + t2h_freebsd_timeval(&tv[1], arg2 + + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + tvp =3D tv; + } else { + tvp =3D NULL; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(utimes(p, tvp)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* lutimes(2) */ +static inline abi_long do_freebsd_lutimes(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + struct timeval *tvp, tv[2]; + + if (arg2 !=3D 0) { + if (t2h_freebsd_timeval(&tv[0], arg2) || + t2h_freebsd_timeval(&tv[1], arg2 + + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + tvp =3D tv; + } else { + tvp =3D NULL; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(lutimes(p, tvp)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* futimes(2) */ +static inline abi_long do_freebsd_futimes(abi_long arg1, abi_long arg2) +{ + struct timeval *tvp, tv[2]; + + if (arg2 !=3D 0) { + if (t2h_freebsd_timeval(&tv[0], arg2) || + t2h_freebsd_timeval(&tv[1], arg2 + + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + tvp =3D tv; + } else { + tvp =3D NULL; + } + + return get_errno(futimes(arg1, tvp)); +} + +/* futimesat(2) */ +static inline abi_long do_freebsd_futimesat(abi_long arg1, abi_long arg2, + abi_long arg3) +{ + abi_long ret; + void *p; + struct timeval *tvp, tv[2]; + + if (arg3 !=3D 0) { + if (t2h_freebsd_timeval(&tv[0], arg3) || + t2h_freebsd_timeval(&tv[1], arg3 + + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + tvp =3D tv; + } else { + tvp =3D NULL; + } + + p =3D lock_user_string(arg2); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(futimesat(arg1, p, tvp)); + unlock_user(p, arg2, 0); + + return ret; +} + +/* timer_create(2) */ +static inline abi_long do_freebsd_ktimer_create(abi_long arg1, abi_long ar= g2, + abi_long arg3) +{ + /* args: clockid_t clockid, struct sigevent *sevp, int *timerid */ + abi_long ret; + + struct sigevent host_sevp =3D { 0 }, *phost_sevp =3D NULL; + + int clkid =3D arg1; + int timer_index =3D next_free_host_timer(); + + if (timer_index < 0) { + ret =3D -TARGET_EAGAIN; + } else { + int *phtimer =3D g_posix_timers + timer_index; + + if (arg2) { + phost_sevp =3D &host_sevp; + ret =3D target_to_host_sigevent(phost_sevp, arg2); + if (ret !=3D 0) { + return -TARGET_EFAULT; + } + } + + ret =3D get_errno(__sys_ktimer_create(clkid, phost_sevp, phtimer)); + if (ret) { + phtimer =3D NULL; + } else { + if (put_user(TIMER_MAGIC | timer_index, arg3, int)) { + ret =3D -TARGET_EFAULT; + } + } + } + return ret; +} + +/* timer_delete(2) */ +static inline abi_long do_freebsd_ktimer_delete(abi_long arg1) +{ + /* args: int timerid */ + abi_long ret; + int timerid =3D get_timer_id(arg1); + + if (timerid < 0) { + ret =3D timerid; + } else { + int htimer =3D g_posix_timers[timerid]; + ret =3D get_errno(__sys_ktimer_delete(htimer)); + g_posix_timers[timerid] =3D 0; + } + return ret; +} + +/* timer_settime(2) */ +static inline abi_long do_freebsd_ktimer_settime(abi_long arg1, abi_long a= rg2, + abi_long arg3, abi_long arg4) +{ + /* + * args: int timerid, int flags, const struct itimerspec *new_value, + * struct itimerspec * old_value + */ + abi_long ret; + int timerid =3D get_timer_id(arg1); + + if (timerid < 0) { + ret =3D timerid; + } else if (arg3 =3D=3D 0) { + ret =3D -TARGET_EINVAL; + } else { + int htimer =3D g_posix_timers[timerid]; + struct itimerspec hspec_new =3D {{0},}, hspec_old =3D {{0},}; + + if (target_to_host_itimerspec(&hspec_new, arg3)) { + return -TARGET_EFAULT; + } + ret =3D get_errno( + __sys_ktimer_settime(htimer, arg2, &hspec_new, &hspec_old)); + if (arg4 && host_to_target_itimerspec(arg4, &hspec_old)) { + return -TARGET_EFAULT; + } + } + return ret; +} + +/* timer_gettime(2) */ +static inline abi_long do_freebsd_ktimer_gettime(abi_long arg1, abi_long a= rg2) +{ + /* args: int timerid, struct itimerspec *curr_value */ + abi_long ret; + int timerid =3D get_timer_id(arg1); + + if (timerid < 0) { + ret =3D timerid; + } else if (!arg2) { + ret =3D -TARGET_EFAULT; + } else { + int htimer =3D g_posix_timers[timerid]; + struct itimerspec hspec; + ret =3D get_errno(__sys_ktimer_gettime(htimer, &hspec)); + + if (host_to_target_itimerspec(arg2, &hspec)) { + ret =3D -TARGET_EFAULT; + } + } + return ret; +} + =20 #endif /* FREEBSD_OS_TIME_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139850; cv=none; d=zohomail.com; s=zohoarc; b=ZH0iSdKModbFTc1/pT+NCFK9KepzR62mSeSFFOeUr0is3rYWoWAfQRHI4fsD70fcCBXaVIw+OQW/AkoY16xUXmkQsiD3DHxK2AzYYciTmrLTbi+Z1PqwbEahbkSJD4/irydK8EQMA9NILJC+RDo9UPBWVqqWRU9Q1725kjHx3oM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139850; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=F6IbMmZeC2LhfVH+W9gdfn11/nlbGPUwztLfxxD5nxM=; b=VaOWxQzMSlF+IDl0S8fM9kpJ0EObWz45zNzds+KADzxT3mGhT1GuU0ajdcmh+umI3zObOM7lFq8ffFkJfQ/033kZeq4EPfe7B/XIMupc+U01H0PT7a4gEadUSTxuatI9nHVNUvOmnxpDBr83FPkD1CrNxeMhcLnccLEgCQcTudo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139850924153.61924789217028; Mon, 18 May 2026 14:30:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vj-0000WK-Fi; Mon, 18 May 2026 17:28:27 -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 1wP5Va-0000UD-A2 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:18 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VV-0000V4-4O for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:15 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-47bdee5bfc4so1929535b6e.1 for ; Mon, 18 May 2026 14:28:12 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139691; x=1779744491; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=F6IbMmZeC2LhfVH+W9gdfn11/nlbGPUwztLfxxD5nxM=; b=jfYnV1tMSVIlfIHVci8zFClE4BWRQ+Ts7yHpe6D14msn9ksZbeYqhEQcmSBNpVf/8G tZldfoqH61QyNacdjy/QfWLAi0bN5dYaJ/1n6jgggnTk7uaEijHY3wwaJJqpfWlB4WER MkSZ845KEVq8cJ1CF5qIMNII2R1zEfCDHbR1zGFT7gLCbiaJNgnc0JOA+RWBQefG3j4A bXfrgwEFCZOfgoMxMr2iYUREBFVteOZyOSamz7I970Qaf2I1Dbqn+EGl2iEul3DUS4iy j9cqR6kZCR6mMqb2UVhb1OfgwFKV0q5w6fbGykesxt90kV/0jBtRDrl6VCwzNSv2v8rs xvCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139691; x=1779744491; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=F6IbMmZeC2LhfVH+W9gdfn11/nlbGPUwztLfxxD5nxM=; b=Fjj7c5IWkV4fGeOM3LxoFDo59bRJ+vdNpyP7Gz1PBRg5C09gbarbpPS85k5NiGVMJk Va98HiqImgexKVuXiI+WJXVCESRFqE16ndaD9nFHZVAaYcOSXFsYrPBkcdo5HsDZX160 C73C3L8KUbb06v6+FRYsPP+gRvRguj9kjeW4l1GAwPWZnQXAQpp4O75w0BmX1W7jLxnw A9xAiyYf/wBvsSmbq0zZrhBrkOwJLWpNDyDWoo+BrptXMI3mj5EUOCtBHcZ9F/jUw+jc ZxiFxX9p8Vq3uIx5Y0zTJOUiR9hyMYrRJzYY+Lcwfo9DlzUeW9Ymwo5Ku02jpCXIgwXu 44lg== X-Gm-Message-State: AOJu0YxVeIS2jhD1P9zEeFfGEzno/DuoXydGbOpzDAmTCyZZU0CAQF72 9ahQ29uFnZM7zs4k/iHiRLUwmcMhP7xK7wn+lQmosWU743vroqWf04QPYssJOYDPULo= X-Gm-Gg: Acq92OHZHgI5eLO5Afhy91aR1YI6gzh+5mmzA6srSRakcnf3vlaNdA4b1BLxsQIF7pX Y6BIF4vGOEMhKm9TVazF9Gbd+BaDBY9tuUD/TEpN4jNDeCYc01eULnhKooEKTVUDwtgn3n8Dw0d d8NNsm4nPvQalJvFjIKzS+SGSLGSE9fjrIbKseLJ5SJUJEpL3sO9uQVJNSvdn9jRSl1MgRjRhWY sNQli/EMgv+MQSfWCqiXZ4jQgjKZ75/NpQE5zquQJPr6KIMN1RoSEJo3A6me2H3xTCDBwdpw3oB +IqT0r0uFPDLR3Id2q+OLPCFIDGkRzq/Z492/oI/uh2wBIgQf5jPPFTkoRUC0sTEh3uan/ndhm1 xSuPrP5aV44M1ay7/jPGzw6rCDU2CccrQwl/lOhw2yZCCdPI44RLkIsfCAJSVsUJsF40Sah3Ukb N7CQbDCNvp3A== X-Received: by 2002:a05:6808:199a:b0:479:d7ee:8e48 with SMTP id 5614622812f47-482cb76a1f1mr11577614b6e.8.1779139691083; Mon, 18 May 2026 14:28:11 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:37 -0600 Subject: [PATCH v2 19/37] bsd-user: Add select, pselect, and ppoll to os-time.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-19-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6810; i=imp@bsdimp.com; h=from:subject:message-id; bh=QRMNfdgVjM1p1MaVbK/vwOn5qWkJj8Vh++JBLCnexT0=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RHh6zZRbEEZg9A46JS/zk0JSgtJSB4K7pY9 6k3Kif5e7yJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AEX2D/48S21jbfGtOwmRc04iBWXX9o6PDA3Nd18FIFNo5a96N3/6yQnpRiRWkyhOZgm6FaeawMl tjirUPVeUr/wjLtVl+Y9k7vyPqfCnfQR7uyAmPfjJRhyRRuFjpCqArFIBrLQ1O7Z0E7UTV8aWyV Hfp6Jyb4JVRu2pp95cd/CRVwADURROwUz5B2KiodXmq1YqR0xuXQZhtcne96BTmsfequuuuEuNJ /psj6sWiU2AdpY+QJ6WgEerf+4GZxvQS7q32qS28WU15BIH/rt32/UCnxkTIKB2ZagPdgrGnOcY TdzNJ9DgZZ0cqcSkB2r6cy5LxX5B6/zx7GFyicVtd2NYInD2tZUj0ocIZJPx8o345X12d2ZK7Ql s9kmzIvsi7nkLpSifK7kEEOVeaBue5GKOiB1S59znMlbkqmv3Zym88DF+tPtuvA2qOy7JIOTx/F Iea3mHTXxARq+oGZZifD6OI8yVltpu6GTa/jhHlJ/FK21+KEa3ibgQ3IsJ1VPS/79o3YCzWASkV +R4Y+k+6RgM4THWOcFsM3dJ9wd3JnPQSASqfblnIGzS9h7eo9LqOnmKKnMa8UIb8ZT+8cQjbMVz 3ahvJdI9JzofiXYt1ollEhuatHZfYcZ1ZjsNqg3Et3RAZeZIZE1ynCKSx9P+yCdA2jYVWfa9O3F JNEqB3cbowp8dWw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::234; envelope-from=imp@bsdimp.com; helo=mail-oi1-x234.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139852437154100 Add I/O multiplexing system call shims: select, pselect, and ppoll with proper fd_set, timespec/timeval, and signal mask conversion. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-time.h | 202 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 202 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 05fa043442..12c5ba02e8 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -427,5 +427,207 @@ static inline abi_long do_freebsd_ktimer_gettime(abi_= long arg1, abi_long arg2) return ret; } =20 +/* select(2) */ +static inline abi_long do_freebsd_select(CPUArchState *env, int n, + abi_ulong rfd_addr, abi_ulong wfd_addr, abi_ulong efd_addr, + abi_ulong target_tv_addr) +{ + fd_set rfds, wfds, efds; + fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; + struct timeval tv, *tvp; + abi_long ret, error; + + ret =3D copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); + if (ret !=3D 0) { + return ret; + } + ret =3D copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); + if (ret !=3D 0) { + return ret; + } + ret =3D copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); + if (ret !=3D 0) { + return ret; + } + + if (target_tv_addr !=3D 0) { + if (t2h_freebsd_timeval(&tv, target_tv_addr)) { + return -TARGET_EFAULT; + } + tvp =3D &tv; + } else { + tvp =3D NULL; + } + + ret =3D get_errno(safe_select(n, rfds_ptr, wfds_ptr, efds_ptr, tvp)); + + if (!is_error(ret)) { + if (rfd_addr !=3D 0) { + error =3D copy_to_user_fdset(rfd_addr, &rfds, n); + if (error !=3D 0) { + return error; + } + } + if (wfd_addr !=3D 0) { + error =3D copy_to_user_fdset(wfd_addr, &wfds, n); + if (error !=3D 0) { + return error; + } + } + if (efd_addr !=3D 0) { + error =3D copy_to_user_fdset(efd_addr, &efds, n); + if (error !=3D 0) { + return error; + } + } + if (target_tv_addr !=3D 0) { + error =3D h2t_freebsd_timeval(&tv, target_tv_addr); + if (is_error(error)) { + return error; + } + } + } + return ret; +} + +/* pselect(2) */ +static inline abi_long do_freebsd_pselect(CPUArchState *env, int n, + abi_ulong rfd_addr, abi_ulong wfd_addr, abi_ulong efd_addr, + abi_ulong ts_addr, abi_ulong set_addr) +{ + CPUState *cpu =3D env_cpu(env); + TaskState *tstate =3D cpu->opaque; + fd_set rfds, wfds, efds; + fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; + sigset_t *set_ptr; + struct timespec ts, *ts_ptr; + void *p; + abi_long ret, error; + + ret =3D copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); + if (is_error(ret)) { + return ret; + } + ret =3D copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); + if (is_error(ret)) { + return ret; + } + ret =3D copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); + if (is_error(ret)) { + return ret; + } + + /* Unlike select(), pselect() uses struct timespec instead of timeval = */ + if (ts_addr) { + if (t2h_freebsd_timespec(&ts, ts_addr)) { + return -TARGET_EFAULT; + } + ts_ptr =3D &ts; + } else { + ts_ptr =3D NULL; + } + + if (set_addr !=3D 0) { + p =3D lock_user(VERIFY_READ, set_addr, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&tstate->sigsuspend_mask, p); + unlock_user(p, set_addr, 0); + set_ptr =3D &tstate->sigsuspend_mask; + } else { + set_ptr =3D NULL; + } + + ret =3D get_errno(safe_pselect(n, rfds_ptr, wfds_ptr, efds_ptr, ts_ptr, + set_ptr)); + if (ret !=3D -TARGET_ERESTART) { + tstate->in_sigsuspend =3D true; + } + if (!is_error(ret)) { + if (rfd_addr !=3D 0) { + error =3D copy_to_user_fdset(rfd_addr, &rfds, n); + if (is_error(error)) { + return error; + } + } + if (wfd_addr !=3D 0) { + error =3D copy_to_user_fdset(wfd_addr, &wfds, n); + if (is_error(error)) { + return error; + } + } + if (efd_addr !=3D 0) { + error =3D copy_to_user_fdset(efd_addr, &efds, n); + if (is_error(error)) { + return error; + } + } + } + return ret; +} + +/* ppoll(2) */ +static inline abi_long do_freebsd_ppoll(CPUArchState *env, abi_long arg1, + abi_long arg2, abi_ulong arg3, abi_ulong arg4) +{ + CPUState *cpu =3D env_cpu(env); + TaskState *tstate =3D cpu->opaque; + abi_long ret; + nfds_t i, nfds =3D arg2; + struct pollfd *pfd; + struct target_pollfd *target_pfd; + struct timespec ts, *ts_ptr; + sigset_t *set_ptr; + void *p; + + target_pfd =3D lock_user(VERIFY_WRITE, arg1, + sizeof(struct target_pollfd) * nfds, 1); + if (!target_pfd) { + return -TARGET_EFAULT; + } + pfd =3D alloca(sizeof(struct pollfd) * nfds); + for (i =3D 0; i < nfds; i++) { + pfd[i].fd =3D tswap32(target_pfd[i].fd); + pfd[i].events =3D tswap16(target_pfd[i].events); + } + + /* Unlike poll(), ppoll() uses struct timespec. */ + if (arg3) { + if (t2h_freebsd_timespec(&ts, arg3)) { + return -TARGET_EFAULT; + } + ts_ptr =3D &ts; + } else { + ts_ptr =3D NULL; + } + + if (arg4 !=3D 0) { + p =3D lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&tstate->sigsuspend_mask, p); + unlock_user(p, arg4, 0); + set_ptr =3D &tstate->sigsuspend_mask; + } else { + set_ptr =3D NULL; + } + + ret =3D get_errno(ppoll(pfd, nfds, ts_ptr, set_ptr)); + if (ret !=3D -TARGET_ERESTART) { + tstate->in_sigsuspend =3D true; + } + if (!is_error(ret)) { + for (i =3D 0; i < nfds; i++) { + target_pfd[i].revents =3D tswap16(pfd[i].revents); + } + } + unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds); + + return ret; +} + +/* kqueue(2) */ =20 #endif /* FREEBSD_OS_TIME_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139768; cv=none; d=zohomail.com; s=zohoarc; b=JuX+4nNiTWtwemp0Qf0F+UqB75At4Asii/bka/nPpYd0v5POfvs1sZaO5whTHboETLpy+969rzuSlNauBNLMDUmy64xO7JkuY+VCvT1nNfXq+Qk7qWE+DibiU+4Vn/3mwk4VlHi8c64VA0sLpOZ9IAuo85FO+DBBlByZV9+AHcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139768; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=brViEU6vUuDSXtPFY7z05zUWCGk5By4iJYldPBZNo9I=; b=goLuaGbvOOZht+Y19RQ4zVCCpgtIqJRC43Gk71qj2/QSY/5GYkDpWk7QjtjdoatKQtcWEax0v4wYBWfSHqZIHASo8q3NbQCRYTKyyCaX64cuRyCektHo6heufvD4tYZVF/+OEXoaIJk4MJ3yAAmzepbAV+sUBInGc5v4WVWfKIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177913976859426.535288081555336; Mon, 18 May 2026 14:29:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vf-0000VG-1g; Mon, 18 May 2026 17:28:23 -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 1wP5Va-0000U8-5A for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:18 -0400 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VV-0000VC-63 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:15 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7dbca22dbfeso1426881a34.1 for ; Mon, 18 May 2026 14:28:12 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139692; x=1779744492; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=brViEU6vUuDSXtPFY7z05zUWCGk5By4iJYldPBZNo9I=; b=o240d/tMgWsxLhQikz/xI8TDfLHDG/+/1IPNgZTTBIrj2H4Mha2RxOugZg9mWe2T5c qifsmlm/F25xySbSxF6mXccO/SYJYAssQs6gtgiJK+P2RUPz7ABpWTsYl4Mi8g7joqzn 0WRplyYlP+YdA6B8mBkgrpc+4+lQbDjCpv6xu6g4F0K1f9nkrq7tpxqD+DLp/axQj037 KaABjOmAdBPJmspM5+7PWfa16Wgb9oiHXhquIHmZB/UuikRvJ6Mmx5eeBcQxd29xljzO hQbNS3ccuRNmydBDxGMiOU4EkYRR+A8jxeskIJ2SWyv2mFFEGtU58XLLOvNBf41Fv9dW kVgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139692; x=1779744492; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=brViEU6vUuDSXtPFY7z05zUWCGk5By4iJYldPBZNo9I=; b=XioaNU7mdJz8VK5DHYyrz/hy9DMZ1HAjBdPxefvOcjtI6csKRgAqUOkm5+YogbM9Xs ZNaysA6PQI6l73stR6GOXVqUCpqTBCS4iw2Ay4QKwm4ZqjvOqik9aJ9PezmbCwR2ExXx zjKhrQHnniLKsIgzOXctc5VActnALeNurerCyl0ttbSSHLx5MVSNvG3SYPwZUNgd6fLM VihXSDE7TsPuGuVQoVzb7nl4/JJPNVepoxvYLFf0pBapgicfe0vQcz6dmus5gDagb6Gs jwFYM4xhoF7Q/fR2VewOzZnQGOGLBA4KQCKxE6+yv00vkpmhCkv97202l6w+vNgtwCGz baSA== X-Gm-Message-State: AOJu0YwCDpcsZ/qCkoEKtllSuSkIGEagI6iD5+lHM7iX2UmAjFvL14GY f9analeptv73EHqLG163H4+JmSehiF+YB/9VLWPTGTWqUw9AzoVDyA8ADQ3mXI2vmRs= X-Gm-Gg: Acq92OEM51ySAz9DFTQJZN5iKykujx95RpW96Gh7S0hiOi5lqHAfRltA/zfgfmcBHyf HTqR7bR8BMJ9tck6Xc+b/h1wJfGEFhdtJhFpL0/e0DvHFiXYEQ0aCRy0vX3wjXqZhWZuHQLiaP9 S8qoF1E00qgA203e2gkCWdGkZSDKir0hFZF4vMsf58AdDzztpBKZ/RAq/5irYXRdM4b6NvQbue9 W36izYPaNdVhC08LwkrCJW8Sa9J/3dFlp/P+TK1tkAl1sHhPJe5/vespJRRIO9uBLm74tKHyXZi d6m+SoSmEimqJxCLEq1e25LeJI2vivb0g0VKoLJMIpLfEC7iE9vyTGIDtvUJnu218ECDAnN55af nhpUWPje6klYL05VrApCBme0PkIZ3lqcX3otil1Vok3hbwx8DQhBwTg0j82QUSnkknsf/Tkd3Ev Uw5tvt9AE25bYK08n1rpKd X-Received: by 2002:a05:6830:3983:b0:7de:44a5:51ea with SMTP id 46e09a7af769-7e4ea07a522mr10373030a34.6.1779139691985; Mon, 18 May 2026 14:28:11 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:38 -0600 Subject: [PATCH v2 20/37] bsd-user: Add kqueue and kevent functions to os-time.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-20-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Sean Bruno , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8160; i=imp@bsdimp.com; h=from:subject:message-id; bh=V7aPc+aOfD1PWed0e7bWG+wlTSpCwp0HL2tfbVJtQQY=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RHBBj0qH/Gxv3NexcrLSRzHINEUOHB0FyOP KpS6X8qvUeJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguERwAKCRBsHNEofbAR AMNsEADSwqe3yqI8wOrcQS9wTCQHe9W9GjD6gsgBeJCvlyfVqYr36x3QrYz6MBtPVfoYfQHKEyZ ZVVU/+auUgGQGAd6JTnkrSOS5Ax/o56r/r0w0MYDZbVEXCg8+m8ODgnYDX69Ka9MlXgCDJI4LDf uWVoXf20lwbha9pB/4cy93QtQq5lTUCQxd+GVVGjy28UFUNPbw/4oCTgy79b1GrVrqFofCXho2I f15foyKCrcEP+sz1wfpsx7MHLak3M3tcS2XdNDc2AGwL7CbqtE/hxsyu6nhPOWIOs/NHhzEd/oY YRlhhX5QKvUK7VTZxCa/cyTHXbHN3DtZyvEYyAsFHOfqoxVuhozLlM1VYuIc7HuC3qH5B0TW7n7 AVxpC6Emx99wJ5JRYiFwgp+jvSX03O8wJjl/y3ABcD+YXDKr8coPzCUxwvITjWU7aeJxjR/txBI u8fULtGjWXS8dAuJEZDLP/HkgGEapJ7WDiFnPVpCz1q0+2k9h/v6tZrY7yv5mt1MyW9CImVvmoO 8hkDnObu/8HtBKZZdIcQMoOBMBAQpI6maEtN5fP/cNZLYARc5DtW0osipp0izuh+RjHaQDKFKi5 l4xEImK1fljnbu/iXz8uZYq9R7DrCiWLdPD1onwMp6lZ7Fa4NWqfRqHDI6Zp/W5BL8iM+yKnbUR czbaGDMM8Up0n0g== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32a; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32a.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139769249158500 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=C3=ABl Urankar Signed-off-by: Sean Bruno Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-time.h | 173 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 173 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 12c5ba02e8..078355392d 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -629,5 +629,178 @@ static inline abi_long do_freebsd_ppoll(CPUArchState = *env, abi_long arg1, } =20 /* 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 =3D NULL, *eventlist =3D NULL; + struct target_freebsd11_kevent *target_changelist, *target_eventlist; + struct timespec ts; + int i; + + if (arg3 !=3D 0) { + target_changelist =3D lock_user(VERIFY_READ, arg2, + sizeof(*target_changelist) * arg3, 1= ); + if (target_changelist =3D=3D NULL) { + return -TARGET_EFAULT; + } + + changelist =3D alloca(sizeof(struct kevent) * arg3); + memset(changelist, '\0', sizeof(struct kevent) * arg3); + for (i =3D 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 =3D=3D 32 + changelist[i].udata =3D (void *)(uintptr_t)target_changelist[i= ].udata; + tswap32s((uint32_t *)&changelist[i].udata); +#else + changelist[i].udata =3D (void *)(uintptr_t)target_changelist[i= ].udata; + tswap64s((uint64_t *)&changelist[i].udata); +#endif + } + unlock_user(target_changelist, arg2, sizeof(*target_changelist) * = arg3); + } + + if (arg5 !=3D 0) { + eventlist =3D alloca(sizeof(struct kevent) * arg5); + } + if (arg6 !=3D 0) { + if (t2h_freebsd_timespec(&ts, arg6)) { + return -TARGET_EFAULT; + } + } + ret =3D get_errno(safe_kevent(arg1, changelist, arg3, eventlist, arg5, + arg6 !=3D 0 ? &ts : NULL)); + + if (arg5 =3D=3D 0) { + return ret; + } + + if (!is_error(ret)) { + target_eventlist =3D lock_user(VERIFY_WRITE, arg4, + sizeof(*target_eventlist) * arg5, 0); + if (target_eventlist =3D=3D NULL) { + return -TARGET_EFAULT; + } + for (i =3D 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 =3D=3D 32 + tswap32s((uint32_t *)&eventlist[i].udata); + target_eventlist[i].udata =3D (uintptr_t)eventlist[i].udata; +#else + tswap64s((uint64_t *)&eventlist[i].udata); + target_eventlist[i].udata =3D (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 =3D NULL, *eventlist =3D NULL; + struct target_freebsd_kevent *target_changelist, *target_eventlist; + struct timespec ts; + int i; + + if (arg3 !=3D 0) { + target_changelist =3D lock_user(VERIFY_READ, arg2, + sizeof(struct target_freebsd_kevent) * arg3, 1); + if (target_changelist =3D=3D NULL) { + return -TARGET_EFAULT; + } + + changelist =3D alloca(sizeof(struct kevent) * arg3); + for (i =3D 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 =3D=3D 32 + changelist[i].udata =3D (void *)(uintptr_t)target_changelist[i= ].udata; + tswap32s((uint32_t *)&changelist[i].udata); +#else + changelist[i].udata =3D (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 !=3D 0) { + eventlist =3D alloca(sizeof(struct kevent) * arg5); + } + if (arg6 !=3D 0) { + if (t2h_freebsd_timespec(&ts, arg6)) { + return -TARGET_EFAULT; + } + } + ret =3D get_errno(safe_kevent(arg1, changelist, arg3, eventlist, arg5, + arg6 !=3D 0 ? &ts : NULL)); + + if (arg5 =3D=3D 0) { + return ret; + } + + if (!is_error(ret)) { + target_eventlist =3D lock_user(VERIFY_WRITE, arg4, + sizeof(struct target_freebsd_kevent) * arg5, 0); + if (target_eventlist =3D=3D NULL) { + return -TARGET_EFAULT; + } + for (i =3D 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 =3D=3D 32 + tswap32s((uint32_t *)&eventlist[i].udata); + target_eventlist[i].udata =3D (uintptr_t)eventlist[i].udata; +#else + tswap64s((uint64_t *)&eventlist[i].udata); + target_eventlist[i].udata =3D (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) */ =20 #endif /* FREEBSD_OS_TIME_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139889; cv=none; d=zohomail.com; s=zohoarc; b=QZ7lntfmLCbRtFmrwGrGBJcxW/Ofx1f/9A36YKN+1B+1hS5xH/ln/86uCHmU8PssP3IW3J+6zTVBRtaEq5hywZBLFxhT/Vzr+yRyMCwH9AzwgcPbnvZBzTxBohxoquwXAQvfK7Dl7u2vwXBGefIlVfAI/Drl3qWKSBsEWwsfRak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139889; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8thu+PPYmdudevPxRG88hz59xzWDVpPHXseXpV6+kjA=; b=HWv5ynNNBBcsDkwGmjd1C61vbMrqI9esy/fKu0Qz9F5ttHHqcCBUxNL0wvBNUPjQL0PLHHgW1ESvbhQo6dQbeoDGcyQCJVu5sX7ob+P3jNxRE6JI9Q6Q4Ts7ULsYg6GI9NC9OM8tpzdcz5swfP0Xd7L+QpvBThX2NSQ6ho3LbjI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139889230919.1664852401385; Mon, 18 May 2026 14:31:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vk-0000X7-Aq; Mon, 18 May 2026 17:28:28 -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 1wP5Vb-0000UV-0b for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:19 -0400 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VW-0000VK-Ja for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:16 -0400 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-7dea20cf21aso2964828a34.1 for ; Mon, 18 May 2026 14:28:13 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139693; x=1779744493; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8thu+PPYmdudevPxRG88hz59xzWDVpPHXseXpV6+kjA=; b=ZYie1Q/hwkKJ2RhrRZMv9jsm2pvxU/rjnBj0jrnA1dSq2V2t9G2d9optuUsV1GEgFP 4fr38fG4BywnsuHFt80atJA+iV/C4Crypeer9bz8gc+LOUmqGtg7CQij9W8NKuDtLDX5 9R+V6BjDOprgefXuByr5qwz9NeucrBabbcDfAA2DGY2nu06yuNUhLCs5UAfy8aZPTwF3 7oc2BHQTWFHlFCHeJwVzmtB+0qbAX6RYeEHCPQrOnNcCY5G6+uBtmtyIfYvQbZ5LaDsl OLEmGruPPFUTCGjOTgDhuZxUTZGEFDpGeXS+8NCGh6My60UYwaQcr6Yr6YkeYH2l+zWH XEOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139693; x=1779744493; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=8thu+PPYmdudevPxRG88hz59xzWDVpPHXseXpV6+kjA=; b=Ew0aOzbyuGu3qiwlOUROQHTqIq+GehHs6l0txXzfmSyi4G2bZBY0z6Fuz8CV5nHynM ADhr/8hTpfr2RQa1xeMUgBGmD1wUn+ZSJsQ07/pmWkQ+0RmGNPeaXd9/9/6zL4dvZ5CM 3N8UoGFm9tlcNW/dKBFUjm7mSk3THoEz7AFpMu/+SNhBoz2fpzQ/dg5bL7wmEX3v+b5T o86S60I5hM8M3NAIWzaqXLvA3RXfVsFUGd7pfn+jnfnevrAQwGGa2c7N8z8hdccLXx6j 1AZv3F8rzHg5n++nxurS95w8gKhbYqaQULVZd1lKxH3YgPsRt2jvTCxPmM1YXiQYvM9l 0jgw== X-Gm-Message-State: AOJu0YzPh1DaRdAENw1tET3CNpuLOMsvKMOUyVUtQqjYdDX1vxT/9nKh W8IafxF7B0K3A3PsxSq48dZTz2+e19gOkNSBvPGa+8fCNfbnHDefXOkcuSuGFQ5trrw= X-Gm-Gg: Acq92OFvmepIYMhOqcAapkF2VcS4zmhWIFnn6090x8lBcGpLQ/HyW5/GtwXCRAxtSnj GPEDKxnd11fuadvPQZZxqnaGsKR1f+IWCRrrjw6PHh9VrvMritME+BfVt7FS4/arSq2Tx13fG4B +G9K3aMHrY8zgc57xWfgHBXdy6EuGu5TVnKRu9FGv+p/6wThlTxansD4LnMoxiQ8aEI95DZGK3v piPczXCbVxbEvA2uk4OYvhkolru1MA+qDIcb9a7ous0jLxgUgccmM6or3o+F0fWOqy0FZ7E/NjL Eq1ubp3SDRotnQpgDiERzIE0wjcebY32C8EEljk8bthR9NTGs//pS/U2NaEGkrCazmQvUgITrgV d1Oh6rH4CxUZ8PjaaE+8xmTi848XvC7lmaZPvq+GWkaA4397zDJjvI7KaAVzmdpgkpHjT2xy+oK SpsIVS+wT51XKwwAIX3cDf X-Received: by 2002:a05:6830:6417:b0:7dc:c4ae:a679 with SMTP id 46e09a7af769-7e4ea07276amr11812246a34.9.1779139692871; Mon, 18 May 2026 14:28:12 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:39 -0600 Subject: [PATCH v2 21/37] bsd-user: Add sigtimedwait, itimer, and futimens to os-time.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-21-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8135; i=imp@bsdimp.com; h=from:subject:message-id; bh=Y25u3JDX7lhIWEMCTPHXKRs1q58haafXWKW3JERQHSM=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RI5l4xcPIKF1PlE/gqJZQFf7u0WIL41e6n+ TDSbFpTGuuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AJEzD/4iXkooiUjSRAaMIM5CFzsdh+s9cFJdMtXOeU8XTFgIGU9iDlarAJTrsonsyebtrkfrqe9 9aOsZMc6eqvInCbfzASLDZDirSROk3VOfOarfdHMKpsH97kTU+ciBa/bPbpd417tEeJPenGHPlp sSwmc62tgrLw/AAIB6RgI7jH0QybTd4h2Sup+ilNnYMgooH+37lyq1yq13p2fT2M4iB5cZP5a+5 PtpGPxqY9eMUOjzB2siq0USpjDugMh1sUNraFkdnnxuUhBKJq4W7lBbGqxc6kOVM+v36Sj6iCDW Eb9BEZTvKvq0rvkVFKZ30uv8f0iPAisyzfChRZM6mhAPXqCDDbm7BFFZXJx+E8ADvhxCOoQnvZk 6F2JjJ1DrbTXj1XhLaNSRx4WZ3tFVDDN+pPNTF6N3w6cbqawsNZgArTjhr/19WccKcsBJXlS+DQ hndujDePVi00uFCmRgExeezsxnxZ3Zf4iAH3xHVkp3CF92iR2mji3M9XPUNneQA6pkqA+3TeeOU 7CqUIZiPMzuwmTCnYGKPTNgAxWMFqSRGUsqLqKLOjQfFcX+g27xfKcCZKrp+3Hb6A/pgMp+bwNf V3q+N57qPS1m91kYiIuSwv0HP2+GdkOWQ/xoK6kN86wzG73Anlz7e4H3tuNe6CQy64fgo7nIrSr hhnsoID0IpuSvMw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32c; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32c.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139890814158500 Complete os-time.h with sigtimedwait, setitimer, getitimer, clock_getcpuclockid2, futimens, and utimensat system call shims. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-time.h | 194 +++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 184 insertions(+), 10 deletions(-) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 078355392d..f24b6f35db 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -124,19 +124,19 @@ static inline abi_long do_freebsd_gettimeofday(abi_ul= ong arg1, abi_ulong arg2) struct timeval tv; struct timezone tz, *target_tz; /* XXX */ =20 - if (arg2 !=3D 0) { - if (!lock_user_struct(VERIFY_READ, target_tz, arg2, 0)) { - return -TARGET_EFAULT; - } - __get_user(tz.tz_minuteswest, &target_tz->tz_minuteswest); - __get_user(tz.tz_dsttime, &target_tz->tz_dsttime); - unlock_user_struct(target_tz, arg2, 1); - } ret =3D get_errno(gettimeofday(&tv, arg2 !=3D 0 ? &tz : NULL)); if (!is_error(ret)) { if (h2t_freebsd_timeval(&tv, arg1)) { return -TARGET_EFAULT; } + if (arg2 !=3D 0) { + if (!lock_user_struct(VERIFY_WRITE, target_tz, arg2, 0)) { + return -TARGET_EFAULT; + } + __put_user(tz.tz_minuteswest, &target_tz->tz_minuteswest); + __put_user(tz.tz_dsttime, &target_tz->tz_dsttime); + unlock_user_struct(target_tz, arg2, 1); + } } =20 return ret; @@ -149,12 +149,12 @@ static inline abi_long do_freebsd_settimeofday(abi_lo= ng arg1, abi_long arg2) struct timezone tz, *target_tz; /* XXX */ =20 if (arg2 !=3D 0) { - if (!lock_user_struct(VERIFY_READ, target_tz, arg2, 0)) { + if (!lock_user_struct(VERIFY_READ, target_tz, arg2, 1)) { return -TARGET_EFAULT; } __get_user(tz.tz_minuteswest, &target_tz->tz_minuteswest); __get_user(tz.tz_dsttime, &target_tz->tz_dsttime); - unlock_user_struct(target_tz, arg2, 1); + unlock_user_struct(target_tz, arg2, 0); } if (t2h_freebsd_timeval(&tv, arg1)) { return -TARGET_EFAULT; @@ -595,6 +595,7 @@ static inline abi_long do_freebsd_ppoll(CPUArchState *e= nv, abi_long arg1, /* Unlike poll(), ppoll() uses struct timespec. */ if (arg3) { if (t2h_freebsd_timespec(&ts, arg3)) { + unlock_user(target_pfd, arg1, 0); return -TARGET_EFAULT; } ts_ptr =3D &ts; @@ -605,6 +606,7 @@ static inline abi_long do_freebsd_ppoll(CPUArchState *e= nv, abi_long arg1, if (arg4 !=3D 0) { p =3D lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1); if (p =3D=3D NULL) { + unlock_user(target_pfd, arg1, 0); return -TARGET_EFAULT; } target_to_host_sigset(&tstate->sigsuspend_mask, p); @@ -802,5 +804,177 @@ static inline abi_long do_freebsd_kevent(abi_long arg= 1, abi_ulong arg2, } =20 /* sigtimedwait(2) */ +static inline abi_long do_freebsd_sigtimedwait(abi_ulong arg1, abi_ulong a= rg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + sigset_t set; + struct timespec uts, *puts; + siginfo_t uinfo; + + p =3D lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&set, p); + unlock_user(p, arg1, 0); + if (arg3) { + puts =3D &uts; + ret =3D t2h_freebsd_timespec(puts, arg3); + if (ret !=3D 0) { + return ret; + } + } else { + puts =3D NULL; + } + ret =3D get_errno(sigtimedwait(&set, &uinfo, puts)); + if (!is_error(ret) && arg2) { + p =3D lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t), 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + host_to_target_siginfo(p, &uinfo); + unlock_user(p, arg2, sizeof(target_siginfo_t)); + } + return ret; +} + +/* setitimer(2) */ +static inline abi_long do_freebsd_setitimer(int arg1, abi_ulong arg2, + abi_ulong arg3) +{ + abi_long ret =3D 0; + struct itimerval value, ovalue, *pvalue; + + if (arg2) { + pvalue =3D &value; + if (t2h_freebsd_timeval(&pvalue->it_interval, arg2) || + t2h_freebsd_timeval(&pvalue->it_value, + arg2 + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + } else { + pvalue =3D NULL; + } + ret =3D get_errno(setitimer(arg1, pvalue, &ovalue)); + if (!is_error(ret) && arg3) { + if (h2t_freebsd_timeval(&ovalue.it_interval, arg3) || + h2t_freebsd_timeval(&ovalue.it_value, + arg3 + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + } + return ret; +} + +/* getitimer(2) */ +static inline abi_long do_freebsd_getitimer(int arg1, abi_ulong arg2) +{ + abi_long ret =3D 0; + struct itimerval value; + + ret =3D get_errno(getitimer(arg1, &value)); + if (!is_error(ret) && arg2) { + if (h2t_freebsd_timeval(&value.it_interval, arg2) || + h2t_freebsd_timeval(&value.it_value, + arg2 + sizeof(struct target_freebsd_timeval))) { + return -TARGET_EFAULT; + } + } + return ret; +} + +/* clock_getcpuclockid2(id_t, int, clockid_t *) Not documented. */ +static inline abi_long do_freebsd_clock_getcpuclockid2(abi_ulong arg1, + abi_ulong arg2, abi_ulong arg3, abi_ulong arg4) +{ + abi_long ret =3D 0; + id_t id; /* 64-bit value */ + int which; + abi_ulong target_clk_id_addr; + clockid_t clk_id; + +#if TARGET_ABI_BITS =3D=3D 32 + id =3D (id_t)target_arg64(arg1, arg2); + which =3D (int)arg3; + target_clk_id_addr =3D arg4; +#else + id =3D (id_t)arg1; + which =3D (int)arg2; + target_clk_id_addr =3D arg3; +#endif + + if (target_clk_id_addr =3D=3D 0) { + return -TARGET_EINVAL; + } + + switch (which) { + case TARGET_CPUCLOCK_WHICH_PID: + ret =3D get_errno(clock_getcpuclockid2(id, CPUCLOCK_WHICH_PID, &cl= k_id)); + break; + + case TARGET_CPUCLOCK_WHICH_TID: + ret =3D get_errno(clock_getcpuclockid2(id, CPUCLOCK_WHICH_TID, &cl= k_id)); + break; + + default: + ret =3D -TARGET_EINVAL; + break; + } + + if (!ret && put_user_s32(clk_id, target_clk_id_addr)) { + ret =3D -TARGET_EFAULT; + } + + return ret; +} + +static inline abi_long do_freebsd_futimens(abi_ulong arg1, + abi_ulong arg2) +{ + struct timespec *tvp, tv[2]; + + if (arg2 !=3D 0) { + if (t2h_freebsd_timespec(&tv[0], arg2) || + t2h_freebsd_timespec(&tv[1], arg2 + + sizeof(struct target_freebsd_timespec))) { + return -TARGET_EFAULT; + } + tvp =3D tv; + } else { + tvp =3D NULL; + } + + return get_errno(futimens(arg1, tvp)); +} + +static inline abi_long do_freebsd_utimensat(abi_ulong arg1, + abi_ulong arg2, abi_ulong arg3, abi_ulong arg4) +{ + abi_long ret =3D 0; + void *p; + struct timespec *tvp, tv[2]; + + if (arg3 !=3D 0) { + if (t2h_freebsd_timespec(&tv[0], arg3) || + t2h_freebsd_timespec(&tv[1], arg3 + + sizeof(struct target_freebsd_timespec))) { + return -TARGET_EFAULT; + } + tvp =3D tv; + } else { + tvp =3D NULL; + } + + p =3D lock_user_string(arg2); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(utimensat(arg1, p, tvp, + target_to_host_bitmask(arg4, fcntl_flags_tbl))); + unlock_user(p, arg2, 0); + return ret; +} =20 #endif /* FREEBSD_OS_TIME_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139885; cv=none; d=zohomail.com; s=zohoarc; b=ewWod2xYIDQiBhD1izJ6AyLpF9zduycKUryVkK8ZWsEvTY9QIHjc9TdG+ggm0K+zuessc1mNsmIWu2rvwj7ZSOJBFk8JW403NGnsy6nmyZg/TW6hs3AUlE5/djVgsvu1Ivz5RsKGJeHofyniSpbyi1gTVY/czoy7Nu5qdti0RT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139885; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lRgIbZa5zVZI9ihk3p6ZJUVVoOaxd087DgvBy7iqbWQ=; b=dA5fRgqI4J9oXvQGUFz6jpzVFHlrwIGABf7226nltYmw3PJsuaHKaHTkz2UFQm+XxNbHkte/nIlq/jMwxDz9RNLfRDiP2g5r2jX5P8E4xtPzqkNvpQ/fdYLlhVsyEo/09/7Oxqca0l/DERN67916Y67Jecsm7gGqmeYRVL4//ZE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139885246876.7316753162107; Mon, 18 May 2026 14:31:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vk-0000Wq-4O; Mon, 18 May 2026 17:28:28 -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 1wP5Vc-0000Uq-Ut for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:21 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5VZ-0000VU-1P for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:20 -0400 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-47c6f914617so1366012b6e.1 for ; Mon, 18 May 2026 14:28:15 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139694; x=1779744494; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lRgIbZa5zVZI9ihk3p6ZJUVVoOaxd087DgvBy7iqbWQ=; b=NrwvFipAOAzFHzXU2pX4IbUBpxXU48D8drVaws8gnQq6EZeZtVQoQO01tZCBe4ZFZi HOAtn6fyd1Uomn+ivXTdlb6shdqJaJsbN81YrWADRWAye6KginL5YfbhNiMKuGw0qcaS OD6Amdqzh1IcMwpG62k4ugg23iac7kywmx8/DYL4LrutWIlvN6SPqNfUCkXkHYzmOaX2 vpjGeu/M+jEGPJJtoUruUwWzDFl9mlacb2JOWuRtx9j+XpR8UrNqa0Ao9WGSoZbnw7Y2 mlU1J3Vhq5eYWq7+9Zg/yJJKCMNQU/rZWiTN2gHyE1/iZ7P3oYTL1qitF1eSRm900hjz DgaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139694; x=1779744494; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=lRgIbZa5zVZI9ihk3p6ZJUVVoOaxd087DgvBy7iqbWQ=; b=ff6/wTQcKqJWb4gercSNOEdimUCWnzou+H/LALQuG5557+WjiCrr3dvxmk9q42ysLG QyUk38fWEZo5QEQYRABIair21dfR6ykAB6briaGVTH211BxhCx8bEXPJJPDlVtmxdSBY 1dpV/GJsluudETzRXU9p9Z/V7+7OTcV59xjde3401nFIdlgLlRy65p9A9enUIJiZ7j9U 2yTahoIyCTlpWn8kMujHEHoKDSEb1bq3++VbF3VeFeUDUMcj4OAO4RBQwK8oF/VV4MP8 x/uMTyeM8DDqoD1eVGB8vjY/bmq5O8UUK8CgYC8BjngZ0rFoxnGXUKnFNRak8+E5lubX rr2Q== X-Gm-Message-State: AOJu0Yxwz/yISob10ptgPW1mbceavGlReB395K7+iL18HZZx8Vt3uVz7 lXaoP6Oz0wbFudhqIQuQgI+124dSNNUIU/E5HEEXuuyT4v/BTBOG/+WQqRxIkDbo8Xc= X-Gm-Gg: Acq92OEHqVpGuqOQ2EqbpevDGdHudGgaSUSVTgl1n/UTkGnbIUfZaD8NogSdFMSZ2pu sHB8m2NYtQ/bXqDE3k4dfyO2D25wXEhyoFSiCJqgDSvraWWG9cB/oQ1KL465MoF0OPDaxSvDWCl gceKEr3/cFFSKGXhiTQ8fcjS1j32QBqcr1BUGXu24+yvmKrDxo+v56uZ8JyQgEttxXcMHpogN16 fuqf78fBFumc0HWj7T2/Ape6ZflBgHQ/SxuZ/PQeaHSmeHc25aXtTLureWD7VssmoadNUfbkset 7CCMAu+XbmtgW4hetD2Wme2EitFCG+U4YkW5Q9d0QrqN/EUEFuT3e3/Syjr39zNjzq4u8bfKHly iRmcEnf/Fe2ndCTlLZWDm6D9lcYbvXuN9cTOrKTFT6+y9sQtJW6gT9dQ5EaOmFPwveYIE+dYthJ +Tuoscymnckg== X-Received: by 2002:a05:6808:f8c:b0:47c:3f6f:db97 with SMTP id 5614622812f47-482e564d750mr10848042b6e.21.1779139693777; Mon, 18 May 2026 14:28:13 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:40 -0600 Subject: [PATCH v2 22/37] bsd-user: Add os-time.c and time-related type definitions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-22-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , =?utf-8?q?Mika=C3=ABl_Urankar?= , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=13090; i=imp@bsdimp.com; h=from:subject:message-id; bh=L7v65mJI2fLjLDk/Nuzxs+s7fXNRPx2eJpEFl8Z7fLc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RIXpw4x/bgodWYrWK9P/y3l9lx2wVC9TRda IaI/+yn+peJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AHO8D/sEzqfn1ZPArz7CmShI5W/3nhlCuEK90U7dc77+Q3fPZ+chWbDQLncKbxE0lski19Hn8ZA GoScK1UdiVKpAlqUWY3OaE3sn1pQ/VSk40b4R+CPvQmyYdaBPqX1nXwIX5IxdwbjXrMi6gvs1CQ VrdJS8gVqNx0lWdNPVJZJ8cc2Pixf+pgz+j0ugExvDTZi6J/wZddSIbjOq3BJpYAwnrpe9t2Xui n44eWIOrVbP0Do+SmqFUC/HmsCIrPIKPpQCkZR2fTbNTpT0pUm6I6fXgL/C3AgzvlPTYSqs3znl RFRQKavrtxlhvB+9fdYbl74b+Y0l/oIVpwxDx/uZJ6JXlBiMi3x8Xp2bZ3KJdYuHnu65hYPEpV7 UafpMR8tH3A4J0e4D1iLpMjftzUxnRy8IYB9F9T46grHCkqvdUUEYSBS6Zu2OC5qLmjlDFdvDcZ iDCqhp+zJiYvvaG9F0/6PslIa6EVbBqqLy4ti5KovdRo8NLJOPVCZ1jcZXKP/zOYBwCnZ3HVNWj 8+R6H8SD/exqYwnWc38p/6r9+HZzUNgdcU/uOWwDZLvit8zzxf3/+zBBD2VlqpY99L/W45qU7SR bBPXEd7fFK8vl510KmIMR5yLssI75k4vwTdY9WAfumFNbhKO9+7vJCOKpNGqoKIZsDqQb56NfAO wn+o9nSgxPF/CrQ== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::230; envelope-from=imp@bsdimp.com; helo=mail-oi1-x230.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139887239154100 Add os-time.c with time conversion helpers (t2h/h2t functions for timespec, timeval, timex, ntptimeval, itimerspec) and POSIX timer helper functions. Also add target_freebsd_timex, target_freebsd_ntptimeval, target_freebsd_itimerspec, kevent structures, and timer definitions to syscall_defs.h. Signed-off-by: Stacey Son Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-syscall.c | 2 + bsd-user/freebsd/os-time.c | 346 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-time.h | 3 + 3 files changed, 351 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 6fbd2da261..020d16fda3 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -98,6 +98,8 @@ safe_syscall6(int, kevent, int, kq, const struct kevent *= , changelist, int, nchanges, struct kevent *, eventlist, int, nevents, const struct timespec *, timeout); =20 +int g_posix_timers[32] =3D { 0, } ; + /* used in os-proc */ safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options, struct rusage *, rusage); diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c new file mode 100644 index 0000000000..f1c1cc2c1a --- /dev/null +++ b/bsd-user/freebsd/os-time.c @@ -0,0 +1,346 @@ +/* + * FreeBSD time related system call helpers + * + * Copyright (c) 2013-2015 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" + +#include +#include +#include +#include +#include +#include + +#include "qemu.h" +#include "qemu-os.h" + +/* + * FreeBSD time conversion functions + */ +abi_long t2h_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr) +{ + struct target_freebsd_timeval *target_tv; + + if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(tv->tv_sec, &target_tv->tv_sec); + __get_user(tv->tv_usec, &target_tv->tv_usec); + unlock_user_struct(target_tv, target_tv_addr, 0); + + return 0; +} + +abi_long h2t_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr) +{ + struct target_freebsd_timeval *target_tv; + + if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(tv->tv_sec, &target_tv->tv_sec); + __put_user(tv->tv_usec, &target_tv->tv_usec); + unlock_user_struct(target_tv, target_tv_addr, 1); + + return 0; +} + +abi_long t2h_freebsd_timespec(struct timespec *ts, abi_ulong target_ts_add= r) +{ + struct target_freebsd_timespec *target_ts; + + if (!lock_user_struct(VERIFY_READ, target_ts, target_ts_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(ts->tv_sec, &target_ts->tv_sec); + __get_user(ts->tv_nsec, &target_ts->tv_nsec); + unlock_user_struct(target_ts, target_ts_addr, 0); + + return 0; +} + +abi_long h2t_freebsd_timespec(abi_ulong target_ts_addr, struct timespec *t= s) +{ + struct target_freebsd_timespec *target_ts; + + if (!lock_user_struct(VERIFY_WRITE, target_ts, target_ts_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(ts->tv_sec, &target_ts->tv_sec); + __put_user(ts->tv_nsec, &target_ts->tv_nsec); + unlock_user_struct(target_ts, target_ts_addr, 1); + + return 0; +} + +abi_long t2h_freebsd_umtx_time(abi_ulong target_ut_addr, + abi_ulong target_ut_size, void *host_t, size_t *host_tsz) +{ + abi_long ret; + + if (target_ut_size <=3D sizeof(struct target_freebsd_timespec)) { + ret =3D t2h_freebsd_timespec((struct timespec *)host_t, target_ut_= addr); + if (ret =3D=3D 0) { + *host_tsz =3D sizeof(struct timespec); + } + return ret; + } else { + struct target_freebsd__umtx_time *target_ut; + struct _umtx_time *ut =3D (struct _umtx_time *)host_t; + + if (!lock_user_struct(VERIFY_READ, target_ut, target_ut_addr, 1)) { + return -TARGET_EFAULT; + } + if (t2h_freebsd_timespec(&ut->_timeout, h2g(&target_ut->_timeout))= ) { + return -TARGET_EFAULT; + } + __get_user(ut->_flags, &target_ut->_flags); + __get_user(ut->_clockid, &target_ut->_clockid); + unlock_user_struct(target_ut, target_ut_addr, 0); + + if (target_ut_size > sizeof(struct target_freebsd__umtx_time)) { + *host_tsz =3D sizeof(struct _umtx_time) + sizeof(struct timesp= ec); + } else { + *host_tsz =3D sizeof(struct _umtx_time); + } + + return 0; + } +} + +abi_long t2h_freebsd_timex(struct timex *host_tx, abi_ulong target_tx_addr) +{ + struct target_freebsd_timex *target_tx; + + if (!lock_user_struct(VERIFY_READ, target_tx, target_tx_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_tx->modes, &target_tx->modes); + __get_user(host_tx->offset, &target_tx->offset); + __get_user(host_tx->freq, &target_tx->freq); + __get_user(host_tx->maxerror, &target_tx->maxerror); + __get_user(host_tx->esterror, &target_tx->esterror); + __get_user(host_tx->status, &target_tx->status); + __get_user(host_tx->constant, &target_tx->constant); + __get_user(host_tx->precision, &target_tx->precision); + __get_user(host_tx->tolerance, &target_tx->tolerance); + __get_user(host_tx->ppsfreq, &target_tx->ppsfreq); + __get_user(host_tx->jitter, &target_tx->jitter); + __get_user(host_tx->shift, &target_tx->shift); + __get_user(host_tx->stabil, &target_tx->stabil); + __get_user(host_tx->jitcnt, &target_tx->jitcnt); + __get_user(host_tx->calcnt, &target_tx->calcnt); + __get_user(host_tx->errcnt, &target_tx->errcnt); + __get_user(host_tx->stbcnt, &target_tx->stbcnt); + unlock_user_struct(target_tx, target_tx_addr, 0); + + return 0; +} + +abi_long h2t_freebsd_timex(abi_ulong target_tx_addr, struct timex *host_tx) +{ + struct target_freebsd_timex *target_tx; + + if (!lock_user_struct(VERIFY_WRITE, target_tx, target_tx_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_tx->modes, &target_tx->modes); + __put_user(host_tx->offset, &target_tx->offset); + __put_user(host_tx->freq, &target_tx->freq); + __put_user(host_tx->maxerror, &target_tx->maxerror); + __put_user(host_tx->esterror, &target_tx->esterror); + __put_user(host_tx->status, &target_tx->status); + __put_user(host_tx->constant, &target_tx->constant); + __put_user(host_tx->precision, &target_tx->precision); + __put_user(host_tx->tolerance, &target_tx->tolerance); + __put_user(host_tx->ppsfreq, &target_tx->ppsfreq); + __put_user(host_tx->jitter, &target_tx->jitter); + __put_user(host_tx->shift, &target_tx->shift); + __put_user(host_tx->stabil, &target_tx->stabil); + __put_user(host_tx->jitcnt, &target_tx->jitcnt); + __put_user(host_tx->calcnt, &target_tx->calcnt); + __put_user(host_tx->errcnt, &target_tx->errcnt); + __put_user(host_tx->stbcnt, &target_tx->stbcnt); + unlock_user_struct(target_tx, target_tx_addr, 1); + + return 0; +} + +abi_long h2t_freebsd_ntptimeval(abi_ulong target_ntv_addr, + struct ntptimeval *ntv) +{ + struct target_freebsd_ntptimeval *target_ntv; + + if (!lock_user_struct(VERIFY_WRITE, target_ntv, target_ntv_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(ntv->time.tv_sec, &target_ntv->time.tv_sec); + __put_user(ntv->time.tv_nsec, &target_ntv->time.tv_nsec); + __put_user(ntv->maxerror, &target_ntv->maxerror); + __put_user(ntv->esterror, &target_ntv->esterror); + __put_user(ntv->tai, &target_ntv->tai); + __put_user(ntv->time_state, &target_ntv->time_state); + unlock_user_struct(target_ntv, target_ntv_addr, 1); + + return 0; +} + +/* + * select(2) fdset copy functions + */ +abi_ulong copy_from_user_fdset(fd_set *fds, abi_ulong target_fds_addr, int= n) +{ + int i, nw, j, k; + abi_ulong b, *target_fds; + + nw =3D (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; + target_fds =3D lock_user(VERIFY_READ, target_fds_addr, + sizeof(abi_ulong) * nw, 1); + if (target_fds =3D=3D NULL) { + return -TARGET_EFAULT; + } + FD_ZERO(fds); + k =3D 0; + for (i =3D 0; i < nw; i++) { + /* grab the abi_ulong */ + __get_user(b, &target_fds[i]); + for (j =3D 0; j < TARGET_ABI_BITS; j++) { + /* check the bit inside the abi_ulong */ + if ((b >> j) & 1) { + FD_SET(k, fds); + } + k++; + } + } + unlock_user(target_fds, target_fds_addr, 0); + + return 0; +} + +abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr, + abi_ulong target_fds_addr, int n) +{ + + if (target_fds_addr) { + if (copy_from_user_fdset(fds, target_fds_addr, n)) { + return -TARGET_EFAULT; + } + *fds_ptr =3D fds; + } else { + *fds_ptr =3D NULL; + } + + return 0; +} + +abi_long copy_to_user_fdset(abi_ulong target_fds_addr, const fd_set *fds, = int n) +{ + int i, nw, j, k; + abi_long v; + abi_ulong *target_fds; + + nw =3D (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; + target_fds =3D lock_user(VERIFY_WRITE, target_fds_addr, + sizeof(abi_ulong) * nw, 0); + if (target_fds =3D=3D NULL) { + return -TARGET_EFAULT; + } + k =3D 0; + for (i =3D 0; i < nw; i++) { + v =3D 0; + for (j =3D 0; j < TARGET_ABI_BITS; j++) { + v |=3D ((FD_ISSET(k, fds) !=3D 0) << j); + k++; + } + __put_user(v, &target_fds[i]); + } + unlock_user(target_fds, target_fds_addr, sizeof(abi_ulong) * nw); + + return 0; +} + +abi_int next_free_host_timer(void) +{ + int k ; + /* FIXME: Does finding the next free slot require a lock? */ + for (k =3D 0; k < ARRAY_SIZE(g_posix_timers); k++) { + if (g_posix_timers[k] =3D=3D 0) { + g_posix_timers[k] =3D 1; + return k; + } + } + return -1; +} + +int host_to_target_timerid(int timerid) +{ + int k; + + for (k =3D 0; k < ARRAY_SIZE(g_posix_timers); k++) { + if (g_posix_timers[k] =3D=3D timerid) { + return TIMER_MAGIC | k; + } + } + + return -1; +} + +abi_long target_to_host_itimerspec(struct itimerspec *host_itspec, + abi_ulong target_addr) +{ + struct target_freebsd_itimerspec *target_itspec; + + if (!lock_user_struct(VERIFY_READ, target_itspec, target_addr, 1)) { + return -TARGET_EFAULT; + } + + host_itspec->it_interval.tv_sec =3D + tswapal(target_itspec->it_interval.tv_sec); + host_itspec->it_interval.tv_nsec =3D + tswapal(target_itspec->it_interval.tv_nsec); + host_itspec->it_value.tv_sec =3D tswapal(target_itspec->it_value.tv_se= c); + host_itspec->it_value.tv_nsec =3D tswapal(target_itspec->it_value.tv_n= sec); + + unlock_user_struct(target_itspec, target_addr, 0); + return 0; +} + +abi_long host_to_target_itimerspec(abi_ulong target_addr, + struct itimerspec *host_its) +{ + struct target_freebsd_itimerspec *target_itspec; + + if (!lock_user_struct(VERIFY_WRITE, target_itspec, target_addr, 0)) { + return -TARGET_EFAULT; + } + + target_itspec->it_interval.tv_sec =3D tswapal(host_its->it_interval.tv= _sec); + target_itspec->it_interval.tv_nsec =3D tswapal(host_its->it_interval.t= v_nsec); + + target_itspec->it_value.tv_sec =3D tswapal(host_its->it_value.tv_sec); + target_itspec->it_value.tv_nsec =3D tswapal(host_its->it_value.tv_nsec= ); + + unlock_user_struct(target_itspec, target_addr, 1); + return 0; +} + +/* Convert QEMU provided timer ID back to internal 16bit index format */ +int get_timer_id(abi_long arg) +{ + int timerid =3D arg; + + if ((timerid & TIMER_MAGIC_MASK) !=3D TIMER_MAGIC) { + return -TARGET_EINVAL; + } + + timerid &=3D 0xffff; + + if (timerid >=3D ARRAY_SIZE(g_posix_timers)) { + return -TARGET_EINVAL; + } + + return timerid; +} diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index f24b6f35db..e91a3f9bcf 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -198,6 +198,9 @@ static inline abi_long do_freebsd_ntp_adjtime(abi_ulong= target_tx_addr) if (ret =3D=3D 0) { ret =3D get_errno(ntp_adjtime(&host_tx)); } + if (!is_error(ret)) { + h2t_freebsd_timex(target_tx_addr, &host_tx); + } =20 return ret; } --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139795; cv=none; d=zohomail.com; s=zohoarc; b=YVWAztndNCrwz3F39mZK48vfQlHpRg3x46k+12unMioeHaVtbKyK2sjCMvMzKXwq6k0qIpNLEt1PAMyBT7SYZz40ETiXWa7S2rkHB6+jK20NsqQIY4RB+x0dFnjXxbso+oTOW4ZDeXca38sHFy7MsoJGJEZ5XsuotHu8Kmt752s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139795; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+8Ux4G6M9Fv0nwLtFscsvZGnjN/b2cZpTTDBQ0OTQp0=; b=LUwGtt5jR4VwOp5CSlu2rziqKmEMJY/nuHnxF5QE53zcvfI5X40Zh4N7UnE/ImrVRAkJ3/Cfj5z6BQJHvPRNHxi/BtdsTbbD3/ZDzQ4EmPi2C+VSr2Biee4AlnY9G3KrCUNXdSggniHPR1MV4ZqbNcVXN5STkfpUn1DPN1Ek/TE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139795468488.0526959389522; Mon, 18 May 2026 14:29:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vl-0000XO-6X; Mon, 18 May 2026 17:28:29 -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 1wP5Vc-0000Ur-Vx for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:21 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Va-0000Vq-2y for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:20 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7dcdd1b492eso2948061a34.1 for ; Mon, 18 May 2026 14:28:16 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139695; x=1779744495; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+8Ux4G6M9Fv0nwLtFscsvZGnjN/b2cZpTTDBQ0OTQp0=; b=LQPet8oXoEsO9mFPu2hq5G7wCqkZ/it+SyQVk2tBOubTQOb/Y85lgCPgY5AYLw32Y1 uZLYkDEJeLVpViwm+J3x65toqc4dbb7x0Oej8Ucp8dM5NPKRL/SeAflv1f6cItER0t2d NWwuZ+6j0pRkwx7KkdtQsWbaOLd6LV6U7ZxOy+dwra6YiOdkr7TbOgab2Af6qjBE2VrB 1isnKo97+DZrjUkcZfPEgPtLg+xwjBcc2Kqkl/nEhc/Mmreirwb4DQUi+1suF9km8ABK wJrje4j4ro/Qfs55x1tdP5jMDR52EpOdHQesqjWbK7f7doYOq/We7EfMbpJpG4R8IVA6 HFfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139695; x=1779744495; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=+8Ux4G6M9Fv0nwLtFscsvZGnjN/b2cZpTTDBQ0OTQp0=; b=htdC0MY13PAqu5xgrAInctwB4cQyDBqp1uKy4cR+1XwtyeUGYNdcCy+C7KjJJGm031 zIt7pPxP1hrn1uR2RZDQcDdxfvgRwrpGZoMh1gIYW+FaswAH3N0nx+Fr1k/zZOvKp6EX JK5XJ1l+lCnptXMfVIssd1OnTWkCrzyFepPf1nm3z3wnEB5stkZllKbxBvbyQrKqLw0r xhT7XF5Pe8oW2hfjZlYKNTclCXjmS5vJu1kjQkvmVmsF7MXyLG6k9jAz9AW99yQ+jXtc wJgjRSOt3hqimsHEjwbEb356sAiUCtA+2pxoIG5+N3kBBHU4WqcWtShQl5vftWCIEsdR Z1zw== X-Gm-Message-State: AOJu0Yzn2EgCyzDhFCkGdmuPzSnwvUkGUyIyiZDrlhM5NFm5J8xvmkD/ ZLAPOcdUZePJphNtbhl9EfsU8w5hG9OHoG4VN9DTSKj69gpXCFyM6maiQn9pbK5rpSg= X-Gm-Gg: Acq92OEEfKBUsjGyGP9UGJBD/peC5evfaGAbhxQZrqG0HP70ERAB+QeIvrG3O1GAC3U oAKTcZIt7/fJUU83IzCVjCGCApbCvBznRufQMRA743lBZIobQX0ji3aofrhhsQZv2EV/VgM11q/ doiE/NEkPLe+5bXCOOlVtIeg2xeFWckUQzvYolW6ON3lzXRvd0s/J2yiqzcLzGqqAgvacXQbP9k FD1IlmX3KF142xAXFP0vbdD8c1U4daAGcexvWrw3MhouCy266XdBzpg71kj7Qw3LcTchqEITWs9 jJHKE4qr6Fb+Q4PN2sJPtezGiaaPCJh4o2GKYOOtYtEy8r9Sg1cgRv04Rq/fnKT58PeOQxK/VbL uU+Vf+bQfgyxCiBr+M3QrbbOZfIafseCz09lvDk0/0Pmd8JYl2zqeFeZ2lAERJfrxLpz6+sK8Q6 p4QTgzfXIkdA== X-Received: by 2002:a05:6830:90b:b0:7dc:1bcd:43be with SMTP id 46e09a7af769-7e49a9379f2mr10129938a34.5.1779139695293; Mon, 18 May 2026 14:28:15 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:41 -0600 Subject: [PATCH v2 23/37] bsd-user: Add time system call dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-23-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5661; i=imp@bsdimp.com; h=from:subject:message-id; bh=y/M4lfN1u9uogW+bC03bPRccqF4MOtoBLBj5D18mpLY=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RIFYh+m+c6vLv4b8kqiNi45fNu9405XPeVT lruuhra0L2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AB2aD/4poG/I3X1440nqhNS1my7JsoSHgRqW4BRX6m7imf8iiSLeRujmPOe/fe/Rq8VCn1TXHuc TSOIc43cN+ayvHgK9l0Gel6jR/PWu3FtUFKzuyn87LMSF5XXC9Xv4F43kDO/s1UvMMyejPzhsYW WZTUrOwi+crgfNHEU7u+e2rdRVBVhVi4dBM+oTUVAaaYSx4Tf99teRrAxW/eGaadvsaOh7ke3Tg tpYNThb7IA42QZvzh3cvCGdtLFxInBIlUq0LK4/MZq0hd0ZRf+SrMSpNTEyDPYLdgxNYEXLGV3A mqJcLRNzKoRDa5jkA3B9uPEMtEGfzeIAARS8w3L/V0H+J0yviges2N42sNwrQTeKlIn7T89dWiH f+DF9aUvdAQJPt+dBUjQe04DnLUgqovaxM5Jk3Z21h9AJvFJjjkX0jUO4gqyodoJ+1lee69Gmc8 FjfWRvXza7ypbZSQdBV/XoGQC74VS7CLs9rRi5oFWcyWes0eEG74jYbEl/TWA4ougCLFc6uQiud Ig/u1PwS4qcOUy91hLLrwZ+gMYzED91eenXuxe9G4g//EwFSTaPwXausN3baHsAl8Tm3a1I9BNQ Lwa8APyM6yVdyzfsXqX4gpc0pY5QPyXzk8ri7SnYKKVhvDUZt4amAiAVSHTeTjLF5cuiOqgyXEL HGm21ybRSBS7rvQ== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::333; envelope-from=imp@bsdimp.com; helo=mail-ot1-x333.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139797213154100 Wire up time-related system calls in the FreeBSD syscall dispatcher: nanosleep, clock_nanosleep, clock_gettime, clock_settime, clock_getres, gettimeofday, settimeofday, adjtime, ntp_adjtime, ntp_gettime, clock_getcpuclockid2, utimes, lutimes, futimes, futimesat, ktimer_create, ktimer_delete, ktimer_settime, ktimer_gettime, select, pselect, ppoll, kqueue, freebsd11_kevent, kevent, setitimer, getitimer, futimens, utimensat, and sigtimedwait. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/os-syscall.c | 124 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 124 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 020d16fda3..cc66be3b7c 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -48,6 +48,7 @@ #include "os-signal.h" #include "os-file.h" #include "os-socket.h" +#include "os-time.h" #include "os-misc.h" =20 /* I/O */ @@ -1037,9 +1038,132 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, ret =3D do_bsd_getdtablesize(); break; =20 + /* + * time related system calls. + */ + case TARGET_FREEBSD_NR_nanosleep: /* nanosleep(2) */ + ret =3D do_freebsd_nanosleep(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_clock_nanosleep: /* clock_nanosleep(2) */ + ret =3D do_freebsd_clock_nanosleep(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_clock_gettime: /* clock_gettime(2) */ + ret =3D do_freebsd_clock_gettime(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_clock_settime: /* clock_settime(2) */ + ret =3D do_freebsd_clock_settime(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_clock_getres: /* clock_getres(2) */ + ret =3D do_freebsd_clock_getres(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_gettimeofday: /* gettimeofday(2) */ + ret =3D do_freebsd_gettimeofday(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_settimeofday: /* settimeofday(2) */ + ret =3D do_freebsd_settimeofday(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_adjtime: /* adjtime(2) */ + ret =3D do_freebsd_adjtime(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_ntp_adjtime: /* ntp_adjtime(2) */ + ret =3D do_freebsd_ntp_adjtime(arg1); + break; + + case TARGET_FREEBSD_NR_clock_getcpuclockid2: /* Not documented. */ + ret =3D do_freebsd_clock_getcpuclockid2(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_ntp_gettime: /* ntp_gettime(2) */ + ret =3D do_freebsd_ntp_gettime(arg1); + break; + + case TARGET_FREEBSD_NR_utimes: /* utimes(2) */ + ret =3D do_freebsd_utimes(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_lutimes: /* lutimes(2) */ + ret =3D do_freebsd_lutimes(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_futimes: /* futimes(2) */ + ret =3D do_freebsd_futimes(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_futimesat: /* futimesat(2) */ + ret =3D do_freebsd_futimesat(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_ktimer_create: /* timer_create(2) */ + ret =3D do_freebsd_ktimer_create(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_ktimer_delete: /* timer_delete(2) */ + ret =3D do_freebsd_ktimer_delete(arg1); + break; + + case TARGET_FREEBSD_NR_ktimer_settime: /* timer_settime(2) */ + ret =3D do_freebsd_ktimer_settime(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_ktimer_gettime: /* timer_gettime(2) */ + ret =3D do_freebsd_ktimer_gettime(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_select: /* select(2) */ + ret =3D do_freebsd_select(env, arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_pselect: /* pselect(2) */ + ret =3D do_freebsd_pselect(env, arg1, arg2, arg3, arg4, arg5, arg6= ); + break; + + case TARGET_FREEBSD_NR_ppoll: /* ppoll(2) */ + ret =3D do_freebsd_ppoll(env, arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_kqueue: /* kqueue(2) */ + ret =3D do_freebsd_kqueue(); + break; + + case TARGET_FREEBSD_NR_freebsd11_kevent: /* kevent(2) */ + ret =3D do_freebsd_freebsd11_kevent(arg1, arg2, arg3, arg4, arg5, = arg6); + break; + + case TARGET_FREEBSD_NR_kevent: /* kevent(2) */ + ret =3D do_freebsd_kevent(arg1, arg2, arg3, arg4, arg5, arg6); + break; + + case TARGET_FREEBSD_NR_setitimer: /* setitimer(2) */ + ret =3D do_freebsd_setitimer(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getitimer: /* getitimer(2) */ + ret =3D do_freebsd_getitimer(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_futimens: /* futimens(2) */ + ret =3D do_freebsd_futimens(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_utimensat: /* utimensat(2) */ + ret =3D do_freebsd_utimensat(arg1, arg2, arg3, arg4); + break; + /* * signal system calls */ + case TARGET_FREEBSD_NR_sigtimedwait: /* sigtimedwait(2) */ + ret =3D do_freebsd_sigtimedwait(arg1, arg2, arg3); + break; + case TARGET_FREEBSD_NR_sigaction: /* sigaction(2) */ ret =3D do_bsd_sigaction(arg1, arg2, arg3); break; --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139779; cv=none; d=zohomail.com; s=zohoarc; b=Y1b8RrDJqSdH2vA3aXNu5C1Q/kgm50HXKymVljEQzdHyhlTCbOfy9Bv1EZH+9YO6QViZwyn32kZZvHpvtYljX6s9xTuWHa9Bjf1zjCXHnnXzr2kZCScvTEavg4bIOaPKXppVmLS8124nT8G/foIjvVgs9Q/cN/HCC23cFzTkr/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139779; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=e1KKh3NJyoAfAywDQWcClG1KUzUlSs1U1KJ4/IY95AA=; b=GFuICUXhk+rjNGHu8M0BbJOconLIEuuzrztDzeJSDETJbmvNIahsu+3uMXsGfXOJZt0SArFT0pt6MlYtSNRRCZZGqYHrlKnsjHTrekx1Wl5udQHMkSvWpPZZugSQGwXXP1EI9Vrl7+iAGiGbB6w9yzgSeyo9tM2cHsW2wgxJh30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139779992364.56610310362043; Mon, 18 May 2026 14:29:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vo-0000YN-Ga; Mon, 18 May 2026 17:28:32 -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 1wP5Ve-0000VB-Sp for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:22 -0400 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Va-0000W5-Q6 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:21 -0400 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-479dd56d016so2331437b6e.3 for ; Mon, 18 May 2026 14:28:17 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139696; x=1779744496; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=e1KKh3NJyoAfAywDQWcClG1KUzUlSs1U1KJ4/IY95AA=; b=gxaxx4YKZyeDr2ivO/a5vdRh1R9sDD7g+F18CvSz778KV+4LsRRn/5ud+Cu41hE4Ef 6KHigl5ZUZG2dR3ZNEUN/Fgv9t9NXWomojeD1BXZOE0MhVJpZpF+nY8iNoZQ9fgBovtx bsh5X5HSY8clD2g3Q2EK3Vzg3GX38RtjsWNMCrV3rbu39Vv3CJPWCGxBjY3WFYkqcd2e Q/Zrtkf0Wm1+5nYIXnx5wLgPLkdgkDEBdtyYAQpdmEZu/+DWDUqXReFjimFgFVBS3uSs p1doxi61zpPFKMKfxMD/K6LFohd/TF9/EoGc3cLCB1Vc2ZoyjT9wRhtYMz9JfgFBkurB 5o0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139696; x=1779744496; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=e1KKh3NJyoAfAywDQWcClG1KUzUlSs1U1KJ4/IY95AA=; b=Dth45ZhOoiiT7ruJgdqNz4yCoiI15U3DAjZcvj6wmB2nfWMk1bS9ZYtLP8wjv+Htyh n/s4q/tdXesRRCOWYXH7N5V3Pm+26UB+IPuXGACs6+/DM0z1u4ZROsI3BfE+HdOX/ZDO wST7vExyzbnXdjdBUGJ7cREyqQKY9GKxQ/zVSqCiD0ns1as4nroGlXu/bMcYv+xzehWH dM1368SoW67XtCY9uhmfbHjtcZykBomB164CkIdjixM+gKDL6a+AEQ+AqVxSvGRUj/yc Jj9Pdy3zt9vbCtTZv0xlwuwmu9xH/tBLDyvHkW/g5HjrKgdWEwC0ZsqSl31fP4cd1Tvg jkGA== X-Gm-Message-State: AOJu0YyKy2tbjIuBBQ6VXbt3COgoUR7239dJhmFlasU+RIaPdKaJRTOF Bve7Ddtci1KArvceetBGLnb/SRrsLkyoFTR3lQFCpeg/RITg88P/ATR5jT435TeEeJ4= X-Gm-Gg: Acq92OGEwM+pXwJXipPYA0psbcC94nxiRQpAT+MRFI9KhUh/1ZdoIjkW+LYGFvRbht8 xkYkp3O8E2reYWohJQPgAw6juJV7A9a8jwP/aKjZFalGljhBRuJ6Ldic2JE0a5EVmi5udigGP9b 8PCAfzwW+fEeCkmWi/wT7ZOaZQCxKwg6jJFIwlO7d2IXfVZOOmZj6UGZWvpLsJNx3GxxkeLAqtU UfErXBHSls9I/4X4gAevwQK+LIq3ZqNA/gU3RZvrmkyEH8G2AmaR4PXj9WIysmgeNPBumZozjfD A3iQD9jZfkM4fQ55jcsMHmaR1w99Kc08Md4pFs8/ECbFY8C6J2WqLmedgdU/m6D5PYvxk5OY/rL p8wpTbXOfu5WHn/Qx0SihTnNMIW7cQLK0itXAkiF44RG/4gYJpwle2u10fSN8C0eXn01vz2S80k Y6wxN3T42ZqQ== X-Received: by 2002:a05:6808:16a1:b0:479:72dc:bb6 with SMTP id 5614622812f47-482e57c23c5mr10572771b6e.44.1779139696457; Mon, 18 May 2026 14:28:16 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:42 -0600 Subject: [PATCH v2 24/37] bsd-user: Add thread, umtx, and ACL type definitions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-24-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5874; i=imp@bsdimp.com; h=from:subject:message-id; bh=YQd/Oq+9S9585bZGziOcoxm1El/aE/JxQDVF39O014k=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RITGGaJkah3dvJtMcxJq3+mgSWuAiuz0LSw mkry1gFGbSJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AG66D/9QJz3ULM333QTuFw2kCRsh4nMndzEaYzLEqNrSisXnD1YkF8tLLHhLX70pjIaasS2xHnu Ljur9L/0G+BjFtG8UfWsuL/vnZF8uwZUONWk97ogXzvMw+JmYrUnfbE8XQzau0/JI46tk5m2JAk asqdX75qsXb5E9EdMD9HR9kPawo6qlZ7OPzk8Gd/k/C3GB7UKNPX1zHiuBCIQnsgDep6EO0dtOb PllTWyqbw3m6NJ1p3ihHsVQXVT+sqFO3H5GXSgEBWSmsxS1qZsy6hgSIYDNvZao1J7hup1IuQQj VsHN5GCvbh8EEaCdF6d/r//hUlN9rxM00d5NjnEeFJ67Eb0JbUXoSmL6Oaf6aVspvniaa1rOgVC rTtcvx8N3ansjyv31HPpkMVHvetrWmIOO3QoegrEwqDslXHSQvJR9Hv4r+sX7PCSVuBx8+Q/+Rh WQ37UNQIujIfCUT2xwxGNwg+1ProzlKt4js18ycM27UeM8iElUO2BMtNVOxjKc3xciFA29x1zKg SFCMNI/rtA05Wnm/VH1gxh3Yu5dwJYpyjFeHgyLMoPDQryqPsu9wesYQpeAYs/uc0Yrs6yofVGA gs26Gy2w+nWYSaMTqkhC1uMxcL0X+hD97k3AbJ4z/WdMKTYpAOxKa62L17dG18Ap0QXHm2ahPG5 ttKBb0mKK1LDiFw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::229; envelope-from=imp@bsdimp.com; helo=mail-oi1-x229.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139783128154100 Add target_freebsd_thr_param, target_freebsd_rtprio, new_freebsd_thread_info_t, TARGET_UMTX_OP_* opcodes, umutex/urwlock flags, and target_freebsd_acl structures to syscall_defs.h. Add forward declarations for os-time.c, os-socket.c, os-thread.c, and os-extattr.c functions to qemu-os.h. Add thread and umtx function declarations to qemu.h. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/freebsd/qemu-os.h | 48 ++++++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/qemu.h | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/bsd-user/freebsd/qemu-os.h b/bsd-user/freebsd/qemu-os.h index 12adc50928..b1ff5c0cd5 100644 --- a/bsd-user/freebsd/qemu-os.h +++ b/bsd-user/freebsd/qemu-os.h @@ -32,6 +32,54 @@ =20 struct freebsd11_stat; =20 +/* os-time.c */ +abi_long t2h_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr); +abi_long h2t_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr); + +abi_long t2h_freebsd_timespec(struct timespec *ts, abi_ulong target_ts_add= r); +abi_long h2t_freebsd_timespec(abi_ulong target_ts_addr, struct timespec *t= s); + +abi_long t2h_freebsd_umtx_time(abi_ulong target_ut_addr, + abi_ulong target_ut_size, void *host_t, size_t *host_tsz); + +abi_long t2h_freebsd_timex(struct timex *host_tx, abi_ulong target_tx_addr= ); +abi_long h2t_freebsd_timex(abi_ulong target_tx_addr, struct timex *host_tx= ); + +abi_long h2t_freebsd_ntptimeval(abi_ulong target_ntv_addr, + struct ntptimeval *ntv); + +abi_ulong copy_from_user_fdset(fd_set *fds, abi_ulong target_fds_addr, int= n); +abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr, + abi_ulong target_fds_addr, int n); +abi_long copy_to_user_fdset(abi_ulong target_fds_addr, const fd_set *fds, + int n); + +abi_int next_free_host_timer(void); +int host_to_target_timerid(int timerid); +abi_long target_to_host_itimerspec(struct itimerspec *host_itspec, + abi_ulong target_addr); +abi_long host_to_target_itimerspec(abi_ulong target_addr, + struct itimerspec *host_its); +int get_timer_id(abi_long arg); + +/* os-socket.c */ +abi_long t2h_freebsd_cmsg(struct msghdr *msgh, + struct target_msghdr *target_msgh); +abi_long h2t_freebsd_cmsg(struct target_msghdr *target_msgh, + struct msghdr *msgh); + +/* os-thread.c */ +abi_long t2h_freebsd_rtprio(struct rtprio *host_rtp, abi_ulong target_addr= ); +abi_long h2t_freebsd_rtprio(abi_ulong target_addr, struct rtprio *host_rtp= ); +abi_long do_freebsd_thr_new(CPUArchState *env, abi_ulong target_param_addr, + int32_t param_size); + +/* os-extattr.c */ +struct acl; +abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr); +abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl); +abi_long t2h_freebsd_acl_type(acl_type_t *host_type, abi_long target_type); + /* os-stat.c */ abi_long h2t_freebsd11_stat(abi_ulong target_addr, struct freebsd11_stat *host_st); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 60d1adf560..069baa7011 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -249,6 +249,47 @@ abi_long do_freebsd_sysctlbyname(CPUArchState *env, ab= i_ulong namep, abi_ulong newlen); abi_long do_freebsd_sysarch(CPUArchState *env, abi_long arg1, abi_long arg= 2); =20 +/* os-thread.c */ +extern pthread_mutex_t *new_freebsd_thread_lock_ptr; +extern pthread_mutex_t *freebsd_umtx_wait_lck_ptr; +void *new_freebsd_thread_start(void *arg); +abi_long freebsd_lock_umtx(abi_ulong target_addr, abi_long tid, + size_t tsz, void *t); +abi_long freebsd_unlock_umtx(abi_ulong target_addr, abi_long id); +abi_long freebsd_umtx_wait(abi_ulong targ_addr, abi_ulong id, + size_t tsz, void *t); +abi_long freebsd_umtx_wake(abi_ulong target_addr, uint32_t n_wake); +abi_long freebsd_umtx_wake_unsafe(abi_ulong target_addr, uint32_t n_wake); +abi_long freebsd_umtx_mutex_wake(abi_ulong target_addr, abi_long val); +abi_long freebsd_umtx_wait_uint(abi_ulong obj, uint32_t val, size_t tsz, + void *t); +abi_long freebsd_umtx_wait_uint_private(abi_ulong obj, uint32_t val, + size_t tsz, void *t); +abi_long freebsd_umtx_wake_private(abi_ulong obj, uint32_t val); +abi_long freebsd_umtx_nwake_private(abi_ulong obj, uint32_t val); +abi_long freebsd_umtx_mutex_wake2(abi_ulong obj, uint32_t val); +abi_long freebsd_umtx_sem2_wait(abi_ulong obj, size_t tsz, void *t); +abi_long freebsd_umtx_sem2_wake(abi_ulong obj); +abi_long freebsd_umtx_sem_wait(abi_ulong obj, size_t tsz, void *t); +abi_long freebsd_umtx_sem_wake(abi_ulong obj); +abi_long freebsd_lock_umutex(abi_ulong target_addr, uint32_t id, + void *ts, size_t tsz, int mode, abi_ulong val); +abi_long freebsd_unlock_umutex(abi_ulong target_addr, uint32_t id); +abi_long freebsd_cv_wait(abi_ulong target_ucond_addr, + abi_ulong target_umtx_addr, struct timespec *ts, int wflags); +abi_long freebsd_cv_signal(abi_ulong target_ucond_addr); +abi_long freebsd_cv_broadcast(abi_ulong target_ucond_addr); +abi_long freebsd_rw_rdlock(abi_ulong target_addr, long fflag, + size_t tsz, void *t); +abi_long freebsd_rw_wrlock(abi_ulong target_addr, long fflag, + size_t tsz, void *t); +abi_long freebsd_rw_unlock(abi_ulong target_addr); +abi_long freebsd_umtx_shm(abi_ulong target_addr, long fflag); +abi_long freebsd_umtx_robust_list(abi_ulong target_addr, size_t rbsize); +abi_long freebsd_set_ceiling(abi_ulong target_addr, uint32_t ceiling, + uint32_t *old_ceiling); +CPUArchState *cpu_copy(CPUArchState *env); + /* user access */ =20 #define VERIFY_READ PAGE_READ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139786; cv=none; d=zohomail.com; s=zohoarc; b=c0Lxa3q4casjPq3Sl2GEYl9ydOUF4PkVWfmr222Iw9keaNEH1w+mTqg8tU8V2bh0yxcbpQgodbAJmCxPVq5R3tpyFuU0XhkAcPKOkQTMWJ8PsICoCoOvX9q+wLSnlQZVZ4uSPGdlSzndZLF5aq3KZRAQrPXKuK8PVdi3z6pcyfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139786; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NLw1jYsA1FC75BIK+XU/FjvD1FNM1m0O7ZBaQMzntbs=; b=Fj6mDtQXz23tvV1mhVzBV83AXXTfM6BitYldbOy9u9iDT7nxN3JpVkzIS+7+F3Bn7qSvRpPbbhckZXokKEHwAyftr6AMl+9p2KWimiBpSmL8st2THevnIYayrFzwr+MOVSb3sF4qnTiP5eYPEcRDZZyZxeqwIWETO3J2iidFIl8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139786321602.2114584583297; Mon, 18 May 2026 14:29:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vk-0000XM-Jv; Mon, 18 May 2026 17:28:28 -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 1wP5Ve-0000VC-Sp for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:22 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Va-0000WG-Tg for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:22 -0400 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-479e6bc357eso1005483b6e.2 for ; Mon, 18 May 2026 14:28:18 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139697; x=1779744497; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NLw1jYsA1FC75BIK+XU/FjvD1FNM1m0O7ZBaQMzntbs=; b=n0QsfdPD+xaUHlC0/Vr2cbPPa5IX53slBMnYEsop+d4Fxk1odsmTPNm4jPjxPXSj46 P7aSsOtmYxnHbxvmSAtAITU46liwpo2Wjx4vfr6OVafsug1kKL4aBASwSVIjn+b20zcm silbZ+q6TltEI4S/czxPHEz3aOR3/phaXr6sWePN0Gpw1Dn2ad+d7YSpGFs79j2mm16E GgqF6x/mO+W9pfrUI/9q77yt5sLDdBQN0/C33LdqofiEcrpoVP5PeoqFbZgXQeGT7538 0sWjUtXyIXuKRudnTvBbNQtwTXmxHq24vjihVUSwDGkuQmQvJ5/8eAQoScyDXrGtnO8k ACNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139697; x=1779744497; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NLw1jYsA1FC75BIK+XU/FjvD1FNM1m0O7ZBaQMzntbs=; b=KCbkTQohWk350+FwTg11Iwgv6u2Ipifa48xE2D2gyiLm9mf+D6G3YrQ35zfCqm6hal 5RGIjKRWRkL7e7rjI4rbEt7l6HTS0EjHtECnv8mM/iwgf2a/Eq048xiX7w320Ape+Ejn 5WHYycCCNb21gUFtQy0gghnF0HN/80HOFcKcUwtMFxN6QTtyqOr0jEP1PNVaYMfc3rrz q8n0yvDLGVd7oZBzBLxPG1Y2nCXZde/54pydMTedoC01VIcCQ5xAGwJd1Sc1Udrc/6nT t7QRkF2PE99fqDnbrpw0OS/VGQPiPuJounopILbO+O1xtCFU5TpKAmyBuxnvpcG4Jkzs vMLA== X-Gm-Message-State: AOJu0YyiWoUhKUS9MkHNQcAZ4De3m3XNOb2n0ToY6C4o4dOEHGsEtkRI L0F22IXSINPZ1V1tI1tWcUA+lvK3vb+skzRLr8kFoVtORsccMaA9MhXwjuqrebXYjKg= X-Gm-Gg: Acq92OHrQI3Dau53p2/OEtybVeTUIcC0Olt/JyXBOsekh04AYr0GqtslZkcbRvGzU/p 2UeHj03/UkGMpwMe6MhtzxHp/oWnb72k0jwrG9RT7Z1ZaHUegEzCn3Qqpv62FNgoaBOFttorWld ZDpbkxhi2wuV0Do0SfTiWUEmR/yt9l9ea9D6qQXfZmNRUQnnqm/r/3MZPhIwBq7kFn0jQQ04LuL z3zIU27ZNy7a4Tcp+V+d1wQkjLf4GUgfdxK8OwVl6cWoqpdeldKYy7d8ayg+MYSWn4slMtyhr8P d3wJbfVCGiGVLSihsoWfSYk++FxdckEoBHqYUbHyQLvYWPOik2Jc1KQt85GhHXhyKAhWSpFWa0Z H1DOSCEexk8d1SYjhSJcJZmGZmhC/OnnlCmj32/WsiR/thTbpEO8i/5hoiXsNyh+c7X8/P5vaxw sTu8i9lua2oA== X-Received: by 2002:a54:438e:0:b0:47b:c8d0:512e with SMTP id 5614622812f47-482e577b3dcmr7866339b6e.34.1779139697265; Mon, 18 May 2026 14:28:17 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:43 -0600 Subject: [PATCH v2 25/37] bsd-user: Add cpu_copy and make init_task_state non-static MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-25-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2745; i=imp@bsdimp.com; h=from:subject:message-id; bh=eDWZgAgv3qFfpEQZ8pRz9vg/5ayhGnyO/P476vk93so=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RIqVy/pi7k3DZyBX5FnQVZ+YbMtZe5rAQGT zhuy3eIy8GJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AGQxD/9941+EMW3JhBaevzrUxc0sh7h9E6+oxDxjXZsenqTIJpqhwFGmjLkVvCd2+RGVLZLBDx/ ZKgBhduY/yV8sJXKmUyZ+EcWJTejsQ3x80uJJwWkdv9R2daO8nE05BX6W6++9ltLrWQlVUFy65v Us4OdIaDLRaTWu7gKglOsxYa1bEVxp6gv01hdocMUvpZ7AUel0/1zkVy+zO6gHNXGwiK1g6/d2I lYa7dd4RqNSX+fkxYabLFYX545PKJZvyY3c/u9F6d7W43jgZoakN4rgPkHc/YDGK9FXgm+WdvNK 1hCJqnZw8Y8OvXOedKZh6A86PKvQXwqTSSFwhK35djYj0WocbGbypc5BK+n/C+Wo5bbi7HwYXYu UD1PcrTqnE9Lx8eG9ulIB/boKXNdywiIHQEIAma89my84dS2puiaBQmsYCqT1BaB1iEiaOB6vWe nDs9CuSdC4nnwLrfsAESV0uWpsh9lLc5mmhRdYc1yYa2gqNhFJm09cdfwnTAKUOlW3/ABmJRbWz ME5QFWWGgsJ6o3Q0ElJyDny8Y9ieU0vwC/ni+mfyHKQ8u7ePtv4eIzx6nqaGhurukqKXlzSgIMb 32Gg2mtRWXoyG0OwgscfF2UTnkk5Bm6zItkZlWAM5CZYzSczUc4X0bZhK5/47X3wdL6Wlpp6e44 dy5Dj2L0OQY/nhg== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::236; envelope-from=imp@bsdimp.com; helo=mail-oi1-x236.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139789183154100 Add cpu_copy() function for thread creation support and make init_task_state() non-static so it can be called from os-thread.c. Move cpu_type to file scope so cpu_copy() can access it. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) Reviewed-by: Pierrick Bouvier --- bsd-user/main.c | 32 ++++++++++++++++++++++++++++++-- bsd-user/qemu.h | 1 + 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 73aae8c327..3c150b54cd 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -49,6 +49,7 @@ #include "qemu/guest-random.h" #include "gdbstub/user.h" #include "exec/page-vary.h" +#include "exec/watchpoint.h" =20 #include "host-os.h" #include "target_arch_cpu.h" @@ -215,7 +216,7 @@ bool qemu_cpu_is_self(CPUState *cpu) } =20 /* Assumes contents are already zeroed. */ -static void init_task_state(TaskState *ts) +void init_task_state(TaskState *ts) { ts->sigaltstack_used =3D (struct target_sigaltstack) { .ss_sp =3D 0, @@ -224,6 +225,34 @@ static void init_task_state(TaskState *ts) }; } =20 +static const char *cpu_type; + +CPUArchState *cpu_copy(CPUArchState *env) +{ + CPUState *cpu =3D env_cpu(env); + CPUState *new_cpu =3D cpu_create(cpu_type); + CPUArchState *new_env =3D cpu_env(new_cpu); + CPUBreakpoint *bp; + + /* Reset non arch specific state */ + cpu_reset(new_cpu); + + new_cpu->tcg_cflags =3D cpu->tcg_cflags; + memcpy(new_env, env, sizeof(CPUArchState)); + + /* + * Clone all break/watchpoints. + * Note: Once we support ptrace with hw-debug register access, make su= re + * BP_CPU break/watchpoints are handled correctly on clone. + */ + QTAILQ_INIT(&new_cpu->breakpoints); + QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { + cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL); + } + + return new_env; +} + static QemuPluginList plugins =3D QTAILQ_HEAD_INITIALIZER(plugins); =20 void gemu_log(const char *fmt, ...) @@ -256,7 +285,6 @@ int main(int argc, char **argv) { const char *filename; const char *cpu_model; - const char *cpu_type; const char *log_file =3D NULL; const char *log_mask =3D NULL; const char *seed_optarg =3D NULL; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 069baa7011..d2dd8c2ee8 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -122,6 +122,7 @@ struct TaskState { struct target_sigaltstack sigaltstack_used; } __attribute__((aligned(16))); =20 +void init_task_state(TaskState *ts); void stop_all_tasks(void); extern const char *interp_prefix; extern const char *qemu_uname_release; --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139904; cv=none; d=zohomail.com; s=zohoarc; b=FeMJA+Zpzs9Dc1GfAebvSZJpFAEy946P6pyp9pIKnMOA+Aj8Dl+IvUJ/uR/S38XUkfdB6h8ZqM+bhfItV5/0qpu2cgpkGczRPyX1Si6USyJcJuCqxMLUtwRXYSJJue+mQ0rrYDagn7a5jcQspMwguRIgsS6p/2BZOJY3iAxMSTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139904; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ldcai+Sh0yZjHsZmgqYAlRKl+2d8wfQPogMXY1nKO5I=; b=PMCgzQOiZ3u3sgDcI50ZUXNtfCvoS4bLjx3JPv5ErnUraUNeYF2kCd999RLwK3i4In9noJRn/MDWuJ3XKQSZD7+ud/P3tsXVAZ0hxFh4iUOCSjHGBrRal5kZUmztM7HwSiScrBNSB1cQqdI5NeY+pSJafI3HC/lfQhx88/FRAr4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177913990477752.67390776907882; Mon, 18 May 2026 14:31:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vr-0000kv-LY; Mon, 18 May 2026 17:28:35 -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 1wP5Ve-0000VF-Tj for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:22 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vb-0000Xw-IG for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:22 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7e55b95ba13so1605361a34.3 for ; Mon, 18 May 2026 14:28:19 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139698; x=1779744498; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ldcai+Sh0yZjHsZmgqYAlRKl+2d8wfQPogMXY1nKO5I=; b=UVBQatX7214MorA0wIASWwRKNILVACAG/JK5tlNaMcGAWrOXuxLSzmTsKX2oLwxcUo dQ8Mx4OepTNq/y05ojpSpSd7D8hD9YKmDIGea6fMEtpFFtGEYTh46HwbxyL+33RdMZfN /xTOc1o+WwyxGHIIeci/Cn4OcaTeIfreMMQTEVqgf4ugfh3ytOqESCdaos4ES4DRJDwa sHul513X3gqFE/QN/UcCJJNWLUcB4SIK6H7tDSNPmFxXTPnFc0iSLAUYaMTGrM+lVWU4 FCEHJU9r1mFiQKY6lNF5jUirqLHhWUSpPo5wsU9cADL43+YCyxJY0eLJ85xnrG9N+7wP ZpNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139698; x=1779744498; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ldcai+Sh0yZjHsZmgqYAlRKl+2d8wfQPogMXY1nKO5I=; b=BzvdKKZQvxK3o3k4Mo8mow0t0UAMTmirCHhLSltd1M/tfN5FShsNY20C7636P8Pzhv BTqdWr+PCG81n9/hTfGuaAtbAl6oX7atmSoCe9ggM1KibqMTucHdeJ77ZtOnpI+H37OE rRRvSbweNPWRTggUcm0JiM/N8b82fqnHAVcJxXQRLxQ2C8z7Fagt/HMjK4rPd9loOf6k B6WtWDi66D1+Vyt9XAZPGAYAPuEbRQaWnihLv73ayalL0cnBGLfNo2Vs+mXf3wqetf9Z xMNllFw0A3VauJuIMXVtw3x6hrL2ij0kZD1NiIr4mOX9yKrzVB0NI85cqlEx9pXMTqKv QVew== X-Gm-Message-State: AOJu0YzxiAvwjT3AqUwDTgTzkQbAMTsDu+THDp6hR8Tu8RY0LSXegbE5 jnWTIkp+6hMgKUJvR0iARq/FrCLLFa2KabWz2RhbNyKsOkL4ywVbDMSbODiujbBjvuU= X-Gm-Gg: Acq92OEDEuVq7HM7Zwh26T6+FSb7b/7vBAmsUoRxn2XLuAoVQmZL6XpLRMrlZ6jmyYk 5WOJ0WaN2UfjopsL2dxs/8O/nMGdBMUJRdPadQiUmaBYySt4WA/t0zRHnt11CBUQM646oB6DwbV r0uwvQbpX/RNqH2AHwDMWkLRjeTXkH3xBy+7hHE3ZWdcw7OOSnrGW8zOqUfwrepyIxc6R9SEDtH CxskQn2B8tBqzFo5yLOrO0gLNMbuDYvwZw7sq+YMLj494jgyTxG24MzumtpRQ3lUIEVxacHuIcM lINmy9cAmfLOpI3xNKr2Ady6YVupgYC1v8vAvwDry/Gx0ddJdYObdK/yXDFU4jaPPfDxTbGWlyo kIrn+rNb+UkyWPDeG58qidBme+dh90tFzQoIHsND3NFCPa8dEHvqC8mPqD6U68qKjJpuDajua5Y 8oxnPKLUSOz9GSudRpHh52 X-Received: by 2002:a05:6830:6995:b0:7d7:419a:7ac8 with SMTP id 46e09a7af769-7e4f2b8bdd6mr11443163a34.15.1779139698499; Mon, 18 May 2026 14:28:18 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:44 -0600 Subject: [PATCH v2 26/37] bsd-user: Add os-thread.h with thr and context functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-26-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans , Jessica Clarke , Michal Meloun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8532; i=imp@bsdimp.com; h=from:subject:message-id; bh=sb0rse5R0BhLV4cqBE8oVJE9gMbfncsjbjf2mHN6Geo=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RIm/169DzExGNwn+xvGlhm3gfrCGDQ1v6Gl gQYEb8+gEaJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR APdAD/0ST1M/khobsfdlUI5fVdn1khAW67p62ZZsPVRceb0ikYZO0RBBjj0QP7WyPHjT3viIvt3 Dh8sjmRVnbmm+w1nhTKo0qUFAndHKuGRvy0tYU/QRcgy/MYG8Je2Mvhyskkxqk5dx32Gg/+gJyo xeYh4TCHpVBt2+5xbeeK9fUpymgOuJquJzWy396USPtBcq2LhQzj2+bgMujVnP1+S2J4V/osmaL 3xOZpWFdYiXacYYzfGT4rK9mQYnnyvSjHeezODJs46mmMvrtqkF9Z2+0YAEvhbTwnNVOdVJfQMv S3CC2Q31Ws/OEYNZz97LeoHp+FWWBoFC/pQuUxlxaIkgJpq0ohhyCODXIWmSXu8vRxQodahNpLd 06r8UZHKkdTiiNAiUCE7RR0Lmzha4gygeyaY1LEBlJohy2NkqIfqnw9XkhLiGdNBCXptlP0W3es l2otMKpCSROTW+7X+fRIA5rC+nyllaIYagq+f9rtTUWpOZ7tCoUxVzJ8Np5PkgeznHhHZzJi+Km mWjBhADV2L0J3sMPn9zH4yYBz/M2rH3oUVLbp/ysivZfz4NBPlWldI/h8emb/M4CmxbF3QDoMDB I9ShOxkNvZ/XJkV7nf1dM78uRdKulIfaoiw0r6c+gO1FkvOtf7ZKN2/ilhuClvYoxoYPpoRdqLz Jor+UZ9jDc1SrVw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::332; envelope-from=imp@bsdimp.com; helo=mail-ot1-x332.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139907013158500 Add thread management system call shims: thr_self, thr_exit, thr_kill, thr_kill2, thr_suspend, thr_wake, thr_set_name, rtprio_thread, getcontext, setcontext, and swapcontext. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Jessica Clarke Signed-off-by: Michal Meloun Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-syscall.c | 6 ++ bsd-user/freebsd/os-thread.h | 244 ++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 250 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index cc66be3b7c..f2c3ff25e8 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -49,6 +49,7 @@ #include "os-file.h" #include "os-socket.h" #include "os-time.h" +#include "os-thread.h" #include "os-misc.h" =20 /* I/O */ @@ -90,6 +91,11 @@ safe_syscall6(ssize_t, sendto, int, fd, const void *, bu= f, size_t, len, int, safe_syscall3(ssize_t, recvmsg, int, s, struct msghdr *, msg, int, flags); safe_syscall3(ssize_t, sendmsg, int, s, const struct msghdr *, msg, int, f= lags); =20 +/* used in os-thread */ +safe_syscall1(int, thr_suspend, struct timespec *, timeout); +safe_syscall5(int, _umtx_op, void *, obj, int, op, unsigned long, val, voi= d *, + uaddr, void *, uaddr2); + /* used in os-time */ safe_syscall2(int, nanosleep, const struct timespec *, rqtp, struct timesp= ec *, rmtp); diff --git a/bsd-user/freebsd/os-thread.h b/bsd-user/freebsd/os-thread.h new file mode 100644 index 0000000000..bb8f279060 --- /dev/null +++ b/bsd-user/freebsd/os-thread.h @@ -0,0 +1,244 @@ +/* + * FreeBSD thread and user mutex related system call shims + * + * Copyright (c) 2013-2015 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef FREEBSD_OS_THREAD_H +#define FREEBSD_OS_THREAD_H + +#include +#include +#include + +#include "qemu.h" +#include "qemu-os.h" + +int safe_thr_suspend(struct timespec *timeout); +int safe__umtx_op(void *, int, unsigned long, void *, void *); + +#if defined(HOST_BIG_ENDIAN) =3D=3D defined(TARGET_BIG_ENDIAN) && \ + (TARGET_ABI_BITS =3D=3D HOST_LONG_BITS || defined(UMTX_OP__32BIT)) +#define _UMTX_OPTIMIZED +#if defined(TARGET_ABI32) +#define QEMU_UMTX_OP(n) (UMTX_OP__32BIT | (n)) +#else +#define QEMU_UMTX_OP(n) (n) +#endif /* TARGET_ABI32 */ +#else +#define QEMU_UMTX_OP(n) (n) +#endif + +static inline abi_long do_freebsd_thr_self(abi_ulong target_id) +{ + abi_long ret; + long tid; + + ret =3D get_errno(thr_self(&tid)); + if (!is_error(ret)) { + if (put_user_sal(tid, target_id)) { + return -TARGET_EFAULT; + } + } + return ret; +} + +static inline abi_long do_freebsd_thr_exit(CPUArchState *env, + abi_ulong tid_addr) +{ + CPUState *cpu =3D env_cpu(env); + TaskState *ts; + + if (block_signals()) { + return -TARGET_ERESTART; + } + + pthread_mutex_lock(new_freebsd_thread_lock_ptr); + + ts =3D cpu->opaque; + + if (tid_addr) { + /* Signal target userland that it can free the stack. */ + if (!put_user_sal(1, tid_addr)) { + freebsd_umtx_wake_unsafe(tid_addr, INT_MAX); + } + } + + object_unparent(OBJECT(env_cpu(env))); + object_unref(OBJECT(env_cpu(env))); + /* + * At this point the CPU should be unrealized and removed + * from cpu lists. We can clean-up the rest of the thread + * data without the lock held. + */ + + pthread_mutex_unlock(new_freebsd_thread_lock_ptr); + + thread_cpu =3D NULL; + g_free(ts); + rcu_unregister_thread(); + pthread_exit(NULL); + /* Doesn't return */ + return 0; +} + +static inline abi_long do_freebsd_thr_kill(long id, int sig) +{ + + return get_errno(thr_kill(id, target_to_host_signal(sig))); +} + +static inline abi_long do_freebsd_thr_kill2(pid_t pid, long id, int sig) +{ + + return get_errno(thr_kill2(pid, id, target_to_host_signal(sig))); +} + +static inline abi_long do_freebsd_thr_suspend(abi_ulong target_ts) +{ + abi_long ret; + struct timespec ts; + + if (target_ts !=3D 0) { + if (t2h_freebsd_timespec(&ts, target_ts)) { + return -TARGET_EFAULT; + } + ret =3D get_errno(safe_thr_suspend(&ts)); + } else { + ret =3D get_errno(safe_thr_suspend(NULL)); + } + return ret; +} + +static inline abi_long do_freebsd_thr_wake(long tid) +{ + + return get_errno(thr_wake(tid)); +} + +static inline abi_long do_freebsd_thr_set_name(long tid, abi_ulong target_= name) +{ + abi_long ret; + void *p; + + p =3D lock_user_string(target_name); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(thr_set_name(tid, p)); + unlock_user(p, target_name, 0); + + return ret; +} + +static inline abi_long do_freebsd_rtprio_thread(int function, lwpid_t lwpi= d, + abi_ulong target_addr) +{ + int ret; + struct rtprio rtp; + + ret =3D t2h_freebsd_rtprio(&rtp, target_addr); + if (!is_error(ret)) { + ret =3D get_errno(rtprio_thread(function, lwpid, &rtp)); + } + if (!is_error(ret)) { + ret =3D h2t_freebsd_rtprio(target_addr, &rtp); + } + return ret; +} + +static inline abi_long do_freebsd_getcontext(CPUArchState *env, abi_ulong = arg1) +{ + abi_long ret; + target_ucontext_t *ucp; + sigset_t sigmask; + + if (arg1 =3D=3D 0) { + return -TARGET_EINVAL; + } + ret =3D do_sigprocmask(0, NULL, &sigmask); + if (!is_error(ret)) { + ucp =3D lock_user(VERIFY_WRITE, arg1, sizeof(target_ucontext_t), 0= ); + if (ucp =3D=3D 0) { + return -TARGET_EFAULT; + } + ret =3D get_mcontext(env, &ucp->uc_mcontext, TARGET_MC_GET_CLEAR_R= ET); + host_to_target_sigset(&ucp->uc_sigmask, &sigmask); + memset(ucp->__spare__, 0, sizeof(ucp->__spare__)); + unlock_user(ucp, arg1, sizeof(target_ucontext_t)); + } + return ret; +} + +static inline abi_long do_freebsd_setcontext(CPUArchState *env, abi_ulong = arg1) +{ + abi_long ret; + target_ucontext_t *ucp; + sigset_t sigmask; + if (arg1 =3D=3D 0) { + return -TARGET_EINVAL; + } + ucp =3D lock_user(VERIFY_READ, arg1, sizeof(target_ucontext_t), 1); + if (ucp =3D=3D 0) { + return -TARGET_EFAULT; + } + ret =3D set_mcontext(env, &ucp->uc_mcontext, 0); + target_to_host_sigset(&sigmask, &ucp->uc_sigmask); + unlock_user(ucp, arg1, 0); + if (!is_error(ret)) { + (void)do_sigprocmask(SIG_SETMASK, &sigmask, NULL); + } + return ret =3D=3D 0 ? -TARGET_EJUSTRETURN : ret; +} + +/* swapcontext(2) */ +static inline abi_long do_freebsd_swapcontext(CPUArchState *env, abi_ulong= arg1, + abi_ulong arg2) +{ + abi_long ret; + target_ucontext_t *ucp; + sigset_t sigmask; + + if (arg1 =3D=3D 0 || arg2 =3D=3D 0) { + return -TARGET_EINVAL; + } + /* Save current context in arg1. */ + ret =3D do_sigprocmask(0, NULL, &sigmask); + if (!is_error(ret)) { + ucp =3D lock_user(VERIFY_WRITE, arg1, sizeof(target_ucontext_t), 0= ); + if (ucp =3D=3D 0) { + return -TARGET_EFAULT; + } + ret =3D get_mcontext(env, &ucp->uc_mcontext, TARGET_MC_GET_CLEAR_R= ET); + host_to_target_sigset(&ucp->uc_sigmask, &sigmask); + memset(ucp->__spare__, 0, sizeof(ucp->__spare__)); + unlock_user(ucp, arg1, sizeof(target_ucontext_t)); + } + if (is_error(ret)) { + return ret; + } + + /* Restore the context in arg2 to the current context. */ + ucp =3D lock_user(VERIFY_READ, arg2, sizeof(target_ucontext_t), 1); + if (ucp =3D=3D 0) { + return -TARGET_EFAULT; + } + ret =3D set_mcontext(env, &ucp->uc_mcontext, 0); + target_to_host_sigset(&sigmask, &ucp->uc_sigmask); + unlock_user(ucp, arg2, 0); + if (!is_error(ret)) { + (void)do_sigprocmask(SIG_SETMASK, &sigmask, NULL); + } + return ret =3D=3D 0 ? -TARGET_EJUSTRETURN : ret; +} + + +#define safe_g2h_untagged(x) ((x) !=3D 0 ? g2h_untagged(x) : NULL) + +/* + * undocumented _umtx_op(void *obj, int op, u_long val, void *uaddr, + * void *target_time); + */ + +#endif /* FREEBSD_OS_THREAD_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139884; cv=none; d=zohomail.com; s=zohoarc; b=SS4SXlLxDeZCYIgnCKhWyEPF3yICGNgUAq81g7YlUdwrLXi96HT8CIo2KFR4DoS/pAVsFRFglCtpRDsXLgFfRt1DIqY6/daFzV12Z3ynxf5nomv728TTra6uQ+dwlhIW9QYMwNbn0qSSs1Z1Zyl3NXjI3kllqS/PpX2dF7xzEZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139884; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=if9zs5/BYj3vgggDFOtTdd7tyuToJLpo8aht9ThzVZ4=; b=Gco3Dq/bNDwlOWASXW3gIrU8U0ThIjzy4k0+syWWDoBA6mtrL1eIGZbGlZZj+mTIGHWu9AwSftFNVTrD6hHz/rFGSQDSe3YB2E1+E7ZsJaRZOjRI8pqXnvK05c7maF5tGY9FDGcnPcwUGr3HZomjgJuVkRCg6KIdRFqHFYEOlYI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139884049269.4020080061339; Mon, 18 May 2026 14:31:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vm-0000Xt-Il; Mon, 18 May 2026 17:28:30 -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 1wP5Vg-0000Vm-RX for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:26 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Ve-0000Zz-L2 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:24 -0400 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7e36bb16a92so1712551a34.2 for ; Mon, 18 May 2026 14:28:21 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139700; x=1779744500; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=if9zs5/BYj3vgggDFOtTdd7tyuToJLpo8aht9ThzVZ4=; b=NLJ2+8703OJlqvl0TDW+GLk5FwGTK9Dl6lI1qXBqsMB8kHXA+zQfb5ymwstSnZH13d nXDmiH6EW5D9KucTdsYCZbohqIW50+HvijIr90e36fcxwWx9sL5o+MyaVsC0yHLFWznD 3KNKOX2T8aM5vytGbw+/S+/XfyAURrOXDoQhnIf5CmyK2O4JtIG1pZkI2+c3XecOFNqn iEnUPrgI0NvReYL1ozVXdjpxLm3lwUwS5DHfMsh6+OKLDFyye6vbBMosDcwj0TSy6gsx 6eZ+5JVu+/0RAu4viwpB6TO526uO3XoxRTKeGCjXkUCJlGsWwrd3izDoIIwdXxJhm57f RzTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139700; x=1779744500; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=if9zs5/BYj3vgggDFOtTdd7tyuToJLpo8aht9ThzVZ4=; b=ruRi40ibt2QgOJsf10mphK/Rnm8wfMGEyE7Xqd5JlMiMo0bGeJzpZIRqqtxKrlcSv9 8WFHeyOssl3j8IntLB1cHuW+t0o8DobymRnc99yIUQEqE4zqkgRhn8JuiDBb9fxAG8uK k1hFHx5nPNHm9bXPSp6lVJUrG5j5Yt49IyVgZAov3ekrNd1XQAd9eJSA+lm7BuJyuq0C hmmZSgjk7T45Wws7TzdLn36y23/GlO3HpoQVzAiuZZ3b12+djNWbNuyF4jN3UZVxd3Z4 xKyhv291hpwbLWCGh+ef1VttCsVxj6My1HOp0Vrf+Am2W1FI1G6dRiBAAo1FROBUws/c mkWA== X-Gm-Message-State: AOJu0YyKIarSgQHVaZ6yKVdpJvEuZS8DwuTmWYBT+O9AnWCvMlRFpFy4 xwfxXh6rN51xeqKvkP7Q6jCjNCVpMTerK4EOMQPwKc3yJmkrt/Td437kqGEiPvsXhGw= X-Gm-Gg: Acq92OGl70k4lnkLJ9FD4KrdlKn4XkHS9AzrLvSSEdW2Ldul0ZpOtEUn/Enl+2EujbM YkNBbh7KzPYyrKaEbBIcULaqt6owhNWo4StGXuQsTZOdUUNxZpYgbjtiWZZ63Mc8KkkjaAEhQIU eJkZkvNtnJeBw2q2ooxt2STkDRbPU7GgNHLNK75Vx6NLt/g/4RLhCAiSwA7ym7mFKw/WwqwADT5 xIODxLCitRyNIEPFhT6bdDef7B2o3Us90uxxjoAARBJhIsPkyUlxxfcpgH7+tpRvJcC+du/HP/c utowkEIv1JrJYrftVHLTrkNWPZp7J0wrZplnJS8a+4z8RRxCsrIJuKSU7HdeqKYatTvd98O3WQJ taCHT9MbcK9HWIAMa1HQI2vcmlk6rLjej+l7Fj7zSilzRGtz0fxdesdoK2iqogETpnle5oEgrUR bEuWd/CmnRgA== X-Received: by 2002:a9d:3e17:0:b0:7e5:6f53:5bee with SMTP id 46e09a7af769-7e56f535debmr6516762a34.21.1779139700162; Mon, 18 May 2026 14:28:20 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:45 -0600 Subject: [PATCH v2 27/37] bsd-user: Add do_freebsd__umtx_op to os-thread.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-27-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans , Jessica Clarke , Sean Bruno X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=13091; i=imp@bsdimp.com; h=from:subject:message-id; bh=4+GA8QrCmXfs+eg4WCBeD7ThMbhd3jADQhQetC+1sMw=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RIbENyMNLx/ppCPS1aLYRJtrTnWDkDPmPgV VL7m/u+60GJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AEPVEACcWjbLH9UCPw7pu2EWfRmdJSrPI6U9OqMuwJKf9qBcdMGEwimQKppCS8PWlm2zwZuX7Nr k6m/y3s+TNwbggRqSSOwXLyCmEVkKQ19mdXC8EcIYmnWMZXsf7V+lty0medAJiMHXbbbRBXEJd3 yb1/POMlHfAApU60WQ4YhMaQJ0hTGsJpQ1jAAdBYd1FlSaf1imEoemET4AWZmGeEElOFD0bWPvf pu+u2N9cth8/Kz23QFlC1v4STeECiySHtk1wXyoSOsa1+nvYKaGU7uQXL3CO7Em5jrr8kUTeItn zNa7LFdcdNHzFKYlo/Wx/f4zO6WFLhEEiTwGXIQ193hDFTzy0S5gtUHtjn9fERa+2/E/ynCTE7p 7Q3FquXbBHa51ACMZMMyYiWOdnw9VeF0Xp3e/DabVXyYkTS77zXr+iC+AheePFZGsoET1MOm7oN 92hV9jjEoUQ1fO6/2eFY5hR8PC3EHTTM/aA5HnoScRO/MWfiR7GEKylfZdlw07SY16kuRAxvn23 3UyBNPuO7KlLTKH/7636bpzg2oC0nmYOyAWLFmP6P/fqc2ivDIhdcw+6cbQOEhfHM0hIyJEWYHc JUtml3rpnJVZC2qQcSy0+VMU0XmfxWCBx/FWzvHVuEjUgcwkWHuDEurXGhPIYiIjwINC3VsigL5 Ew9UWbPP9G1aRVQ== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::336; envelope-from=imp@bsdimp.com; helo=mail-ot1-x336.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139884748158500 Add the _umtx_op system call implementation with support for UMTX lock/unlock, mutex operations, condition variables, reader-writer locks, semaphores, shared memory, and robust lists. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Jessica Clarke Signed-off-by: Sean Bruno Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-thread.h | 352 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 352 insertions(+) diff --git a/bsd-user/freebsd/os-thread.h b/bsd-user/freebsd/os-thread.h index bb8f279060..98fcd61009 100644 --- a/bsd-user/freebsd/os-thread.h +++ b/bsd-user/freebsd/os-thread.h @@ -240,5 +240,357 @@ static inline abi_long do_freebsd_swapcontext(CPUArch= State *env, abi_ulong arg1, * undocumented _umtx_op(void *obj, int op, u_long val, void *uaddr, * void *target_time); */ +static inline abi_long do_freebsd__umtx_op(abi_ulong obj, int op, abi_ulon= g val, + abi_ulong uaddr, abi_ulong target_time) +{ + abi_long ret; +#ifndef _UMTX_OPTIMIZED + struct _umtx_time ut[2]; + struct timespec ts; + size_t utsz; + long tid; +#endif + + switch (op) { + case TARGET_UMTX_OP_WAIT: + /* args: obj *, val, (void *)sizeof(ut), ut * */ +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_umtx_wait(obj, val, uaddr, + safe_g2h_untagged(target_time)); +#else + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_umtx_wait(obj, tswapal(val), utsz, &ut); + } else { + ret =3D freebsd_umtx_wait(obj, tswapal(val), 0, NULL); + } +#endif + break; + + case TARGET_UMTX_OP_WAKE: + /* args: obj *, nr_wakeup */ + ret =3D freebsd_umtx_wake(obj, val); + break; + + case TARGET_UMTX_OP_MUTEX_LOCK: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_lock_umutex(obj, 0, safe_g2h_untagged(target_time)= , uaddr, + 0, val); +#else + ret =3D get_errno(thr_self(&tid)); + if (is_error(ret)) { + return ret; + } + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_lock_umutex(obj, tid, ut, utsz, 0, tswapal(val= )); + } else { + ret =3D freebsd_lock_umutex(obj, tid, NULL, 0, 0, tswapal(val)= ); + } +#endif + break; + + case TARGET_UMTX_OP_MUTEX_UNLOCK: +#ifdef _UMTX_OPTIMIZED + ret =3D freebsd_unlock_umutex(obj, 0); +#else + ret =3D get_errno(thr_self(&tid)); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_unlock_umutex(obj, tid); +#endif + break; + + case TARGET_UMTX_OP_MUTEX_TRYLOCK: +#ifdef _UMTX_OPTIMIZED + ret =3D freebsd_lock_umutex(obj, 0, NULL, 0, TARGET_UMUTEX_TRY, va= l); +#else + ret =3D get_errno(thr_self(&tid)); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_lock_umutex(obj, tid, NULL, 0, TARGET_UMUTEX_TRY, + tswapal(val)); +#endif + break; + + case TARGET_UMTX_OP_MUTEX_WAIT: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_lock_umutex(obj, 0, safe_g2h_untagged(target_time)= , uaddr, + TARGET_UMUTEX_WAIT, val); +#else + ret =3D get_errno(thr_self(&tid)); + if (is_error(ret)) { + return ret; + } + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_lock_umutex(obj, tid, ut, utsz, TARGET_UMUTEX_= WAIT, + tswapal(val)); + } else { + ret =3D freebsd_lock_umutex(obj, tid, NULL, 0, TARGET_UMUTEX_W= AIT, + tswapal(val)); + } +#endif + break; + + case TARGET_UMTX_OP_MUTEX_WAKE: + /* Don't need to do access_ok(). */ + ret =3D freebsd_umtx_mutex_wake(obj, val); + break; + + case TARGET_UMTX_OP_SET_CEILING: + ret =3D 0; /* XXX quietly ignore these things for now */ + break; + + case TARGET_UMTX_OP_CV_WAIT: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_cv_wait(obj, uaddr, safe_g2h_untagged(target_time)= , val); +#else + /* + * Initialization of the struct conv is done by + * bzero'ing everything in userland. + */ + if (target_time !=3D 0) { + if (t2h_freebsd_timespec(&ts, target_time)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_cv_wait(obj, uaddr, &ts, val); + } else { + ret =3D freebsd_cv_wait(obj, uaddr, NULL, val); + } +#endif + break; + + case TARGET_UMTX_OP_CV_SIGNAL: + /* + * XXX + * User code may check if c_has_waiters is zero. Other + * than that it is assume that user code doesn't do + * much with the struct conv fields and is pretty + * much opauque to userland. + */ + ret =3D freebsd_cv_signal(obj); + break; + + case TARGET_UMTX_OP_CV_BROADCAST: + /* + * XXX + * User code may check if c_has_waiters is zero. Other + * than that it is assume that user code doesn't do + * much with the struct conv fields and is pretty + * much opauque to userland. + */ + ret =3D freebsd_cv_broadcast(obj); + break; + + case TARGET_UMTX_OP_WAIT_UINT: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_umtx_wait_uint(obj, val, uaddr, + safe_g2h_untagged(target_time)); +#else + if (!access_ok(VERIFY_READ, obj, sizeof(abi_ulong))) { + return -TARGET_EFAULT; + } + /* args: obj *, val, (void *)sizeof(ut), ut * */ + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_umtx_wait_uint(obj, tswap32((uint32_t)val), + utsz, &ut); + } else { + ret =3D freebsd_umtx_wait_uint(obj, tswap32((uint32_t)val), 0,= NULL); + } +#endif + break; + + case TARGET_UMTX_OP_WAIT_UINT_PRIVATE: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_umtx_wait_uint_private(obj, val, uaddr, + safe_g2h_untagged(target_time)); +#else + if (!access_ok(VERIFY_READ, obj, sizeof(abi_ulong))) { + return -TARGET_EFAULT; + } + /* args: obj *, val, (void *)sizeof(ut), ut * */ + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_umtx_wait_uint_private(obj, tswap32((uint32_t)= val), + utsz, &ut); + } else { + ret =3D freebsd_umtx_wait_uint_private(obj, tswap32((uint32_t)= val), + 0, NULL); + } +#endif + break; + + case TARGET_UMTX_OP_WAKE_PRIVATE: + /* Don't need to do access_ok(). */ + ret =3D freebsd_umtx_wake_private(obj, val); + break; + + case TARGET_UMTX_OP_RW_RDLOCK: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_rw_rdlock(obj, val, uaddr, + safe_g2h_untagged(target_time)); +#else + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_rw_rdlock(obj, val, utsz, &ut); + } else { + ret =3D freebsd_rw_rdlock(obj, val, 0, NULL); + } +#endif + break; + + case TARGET_UMTX_OP_RW_WRLOCK: +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_rw_wrlock(obj, val, uaddr, + safe_g2h_untagged(target_time)); +#else + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_rw_wrlock(obj, val, utsz, &ut); + } else { + ret =3D freebsd_rw_wrlock(obj, val, 0, NULL); + } +#endif + break; + + case TARGET_UMTX_OP_RW_UNLOCK: + ret =3D freebsd_rw_unlock(obj); + break; + +#ifdef UMTX_OP_MUTEX_WAKE2 + case TARGET_UMTX_OP_MUTEX_WAKE2: + ret =3D freebsd_umtx_mutex_wake2(obj, val); + break; +#endif /* UMTX_OP_MUTEX_WAKE2 */ + +#ifdef UMTX_OP_NWAKE_PRIVATE + case TARGET_UMTX_OP_NWAKE_PRIVATE: + ret =3D freebsd_umtx_nwake_private(obj, val); + break; +#endif /* UMTX_OP_NWAKE_PRIVATE */ + + case TARGET_UMTX_OP_SEM2_WAIT: + /* args: obj *, val, (void *)sizeof(ut), ut * */ +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok( + (uaddr > sizeof(struct target_freebsd__umtx_time) ? VERIFY_WRI= TE : + VERIFY_READ), target_time, uaddr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_umtx_sem2_wait(obj, uaddr, + safe_g2h_untagged(target_time)); +#else + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + /* Kernel writes out the ut[1] if utsz >=3D _umtx_time + times= pec. */ + ret =3D freebsd_umtx_sem2_wait(obj, utsz, ut); + if (ret =3D=3D -TARGET_EINTR && (ut[0]._flags & UMTX_ABSTIME) = =3D=3D 0 && + utsz >=3D sizeof(struct target_freebsd__umtx_time) + + sizeof(struct target_freebsd_timespec)) { + abi_ulong cret; + + cret =3D h2t_freebsd_timespec(target_time + + sizeof(struct target_freebsd__umtx_time), &ut[1]._time= out); + if (is_error(cret)) { + ret =3D cret; + } + } + } else { + ret =3D freebsd_umtx_sem2_wait(obj, 0, NULL); + } +#endif + break; + + case TARGET_UMTX_OP_SEM2_WAKE: + /* Don't need to do access_ok(). */ + ret =3D freebsd_umtx_sem2_wake(obj); + break; + case TARGET_UMTX_OP_SEM_WAIT: + /* args: obj *, val, (void *)sizeof(ut), ut * */ +#ifdef _UMTX_OPTIMIZED + if (target_time !=3D 0 && !access_ok(VERIFY_READ, target_time, uad= dr)) { + return -TARGET_EFAULT; + } + ret =3D freebsd_umtx_sem_wait(obj, uaddr, safe_g2h_untagged(target= _time)); +#else + if (target_time !=3D 0) { + ret =3D t2h_freebsd_umtx_time(target_time, uaddr, ut, &utsz); + if (is_error(ret)) { + return ret; + } + ret =3D freebsd_umtx_sem_wait(obj, utsz, ut); + } else { + ret =3D freebsd_umtx_sem_wait(obj, 0, NULL); + } +#endif + break; + + case TARGET_UMTX_OP_SEM_WAKE: + /* Don't need to do access_ok(). */ + ret =3D freebsd_umtx_sem_wake(obj); + break; + case UMTX_OP_SHM: + ret =3D freebsd_umtx_shm(uaddr, val); + break; + case TARGET_UMTX_OP_ROBUST_LISTS: + ret =3D freebsd_umtx_robust_list(uaddr, val); + break; + default: + return -TARGET_EINVAL; + } + return ret; +} =20 #endif /* FREEBSD_OS_THREAD_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139923; cv=none; d=zohomail.com; s=zohoarc; b=AZ+YTPFyu2TJnzWmJNVfeRmzxKyDUf638MB/x0+YFuIJxB6LCqSG8HHnz/ds1Ahz6PklSyHNcoa1De0KsFi6HTi8d24Q1qMlAW4KTG9kzIIJwYL5qSLb5zBNiaOOp42D2fcnT0OE/E3CyEGlEiDlbrLC5Cdhu4UG8YAeMA9teKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139923; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5Ym5e+SajqMg43ILFEA/gLXJCeMOEhtFDwp7ME9PnMY=; b=nduffcjITScKnOJBy/5j3268qgGWhGASiaUr7kXFROwUeOMzhZzKL1QyWrdarvn9ssFZFC3m5ZGCE/lGttpkMvifVnrMNFLuBRDRD+bHEkpbS5DE+nygOAldnYWgMNaq6sqK9DDnQ15pw6tFl9gueMLetS8A6VT9ll2qah01tLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139923492669.9214262195585; Mon, 18 May 2026 14:32:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vs-0000mC-KT; Mon, 18 May 2026 17:28:36 -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 1wP5Vj-0000WE-7S for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:27 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Ve-0000aJ-LN for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:26 -0400 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7dd73b7c757so1437649a34.0 for ; Mon, 18 May 2026 14:28:22 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139701; x=1779744501; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5Ym5e+SajqMg43ILFEA/gLXJCeMOEhtFDwp7ME9PnMY=; b=J6dzKzdBIMXL63xrOQ5AnE6enkWnrXHd1zJWMgea+zWCTk6trT6Vp+suI+8P9J2UbD uV5qUCTBECaJqyNVDAw0zam6EmtsvPC3e2DbRdme91nXiQx7ddRPP/UeyOQ/Tdm434S3 yIvJdanUP5Av9HMjFV/MnvCHN8IdTqGJcYeC327G4JF6JtaCNFxwjauvKD4nFgkDOKVU n4RYAkfXGH2q7wI2KLEFDIU4rT3LPvW3iRuhil0+x/Re3qCQfiOTAHSE8+tjFvJaWtqr tcqRS9gXBLamJYLtQeQAWGyEvRjNortZU62s+gUDBCyGkeY0sZyhkGwhizDlCYEyU/2E 6d6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139701; x=1779744501; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=5Ym5e+SajqMg43ILFEA/gLXJCeMOEhtFDwp7ME9PnMY=; b=GKCDiTzOsKBYKGbC/dLSvv20iH/OP0z7MyTxecfbcr/mAMwS+ArCtfrbdMN0Jonca8 JqZo/+MusQJjIwpUW5QOQU1pKuu8EF3n9vKpKkGi1yIKaJKh5msLGbfVKu6nTu+zvzW+ GmNr0uhRlAOA76yoHqeg41hXPmyd2DWyVfcGlbnoU1/Wrf8hs4Syo5nfTxDW5lVOmOO5 WvWLRyZDize9RXOqeo4oM30NRePnnZmeUyWGV+sVGig8VDoOYi8lHlwi3LcIAnJIvh9k hZqaR6CXB2/7m2I0cRbvLPS1xygJcK2jl8j47ck4sg9UWt80QMJoiZghBNr/lqEJZJgV AD3w== X-Gm-Message-State: AOJu0YyEmIOsTUx55HmF/1+uCY6kJsV29TiKDK2ffWZ3FhUCZAbPoMfc Ap7KsA7xy/Zin04xSHTD94RruuS9LG+GILeAeylYd8UWUnQaQ5aAHfzFHTWRkcGowvU= X-Gm-Gg: Acq92OGRKFv3muL2+1EZBVYkbx+Ertgfhwp2UZfyksMKAqqT75yhqf0aaNFiRtOyhtA EPgCUVosA2LWLGNw7wzQLy2VMjAIZI/bfEm67dKOGboGjM1lSF+2m4lJpwjftYZPQ/3aEmgTJdn ozk45iZmqWcorMFd92vZ76/tjWZq9/N28W6T18nkDgRFKGHiy5NRz7fPlAGJeIXaza1rNTXKtFN 0zkmnfhIhXEIdblZ1Aq0YQdlpv22OqCPACeBTQSfwZIBT7GPxNoEwB3vcVJTRFWcZoBcMf+mPav m+Xf5XMdRZtzmed5weKDVrR/MrHvf24Ciq3hY9VcTFbDMuS6FZMVP4sCifHiUxp/PFkrrZDaFzX T+vX7Po4U2DBU1C5fK46vD2pq9uburrCTlTr+/rvnpK+7Oml+naLIuP3VuuLmq3FYmqSrdlzhtj Ftaj3h58bquw== X-Received: by 2002:a05:6830:2589:b0:7e1:cbe3:bb1b with SMTP id 46e09a7af769-7e4de6a6079mr10842367a34.0.1779139701178; Mon, 18 May 2026 14:28:21 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:46 -0600 Subject: [PATCH v2 28/37] bsd-user: Add os-thread.c with umtx, mutex, and thread creation MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-28-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans , Jessica Clarke , Sean Bruno , Michal Meloun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=59857; i=imp@bsdimp.com; h=from:subject:message-id; bh=4mnFhJd5dcbA7v1boAaSw5bHaZMUX/CSC2qF9GM+qUQ=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RIDpdtrblPd6+4Fkms72Xec4zRzE6hWZrJN 5tjfMfqLdGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AO6hEADDGe/YE8fE8FVFjXor1Cier4XqDnFkKDtHYujKChJ1P/ZWIX1qvsu3Mue5f/JlwdBmDTD ejmt4nOA6TanxOmQnC+XpGyjJe/PiYXYnvzRaotpYLmC4+qH2psX6Ib3XOsJMAEVRK3+YENP8xo v2c8mmXw9cSi1YCK6U2PTloKFpRsxPiLALvS10Lau8RVS5CVljDDqhgSmYAnlBqXf1Lhj9Jh4VC qsoxOZLJ2hYw2v4YpnAqGE51evYrbdFkC1IgYxPUwlsVJwZvpVCdXUO0xGs+ZMk/BgSar6kwVW7 oAZVbb32X3OwB96O2vgdL+al/P5i+aVyKtIQuoGdcndZ0DPYp6UZi5gjS7xzu3N8xR4zgAS4GBK aiKXNNkWetqb84piabsghOab1i1iw+HzMEOdW8ByVOyT83TqM8WdFO7OcyZjJPNZqFqJ+SkXNrN al4cEhEAlFItUbtuwJ8wagoS+nx/zkklfKx7KAnOvuiBzviMHzllvmR/C5WJtaB+k7VwJFs+uSz y00RkLYVHwjypEPc0UYn84qscVLxp1JkNOC3IQm5NCC2g5mwAWXjO8d4AGd2VB+h793mGvtVQQ1 Kn6WM6HlyTI8U45LLvBPdApVtoMXYSpgeFGdhRaQf5vr/l42EG6iatxskGChy4BKK7EszoP7u7l /EE/JBdduoYJ4vw== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32d; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32d.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_FILL_THIS_FORM_SHORT=0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139925861154100 Add the FreeBSD threading implementation including: umtx wait/wake operations, mutex lock/unlock, condition variables, reader-writer locks, semaphores, thread creation (thr_new), rtprio conversion, robust list support, and shared memory operations. This is a large implementation file that provides the backing for the _umtx_op syscall and related thread operations. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Jessica Clarke Signed-off-by: Sean Bruno Signed-off-by: Michal Meloun Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-thread.c | 1682 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 1682 insertions(+) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c new file mode 100644 index 0000000000..dcf2216525 --- /dev/null +++ b/bsd-user/freebsd/os-thread.c @@ -0,0 +1,1682 @@ +/* + * FreeBSD thr emulation support code + * + * Copyright (c) 2013-2015 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" + +#include + +#include "qemu.h" +#include "qemu-os.h" +#include "signal-common.h" +#include "target_arch_cpu.h" +#include "target_arch_thread.h" +#include "tcg/startup.h" +#include "exec/tb-flush.h" + +#include "os-thread.h" + +/* #define DEBUG_UMTX(...) fprintf(stderr, __VA_ARGS__) */ +/* #define DEBUG_UMTX(...) qemu_log(__VA_ARGS__) */ +#define DEBUG_UMTX(...) + +#define DETECT_DEADLOCK 0 +#define DEADLOCK_TO 1200 + +#define NEW_STACK_SIZE 0x40000 + +/* sys/_umtx.h */ +struct target_umtx { + abi_ulong u_owner; /* Owner of the mutex. */ +}; + +struct target_umutex { + uint32_t m_owner; /* Owner of the mutex */ + uint32_t m_flags; /* Flags of the mutex */ + uint32_t m_ceiling[2]; /* Priority protect ceiling */ + abi_ulong m_rb_lnk; /* Robust linkage. */ +#if TARGET_ABI_BITS =3D=3D 32 + uint32_t m_pad; +#endif + uint32_t m_spare; + uint32_t m_count; /* QEMU-internal; takes one spare. */ +}; + +struct target_ucond { + uint32_t c_has_waiters; /* Has waiters in kernel */ + uint32_t c_flags; /* Flags of the condition variable */ + uint32_t c_clockid; /* Clock id */ + uint32_t c_spare[1]; +}; + +struct target_urwlock { + uint32_t rw_state; + uint32_t rw_flags; + uint32_t rw_blocked_readers; + uint32_t rw_blocked_writers; + uint32_t rw_spare[4]; +}; + +struct target__usem { + uint32_t _has_waiters; + uint32_t _count; + uint32_t _flags; +}; + +struct target__usem2 { + uint32_t _count; + uint32_t _flags; +}; + +struct target_umtx_robust_lists_params { + abi_ulong robust_list_offset; +#if TARGET_ABI_BITS =3D=3D 32 + uint32_t m_pad1; +#endif + abi_ulong robust_priv_list_offset; +#if TARGET_ABI_BITS =3D=3D 32 + uint32_t m_pad2; +#endif + abi_ulong robust_inact_offset; +#if TARGET_ABI_BITS =3D=3D 32 + uint32_t m_pad3; +#endif +}; + +/* + * !!! These mutexes must be reset in fork_end() (in bsd-user/main.c). + */ +static pthread_mutex_t new_thread_lock =3D PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *new_freebsd_thread_lock_ptr =3D &new_thread_lock; +static pthread_mutex_t umtx_wait_lck =3D PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *freebsd_umtx_wait_lck_ptr =3D &umtx_wait_lck; + +static void rtp_to_schedparam(const struct rtprio *rtp, int *policy, + struct sched_param *param) +{ + + switch (rtp->type) { + case RTP_PRIO_REALTIME: + *policy =3D SCHED_RR; + param->sched_priority =3D RTP_PRIO_MAX - rtp->prio; + break; + + case RTP_PRIO_FIFO: + *policy =3D SCHED_FIFO; + param->sched_priority =3D RTP_PRIO_MAX - rtp->prio; + break; + + default: + *policy =3D SCHED_OTHER; + param->sched_priority =3D 0; + break; + } +} + +void *new_freebsd_thread_start(void *arg) +{ + new_freebsd_thread_info_t *info =3D arg; + CPUArchState *env; + CPUState *cpu; + long tid; + + rcu_register_thread(); + tcg_register_thread(); + env =3D info->env; + cpu =3D env_cpu(env); + thread_cpu =3D cpu; + (void)thr_self(&tid); + + /* copy out the child TID to both locations */ + if (info->param.child_tid) { + put_user_ual(tid, info->param.child_tid); + } + if (info->param.parent_tid) { + put_user_ual(tid, info->param.parent_tid); + } + + /* Set arch dependent registers to start thread. */ + target_thread_set_upcall(env, info->param.start_func, info->param.arg, + info->param.stack_base, info->param.stack_size); + target_cpu_set_tls(env, info->param.tls_base); + + /* Enable signals */ + sigprocmask(SIG_SETMASK, &info->sigmask, NULL); + /* Signal to the parent that we're ready. */ + pthread_mutex_lock(&info->mutex); + pthread_cond_broadcast(&info->cond); + pthread_mutex_unlock(&info->mutex); + /* Wait until the parent has finished. */ + pthread_mutex_lock(new_freebsd_thread_lock_ptr); + pthread_mutex_unlock(new_freebsd_thread_lock_ptr); + + cpu_loop(env); + /* never exits */ + + return NULL; +} + +/* + * FreeBSD user mutex (_umtx) emulation + */ +static int tcmpset_al(abi_ulong *addr, abi_ulong a, abi_ulong b) +{ + abi_ulong current =3D tswapal(a); + abi_ulong new =3D tswapal(b); + +#ifdef TARGET_ABI32 + return atomic_cmpset_acq_32(addr, current, new); +#else + return atomic_cmpset_acq_64(addr, current, new); +#endif +} + +#ifdef _UMTX_OPTIMIZED +static int optimized_umtx_op(abi_ulong obj, int op, abi_ulong val, + void *uaddr1, void *uaddr2) +{ + + return get_errno(safe__umtx_op(g2h_untagged(obj), QEMU_UMTX_OP(op), va= l, + uaddr1, uaddr2)); +} + +#else /* !_UMTX_OPTIMIZED */ + +/* + * _cv_mutex keeps other threads from doing a signal or broadcast until + * the thread is actually asleep and ready. This is a global mutex for all + * condition vars so I am sure performance may be a problem if there are l= ots + * of CVs. + * + */ +static struct umutex _cv_mutex; + +static int tcmpset_32(uint32_t *addr, uint32_t a, uint32_t b) +{ + uint32_t current =3D tswap32(a); + uint32_t new =3D tswap32(b); + + return atomic_cmpset_acq_32(addr, current, new); +} + +#endif /* _UMTX_OPTIMIZED */ + +static abi_long _umtx_wait_uint(uint32_t *addr, uint32_t target_val, + size_t tsz, void *t, const char *where) +{ +#if DETECT_DEADLOCK + abi_long ret; + long cnt =3D 0; + + /* target_val has already been tswap'ed. */ + if (t =3D=3D NULL) { + struct timespec ts; + + ts.tv_sec =3D 5; + ts.tv_nsec =3D 0; + + do { + if (target_val !=3D *addr) { + return 0; + } + + ret =3D get_errno(safe__umtx_op(addr, QEMU_UMTX_OP(UMTX_OP_WAI= T_UINT), + target_val, NULL, &ts)); + + if (ret !=3D -TARGET_ETIMEDOUT) { + return ret; + } + if (cnt++ > DEADLOCK_TO) { + fprintf(stderr, "QEMU: Deadlock in %s from %s\n", + __func__, where); + abort(); + } + } while (1); + } else +#endif + return get_errno(safe__umtx_op(addr, QEMU_UMTX_OP(UMTX_OP_WAIT_UIN= T), + target_val, (void *)tsz, t)); +} + +abi_long freebsd_umtx_wait_uint(abi_ulong obj, uint32_t target_val, + size_t tsz, void *t) +{ + /* target_val has already been tswap'ed. */ + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, %d, %p)\n", __func__, + g2h_untagged(obj), UMTX_OP_WAIT_UINT, target_val, (int)tsz,= t); + + return _umtx_wait_uint(g2h_untagged(obj), target_val, tsz, t, __func__= ); +} + +static abi_long _umtx_wait_uint_private(uint32_t *addr, uint32_t target_va= l, + size_t tsz, void *t, const char *where) +{ +#if DETECT_DEADLOCK + abi_long ret; + long cnt =3D 0; + + /* target_val has already been tswap'ed. */ + if (t =3D=3D NULL) { + struct timespec ts; + + ts.tv_sec =3D 5; + ts.tv_nsec =3D 0; + + do { + if (target_val !=3D *addr) { + return 0; + } + + ret =3D get_errno(safe__umtx_op(addr, + QEMU_UMTX_OP(UMTX_OP_WAIT_UINT_PRIVATE), target_val, NULL, + &ts)); + + if (ret !=3D -TARGET_ETIMEDOUT) { + return ret; + } + if (cnt++ > DEADLOCK_TO) { + fprintf(stderr, "QEMU: Deadlock in %s from %s\n", __func__, + where); + abort(); + } + } while (1); + } else +#endif /* DETECT_DEADLOCK */ + { + return get_errno(safe__umtx_op(addr, + QEMU_UMTX_OP(UMTX_OP_WAIT_UINT_PRIVATE), target_val, (void *)t= sz, + t)); + } +} + +abi_long freebsd_umtx_wait_uint_private(abi_ulong obj, uint32_t target_val, + size_t tsz, void *t) +{ + DEBUG_UMTX(" %s: _umtx_op(%p (%u), %d, 0x%x, %d, %p= )\n", + __func__, g2h_untagged(obj), tswap32(*(uint32_t *)g2h_untagged(obj= )), + UMTX_OP_WAIT_UINT_PRIVATE, target_val, (int)tsz, t); + + return _umtx_wait_uint_private(g2h_untagged(obj), target_val, tsz, t, + __func__); +} + +static abi_long _umtx_wait(abi_ulong *addr, abi_ulong target_val, size_t t= sz, + void *t, const char *where) +{ +#if DETECT_DEADLOCK + abi_long ret; + long cnt =3D 0; + + /* target_val has already been tswap'ed. */ + + if (t =3D=3D NULL) { + struct timespec ts; + + ts.tv_sec =3D 5; + ts.tv_nsec =3D 0; + + do { + if (target_val !=3D *addr) { + return 0; + } + + ret =3D get_errno(safe__umtx_op(addr, QEMU_UMTX_OP(UMTX_OP_WAI= T), + target_val, NULL, &ts)); + if (ret !=3D -TARGET_ETIMEDOUT) { + return ret; + } + + if (cnt++ > DEADLOCK_TO) { + fprintf(stderr, "QEMU: Deadlock in %s from %s\n", __func__, + where); + abort(); + } + } while (1); + } else +#endif /* DETECT_DEADLOCK */ + { + return get_errno(safe__umtx_op(addr, QEMU_UMTX_OP(UMTX_OP_WAIT), + target_val, (void *)tsz, t)); + } +} + +abi_long freebsd_umtx_wait(abi_ulong targ_addr, abi_ulong target_id, size_= t tsz, + void *t) +{ + + /* target_id has already been tswap'ed. */ + + /* We want to check the user memory but not lock it. We might sleep. = */ + if (!access_ok(VERIFY_READ, targ_addr, sizeof(abi_ulong))) { + return -TARGET_EFAULT; + } + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%llx, %d, %p)\n", + __func__, g2h_untagged(targ_addr), UMTX_OP_WAIT, (long long)target= _id, + (int)tsz, t); + return _umtx_wait(g2h_untagged(targ_addr), target_id, tsz, t, __func__= ); +} + + +abi_long freebsd_umtx_wake_private(abi_ulong obj, uint32_t val) +{ + + DEBUG_UMTX(" %s: _umtx_op(%p (%d), %d, %u, NULL, NULL)\n= ", + __func__, g2h_untagged(obj), tswap32(*(uint32_t *)g2h_untagged(obj= )), + UMTX_OP_WAKE_PRIVATE, val); + return get_errno(safe__umtx_op(g2h_untagged(obj), + QEMU_UMTX_OP(UMTX_OP_WAKE_PRIVATE), val, NULL, NULL)); +} + +#if defined(UMTX_OP_NWAKE_PRIVATE) +#define BATCH_SIZE 128 +abi_long freebsd_umtx_nwake_private(abi_ulong target_array_addr, uint32_t = num) +{ +#ifdef _UMTX_OPTIMIZED + abi_ulong *tp; + uintptr_t uaddrs[BATCH_SIZE]; + int count, error, i, j; + + if (!access_ok(VERIFY_READ, target_array_addr, num * sizeof(abi_ulong)= )) { + return -TARGET_EFAULT; + } + + /* + * If we haven't relocated the guest, there's a 1:1 mapping so we can = avoid + * having to g2h_untagged() each address and just pass it through as-i= s. + */ + if (!have_guest_base && !reserved_va) { + return optimized_umtx_op(target_array_addr, UMTX_OP_NWAKE_PRIVATE,= num, + NULL, NULL); + } + + tp =3D (abi_ulong *)g2h_untagged(target_array_addr); + for (i =3D 0, count =3D num; i < num; i +=3D BATCH_SIZE, count -=3D BA= TCH_SIZE) { + for (j =3D i; j < i + MIN(BATCH_SIZE, count); j++) { + uaddrs[j % BATCH_SIZE] =3D (uintptr_t)g2h_untagged(tp[j]); + } + + /* + * This one should not be passed as compat32 at this point; we've + * converted them all to host pointers. + */ + error =3D safe__umtx_op(uaddrs, UMTX_OP_NWAKE_PRIVATE, + MIN(BATCH_SIZE, count), NULL, NULL); + if (error !=3D 0) { + return error; + } + } + + return 0; +#else + int i; + abi_ulong *uaddr; + abi_long ret =3D 0; + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL) Wakin= g: ", + __func__, g2h_untagged(target_array_addr), UMTX_OP_NWAKE_PRIVATE, = num); + + if (!access_ok(VERIFY_READ, target_array_addr, num * sizeof(abi_ulong)= )) { + return -TARGET_EFAULT; + } + + uaddr =3D (abi_ulong *)g2h_untagged(target_array_addr); + for (i =3D 0; i < (int32_t)num; i++) { + DEBUG_UMTX("%p (%u) ", g2h_untagged(tswapal(uaddr[i])), + tswap32(*(uint32_t *)g2h_untagged(tswapal(uaddr[i])))); + ret =3D get_errno(safe__umtx_op(g2h_untagged(tswapal(uaddr[i])), + UMTX_OP_WAKE_PRIVATE, INT_MAX, NULL, NULL)); + if (is_error(ret)) { + DEBUG_UMTX("\n"); + return ret; + } + } + DEBUG_UMTX("\n"); + return ret; +#endif /* _UMTX_OPTIMIZED */ +} +#endif /* UMTX_OP_NWAKE_PRIVATE */ + +#if defined(UMTX_OP_MUTEX_WAKE2) +abi_long freebsd_umtx_mutex_wake2(abi_ulong target_addr, uint32_t flags) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_addr, sizeof(struct target_umutex)= )) { + return -TARGET_EFAULT; + } + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_addr), UMTX_OP_MUTEX_WAKE2, flags); + return optimized_umtx_op(target_addr, UMTX_OP_MUTEX_WAKE2, flags, NULL, + NULL); +#else + uint32_t count, owner, *addr; + struct target_umutex *target_umutex; + + if (!lock_user_struct(VERIFY_WRITE, target_umutex, target_addr, 1)) { + return -TARGET_EFAULT; + } + pthread_mutex_lock(&umtx_wait_lck); + __get_user(count, &target_umutex->m_count); + __get_user(owner, &target_umutex->m_owner); + while ((owner & TARGET_UMUTEX_CONTESTED) =3D=3D 0 && (count > 1 || + (count =3D=3D 1 && (owner & ~TARGET_UMUTEX_CONTESTED) !=3D 0))= ) { + if (tcmpset_32(&target_umutex->m_owner, owner, + (owner | TARGET_UMUTEX_CONTESTED))) + break; + + /* owner has changed */ + __get_user(owner, &target_umutex->m_owner); + } + pthread_mutex_unlock(&umtx_wait_lck); + addr =3D &target_umutex->m_owner; + /* tcmpset_32 above writes to guest, and addr is just a key below */ + unlock_user_struct(target_umutex, target_addr, 0); + + return get_errno(safe__umtx_op(addr, UMTX_OP_WAKE_PRIVATE, 1, NULL, + NULL)); +#endif /* _UMTX_OPTIMIZED */ +} +#endif /* UMTX_OP_MUTEX_WAKE2 */ + +abi_long freebsd_umtx_sem2_wait(abi_ulong obj, size_t tsz, void *t) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, obj, sizeof(struct target__usem2))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(obj, UMTX_OP_SEM2_WAIT, 1, + (void *)(uintptr_t)tsz, t); +#else + struct target__usem2 *t__usem2; + uint32_t count, flags; + uint32_t *addr; + abi_long ret =3D 0; + + if (!lock_user_struct(VERIFY_WRITE, t__usem2, obj, 0)) { + return -TARGET_EFAULT; + } + + /* + * Make sure the count field has the has USEM_HAS_WAITERS flag set + * so userland will always call freebsd_umtx_sem2_wake(). + */ + for (;;) { + __get_user(count, &t__usem2->_count); + if (USEM_COUNT(count) !=3D 0) { + unlock_user_struct(t__usem2, obj, 1); + return 0; + } + if ((count & USEM_HAS_WAITERS) !=3D 0) { + break; + } + if (tcmpset_32(&t__usem2->_count, count, (count | USEM_HAS_WAITERS= ))) { + break; + } + } + + __get_user(flags, &t__usem2->_flags); + addr =3D &t__usem2->_count; + unlock_user_struct(t__usem2, obj, 1); + + if ((flags & USYNC_PROCESS_SHARED) =3D=3D 0) { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %p)\n", + __func__, addr, UMTX_OP_WAIT_UINT_PRIVATE, (int)tsz, t); + +#if DETECT_DEADLOCK + if (t !=3D NULL) { + ret =3D _umtx_wait_uint_private(addr, tswap32(USEM_HAS_WAITERS= ), tsz, + t, __func__); + } else { + for (;;) { + struct timespec ts; + + ts.tv_sec =3D 120; + ts.tv_nsec =3D 0; + + ret =3D _umtx_wait_uint_private(addr, tswap32(USEM_HAS_WAI= TERS), + 0, (void *)&ts, __func__); + if (ret =3D=3D 0) { + break; + } + if (ret !=3D -ETIMEDOUT) { + break; + } + if (!lock_user_struct(VERIFY_READ, t__usem2, obj, 1)) { + return -TARGET_EFAULT; + } + __get_user(count, &t__usem2->_count); + unlock_user_struct(t__usem2, obj, 0); + if (USEM_COUNT(count) !=3D 0) { + fprintf(stderr, "QEMU:(%s) TIMEOUT (count!=3D0)\n", __= func__); + ret =3D 0; + break; + } + if (ret =3D=3D -ETIMEDOUT) { + fprintf(stderr, "QEMU:(%s) TIMEOUT (exiting)\n", __fun= c__); + exit(-1); + } + } + } +#else + ret =3D _umtx_wait_uint_private(addr, tswap32(USEM_HAS_WAITERS), + tsz, t, __func__); +#endif /* DETECT_DEADLOCK */ + } else { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %p)\n", + __func__, addr, UMTX_OP_WAIT_UINT, (int)tsz, t); +#if DETECT_DEADLOCK + if (t !=3D NULL) { + ret =3D _umtx_wait_uint(addr, tswap32(USEM_HAS_WAITERS), tsz, = t, + __func__); + } else { + for (;;) { + struct timespec ts; + + ts.tv_sec =3D 120; + ts.tv_nsec =3D 0; + + ret =3D _umtx_wait_uint(addr, tswap32(USEM_HAS_WAITERS), 0, + (void *)&ts, __func__); + if (ret =3D=3D 0) { + break; + } + if (ret !=3D -ETIMEDOUT) { + break; + } + if (!lock_user_struct(VERIFY_READ, t__usem2, obj, 1)) { + return -TARGET_EFAULT; + } + __get_user(count, &t__usem2->_count); + unlock_user_struct(t__usem2, obj, 0); + if (USEM_COUNT(count) !=3D 0) { + fprintf(stderr, "QEMU:(%s) TIMEOUT (count!=3D0)\n", __= func__); + ret =3D 0; + break; + } + if (ret =3D=3D -ETIMEDOUT) { + fprintf(stderr, "QEMU:(%s) TIMEOUT (exiting)\n", __fun= c__); + exit(-1); + } + } + } +#else + ret =3D _umtx_wait_uint(addr, tswap32(USEM_HAS_WAITERS), tsz, t, + __func__); +#endif /* DETECT_DEADLOCK */ + } + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_umtx_sem2_wake(abi_ulong obj) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_READ, obj, sizeof(struct target__usem2))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(obj, UMTX_OP_SEM2_WAKE, 1, NULL, NULL); +#else + struct target__usem2 *t__usem2; + uint32_t *addr, flags; + abi_long ret; + + if (!lock_user_struct(VERIFY_READ, t__usem2, obj, 1)) { + return -TARGET_EFAULT; + } + + __get_user(flags, &t__usem2->_flags); + addr =3D &t__usem2->_count; + unlock_user_struct(t__usem2, obj, 0); + + if ((flags & USYNC_PROCESS_SHARED) =3D=3D 0) { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL)\n", + __func__, addr, UMTX_OP_WAKE_PRIVATE, INT_MAX); + ret =3D get_errno(safe__umtx_op(addr, UMTX_OP_WAKE_PRIVATE, INT_MA= X, NULL, + NULL)); + } else { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL)\n", + __func__, addr, UMTX_OP_WAKE, INT_MAX); + ret =3D get_errno(safe__umtx_op(addr, UMTX_OP_WAKE, INT_MAX, NULL,= NULL)); + } + + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_umtx_sem_wait(abi_ulong obj, size_t tsz, void *t) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, obj, sizeof(struct target__usem))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(obj, UMTX_OP_SEM_WAIT, 1, + (void *)(uintptr_t)tsz, t); +#else + struct target__usem *t__usem; + uint32_t count, flags, *addr; + abi_long ret; + + if (!lock_user_struct(VERIFY_WRITE, t__usem, obj, 0)) { + return -TARGET_EFAULT; + } + + __get_user(count, &t__usem->_count); + if (count !=3D 0) { + unlock_user_struct(t__usem, obj, 1); + return 0; + } + + /* + * Make sure the _has_waiters field is set so userland will always + * call freebsd_umtx_sem_wake(). + */ + __put_user(1, &t__usem->_has_waiters); + + __get_user(flags, &t__usem->_flags); + addr =3D &t__usem->_count; + unlock_user_struct(t__usem, obj, 1); + + if ((flags & USYNC_PROCESS_SHARED) =3D=3D 0) { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL)\n", + __func__, &t__usem->_count, UMTX_OP_WAKE_PRIVATE, = 0); + ret =3D _umtx_wait_uint_private(addr, 0, tsz, t, __func__); + } else { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL)\n", + __func__, &t__usem->_count, UMTX_OP_WAKE, 0); + ret =3D _umtx_wait_uint(addr, 0, tsz, t, __func__); + } + + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_umtx_sem_wake(abi_ulong obj) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, obj, sizeof(struct target__usem))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(obj, UMTX_OP_SEM_WAKE, 1, NULL, NULL); +#else + struct target__usem *t__usem; + uint32_t flags, *addr; + abi_long ret; + + if (!lock_user_struct(VERIFY_READ, t__usem, obj, 1)) { + return -TARGET_EFAULT; + } + __get_user(flags, &t__usem->_flags); + addr =3D &t__usem->_count; + unlock_user_struct(t__usem, obj, 0); + + if ((flags & USYNC_PROCESS_SHARED) =3D=3D 0) { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL)\n", + __func__, &t__usem->_count, UMTX_OP_WAKE_PRIVATE, = 1); + ret =3D get_errno(safe__umtx_op(addr, UMTX_OP_WAKE_PRIVATE, 1,= NULL, + NULL)); + } else { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, %d, NULL, NULL)\n", + __func__, &t__usem->_count, UMTX_OP_WAKE, 1); + ret =3D get_errno(safe__umtx_op(addr, UMTX_OP_WAKE, 1, NULL, N= ULL)); + } + + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long t2h_freebsd_rtprio(struct rtprio *host_rtp, abi_ulong target_addr) +{ + struct target_freebsd_rtprio *target_rtp; + + if (!lock_user_struct(VERIFY_READ, target_rtp, target_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_rtp->type, &target_rtp->type); + __get_user(host_rtp->prio, &target_rtp->prio); + unlock_user_struct(target_rtp, target_addr, 0); + return 0; +} + +abi_long h2t_freebsd_rtprio(abi_ulong target_addr, struct rtprio *host_rtp) +{ + struct target_freebsd_rtprio *target_rtp; + + if (!lock_user_struct(VERIFY_WRITE, target_rtp, target_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(host_rtp->type, &target_rtp->type); + __put_user(host_rtp->prio, &target_rtp->prio); + unlock_user_struct(target_rtp, target_addr, 1); + return 0; +} + +/* XXX We should never see this? OP_LOCK and OP_UNLOCK are now RESERVED{0,= 1} */ +abi_long freebsd_lock_umtx(abi_ulong target_addr, abi_long id, size_t tsz, + void *t) +{ + abi_long ret; + abi_long owner; + + gemu_log("This is unreachable."); + + /* + * XXX Note that memory at umtx_addr can change and so we need to be + * careful and check for faults. + */ + for (;;) { + struct target_umtx *target_umtx; + + if (!lock_user_struct(VERIFY_WRITE, target_umtx, target_addr, 0)) { + return -TARGET_EFAULT; + } + /* Check the simple uncontested case. */ + if (tcmpset_al(&target_umtx->u_owner, + TARGET_UMTX_UNOWNED, id)) { + unlock_user_struct(target_umtx, target_addr, 1); + return 0; + } + /* Check to see if the lock is contested but free. */ + __get_user(owner, &target_umtx->u_owner); + + if (TARGET_UMTX_CONTESTED =3D=3D owner) { + if (tcmpset_al(&target_umtx->u_owner, TARGET_UMTX_CONTESTED, + id | TARGET_UMTX_CONTESTED)) { + unlock_user_struct(target_umtx, target_addr, 1); + return 0; + } + /* We failed because it changed on us, restart. */ + unlock_user_struct(target_umtx, target_addr, 1); + continue; + } + + /* Set the contested bit and sleep. */ + do { + __get_user(owner, &target_umtx->u_owner); + if (owner & TARGET_UMTX_CONTESTED) { + break; + } + } while (!tcmpset_al(&target_umtx->u_owner, owner, + owner | TARGET_UMTX_CONTESTED)); + + __get_user(owner, &target_umtx->u_owner); + unlock_user_struct(target_umtx, target_addr, 1); + + /* Byte swap, if needed, to match what is stored in user mem. */ + owner =3D tswapal(owner); + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%llx, NULL, NULL)\n", + __func__, g2h_untagged(target_addr), UMTX_OP_WAIT, + (long long)owner); + ret =3D _umtx_wait(g2h_untagged(target_addr), owner, tsz, t, __fun= c__); + if (is_error(ret)) { + return ret; + } + } +} + +/* XXX We should never see this? OP_LOCK and OP_UNLOCK are now RESERVED{0,= 1} */ +abi_long freebsd_unlock_umtx(abi_ulong target_addr, abi_long id) +{ + abi_ulong owner; + struct target_umtx *target_umtx; + + gemu_log("This is unreachable."); + if (!lock_user_struct(VERIFY_WRITE, target_umtx, target_addr, 0)) { + return -TARGET_EFAULT; + } + __get_user(owner, &target_umtx->u_owner); + if ((owner & ~TARGET_UMTX_CONTESTED) !=3D id) { + unlock_user_struct(target_umtx, target_addr, 1); + return -TARGET_EPERM; + } + /* Check the simple uncontested case. */ + if ((owner & ~TARGET_UMTX_CONTESTED) =3D=3D 0) { + if (tcmpset_al(&target_umtx->u_owner, owner, + TARGET_UMTX_UNOWNED)) { + unlock_user_struct(target_umtx, target_addr, 1); + return 0; + } + } + /* This is a contested lock. Unlock it. */ + __put_user(TARGET_UMTX_UNOWNED, &target_umtx->u_owner); + unlock_user_struct(target_umtx, target_addr, 1); + + /* Wake up all those contesting it. */ + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_addr), UMTX_OP_WAKE, 0); + return get_errno(safe__umtx_op(g2h_untagged(target_addr), + QEMU_UMTX_OP(UMTX_OP_WAKE), 0, 0, 0)); +} + +abi_long freebsd_umtx_wake(abi_ulong target_addr, uint32_t n_wake) +{ + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_addr), UMTX_OP_WAKE, n_wake); + return get_errno(safe__umtx_op(g2h_untagged(target_addr), + QEMU_UMTX_OP(UMTX_OP_WAKE), n_wake, NULL, 0)); +} + +abi_long freebsd_umtx_wake_unsafe(abi_ulong target_addr, uint32_t n_wake) +{ + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_addr), UMTX_OP_WAKE, n_wake); + return get_errno(_umtx_op(g2h_untagged(target_addr), + QEMU_UMTX_OP(UMTX_OP_WAKE), n_wake, NULL, 0)); +} + +abi_long freebsd_umtx_mutex_wake(abi_ulong obj, abi_long val) +{ + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%llx, NULL, NULL)\n", + __func__, g2h_untagged(obj), UMTX_OP_WAKE, (long long)val); + return get_errno(safe__umtx_op(g2h_untagged(obj), + QEMU_UMTX_OP(UMTX_OP_MUTEX_WAKE), val, NULL, NULL)); +} + +abi_long freebsd_lock_umutex(abi_ulong target_addr, uint32_t id, + void *ts, size_t tsz, int mode, abi_ulong val) +{ +#ifdef _UMTX_OPTIMIZED + int op; + + if (!access_ok(VERIFY_WRITE, target_addr, sizeof(struct target_umutex)= )) { + return -TARGET_EFAULT; + } + + switch (mode) { + case TARGET_UMUTEX_WAIT: + op =3D UMTX_OP_MUTEX_WAIT; + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%llx, %p, %p)\n", + __func__, g2h_untagged(target_addr), op, (long long)val, + (void *)(uintptr_t)tsz, ts); + break; + case TARGET_UMUTEX_TRY: + op =3D UMTX_OP_MUTEX_TRYLOCK; + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%llx, %p, %p)\n= ", + __func__, g2h_untagged(target_addr), op, (long long)val, + (void *)(uintptr_t)tsz, ts); + break; + default: + op =3D UMTX_OP_MUTEX_LOCK; + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%llx, %p, %p)\n", + __func__, g2h_untagged(target_addr), op, (long long)val, + (void *)(uintptr_t)tsz, ts); + break; + } + + return optimized_umtx_op(target_addr, op, val, (void *)(uintptr_t)tsz,= ts); +#else + struct target_umutex *target_umutex; + uint32_t owner, flags, count, *addr; + int ret =3D 0; + + if (!lock_user_struct(VERIFY_WRITE, target_umutex, target_addr, 0)) { + return -TARGET_EFAULT; + } + + for (;;) { + + __get_user(owner, &target_umutex->m_owner); + + if ((owner & ~TARGET_UMUTEX_CONTESTED) =3D=3D 0) { + /* Lock is unowned. */ + if (TARGET_UMUTEX_WAIT =3D=3D mode) { + /* Waiting on an unlocked mutex; bail out. */ + unlock_user_struct(target_umutex, target_addr, 1); + return 0; + } + + /* Attempt to acquire it, preserve the contested bit ("owner")= . */ + while ((owner & ~TARGET_UMUTEX_CONTESTED) =3D=3D 0 && + !tcmpset_32(&target_umutex->m_owner, owner, owner | id= )) { + __get_user(owner, &target_umutex->m_owner); + } + + if ((owner & ~TARGET_UMUTEX_CONTESTED) =3D=3D 0) { + /* + * The acquire succeeded, because we didn't observe owner = with + * a different id. + */ + unlock_user_struct(target_umutex, target_addr, 1); + return 0; + } + + /* Otherwise, someone beat us to it; carry on. */ + } + + __get_user(flags, &target_umutex->m_flags); + if ((flags & TARGET_UMUTEX_ERROR_CHECK) !=3D 0 && + (owner & ~TARGET_UMUTEX_CONTESTED) =3D=3D id) { + unlock_user_struct(target_umutex, target_addr, 1); + return -TARGET_EDEADLK; + } + + if (TARGET_UMUTEX_TRY =3D=3D mode) { + unlock_user_struct(target_umutex, target_addr, 1); + return -TARGET_EBUSY; + } + + /* Set the contested bit and sleep. */ + while ((owner & TARGET_UMUTEX_CONTESTED) =3D=3D 0) { + if (tcmpset_32(&target_umutex->m_owner, owner, + owner | TARGET_UMUTEX_CONTESTED)) { + /* + * Keep our local view of owner consistent with what we th= ink + * we've set it to. We're about to sleep on it, and we do= n't + * really want a spurious return from _umtx_op because of = this. + */ + owner |=3D TARGET_UMUTEX_CONTESTED; + + break; + } else { + __get_user(owner, &target_umutex->m_owner); + } + } + + /* + * If it changed during the above loop, we may be able to acquire = now. + */ + if ((owner & ~TARGET_UMUTEX_CONTESTED) =3D=3D 0) { + continue; + } + + pthread_mutex_lock(&umtx_wait_lck); + __get_user(count, &target_umutex->m_count); + count++; + __put_user(count, &target_umutex->m_count); + pthread_mutex_unlock(&umtx_wait_lck); + + addr =3D &target_umutex->m_owner; + + /* addr used only as key below, not dereferenced */ + unlock_user_struct(target_umutex, target_addr, 1); + + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, %d, %jx) " + "count =3D %d\n", __func__, g2h_untagged(target_addr), + UMTX_OP_WAIT_PRIVATE, tswap32(target_umutex->m_owner), tsz, + (uintmax_t)ts, count); + ret =3D _umtx_wait_uint_private(addr, owner, tsz, (void *)ts, __fu= nc__); + + if (!lock_user_struct(VERIFY_WRITE, target_umutex, target_addr, 0)= ) { + return -TARGET_EFAULT; + } + + pthread_mutex_lock(&umtx_wait_lck); + __get_user(count, &target_umutex->m_count); + count--; + __put_user(count, &target_umutex->m_count); + pthread_mutex_unlock(&umtx_wait_lck); + if (ret !=3D 0) { + unlock_user_struct(target_umutex, target_addr, 1); + break; + } + } + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_unlock_umutex(abi_ulong target_addr, uint32_t id) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_addr, sizeof(struct target_umutex)= )) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_addr, UMTX_OP_MUTEX_UNLOCK, 0, NULL, N= ULL); +#else + struct target_umutex *target_umutex; + uint32_t count, owner, *addr, flags; + + if (!lock_user_struct(VERIFY_WRITE, target_umutex, target_addr, 0)) { + return -TARGET_EFAULT; + } + /* Make sure we own this mutex. */ + __get_user(owner, &target_umutex->m_owner); + if ((owner & ~TARGET_UMUTEX_CONTESTED) !=3D id) { + unlock_user_struct(target_umutex, target_addr, 1); + return -TARGET_EPERM; + } + pthread_mutex_lock(&umtx_wait_lck); + __get_user(count, &target_umutex->m_count); + + /* Unlock it; set the contested bit as needed. */ + flags =3D TARGET_UMUTEX_UNOWNED; + if (count > 1) { + flags |=3D TARGET_UMUTEX_CONTESTED; + } + __put_user(flags, &target_umutex->m_owner); + pthread_mutex_unlock(&umtx_wait_lck); + + addr =3D &target_umutex->m_owner; + + /* addr is used only as a key, so we can unlock before we use it below= */ + unlock_user_struct(target_umutex, target_addr, 1); + + /* + * And wake up any that may be contested it. We used to only do this = if the + * lock wasn't contested coming in, but that could have changed in the + * interim. Unconditionally issue the wakeup, in conjunction with the + * previous change of owner this should catch all cases. + */ + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_addr), UMTX_OP_WAKE, 0); + return get_errno(safe__umtx_op(addr, UMTX_OP_WAKE_PRIVATE, 1, NULL, NU= LL)); +#endif /* _UMTX_OPTIMIZED */ +} + +/* + * wflags CVWAIT_CHECK_UNPARKING, CVWAIT_ABSTIME, CVWAIT_CLOCKID + */ +abi_long freebsd_cv_wait(abi_ulong target_ucond_addr, + abi_ulong target_umtx_addr, struct timespec *ts, int wflags) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_ucond_addr, + sizeof(struct target_ucond))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_ucond_addr, UMTX_OP_CV_WAIT, wflags, + g2h_untagged(target_umtx_addr), ts); +#else + abi_long ret; + long tid; + struct target_ucond *target_ucond; + + if (!lock_user_struct(VERIFY_WRITE, target_ucond, target_ucond_addr, 0= )) { + return -TARGET_EFAULT; + } + + /* Check the clock ID if needed. */ + if ((wflags & TARGET_CVWAIT_CLOCKID) !=3D 0) { + uint32_t clockid; + + __get_user(clockid, &target_ucond->c_clockid); + if (clockid >=3D CLOCK_THREAD_CPUTIME_ID) { + /* Only HW clock id will work. */ + unlock_user_struct(target_ucond, target_ucond_addr, 1); + return -TARGET_EINVAL; + } + } + + thr_self(&tid); + + /* Lock the _cv_mutex so we can safely unlock the user mutex */ + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_LOCK, 0, NULL, NULL); + + /* Set c_has_waiters before releasing the user mutex! */ + __put_user(1, &target_ucond->c_has_waiters); + + /* unlock the user mutex */ + ret =3D freebsd_unlock_umutex(target_umtx_addr, tid); + if (is_error(ret)) { + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_UNLOCK, 0, NULL, NULL); + unlock_user_struct(target_ucond, target_ucond_addr, 1); + return ret; + } + + /* UMTX_OP_CV_WAIT unlocks _cv_mutex */ + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, %p, NULL)\n", + __func__, g2h_untagged(target_ucond_addr), UMTX_OP_CV_WAIT, wflags, + &_cv_mutex); + ret =3D safe__umtx_op(g2h_untagged(target_ucond_addr), UMTX_OP_CV_WAIT, + wflags, &_cv_mutex, ts); + + if (is_error(ret)) { + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_UNLOCK, 0, NULL, NULL); + unlock_user_struct(target_ucond, target_ucond_addr, 1); + return ret; + } + ret =3D freebsd_lock_umutex(target_umtx_addr, tid, NULL, 0, TARGET_UMU= TEX_TRY, + 0); + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_UNLOCK, 0, NULL, NULL); + unlock_user_struct(target_ucond, target_ucond_addr, 1); + + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_cv_signal(abi_ulong target_ucond_addr) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_ucond_addr, + sizeof(struct target_ucond))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_ucond_addr, UMTX_OP_CV_SIGNAL, 0, NULL, + NULL); +#else + abi_long ret; + + if (!access_ok(VERIFY_WRITE, target_ucond_addr, + sizeof(struct target_ucond))) { + return -TARGET_EFAULT; + } + + /* Lock the _cv_mutex to prevent a race in do_cv_wait(). */ + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_LOCK, 0, NULL, NULL); + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_ucond_addr), UMTX_OP_CV_SIGNAL, = 0); + ret =3D get_errno(safe__umtx_op(g2h_untagged(target_ucond_addr), + UMTX_OP_CV_SIGNAL, 0, NULL, NULL)); + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_UNLOCK, 0, NULL, NULL); + + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_cv_broadcast(abi_ulong target_ucond_addr) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_ucond_addr, + sizeof(struct target_ucond))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_ucond_addr, UMTX_OP_CV_BROADCAST, 0, N= ULL, + NULL); +#else + int ret; + + if (!access_ok(VERIFY_WRITE, target_ucond_addr, + sizeof(struct target_ucond))) { + return -TARGET_EFAULT; + } + + /* Lock the _cv_mutex to prevent a race in do_cv_wait(). */ + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_LOCK, 0, NULL, NULL); + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, g2h_untagged(target_ucond_addr), UMTX_OP_CV_BROADCAST, 0= ); + ret =3D get_errno(safe__umtx_op(g2h_untagged(target_ucond_addr), + UMTX_OP_CV_BROADCAST, 0, NULL, NULL)); + safe__umtx_op(&_cv_mutex, UMTX_OP_MUTEX_UNLOCK, 0, NULL, NULL); + + return ret; +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_rw_rdlock(abi_ulong target_addr, long fflag, size_t tsz, + void *t) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_addr, sizeof(struct target_urwlock= ))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_addr, UMTX_OP_RW_RDLOCK, fflag, + (void *)(uintptr_t)tsz, t); +#else + struct target_urwlock *target_urwlock; + uint32_t flags, wrflags; + uint32_t state; + uint32_t blocked_readers; + abi_long ret; + + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, target_addr, 0)) { + return -TARGET_EFAULT; + } + + __get_user(flags, &target_urwlock->rw_flags); + wrflags =3D TARGET_URWLOCK_WRITE_OWNER; + if (!(fflag & TARGET_URWLOCK_PREFER_READER) && + !(flags & TARGET_URWLOCK_PREFER_READER)) { + wrflags |=3D TARGET_URWLOCK_WRITE_WAITERS; + } + for (;;) { + __get_user(state, &target_urwlock->rw_state); + /* try to lock it */ + while (!(state & wrflags)) { + if (TARGET_URWLOCK_READER_COUNT(state) =3D=3D + TARGET_URWLOCK_MAX_READERS) { + unlock_user_struct(target_urwlock, + target_addr, 1); + return -TARGET_EAGAIN; + } + if (tcmpset_32(&target_urwlock->rw_state, state, + (state + 1))) { + /* The acquired succeeded. */ + unlock_user_struct(target_urwlock, + target_addr, 1); + return 0; + } + __get_user(state, &target_urwlock->rw_state); + } + /* set read contention bit */ + if (!tcmpset_32(&target_urwlock->rw_state, state, + state | TARGET_URWLOCK_READ_WAITERS)) { + /* The state has changed. Start over. */ + continue; + } + + /* contention bit is set, increase read waiter count */ + __get_user(blocked_readers, &target_urwlock->rw_blocked_readers); + while (!tcmpset_32(&target_urwlock->rw_blocked_readers, + blocked_readers, blocked_readers + 1)) { + __get_user(blocked_readers, &target_urwlock->rw_blocked_reader= s); + } + + ret =3D 0; + while (state & wrflags) { + /* sleep/wait */ + unlock_user_struct(target_urwlock, target_addr, 1); + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x (0x%x), NULL, NUL= L)\n", + __func__, &target_urwlock->rw_state, + UMTX_OP_WAIT_UINT, tswap32(state), + target_urwlock->rw_state); + ret =3D _umtx_wait_uint(&target_urwlock->rw_state, tswap32(sta= te), + tsz, t, __func__); + if (is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, + target_addr, 0)) { + return ret; + } + goto rdlock_decrement; + } + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, target_add= r, + 0)) { + return -TARGET_EFAULT; + } + __get_user(state, &target_urwlock->rw_state); + } + + /* decrease read waiter count */ +rdlock_decrement: + __get_user(blocked_readers, &target_urwlock->rw_blocked_readers); + while (!tcmpset_32(&target_urwlock->rw_blocked_readers, + blocked_readers, (blocked_readers - 1))) { + __get_user(blocked_readers, &target_urwlock->rw_blocked_reader= s); + } + if (blocked_readers =3D=3D 1) { + /* clear read contention bit */ + __get_user(state, &target_urwlock->rw_state); + while (!tcmpset_32(&target_urwlock->rw_state, state, + state & ~TARGET_URWLOCK_READ_WAITERS)) { + __get_user(state, &target_urwlock->rw_state); + } + } + if (is_error(ret)) { + /* tcmpset_32 operates on the target memory, so don't double c= opy */ + unlock_user_struct(target_urwlock, target_addr, 0); + return ret; + } + } +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_rw_wrlock(abi_ulong target_addr, long fflag, size_t tsz, + void *t) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_addr, sizeof(struct target_urwlock= ))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_addr, UMTX_OP_RW_WRLOCK, fflag, + (void *)(uintptr_t)tsz, t); +#else + struct target_urwlock *target_urwlock; + uint32_t blocked_readers, blocked_writers; + uint32_t state; + abi_long ret; + + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, target_addr, 0)) { + return -TARGET_EFAULT; + } + blocked_readers =3D 0; + for (;;) { + __get_user(state, &target_urwlock->rw_state); + while (!(state & TARGET_URWLOCK_WRITE_OWNER) && + TARGET_URWLOCK_READER_COUNT(state) =3D=3D 0) { + if (tcmpset_32(&target_urwlock->rw_state, state, + state | TARGET_URWLOCK_WRITE_OWNER)) { + unlock_user_struct(target_urwlock, target_addr, 1); + return 0; + } + __get_user(state, &target_urwlock->rw_state); + } + + if (!(state & (TARGET_URWLOCK_WRITE_OWNER | + TARGET_URWLOCK_WRITE_WAITERS)) && + blocked_readers !=3D 0) { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, &target_urwlock->rw_state, UMTX_OP_WAKE, + tswap32(state)); + ret =3D get_errno(safe__umtx_op(&target_urwlock->rw_state, + UMTX_OP_WAKE, INT_MAX, NULL, NULL)); + unlock_user_struct(target_urwlock, target_addr, ret =3D=3D 0); + return ret; + } + /* re-read the state */ + __get_user(state, &target_urwlock->rw_state); + + /* and set TARGET_URWLOCK_WRITE_WAITERS */ + while (((state & TARGET_URWLOCK_WRITE_OWNER) || + TARGET_URWLOCK_READER_COUNT(state) !=3D 0) && + (state & TARGET_URWLOCK_WRITE_WAITERS) =3D=3D 0) { + if (tcmpset_32(&target_urwlock->rw_state, state, + state | TARGET_URWLOCK_WRITE_WAITERS)) { + break; + } + __get_user(state, &target_urwlock->rw_state); + } + + /* contention bit is set, increase write waiter count */ + __get_user(blocked_writers, &target_urwlock->rw_blocked_writers); + while (!tcmpset_32(&target_urwlock->rw_blocked_writers, + blocked_writers, blocked_writers + 1)) { + __get_user(blocked_writers, &target_urwlock->rw_blocked_writer= s); + } + + /* sleep */ + ret =3D 0; + while ((state & TARGET_URWLOCK_WRITE_OWNER) || + (TARGET_URWLOCK_READER_COUNT(state) !=3D 0)) { + unlock_user_struct(target_urwlock, target_addr, 1); + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x(0x%x), NULL, NULL= )\n", + __func__, &target_urwlock->rw_blocked_writers, + UMTX_OP_WAIT_UINT, tswap32(state), + target_urwlock->rw_state); + ret =3D _umtx_wait_uint(&target_urwlock->rw_state, + tswap32(state), tsz, t, __func__); + if (is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, + target_addr, 0)) { + return ret; + } + goto wrlock_decrement; + } + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, target_add= r, + 0)) { + return -TARGET_EFAULT; + } + __get_user(state, &target_urwlock->rw_state); + } + + /* decrease the write waiter count */ +wrlock_decrement: + __get_user(blocked_writers, &target_urwlock->rw_blocked_writers); + while (!tcmpset_32(&target_urwlock->rw_blocked_writers, + blocked_writers, (blocked_writers - 1))) { + __get_user(blocked_writers, &target_urwlock->rw_blocked_writer= s); + } + if (blocked_writers =3D=3D 1) { + /* clear write contention bit */ + __get_user(state, &target_urwlock->rw_state); + while (!tcmpset_32(&target_urwlock->rw_state, state, + state & ~TARGET_URWLOCK_WRITE_WAITERS)) { + __get_user(state, &target_urwlock->rw_state); + } + __get_user(blocked_readers, &target_urwlock->rw_blocked_reader= s); + } else { + blocked_readers =3D 0; + } + if (is_error(ret)) { + /* tcmpset_32 operates on the target memory, so don't double c= opy */ + unlock_user_struct(target_urwlock, target_addr, 0); + return ret; + } + } +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long freebsd_rw_unlock(abi_ulong target_addr) +{ +#ifdef _UMTX_OPTIMIZED + if (!access_ok(VERIFY_WRITE, target_addr, sizeof(struct target_urwlock= ))) { + return -TARGET_EFAULT; + } + + return optimized_umtx_op(target_addr, UMTX_OP_RW_UNLOCK, 0, NULL, NULL= ); +#else + struct target_urwlock *target_urwlock; + uint32_t flags, state, count =3D 0; + + if (!lock_user_struct(VERIFY_WRITE, target_urwlock, target_addr, 0)) { + return -TARGET_EFAULT; + } + + __get_user(flags, &target_urwlock->rw_flags); + __get_user(state, &target_urwlock->rw_state); + + if (state & TARGET_URWLOCK_WRITE_OWNER) { + for (;;) { + if (!tcmpset_32(&target_urwlock->rw_state, state, + state & ~TARGET_URWLOCK_WRITE_OWNER)) { + /* + * Update the state here because we want to make sure that + * another thread didn't unste the flag from underneath us. + * If they did, we throw EPERM as the kernel does. + */ + __get_user(state, &target_urwlock->rw_state); + if (!(state & TARGET_URWLOCK_WRITE_OWNER)) { + unlock_user_struct(target_urwlock, target_addr, 1); + return -TARGET_EPERM; + } + } else { + break; + } + } + } else if (TARGET_URWLOCK_READER_COUNT(state) !=3D 0) { + /* decrement reader count */ + for (;;) { + if (!tcmpset_32(&target_urwlock->rw_state, state, (state - 1)= )) { + /* + * Just as in the branch above; we update the state here b= ecause + * we want to make sure the reader count didn't hit 0 whil= e we + * are still trying to decrement this. The kernel also ret= urns + * EPERM here. + */ + __get_user(state, &target_urwlock->rw_state); + if (TARGET_URWLOCK_READER_COUNT(state) =3D=3D 0) { + unlock_user_struct(target_urwlock, target_addr, 1); + return -TARGET_EPERM; + } + } else { + break; + } + } + } else { + unlock_user_struct(target_urwlock, target_addr, 1); + return -TARGET_EPERM; + } + + if (!(flags & TARGET_URWLOCK_PREFER_READER)) { + if (state & TARGET_URWLOCK_WRITE_WAITERS) { + count =3D 1; + } else if (state & TARGET_URWLOCK_READ_WAITERS) { + count =3D INT_MAX; + } + } else { + if (state & TARGET_URWLOCK_READ_WAITERS) { + count =3D INT_MAX; + } else if (state & TARGET_URWLOCK_WRITE_WAITERS) { + count =3D 1; + } + } + + /* rw_state used below as key only */ + unlock_user_struct(target_urwlock, target_addr, 1); + if (count !=3D 0) { + DEBUG_UMTX(" %s: _umtx_op(%p, %d, 0x%x, NULL, NULL)\n", + __func__, &target_urwlock->rw_state, UMTX_OP_WAKE, count); + return get_errno(safe__umtx_op(&target_urwlock->rw_state, UMTX_OP_= WAKE, + count, NULL, NULL)); + } else { + return 0; + } +#endif /* _UMTX_OPTIMIZED */ +} + +abi_long +freebsd_umtx_shm(abi_ulong target_addr, long fflag) +{ + + return get_errno(safe__umtx_op(NULL, QEMU_UMTX_OP(UMTX_OP_SHM), fflag, + g2h_untagged(target_addr), NULL)); +} + +abi_long +freebsd_umtx_robust_list(abi_ulong target_addr, size_t rbsize) +{ +#ifdef _UMTX_OPTIMIZED + struct target_umtx_robust_lists_params *tparams; + struct umtx_robust_lists_params hparams; + abi_long error; + + if (rbsize < sizeof(*tparams)) { + return -TARGET_EINVAL; + } + + if (!lock_user_struct(VERIFY_READ, tparams, target_addr, 1)) { + return -TARGET_EFAULT; + } + + hparams.robust_list_offset =3D + (uintptr_t)g2h_untagged(tparams->robust_list_offset); + hparams.robust_priv_list_offset =3D + (uintptr_t)g2h_untagged(tparams->robust_priv_list_offset); + hparams.robust_inact_offset =3D + (uintptr_t)g2h_untagged(tparams->robust_inact_offset); + + error =3D optimized_umtx_op(0, UMTX_OP_ROBUST_LISTS, sizeof(hparams), + &hparams, NULL); + unlock_user_struct(tparams, target_addr, 0); + return error; +#else + gemu_log("safe__umtx_op(..., UMTX_OP_ROBUST_LISTS. ...) not supported= \n"); + return -TARGET_EOPNOTSUPP; +#endif +} + +abi_long do_freebsd_thr_new(CPUArchState *env, + abi_ulong target_param_addr, int32_t param_size) +{ + new_freebsd_thread_info_t info; + pthread_attr_t attr; + TaskState *ts; + CPUArchState *new_env; + CPUState *new_cpu; + struct target_freebsd_thr_param *target_param; + abi_ulong target_rtp_addr; + struct target_freebsd_rtprio *target_rtp; + struct rtprio *rtp_ptr, rtp; + CPUState *cpu =3D env_cpu(env); + TaskState *parent_ts =3D (TaskState *)cpu->opaque; + sigset_t sigmask; + struct sched_param sched_param; + int sched_policy; + int ret =3D 0; + + memset(&info, 0, sizeof(info)); + + if (!lock_user_struct(VERIFY_READ, target_param, target_param_addr, 1)= ) { + return -TARGET_EFAULT; + } + info.param.start_func =3D tswapal(target_param->start_func); + info.param.arg =3D tswapal(target_param->arg); + info.param.stack_base =3D tswapal(target_param->stack_base); + info.param.stack_size =3D tswapal(target_param->stack_size); + info.param.tls_base =3D tswapal(target_param->tls_base); + info.param.tls_size =3D tswapal(target_param->tls_size); + info.param.child_tid =3D tswapal(target_param->child_tid); + info.param.parent_tid =3D tswapal(target_param->parent_tid); + info.param.flags =3D tswap32(target_param->flags); + target_rtp_addr =3D info.param.rtp =3D tswapal(target_param->rtp); + unlock_user_struct(target_param, target_param_addr, 0); + + thr_self(&info.parent_tid); + + if (target_rtp_addr) { + if (!lock_user_struct(VERIFY_READ, target_rtp, target_rtp_addr, 1)= ) { + return -TARGET_EFAULT; + } + rtp.type =3D tswap16(target_rtp->type); + rtp.prio =3D tswap16(target_rtp->prio); + unlock_user_struct(target_rtp, target_rtp_addr, 0); + rtp_ptr =3D &rtp; + } else { + rtp_ptr =3D NULL; + } + + /* Create a new CPU instance. */ + ts =3D g_malloc0(sizeof(TaskState)); + init_task_state(ts); + + /* Grab a mutex so that thread setup appears atomic. */ + pthread_mutex_lock(new_freebsd_thread_lock_ptr); + + /* + * If this is our first additional thread, we need to ensure we + * generate code for parallel execution and flush old translations. + * Do this now so that the copy gets CF_PARALLEL too. + */ + if (!(cpu->tcg_cflags & CF_PARALLEL)) { + cpu->tcg_cflags |=3D CF_PARALLEL; + tb_flush__exclusive_or_serial(); + } + + new_env =3D cpu_copy(env); + + new_cpu =3D env_cpu(new_env); + new_cpu->opaque =3D ts; + ts->bprm =3D parent_ts->bprm; + ts->info =3D parent_ts->info; + ts->signal_mask =3D parent_ts->signal_mask; + ts->ts_tid =3D qemu_get_thread_id(); + + pthread_mutex_init(&info.mutex, NULL); + pthread_mutex_lock(&info.mutex); + pthread_cond_init(&info.cond, NULL); + info.env =3D new_env; + + /* XXX check return values... */ + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, NEW_STACK_SIZE); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + if (rtp_ptr) { + rtp_to_schedparam(&rtp, &sched_policy, &sched_param); + pthread_attr_setschedpolicy(&attr, sched_policy); + pthread_attr_setschedparam(&attr, &sched_param); + } + + /* + * It is not safe to deliver signals until the child has finished + * initializing, so temporarily block all signals. + */ + sigfillset(&sigmask); + sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); + + ret =3D pthread_create(&info.thread, &attr, new_freebsd_thread_start, = &info); + + sigprocmask(SIG_SETMASK, &info.sigmask, NULL); + pthread_attr_destroy(&attr); + if (ret =3D=3D 0) { + /* Wait for the child to initialize. */ + pthread_cond_wait(&info.cond, &info.mutex); + } else { + /* Creation of new thread failed. */ + object_unparent(OBJECT(new_cpu)); + object_unref(OBJECT(new_cpu)); + g_free(ts); + ret =3D -host_to_target_errno(errno); + } + + pthread_mutex_unlock(&info.mutex); + pthread_cond_destroy(&info.cond); + pthread_mutex_destroy(&info.mutex); + pthread_mutex_unlock(new_freebsd_thread_lock_ptr); + + return ret; +} --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139863; cv=none; d=zohomail.com; s=zohoarc; b=ONXxD0kmPdxaYThCOb8z3abwlUir7RPhK4TCYHujmPNyx2AWmVBNUIYQyHTP4t6j/TUiQ0T5JpiPaR6fzt3PumnEmCIrMhniLfzs4jkDi2pwELNORsQl9pkkpJzp0DBMalNx1gv0Vu1lwVNgpt3U/ZbxBDXbpT+0H6UFP4i6NY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139863; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VjcpVZ6ruto1s3vfaA9tu6Wodi+LdfzqPHS4wMxKL5U=; b=b68aM4bNXRTuNxT8bk7YRQtUq0i8QMdHWdd6Km1pww1HrZXh55pSsnz/SYlqijeE4lglGwC+OriUDgDdm0AVrH9rLRSRBPoZ3NTEMlVpnZJDOapIqV+xtFRxTZ6MrsHMJV/o4rYbWS6SLgVvmGtFCj3d/PKJlj3yhR8ulLw6RBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177913986388588.11437947733373; Mon, 18 May 2026 14:31:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vs-0000lf-5o; Mon, 18 May 2026 17:28:36 -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 1wP5Vi-0000Vp-8T for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:26 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vg-0000al-1O for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:25 -0400 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7d4c383f2fcso2793921a34.0 for ; Mon, 18 May 2026 14:28:23 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139702; x=1779744502; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=VjcpVZ6ruto1s3vfaA9tu6Wodi+LdfzqPHS4wMxKL5U=; b=gPnH7fv0QaY+TmXSEWeO6rfD195PEtP5krGN5BubwrqbcHlw5+J5WFmOb2PJDfymvj Q8tdjSekxvzZJ3L15jdXOqj4yiq+f6GvsEfkzl1rvOzTDGdaXG1np8HLTqpd29JWKqmQ qTYAJeBaE8wiqsSUxZZDDruKOvzs4p+jkyGjYDN6J+Kf/CngvgmFaFhZj60AOBkszNhT s+gYQCBAvPEu8eUz/03EaIziPLKKBJgslacAwRaMNX5LBMobyBjKU61NaBufPoaWL79g L9ZOEzcKx6qiuX5g82d1zSLpm9RevnTR8voyz0LszBctWz6SGZ6iMOCilw4OEofPA7CF xkiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139702; x=1779744502; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VjcpVZ6ruto1s3vfaA9tu6Wodi+LdfzqPHS4wMxKL5U=; b=dkw+8ZfLkgte16qQKoL8CnsK5/Fk7d8K1K/UWDkp/btu7y4olDu85LKyVVxa107MWY ykiO8Z7rdk2azOrCcoa/Zt0ZQXwQfGyDahsfzFE7XeV6mlC4We6zi0lA21wc61KLyrkZ DSZ3Ry8DHQNRK7lRo3Yuzaq68lwLBUDG4J7qcJf9x/WooLqtcv+0cTvhcwsfG5N94UNy kBjyysGr6+dnfPlMPfGuP/quinUktZV5vKpaCtOHLSzhL/vjYuIZe49CWbx3h/E4A0cE u6dj13e6uGKMBEFvXUFHzMIuwdHA5vPhwAZlxFuCfC0xfMsUzrdt3pTlkDTKcnYLQEyz wggg== X-Gm-Message-State: AOJu0YwBvtScgiLvlTKBqycjh2UDK2tFLOwlkD+eQFHTKx67Ks51LVjT fEcZ37lm2L+TNilefnL+uCL/cLGHADjt5jTOtxdvJGLGpJgl8F7ycLcYE2XmzEaFWf0= X-Gm-Gg: Acq92OHRIwTb0VJXrNmbu04+Mu1+1WU8/V2vZWvwJRv5INiQe35pcAb//XnjyNYeAX0 r79W7ksqjk/h2/KgtkoY0BL4ixae+0V46JrzHOY5NdLs34NnjsKH4bCC+WRbmHMmHLs5URLMc0/ KkyNYqF2EJLAvTtFshy1POHtBTd9AHJtys3KZ4EE/dcupGsBUXYbt+Y+wnQY1M2F8rIWw4iR28G 3E40HHD/E/De5UwehBcvY0dlrAZWczWxHCVR1ZTrtlgDYEte08itzgUrcKw3bS4db4woIiJ9sMO 0w/CsR07/qJWroWIelrxrz1YhOurpTdUa1VpC9W5fm/CmYHj+DObFECaXpU77FxYIxrLGoBPtQt mTq0pNoyMVYfcQbwaFVm41VLhbBEyuMdtCcKrvOuZ7hGqSc44jIOZOf5QqVkt/UGn57GwFVjNon Uu70zzRD4biQ== X-Received: by 2002:a05:6830:710e:b0:7d9:71fa:3079 with SMTP id 46e09a7af769-7e4f2a13f65mr12075492a34.10.1779139702093; Mon, 18 May 2026 14:28:22 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:47 -0600 Subject: [PATCH v2 29/37] bsd-user: Add thread system call dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-29-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2698; i=imp@bsdimp.com; h=from:subject:message-id; bh=asnQtYV47YyPo4EF9BS4x3B4tv7oCfQH0yj2OEdHsb0=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RI82hUkPG34jVGmDGPszVjD47hlvV3fAtCc ID7x+CT96aJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AP+qD/oCZC26l6kuqSHV6iBJoe2eNsqeqRC26+GuNEYBHKtLtklhZNx7uv36/VINPBFRDNNSoaO 0kPA2xWCXbub971tu08dTl8OBkzez+eUYTefZyxKpanFva6FjnLDh00GWTvZ8lIheOYPK7+4ao8 8yvte2undgEtrdXmNCIYpI0mDdcUJk1dvKiErkjnLCIClkbQL65af0ILS/YukNo0RLSk/U8b0D6 ee7F4JxZVRKVJfzgebNg3l+QryL2dP0wfunLkfPVNvnNO5MmAM7T7nw39yvAb06p34mARi9r9tE 5y1RM6YwgfgUW6RLV0vtcOTy85992IDynBPN7YUrKr9hp1qL6KglF3NR/Q4KYC5msztpZZHDEEI pNv+qM+/m1vUhAR1jsg97GnAMsYbynDjD5d5ErpA8sFMUOK8Duc1Hzpx1ONWqmpaHZYSUvHxwmi KGtbc6eBKoXT+bhVW2tRqtnSM+ShYdXvL0lz+D/3L/rYwZeDLFDhkOa/d7dL9SsO7WXyInAgS3T bmSjlH7Uf1u69LPfvqIRJt72wCE42Y9DnofPH+mkanSQ/FcdYHBs2/I8N6w3Ps2K+ZBVsblLGFa BcvZJeJ/yY30U4P+lkK81UskzPMSyIV5sW+QXKImmArtnQ6ffTb6pOv+5eVNjOKPpNL1tWfBxjW haspBkdAyYdDlrA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32d; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32d.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139866729154100 Wire up thread-related system calls: thr_new, thr_set_name, thr_self, thr_suspend, thr_wake, thr_kill, thr_kill2, thr_exit, rtprio_thread, getcontext, setcontext, swapcontext, and _umtx_op. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-syscall.c | 55 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 55 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index f2c3ff25e8..0c729da0ab 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -1293,6 +1293,61 @@ static abi_long freebsd_syscall(CPUArchState *env, i= nt num, abi_long arg1, ret =3D do_freebsd_setfib(arg1); break; =20 + /* + * thread system calls + */ + case TARGET_FREEBSD_NR_thr_new: /* thr_new(2) */ + ret =3D do_freebsd_thr_new(env, arg1, arg2); + break; + + case TARGET_FREEBSD_NR_thr_set_name: /* thr_set_name(2) */ + ret =3D do_freebsd_thr_set_name(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_thr_self: /* thr_self(2) */ + ret =3D do_freebsd_thr_self(arg1); + break; + + case TARGET_FREEBSD_NR_thr_suspend: /* thr_suspend(2) */ + ret =3D do_freebsd_thr_suspend(arg1); + break; + + case TARGET_FREEBSD_NR_thr_wake: /* thr_wake(2) */ + ret =3D do_freebsd_thr_wake(arg1); + break; + + case TARGET_FREEBSD_NR_thr_kill: /* thr_kill(2) */ + ret =3D do_freebsd_thr_kill(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_thr_kill2: /* thr_kill2(2) */ + ret =3D do_freebsd_thr_kill2(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_thr_exit: /* thr_exit(2) */ + ret =3D do_freebsd_thr_exit(env, arg1); + break; + + case TARGET_FREEBSD_NR_rtprio_thread: /* rtprio_thread(2) */ + ret =3D do_freebsd_rtprio_thread(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getcontext: /* getcontext(2) */ + ret =3D do_freebsd_getcontext(env, arg1); + break; + + case TARGET_FREEBSD_NR_setcontext: /* setcontext(2) */ + ret =3D do_freebsd_setcontext(env, arg1); + break; + + case TARGET_FREEBSD_NR_swapcontext: /* swapcontext(2) */ + ret =3D do_freebsd_swapcontext(env, arg1, arg2); + break; + + case TARGET_FREEBSD_NR__umtx_op: /* undocumented */ + ret =3D do_freebsd__umtx_op(arg1, arg2, arg3, arg4, arg5); + break; + /* * sys{ctl, arch, call} */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139917; cv=none; d=zohomail.com; s=zohoarc; b=gPHM5CTAGPu/aUFrXyDqVgLwFTr5+KMdBoJCJWcQH6eYolE/Q0Wr1mfaGHpWP9D/tJ7BI7D721L2zuG3NnMPbgIqY99u2aIU19WEN3DUoW/K69bTt6Nawbz8lLetfdPazEibLC7zad6OmgkyTKr0oGbCjhW0fz8Eg1wPpFTgBX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139917; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M1JQVOiuc+A4ksNToUTMbfJYQEFXRR5y86p07JOscgc=; b=JJHWuAURgz/T38bHBIAcdJrBj1r5IxUs3p3UezGk5Kmg+ds3t8uiSpswvyh8S/dP8s8txTljpS1yfyaeUmNXvMZRkhgeFWOVkOnM0TCdt+E66pVMi0ufxoVBKLeMEXltGQwhQS+h7QyifH5O6MAK6xaKOuRDIweo3D5zRYh9QUM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139917198248.46444282331038; Mon, 18 May 2026 14:31:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vs-0000lR-2f; Mon, 18 May 2026 17:28:36 -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 1wP5Vi-0000Vr-FK for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:26 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vg-0000as-B1 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:26 -0400 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-479f7e75a6bso1006780b6e.2 for ; Mon, 18 May 2026 14:28:24 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139703; x=1779744503; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=M1JQVOiuc+A4ksNToUTMbfJYQEFXRR5y86p07JOscgc=; b=JHi5mFqpIkXIQas63BSuCTzeRQn+LsHjVtV1UgL/i+0OM2Ki4CQUGM0oa2I9aQ/oOI NxX/VqR7BkRnNe55Zj41Uw2KxfvJSUPc8o/kurKx0f/X+n7zkbtqTkjF5/9bVcDJ1hnM TGg/KtRsdjpHtm113zqUT/XmJRj7m13ajSkEgQLO2U4+k4rGi+J39/8sN8HgJ53eKdIr A9KuFtr3CDsdOUbyGZJq3IgXBed9x/Oy6ENFeU8okbpaPiWB0Br1CqD3ULnBKFOkwkbN FZHd/1JTs7jKrhMAn2rplZtwyQ7Jnl16X7jIFmAY5fdgv7+DWxkmtYWhCbzCT4B4wZDu D1TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139703; x=1779744503; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=M1JQVOiuc+A4ksNToUTMbfJYQEFXRR5y86p07JOscgc=; b=PM8e5Yi/ol+gb5IV3HQZnzTpsA5ZZd0eUh4R4QATobqZaVcTV/jxOW/w38ykkspGv0 o3zL/UKM77NUAXwan5FuaS7Ih9cayVyEogiAO4s9CUUNwTXW3I3cGqn7Ki9L4i3KQFao tLbSN9r2aNDgQfgHGMZdLtShDE+vnSL+rp+gSUwG47Z3QX8l0b7MPeKkDcUUam3tuo7K wHrcE9ogF68btb8cFyjxuiKmV6CkWUrGeyvUMrZkGKXJ/XJPmLwwW9ySjHipRtfQ6n1c YoIggNTJN1I0SlqO8iYew+2ccyjFcBdc4J5iRkp0nYDdEOy5qHYfq7acMK8klsw4aKlR Zv4A== X-Gm-Message-State: AOJu0YyYFzgi2eJkka5utWpN/mRwCsRpleFgArOuJ68nbHzQA7zXy0kJ yi5wO/P+uh3/y1o09epmIU3hZxO0y7d3Z9zdAGVcsGP/7pVf8hT360j6gwqqwQMkdl4= X-Gm-Gg: Acq92OH1RVYNMQb+TsY7dAvlT5FuK7lHhPnxKGTry6OP/EQ6+l9Po2o8uHkNWRH6b80 uFWhrwywqPGrNK36BnZOmBzYgbh+2UNYqhMCaRbV+6Zj2DKvPhlK78O8bJUzY97oYAxCzPu6dCH NLMLPDo6bmJ12OICmg9QwFq8oY42WiBxX7Ts52WtNAT5/qNa/S2aFha7E00gVIcuKkNdU6wmOBU yHlHK4MNJJJVwbCoUa/OpHm25DIxMBfHfcPLOq+LAWZUoOCZnS/6Pv4j/+I797u6KWiI4MN7zNl w5aqEBoq9dQ//HAv4WtV1XxddDOUO6I8OVDAkjYLLu2kzaERZs1KdNhrUMl1FiZEcZl9oGf11Za dXP17Ry7UF5aEcZgleng5k63SpqRTmWlogwn0uI/wcAhpQrd0BcCDqNROy1PJi6ofOQ6CALVuZu wX7RHdw9lo/A== X-Received: by 2002:a05:6808:c1e6:b0:47b:bd7b:10e5 with SMTP id 5614622812f47-482e55e6829mr10953018b6e.3.1779139703350; Mon, 18 May 2026 14:28:23 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:48 -0600 Subject: [PATCH v2 30/37] bsd-user: Add os-extattr.h with file and fd extattr functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-30-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6734; i=imp@bsdimp.com; h=from:subject:message-id; bh=Mm8GHafCndpbMfsQZNiUocUTnedWT7NJI/bDY50K/R0=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RINy1INaeXWug354SI7pRmAGneCXYV3+a7t p4ZpDdFNFeJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESAAKCRBsHNEofbAR AE7pD/0YrY9FyD5ypFx8E/SHhnbO4Q1JGDVe/0vtbUCsWp5Pr0tmsHqp0p53lNWaTzG6rEmz655 Ol5FNz4khSCVNYPHoBht9V4rTZvmkCzyQbj/UJaaJVjVCL2mnm7DpUP0JIQ+nagFbyPCRe3cl4l 6XSvozriuxsBQu+xaZC5tvZDfq8yRYQxq29efkAsFWJkesd7NhIXrGEHdyLCp4o5IvbMMzidhhx T3JBEluxwjsFKZ4a3bFbwTixl3Bde2JwZtwTASNJwd4Exny+rCYjC1cOUr0o/NpZW2QTfwUNkSG 4trVp3XXYhTLI2Y0peraKAw9ydNv6Lzd4RcpS3UcR8vO8iw0O6sIMW6OArUYlNHtKk9GGQGN6V4 iAziOhYgiZ3sUzIXSd+HmlFD0kOfPXiOA2ikbxgXqXOPfDyg1cc6YDGlqeu1zKV6xLxHnQCEmKL eF6QhZ0mtb5eVWE2Ud4po1HrHJ9ndcL0K0QqQpWGJFdynCT+Q2HindGA7I5+kUsmhUesEGx8H3v SHcwqkP2/zycJur27ND2A0FGOjbxKl4JL30rNU3rpOjTgZl/NPTe0YXEM9uCLl/ASkg46pF42B/ L4xKHMBcg9+iKnL1NDV44SA6aB0hKezAxmgzEDe1XndOR6TtTDCQ6wJdG1wH8WyXCfqV78JcW6g UyddGnAGKahBBOA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::236; envelope-from=imp@bsdimp.com; helo=mail-oi1-x236.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139919628154100 Add the first part of extended attribute support: extattrctl, extattr_set_file, extattr_get_file, extattr_delete_file, extattr_set_fd, extattr_get_fd, and extattr_delete_fd. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-extattr.h | 208 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 208 insertions(+) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h new file mode 100644 index 0000000000..f1dfa344cf --- /dev/null +++ b/bsd-user/freebsd/os-extattr.h @@ -0,0 +1,208 @@ +/* + * FreeBSD extended attributes and ACL system call support + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include + +/* extattrctl() */ +static inline abi_long do_freebsd_extattrctl(abi_ulong arg1, abi_ulong arg= 2, + abi_ulong arg3, abi_ulong arg= 4, + abi_ulong arg5) +{ + abi_long ret; + void *p, *a, *f; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + f =3D lock_user_string(arg3); + if (f =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg5); + if (a =3D=3D NULL) { + unlock_user(f, arg3, 0); + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattrctl(path(p), arg2, f, arg4, a)); + unlock_user(a, arg5, 0); + unlock_user(f, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_set_file(2) */ +static inline abi_long do_freebsd_extattr_set_file(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3, + abi_ulong arg4, + abi_ulong arg5) +{ + abi_long ret; + void *p, *a, *d; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + d =3D lock_user(VERIFY_READ, arg4, arg5, 1); + if (d =3D=3D NULL) { + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_set_file(path(p), arg2, a, d, arg5)); + unlock_user(d, arg4, arg5); + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_get_file(2) */ +static inline abi_long do_freebsd_extattr_get_file(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3, + abi_ulong arg4, + abi_ulong arg5) +{ + abi_long ret; + void *p, *a, *d; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + if (arg4 && arg5 > 0) { + d =3D lock_user(VERIFY_WRITE, arg4, arg5, 0); + if (d =3D=3D NULL) { + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_get_file(path(p), arg2, a, d, arg5)); + unlock_user(d, arg4, arg5); + } else { + ret =3D get_errno(extattr_get_file(path(p), arg2, a, NULL, arg5)); + } + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_delete_file(2) */ +static inline abi_long do_freebsd_extattr_delete_file(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + void *p, *a; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_delete_file(path(p), arg2, a)); + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_set_fd(2) */ +static inline abi_long do_freebsd_extattr_set_fd(abi_long arg1, abi_long a= rg2, + abi_ulong arg3, abi_ulong= arg4, + abi_ulong arg5) +{ + abi_long ret; + void *a, *d; + + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + return -TARGET_EFAULT; + } + d =3D lock_user(VERIFY_READ, arg4, arg5, 1); + if (d =3D=3D NULL) { + unlock_user(a, arg3, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_set_fd(arg1, arg2, a, d, arg5)); + unlock_user(d, arg4, arg5); + unlock_user(a, arg3, 0); + + return ret; +} + +/* extattr_get_fd(2) */ +static inline abi_long do_freebsd_extattr_get_fd(abi_long arg1, abi_long a= rg2, + abi_ulong arg3, abi_ulong= arg4, + abi_ulong arg5) +{ + abi_long ret; + void *a, *d; + + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + return -TARGET_EFAULT; + } + + if (arg4 && arg5 > 0) { + d =3D lock_user(VERIFY_WRITE, arg4, arg5, 0); + if (d =3D=3D NULL) { + unlock_user(a, arg3, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_get_fd(arg1, arg2, a, d, arg5)); + unlock_user(d, arg4, arg5); + } else { + ret =3D get_errno(extattr_get_fd(arg1, arg2, a, NULL, arg5)); + } + unlock_user(a, arg3, 0); + + return ret; +} + +/* extattr_delete_fd(2) */ +static inline abi_long do_freebsd_extattr_delete_fd(abi_long arg1, + abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + void *a; + + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_delete_fd(arg1, arg2, a)); + unlock_user(a, arg3, 0); + + return ret; +} + + +#endif /* FREEBSD_OS_EXTATTR_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139895; cv=none; d=zohomail.com; s=zohoarc; b=i2BvtGzO+x/GKsbD/R64wMUK4Q8WFqji3prxG4VuXY886Z4t4uRFSioj8KsTuQ2M0fTTcaadXf63AbsriNA/06sX40IOsOba4FQayOzCVUNNrXYa7rZrnQwfA+ngSA7jXMUQwc2qvvFx5zFgkCtC7ffQmHncCdhONuFQh+WqHdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139895; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9/Pm983+RalHXEJdvhTE1ujaaD6WPIIdOj3PbrYoEDY=; b=GiHI4RKKQcdQ3lXh+OiV0KoKfttmaoDislaX4BogWHr+RCXkCbT9hYc22Qk11Weos18sRntlS7mnhNMFvKcYjSFLn1h6jhsisKN0RvIF3k+9ATwTz2pISQDgwrc6k53pK6yaWI1AyAowhJxuqW70FcwyeYdWgpRubZCbd24WQ0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17791398954611007.3117343947454; Mon, 18 May 2026 14:31:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vm-0000Xm-IY; Mon, 18 May 2026 17:28:30 -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 1wP5Vj-0000WS-J2 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:27 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vh-0000b8-71 for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:27 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7dcd689829eso2448348a34.3 for ; Mon, 18 May 2026 14:28:24 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139704; x=1779744504; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9/Pm983+RalHXEJdvhTE1ujaaD6WPIIdOj3PbrYoEDY=; b=gGF2UTrQ/XXc4NHuTUnA11mhZLme189qbbgwP4jvL82PlQpFeXX7pFe+uCxak8gvsr CVg/HD5dOUmkQ4mpygf6+DRpebQy5+EixRNtguoN7inJc8dPQcNtxarRpw49bTOP2Tj/ 7XUqFDigrPgTCK/W1KEjK12LWVC4gweC5O9f1yj4NXbxdyrJ3869w1G1Z5RPfpb9olXh upfxAuetsQdatn9bhvrzonH2FWgHwCe82Kfb17eraDI0kWxekpav/eG2aMIDTtZBzTgp AwJ2I8t7BsTW6ADjwpbn4o5O+g8iLjSKANKHKhJz9YpBRQInoMUHILQb4yUDC9ees+Cs f3Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139704; x=1779744504; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=9/Pm983+RalHXEJdvhTE1ujaaD6WPIIdOj3PbrYoEDY=; b=c+PwOXCdK6Mlq7KyFps+qRuwk4aKYyCtHWvNbgAUqQu4SpxTArrvad9FVT8mxeoGZx nAGYF/K7c1MAKoDHhSSYHGQWFKY6Ph4uiEw22MTY7PaLUBVwR7geO5pkskygQ/WGBCZ5 pFOkVEtBWRddCs2Wx1KAgmuDjK/vc4Kx1C1GPiOQyXMuvShYRzk/SmBOlndMVObvmnDe VThZPE6TjBCWkDhM4DYhVkTX3pbk7ugwq4/JHDbqwih5UMKpr/RUkGp4/HDdlqDzyD6a djG/A6MZHTz+Gho/vTz/RQjEFhOPxKZ9my+U4CpSxp4aSgJtlTOAsjQATG8UrR/lBZDf 5mFw== X-Gm-Message-State: AOJu0Ywryg44eMLlD6IWpr1Cxd01UznJSMvsJasVGQ9YQ84LOgjJNMP4 cyVhIOwwC8vFjJC/i76iN3EXrg8f+Y09RiOJ6qETxWspzeImVo20+aqejFQFz1D1JN4= X-Gm-Gg: Acq92OG+XnSYi9HjNZnOS6ShTpyY+fgFZjuO0PiGM1vZePr2AAmGEH7csq8bnsIIdzT HOPUAPvc+Iq30yzlvwtKpSXM9P0w+4KdFqDC6DFKTQ3AiLZNlDu61+yrdBHTBg7PRFcrv34/prD w26qNmCwE+OOKQA6Y+/70/CYQyz/3QFtLUIaSAO+BmNCwaksvznkWVXwOM/vr7Lq+9I8rikV8Pc KJ0zT4HbGQ44S/emm4j7RPB6a99vWKqw3brR7X6Rqlmqt1mODl3jGzJYrJhNsoNeGR5nRZZe0Q7 gK4IVKe6OVjw1IBciMEA5iBqgpCiaer+YgQzYtxql5KaDO1wAzydAKdvBf1t234+3a1BqdV6jbB Gk2hY2QHYwh0wC5huteSLXHguGSAShbiTqzSQ2sURF2NP4JzbS7O6dACiKmcGymEWoFUTp1KSX7 5uMD009TuDLg== X-Received: by 2002:a05:6830:3c10:b0:7d7:58b0:7685 with SMTP id 46e09a7af769-7e4f2b45a37mr11795047a34.13.1779139704277; Mon, 18 May 2026 14:28:24 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:49 -0600 Subject: [PATCH v2 31/37] bsd-user: Add link and list extattr functions to os-extattr.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-31-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5758; i=imp@bsdimp.com; h=from:subject:message-id; bh=PPbhfZAlz9FxOpn1hoNZ1jrd9DPBmOMpHGkAGZveSpc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJE2p5r0kysLDzLNjAnUH0pZbZOSUJhksaz OkrBm/eqkuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR AKNFEADe7TJLTpUEb8WF75QT84uyv4ShkP10lkYzSVsJRZkXV6ywwqD4yO8yOp0ClGJtxgXdMHF XWGoGRqc3MEInOBN/PQ6z5fV3fgiMFm2P6iB7sgNiuGmuuEJo3RjI4ds317/6lPvWKo9Mx7phu/ dlw3CtoPkk+Jc0iPLcM+9T3IX9yEVhBV48Y8wfePJoZjMVAjBkK3QJerWRlhwbqEaDwranLCu1P xTIBaaFS7rDf9YzuHnMU2p6rUlmGafQ2tuo22gZw2V4dWUEeWcjy5p/eaHZQq6naerunQ4ZRrqn yww70NdkQhRGG3iWNODrz0wY28m2xXfR/Mq6hvijBWJSYEgMQKfg5toyedvcZsbnayAXmTca/EB /l7LZj3cowWlSd8iFQ1G7Zv5iP3mf4VXCaMCJSc+F6qdwBfZzMpEmOwrQ92eLwTcS7Y+2SJqlnq spDGVhcKUWJaTyqCailqYEQLaLf7+fkU9/DeFfMXjXiZqZQ+6iWFBU7n3czWoQqlsJxBijGVgXc ztBZzcaJwN+bsZ750Lm4e/2jj0MyXSqBMYVYjMQ5zja6nRBMjgMPJ1zARSWYlBTlS+eXQDXiHeK gf63hnPuxmNFfVQuxEDuIfn0/3UQYsPLWDmJ96vcwY/1WCBOtSD62cBrYTKgDCuvsdvtNw1TGHf 45otcow17+q5xVg== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32f; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32f.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139897354154100 Add extattr_get_link, extattr_set_link, extattr_delete_link, extattr_list_fd, extattr_list_file, and extattr_list_link. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-extattr.h | 172 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 172 insertions(+) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h index f1dfa344cf..788e40ef30 100644 --- a/bsd-user/freebsd/os-extattr.h +++ b/bsd-user/freebsd/os-extattr.h @@ -204,5 +204,177 @@ static inline abi_long do_freebsd_extattr_delete_fd(a= bi_long arg1, return ret; } =20 +/* extattr_get_link(2) */ +static inline abi_long do_freebsd_extattr_get_link(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3, + abi_ulong arg4, + abi_ulong arg5) +{ + abi_long ret; + void *p, *a, *d; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + if (arg4 && arg5 > 0) { + d =3D lock_user(VERIFY_WRITE, arg4, arg5, 0); + if (d =3D=3D NULL) { + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_get_link(path(p), arg2, a, d, arg5)); + unlock_user(d, arg4, arg5); + } else { + ret =3D get_errno(extattr_get_link(path(p), arg2, a, NULL, arg5)); + } + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_set_link(2) */ +static inline abi_long do_freebsd_extattr_set_link(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3, + abi_ulong arg4, + abi_ulong arg5) +{ + abi_long ret; + void *p, *a, *d; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + d =3D lock_user(VERIFY_READ, arg4, arg5, 1); + if (d =3D=3D NULL) { + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_set_link(path(p), arg2, a, d, arg5)); + unlock_user(d, arg4, arg5); + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_delete_link(2) */ +static inline abi_long do_freebsd_extattr_delete_link(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + void *p, *a; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + a =3D lock_user_string(arg3); + if (a =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_delete_link(path(p), arg2, a)); + unlock_user(a, arg3, 0); + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_list_fd(2) */ +static inline abi_long do_freebsd_extattr_list_fd( + abi_long arg1, abi_long arg2, abi_ulong arg3, abi_ulong arg4) +{ + abi_long ret; + void *d; + + if (arg3 && arg4 > 0) { + d =3D lock_user(VERIFY_WRITE, arg3, arg4, 0); + if (d =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_list_fd(arg1, arg2, d, arg4)); + unlock_user(d, arg3, arg4); + } else { + ret =3D get_errno(extattr_list_fd(arg1, arg2, NULL, arg4)); + } + return ret; +} + +/* extattr_list_file(2) */ +static inline abi_long do_freebsd_extattr_list_file( + abi_long arg1, abi_long arg2, abi_ulong arg3, abi_ulong arg4) +{ + abi_long ret; + void *p, *d; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + if (arg3 && arg4 > 0) { + d =3D lock_user(VERIFY_WRITE, arg3, arg4, 0); + if (d =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_list_file(path(p), arg2, d, arg4)); + unlock_user(d, arg3, arg4); + } else { + ret =3D get_errno(extattr_list_file(path(p), arg2, NULL, arg4)); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* extattr_list_link(2) */ +static inline abi_long do_freebsd_extattr_list_link( + abi_long arg1, abi_long arg2, abi_ulong arg3, abi_ulong arg4) +{ + abi_long ret; + void *p, *d; + + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + if (arg3 && arg4 > 0) { + d =3D lock_user(VERIFY_WRITE, arg3, arg4, 0); + if (d =3D=3D NULL) { + unlock_user(p, arg1, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(extattr_list_link(path(p), arg2, d, arg4)); + unlock_user(d, arg3, arg4); + } else { + ret =3D get_errno(extattr_list_link(path(p), arg2, NULL, arg4)); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* + * Access Control Lists + */ + =20 #endif /* FREEBSD_OS_EXTATTR_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139881; cv=none; d=zohomail.com; s=zohoarc; b=Am7/2a2bhxQCBuKqM1WHV9tW5zM+dBR7DX2RmqMTjV79aoLcPey3lEe6d0nXm6LNaxHIn2dE+PxESWfaqfqBpbu2Vv9OXhlgX6sCAXk8QjmoqU8waNhve93CZB33iu7qu5AuYIN0Rj9B9O7hEYTajde6h69wM1i4f52PB1ZQ4Ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139881; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=46PeUjItrCiTFLvIk8NnwF5r7lBcB9iBG7KmhEjuYK0=; b=SReh+aOcV2KZt4XgQVjjnw3fu18LCCocyj0cEe4em6XEIpd8xnutAhCot6SPj8rbd9WqdQcnhBNj3E/UH5frbQuygHGuqrnX3NsTOudng7Oxe3ndtMTfdH1PidfSN3rHlGR6Kgu4HVOOKPPoVFwQWGhP2LzrbU1j/dFgZXXPHZE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139881071571.9981992789412; Mon, 18 May 2026 14:31:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vq-0000hS-6v; Mon, 18 May 2026 17:28:34 -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 1wP5Vk-0000XP-Pb for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:29 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vi-0000cD-8Q for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:28 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7dd73b7c757so1437674a34.0 for ; Mon, 18 May 2026 14:28:25 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139705; x=1779744505; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=46PeUjItrCiTFLvIk8NnwF5r7lBcB9iBG7KmhEjuYK0=; b=XWo1CF/JxEvMTtuhPghaeYzJo7e7B3bTsvfni7i2LUMUy1cgrKeb8pGaFqblJF4i+U RFCmpAuPVdOcDwWKbgzvS+cXGW7wBmaFO5xr92ON5Yie7SeitzwgIoKL8QgSFjxTovLC Ao371XcK+I3nEjZTc9y5rmwyZu4ssbrGeKW6us81cbfE+XfT/7aVFvVDYopHYnhiqak7 7Iw4e+Ihz3bc34Zh3w3ldnwVa0n8HR8384rYw+gW862dPYQEjcnCcpWe1PcsIo1lswGy V9mpd6rMjaQsuN+PXMlPHD3DVqc7KJUNqL5kOC/74Lp8Yt+N0WRcRwT5OtHqVEjFHCKi O0GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139705; x=1779744505; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=46PeUjItrCiTFLvIk8NnwF5r7lBcB9iBG7KmhEjuYK0=; b=fd1G6dzeGkjJifPz5AaLKfH13GJ7sehLhTykUs1ix2rBXCBAoJfQol1MZqXvt7rk57 ewkPFJ/VdXwhu6t4yDGfZs91UQGq8YUrdUg3ckBKwepAqSOnsh5IsqN2Be4xm3Txqd/Q /VQcoWkdrWaiHfMzJ3ZVwpWm7p/HrWkFVRmJvgi/7UbQ+lZ4JjVcDb+9Imzyy6VIEyPj VEgt/07nL/gj33hCvzXLL0gip1Q/MVcUZM30NjBuo99JsHx5JIJf5+0E23gWW4HXkbg3 A3aL/t7SfIVc1+P7Hk9rjRCPTWXbBN+/P+V+Rg7NmByoqoOc12UUD0yWG7MRkcNtB+UP 5Y/g== X-Gm-Message-State: AOJu0YwJMjFbh5SFOE95rfEY5XESzsM470s8TzGrIx96weR+7dmM522y CrY8DzV9uiP+jpEIp/DDVdO+D2cbzVJcNA9bBsxlNzz/VGmU59QE+kQie+GRVg6vG4k= X-Gm-Gg: Acq92OEBr5bs8fozjt6o79IHxN+spj10ntunBLXIf4lF7voVu9vMI8CBBSOfwRzZKbD 2Fl3W+h9KsvQD7K2zEfk9ooWoXw6HbH2mlYGXq0FXXGSxqok79zIW6xJ+8TgGOwAh1h6BFNjNPX hMvOsSYWsR6VOnpCmPPfHli1aFjYybwO7Pjw3ninFiYaEDggDRzmlafjYosZxpzvrTOkjj2aoPE GPRsHtx1jmk9oegPf4nJjXD9Pdat5sW2QONI1ebRHsPJjoZNmXT7bkrQagiscsbA7wtVQLPqAC8 XIkEfj3kMnKSmxJT32AVsBYzDFxneihQzGlC2M5wEh1uFbTNyDXQx+i5BvR2NUvh3fTx2i5smgV bsptvnObt/fh6hv9rk7NHPdEkX2VWnE6IIy4xsLTtw4JtHd6VIlNvOoq6ocIp635n9DDPHUbWMy +Wbn125tQbJg== X-Received: by 2002:a05:6830:4ac1:b0:7dc:dd19:7f69 with SMTP id 46e09a7af769-7e4f2bd7a56mr11041453a34.17.1779139705115; Mon, 18 May 2026 14:28:25 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:50 -0600 Subject: [PATCH v2 32/37] bsd-user: Add ACL system call shims to os-extattr.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-32-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=9931; i=imp@bsdimp.com; h=from:subject:message-id; bh=cxGOb8uOizVRPPdFfcThc7BXNzJpQX4gEPSZTPwW3gc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJCbmGXBibmRp8k9xaGxsyFDTNMj3XUABpy WwVx4I6y6aJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR APXSD/90wnATv6GJmeZkgAgGazgUDuGF0giIqOyZczOFIi5c5tHvtKS3cKH+FsryQQ0u+7J3/nX oNGbpucKFvQ+j5wDhuH+BMTE5MG2TAqsWbdqV/r7APaZ1YbqPix98zhZJQVJsSsmBLXJiwa7lfG TPYAbEFEVHEnXRLvuF3FOOmq7hvuwkpL5tzgbPNL7kzSJgFsqXDWXpEYhtd3RdqnjCW2gaHGQgY 4I/OR7NyVUhxCDOmtE3eFZA3eji9yT49nayjbqrpuALD3aqvHjdZhF/gl/KCQvE/vyghYkfP2rZ 8NiZL8O0kxDy2GbDbTc1tQCqE247WbvXNpeObPa0p3Ovt/D0m4lp2+wTjlnE/bFmQ2GCLbDVnwj akHWdMUl7FbXTVwWI9vBzpJu3HE0rEfK0547NxPMIgnrDpXUxaoy7z/gB/8pAZn+w13mgWQ8sgK TnLFHMCCgcNH6RREhW3ga4eeWmSv+FM4Zidw8WUBEvmdaYIIkd3yvfnHEPPkNZRieX2iq7xyvZr 93vB2pqU8xqE/CeUZJQq4qd56ivJLCc0MxA8BEvsiDmvbykeQnFH+TrJQ6pzRhVJ2tPg0iFGxvJ yYfTQ0Dirj8Vu3/TT8gZTEAGM7rVvwqXSsmQuUa5gU65p7MpUUvFieW1mLjsGEx+aAhV8gWneUW vD2LEBCIxFNyNTA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::332; envelope-from=imp@bsdimp.com; helo=mail-ot1-x332.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139883140154100 Complete os-extattr.h with ACL operations: __acl_aclcheck_fd, __acl_aclcheck_file, __acl_aclcheck_link, __acl_delete_fd, __acl_delete_file, __acl_delete_link, __acl_get_fd, __acl_get_file, __acl_get_link, __acl_set_fd, __acl_set_file, and __acl_set_link. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-extattr.h | 290 ++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 286 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h index 788e40ef30..5f5678b380 100644 --- a/bsd-user/freebsd/os-extattr.h +++ b/bsd-user/freebsd/os-extattr.h @@ -65,7 +65,7 @@ static inline abi_long do_freebsd_extattr_set_file(abi_ul= ong arg1, return -TARGET_EFAULT; } ret =3D get_errno(extattr_set_file(path(p), arg2, a, d, arg5)); - unlock_user(d, arg4, arg5); + unlock_user(d, arg4, 0); unlock_user(a, arg3, 0); unlock_user(p, arg1, 0); =20 @@ -151,7 +151,7 @@ static inline abi_long do_freebsd_extattr_set_fd(abi_lo= ng arg1, abi_long arg2, return -TARGET_EFAULT; } ret =3D get_errno(extattr_set_fd(arg1, arg2, a, d, arg5)); - unlock_user(d, arg4, arg5); + unlock_user(d, arg4, 0); unlock_user(a, arg3, 0); =20 return ret; @@ -267,7 +267,7 @@ static inline abi_long do_freebsd_extattr_set_link(abi_= ulong arg1, return -TARGET_EFAULT; } ret =3D get_errno(extattr_set_link(path(p), arg2, a, d, arg5)); - unlock_user(d, arg4, arg5); + unlock_user(d, arg4, 0); unlock_user(a, arg3, 0); unlock_user(p, arg1, 0); =20 @@ -376,5 +376,287 @@ static inline abi_long do_freebsd_extattr_list_link( * Access Control Lists */ =20 +/* __acl_aclcheck_fd(int filedes, acl_type_t type, struct acl *aclp); */ +static inline abi_long do_freebsd__acl_aclcheck_fd(abi_long arg1, abi_long= arg2, + abi_ulong arg3) +{ + abi_long ret; + struct acl host_acl; + acl_type_t type; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + ret =3D t2h_freebsd_acl(&host_acl, arg3); + if (!is_error(ret)) { + ret =3D get_errno(__acl_aclcheck_fd(arg1, type, &host_acl)); + } + + return ret; +} + +/* __acl_aclcheck_file(const char *path, acl_type_t type, struct acl *aclp= ); */ +static inline abi_long do_freebsd__acl_aclcheck_file(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + struct acl host_acl; + acl_type_t type; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D t2h_freebsd_acl(&host_acl, arg3); + if (!is_error(ret)) { + ret =3D get_errno(__acl_aclcheck_file(path(p), type, &host_acl)); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* __acl_aclcheck_link(const char *path, acl_type_t type, struct acl *aclp= ); */ +static inline abi_long do_freebsd__acl_aclcheck_link(abi_ulong arg1, + abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + struct acl host_acl; + acl_type_t type; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D t2h_freebsd_acl(&host_acl, arg3); + if (!is_error(ret)) { + ret =3D get_errno(__acl_aclcheck_link(path(p), type, &host_acl)); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* int __acl_delete_fd(int filedes, acl_type_t type); */ +static inline abi_long do_freebsd__acl_delete_fd(abi_long arg1, abi_long a= rg2) +{ + abi_long ret; + acl_type_t type; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + return get_errno(__acl_delete_fd(arg1, type)); +} + +/* int __acl_delete_file(const char *path, acl_type_t type); */ +static inline abi_long do_freebsd__acl_delete_file(abi_ulong arg1, + abi_long arg2) +{ + abi_long ret; + void *p; + acl_type_t type; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(__acl_delete_file(path(p), type)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* int __acl_delete_link(const char *path, acl_type_t type); */ +static inline abi_long do_freebsd__acl_delete_link(abi_ulong arg1, + abi_long arg2) +{ + abi_long ret; + void *p; + acl_type_t type; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(__acl_delete_link(path(p), type)); + unlock_user(p, arg1, 0); + + return ret; +} + +/* int __acl_get_fd(int filedes, acl_type_t type, struct acl *aclp); */ +static inline abi_long do_freebsd__acl_get_fd(abi_long arg1, abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + acl_type_t type; + struct acl host_acl; + + memset(&host_acl, 0, sizeof(struct acl)); + host_acl.acl_maxcnt =3D ACL_MAX_ENTRIES; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + ret =3D get_errno(__acl_get_fd(arg1, type, &host_acl)); + if (!is_error(ret)) { + ret =3D h2t_freebsd_acl(arg3, &host_acl); + } + + return ret; +} + +/* __acl_get_file(const char *path, acl_type_t type, struct acl *aclp); */ +static inline abi_long do_freebsd__acl_get_file(abi_ulong arg1, abi_long a= rg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + acl_type_t type; + struct acl host_acl; + + memset(&host_acl, 0, sizeof(struct acl)); + host_acl.acl_maxcnt =3D ACL_MAX_ENTRIES; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(__acl_get_file(path(p), type, &host_acl)); + if (!is_error(ret)) { + ret =3D h2t_freebsd_acl(arg3, &host_acl); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* int __acl_get_link(const char *path, acl_type_t type, struct acl *aclp)= ; */ +static inline abi_long do_freebsd__acl_get_link(abi_ulong arg1, abi_long a= rg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + acl_type_t type; + struct acl host_acl; + + memset(&host_acl, 0, sizeof(struct acl)); + host_acl.acl_maxcnt =3D ACL_MAX_ENTRIES; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(__acl_get_link(path(p), type, &host_acl)); + if (!is_error(ret)) { + ret =3D h2t_freebsd_acl(arg3, &host_acl); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* int __acl_set_fd(int filedes, acl_type_t type, struct acl *aclp); */ +static inline abi_long do_freebsd__acl_set_fd(abi_long arg1, abi_long arg2, + abi_ulong arg3) +{ + abi_long ret; + acl_type_t type; + struct acl host_acl; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + ret =3D t2h_freebsd_acl(&host_acl, arg3); + if (!is_error(ret)) { + ret =3D get_errno(__acl_set_fd(arg1, type, &host_acl)); + } + + return ret; +} + +/* int __acl_set_file(const char *path, acl_type_t type, struct acl *aclp)= ; */ +static inline abi_long do_freebsd__acl_set_file(abi_ulong arg1, abi_long a= rg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + acl_type_t type; + struct acl host_acl; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D t2h_freebsd_acl(&host_acl, arg3); + if (!is_error(ret)) { + ret =3D get_errno(__acl_set_file(path(p), type, &host_acl)); + } + unlock_user(p, arg1, 0); + + return ret; +} + +/* int __acl_set_link(const char *path, acl_type_t type, struct acl *aclp)= ; */ +static inline abi_long do_freebsd__acl_set_link(abi_ulong arg1, abi_long a= rg2, + abi_ulong arg3) +{ + abi_long ret; + void *p; + acl_type_t type; + struct acl host_acl; + + ret =3D t2h_freebsd_acl_type(&type, arg2); + if (is_error(ret)) { + return ret; + } + p =3D lock_user_string(arg1); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D t2h_freebsd_acl(&host_acl, arg3); + if (!is_error(ret)) { + ret =3D get_errno(__acl_set_link(path(p), type, &host_acl)); + } + unlock_user(p, arg1, 0); + + return ret; +} =20 -#endif /* FREEBSD_OS_EXTATTR_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139856; cv=none; d=zohomail.com; s=zohoarc; b=oI/Cz59LAfxjJFDubc8rQoj886XedhCndiPnDz6mj3RpvjyT0BmzTRroQIfXo9AQ2k3QwVO283MWHqc3GZ74OkC4G+hXWBoLuFYO098I1AtQp7ocO0sqMkREkAc9FkmM90VhK6dB2/fGIOQ9oZaZhYGdI7KmDAAiNsnOqCLgIAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139856; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6BsiMsWnWcz0ZD7fdHEqgpW91pDlHqlwEAlWvdbmtTQ=; b=fPjomrdU/g9qCt9UrQYdYw+SwTVZx66Uoq2TsxEkPbt3/f1guCjzGUPWitcm1uTq7FfC2BF/BCHRcqxqp3uwQsZeV08H3CNdbucxm2yoswnq/PeUJD1M+TUTpzjxccjp3dXQVWGXpu9dfZPavVtGWPABzH0iSPlYBRc7i8TwcoE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177913985676267.4421558549086; Mon, 18 May 2026 14:30:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vq-0000jN-Mg; Mon, 18 May 2026 17:28:34 -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 1wP5Vl-0000Xb-7B for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:29 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vj-0000eH-BS for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:28 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-479eb8bcacbso1903192b6e.1 for ; Mon, 18 May 2026 14:28:26 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139706; x=1779744506; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6BsiMsWnWcz0ZD7fdHEqgpW91pDlHqlwEAlWvdbmtTQ=; b=WmDtAY7tmUFTiroWwModz6DYW0dFLV+k7mq07MsQQgHDn08SzENgsTWZr7Bmld2wyd jpectl/PfTpOuZy6P4nRxi/TffJ2mM6FBazewSrmXbNJ+PVAzGO2jnkHchl0rWARUupP ArsjkfJCU6nZtINF0lDKeIto+rpmhEarrsalOk7WEflvYWNkb7iK+23KYvFsaX/3IcnW F13vr1H4pK/N6N2pNZ6GLn0kivJnXNNTHgUC6LzkY5t5lGUlBnJGMalQUu2Vqhv7EncR 79XpMDe9EmosDMJguw3CPZb9vWgZhsHzFAS4ZCtZdT6bZ+TlL5F7qjpSAIieVjpG4o+o fq5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139706; x=1779744506; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=6BsiMsWnWcz0ZD7fdHEqgpW91pDlHqlwEAlWvdbmtTQ=; b=fsnJ+hV/71BiCemWFosqzY0CJDxO4i1dfz8HXrfI+d42ZQvam12d+ueN7zN8s8nSNu rlQdxaYFIZOhBexPp9fZ/SyFL6biDIqXrOS61D1tdKYoM/UpyFnIGCxS3xDVCWVz2kwc MmflZo0/Y+IyLJpsgsJNJ+E7GUFN/DfZCLINo2YKXEo7Imtgcnuku2Qp3Lw2wSrBoLi0 Epbbg+yXgL+yuash7z/lK8EKAMtp5z1iDKKQFHWDVieKiMUd9TdXNwCxoazGz4SS5z1z JqIAK0T3ZT1nBynPy+jMo9oJ4g1wuF6oM3L7tPqel7KNZpOT+kWncv/UAQxrItLX3OjY 6G+w== X-Gm-Message-State: AOJu0YxK5vT0QOZ8vROOJnjB49z1QFMAXC83l2rcD2Ee2GPRv+md1zBo C8PaNgnhARYa0TuVj+oY4MphlBE3AJhzhVxjIHWC/LOeT1qjZ/1CfBoaMohhC5awhH6lYpeJQKu UksHsbGM= X-Gm-Gg: Acq92OFdbFITeHgRlkenbvzCSJpIKsfAbkNtmTjypRNNikbPhX0etJxWmENqeUNdxU4 q/k0rLEVpjV75TlGIfPMl40aJtEFZkd6auQsGJxLzgyKNvYrkv2gQgleH/YQagKC7CZMx4Ub0H+ i87EpxJhe3DRy8aEQlatmd10GggUFVzf4/oxg7x7xSpQi8PsyuUqFPckArckDTQTiyHRKPn0Pxn XlPkI5HOJFHjkYwO+Mos7IA6iQR6VCX+K4G/r4Xz31pzXQLl5hHfUnz5bbDKd3O7rHyQLxE9Ujb vhSzU7v5IlbuFKfMFjcUmOzom2z0piaRnS+Be9haDq3FExsBXsKiOfBfXTKZjQU01Z5zzX6yLC4 41jC1YMXfTMk9rhV3N0OaIzcihrRIq3o92EGx6ybMJsKMjT07vcbrqosRAynMeqWkp7E5jwM/ll 8XdYm2HKkPpA== X-Received: by 2002:a05:6808:5282:b0:479:d16e:9629 with SMTP id 5614622812f47-482e56ea6f3mr11772616b6e.21.1779139706088; Mon, 18 May 2026 14:28:26 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:51 -0600 Subject: [PATCH v2 33/37] bsd-user: Add os-extattr.c with ACL conversion functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-33-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4778; i=imp@bsdimp.com; h=from:subject:message-id; bh=xbLf/gX+EPcfRk77GR+uzvmVg3QKmNFciyS2O2arL5c=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJnG5tw0B8UWEUi+rhwIn9dlBatkzMZaTiW VZYohXh/S2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR AFN2EAClTyeyrDUqrC+BdEgRlQpLsIE9BiGMWzlMb6atthr9VBvskFUnXs20kYGJAzckG9IvLKZ FBj+ofCgX8GYK4vknn5BC67o9DC0BElhy/iARIiq5BoNBktgpPDAn0ZF39DDBtIsqgkXMrbdHgC WwPU8MQFY1d+/QkRZfMVc4fzwbN43MRrkUpmnioY0o+1fo0XfP/hfFgXUjakMZ66LGoJOaUDYB+ upe0986XgGu4tbolKtzOv0Q6A6fIiB3B6u8pg4DenyDzaKhOSRd7lvOQ4BPEIK4FRq6CNWk2x+1 6pNNpkqtNTfozIekL2aXGKNaKNtwx4rtqe1MTSqacVKcLlunnpw3yokTDiNyCjMaWvztpEgz7TZ MOXdd/wp0jeeT9IwsB4iJk7iDiGEddyymeglu9C2alcVeVpBXxwwMKHWpyuSZtZOB9DuNrC8A+5 WFFzxnTDJbqBZP45O5BZ/TI4a4JImpW4RzUSIitckY/JdOHe84z8BMi+h8uKyfTkRne5mEWOCGa bckBlb/WBH7GrbP4nMjQruMQI5hzLusHHWh0bEVcCLNShwCjYir6VLkEt9Tr3ZHdKQrtXYltAk7 LhOFfFtzI0YZf7+QHeGVB9Zot6iHHS6xWOVb5PWX6ePBrdxswpyNwP6Hs2tr5XGnF1PkwONygrb eQxR6v5E1oMT4KA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::22a; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22a.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139858561154100 Add os-extattr.c with t2h_freebsd_acl, h2t_freebsd_acl, and t2h_freebsd_acl_type helper functions for ACL operations. Add os-extattr.c to the build and include os-extattr.h in the syscall dispatcher. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-extattr.c | 116 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 2 + 2 files changed, 118 insertions(+) diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c new file mode 100644 index 0000000000..0f0c7123dd --- /dev/null +++ b/bsd-user/freebsd/os-extattr.c @@ -0,0 +1,116 @@ +/* + * FreeBSD extend attributes and ACL conversions + * + * Copyright (c) 2013 Stacey D. Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" + +#ifndef _ACL_PRIVATE +#define _ACL_PRIVATE +#endif +#include + +#include "qemu.h" +#include "qemu-os.h" + +/* + * FreeBSD ACL conversion. + */ +abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr) +{ + uint32_t i; + struct target_freebsd_acl *target_acl; + + if (!lock_user_struct(VERIFY_READ, target_acl, target_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_acl->acl_maxcnt, &target_acl->acl_maxcnt); + __get_user(host_acl->acl_cnt, &target_acl->acl_cnt); + + if (host_acl->acl_maxcnt > ACL_MAX_ENTRIES) { + unlock_user_struct(target_acl, target_addr, 0); + return -TARGET_EINVAL; + } + + for (i =3D 0; i < host_acl->acl_maxcnt; i++) { + __get_user(host_acl->acl_entry[i].ae_tag, + &target_acl->acl_entry[i].ae_tag); + __get_user(host_acl->acl_entry[i].ae_id, + &target_acl->acl_entry[i].ae_id); + __get_user(host_acl->acl_entry[i].ae_perm, + &target_acl->acl_entry[i].ae_perm); + __get_user(host_acl->acl_entry[i].ae_entry_type, + &target_acl->acl_entry[i].ae_entry_type); + __get_user(host_acl->acl_entry[i].ae_flags, + &target_acl->acl_entry[i].ae_flags); + } + + unlock_user_struct(target_acl, target_addr, 0); + return 0; +} + +abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl) +{ + uint32_t i; + struct target_freebsd_acl *target_acl; + + if (host_acl->acl_maxcnt > ACL_MAX_ENTRIES) { + return -TARGET_EINVAL; + } + + if (!lock_user_struct(VERIFY_WRITE, target_acl, target_addr, 0)) { + return -TARGET_EFAULT; + } + + __put_user(host_acl->acl_maxcnt, &target_acl->acl_maxcnt); + __put_user(host_acl->acl_cnt, &target_acl->acl_cnt); + + for (i =3D 0; i < host_acl->acl_maxcnt; i++) { + __put_user(host_acl->acl_entry[i].ae_tag, + &target_acl->acl_entry[i].ae_tag); + __put_user(host_acl->acl_entry[i].ae_id, + &target_acl->acl_entry[i].ae_id); + __put_user(host_acl->acl_entry[i].ae_perm, + &target_acl->acl_entry[i].ae_perm); + __put_user(host_acl->acl_entry[i].ae_entry_type, + &target_acl->acl_entry[i].ae_entry_type); + __put_user(host_acl->acl_entry[i].ae_flags, + &target_acl->acl_entry[i].ae_flags); + } + + unlock_user_struct(target_acl, target_addr, 1); + return 0; +} + +abi_long t2h_freebsd_acl_type(acl_type_t *host_type, abi_long target_type) +{ + + switch (target_type) { + case TARGET_FREEBSD_ACL_TYPE_ACCESS_OLD: + *host_type =3D ACL_TYPE_ACCESS_OLD; + break; + + case TARGET_FREEBSD_ACL_TYPE_DEFAULT_OLD: + *host_type =3D ACL_TYPE_DEFAULT_OLD; + break; + + case TARGET_FREEBSD_ACL_TYPE_ACCESS: + *host_type =3D ACL_TYPE_ACCESS; + break; + + case TARGET_FREEBSD_ACL_TYPE_DEFAULT: + *host_type =3D ACL_TYPE_DEFAULT; + break; + + case TARGET_FREEBSD_ACL_TYPE_NFS4: + *host_type =3D ACL_TYPE_NFS4; + break; + + default: + return -TARGET_EINVAL; + } + return 0; +} + diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 0c729da0ab..f385034a53 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -17,6 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ +#define _ACL_PRIVATE #include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/path.h" @@ -43,6 +44,7 @@ #include "bsd-socket.h" =20 /* BSD dependent syscall shims */ +#include "os-extattr.h" #include "os-stat.h" #include "os-proc.h" #include "os-signal.h" --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139911; cv=none; d=zohomail.com; s=zohoarc; b=FE16Wv6D2WrAQqU7O1nYFcs3KzZNqMO0YKG9SCl8O0pDiEyaIxU//C6U0+zqen4+BhQ7qHimDtuKUwVaxD6MPdOfZGy6sdu2i/c2nx3sIL98QuSXiqZ5xiAeOS1eJpvO2dtWSo0y7HhAu7p2RC0KxM+xdFLqED0d/qIlLhYgymo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139911; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sSzVC6h9YW49+ZfM5l/6+Z7F9FLLQN1G4shYKdPjNRs=; b=BMly00YR18y9XcofjNvUgFfSyEfCdn6/huTS5akV+tYksHvQyMzCXg+GfY+XM2+naGox9uRfMzFTPs7ZVelEXvEtMmwPS5dq6CP6+bL3+RfEbp1IL6kPRcF5BqCftHM7y9KiMzzt+GzXi0S22zGl8+N85WfX4dL3osjthxruGv0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139911924156.74906440984796; Mon, 18 May 2026 14:31:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vr-0000kO-7L; Mon, 18 May 2026 17:28:35 -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 1wP5Vm-0000Xu-5p for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:30 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vk-0000ff-Hd for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:29 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7e582b3bcaaso2129121a34.3 for ; Mon, 18 May 2026 14:28:27 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139707; x=1779744507; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sSzVC6h9YW49+ZfM5l/6+Z7F9FLLQN1G4shYKdPjNRs=; b=UmWmteDHRzTiIMdZGishd7CkL/t6qlbIWeyOrOH5z2hQOJxi/ff9SBTcADqQsWdnrF Citl8o20cD3ay9EfqN4NH0aw8u0URaGzt+Xu5jgDylIoF6Y17ActLQ3d8ym2wUS8PuSu V2ZiHFyMvpZ1t9SVzV4TiPZmdxxJvlDk/lOPgv1wzbkNcV0hNNKAEaeoq37FBbUhnH7d qx3R9U+QxilTr21nEp9J7lmWFQpMk1ZY93gkVpAR+BMbmIq9ztEIuNS4Ow0FJEIT9A7l JUPy+KNjWUimN2vZGnmQrdTF1yFAAHOPG255jH9uvpdY3/iAcQSQIyIdT54OGZvnKdq8 t2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139707; x=1779744507; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sSzVC6h9YW49+ZfM5l/6+Z7F9FLLQN1G4shYKdPjNRs=; b=Tjy8s42/rQ7fyCu73a1wb78bgDd/qNxAEVhnX/gDl6GMEO2MRi2ZzIzcuSl+XV/jSW RFlnk88SbPDzLSI9J2nERJ29bqOEMID+KTpS9a5l67OncPgsCbdtjXtA+gQ0f12nuiwy IRNhi8PDORSnmNd7Nms+lClVZ8lHGVshJ7AYuz354dyR3rqkRvQ0IWvuPsy98EiOTY/G mK34ibsXx2Fs6EQwnsgsj+a8jPEiEczgDtRHLmtVoE8945PMeAnkfepxm1mjRaIytLBa A3chT/6492qsdnjdedsfd7+HDwEp562tYXkB/sEtFZ30nyWD6x8jVNHZv/sg91I2hJs0 Y9sQ== X-Gm-Message-State: AOJu0YxpDFSgiVyDfXguE9armOB66alrvhF9ecrDwoiPd2vPeF1JHnEy uxd5TxLFW/vdDAVtQRUopuYmr6NbeDYeGXx35TMy+5QAmZdxstcZzpyLwWhgsKp3+1A= X-Gm-Gg: Acq92OHBJo8rC6k4s/odPJqZEGruq3ToCxSmgral8tC0ItwOT/RLHtqDNj3M5qldjZK o/UZ0ObM+5WoZ4TzZ5OQwJIXKJ0jLcAO/gTQIXGcaZRbpHuRYcHb9fPbdtI3/eXY/JfkE81/G6O CMymruGfiT2YuMVTefVcjWdXwueTLt90GRvjrz8IoX9Syy/T5vrALFSbLUrJcNwg7exCYPwC1Do trhYLe0g3XCtb8IJ8v4OpI0obH0YT0oH3RAnvKRK2GCn9yEMFe0E0SRriKWuqxhycNcdV/jztyF QEJvtV8dIQUdUTdGvs347e82/yHtrYutONQt3isXLCvVPAynU0gtgEQWaEBLOQZDjcfKpWz8mi5 kWDVhCh8+R2a5TVErPnKw6kaTZH+qbxMHuDIDu/P181I1N5RrhIhNVLKDbuunCPy60zK8/byTIj kqDmwRBlPqRjEBZxinVcng X-Received: by 2002:a05:6830:4387:b0:7dc:db3c:1d82 with SMTP id 46e09a7af769-7e4ea17e2dbmr13699259a34.10.1779139706828; Mon, 18 May 2026 14:28:26 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:52 -0600 Subject: [PATCH v2 34/37] bsd-user: Add extended attribute and ACL system call dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-34-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5002; i=imp@bsdimp.com; h=from:subject:message-id; bh=hz3iLr6GJQnPMw6JXtduOv2rNv9Bqx6Ov86pywyJ/KM=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJbbs6F8VFZyi4Y2XK+weRMj0zBYN5ZriiA XMaZ+cdMg2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR AB55D/9elkp97qRuCGzw3VcJFZS9mpB2KO4H//7ypoBznkmCTbi0xzjrlUlvA6IFQFk/X9LAOIq XokuK7nDt7MJRhtK2VOQfEi8HWV2GHQBdve5Zhtn5d5fvO7YQHCualMxMTRrLO9kw1pLSqzOJHS e3S2DNn3QWvDYjPXLyYpQOHkpMQdKhkA/rG7UbGSW20LTLXgRnlwzJIZjQMD+ksoi2cR7QVMtlR miig4tAOVTUaOF+cHr+lB38BXPsfvfPivI3I4wD/IDbvgRnDuBjhOlpTw3wCtSogbLO4tWRNS3u hM0EhEuid5CnTFtCm+68oCeLFbjeDT2TU1nrtBWyxRCt5XtZ7AGaPms8zlOWEHy8dhKnnk2Sz3q lulXldagDzIFrPSLAtlKazbJ0bzKHvE+25ZqC3c1Z7B48A4cdfS6YP5LoSwD4+xMyZhXZlEOCNM 3jeVclHYEYyrNwTjwvenZeB9z4cSGHbvkUElRPNFf3OGFx8LLpBRqYnrOgZ+as5rzj/Nwe9uUqC /hsQQpGSa4Xxnnz7CvLfuVooeAtX1nKFb/L9GYzLUfr8XgT+dMDtZGItxhVO+6ggdp6pVCS/rbM /x2xnWN/ocT60EtS6jMhkqdH94NGXx5ZfNV+XzS7W0uJhezkI6WO6xtHTjyi7a8eVyNwek1vTrF MVAns2hVZCu5btg== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::332; envelope-from=imp@bsdimp.com; helo=mail-ot1-x332.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139912898158500 Wire up extended attribute and ACL system calls: extattrctl, extattr_set/get/delete for file, fd, and link variants, extattr_list for fd, file, and link, and all __acl_* operations (aclcheck, delete, get, set for fd, file, and link). Signed-off-by: Stacey Son Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-syscall.c | 103 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 103 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index f385034a53..7825e042b0 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -1365,6 +1365,109 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, ret =3D do_freebsd_sysarch(env, arg1, arg2); break; =20 + /* + * extended attributes and ACL system calls + */ + case TARGET_FREEBSD_NR_extattrctl: /* extattrctl() */ + ret =3D do_freebsd_extattrctl(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_extattr_set_file: /* extattr_set_file(2) */ + ret =3D do_freebsd_extattr_set_file(arg1, arg2, arg3, arg4, arg4); + break; + + case TARGET_FREEBSD_NR_extattr_get_file: /* extattr_get_file(2) */ + ret =3D do_freebsd_extattr_get_file(arg1, arg2, arg3, arg4, arg4); + break; + + case TARGET_FREEBSD_NR_extattr_delete_file: /* extattr_delete_file(2) = */ + ret =3D do_freebsd_extattr_delete_file(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_extattr_set_fd: /* extattr_set_fd(2) */ + ret =3D do_freebsd_extattr_set_fd(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_extattr_get_fd: /* extattr_get_fd(2) */ + ret =3D do_freebsd_extattr_get_fd(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_extattr_delete_fd: /* extattr_delete_fd(2) */ + ret =3D do_freebsd_extattr_delete_fd(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_extattr_get_link: /* extattr_get_link(2) */ + ret =3D do_freebsd_extattr_get_link(arg1, arg2, arg3, arg4, arg4); + break; + + case TARGET_FREEBSD_NR_extattr_set_link: /* extattr_set_link(2) */ + ret =3D do_freebsd_extattr_set_link(arg1, arg2, arg3, arg4, arg4); + break; + + case TARGET_FREEBSD_NR_extattr_delete_link: /* extattr_delete_link(2) = */ + ret =3D do_freebsd_extattr_delete_link(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_extattr_list_fd: /* extattr_list_fd(2) */ + ret =3D do_freebsd_extattr_list_fd(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_extattr_list_file: /* extattr_list_file(2) */ + ret =3D do_freebsd_extattr_list_file(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_extattr_list_link: /* extattr_list_link(2) */ + ret =3D do_freebsd_extattr_list_link(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR___acl_aclcheck_fd: /* __acl_aclcheck_fd() */ + ret =3D do_freebsd__acl_aclcheck_fd(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_aclcheck_file: /* __acl_aclcheck_file() */ + ret =3D do_freebsd__acl_aclcheck_file(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_aclcheck_link: /* __acl_aclcheck_link() */ + ret =3D do_freebsd__acl_aclcheck_link(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_delete_fd: /* __acl_delete_fd() */ + ret =3D do_freebsd__acl_delete_fd(arg1, arg2); + break; + + case TARGET_FREEBSD_NR___acl_delete_file: /* __acl_delete_file() */ + ret =3D do_freebsd__acl_delete_file(arg1, arg2); + break; + + case TARGET_FREEBSD_NR___acl_delete_link: /* __acl_delete_link() */ + ret =3D do_freebsd__acl_delete_link(arg1, arg2); + break; + + case TARGET_FREEBSD_NR___acl_get_fd: /* __acl_get_fd() */ + ret =3D do_freebsd__acl_get_fd(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_get_file: /* __acl_get_file() */ + ret =3D do_freebsd__acl_get_file(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_get_link: /* __acl_get_link() */ + ret =3D do_freebsd__acl_get_link(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_set_fd: /* __acl_get_fd() */ + ret =3D do_freebsd__acl_set_fd(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_set_file: /* __acl_set_file() */ + ret =3D do_freebsd__acl_set_file(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___acl_set_link: /* __acl_set_link() */ + ret =3D do_freebsd__acl_set_link(arg1, arg2, arg3); + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret =3D -TARGET_ENOSYS; --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139921; cv=none; d=zohomail.com; s=zohoarc; b=G0nki0fXlldhjW8VoYEK5WaYwN507rNEvDCu2Eu8pGixqVuqoeFmkpYPnZw07QmN6HOGeZyRirtYWx/ajdN8QkvT5kmDr9bHrp+w8E6BIPQAWcIKr0zZUGMIafT7A+sb+rMWS6UnzKRtsBn/Y9ojdfx1C02Uwlr+tI91Qrtevfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139921; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Dk/gcJTcR+HqotYXXre567+adU5e8XCaDOO7/5sPCWw=; b=VL5ts5Ytb0QdH7cEGicnZUXttavQlCLxFbpWogqb+7+yWkGkOkcRQSDkUOU/QOB9GMmHtQGVXCUggz+1JAPBgVHbqrht57YOEPxEhzRorTdiTaexYMscJ0wf61xMoOsRyBw8wN2SIfRRunlPe/uFgyNNOjIzWrqTytzZIhDof/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139921762368.07356685684726; Mon, 18 May 2026 14:32:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vs-0000mH-Na; Mon, 18 May 2026 17:28:36 -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 1wP5Vm-0000YO-Ua for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:32 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vk-0000hX-Tj for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:30 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7e36bb16a92so1712596a34.2 for ; Mon, 18 May 2026 14:28:28 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139708; x=1779744508; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Dk/gcJTcR+HqotYXXre567+adU5e8XCaDOO7/5sPCWw=; b=hjfDy+ukXnxul+bMuKYCWffdotVaDf6RtWZIHDbI3+A8rlsc6Y+Txuo5SHzmfQTpPx ByRwg/BMgS9S1dUIaHR/hqZlQ4DuhDJPjrn+NRIJpxM+6Em2tmusqdxdAIHd+8msdKl+ XH6e6tVbG+wHo/LpJo7B5POW1s4/YK9argKTPw5FGik9Yems8ePxCsxXyvHB0/DGgRpo UCj39bmml87P96TBMsGVwsUh19Jj0dWh6+S/vuzx4TAM+h5bmFxx+xQGr8+V5ipKoG9i WCEVbtavqYioutr2FazG5ec4tD0ryyV06lLrnPyv2uy6e+Caj5sNEPJStrwbqoc9xyQv Zcnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139708; x=1779744508; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Dk/gcJTcR+HqotYXXre567+adU5e8XCaDOO7/5sPCWw=; b=eF8ZJmmx38Dx/n3sFNv4TQR7W/fsnjRYxB2UtLTG9oOOrj7KTPQSamAzqRWF2HbOXn tLlwGenWtQTWRbc3kDUZa/RrF8GHH2jgNV6uBuRrhj9Hwf8lG8z83pgBAW7iOhBMV/6l /0Dorcn7PM9laUyCtQQGqFoTJdGA67rGAYtzt+HE/D5eF0stTF7SzFZOXjbYFWBBBwFx 87WKkTLP8Sc9gOg+9ukrWzFze4FmgDbsuNO8Xa2cqNjiYKWf/p77flJVC0/QO3A1Z32j h9dUhD33MHE4eu82Z3ESUr2nzJ0XNS4mMSYUuoPoW2zIMUUaGu22Fst4UiVixMV4ILdD Dlsg== X-Gm-Message-State: AOJu0Yw2242gwOcqZJ/P+amrECeGwWB9ub927Dy3RXQkTTHHW7FBoFiZ reZe8uj/wJt9bkzcrRlMIPcygHZ/T+9tMhkfoKKurSIQGh9i7amJIidj7WIRBnkv92s= X-Gm-Gg: Acq92OGMYImwYgsMik64LtgBFbvrlIUvRioZ/JTpKbs7CNMQNKRwUL+NSx9LXb0p3p+ 66a4GswVMj1xyZVewpFUfD3sT8TfK1E4eAHa1XrZdK4yrRhhH/KJk96+qm5Eus4Yx8V8UCFzdGC lwcuYoBv1iAmB7vg5QZwusZgOaVhIJ9Hg2kS7SfADh9wXGmn4wBXa7KLLW0pTfDJEjTvxJRI1Gx pkCrbsCEME7S9NazcY2NCOjBuqvCIWkYYO3iobj48eQZLIfkFh5MB2R8u6Ho6T+6faxs2xxrGR0 muCNsrXtuCGcYBkEeftAH0Wq31/eAOMxdV9IIdmPpb8o517fBe51r4w4FYeKWoa2HTZ4j8l+Obh rH/nGAuamjjGkMkZXe5MvQWB6FZoocDz8S+poh03WSWcTJ63XTY2KFUHKw2uWDTPAXovy63yxHO NSmAl5nJy6oA== X-Received: by 2002:a05:6830:4486:b0:7d7:f638:7a03 with SMTP id 46e09a7af769-7e4ea07fd2bmr13318626a34.10.1779139707825; Mon, 18 May 2026 14:28:27 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:53 -0600 Subject: [PATCH v2 35/37] bsd-user: Add scheduler and cpuset functions to os-misc.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-35-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Sean Bruno , =?utf-8?q?Mika=C3=ABl_Urankar?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=11338; i=imp@bsdimp.com; h=from:subject:message-id; bh=VJLI5yf/kV1K/lBJ1hjwgi5j2yWe3Wg0MdjyGKt/tVc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJbLhq5nA+nbNGVfUyudY3q9nuvkGQSdjIJ fAofqUhnxCJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR APH5EACKR6eWJtotiEjl9iUuDyOWWspUpXJyK9P8sbGxA05a8SikFRNtcU8Ux/qWMR399ck7VPY UUT9F9/4qvm7ov/FpRJFG0NaxsRSOoZ7i4hFfD4mD4Qh8jMYWL7W0hL7Y5LBMOnhNBe0/8vWYOL ZUMnCVbeh01T95elBhiZlphU0VBweeemLv26W9RuaJhEJr5d8/Kj85qau5oKwoCHQjFoxlqbvlr ltF0uUkoNbey4rUjGJSx7TuCIBSVSNHoc9wOdbJfKmj7YNSJFP15y4qyCUyCxEDOnoxdidHQY7f wMcTLdM8XTKHzIFCJ9l4NrE/fjv1eT5pLuYSJCepavak8eTHHstNZBhl2i4fvuQmUMHkMPdgwFP Kp255VYcvoiVxALPg0DmB0HXcn956cf1sLv61/k3GCrqUmtswYDi/0yqHSuye4L1Bjhk06fsEAk rtbUVoIenYuXy+9esbDQPi423BedLDnyTAxxPAFcz3aTYoyoUyuDfLUaphmU1HFhtDmFYphq0k3 p1acWJH2bgl64Vj5CbPEcbhj3YL3dYM4IRPu+9sTqofT8HBOIk3SLlYCVHhWRd2LkPENjAdkhgV D7PytXSCfm2edXQLaeH4psAT2/cLs9nzLfk/SC98ph0Z4mrpNM6U9KubsXt594IUc2Ee0u49tsH c0ftXvHWcqbJSUQ== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::332; envelope-from=imp@bsdimp.com; helo=mail-ot1-x332.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139923810154100 Expand os-misc.h with scheduler functions (sched_setparam, sched_getparam, sched_setscheduler, sched_getscheduler, sched_rr_get_interval) and CPU affinity functions (cpuset, cpuset_setid, cpuset_getid, cpuset_getaffinity, cpuset_setaffinity). Also add sched_yield, sched_get_priority_min, and sched_get_priority_max to bsd-proc.h. Signed-off-by: Stacey Son Signed-off-by: Sean Bruno Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/bsd-proc.h | 20 +++- bsd-user/freebsd/os-misc.h | 288 +++++++++++++++++++++++++++++++++++++----= ---- 2 files changed, 257 insertions(+), 51 deletions(-) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 62052c70b9..b9973dbedf 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -400,4 +400,22 @@ static inline abi_long do_bsd_setpriority(abi_long whi= ch, abi_long who, return get_errno(setpriority(which, who, prio)); } =20 -#endif /* !BSD_PROC_H_ */ +/* sched_yield(2) */ +static inline abi_long do_bsd_sched_yield(void) +{ + return get_errno(sched_yield()); +} + +/* sched_get_priority_min(2) */ +static inline abi_long do_bsd_sched_get_priority_min(int policy) +{ + return get_errno(sched_get_priority_min(policy)); +} + +/* sched_get_priority_max(2) */ +static inline abi_long do_bsd_sched_get_priority_max(int policy) +{ + return get_errno(sched_get_priority_max(policy)); +} + +#endif /* !BSD_PROC_H */ diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index d9979b2a8b..74ed1d2f47 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -11,76 +11,264 @@ #include #include #include +#include =20 -/* - * shm_open2 isn't exported, but the __sys_ alias is. We can use either fo= r the - * static version, but to dynamically link we have to use the sys version. - */ -int __sys_shm_open2(const char *path, int flags, mode_t mode, int shmflags, +int shm_open2(const char *path, int flags, mode_t mode, int shmflags, const char *); =20 -#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1300048 -/* shm_open2(2) */ -static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong f= lags, - abi_long mode, abi_ulong shmflags, abi_ulong nameptr) +/* sched_setparam(2) */ +static inline abi_long do_freebsd_sched_setparam(pid_t pid, + abi_ulong target_sp_addr) { - int ret; - void *uname, *upath; + abi_long ret; + struct sched_param host_sp; =20 - if (pathptr =3D=3D (uintptr_t)SHM_ANON) { - upath =3D SHM_ANON; - } else { - upath =3D lock_user_string(pathptr); - if (upath =3D=3D NULL) { - return -TARGET_EFAULT; - } + ret =3D get_user_s32(host_sp.sched_priority, target_sp_addr); + if (!is_error(ret)) { + ret =3D get_errno(sched_setparam(pid, &host_sp)); } + return ret; +} =20 - uname =3D NULL; - if (nameptr !=3D 0) { - uname =3D lock_user_string(nameptr); - if (uname =3D=3D NULL) { - unlock_user(upath, pathptr, 0); - return -TARGET_EFAULT; - } +/* sched_get_param(2) */ +static inline abi_long do_freebsd_sched_getparam(pid_t pid, + abi_ulong target_sp_addr) +{ + abi_long ret; + struct sched_param host_sp; + + ret =3D get_errno(sched_getparam(pid, &host_sp)); + if (!is_error(ret)) { + ret =3D put_user_s32(host_sp.sched_priority, target_sp_addr); } - ret =3D get_errno(__sys_shm_open2(upath, - target_to_host_bitmask(flags, fcntl_flags_tbl), mode, - target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname= )); + return ret; +} + +/* sched_setscheduler(2) */ +static inline abi_long do_freebsd_sched_setscheduler(pid_t pid, int policy, + abi_ulong target_sp_addr) +{ + abi_long ret; + struct sched_param host_sp; =20 - if (upath !=3D SHM_ANON) { - unlock_user(upath, pathptr, 0); + ret =3D get_user_s32(host_sp.sched_priority, target_sp_addr); + if (!is_error(ret)) { + ret =3D get_errno(sched_setscheduler(pid, policy, &host_sp)); } - if (uname !=3D NULL) { - unlock_user(uname, nameptr, 0); + return ret; +} + +/* sched_getscheduler(2) */ +static inline abi_long do_freebsd_sched_getscheduler(pid_t pid) +{ + + return get_errno(sched_getscheduler(pid)); +} + +/* sched_getscheduler(2) */ +static inline abi_long do_freebsd_sched_rr_get_interval(pid_t pid, + abi_ulong target_ts_addr) +{ + abi_long ret; + struct timespec host_ts; + + ret =3D get_errno(sched_rr_get_interval(pid, &host_ts)); + if (!is_error(ret)) { + ret =3D h2t_freebsd_timespec(target_ts_addr, &host_ts); } return ret; } -#endif /* __FreeBSD_version >=3D 1300048 */ =20 -#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1300049 -/* shm_rename(2) */ -static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong = toptr, - abi_ulong flags) +/* cpuset(2) */ +static inline abi_long do_freebsd_cpuset(abi_ulong target_cpuid) { - int ret; - void *ufrom, *uto; + abi_long ret; + cpusetid_t setid; =20 - ufrom =3D lock_user_string(fromptr); - if (ufrom =3D=3D NULL) { - return -TARGET_EFAULT; + ret =3D get_errno(cpuset(&setid)); + if (is_error(ret)) { + return ret; } - uto =3D lock_user_string(toptr); - if (uto =3D=3D NULL) { - unlock_user(ufrom, fromptr, 0); - return -TARGET_EFAULT; + return put_user_s32(setid, target_cpuid); +} + +#define target_to_host_cpuset_which(hp, t) { \ + (*hp) =3D t; \ +} while (0) + +#define target_to_host_cpuset_level(hp, t) { \ + (*hp) =3D t; \ +} while (0) + +/* cpuset_setid(2) */ +static inline abi_long do_freebsd_cpuset_setid(CPUArchState *env, abi_long= arg1, + abi_ulong arg2, abi_ulong arg3, abi_ulong arg4, abi_ulong arg5) +{ + id_t id; /* 64-bit value */ + cpusetid_t setid; + cpuwhich_t which; + + target_to_host_cpuset_which(&which, arg1); +#if TARGET_ABI_BITS =3D=3D 32 + /* See if we need to align the register pairs */ + if (regpairs_aligned(env)) { + id =3D target_arg64(arg3, arg4); + setid =3D arg5; + } else { + id =3D target_arg64(arg2, arg3); + setid =3D arg4; } - ret =3D get_errno(shm_rename(ufrom, uto, flags)); - unlock_user(ufrom, fromptr, 0); - unlock_user(uto, toptr, 0); +#else + id =3D arg2; + setid =3D arg3; +#endif + return get_errno(cpuset_setid(which, id, setid)); +} + +/* cpuset_getid(2) */ +static inline abi_long do_freebsd_cpuset_getid(abi_long arg1, abi_ulong ar= g2, + abi_ulong arg3, abi_ulong arg4, abi_ulong arg5) +{ + abi_long ret; + id_t id; /* 64-bit value */ + cpusetid_t setid; + cpuwhich_t which; + cpulevel_t level; + abi_ulong target_setid; + + target_to_host_cpuset_which(&which, arg1) + ; + target_to_host_cpuset_level(&level, arg2); +#if TARGET_ABI_BITS =3D=3D 32 + id =3D target_arg64(arg3, arg4); + target_setid =3D arg5; +#else + id =3D arg3; + target_setid =3D arg4; +#endif + ret =3D get_errno(cpuset_getid(level, which, id, &setid)); + if (is_error(ret)) { + return ret; + } + return put_user_s32(setid, target_setid); +} + +static abi_ulong copy_from_user_cpuset_mask(cpuset_t *mask, + abi_ulong target_mask_addr) +{ + int i, j, k; + abi_ulong b, *target_mask; + + target_mask =3D lock_user(VERIFY_READ, target_mask_addr, + CPU_SETSIZE / 8, 1); + if (target_mask =3D=3D NULL) { + return -TARGET_EFAULT; + } + CPU_ZERO(mask); + k =3D 0; + for (i =3D 0; i < ((CPU_SETSIZE / 8) / sizeof(abi_ulong)); i++) { + __get_user(b, &target_mask[i]); + for (j =3D 0; j < TARGET_ABI_BITS; j++) { + if ((b >> j) & 1) { + CPU_SET(k, mask); + } + k++; + } + } + unlock_user(target_mask, target_mask_addr, 0); + + return 0; +} + +static abi_ulong copy_to_user_cpuset_mask(abi_ulong target_mask_addr, + cpuset_t *mask) +{ + int i, j, k; + abi_ulong b, *target_mask; + + target_mask =3D lock_user(VERIFY_WRITE, target_mask_addr, + CPU_SETSIZE / 8, 0); + if (target_mask =3D=3D NULL) { + return -TARGET_EFAULT; + } + k =3D 0; + for (i =3D 0; i < ((CPU_SETSIZE / 8) / sizeof(abi_ulong)); i++) { + b =3D 0; + for (j =3D 0; j < TARGET_ABI_BITS; j++) { + b |=3D ((CPU_ISSET(k, mask) !=3D 0) << j); + k++; + } + __put_user(b, &target_mask[i]); + } + unlock_user(target_mask, target_mask_addr, (CPU_SETSIZE / 8)); + + return 0; +} + +/* cpuset_getaffinity(2) */ +/* cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t *); */ +static inline abi_long do_freebsd_cpuset_getaffinity(cpulevel_t level, + cpuwhich_t which, abi_ulong arg3, abi_ulong arg4, abi_ulong arg5, + abi_ulong arg6) +{ + cpuset_t mask; + abi_long ret; + id_t id; /* 64-bit */ + abi_ulong setsize, target_mask; + +#if TARGET_ABI_BITS =3D=3D 32 + id =3D (id_t)target_arg64(arg3, arg4); + setsize =3D arg5; + target_mask =3D arg6; +#else + id =3D (id_t)arg3; + setsize =3D arg4; + target_mask =3D arg5; +#endif + + ret =3D get_errno(cpuset_getaffinity(level, which, id, setsize, &m= ask)); + if (ret =3D=3D 0) { + ret =3D copy_to_user_cpuset_mask(target_mask, &mask); + } =20 return ret; } -#endif /* __FreeBSD_version >=3D 1300049 */ + +/* cpuset_setaffinity(2) */ +/* cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const cpuset_t= *);*/ +static inline abi_long do_freebsd_cpuset_setaffinity(cpulevel_t level, + cpuwhich_t which, abi_ulong arg3, abi_ulong arg4, abi_ulong arg5, + abi_ulong arg6) +{ + cpuset_t mask; + abi_long ret; + id_t id; /* 64-bit */ + abi_ulong setsize, target_mask; + +#if TARGET_ABI_BITS =3D=3D 32 + id =3D (id_t)target_arg64(arg3, arg4); + setsize =3D arg5; + target_mask =3D arg6; +#else + id =3D (id_t)arg3; + setsize =3D arg4; + target_mask =3D arg5; +#endif + + ret =3D copy_from_user_cpuset_mask(&mask, target_mask); + if (ret =3D=3D 0) { + ret =3D get_errno(cpuset_setaffinity(level, which, id, set= size, + &mask)); + } + + return ret; +} + +/* + * Pretend there are no modules loaded into the kernel. Don't allow loadin= g or + * unloading of modules. This works well for tests, and little else seems = to + * care. Will reevaluate if examples are found that do matter. + */ + =20 #endif /* OS_MISC_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139900; cv=none; d=zohomail.com; s=zohoarc; b=dsh30RGtwoOxEoUvJQ4OhSiPo7MvLX1cI8ii1phF6AF5QkOZhlTD3reQgJdSZvypgk/QBRBSM8zIJxxhj4HCpBCZ/k9NG82aijZFivTkOr9lH5qTVgbMTVPs9mdiFZNHlfSSEmwREmZBcynCADtF+LUuxh5CT7ZgqQbsc+ilvz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139900; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jGHnVuP8jIyMC8JIdhhrduGtNIGJ/j5NOLUiUoZFHBY=; b=M1lqqrCZsKnx0/CNT93O7E0sxnkICks2fp7qt51/7czfynQ1LF3FlWE4GmTIIK5l7Gs6K9TJHbkjxwwJB8nbZ2PtaZ74Z6Kha/fC/QFlrjQiy/k7+mzP37QQ9CO7HQDJiFjK7OoaL0drolBpHR4iY+Ow3O/f4RNSxj66x6luIUE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139900585981.1525715504864; Mon, 18 May 2026 14:31:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vr-0000l0-Mq; Mon, 18 May 2026 17:28:35 -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 1wP5Vn-0000YS-TP for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:32 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vl-0000jM-SF for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:31 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7de4a9cb8eeso2865720a34.0 for ; Mon, 18 May 2026 14:28:29 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139709; x=1779744509; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jGHnVuP8jIyMC8JIdhhrduGtNIGJ/j5NOLUiUoZFHBY=; b=CbAc9sex+D9krn9X3dayteBWGqRig1CYPKvv6NZwaYZig6QTMil/gkeBsBv7Sn10BW 15SKYz30s6egvsVRgqhfToaWL+jTFcMhek/fL5ZyAghQ37bDdEOL7B2RN01ODGrY7rOc v1l0yXwwwdJHSs/Y2jpnbVtI9uZXFqKZCDvQHFC9l7PwU+sc+gP9N8xCmtioZJ7vm/Fk qffT1t4EmHMl+ZUZ5f9RD1+e8xoi0RHLW1s2Ld74IfC4z4VBpsQNbWIA38bta5ROMrOl 7GO4Yzpxk7c0nwz6NVW0ewUifWjWMTroP7U3ujcnVR1PqlQrZCiVEglG5wMbV9Ghmutt 8DHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139709; x=1779744509; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=jGHnVuP8jIyMC8JIdhhrduGtNIGJ/j5NOLUiUoZFHBY=; b=nkq0YP1kbY+8CPqbP/LqtTac6e+e4lsKi5Bc+N9IakdG7DkdnO0u/yFYMXfq0V3ead ZzWCCnae43LbJ9/JgyMcy1e9zSLxrJIjfylkTar3zPD0H0uUsBTgcL+8GTdH7CZIYUFg GefS8h2WP6VWuoSUdnK8a4JAgAWYa5R/uUlaZ4Zz6uRngKoh6CwsK3t9LA4rw4F64qcg iqPs3Q8yPCqNzoj1/ktg3GWZajJ2Ty7d1HRCEVpQFSIAwuHi/yotwQWM7nhovpEgmgfo OL4MXlRietWLghIcu9Fvif9a3Di/lqO+oQU3DpA6E1gbl83zx9bUxaFrgCYkUsiSGqRs cvBg== X-Gm-Message-State: AOJu0Yy2cKsKz69ityXbCZKw1+JqYX7fw8+BTwQeDyddVanwl9KLHZ3z 2YhrJy922OS4Rn+Kt4fAqudB0Gi+1YQrXkV8heS0qnxsm64XajO15ywiLU7+2IILP0E= X-Gm-Gg: Acq92OGQ8Z1HcjKxtvaBgkxnrcTrpxIZPO7NsHBIzJ+KS5aCzsCsASKm65/gZv41QHH sVIhrjspaUodABwz3e5qY4Raa+rgTNkECn/LfM2ItSNjY2kazJVWZGKWRGZuGud1FX7UmJYbLBu lcEGgkF8WqN3vJeS05JH3gzSC4iwXUl/wn/NNYBTICSLoC8jOhyH6c6K0OtCs5giOP3lpfjqt/A 8fq1ScQ+JACatlGxZWZrJKGXSluaSuOMiTSnjmeB+2Mqgk1lGLncmuwsWW7psgH/CZwYZwO5PhD e1V/Z/68qqZUFuezIunIAILlJEYWffhgkFjE4Mh/Qg0IkzCB+7zfPnq21f9N3+IPfOcnu8Mnc7N r6C0xzeKrtPo/ERaqYtU83LmpuDj4Ag7s8KbLcN5LYu79SK2c9J/BiWqHcyKQade1p82+u//jLA Si3f3lrIedAQ== X-Received: by 2002:a05:6830:3910:b0:7d7:4fc9:5204 with SMTP id 46e09a7af769-7e4ea01a8bfmr11360487a34.2.1779139708849; Mon, 18 May 2026 14:28:28 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:54 -0600 Subject: [PATCH v2 36/37] bsd-user: Add kmod, posix, and misc functions to os-misc.h MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-36-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Karim Taha , Sean Bruno , Alexander Kabaev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8178; i=imp@bsdimp.com; h=from:subject:message-id; bh=AEXzakBRiEw81OkCt4uOUOmVZS5H1ln6ibu6g6qBDME=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJx7pk7hVDeU2lhpnTN4VKMgf9jk7AS2dT6 bSJ6oQZL5yJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR AOPeEADhxq4TScRL/sJ26EKsajcDXL8ebRNBYXQRusjL6GOIv7j+WZ+wiHXL7Kw/zcr1/WYAd0s eG2bx8vtYZ800t6FCeXNQEAv2lW7QHecxA0EJEj4huEp0bvUcHOVGp1PcoiHqZVomjhNXiT4/iP puRYwrajr3tM7J3UkHSp2RG+zTLghIn4Ig1F0CEaBBy73miIu5mcr5onH8QjOMqzCDiLG81Cfs/ tq03+J2wR+TSogDZRFF0t217TxLc5Xr4b3+D4BksKxzYsX2hctRyy+zbrGwJMZ3bI+LcjN5Hj2f XZZDIBtBXO4tmFFfB10uOmVe2rnDlwx5YN1Q3BNoNn2U4ZNasbrD3h3/DiMxWvDTVmDfggNSXcr YOlVMvJvvsV7WRm95G5PwamWBlZqjKVhxgXUh60WBJmfBNt8bzxmvMXGVWAY7CKWy5VC+FRS3tP VSOsB9vKdJb1s3sBsjhIiLxlsipK2kDGJnOhMQkdgL/gd+L13SmGoI2ALF2d9qDxfPP0d9sALM1 cPhlsYwlh6yWoAC525B2Qpuf9E6yMOM5EEqn+bGjDsV4yxTpVnDb91XEefPAyzOoLMEewdkNh+Q K3W6kIkNGiWjuvVoOMW/CNB48EQ/ClmyqFG4I+oaMDud05FnLCDc1l1veLLhFKOUYp9csikLpqi I4nLz1qC/kotugA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32b; envelope-from=imp@bsdimp.com; helo=mail-ot1-x32b.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139901427154100 Complete os-misc.h with kernel module functions (modfnext, modfind, kldload, kldunload, kldunloadf, kldfind, kldnext, kldstat, kldfirstmod, kldsym), POSIX functions (posix_fallocate, posix_openpt), getrandom, and kenv. Signed-off-by: Stacey Son Signed-off-by: Karim Taha Signed-off-by: Sean Bruno Signed-off-by: Alexander Kabaev Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/freebsd/os-misc.h | 274 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 274 insertions(+) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 74ed1d2f47..cc33d16abb 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -270,5 +270,279 @@ static inline abi_long do_freebsd_cpuset_setaffinity(= cpulevel_t level, * care. Will reevaluate if examples are found that do matter. */ =20 +/* modfnext(2) */ +static inline abi_long do_freebsd_modfnext(abi_long modid) +{ + return -TARGET_ENOENT; +} + +/* modfind(2) */ +static inline abi_long do_freebsd_modfind(abi_ulong target_name) +{ + return -TARGET_ENOENT; +} + +/* kldload(2) */ +static inline abi_long do_freebsd_kldload(abi_ulong target_name) +{ + return -TARGET_EPERM; +} + +/* kldunload(2) */ +static inline abi_long do_freebsd_kldunload(abi_long fileid) +{ + return -TARGET_EPERM; +} + +/* kldunloadf(2) */ +static inline abi_long do_freebsd_kldunloadf(abi_long fileid, abi_long fla= gs) +{ + return -TARGET_EPERM; +} + +/* kldfind(2) */ +static inline abi_long do_freebsd_kldfind(abi_ulong target_name) +{ + return -TARGET_ENOENT; +} + +/* kldnext(2) */ +static inline abi_long do_freebsd_kldnext(abi_long fileid) +{ + return -TARGET_ENOENT; +} + + +/* kldstat(2) */ +static inline abi_long do_freebsd_kldstat(abi_long fileid, + abi_ulong target_stat) +{ + return -TARGET_ENOENT; +} + +/* kldfirstmod(2) */ +static inline abi_long do_freebsd_kldfirstmod(abi_long fileid) +{ + return -TARGET_ENOENT; +} + +/* kldsym(2) */ +static inline abi_long do_freebsd_kldsym(abi_long fileid, abi_long cmd, + abi_ulong target_data) +{ + return -TARGET_ENOENT; +} + +/* + * New posix calls + */ + +#if TARGET_ABI_BITS =3D=3D 32 +static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) +{ +#ifdef TARGET_BIG_ENDIAN + return ((uint64_t)word0 << 32) | word1; +#else + return ((uint64_t)word1 << 32) | word0; +#endif +} +#else /* TARGET_ABI_BITS =3D=3D 32 */ +static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) +{ + return word0; +} +#endif /* TARGET_ABI_BITS !=3D 32 */ + +/* posix_fallocate(2) */ +static inline abi_long do_freebsd_posix_fallocate(abi_long arg1, abi_long = arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ + +#if TARGET_ABI_BITS =3D=3D 32 + return get_errno(posix_fallocate(arg1, target_offset64(arg3, arg4), + target_offset64(arg5, arg6))); +#else + return get_errno(posix_fallocate(arg1, arg2, arg3)); +#endif +} + +/* posix_openpt(2) */ +static inline abi_long do_freebsd_posix_openpt(abi_long flags) +{ + + return get_errno(posix_openpt(flags)); +} + +/* + * shm_open2 isn't exported, but the __sys_ alias is. We can use either fo= r the + * static version, but to dynamically link we have to use the sys version. + */ +int __sys_shm_open2(const char *path, int flags, mode_t mode, int shmflags, + const char *); + +/* shm_open2(2) */ +static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong f= lags, + abi_long mode, abi_ulong shmflags, abi_ulong nameptr) +{ + int ret; + void *uname, *upath; + + if (pathptr =3D=3D (uintptr_t)SHM_ANON) { + upath =3D SHM_ANON; + } else { + upath =3D lock_user_string(pathptr); + if (upath =3D=3D NULL) { + return -TARGET_EFAULT; + } + } + + uname =3D NULL; + if (nameptr !=3D 0) { + uname =3D lock_user_string(nameptr); + if (uname =3D=3D NULL) { + unlock_user(upath, pathptr, 0); + return -TARGET_EFAULT; + } + } + ret =3D get_errno(__sys_shm_open2(upath, + target_to_host_bitmask(flags, fcntl_flags_tbl), mode, + target_to_host_bitmask(shmflags, shmflag_flags_tbl), uname= )); + + if (upath !=3D SHM_ANON) { + unlock_user(upath, pathptr, 0); + } + if (uname !=3D NULL) { + unlock_user(uname, nameptr, 0); + } + return ret; +} + +/* shm_rename(2) */ +static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong = toptr, + abi_ulong flags) +{ + int ret; + void *ufrom, *uto; + + ufrom =3D lock_user_string(fromptr); + if (ufrom =3D=3D NULL) { + return -TARGET_EFAULT; + } + uto =3D lock_user_string(toptr); + if (uto =3D=3D NULL) { + unlock_user(ufrom, fromptr, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(shm_rename(ufrom, uto, flags)); + unlock_user(ufrom, fromptr, 0); + unlock_user(uto, toptr, 0); + + return ret; +} + +#if defined(CONFIG_GETRANDOM) +static inline abi_long do_freebsd_getrandom(abi_ulong buf, abi_ulong bufle= n, + abi_ulong flags) +{ + abi_long ret; + void *p; + + p =3D lock_user(VERIFY_WRITE, buf, buflen, 0); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } + ret =3D get_errno(getrandom(p, buflen, flags)); + unlock_user(p, buf, ret); + + return ret; +} +#endif + +static inline abi_long do_freebsd_kenv(abi_long action, abi_ulong name, + abi_ulong value, abi_long len) +{ + abi_long ret; + void *gname =3D NULL; /* unlocked in cases where set */ + void *gvalue =3D NULL; /* unlocked in cases where set */ + + ret =3D -TARGET_EINVAL; + switch (action) { + case KENV_GET: + gname =3D lock_user_string(name); + if (gname =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + break; + } + gvalue =3D lock_user(VERIFY_WRITE, value, len, 0); + if (gvalue =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + break; + } + ret =3D get_errno(kenv(action, gname, gvalue, len)); + if (ret > 0) { + len =3D ret; + } else { + len =3D 0; + } + break; + case KENV_SET: + gname =3D lock_user_string(name); + if (gname =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + break; + } + gvalue =3D lock_user(VERIFY_READ, value, len, 1); + if (gvalue =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + break; + } + ret =3D get_errno(kenv(action, gname, gvalue, len)); + unlock_user(gvalue, value, 0); + gvalue =3D NULL; + break; + case KENV_UNSET: + gname =3D lock_user_string(name); + if (gname =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + break; + } + /* value and name ignored, per kenv(2) */ + ret =3D get_errno(kenv(action, gname, NULL, 0)); + break; + /* All three treated the same */ + case KENV_DUMP: + case KENV_DUMP_LOADER: + case KENV_DUMP_STATIC: + /* value =3D=3D NULL -> just return length */ + if (value !=3D 0) { + gvalue =3D lock_user(VERIFY_WRITE, value, len, 0); + if (gvalue =3D=3D NULL) { + ret =3D -TARGET_EFAULT; + break; + } + } + /* name is ignored, per kenv(2) */ + ret =3D get_errno(kenv(action, NULL, gvalue, len)); + if (ret > 0) { + len =3D ret; + } else { + len =3D 0; + } + break; + default: + ret =3D -TARGET_EINVAL; + break; + } + + /* Unmap everything mapped */ + if (gvalue !=3D NULL) { + unlock_user(gvalue, value, len); + } + if (gname !=3D NULL) { + unlock_user(gname, name, 0); + } + + return ret; +} =20 #endif /* OS_MISC_H */ --=20 2.52.0 From nobody Sat May 30 18:35:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779139798; cv=none; d=zohomail.com; s=zohoarc; b=Wc2TsDhyksSvc/YupfMD+Vaxssy/nwAGtOyqi/BF4O3lTHxCRLPqmiCRzIumOuJMWZgth4JlVhj+rK2Z+yStvH81W/KOF0ewR4B/cbvjk/z1sStWaKLy/9KGNh8meq5OAk7FxBX7m8EfF5ybPq4rb5MGUO1nf3vZgsT/hlErYQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779139798; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IjtYKiTslteh1AqUlT8SGFsxQA2/06AYOpihNDH2hQg=; b=YgYDR16MmwaYhxkgRinWYEGSanthYv66DrEzJ9u5kb4afW0ciJuuVl9yjmKDziBAlUTfpHci5SvEer6yZ1IeShPJpUag2dW29PEW21/+V+QVFmJ6UUFf+EYHIFIEOCi9V+5yVyNwoGG8RUxwfZ/n92EMuEDvEisea3YyEgRQcXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779139798647952.1978230031044; Mon, 18 May 2026 14:29:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wP5Vt-0000mL-3i; Mon, 18 May 2026 17:28: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 1wP5Vq-0000hO-3q for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:34 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wP5Vn-0000lR-8P for qemu-devel@nongnu.org; Mon, 18 May 2026 17:28:33 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-4824176bbbeso839779b6e.0 for ; Mon, 18 May 2026 14:28:30 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b81cc5asm7980358a34.8.2026.05.18.14.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 14:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1779139710; x=1779744510; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IjtYKiTslteh1AqUlT8SGFsxQA2/06AYOpihNDH2hQg=; b=IbswSeUmnpg3CkEJ+OdDDJPRM3fEeGcudxSnHAzsCwq9KZir0A0xtfWwYmhrqte8li pQOwtVBGtanE+b8Csx4PxHYWauo/HRj89vZrVfiIVMnvM0fqKfKm8o7yMNCCycALY8xD ONl/epAp3YrWbjo/zxVoHzxJc39PqX9dby8r1pVswHumIdKkAvOommsKtRHxKoFVflF5 8+O9q/NKHXzVWWUaDCepNh8Ql0FO0zXOMHXHv2RR2GnbeERQHboGa2/Udw+tXh/B7xtl ZoQQydXL93C6FQ97hMOCcC814hsnPrprNvFBqFXfU/Bse5sid1qg+qB+fcYgQSuD4+ux gcKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779139710; x=1779744510; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IjtYKiTslteh1AqUlT8SGFsxQA2/06AYOpihNDH2hQg=; b=HwDhpUNE3yDcM/asHfGzwvhr3hvsx4HVX1wPAEOuZ2aWQs/UKJMTurpiF6hX7RE/GE yIClsXviyyb2pTJaXZe7crgcOhUFVa1Zm2h84ILQWpZtS3BJ7wGsCA/8ry7PM5C+Kthn LCa1Zu8eKspy9rHNn49MqU4kV2Sul8IYUCHKf5h4X36yurend1kxj/Mj9SBHECOwfF76 FTIMemy1CNiiQon4f/SxBi5SrJAIfhY5juCwU79QyDC4GrAvwSUZTSe5snWtSkmR2AgR 1tvaSw553plS+SKWQQiX6YsRkXcmgsV4eSocz0UyoEBM+gU7ywK+smw5NnxIPQ78P56U t7ew== X-Gm-Message-State: AOJu0YzDdNYXFRSYAhU1byUb8rNfCySfxKY2J67XUw7Ybm0JqxbgyKlF 8K2m9mA2m/f1rpECgsDusJjRs3q5eCNm1oybCL2YTD47BMtR5iVFXwwEaoLqsNhEFZEz79SofZU uqhzXjFo= X-Gm-Gg: Acq92OGKEsnfNa+SC5H5V08sHV790Ro+xwaL5g0DL91n7otLVQcmJn9d4xcarhXtVV7 77RpiY7KRJOxIHDGha9RcUfJqsSGHRinaWtsX0CeGX7W6uToOM0iGOKKg48FjKo7m8zNO3UpEeh 6D+FvnvrqYrADwVAZWVyM0nXlLmxlevSkoTnWnrS37QiLA7JP29uivr/EZ3f5Ii1iau0WoJ1qsM zTewkrSzpzJNtacZMs8esfymMU4l4InpQYZOUwH1Rh8No5BYpisYlTsL8aeO2W6IGhzp0Gz59IY xh1f3RoJVdqbsjr/stpQVh5xuawc0DxiBH0y4LMRN2v+CxbUg23hLYgyAYdMRnUMTFqDrxd2NjY C6s/g8vUw02fWqcquvvcScM1fHlxZ3rE9MEC+woHsdDUuRNQK02z5pZRwbeD4mjwWBQ+1L+iPuE 9p95lAZ7EPKg== X-Received: by 2002:a05:6808:2f0e:b0:482:4dbd:4fe8 with SMTP id 5614622812f47-482e58dbf6emr10815574b6e.46.1779139709916; Mon, 18 May 2026 14:28:29 -0700 (PDT) From: Warner Losh Date: Mon, 18 May 2026 15:27:55 -0600 Subject: [PATCH v2 37/37] bsd-user: Add scheduler, cpuset, kmod, and misc syscall dispatch MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260518-misc-2026q2-v2-37-6c16fe448301@bsdimp.com> References: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> In-Reply-To: <20260518-misc-2026q2-v2-0-6c16fe448301@bsdimp.com> To: qemu-devel@nongnu.org Cc: Kyle Evans , Pierrick Bouvier , Warner Losh , Stacey Son , Kyle Evans X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=23108; i=imp@bsdimp.com; h=from:subject:message-id; bh=75INCCR67WngC+LgfJZw3jtrQDBBgN+N/9/tttTIEPk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqC4RJ1iac9mh4GX3RFCxyyaaF6+SRdGOX1G7Ic 5PAf3WAOcyJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCaguESQAKCRBsHNEofbAR ANDNEADZMaUAl1WEgt05iiuBzGwHIxrumTR+ijRzbGCk9x+YPBXXnos28lfwIpVvFHlfdubQdA2 1pykTuHeiN3E9jWopaLeqmTdz+wmR0lh3de9tu7OhLKVz2SBvxvnEoxxQjkurzx4FjYGsUO52Bh Qk9mzW83lJEdsIcYoTGkTsSjdEE9EK8lVeh5XIyVrKJ34CXjtADMlr5qQy4PRP4q9Csdx5c38be RcXXK7MFFfT820jKUVxNYMIPCDxGZj9iUazyvJZHuaB8Hsjf21/OV6l00ZlLmJd66S6IprwIzxb +liytqJC1+vvc0s7kXve1WMkHNBaMo7uwxrKTqFoOcDtRzMphEW5Y7hUZSbt32xjIpLPofxFspY ZC/EEBtSl4loMSPfhotUw8QH6L0JS4tonE8ySKZ7gyt1N3BS92h4SOPXzi9wT0ckkfz6pUaSjU0 I/hVen7khAkEhDy6mTA3BmmMfmPfHJc4AfaTBTOKBpoX6dE0CGV9Hegw6MZibx5zPWlJ2aJ5T07 xmFhb2JwWYrMqDFbTCrWIpaZva9XxVcBu8QkwsC7wWCU/2rsKDP8+QsY8qGKpD76vYtNlesME3g 9bjyvzXLyYXdtpg5gFQoD2C4kHwk2Apu6TWY5NzKdD/fYHMrkFdiFyWbEgG95t1oXnAMDD7C5d6 6aioZgzxcEY3jQA== X-Developer-Key: i=imp@bsdimp.com; a=openpgp; fpr=2035F894B00AA3CF7CCDE1B76C1CD1287DB01100 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::22b; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22b.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, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20251104.gappssmtp.com) X-ZM-MESSAGEID: 1779139801314154100 Wire up remaining system calls: sched_setparam, sched_getparam, sched_setscheduler, sched_getscheduler, sched_get_priority_max, sched_get_priority_min, sched_rr_get_interval, sched_yield, cpuset, cpuset_setid, cpuset_getid, cpuset_getaffinity, cpuset_setaffinity, modfnext, modfind, kldload, kldunload, kldunloadf, kldfind, kldnext, kldstat, kldfirstmod, kldsym, posix_fallocate, posix_openpt, getrandom, kenv, cap_rights_limit, cap_ioctls_limit, cap_fcntls_limit, cap_enter, syscall, and __syscall. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Assisted-by: Claude Opus 4.6 (1M context) --- bsd-user/bsd-proc.h | 2 +- bsd-user/freebsd/os-syscall.c | 522 ++++++++++++++++++++++++++------------= ---- 2 files changed, 329 insertions(+), 195 deletions(-) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index b9973dbedf..70a72a6a94 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -418,4 +418,4 @@ static inline abi_long do_bsd_sched_get_priority_max(in= t policy) return get_errno(sched_get_priority_max(policy)); } =20 -#endif /* !BSD_PROC_H */ +#endif /* !BSD_PROC_H_ */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 7825e042b0..c8f88efc6f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -532,6 +532,10 @@ static abi_long freebsd_syscall(CPUArchState *env, int= num, abi_long arg1, ret =3D do_bsd_closefrom(arg1); break; =20 + case TARGET_FREEBSD_NR_close_range: /* close_range(2) */ + ret =3D do_freebsd_close_range(arg1, arg2, arg3); + break; + case TARGET_FREEBSD_NR_revoke: /* revoke(2) */ ret =3D do_bsd_revoke(arg1); break; @@ -696,6 +700,10 @@ static abi_long freebsd_syscall(CPUArchState *env, int= num, abi_long arg1, ret =3D do_bsd_chflags(arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_chflagsat: /* chflagsat(2) */ + ret =3D do_bsd_chflagsat(arg1, arg2, arg3, arg4); + break; + case TARGET_FREEBSD_NR_lchflags: /* lchflags(2) */ ret =3D do_bsd_lchflags(arg1, arg2); break; @@ -740,6 +748,10 @@ static abi_long freebsd_syscall(CPUArchState *env, int= num, abi_long arg1, ret =3D do_bsd_poll(arg1, arg2, arg3); break; =20 + case TARGET_FREEBSD_NR_ppoll: /* ppoll(2) */ + ret =3D do_freebsd_ppoll(env, arg1, arg2, arg3, arg4); + break; + case TARGET_FREEBSD_NR_lseek: /* lseek(2) */ ret =3D do_bsd_lseek(env, arg1, arg2, arg3, arg4, arg5); break; @@ -766,14 +778,6 @@ static abi_long freebsd_syscall(CPUArchState *env, int= num, abi_long arg1, ret =3D do_bsd_swapoff(arg1, arg2); break; =20 - case TARGET_FREEBSD_NR_chflagsat: /* chflagsat(2) */ - ret =3D do_bsd_chflagsat(arg1, arg2, arg3, arg4); - break; - - case TARGET_FREEBSD_NR_close_range: /* close_range(2) */ - ret =3D do_freebsd_close_range(arg1, arg2, arg3); - break; - case TARGET_FREEBSD_NR___realpathat: /* __realpathat(2) (XXX no realpathat()) */ ret =3D do_freebsd_realpathat(arg1, arg2, arg3, arg4, arg5); @@ -787,125 +791,12 @@ static abi_long freebsd_syscall(CPUArchState *env, i= nt num, abi_long arg1, ret =3D do_freebsd___specialfd(arg1, arg2, arg3); break; =20 - /* - * ioctl(2) - */ - case TARGET_FREEBSD_NR_ioctl: /* ioctl(2) */ - ret =3D do_bsd_ioctl(arg1, arg2, arg3); - break; - - /* - * stat system calls - */ - case TARGET_FREEBSD_NR_freebsd11_stat: /* stat(2) */ - ret =3D do_freebsd11_stat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_lstat: /* lstat(2) */ - ret =3D do_freebsd11_lstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_fstat: /* fstat(2) */ - ret =3D do_freebsd11_fstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_fstat: /* fstat(2) */ - ret =3D do_freebsd_fstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_fstatat: /* fstatat(2) */ - ret =3D do_freebsd11_fstatat(arg1, arg2, arg3, arg4); - break; - - case TARGET_FREEBSD_NR_fstatat: /* fstatat(2) */ - ret =3D do_freebsd_fstatat(arg1, arg2, arg3, arg4); - break; - - case TARGET_FREEBSD_NR_freebsd11_nstat: /* undocumented */ - ret =3D do_freebsd11_nstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_nfstat: /* undocumented */ - ret =3D do_freebsd11_nfstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_nlstat: /* undocumented */ - ret =3D do_freebsd11_nlstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_getfh: /* getfh(2) */ - ret =3D do_freebsd_getfh(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_lgetfh: /* lgetfh(2) */ - ret =3D do_freebsd_lgetfh(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_fhopen: /* fhopen(2) */ - ret =3D do_freebsd_fhopen(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_fhstat: /* fhstat(2) */ - ret =3D do_freebsd11_fhstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_fhstat: /* fhstat(2) */ - ret =3D do_freebsd_fhstat(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_fhstatfs: /* fhstatfs(2) */ - ret =3D do_freebsd11_fhstatfs(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_fhstatfs: /* fhstatfs(2) */ - ret =3D do_freebsd_fhstatfs(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_statfs: /* statfs(2) */ - ret =3D do_freebsd11_statfs(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_statfs: /* statfs(2) */ - ret =3D do_freebsd_statfs(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_fstatfs: /* fstatfs(2) */ - ret =3D do_freebsd11_fstatfs(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_fstatfs: /* fstatfs(2) */ - ret =3D do_freebsd_fstatfs(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_freebsd11_getfsstat: /* getfsstat(2) */ - ret =3D do_freebsd11_getfsstat(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR_getfsstat: /* getfsstat(2) */ - ret =3D do_freebsd_getfsstat(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR_freebsd11_getdents: /* getdents(2) */ - ret =3D do_freebsd11_getdents(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR_getdirentries: /* getdirentries(2) */ - ret =3D do_freebsd_getdirentries(arg1, arg2, arg3, arg4); - break; - - case TARGET_FREEBSD_NR_freebsd11_getdirentries: /* getdirentries(2) */ - ret =3D do_freebsd11_getdirentries(arg1, arg2, arg3, arg4); - break; - case TARGET_FREEBSD_NR_fcntl: /* fcntl(2) */ - ret =3D do_freebsd_fcntl(arg1, arg2, arg3); - break; - /* * Memory management system calls. */ case TARGET_FREEBSD_NR_mmap: /* mmap(2) */ ret =3D do_bsd_mmap(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, - arg8); + arg8); break; =20 case TARGET_FREEBSD_NR_munmap: /* munmap(2) */ @@ -952,17 +843,13 @@ static abi_long freebsd_syscall(CPUArchState *env, in= t num, abi_long arg1, ret =3D do_bsd_shm_open(arg1, arg2, arg3); break; =20 -#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1300048 case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */ ret =3D do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5); break; -#endif =20 -#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1300049 case TARGET_FREEBSD_NR_shm_rename: /* shm_rename(2) */ ret =3D do_freebsd_shm_rename(arg1, arg2, arg3); break; -#endif =20 case TARGET_FREEBSD_NR_shm_unlink: /* shm_unlink(2) */ ret =3D do_bsd_shm_unlink(arg1); @@ -984,68 +871,10 @@ static abi_long freebsd_syscall(CPUArchState *env, in= t num, abi_long arg1, ret =3D do_bsd_shmdt(arg1); break; =20 - /* - * System V Semaphores - */ - case TARGET_FREEBSD_NR_semget: /* semget(2) */ - ret =3D do_bsd_semget(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR_semop: /* semop(2) */ - ret =3D do_bsd_semop(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR___semctl: { /* __semctl() undocumented */ - ret =3D do_bsd___semctl(arg1, arg2, arg3, arg4); - break; - } - - /* - * System V Messages - */ - case TARGET_FREEBSD_NR_msgctl: /* msgctl(2) */ - ret =3D do_bsd_msgctl(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR_msgget: /* msgget(2) */ - ret =3D do_bsd_msgget(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_msgsnd: /* msgsnd(2) */ - ret =3D do_bsd_msgsnd(arg1, arg2, arg3, arg4); - break; - - case TARGET_FREEBSD_NR_msgrcv: /* msgrcv(2) */ - ret =3D do_bsd_msgrcv(arg1, arg2, arg3, arg4, arg5); - break; - case TARGET_FREEBSD_NR_freebsd11_vadvise: ret =3D do_bsd_vadvise(); break; =20 - /* - * Misc - */ - case TARGET_FREEBSD_NR_break: - ret =3D do_obreak(arg1); - break; - - case TARGET_FREEBSD_NR_quotactl: /* quotactl(2) */ - ret =3D do_bsd_quotactl(arg1, arg2, arg3); - break; - - case TARGET_FREEBSD_NR_reboot: /* reboot(2) */ - ret =3D do_bsd_reboot(arg1); - break; - - case TARGET_FREEBSD_NR_uuidgen: /* uuidgen(2) */ - ret =3D do_bsd_uuidgen(arg1, arg2); - break; - - case TARGET_FREEBSD_NR_getdtablesize: /* getdtablesize(2) */ - ret =3D do_bsd_getdtablesize(); - break; - /* * time related system calls. */ @@ -1133,10 +962,6 @@ static abi_long freebsd_syscall(CPUArchState *env, in= t num, abi_long arg1, ret =3D do_freebsd_pselect(env, arg1, arg2, arg3, arg4, arg5, arg6= ); break; =20 - case TARGET_FREEBSD_NR_ppoll: /* ppoll(2) */ - ret =3D do_freebsd_ppoll(env, arg1, arg2, arg3, arg4); - break; - case TARGET_FREEBSD_NR_kqueue: /* kqueue(2) */ ret =3D do_freebsd_kqueue(); break; @@ -1350,6 +1175,119 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, ret =3D do_freebsd__umtx_op(arg1, arg2, arg3, arg4, arg5); break; =20 + /* + * ioctl(2) + */ + case TARGET_FREEBSD_NR_ioctl: /* ioctl(2) */ + ret =3D do_bsd_ioctl(arg1, arg2, arg3); + break; + + /* + * stat system calls + */ + case TARGET_FREEBSD_NR_freebsd11_stat: /* stat(2) */ + ret =3D do_freebsd11_stat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_lstat: /* lstat(2) */ + ret =3D do_freebsd11_lstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_fstat: /* fstat(2) */ + ret =3D do_freebsd11_fstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_fstat: /* fstat(2) */ + ret =3D do_freebsd_fstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_fstatat: /* fstatat(2) */ + ret =3D do_freebsd11_fstatat(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_fstatat: /* fstatat(2) */ + ret =3D do_freebsd_fstatat(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_freebsd11_nstat: /* undocumented */ + ret =3D do_freebsd11_nstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_nfstat: /* undocumented */ + ret =3D do_freebsd11_nfstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_nlstat: /* undocumented */ + ret =3D do_freebsd11_nlstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_getfh: /* getfh(2) */ + ret =3D do_freebsd_getfh(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_lgetfh: /* lgetfh(2) */ + ret =3D do_freebsd_lgetfh(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_fhopen: /* fhopen(2) */ + ret =3D do_freebsd_fhopen(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_fhstat: /* fhstat(2) */ + ret =3D do_freebsd11_fhstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_fhstat: /* fhstat(2) */ + ret =3D do_freebsd_fhstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_fhstatfs: /* fhstatfs(2) */ + ret =3D do_freebsd11_fhstatfs(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_fhstatfs: /* fhstatfs(2) */ + ret =3D do_freebsd_fhstatfs(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_statfs: /* statfs(2) */ + ret =3D do_freebsd11_statfs(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_statfs: /* statfs(2) */ + ret =3D do_freebsd_statfs(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_fstatfs: /* fstatfs(2) */ + ret =3D do_freebsd11_fstatfs(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_fstatfs: /* fstatfs(2) */ + ret =3D do_freebsd_fstatfs(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_freebsd11_getfsstat: /* getfsstat(2) */ + ret =3D do_freebsd11_getfsstat(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getfsstat: /* getfsstat(2) */ + ret =3D do_freebsd_getfsstat(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_freebsd11_getdents: /* getdents(2) */ + ret =3D do_freebsd11_getdents(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_getdirentries: /* getdirentries(2) */ + ret =3D do_freebsd_getdirentries(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_freebsd11_getdirentries: /* getdirentries(2) */ + ret =3D do_freebsd11_getdirentries(arg1, arg2, arg3, arg4); + break; + case TARGET_FREEBSD_NR_fcntl: /* fcntl(2) */ + ret =3D do_freebsd_fcntl(arg1, arg2, arg3); + break; + /* * sys{ctl, arch, call} */ @@ -1365,19 +1303,25 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, ret =3D do_freebsd_sysarch(env, arg1, arg2); break; =20 + case TARGET_FREEBSD_NR_syscall: /* syscall(2) */ + case TARGET_FREEBSD_NR___syscall: /* __syscall(2) */ + ret =3D do_freebsd_syscall(env, arg1 & 0xffff, arg2, arg3, arg4, + arg5, arg6, arg7, arg8, 0); + break; + /* - * extended attributes and ACL system calls + * extended attributes system calls */ case TARGET_FREEBSD_NR_extattrctl: /* extattrctl() */ ret =3D do_freebsd_extattrctl(arg1, arg2, arg3, arg4, arg5); break; =20 case TARGET_FREEBSD_NR_extattr_set_file: /* extattr_set_file(2) */ - ret =3D do_freebsd_extattr_set_file(arg1, arg2, arg3, arg4, arg4); + ret =3D do_freebsd_extattr_set_file(arg1, arg2, arg3, arg4, arg5); break; =20 case TARGET_FREEBSD_NR_extattr_get_file: /* extattr_get_file(2) */ - ret =3D do_freebsd_extattr_get_file(arg1, arg2, arg3, arg4, arg4); + ret =3D do_freebsd_extattr_get_file(arg1, arg2, arg3, arg4, arg5); break; =20 case TARGET_FREEBSD_NR_extattr_delete_file: /* extattr_delete_file(2) = */ @@ -1397,11 +1341,11 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, break; =20 case TARGET_FREEBSD_NR_extattr_get_link: /* extattr_get_link(2) */ - ret =3D do_freebsd_extattr_get_link(arg1, arg2, arg3, arg4, arg4); + ret =3D do_freebsd_extattr_get_link(arg1, arg2, arg3, arg4, arg5); break; =20 case TARGET_FREEBSD_NR_extattr_set_link: /* extattr_set_link(2) */ - ret =3D do_freebsd_extattr_set_link(arg1, arg2, arg3, arg4, arg4); + ret =3D do_freebsd_extattr_set_link(arg1, arg2, arg3, arg4, arg5); break; =20 case TARGET_FREEBSD_NR_extattr_delete_link: /* extattr_delete_link(2) = */ @@ -1413,7 +1357,7 @@ static abi_long freebsd_syscall(CPUArchState *env, in= t num, abi_long arg1, break; =20 case TARGET_FREEBSD_NR_extattr_list_file: /* extattr_list_file(2) */ - ret =3D do_freebsd_extattr_list_file(arg1, arg2, arg3, arg4); + ret =3D do_freebsd_extattr_list_file(arg1, arg2, arg3, arg4); break; =20 case TARGET_FREEBSD_NR_extattr_list_link: /* extattr_list_link(2) */ @@ -1468,6 +1412,196 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, ret =3D do_freebsd__acl_set_link(arg1, arg2, arg3); break; =20 + /* + * System V Semaphores + */ + case TARGET_FREEBSD_NR_semget: /* semget(2) */ + ret =3D do_bsd_semget(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_semop: /* semop(2) */ + ret =3D do_bsd_semop(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR___semctl: { /* __semctl() undocumented */ + ret =3D do_bsd___semctl(arg1, arg2, arg3, arg4); + break; + } + + /* + * System V Messages + */ + case TARGET_FREEBSD_NR_msgctl: /* msgctl(2) */ + ret =3D do_bsd_msgctl(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_msgget: /* msgget(2) */ + ret =3D do_bsd_msgget(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_msgsnd: /* msgsnd(2) */ + ret =3D do_bsd_msgsnd(arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_msgrcv: /* msgrcv(2) */ + ret =3D do_bsd_msgrcv(arg1, arg2, arg3, arg4, arg5); + break; + + /* + * FreeBSD scheduler control + */ + case TARGET_FREEBSD_NR_sched_setparam: /* sched_setparam(2) */ + ret =3D do_freebsd_sched_setparam(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_sched_getparam: /* sched_getparam(2) */ + ret =3D do_freebsd_sched_getparam(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_sched_setscheduler: /* sched_setscheduler(2) */ + ret =3D do_freebsd_sched_setscheduler(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_sched_getscheduler: /* sched_getscheduler(2) */ + ret =3D do_freebsd_sched_getscheduler(arg1); + break; + + case TARGET_FREEBSD_NR_sched_get_priority_max: /* sched_get_priority_m= ax(2)*/ + ret =3D do_bsd_sched_get_priority_max(arg1); + break; + + case TARGET_FREEBSD_NR_sched_get_priority_min: /* sched_get_priority_m= in(2)*/ + ret =3D do_bsd_sched_get_priority_min(arg1); + break; + + case TARGET_FREEBSD_NR_sched_rr_get_interval: /* sched_rr_get_interval= (2) */ + ret =3D do_freebsd_sched_rr_get_interval(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_sched_yield: /* sched_yield(2)*/ + ret =3D do_bsd_sched_yield(); + break; + + + /* + * FreeBSD CPU affinity sets management + */ + case TARGET_FREEBSD_NR_cpuset: /* cpuset(2) */ + ret =3D do_freebsd_cpuset(arg1); + break; + + case TARGET_FREEBSD_NR_cpuset_setid: /* cpuset_setid(2) */ + ret =3D do_freebsd_cpuset_setid(env, arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_cpuset_getid: /* cpuset_getid(2) */ + ret =3D do_freebsd_cpuset_getid(arg1, arg2, arg3, arg4, arg5); + break; + + case TARGET_FREEBSD_NR_cpuset_getaffinity: /* cpuset_getaffinity(2) */ + ret =3D do_freebsd_cpuset_getaffinity(arg1, arg2, arg3, arg4, arg5= , arg6); + break; + + case TARGET_FREEBSD_NR_cpuset_setaffinity: /* cpuset_setaffinity(2) */ + ret =3D do_freebsd_cpuset_setaffinity(arg1, arg2, arg3, arg4, arg5= , arg6); + break; + + /* + * FreeBSD kernel module + */ + case TARGET_FREEBSD_NR_modfnext: /* modfnext(2) */ + ret =3D do_freebsd_modfnext(arg1); + break; + + case TARGET_FREEBSD_NR_modfind: /* modfind(2) */ + ret =3D do_freebsd_modfind(arg1); + break; + + case TARGET_FREEBSD_NR_kldload: /* kldload(2) */ + ret =3D do_freebsd_kldload(arg1); + break; + + case TARGET_FREEBSD_NR_kldunload: /* kldunload(2) */ + ret =3D do_freebsd_kldunload(arg1); + break; + + case TARGET_FREEBSD_NR_kldunloadf: /* kldunloadf(2) */ + ret =3D do_freebsd_kldunloadf(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_kldfind: /* kldfind(2) */ + ret =3D do_freebsd_kldfind(arg1); + break; + + case TARGET_FREEBSD_NR_kldnext: /* kldnext(2) */ + ret =3D do_freebsd_kldnext(arg1); + break; + + case TARGET_FREEBSD_NR_kldstat: /* kldstat(2) */ + ret =3D do_freebsd_kldstat(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_kldfirstmod: /* kldfirstmod(2) */ + ret =3D do_freebsd_kldfirstmod(arg1); + break; + + case TARGET_FREEBSD_NR_kldsym: /* kldsym(2) */ + ret =3D do_freebsd_kldsym(arg1, arg2, arg3); + break; + + /* + * FreeBSD additional posix support + */ + case TARGET_FREEBSD_NR_posix_fallocate: /* posix_fallocate(2) */ + ret =3D do_freebsd_posix_fallocate(arg1, arg2, arg3, arg4, arg5, a= rg6); + break; + + case TARGET_FREEBSD_NR_posix_openpt: /* posix_openpt(2) */ + ret =3D do_freebsd_posix_openpt(arg1); + break; + + /* + * Misc + */ + case TARGET_FREEBSD_NR_quotactl: /* quotactl(2) */ + ret =3D do_bsd_quotactl(arg1, arg2, arg3); + break; + + case TARGET_FREEBSD_NR_reboot: /* reboot(2) */ + ret =3D do_bsd_reboot(arg1); + break; + + case TARGET_FREEBSD_NR_uuidgen: /* uuidgen(2) */ + ret =3D do_bsd_uuidgen(arg1, arg2); + break; + + case TARGET_FREEBSD_NR_getdtablesize: /* getdtablesize(2) */ + ret =3D do_bsd_getdtablesize(); + break; + + case TARGET_FREEBSD_NR_break: + ret =3D do_obreak(arg1); + break; + +#if defined(CONFIG_GETRANDOM) + case TARGET_FREEBSD_NR_getrandom: + ret =3D do_freebsd_getrandom(arg1, arg2, arg3); + break; +#endif + case TARGET_FREEBSD_NR_kenv: + ret =3D do_freebsd_kenv(arg1, arg2, arg3, arg4); + break; + + /* XXX */ + case TARGET_FREEBSD_NR_cap_rights_limit: + case TARGET_FREEBSD_NR_cap_ioctls_limit: + case TARGET_FREEBSD_NR_cap_fcntls_limit: + ret =3D -TARGET_EINVAL; + break; + case TARGET_FREEBSD_NR_cap_enter: + ret =3D 0; + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret =3D -TARGET_ENOSYS; --=20 2.52.0