From nobody Sat May 30 18:35:06 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=1778880187; cv=none; d=zohomail.com; s=zohoarc; b=lcNvqwZdlb+VAwqi0rEhtQ4CZdQFaCmVUah/iQmrdjGWyS3LBH2+KEJTODu2H1LjbDvC/7YrJDc1ywybSgWc2k952Lc3zdKMMnT1u1U/fR57pNqRUyxwl3LK0o6RMQ8nY5KRc+nI+akqt33+5/n8JJUTK421gen3lE+F1jAjY3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880187; 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=VcVbNrMo78UvGMTGPzcAl2Ji0ZAKGd2yGtKSEdkXs2tKIx0b6pWrQAwXWJoKj7/KKSbCtZG7Mhq4BbJ6p+PikKKCftQ1sbl21HKWat8GY7O1aWcRSEWDJfeWZsNMRbYF9/rM1tzJ3rzuI138tOz3ASFrSuvk7LxgB6ECEh2SlFg= 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 17788801878261019.1581704483193; Fri, 15 May 2026 14:23:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzwz-00017V-Pd; Fri, 15 May 2026 17:20: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 1wNzwx-00016c-T9 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:03 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzwv-0002cs-Od for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:03 -0400 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7e4004a4a6fso336635a34.1 for ; Fri, 15 May 2026 14:20:01 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880000; x=1779484800; 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=FOofpqmMUBBL30RSrKRVoNH6SNNl5V5E8VI4mDIZBq1pb5wnO6y7L3PP1CxKMAsE+o RPgVjrN4ES7Kq0eAnuCelCZFHieFoVAlC7wXh/Av4HNz/PX4Z5HZ4kYou1xYjOBm45AX BfzXHxb9geF1mnJdo+vk1DD7V9qXhd7+hFcsT9hLhIFbmuxU0xQT62NcbXzbjhuu5XXH gI98meMd3T1WF8ttLv2Jy7QLPh+mrYbNcqa7zWkkK6KLlY+di8dkH1eYoZqNLe8rbkX7 znu17SWaP3or23RMBTVvRCtKfSX6yXE9CybQ3AhXzOE651tHqWlnMP9NAkqH9CnFwHlu YwZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880000; x=1779484800; 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=mXCpslyLM49/nnMAoViQc8WYGzSEYg1Bx2efNnhDVW13PTvHXaMqWEV2sSmM4h78We IOhPRgxzGBPDP6ZVk0U4F+fNM8Q/uDiFhCBcqkOly49XgkpLsKr18GHo/ViX1mDIV8bA dLSMgtQfJmZlfAJoJRktLWsCOoaj9sR591D1aDpLUFNidFE+NhfnLknh5TnNe3sdY0Ei gI9XoMueOnLpRPqxvoJkXVjvJ7o3rWA06s0SqEcYAsJAHvutWJzEyZ1LIqKV7tlyPoOm Y+zuX+2QxtAmOysGlNv9JLwGr/3JVogstNMDaabK9zIk2nGHtCNsbPK5roFmtceBaOXC oxEw== X-Gm-Message-State: AOJu0YyzJleM43LIVF5iSfugRYlqeeLjlnpUStN6N0RvNJ0HaC4XoArh 2ayVhV2SGwLr00RzCHt8SvaO0/Dobs7XHeJO28nOPVmNafq37EXpBYXTicvg35BauGOUaSgMomv RCiamlT4= X-Gm-Gg: Acq92OFRtXwv5H3GU1vpBBqb0vjPxivLCgtegXzI0rW3bNSmxc2+cfXCMxQEX/PJE9h UDtV9nvE5+dW3Rzt5a35ho6wEOU319Wogg9IXBms6nkSrWnFWEF14cYTIuRomb6/LGCV3qKSoBp XS8Ok4QnT9NY5e2ziLB0XCt7rvsZetAUYyjpLCekAe5rR/ELici3eckXFQwgtNo7a4KnCCxljmR jNh7CGrLGTm8aWb3UyVqqEtXGjo6dYFZsZWAE0YXR3ZRUmIbsp1ArdF6kMqGFce8s51nMwHC9Qa dbjXFiqKYciHJfNCenRT+K2h4UsiPQKeerORg1jtN9WjWNan78YqcKMuCeN7+ZkFW/4BjP6WCv+ eGMm14kMaJ4jSKkVFUudUhWtbFFWAykB9yNzY+kt1+WnWNQRF/s83l+6T7v+TrO//ED40sqh3QJ JrU7C2HtKzVDFvvV386Aft X-Received: by 2002:a05:6830:4489:b0:7dc:d601:a69 with SMTP id 46e09a7af769-7e4f2b8e71emr4248089a34.20.1778880000642; Fri, 15 May 2026 14:20:00 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:00 -0600 Subject: [PATCH 01/66] 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: <20260515-misc-2026q2-v1-1-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43h29+NZ+VZeC6ZgQiJn8HpXMjhksTZ4/npe mDpleXfM3aJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR AP2XD/9Qc4PzmAM50SMpjsI9xuJtUgNDxlMZm1xVVntUSM0PGjD3PLJvtZfF5b2/h77Vov94s2R aqCoEP1vwdb9PHaKa2Wdrsk/cOWdkMqhAAyOKk3fwdGCTzVL/ofT+UPHlxbm6gSWisT6XGHoVYx kdjHBRVjaJwp5anILU4KhFZpiBtjXwoWDdMGek+odCfqFxRjvHhS4kDxWCSv1DHRzrjhZiO2bbm vIgmVJvJI9rgSl1ClktO9FFskMW3P+w+wcby0QDgTfbjLHDPM9Qpi4GfrPaFkXzRFzBzH807Vnb z0rmI3DZyXTfWyCEVsnp+fwyymCM8+isjT609Y9P1xF/RzgYTiIyBzOAWGIWCFTfYP7tHPUcNSX jOldSJN/d/qkmIVIsMuO0BOPNg+jbArTkonpxat9Ne2MBgCj87jlyf7zdsq+EZcb+uHF5OjVbkX KILUQ2+KCxFvUVHccjpoyzUCM/WZMNanOSJ5fT6VDO0o+Iy2gkc4vsX8q/H9CaSIuwePwhZtTRK cUAmLpyM920+OhSsFDDlRLt11032wZ7ItKZteE1ZV28uZ3hnlYjhSBi7AjYGBvu6dv/M0Ja1XX6 e5O0Hd0+41DpCpNx+DC+E5aIkNqCyx6K5/hrn8iQVHG8AoacReF4kzqKULRirMSu+ksBkBwEmqU TiO8oAmMVLSv8GA== 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::334; envelope-from=imp@bsdimp.com; helo=mail-ot1-x334.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: 1778880188516158500 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 --- 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:06 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=1778880336; cv=none; d=zohomail.com; s=zohoarc; b=fQAlYixUgJFviSpULxuLAyTZlZEz7Tqs/aP6Uc6P+gUt6lsFvu2jGvfWa+K+LKVYBfSihg29K3JOMNlUdumfKhKlfxEcZpQeDdjHH5D55gMmynMQVtu/hh28OrMp7731UFy4ZnqBz3IrKQwuTOOuV/E3gV2eReu5/6bSd+95cfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880336; 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=Ob9GjFJL2kwW4IUJ8HBrQp5gIx5uvT3sm5em9WMSBGVyHz/fcx7PNs+8No4orOcc14vcgE0fBT2Yt7oGP1yPVxqW1C0FCpdTA5hcBOmx5qF/kaz5EZvtI7HGw6iX+t2HfpG9724XspvABlTQu/qtyhyhk7S+vhjM2v7it0wL5As= 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 1778880336331185.6478878613084; Fri, 15 May 2026 14:25:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx3-00019G-GE; Fri, 15 May 2026 17:20: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 1wNzx0-00017s-P1 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:06 -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 1wNzww-0002dB-OV for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:06 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7dbca22dbfeso156019a34.1 for ; Fri, 15 May 2026 14:20:02 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880001; x=1779484801; 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=DSyZkMeJkGfD692hWhZWzcSR0XRvze8QsSBgUplXOwGOBAB1hHsuu7++CYwdQ/pMYR fI0G5FKwnV3ognRmub2scppfc6xbR8FGuIziMl84JC6qTeL60/FMV0RHhgIZ9laZHnua vDSxrBn1LWmapAamg0dsd4wH1W//QwRNJtTvGmVQ0mU3pbI7cDPlCyoCZQRJJ08aAq7A 5KAxHDUe9Gv85Sy04aZmCryhIDafCBOz8IFtQPGCFE6nX58IWKJIk7+7W2VOuwOAyXqP KMRm9xsG50bt/3ui8r6r2iHbQTchUFLlWlBOhcL0IcK+rUz9PRrU2oRYhcGjE5SEPA5A SIJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880001; x=1779484801; 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=EpMvxLsZrCeyTq/jj0SvdF/3Bo/wNST4P4s/p4oXA1A+9sh+yR3q7stgU43aakzt0V YedfGkwwo2NKfLBP9BGYqcKe5sOMGi3KjZVWiEeeYsOHwuKYOniXpdpoSyMJK5ad55v0 4hEYbmmfm9m1d8M8XETYxfLdoT99GMh+QctdvYOWoAeiV1RM3Zs+HE8BNtmoQLPximkw ajVvLoMmbHUckSNiDBQhTpNnT+yCmcccZTYqm0seX4/EsZnHyYrwBU1hb7uQJKsX+W00 MrlUoRw2dgHFTcJcMKVF0+HxzxOPXfJ8bbH0KIlH89QE1IwatnHlJwmpIMZQ5DACUdPP aCYQ== X-Gm-Message-State: AOJu0Yw9xCJiobKWSexR+6eT3kXDvZ7S47ucH8wTxvJHrEO1L+lqM7jS HD3ofvLnrHAB0RB/Bqaiy0YSXn9FV9tTds5bUfSSKNyEop1CkMG4dqaQAo5ax3muUzU= X-Gm-Gg: Acq92OFj5iy0j3BihfQnDz6yQA+OKjoOr9/tULaCLJ03Tvt/9Zvkix5EGtRDN+5/zZn Ix3tPbRf7TshRNaFr4gZEzwcdBMlf50RvXX43G8nG6YiLZA73gQo7T9sLUyVfN4XFDJDJbWR1PX pqMXx3MDJH6yO2wPcsqHoox6XEECQfIpL1MttImXjTncSuG41+TuEIGZ9RyoISnB7XlnXpqLkYd kn6b4NvXvLmitXAwaR2Tc+XhssRN8DX/Ib80nmfArJ9mAjW6+gQddw59BOp7x53JVMrl70p+B41 8ZZ08gLIYuY/H7H1RPAC2/DVBtMuT6djnG9ZHAm1aFZldHUxlREoOpmdm7BBhDXGU6NquQVKln5 tFJK/Ci+0AoHLEsWZOb/YedFK5XwNl6dKDkwnx5hOP8meJiEmgxVnHTuqgtQIvM8th3jI0GL+14 U5hZdSdW2USw== X-Received: by 2002:a05:6830:2b0a:b0:7dc:cdea:7d4 with SMTP id 46e09a7af769-7e4f2a433cdmr4287449a34.11.1778880001506; Fri, 15 May 2026 14:20:01 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:01 -0600 Subject: [PATCH 02/66] 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: <20260515-misc-2026q2-v1-2-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=kA0DAAoBbBzRKH2wEQAByyZiAGoHjeGiyEDExJx7M7q/pdAq9vLgT7CeBPmuRcXJiNtLOZlYY YkCMwQAAQoAHRYhBCA1+JSwCqPPfM3ht2wc0Sh9sBEABQJqB43hAAoJEGwc0Sh9sBEAc+wQAMMt h9hKhLewqEeNrLMDRtDkPSF7DyR7R9vIRJCk4ZOsDoaZfPpOeGbChJnNI8Fo/0uWHqANJ4IWfrp YKPqnoquqpOMZl1BysyQ8N6GfphcBXBLrx2xSUwtUhJP0vo+t2nsdmbk7+pWd7BMSfCXSoDQ6cd 1Gnj3izTJaudHU0p5sU5YlymISiX3viT/7j+iTtOpZ0+5qHBA+4vo3tkD+h/Tbx5GAmfa4uA0g4 gCjhBJQuEMumWqWlVRkVLePNhTWicFRo3OoDU/RU2B7JXUtHxr2+KkFib/iSfZR5SMqcB5BGewU lSNPyN9DjJRYomkbOcSPDZYpk8tlbbkviVzQJPpfVD290v2wylPwpBaasUEIQEPFCSySo2SoZK0 vj/7v7mLsf+20nV3fmZMB2bVP6pw8tHEoKOAhAnbB9djFQDQmlNX2ZuBlnk+NExWFxSdAhPjw4l m00IaqI2lY5gPU0LPoUkQrCkl8hHRyXsXQQtWMpnlFiG6KkUz0LRU4C2VEarREUDFlVhF9a8WyX pfrKkCr8CjkKiDZ3kgtzvpnMXuoKcHjUW31iGMOHyrEHra2R827q8vL5g/Q14zSX2ct/UxMo14F XWLcohEFUObmPeimd1SgIy/1TXsRwZZLqpmdSDa8Cvnkwg39gPmiNhn6b3KnrfFjrueFkQb6IGt sb+fb 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: 1778880337663158500 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) --- 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:06 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=1778880226; cv=none; d=zohomail.com; s=zohoarc; b=Sy6al6yr2QL5lZ5ijfwxCyGAdVbhgBD1fo5agATVYxAB1Q/tXTovO9f/VI+BTFDszEb7FLZgNydmpS4ML6Qzm85Zfnfsv8E4ZZ6A1NQbcDIbDdqceE0JemLCRzi+BKB1crLEXkZ/JbylgYMoeUgt4P//Y7yqj3DSCGWoDStw46k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880226; 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=a60hp1dWf4eFBFrwG12fEXtrHfuIhsG0O5ntFeHEAEI=; b=A8bi1rp/NbFYTIgOgf4rnYZW8o//C/lHq8bWTBw8/8Wesm0FA2r7r3prnCOVkJ6xVM/Jy0UOo679xeZt9eb/XXindk160F6WyGqVXQLtaGjqlohTdg4h6aVMWS4zK2AtpUrrrAhKmQxskzRzwsTPuw6oyZA64YB1sGgFUOjComg= 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 1778880225959688.8017784010892; Fri, 15 May 2026 14:23:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx2-00018f-DY; Fri, 15 May 2026 17:20: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 1wNzx0-00017p-K3 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:06 -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 1wNzwy-0002lF-Bf for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:06 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7de46b8e432so377125a34.1 for ; Fri, 15 May 2026 14:20:03 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880003; x=1779484803; 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=a60hp1dWf4eFBFrwG12fEXtrHfuIhsG0O5ntFeHEAEI=; b=DwuoUjAnBsAHZpaL3y1M5n6Z/Esdx1j7b+yi5J6DZthuDpdZl+gaPDWLg2SRlhP/L4 eCCaPVmym/nIJzIWUpbdzzo0bwJqoaGaFRSe0FuZy3eXDeYfNsGh/ba/P8u64LROfCZu E7pSzbzIahUqdyjI+2QuvJwR9h7h/zBiOP73P7Nm+u4KiQ7RyZKK/8K9nXf2X14FrSm8 4J60YRiFJAUG16F+7b/JoUjfiVgqAgdpdIkk1ogdn8ipzlNvz9AhTgpGavWrw46EMCwZ sct+kaZhUwloyubsoRA5KWgogRr497tzxtVyfpLgR8m5I8r5uQGIQepf+9wJWTOORSUi UvRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880003; x=1779484803; 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=a60hp1dWf4eFBFrwG12fEXtrHfuIhsG0O5ntFeHEAEI=; b=X/R28QZc9xXnubgLji4mAcRYQCPZ9fNR9p9Vcwkyyr7dTCL8pT5ta9KBE7JDxE9Dq4 xS9ORkDhIfYEQSRnK8rfp3q1HAezljOr335XJtF6hFWltVAuK/aC5W4vr6BUoPOlo3p3 vtCByiuFX4Ck785dX8aoHs/U0dyvVhR89mS+YhMRw8BsjxgNVAHrYrAn0BR0ZdQhJkJ0 RqArfY914KRvTqyJgs2BvrgpfOunY287B8GNol3WxRiQCi3V8gR7ij9GGIGuaCOoJKcA vPwc0TjuKlyRjPH6vHCdG78V+0cJZjE1ZYgOpOZCzvUWEJwU7GSSMrHmqdukjaVWelG5 xrtg== X-Gm-Message-State: AOJu0Yy2nvHhVfud7TGr3NDJjnyVxHTqZZ61kQyumrN5X5njqILM+k29 2rKNtnK38QI2O6Obcfjxp9AMx4spYbVvVf5qxVUWaHvbk3IDpQSYjRyQ9pedGPT6YWk= X-Gm-Gg: Acq92OEpAVdV5ttpqYQpJ/dKsIjvprilGp2vQORc4/dAnuCfjXsl8aXbRs+DwlrDVG4 daeXFCK+dsVxm+nZZBsk+x3wwjIe4ks0UltKNWhf49ENNaxB1ZYgHDYMvjiRGqEh+AfsT+XiNvb SKH8yMKBPrhFZa5XwJ+0rbeZSEbY5VXyjgwty5npwDacwVWT8EYpFlxxxSsRAPUAjj1XwKyz+cI LGnIZxvSzbWu6mCygLUx+X/YEfhuXoUw33biOJQrOftqE6DmiJO4fLdJJ4EimjBIUC0itXr+Mz2 PEyfvEmaBPj6kcnwDYP8NHb6vh+cVVsT/ci+zNUefm9q3kJJXCxNa/iL/uQ3MumS2vIv/zq8rwP p2YRwtSqr5mfy54qja0FMh8S4bge5g70w5X435j0JOpCdpI83/as5GIdWM2EFSL+X0ejXr92SGF pbqKVRmd6OoDBvTTS+eI5a X-Received: by 2002:a05:6830:928:b0:7dc:e08d:d9ec with SMTP id 46e09a7af769-7e4f2b24e30mr4239780a34.15.1778880002797; Fri, 15 May 2026 14:20:02 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:02 -0600 Subject: [PATCH 03/66] 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: <20260515-misc-2026q2-v1-3-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=eUrsSwz/1wp5sSzubNugfDrEiOHWJVZBMoyOulKj8eY=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43hky3oL9OyJENcyns0mztbZjbURUCvTZvTU HZ1mdQ4CjWJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR ALvND/9LyXrLJZR+pXS2y44Dlfwp92J2aHQCuydji5Vx++xAMDo1VUrRPeyd3WXfgNmiqIVOiwZ 6ZRRsnNUOmrZOM0BwBMWTkxXl6DBBNKworwnCoUw5tpFYcj9ez7rpAjI9smcRThwxJ8RK2B4Rxm h/FfnfglLrNY43QLhW3JfIloIruv44APZHCYz9/Gi8eyhB2ozHJWTUSckR7o3jYasC2IblUEanI qy7s2okwGiuQ20O7l2swutyoOjaXy1U0w593WlRx0wK2htbGfT9YD2nj9E9G8XoDPMGhx0YzSId lkEZqZd8LFJGoRKyyf0Yf9ps+0t4bdKYQTGuXSH8GwFwuwBYIACmdEs/kha2Of0NQCUAF3kG29o 9s6n93FAgZ1fTLvRPdgJT6LzMEF2l9vrTeyUg2v8KQjpf4JGRVMGOXjy6L/uFXxUJUTLsPUSi/P Y8HA9UNOZoXCNDc8WXHwEo9qQqwvKP9jVdPWAA1cVnQWOSMefbmX+IVOvDdDp6TvY+o+BgpeTMA eDWp9n4HrmjcCm7ixw29ZFVa8xNQeYIQLeP1wdwJyesTP5a/zGBa7JFjMJBZV7CNnsQg4P9WLI+ F+1WU1BpFKTIehkcbYpR+afyQ3iWGMgYxHybOjd0TEucjWRAYsDjWQ0ane7W1jyLveyyqhyuYXW V5cnMLquTw8aFaA== 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: 1778880226870158500 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) --- 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..8ec206256b 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, 1); + 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:06 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=1778880050; cv=none; d=zohomail.com; s=zohoarc; b=HiB2dLIp/cz/9zTrpVUyBvTXM9u6sIz+e2B33o6Oz6yFwwDBgCpDCnNL6fgm2wgS7LtRuLzZGNFHfhxWqo/kPreqTJ9oYrk98V+UTWwnYWbcBx3+BXqd3niRvmJ0lcg/MZTC+6kTnGUh8BFAiid+sVRHMx+lC6WTwhfzqVLbm0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880050; 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=PNp4xD5EnSUKJC2d0Y8G2M9iexm0cMXDMo42B2lYe10q1XWgsGZBUlWojsSDJp4zKROcL+ln5f0waFRh2bjMgwHfmtrbD9XqS81dFZZwyrFLVU45BBvJ2cwZn3zN/SZ4U8fmOEv4EHYEgN2OYouN7rNymiqaP6hpw5E0S5mf9/U= 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 177888005091559.68146360669459; Fri, 15 May 2026 14:20:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx1-00018K-Sw; Fri, 15 May 2026 17:20: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 1wNzx0-00017r-Ou for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:06 -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 1wNzwy-0002pV-Sx for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:06 -0400 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-4670464029eso238271b6e.2 for ; Fri, 15 May 2026 14:20:04 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880004; x=1779484804; 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=AErxRRDXA+Zne3Xla+ex19JEWkx3XwANLMcNKT6aLdWeyqLVfbwgGZCoqwMh1HRM+T urAHc5l0ybS2P5GlXA7AAB+1nZHs2ssWr1If5hbKrJnXseNZF26HQwhPfL0XZA433QBp HC5QUVZlAJHgkO5hlcQnqLCFu8yUnolKo1P8QSRTTl9kLTCs7cuu+HqWLtZrUXdXb2Da pTosWTagOm5/0LELq9AF6M7hCLxBTksBwOAWXWlju8AQYF1Mo7CahAQlrp6/cmR+RFsj BlYW3z/TNtb8qW6ZFJFhRTZhzzvGdRsiVNzvIQ4jAVCEaRVe3jlBtHcV4AjtITtXfcKw 8Sjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880004; x=1779484804; 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=shVpS9hyX+sHyYxbGNltSWva5DAxE0lyCUuSsYqup+gqLhYQN3K9A4Lmd2Pm7EUEaf I4ayHQ/DloqVVrbMUp0CPiV5AEGFBGtSvKYK/+0Bpeluc/XLd/CiQHt4Fdyyq4f845wq 4ze0nikuzjWWYVKc3nvaj+WSV4GVl4xSG40n39oCrTFkqc5n1BwRI0+0N8x0KnNBEqXt 3Mr1Hr9lS0zQ9wX+TaYUyCq/aQsRAyGTxr1YynoO4I7p6EFz+5i6snqpI2eX/T7qjYST V4vJkykucicNsv9t4kl1T2MCE5z0ErhrQT1gz1Peb81l5CQC63qwBOEuGjjQt06EaPMX Q56Q== X-Gm-Message-State: AOJu0YweTTE+EYNsHNfmuAHXciPVc7HXOycp6CdlUQNgb1pblroq+wm3 SAdaCa3n7EPSNjmpmU0q+Lu02wCxK1oD1Y3LyMnE2SKqbXtINLhpnFDS87kuwTOdx/c= X-Gm-Gg: Acq92OEl9zXRzwR8h3j6Pz9c31w0G8EMal3h5uLm7tKu8dTki4qP1Iy8rv6U4h+zdgN ykvBHQQX1wFUifxg7A7asWsOWGndCMVv74Y3uZyNF8zRuHEqk3EPQzY+5V0FhfJlkgwdlVM8ql0 FmPMWXHT/jR3KHYSV0Weo+QrnZcUoxmrOUgCqzOQLHWty/tCMlIB8p8h0I9N1nVC0LCh4CD/crq JNFl+2zIOmtY30EoZ1JRjczDWeYDUPmzBYwNXDZC0A7g987d0mQbHK/kWpGT8t4kyLnK9wwIB/v 6kDisAITYRgOIAcnlB+vv8qmRPxTdywcjbwj1eR03wjNSNHcTNLXhog4RSu8EAb0nm4jsa7KDZe gUGBOvwjX6aR66OdlsKoMUzHOF88yYXVhpHI2UW+/yUul9eJeOmPWBL06n/1dDRw5ePArDbWtD3 2kbFZonZ3csP42WB2qV8Dy X-Received: by 2002:a05:6808:c2c2:b0:467:1e5:6768 with SMTP id 5614622812f47-482e57c2044mr3876315b6e.43.1778880003673; Fri, 15 May 2026 14:20:03 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:03 -0600 Subject: [PATCH 04/66] 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: <20260515-misc-2026q2-v1-4-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43hchPrzXfGveNPfRiq97I4fx2o8GPHh60hi jUJwNUTUH+JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR AAL3D/wNP+2TzFOjFl3/aFrBaiZcV1pGnZd487Ybxs+hzGoapcEGONbHqiXpx0LK8TWW9Nh7nSR /956AdD0u4W0LRiFm6+4DMFLvMVOBS9WEuq/ehw2CK4EfqlzRaTTP6X2Cw630whXr9iak48GBF+ cAolF+0znbBkzz6ibgP+ulkGFJkDc+YiXSgm84qJBIc8dyDelsF7Uxfk3VR/7dI/u8UBp4+rSKA zsHevYSW7Xal78GNek4s2vom9h+kQeE0Rf55vyR0FODqHaqNpfWWgHAgmkCn3cN5v6EDla+F0sj ICKsGHdgELKtRrGxCNulcwioO9NBWv9/jm4STKWVg9B19umH3LeKU1gVhR+MIEK1AqblpOIEuha WvC5vKJjEAyooZJgpb/3r28oh+HSpYFvkGYkcZAYs7gJZJZViEHjPUQ6SscpO7Yia6xbCtbd9LS P8En4U9MillZjndq7lSBmxZjeIG9TnpodvFvgeyJcS+gZpXBxGAjJ0duZS0ECznAyXxwdNatNb1 9lN+iJG2VzgRU/NquyBikts7BTPTwbG66j1RjU2Z1ASZ3q73yc76KKjwDEJ/jjege8i10e66BGD gCgHVKfcmcAna5meQn7r7bMEbKc00XhSNI2KPw4fWnpbleehJZ1TNmUBrFoQt3dE4mouPrcmAEE fbdcutsUnVxsl8A== 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: 1778880051770158501 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) --- 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:06 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=1778880117; cv=none; d=zohomail.com; s=zohoarc; b=YT98KSzDueQHsErcKUbcLXzQbeAZO3Mk+AYfpBgrByPaoReMCM6OIX+Lx/cbApCekrm4fvQ5o8A+vJCvpw4j3XOoNltJis3GfoLUcJpYsbKFYvi7B+g2RuipyaBCyNDUamY+2YaQi1XpOFELWftK7fV9RM2Mor9kqvBbuDhab6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880117; 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=fpvjsBNRettHs8KVZF5WQ0BIlmx8deEFvHLcXPXmReUwINtznvziFY6maro2ql7LbGPyHJCnhcD/EOda+VRpK1qBZoXXhZoCGz/Gt6UfgkO3XoKMW0aSviX29bv+yDvJ3sLK3P8keZ0qrcPrCtfC3NcQHOywLG1wqJ7Ow3F/zBk= 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 1778880117991258.2017306924313; Fri, 15 May 2026 14:21:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx2-000191-UB; Fri, 15 May 2026 17:20: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 1wNzx2-00018Q-7a for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:08 -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 1wNzx0-0002pp-1j for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:07 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7dbcb467f2bso312692a34.3 for ; Fri, 15 May 2026 14:20:05 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880004; x=1779484804; 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=hC/IKqshTSWwuZnpup/d4aynWXWqi3/Dws0W6Q1eZMH0G+H0m7CXWdJYLxN4aPammY JaO45vx1Db61l19k+4TysLx/62aJFCbpU2FyKmmzPpkHhDwe3RHxSQYWnEc/ufpOFLqf NjQsfewoKZHn9KedNP6AOAmtixOSh0rN31PnIRncxLcq9JgbLWpwz8B9V24HVKr+310p XCBCInqRD7DHJcervr6rgJALZkgX1/4OA/FYfHpoaWMw9+Cps8lH3u6sUxJXtsB5ozqi bsAVsV/HM45Wg8o/Nr/cu/SoXMBjhBq2NCYw9MGPDVEuSDFS0kCsgC5NTOzMFRouHq1O ae2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880004; x=1779484804; 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=BZj0201r/EQhe688nY9KwXlTnwAibBrJ7tOI0WVAvFs/4fI26QNE4Yj0l5Skf4dqTQ 97AT0XhcK1MfIvHAkRbsZDJEECu97bZvJ7UEuIuhB6zwDd8/9vr4QO/fWBlVeMfIY8KT UEIZ+g/xQwGZoNpntYmbvmDcScNW2ki5u78ArF71XJUuPugbhtAJt8hqgNi8vNFOMr/i Aj/RRz4Ds19ZR2H7V6B+BFsbUYvLLNr0P7DeE7xZzTPk/6FwwKO1l2Gn9/hYpkrRVckR Enyp/LbIrKRZcGK8zqL0mZoZI+DGLsEAuTa/uLod+LS2vy2kVXUkQjcj5VXMdYAd2f9K x8aw== X-Gm-Message-State: AOJu0Yz8jpwsMzELO4U0M7AP2amZV+/mNRhBWq1TI0aS2qKiiSQZ5Csp z0tHRCwPuo5i4h98EV6cacuaeOSJo5Uua0Zln3wlsNGf/ism3QRTNRRpSwUp7e4ATEM= X-Gm-Gg: Acq92OEdGgYI5CPy7mOWs8kodOfNOjX1OjVb6Y4Dao6U2Qt+rz1h3eePPH7492CdyaX qwMZ1cj5gpsCJNowXjcymKnXaMlRz+zHIXsWO5fsvnWlU+PgkS/F7uGs0jUU/pa/VGbYSCa4hUS QPumzaly41+uBrBmMU3D7ZuRS7uiROyLjaoRdfiv+jM0NGJfo7lXuojmRJ+5tQjbd6eg5F8fSHh A3RxEqAfCTDty5+RYwkQvoPTEUzEZ6ZtTSx2KH2sBnFtReVWFlciul+W6vasawulfvHhxEbrjtR ciBndz4yxUGmS5bvTXqfxvK5GZv9Z7rgVg9Xa0tqRPA4Ur8En7ifFv7MPddKDzluf6fVVHa5dKb f5EPeUg3mr6wPVQbnzs6J5mRdhfkxNJvdeHwLyDH+CmTCjE+SlV1trhowOcI9C4oBulaT+bsOpd HMqlPRqECUp0Bq5zfxFMnu X-Received: by 2002:a05:6830:4410:b0:7dc:d679:3eb1 with SMTP id 46e09a7af769-7e4f2bcccb3mr4224898a34.25.1778880004606; Fri, 15 May 2026 14:20:04 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:04 -0600 Subject: [PATCH 05/66] 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: <20260515-misc-2026q2-v1-5-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43hs8stSkN2NVLsZUQQ0HDHTah7EV2+IFOet D+HPQ2B8JSJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR AI73D/9mot0b071IZU5hPn57g26L8ehWdK1ESiQ7UaC5+puRDS1SkIUuyaSg02W7qsdsXLT2eHK ANnFihPxLcCLIsczAC+Ecjnecnk4AMMes4S6tW0vTHRSmK6Fv2UsMJ3/NULBxASExV2Tebmgo7N u9xWZdoczPNUJbRMduuCqmYezmqBsZWgrClgd/1i4wu7TIEODrc4koGc1qSRAacpWVqWnEcArgk x0muvcpBILSWtZnfAEhbSmqecIb5ZoiMPlDGEPZSYa9msRCKqSo6gpS+r1hmvxt2TLxgz6qrlOA S6dxZPCBNhVU10Xz43LtXfa7Fuc5OM6IVaa0WvqZ9bqyBmD4ztOONxtnolmA3d6Fzr6Y2dQmIZQ iDrPHHCNdO162iJZFxc+ZqDaUbJEvIt7y6LumZS7f6nsoxJT6Q2idOAED8HQ8MeuGbBRHQAAwfm ppu9HLBw8A8IdW/Ke4yCQWzKZ5arGZeW5Qyfr2senAUGijzy+rhp2IWd+tEN6IF0NFsJOOOfDnY /BWdrAdi7aqyE5YpuqCcf0ik5wDW8d0xugY69HburDCzx5JklOvG2pRYIAfAG/0Q1fZQsUcUOuL ErA3+ubQYGjSDnNk7NOuQ2P+DRiEspfPGD2B9CQ5P39KkXDl9nqUIadFg9bYqXyg8PXAZvObuTb 028dmnaZEnci8Uw== 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: 1778880119991158500 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) --- 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=1778880262; cv=none; d=zohomail.com; s=zohoarc; b=ni6FmIQU4k5poyZyfNR2eolUcICLObgUS1cHS2jAkb/iQBgL43qndgxyhqeMh2LorDolyZHvMFJd32ad7fIDUCSh4hp0CL5KXocG3MgpHcqD4j43zHTfxDvTDIi2/H2o7ODwFj0ALVAuwxP1ASW8zHqHEsszRlDIhnauOJTaJ7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880262; 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=BooZNnRdWQrlMR1bQDHDYaEv9UaFfcsdoKpIuJinjo/iIMmoUjYkc4zcAqjMI/H+RkWmqgBoNWkI4D1iMdVF5VGdIvOsqu46PK2zjI7SC9XJgbX7u2S9x2DtRIwctAbTCXmTtFvBeOepZxXnsWN8m5yXLzgCCX6mDaCk6OjL6MA= 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 1778880262167173.58763291399214; Fri, 15 May 2026 14:24:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx6-0001Ag-F9; Fri, 15 May 2026 17:20:12 -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 1wNzx4-00019e-HD for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:10 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzx1-0002qH-Fh for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:10 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7dca00c1591so111968a34.3 for ; Fri, 15 May 2026 14:20:07 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880006; x=1779484806; 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=Y6szCjsoJ5Qwj+f8TkdNefIX49HDV39gixbKTq0cn97RniLQcSleko7WMH6nC4t5jI g3YhFXfSQCXrElm7Hmj6h9eJcGq70WLjMRt2m6+l9QW0AyEABdpF5nE92pYiG3k5D7aZ pRp3KU9loJu6uLlIgQzl8DsaEcx/GJ9GLmW/K0ffNl7ZsqVacklRQGybBAIVCcxc5KTN Lr6hFzPr8PnCXbR+g2Ff91k2VDXvH4CUvdDLtJhrAw3a4/EBSTAd80rewis+U4uoEevX Cz6LVIuU/CLXokkC7nrXXzvBKKz07mBFyFa8dvvOdQyV+prJGJjtMSjMyiDBBvJGf5g1 zO7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880006; x=1779484806; 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=YN4eIQbMVgyud2wpxis/UiRwrvctkj/mPIbmYOYfaQE4P4QgILjKC+C0sWrzmKVV5L NBxcYqhyCrCAL5LpmG64/BG3flm9GpizllMz/oUiRmqrhR+VcGLtQ7NaKq/TGlHarZJq aR3heFnPNuFglYPCY4gKL+JdeU8oeN+eHoq0CPSStJw/WCl9ushfg1nJtzqUU52YBIPB ZYaoI4aaP86tcMpDXAqPzzOj/xzMnmBxj9qOHKhlfWY2B1yqN5CQkrE50XMCl/I53cLl X77D2janwvsnLFEJIdioA6KvRJIykCBKGPjU9Y/DD5sEkdlVqafW/xaSUWwwb+KriORG RSRw== X-Gm-Message-State: AOJu0Yxn8zYaCVknlpxqvLlSKCZ7XDccnl4Cg55D+UeWGq9LMiqIrpTf T/4CXus/2XWlpAI/Cf5l01tGNvaBHwiqLkqVBvDM1YUP1pYXG1PtwM3Q2wVdj7T+2aQ= X-Gm-Gg: Acq92OFyKkpZ8nfMsLT33sAqTuOwhgvwWtX2OlCdIzSgRPWgPUqM1T7YnjgppJ2tYj+ p710BgQrT/D363bdFP61RcM6bDlPuAo9gtsPx8UWMVnOlkBWPKmZI9OdGiHZ+gck1vywuTPkhmI 8BB8G9oMH2XLh9AZjr/N/ckXtr/xTC+hr1SLB0J4sbs6z6102JCrLNme0iWdkTlYcDDElo+vNcw dJEXO5a5I6cowfEgu1G5kxi5Jx6qXdZkpzpcOArU/5GRkZUibPfTzKHgJ+8rRc4AfoFJpCBobHc wrCXQjYB8zXLHXqEgHZE4NE36ed87+B5iKO7jE/TioKqN85bLwjhoAu1FJVMDUgfxBXCgVx8euO v0lGJKXXRs4pp5RACnmAWVjEVeMgWFfDsLW8wcmJGP4OvO8eNT13x8H3vBrVdeu1vUoFzU27hR8 NDQDJNWzCOyg== X-Received: by 2002:a05:6830:6614:b0:7d7:d615:3040 with SMTP id 46e09a7af769-7e4f2b865d1mr3960151a34.17.1778880005729; Fri, 15 May 2026 14:20:05 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:05 -0600 Subject: [PATCH 06/66] 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: <20260515-misc-2026q2-v1-6-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43hHoLXxKKHpPlTLnNyoBcYKkfiI+LORS4KP vRKhco9bd2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR ABWYEADNaNSwTNR8OVXqZfmDjZdQkOUHUBlrUnA4eTWU5UJyrn6NvAYCiWMEwJ5VjkLm94Nhv90 tuT+b3rDJbu3Ke4Be25eMZgtmscvmxcyzfm2TAVM+EOH8JlwqiRreoNvOS7OGvZD/Lyrb76pGL3 HZKbxXia4LUlrw8XfBG0W5NWB9OR/4IDqKGPU5zC9kZ6JDdgOL32t+Aaxfbr+oz6JV5UKZ59LPe khKGMqL6xFDcz0MxYfljHTftVikR/LxLSCsWvb/TEIEutCdNSYLF+0tP3LVlRVvVhjZDSJyfkV9 +77XgEegF45FUb8GLj39fY4D7N1W5N258do91hGZJEGYN+9LmA2iB+unX+5SnV3cxHBmzvvkUsD HVd8iDoBedX+wr3D6EK62diawJYXTOT92JZC0inbBCLf7qbfjJt76i3L4MxY00s3fpUDC3/l0lR jj0+JVfZx6YgrUgfHz2eNMGVdcCR9h/SWkoJImMIgul3+cyePSunIohoyZY6ux6ckwdRbdlxyyZ zw+E2VFYWmIEL0IjbYBX5VhAQurDa1mKgSiIU5plwIAvKo8put4hSjc6nErgI2jSUFWXE2JADFk 9OBXGs+EUPNBC7BcCeZBVE7rjBFoz8gKwkiVIx+yJj2/e+sEHm6N7Mbzxgd4Y9IPFBVE3Q5AHLy QHCQgSxDYuFgFng== 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::330; envelope-from=imp@bsdimp.com; helo=mail-ot1-x330.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: 1778880263059158500 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) --- 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=1778880080; cv=none; d=zohomail.com; s=zohoarc; b=iv6YzlLY/G9aLWscN1VbrwtDBsBorLV9n3in7a9jLh1wCE1ZOkM75fBYn3mVrNZbCkdNzjCb8slt5mOereYG2xSBdRifxAbDunY4rXRS+WYTkR91pG5u91QkI4C26dSBjkZ2m+kQ3qti/PJfSyJu4mzp8ZaqcQAomSgnU2O+2ak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880080; 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=oBAWkkIXQwxa/hU7AI/aeM5McIKkTJKsiwHaCGzLE90=; b=MBal3O9imBx4Dup7usomUy+zGYx8XZMBZ1PFlmiKI7PugiqhoGxVOuk+iA6bIjEn8IvcmexQPv5vmMPqoGx6AEX0SgjtvJCYXPBhbeOEORrFmegAJf2llSVAtswC4bxB45tqGlXdHFR6BGm5F0zeiuE8fqMzVnhJ8Sjgjb++5Zo= 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 1778880080841926.2112312650875; Fri, 15 May 2026 14:21:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx5-0001AB-LX; Fri, 15 May 2026 17:20:11 -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 1wNzx4-00019H-41 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:10 -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 1wNzx2-0002qN-4X for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:09 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7dbec19732eso371475a34.3 for ; Fri, 15 May 2026 14:20:07 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880007; x=1779484807; 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=oBAWkkIXQwxa/hU7AI/aeM5McIKkTJKsiwHaCGzLE90=; b=R/FEKKCZwtjgqMBoIHcqMriPvgNLswu4me62otPoVZpeZrNV6VKgidx2mY6FZ+mlD/ LIQy1nyt+yi04lAZnJaGuB3MUXKxynEG2a7etEV/fWy2t1AaIxvRRhbep2tHl/6GFUey EnsyfDmYunlddiL/gtG02s9I3ewp2s1H/C3SojgPOf44zDryOwFVe/jHmosfUvN3TKb7 2Qgq5gM7xmuLfy6LIlQjoGW3I64PxcrWh2GJb6ZWoHhNa0McJMK+3yUNw7kfqRRTbOwY gvAIOF2YkajrHTx1RQzpP9vDTrNRDIYxfhPdv7X3hGg8vRhiTU6XtcrKcIj5NKLfXL4V kirg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880007; x=1779484807; 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=oBAWkkIXQwxa/hU7AI/aeM5McIKkTJKsiwHaCGzLE90=; b=ElvbHPkp0MK3mVH5a/k18A4EI9559NWK2w4ucns8F/YRLLhAo9s9OjJaohd6/eW0K+ cDz4pNz4L0MPCCLsmnR3TVqZiOheniEfMVt1dbTGsEH18CXX7HqLLVXrfb45fyvkBvy4 joiGUr8NatzDJ/jqIh8i3hxqhZCTal7bjWGTLihvYg7eppnE2UocXucmgxyaeKyIM54P bzKGnvIhE1ICWnJdYMdFQYZnrCervPqbRVaISU1A141CeMZKIxl5fz44x66bdY9vitFQ w5MvGar5om8QXqesIeRwMxpQ27Ebb9m7u1hmUmaP44T0Y5n6OENSJV9MlZTkW8m94RDM Sq3w== X-Gm-Message-State: AOJu0Yz8adXcaFi4V0dUzwjp7Heuvjr/5JO6OoryZeWNXGhWCjwbkybC mp4cXW//ehQzDyjQFpM+p13GEYg+0YGwUwBhXXr7/d5mYFRYtbMlseGZbOoMnAXk2Kw= X-Gm-Gg: Acq92OH+7e5ZYeka0B+D8enNoIVOMRMKOhg4X9MSMpSyFTzsqFjnYD3qzo7wZf2Sqfp A9qQnFBXjefIJ5ubOUtZkQJzcXzVac1Q8Ad+ar1sKLWLye76JXfC+CyW58OsLjwraBuiaLJRp8/ H//ZhzFN8JeLRkbdRYiFFfxdZJRbQ+oH7FsBXk+arQ9Lvv0ejVUyV2GE544j71XgwLWlBiYqRng ao2lfBSL7HBdFs1z0d1hlW/vu9E6xhe/9qmd8FahboFg4BId1I6IhegIV/kUEnr5UBKh8PLpb51 xGJDpdGwwT10wMK8yAYarEF4JUF2STEYDkNSYFftwk+ecLQKoWQ6MACiIjNtLSnZRMej+5aLqvs dBjsovEYz6ceVmx36xmRntCod6kLR9BzdaYp5NH5F8rdvd8/lDiXixAmLpBQpVIkV8fUeXdodhA sCfaEyl+ZPWQ== X-Received: by 2002:a05:6830:6d47:b0:7d7:d510:4bf9 with SMTP id 46e09a7af769-7e4f2b1c9d5mr4009114a34.12.1778880006778; Fri, 15 May 2026 14:20:06 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:06 -0600 Subject: [PATCH 07/66] 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: <20260515-misc-2026q2-v1-7-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=5255; i=imp@bsdimp.com; h=from:subject:message-id; bh=7vnu695aa0jALtwrU7g7GEc5cgKyz0AD/lhPRKnS0Bk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43hXseM3bISxRUhE09kvGu6xdFhBszLgWxBx s9oq8b+gBeJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR APMTD/418q6CpM+sdbiias+htV4X+buJqj3E/w43UXtri8ySLg2GEu43iH0iUIUqJ+QZWKmjcrL ivHP9udzH1ii6tJVyBmnoJL6zvbCb+k78IgiFfDSVtpfK29y3HXUvawW78Bv7DyCCSY2wnLu0jV ua+6L4+L5ZVFmWORKoctow2phPc/ufCmW1MAe1170h6s/5RJjUICC7K4eEBSvw4hRbUra8Gpu6v ZHcHR9FNMRV8gnv9o3DV3U1cWu4J1cYg8wODejntFE+AHxreVq9d/AADcVFi4dCDxp2bjJPQNP6 qfgKkmOYl2hvO6UFywXxos45GWIPVldPDDbU72HZXGbJukmNMdn67FeBkcNn8LDzvjalyvjI8OR LuBSFIecQmKbLAtEG1C5DLfWHgKT38vx/y17vErGagBFCsuPLZxIs1/3wf86SmW/JYXWgRv6DAZ XjgDfz0Dgd13HNnF17nJHN5PfkC+aCoTgInqg7mA1ol7zmhKbw57ZVca4JmafDKwphvoMFwYTu8 XZ0Y2yNqDsQton8qFi6+tkEnr+2iLTtCWGt3jDKp8mmyGpPyYT+AvZ+dopUmUM9h3aqoWq8ULT1 6MivDZssoJRuWChVhIhu4UudSDnc7zlSpCsCksuVgnj3MKgjHsWAMJnfktJoedMaTPSuEafzyJJ Wde2nNLzGPTnFgQ== 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: 1778880081891158500 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) --- bsd-user/freebsd/os-file.h | 126 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 7 +++ 2 files changed, 133 insertions(+) diff --git a/bsd-user/freebsd/os-file.h b/bsd-user/freebsd/os-file.h new file mode 100644 index 0000000000..bc31064a50 --- /dev/null +++ b/bsd-user/freebsd/os-file.h @@ -0,0 +1,126 @@ +/* + * 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 +int __sys___specialfd(int, const void *, size_t); + +/* + * 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 (is_error(host_ret)) { + 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]))) { + 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 (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, 0)) { + return -TARGET_EFAULT; + } + + evfd.initval =3D tswap32(target_eventfd->initval); + evfd.flags =3D tswap32(target_eventfd->flags); + ret =3D get_errno(__sys___specialfd(type, &evfd, sizeof(evfd))); + 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=1778880386; cv=none; d=zohomail.com; s=zohoarc; b=dQ4RaxCDbfzwmj4T+XuPV6dvSbH2L0J8gdFAgRTCLP7T3w8mUV/ruIieX7YhkSnJhZqRd2AliBIUZalC/UaSi1i6GeaVLNQOrQQ4SBKCpOmcM7L8rTmRJomx7kS6zTE0D8mNGThpWcHWriFUDAMDE95GBZKTj5IOG9RQMYCEJgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880386; 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=lQ4DUSPnf3j70bwsGanbKYeKeZT3XaXnUobP2DFdQmw=; b=PLm2YKDXfFb9tyB9GRF63NUDvyhKYNfxmYhDXG+kBxatV6gn7wKQjVhdVKeec7oNH9i/zyPhX9PjT81QIBXxiaRdg4v46tZth/M9gJqH0dX2W3tWEfC/Ofir1Mi/LTzmlBKIdp2q0ZVKkJ8OGKsNqYrcU+AfamFAFIQ2WXZtQgs= 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 1778880386414366.6971488670813; Fri, 15 May 2026 14:26:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx7-0001BF-02; Fri, 15 May 2026 17:20: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 1wNzx5-00019n-3l for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:11 -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 1wNzx3-0002r5-8x for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:10 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7dcdd1b492eso279567a34.1 for ; Fri, 15 May 2026 14:20:08 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880008; x=1779484808; 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=lQ4DUSPnf3j70bwsGanbKYeKeZT3XaXnUobP2DFdQmw=; b=ppocHrup2XTPZ2M/ZtuoFQpfkVVB7m5GdfKDMg9NGutcnHvnF3co7HUJlTqxVq8Wl7 PixcRLsQuZXjzj/kRxEp0Yl0oBK8tOkXUM4jtzyIP6OSssdKRggcXHS5mFWlW62g3fCG xnc3TqS3J4SxlJcghtDvWrfOV2l+msKz8xJSa+othzxxcCuyNeUOLqg7ReDUGS8EI70V WIWjleEb4m0rC4ltutHCov8+2Ud9fzKYYmWFsIXFaepFppxvFW9bbAs26fEfy+s5GCew KTB5OYNAB099ZxTARy03HM+Ka1uwsa0tNZhdU1cfQw+vOkmBW41SpFuQgVo2iEVssUiG Hgyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880008; x=1779484808; 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=lQ4DUSPnf3j70bwsGanbKYeKeZT3XaXnUobP2DFdQmw=; b=hEq/1AVZp43FlJr/PbXUSuRTqPCrexKrmfIMeR/hgq9EIEINWmM+LsAwNy0oo1VAQx eaYKTaiuUm3/igg0scmKtPya9OBSFYUe8PrpYU+epKbWkYOhVpiza8UTkxb8r+tsq2rn XWcov59QTPkFKVAQ2icK9rX52MQnYiBuCYWxiqJWCkX5g5Jl7byzWM5WhyPgVwEeM75E 3L3s/PS+TgEA/K7cc6jTQyZqbKB8yWpgOHbhSkh2t8tfpXzL9Fu1WD/a4uJBg1wycG2a NxnupA2oGZZLHR2evmulYkNQ5IHg6MwpOlVZEK69ysio+jvYwhLTwWi+m9H36KAONdBz 3NUA== X-Gm-Message-State: AOJu0Yy//Y3NYZVsJrDvI8ILmnEybyDX0LTJhBYO2rawqm11iJdKZxbS VAPb6nhZdY48KOrjI8uVVndFHncsnPj9Ds31xX1qs6Pt9wV8IDDh+4W6dHnfzjbDGeg= X-Gm-Gg: Acq92OGH0m3qwKesoTBwA/UovtvgGgk3ChaOTAipNfwCG3aAMPochGp73ebvT2NrHvF 5cosILGkozokidNXhYUFSi6bYfiAMdwOu/srzKu5MzzosyU9LRYHfKu8/gFWphiHpsTxFr+2ygA Pol57ZE/BdhwhjaON4hYqESI4mfo9DD0/T66zpBoyfGX8clF4boEr07IXwixtGI9MjEJpz85urO Nd394ySqNQvZ4c0Nflfb0AdEm8aLaPqPogaGpcSlZbnLIjsfNtwoPrESDSUZdf/E5nmwx5AnlCq dJamWQz8MYbheKVqGCSXACx68RAShkP/k/GUhCEbSl8iMZh+xQq+t9GAhXMPnmdU4+5jTNSW5ub wWaEXUUDCrKBfmCh+Z719YVXGPjjnoRoO1C0rIqrD9uDWmNqyqyGPXecdDYq8n70EBLZFOhpyni bDItU5XLEr7w== X-Received: by 2002:a05:6830:8290:b0:7d7:fd71:f2d4 with SMTP id 46e09a7af769-7e49a889f33mr3707820a34.3.1778880008089; Fri, 15 May 2026 14:20:08 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:07 -0600 Subject: [PATCH 08/66] 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: <20260515-misc-2026q2-v1-8-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=3857; i=imp@bsdimp.com; h=from:subject:message-id; bh=OdLR4pdCsotXmYKFnvtF6sPHNBWRKVP5533Nm/XNZIU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43hIxzeen3PHgkT2x9aM6CWPppimQroyo/+I uAd1/OlAGSJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4QAKCRBsHNEofbAR AASKD/9a2gCW+WUxeSzYRrhai0XwldV6MXYqQU9UDqRhMkKmlBw3zRxlkaYXeAcDDTi6SaCCz4r s6ov7t9icIGnWC4rEjYO9kp8WN6VVgUCMqRUG8VUKF54Cq1Qxuq/AdlGFok3K/3rQjOrHu3Ekz+ cA54e+M5ay4bTYMUsuYCf1ftfAtlFIVcULOuKe2NNbpsZmVsKafoaiGwy33ieG3ac5ehAnKiG/s JBolGagbxz9ZmYXQkHQC0Q0Civ3seuaUZ0mGRc+ydSF3zheWmcEqnjDObbXkCs+lWofLoKnlflu DLUo1fixw7xvIoKkXAbq+kTrFxIzHNNnfto6oKHSPAYS7Wz05U0CJr+xSxoDC1/ckBXgPXM7mQr 9fL3paqyBn6Aq0E0ZDTVnj3xAOTJvHxJusn1yFXZAXvUc6WJNYEc+D2Tx3Hk7lX6CJoXN2bYHTJ ijCp24U0HNA2yICXUuEoZEdYLvczuA1IH45iOAuGfiX4KpCr2ceEF9qnz0O82Zo7LhL424BXiA8 bLq6y37Gfdbf2erKOXnKPt3P6DQ6JbrTqSWwyC2yB8nD00fZkNnU+nNOyQVcnTmKaUs+PmIC6lN u77rasn69MSC6oVERW+LA3nLykKDSjRxIXHINCwlSLSHE95q8JiK/pom4EirFpYoSHWK8xvfsvv 9uZZY0O6e/4lRcg== 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: 1778880387954158500 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) --- bsd-user/freebsd/os-stat.h | 10 +++++++++ bsd-user/freebsd/os-syscall.c | 51 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 61 insertions(+) diff --git a/bsd-user/freebsd/os-stat.h b/bsd-user/freebsd/os-stat.h index ea95aa6344..679acd338c 100644 --- a/bsd-user/freebsd/os-stat.h +++ b/bsd-user/freebsd/os-stat.h @@ -623,10 +623,16 @@ static inline abi_long do_freebsd_fcntl(abi_long arg1= , abi_long arg2, } =20 #if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1300080 +#if __FreeBSD_version < 1500032 extern int __realpathat(int fd, const char *path, char *buf, size_t size, int flags); /* https://svnweb.freebsd.org/base?view=3Drevision&revision=3D358172 */ +/* Removed in cdb24fbb0a75209043efd3b5e94faa57dfc44bd1 in favor of sys */ /* no man page */ +#else +int __sys___realpathat(int fd, const char *path, char *buf, size_t size, + int flags); +#endif static inline abi_long do_freebsd_realpathat(abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { @@ -640,7 +646,11 @@ static inline abi_long do_freebsd_realpathat(abi_long = arg1, abi_long arg2, return -TARGET_EFAULT; } =20 +#if __FreeBSD_version < 1500032 ret =3D get_errno(__realpathat(arg1, p, b, arg4, arg5)); +#else + ret =3D get_errno(__sys___realpathat(arg1, p, b, arg4, arg5)); +#endif UNLOCK_PATH(p, arg2); unlock_user(b, arg3, ret); =20 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=1778880393; cv=none; d=zohomail.com; s=zohoarc; b=H5x6x8yLTkQqx6SJrIvKXptahs5ShK+Gr1k5v6AWcsLvHvsMdTAKzY73lRHTamIjCp9DoFb5wfuwKf/Xeqr38qD34QYpV4GLdRCSnQHg2Vqv3WVv7vnDGKX332iVTYbRNCTzuPGn3wmxRwVrK9OsmuhlOfU703wWdBFiLlYTaz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880393; 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=dhzXJy3OEpRA4uBwKk/HCvyifLHxiSUo68RBlzjPfO8=; b=i3+LZJaCLTt4p+me92kLQwTUHHicrnqlXoobczpCdn7piVV/RKOvuIVAKPzQbiw+ivJuSSZySYGeSvqZg/6LMY2LeyuWggSe026atzUQSJ2NWFFNLiDfp6p4xAmZZNZthbi8kDSpWIpCTnhNqW7BicH6A0uaEjmAY7gPkjF3zfk= 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 1778880393603889.2069704179148; Fri, 15 May 2026 14:26:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx7-0001Bg-KA; Fri, 15 May 2026 17:20: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 1wNzx6-0001Ah-Er for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:12 -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 1wNzx4-0002rM-Gx for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:12 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7dbcb467f2bso312780a34.3 for ; Fri, 15 May 2026 14:20:10 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880009; x=1779484809; 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=dhzXJy3OEpRA4uBwKk/HCvyifLHxiSUo68RBlzjPfO8=; b=PzoYbP9CHic6ePrirRK/xWz+8vhjF3SWlq/scOviITTPO+RWycOkahb7ZkwaHC3WXA pTAI/R/nIEIxbRFgTlWU58xFuv+1uHTHfjg3Rrz6fHaQts5iH7HvwXq6o/Zrxr6WaEid NJYU1sZNAlikZ69QWdeEb+KbikaNLjZEC3Y9Gorfb3iuruBLWxsN6mdXFZSSS62czPuC Pd6NLY62aciyBkV+nLwCNg8MvZ67TQIF518n+j6Er8LK33/0tK0AHkDcFRr5JK0NMiid egl15PZIkGZK5JItdeiZgZtrllWk79oxtRGRPeAtdmnxMrs9Vih7wldMYFcCjTdElxYp d1Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880009; x=1779484809; 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=dhzXJy3OEpRA4uBwKk/HCvyifLHxiSUo68RBlzjPfO8=; b=g4amXoSLDyyCxGHgR9DK1HtAnPWy9AnxQGEn8AWYjS1I6QJ/CTQ5/BR9cUrOXYdyQL 8JOhb73AIc6Gf3wJbilx3XLWVyMvSSvmfMvrxD6umDrYO557rZxhJDflh0PmrSsa+vSa c+Xmu/Aw2sJ7FhKD1DNr7SwfFrlib5FE2FJ3mKYo4TKUFWFcAlt9B8b1NaPphWbn8a/q p3pQyQcR5NbFDvbWRuDEWG+xovvo6aOLWdi/YytOnMaJ3MzeQlf78yg6u5HbtSCHY3GD bc9vqVU5Kly1yBNG2urFXCA/SiC9x3xm5kGjyp3hSz8ssH4T5vMqnsos7oLYsxp+SN9+ yEjg== X-Gm-Message-State: AOJu0YyUVZKkZTuFwz5AZB4+kVWdb+DFdZMM5CAtL2hP18qaZArcSx9c 3FAKp68ZWYWKxUX85hROdJ6i+hMmm0AKDH0Fut6odXn7QRGRHSZ5hwoys9O70VrApTM= X-Gm-Gg: Acq92OH4g83qXBF5AL7ue4lLVoTS4OYedxPdvL3K/CpKNUg06sS8EH4UJcf5vB87Lqf 7a8eTaO5TV7k2OYUjLDSqEFG2doEExhnx/X3qsXiFcDhZ1LfgY/yH5jd8JOgAGZWVUhlLI0nsoR CBWfeavdaOPECQUc9VYHDeL2B9Y0gszmnN9yuzfxTIEyu/DSffYzrw+KcUggO0pT96pZS90Rm1d wGKHNJE4gLv3YrXyfkJOxJfTJozXHLIw1Ack6D7ExIXEpwKL9+BQ8Qkfabi+3SriiWAh5E5zj1w dTmXaIFIBUmFfZ6cMSTe/QqdPgmmUVg+/geDmQG8a7rbc37k+YvZQeAPMQjsI/ZjgDtkdALKKet 3b/Q9crdurSQJZATYimp3P7Y/hoSYsk/xPjHrJci73TxstWIT7+5tmcAJE9cTGD68BOoXAJCYbX 12lEXgJu8+3w== X-Received: by 2002:a05:6830:4128:b0:7d9:b2b8:e06f with SMTP id 46e09a7af769-7e4f2b6f1f6mr4034266a34.21.1778880009140; Fri, 15 May 2026 14:20:09 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:08 -0600 Subject: [PATCH 09/66] 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: <20260515-misc-2026q2-v1-9-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=6824; i=imp@bsdimp.com; h=from:subject:message-id; bh=fqu9+KzJbMBPt8l/2aDcgObMouWx7lPgmNU+jL1ZR/A=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43igUlr0lWqzA60T38xtzEOAQ6vA2Q9Ft7BB IXOqTLgo+SJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR ABLaEADcVrHbSHxu80ZlX5f7gz5GAaoOsENabOmFXYFfhc/HmLEb8MWgbrG+eeJZ1jM1yW6axCn 8ad7w+6bZ5D4h1hyTOblcPFUqz6j12IxUmTMCvyjibGKB0tygqQpTmA3cP+dg4VpPYcQWeCQA9i M4JxvVAtaLwDh0QL8zPn/4jKjEVC5HAn/bwtQJWG8wkcyMbi3rOTfc3xS422CVQoZreDYJA2c8+ KxENGuhvyV0teK6F76O/pHf99AVY+YjylqonsaznsT0hdnL5LKtQ8LFSELbubWlDy2RGmso/psm cZ1s39caJHJ01MYODIoS7ZM7KVxYoDUgq75pX3tzfxq7qjjgaz81o6IkUn+m9ibPjJW6NmRuiRW eocA/2Xs1tf3DnF5VZcL0R8Ty4duo4X31T7djlkG9yuFkKTf981VOnC1rC5nFo/RE78RbmHeA1I IzxpbyPcg/Eo8L5CjxfG44yPJ8tGLG1GcD/2qbTmPqnKjpkgfkKyZ5c2lmoqMphOoEvtTlAwzMM e5g5Pdr+5gJ70CICG4xK/dLvpi9yAy/D2/8sem0fcLM93xFQCxAt3JiEAm1+RduXW5L1WRvruWN nhey3nJVWUm3/4VLIylPbTVLbuoOzAcKp0DMfJZHa7fNvJajoBsXfjjjU2DmtFmW+/16w8/8X4b O4TqwyTK6ujN48g== 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: 1778880393995158500 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) --- bsd-user/bsd-socket.h | 160 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 15 ++++ 2 files changed, 175 insertions(+) diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h new file mode 100644 index 0000000000..121d3e2a05 --- /dev/null +++ b/bsd-user/bsd-socket.h @@ -0,0 +1,160 @@ +/* + * 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)) { + host_to_target_sockaddr(target_addr, addr, addrlen); + if (put_user_u32(addrlen, target_addrlen_addr)) { + 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)) { + host_to_target_sockaddr(target_addr, addr, addrlen); + 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)) { + host_to_target_sockaddr(target_addr, addr, addrlen); + 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=1778880104; cv=none; d=zohomail.com; s=zohoarc; b=iHtWk6K4l41Nhj0BqIXeExDLG3c+Qxh4KYySFzREFGfnxALHJPvvBam01MBcdRSf4DJCYhVjWNg7FGOgW1ZDcddbNe1i37a0syBgb9ao2y1cXwt/zucQHB8IQNT245doz0K1QR9+vB0in8padmHVm+bk9iZapR2R45U5w+s3au8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880104; 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=QwxcDBxfcEuftcZ6S6KRRMd4HtIR3+pnE2ndVidOVhk=; b=YNzs8kTisFZb68X7dWqcpiFD953VK/fEvnxc9OYqKIMhjV/XXpzW/2P7zySMJYkDj6kPdVI/Xsn3AVGLHCjZSB2JnfyZG282BAiFL9CrikQaE1Au+ozwJfZeL5Kv9eDjtQ6pAAeloVVCftv8LVnkox639c3BDPYXTwnzYyG0GqM= 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 1778880104048962.8911793811911; Fri, 15 May 2026 14:21:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzx8-0001CM-N2; Fri, 15 May 2026 17:20:14 -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 1wNzx7-0001BI-4e for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:13 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzx5-0002sB-DR for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:12 -0400 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7e568ab0bc5so343697a34.0 for ; Fri, 15 May 2026 14:20:11 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880010; x=1779484810; 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=QwxcDBxfcEuftcZ6S6KRRMd4HtIR3+pnE2ndVidOVhk=; b=EewIf0YxRcFtH7VTsrphn33I+3UiG0f4Jp9YamJEAva0OOECgd3SHdapc8GKFWwP6R O8OosRmDcCIFB9vWSUqpVWS5Ki5zcho+CJwGyRglMZ5/U2AAsPkLPiUuPjhtxSYmC69i 0wOjia5Q0RETqwZFTGn4Sf9EXwSOoyy9frofxvu3xcOHOWi45HnMcw1/Znl3IY4NV/yN hXShmV6eyfkywcLVokbZL6KN5ltWsVA/41Gd7n/EP8qENrZfWX9rBMQN+3xdogg5SrC2 4hud9FpO6MuS9ufpxrrqQ16N08MJ2xo++y8Fgnr1sG3fKi4nRLAkuwIL5GPV8ZQLKG5m gT0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880010; x=1779484810; 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=QwxcDBxfcEuftcZ6S6KRRMd4HtIR3+pnE2ndVidOVhk=; b=kOzRVwfKkn3umC085MpYLExEpdXIsJpuyMoh+Ndqqh65Fw/WlxxXtgcVhs4TyccijH C9oR/RJirUqOt3xc+Sll+jkE9hVhKsDFLdksofqRDc1h3B7usP7cFjFRdLttYaEmL757 HPYfXgqZ752ICSobwuyqiW3VPe0MB1jloXOvqHy4CCwAFW5JE6lr0sW4KuZKGdLY6QHz ExPyvuJqnS1lMZ/ekZOU71N0x5om8gWscgqd0DTnX3x8vEYzsZBYBBMMpOiI2aHffbuc MZtFMKAsTguhEh0VLvUtJp0nHQXY8rNeLrmGtgwh0a3fZhk4fy+AOWNm2G7VaWxbADX+ FhhA== X-Gm-Message-State: AOJu0Yw+IxNqzDw4+dWIRGSoC3FdaYRkcNS36ZLxzgKBMzmmeawqEtWo QwAHOLBLd+Wvo738EI+8DQKDHIibvEYUw54CjWECdMj65BFjyRth3q/b31fVqrreBhE= X-Gm-Gg: Acq92OF3BT+2mfYh91k4f3BOqz1hNuT23aiqIKt1REk7am46e3advOgHoAuNeaCLkps iVj3cgBcobqP2bMQUhHCnevwHH2UTnZXpRCPusQKFrjhbvmAe28C/zYR+YeaGLgCxriwC/KQsLv fvkctmI2jgQjiHIlV+Ut5Ira+m3r/93sc4L47GY6dKhwhWiwVQGCeM8TNg0Qvz7oNhR2nKIN7Fd t02gUexpKtbOlgkf9n6BFb4ASqn2i8ZtpSBCvivU6ELnA4VGk/h8wmLJiJxxtVP4wx6wmtCBhV0 1mZHpkPv8yMeH/aFbYV3KKQ/pLP5RjwG7pdTVgy103MUOQ23zD4JE6PvA+QIT0tQFftn1buGOS6 7xuEnNoGlg9FVL3uugtKx1hqz7Uv+gR5VnCUGd1b1lsuPXTDWk6i3RiH4JoyR0gdhyRDsvflJE6 IySePZjEsSsEzDwQwYQwEI X-Received: by 2002:a05:6830:d0d:b0:7dc:cb0d:9e02 with SMTP id 46e09a7af769-7e4a3e5e77bmr3496110a34.9.1778880010384; Fri, 15 May 2026 14:20:10 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:09 -0600 Subject: [PATCH 10/66] 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: <20260515-misc-2026q2-v1-10-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=4186; i=imp@bsdimp.com; h=from:subject:message-id; bh=Z5UdDzcopzUGMjRMp45t8+R+3fsuou9TYbXSLV+0l+I=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43iOikGFSOnUbRn+pX9ly3rXu6Zv8fOkg+Hp OZMx5RCf8SJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR ALGEEADBpKg2YbNQOAbNE2FxQb9Ln1+Wia43WAX9c/xFIuWx3YNhvn0C8/UtmlZLmXTKv4dtvru +3L7spFAEURA4RIHqwaMinHAe9tuRJLgSaF3sQvTrOuKEqNMeytnHQR677uKK/IlI9RL+BPOB9M s3O+eG2MchDID9FDwbMvDYOLZTx0vv7gw9Zn1GT59bPaOmx0UPRgWBriRtfDWRNw//lWOicXdlg 7K6aLSWi72atbfzLIfzC1Zvd0oNxD8dvlsbIjn2tudxL9CQs3tfMxVAANsJvMJlKNXJcK+jdeED hTQgkFVKMW0/jNDak3mjFiTcLDypc/3EDIM8xF+v9GAbWbJynvb/rOgXJoff9fYV+NfJVuPPAYi 4EHaeRbP5OQ7F0WaHAUUGHhBcWdPnC9fD8mY+v8yLK+dEYlS5Wx6gEt+2cbzzjPCJ074GLpTlPL aOVDXxVa588ErKe7Wb8JeSIwnaKUcAEzwdp7JWly1FOP+VrsNiqnzv1HOjVHnpHSFz/SycVqcpf WpA1ICflhApaZo3yoIVoQavp8berAEyvpkD0Fc0/wWdHhYonFQUGFAB6UNWPMhda4tbu5wfJuOC MhM71Y33+H6E5vFk/OHIUOfNVuMVLOhYU+KS/FIc+bjILGdkwDsILujDjpgMR7qHD67NLjsziY3 pg+w5UNndQoInqw== 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::334; envelope-from=imp@bsdimp.com; helo=mail-ot1-x334.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: 1778880105935158500 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) --- bsd-user/bsd-socket.h | 114 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 114 insertions(+) diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h index 121d3e2a05..578cc3959d 100644 --- a/bsd-user/bsd-socket.h +++ b/bsd-user/bsd-socket.h @@ -157,4 +157,118 @@ 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); + 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); + 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) { + host_to_target_sockaddr(target_addr, saddr, addrlen); + 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=1778880261; cv=none; d=zohomail.com; s=zohoarc; b=RWM1AojGue9FfqhwtGxdiT+vEdxG8WIPORin3Cl0b0fMd3INerbpni75G/5MM3lY0uZs3wjYBV4NNVVXf092e/8HvHHp8FLXiNLoC99fBFtueRh5ZXkQ/VcXRHIabPhexRqS65XCBYnSjKSIqGqs9tlytfODDL3+Qz95fNoqAeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880261; 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=MSSbITLdONRNLLTMk7toomTcwKxKHodmUE1uoLUpp4Ts+g72eW73VzYtwnHsmXPsNdEaPZR+aFi0ZFc+9on7njp4B6fao2diP/guEoG20aYCj8pSQ0tcXbDij1dOXuaJR7BC3ybJbatEVyUbyjx4FDS8iZj+jyjwdI/SMowtLcw= 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 1778880261942277.636065502075; Fri, 15 May 2026 14:24:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxA-0001EJ-3F; Fri, 15 May 2026 17:20:16 -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 1wNzx8-0001CR-TD for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:14 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzx6-0002t0-R2 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:14 -0400 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-47c7b282d73so277876b6e.3 for ; Fri, 15 May 2026 14:20:12 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880011; x=1779484811; 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=YfTs3wbm6xtl+oht0SPx0n5JJOBB1tt5+UeE3wDWidDiKLtAF9aL1S43dJrhSfBTrW fVWhSFC6R/1ui/KWHQc0niNe6/FcH3p2UTsVYs78T6Ek/oPJR3VPVkhwEbiZ9MMQbS+k 6g1MBxb3cV7Ip6grY52yyPpqQFgaJsG5rlFi/4nEJDPPkycTBcztnmTWaW9OmHYOJkL7 nKsigcmgmIn9aWQkPOfunXOH4kUPGTmgn7O69d3gDqyOK6qBCsMfCFUJ01arpnkR7ENt hu8De8uFoPunL73yEYjCF8Mfj3CTI7HpgzWsrnpYizeZe+acWERwASxx1+NybXrok0WT cdwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880011; x=1779484811; 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=IYdWTJZTFh+AyDDOCITxlNIBscHyO+31LlIIIPtPSypgjtzwrA3EyHuQ8iD5n108c/ NCwQiFwLaJWY38lSUj+qwJdsuIz+tyI6US9vuttacdpgdLdBVaXlDRZyZcYhtgzFJ2rq /QciYPDu6WL1Pa0QpvcwI5PfDLO6JjRMSa0d+DtbVVssHPnyRurlDPcvNQB5f5GAKxRl XESuK7Fr+XNzXruc+YlYaRE5YCGwfhzA5NYB58VVzX6sh9kfPdZCDS/kbLU1p+uAGuc8 48jjjA766ooKumiUW9POG5I/qamYaKZoPa8truLsat9ZW0nbM7IeZQzdO89UEgXMvWi+ nk/A== X-Gm-Message-State: AOJu0YzyC45D/K0ZY00lMHtQ5SUZGlYSQI+zJMbejdHM43gnrkoG4vE0 pLK7/RfEJFbKJXakf9qbZEOlu6GoxI/RXSXMbuVzkIZ92UE1NOQIKd/lgomoVQSH8Uo= X-Gm-Gg: Acq92OGpcwaOGMp3oYgTb8ybeQLb8/0skXVPCjHwR8Ft01ZHC6yaNBO+7gVlMb2ya++ pKJwFMDmD2JGGX8aSyVpiyx9hWwRCXnz4+iB4899iXH2eLF0ovi5qzRNDKFUz5wndD0/xwWBkqj OXaNuCXeomdWeyoOvwLNyKpbhYe9dDqJpZ8KVbJCEi+p8hN1N6JYxhqM2DFJotiVrZFddMNotBS nB6HcKm6Xmg36cIC7Iap+kKXR5U/d3AvCXwpskK0hCJVTLuMIZThE9nkSY6s/d38eo2d3uhcZhE duKqvMVMNDGldS112soDk+9S0zVPavlPnB/ZQBNlK3RH6s8uj0KxxGuNkNljSpz2RaXVVuBLRYz Z9/9nZ0xG9ZNMelAktNc8mwtMwfL7ZsYtE8WHRfy8eshas6MRLvvIgkA/eQb/CwCrKVATsn4gif Tlh+a9d+IvO/8+Pz6ghe57 X-Received: by 2002:a05:6808:6788:b0:479:646c:f701 with SMTP id 5614622812f47-482e5991ee2mr3838306b6e.41.1778880011478; Fri, 15 May 2026 14:20:11 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:10 -0600 Subject: [PATCH 11/66] 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: <20260515-misc-2026q2-v1-11-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43i2S/mIRicYdyvQAraXNW6QfE7RxpCx8C6T eWLxOY1KnuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR AG40EAC/sRRhQrybzWomqxuq/TG5spNn4PpQXwzr9yuXhmtokqu7DUYW7u2MMuq7zoGbiTL7BZG /QOTRIpuYmQ7sCZzKpPzKWqtuxOgAlR7JLXq6Pj3QcWNjpfvANnKFGiOx461vmflWLzfa9W91hx o6vmZd19RSaCA3s0FmZxHpaaKK+eUmj6Snej6Q2EkBw+TXSilIomJfVyfcP6LPecjRjj5Wfllcr OzJ/RSA2VnLBSba8y7ixwzS6xJllA7bYzkkhhaFKwy3Y7cq96QZ7l8D/CKi4InItfeoP6bs2tUR 4p1+qfOFmhSoKmSOzkBIjZW50Xj0FtLSMFj+fni+Zhe5DBnaLvKrUaRVhl8gMHKfwKZSBnYyEII t/2Hy+gtVvl/Ur1rdn0yMSMCSBEyxLUlyDZWgpPw46RH9glhzKjfgCN0PKqJjUtHREC2YUwm8Wx HE5fIsf1ndJqcgP9fHdx7k+0vr+V6VHbCWGEk0Q/4negR8/GM5cJWPdx0HmBYdOH0NpTtExZwVh qDAdClGuqkJQn7jKWk6T7WwjdDZPuLcncY21+C+cRQLKcZuRCKuiF+E3AJc7pc/I/YfNEXofmuW syaEe1KebBJX5Xmqcm9cwFdSOcU/HAOX4j+29O5UzLtxXzRScxOTVj9LAic//ANSLENGsQZnYFB AEx8OppM/VKUGKw== 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::22e; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22e.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: 1778880263017158500 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) --- 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=1778880036; cv=none; d=zohomail.com; s=zohoarc; b=mYGzGTc0MQgR+TtpVmdPRcLM4tr2PoZFXUEqnTjuW+kYzlHXOYwD4XT2IY+VoS8T6uPjMBhaW4eXm/YWo/xBfCPf6Vxex8qsC+PztU/5jw41R6A/Wq9lWP7XdVXeBTIFAwWsFUoP2vVvfxyceLjfpEMizryXTqoeJkTv9xAwMHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880036; 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=azuMvEPqxf03PBzIl3TO6hsWCvJlx+kQZvV9xsGRaOk=; b=J5PgSv1cCzruujdyeErWDbsYgxOmMk1Rn5yrPqrmCn4cBQvIVvGGh3d40XrhIsIlH0QOtuEH8M569q7WpRO1UPXbCCZVJw13gubobu4PbxJ95k1JYr9zsnfWx/37R/3Cq3xJvd1gNQ6dEN1o7wMIXbCb3g/w/KrVjRCfcH7EEcs= 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 1778880036658847.1343231887026; Fri, 15 May 2026 14:20:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxB-0001HE-Ug; Fri, 15 May 2026 17:20: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 1wNzxA-0001FG-BM for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:16 -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 1wNzx8-0002uQ-4C for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:16 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7d4c383f2fcso322586a34.0 for ; Fri, 15 May 2026 14:20:13 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880013; x=1779484813; 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=azuMvEPqxf03PBzIl3TO6hsWCvJlx+kQZvV9xsGRaOk=; b=SssQFvOuNffpI+KvurGk1sOcePAfy3bNA4yhiYSZdNlkuugYch4hERE2WlU5TrKPqQ kMC/Z7hkTZI/wL4jepIraIRqa6Xn7rJ5Ie+yWs4fhGVgbeqO6ptQYJKA0h2Uu97cAWFT UGpoS5CON9bpcvRMcwyNvdtcvX4TKPvSeAXowrCOGiw3QWHGQLqD8w6jdKd8Xr4xENtj JFpfXaRXkaY3CKT+xsdTuzF65LhuJwTDk3Euf9cn/OQ3eEWhAelAuJodfzZGFfqp6gJW uD6DfCJoARXZ5QudvjYLbj5hbx2S5j95Ao9EcSIgUwTE1KySusGdCtIetds62vSuL9GR r82Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880013; x=1779484813; 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=azuMvEPqxf03PBzIl3TO6hsWCvJlx+kQZvV9xsGRaOk=; b=jz4jIBgK4u0UyaJvXLqZXkPIgYgN0IXcTFqJG52cnuqtCto43yEWjyBeDCFbAFK6Ie hbcHXuEphrkE+aKW5ii+XxdKhdODcaymO3O6CMf5Pt8Hrk8vXRFpp2TFjZLMYGVd9s9L su54mnTVvDXyA5Gwa1p+dx5/ECpgZO4tbal9t6lGF/siIyI2DOPYi/SJCTnFUQcseq2o E3NfFg7AXQXE7DxJqiPozyGZM/ITK4NklElc3YjkSNihtxPVtEZqCWxaMxQ8xQh0VmtX yZbrDUZ5axFju/jk15NQS8qYbBMOpCXtftbKJryotmHf9zc4z5QfGNKADGvVbDvFk44A sj7w== X-Gm-Message-State: AOJu0YzrJoSbite1iSZUIVjKdfDyEDY4SMAlN5X3d3lS+EPd+xm0agB1 ZHj14rf9HfJtJ/kNwcmNCTAHvapdFlOgvK8GT3MyL6WdJuhCmoaI9uHMKPS+EQdVLUI= X-Gm-Gg: Acq92OGkYN1gSYcbrOjG/9IoB91H/+qFcOk6weTaF8ibWMD9cEQsWJclUQEFltVeM23 Fr784CYQlDGv4DPCgXjQTT/Mp/WNhFwJe7dvqnG/ljmLo1G6eA4qU4AXz0Ts9b8lqTgWqJ/aRcf VwrtTr8Klai2z3m6cRMFtduMtYRHtNcOBFEQp641ZYaNd5F1bOXK9OdXS03578zo7/VHhjDpOed pAs4Yr52fm1lWYz/ygymO2T+zIZYOVJKP/OBsHc0jAF4KYbct0zRbdwths4JoZ9Fh4pP/iUOFbQ Pr+sWaKtCOLF7mEGykk0eHu4FyI/kyGbTQqD2K/rF6QnMe5KeMDsjKt3tSPPZeUhogUvBBQfbTw RyVPCqVemwXBiKVq7sUeDeU6VAr6ohBGt1kOnJJ67d2+i9kV/Pr2m/P7iEuEbIZhXdPELtGl+SH z0XNZ9aRi3Yg== X-Received: by 2002:a05:6830:334b:b0:7e5:68d0:462d with SMTP id 46e09a7af769-7e568d053f0mr1082915a34.19.1778880012877; Fri, 15 May 2026 14:20:12 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:11 -0600 Subject: [PATCH 12/66] 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: <20260515-misc-2026q2-v1-12-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=10846; i=imp@bsdimp.com; h=from:subject:message-id; bh=LO3prUvkr6fVoeBG4al+7K5tjdPVDD+KIKT2DCcAJ78=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43iumBwy2fqkfuPggssjIcjstAcw2xrLrXQR 5Pwh9rz01eJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR AMntEAC8J/Mctmw4StNg31OvSTH4HliJgLlK1kY/Aa2Sc07eBJZfWoYlXV0FIT8/X3OwMcIDrfR PgqqyLAqZ5kKKmS3AV+kgaBr/87dAuf3eUPupNAG0vYIYKFjm8+KuRcuhemD9uuZoHTMXilbCX5 TCqMvBPC0BjGu8saqAvqm2szCRyoLjynkbiqjEoH3FwMl6CojOrPt1lmx/rQjExwZiNp5Bhfn3Y NTw4RH82S8nigu3OJK9QoZ8PUWQWVdbFexVqj0opIOE8aFTvodxr+Yy3kCdyjtZx/ndFsw4TcSo xSNfIZLSadLsPok0Jhm5+0p70oeOBXrFPl3qJu+4wScDSalIXTP/bsMlzSZYhKyoy6NgkU5cOiu nR/5rlZsCwO8EBzXiMUz3h/DK3/23WVujhagjVCt3PYqq8wx0f/rYD5Sh6o2EnR+b+Yc++ndcMF PPvt9Kmm96GJJSqDtZy0IVaUVv7vJcwXUX2SbjqLX2LO+T/FqjD1Hn5q3SvqVv9+geik5Wkcgi3 aZ9TkeVbi6wd6bxAAXxG44pIzwaMbLTA8cj6g3srff16Peq/c4N1QYdc/Cm4IyqYcofIQqXf6jk +zdjBBVgQS9XGu4DnQ0RpJ1AZjfsjPRDVumleLZ3LdedCZ+ZecOSQwShZ0Oe7pZoDA6QKTmfJXv A37eoLGISCNDcGw== 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: 1778880037647158500 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 | 258 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 258 insertions(+) diff --git a/bsd-user/freebsd/os-socket.h b/bsd-user/freebsd/os-socket.h index 279157dd05..c565170d09 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -138,5 +138,263 @@ 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, 0); + 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); + target_to_host_ip_mreq(ip_mreq, optval_addr, optlen); + 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=1778880299; cv=none; d=zohomail.com; s=zohoarc; b=a1sEYH6eH5+/jLfOPPQdJCGjZ4fTH8g4SwPejQyl8k0PTZHRyLOzgyxN0b9kT0oN5nAipPvOv0btJiOgF4fdnA0etFL9JdUUDeuFmZY6g5PCrumS8Agb+HHnmuEe0jP0DYCGsnWOMevg+taRFyYU73EFBc0d7tK2cpaNNADLkCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880299; 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=IjWa9KPTIkQLy69DgKF7cEUtyBULk6XSvES0OTbPIbw=; b=Dwemcs1kFJ0fMQR/m39Uz7sY4m9zUp4frBVPegiu6arLJTXSApSH0vK26eF1Vxqbmfl0uSSKqv+OWPzhrRKuPedt7DJcksouonkxXAfDV4qwVKbpZkTP5qA561+d1bBpJZsuDODE8M88Lf+aFyyO0fIJDcPspYZgpxRSqCqG3ls= 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 1778880298999401.9718800503973; Fri, 15 May 2026 14:24:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxD-0001L6-55; Fri, 15 May 2026 17:20:19 -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 1wNzxB-0001Gk-8H for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:17 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzx9-0002uw-A8 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:16 -0400 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7dcd9061b1aso291830a34.2 for ; Fri, 15 May 2026 14:20:14 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880014; x=1779484814; 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=IjWa9KPTIkQLy69DgKF7cEUtyBULk6XSvES0OTbPIbw=; b=jFZkgFiilX2ISWSeWgoRuwapw8MFpAP/l/NjzDEqxdbF6/u8OxNrk5mzGKzgTsrFOk rj3FCGXrExvR64Atzp8snoE/GsYkf4nFRima/oMagAX3UvyYmwVx4WCysWr/nMKIvLs6 Mm1PeMQLeidwvTPtXq9h/J77mYOH3jzFJD9ctAoHEdA9otXzZSpSUr/pLozH2p3/jHNN idBF7Vudk1k338Suc95M1d8esfu48G41e7FfBGItHQBRYccB3RrBvkRKHdunF/NYmbro 1E2PwPs/UII2GHdQHamGkDhlmofKyymz3OzyJ0La2EN5MP95MceqJSVYDgZaobZS00mt MmiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880014; x=1779484814; 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=IjWa9KPTIkQLy69DgKF7cEUtyBULk6XSvES0OTbPIbw=; b=MKxh8o4TzFgGqJ/bgyuskZQNdgyz4ARdlJAhf6j/fuay97/fjRU2EfAktOXQQNec68 mVzuVchRjjnKZ6uYatOoT2xHoSVyWG1iBQA7TuSH+KW9927q0NvE8tZ6MP4QjTmPy/O0 QmnYkeuRm01whCbGzY5w1PJhasvpip1i30a13LefY9uPxIElvn71QyKTbKCz1A80HlLj GQywrPT3gjcMneQeeIX5/Wt+ac5AWZn+zamZaTDdmwenPVbxvmFRyXFeXpdg5kfNIUfc hCGRBX4jbyqomGmG4FUU4iLsowJplyXfn3yfhhi+qoMc8FgTYFoSZC8IYC/BJpeMsB3n M7nQ== X-Gm-Message-State: AOJu0YwqtaVKNxhPwyQr0jwcG1aawFDuE/lixt8OwfvFqu56zWIJywaa JWIHPdBVWsbUxrUjSkA5yHRhXcm8+inZ16GP/9TIGEaSSZevOcoFxGJFRQmywxBRxKQ8a38ASgZ 7n1t6Cwo= X-Gm-Gg: Acq92OEzaeFPzcjFuUvkYoiUupwoIuEgXY4iYip4RtHbhvPqrQ82rEE7D4Luj/p142P bcx+l1hSubLsbyckId7dX46zS/Bn+GYSnRsKp8hWMwvv8drGJMr8JxGgW/LHIK5X0Z5g696+g4d n2JTLc4penOlAOpQ+hIT/VTKl6gp0R/khPbu+ryZlCSy3DF+Tpftci9rA5J1wTO0EuyoHrYDJtP c8qK32Av/EhprIwgwGOlQRGn/zJN4RQsr/Wqd8qfMFw2APUEQjw2FNS0WzdF/xeRhIQbQ7h+UTS RMQHOYuhPm1gSW/ZkrMHUmQiOTDXmgvHfRLUjp5YrNCOP4pJmiwyQEKY/4h+4LNhBnqKYxw8/xy mmk2wIDF/h7Jlgw7ULMKHUyhqeYeb1Omb6dnmnECBk2roGBmxcaFpOBkNmaDuryVJPXpYSXcYHJ 6Tt/3UwvV0PQ== X-Received: by 2002:a05:6830:628a:b0:7e3:d199:3164 with SMTP id 46e09a7af769-7e4f2aa4df0mr4018786a34.11.1778880014147; Fri, 15 May 2026 14:20:14 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:12 -0600 Subject: [PATCH 13/66] bsd-user: Add do_bsd_getsockopt MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-13-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=xZNgyCHx7QOOdFDfCrGcBYGHPYpqPFE+b/19abC8Gss=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43iCL+alsgU/xvYm6u0dH+czKFghXeAPSCCI ZJgiEIaq5uJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR AJB9D/4sUF/VGJNsO9iamSyrfFMP7EJ8sKF7ullEG+qKv4lxD+s6L0rPYkafEtLdOhT0KrRGz5F ujqddg2QJf+scsfhxdgYyCRw7l/+7QUJY/tCTCRcJZYP0mrPxg+HBXQTXuKy8MZVIHI0h5SWUzc Xc7YW1ttKx72d5PtVjeFG6iD+5i7OmgLQavUH5wwt08OoCbjlvKFq+fiMwiqxNZjcVMwlH08x76 rW5ocFgWr/KkJVQZdr3J7G1ZwWDxbTSwMFodiQl5BhMXIXjqZU9Z6yVnMYedAC7HG9m+uW3OCVw xCohqLrzJQvetAQ48hTB8MEU9itKIRDn7H7k4buTIL1UTXZb6EfTuOd3UZV7D63DzjDCyQP8W7k AJzJ7Do53+eZYCkc1WoaUaIY092cWwCul1vvBwQPztqIV8ut3R88wUkFhYpw/BVcYRPwfqU5t4r oVGoN3dFBzgRIUiavhpH600h+Jiv1oGq0tsu5o/B4GDN1tqmfhs4gT4TiCpSMV9qab+9teeXHh/ GZKE+k3DYIDrendcqhS4d7rKuyVPIQ+0NVfI/JeClRviLXQtg3HIgu+R+XUyfFgY/wvYNEsrjg6 X0+TICTTLLsGnXaiZKnnil7SAXOtGxGF+Ju6/ilhSMv3qgzUMlEUwViOvOUzlDoiDNsB0i+ccpl Znw8NanxHn65G9g== 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::334; envelope-from=imp@bsdimp.com; helo=mail-ot1-x334.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: 1778880299311158500 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 c565170d09..cd85d9be8c 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -396,5 +396,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=1778880070; cv=none; d=zohomail.com; s=zohoarc; b=KFz+h9M+jef7cT9CWlQKCFfHZqlqCZR0+5DACgppjADhnJrk8BqXLSLMRv8ZIsDvno6/WqJwDvUSnY7UzbttA0R8lBDlyfrpHLo7z28FLoTlVOOTGylOy8SE1HwuzmsLvJtt/yusf1OlIhE5mVFL/C6rALB36uFIHWAYNmHrJ1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880070; 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=jqhQXs5wR5nd7oLuihoRKnbMlHQOKOF3uFmYpei+6Tc=; b=CegA8afTjadxjL4AkfxHwx39+RGwmzUoYKtjr7p+Fmuywseaj1zvcYPMHP8Q/PgdqPkQ29p0RnUKfR9J3H5HQX4zXtTadE6CqGXzOxPGRxQWGBlU9DewKW4Ch2SJMAwCxBX89LOZz8NZUvUhf/jxNrrEkx7Qes29zQcXxSLPRnc= 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 1778880070196635.8132959831303; Fri, 15 May 2026 14:21:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxE-0001Lj-E0; Fri, 15 May 2026 17:20:20 -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 1wNzxC-0001IW-BY for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:18 -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 1wNzxA-0002v7-Fv for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:18 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7dcdd1b492eso279710a34.1 for ; Fri, 15 May 2026 14:20:16 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880015; x=1779484815; 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=jqhQXs5wR5nd7oLuihoRKnbMlHQOKOF3uFmYpei+6Tc=; b=TK16gMleam7v3q8XR85mqgDC0qFFs1Lku8DhsOeUNbfxaV7ibdpnRkba+G8E96prgs r39/v7tqf8uyAtaKKuKGV8alvz23wbE+Foxs9lPqW4KlXNSz8iqz9xWGjB60JvFl0poY 0mo30B1Sh9ISf5ucyYysyOvnKv1Adj6VzoqkkfsdPUwS+byHmSq2VjGWCoNevx2o4zPm a7Lj1qu6stuQ9PGc10z5ALllpkIPgUSIE52VJuCsh6j9/R4ycpxGT5BhYacz09jedPel jlOcDcwgYQPT/La1hVhwNq+lb/Seh9MpR+ps14JjWpLchYmkXTrsnYDRTQeG/byLU9Wk 56kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880015; x=1779484815; 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=jqhQXs5wR5nd7oLuihoRKnbMlHQOKOF3uFmYpei+6Tc=; b=RrGeuzorMQtGT2HEsvQcZBC5g0+2rw9kNFfjJZZ/xoOkULu2dI2ZUnszNNNdLuQ7NZ 8Er/daXz5j0Eodf9i8d7QbhqyGumJ+SvgZDRDIDVocrRFtRMSrs9kSxG0B28V2F/7jVc 2lkLeTtqhB9CEt00znCnrGZGTuEQ7JWYyzg/cxIbI2dEKbUTZgKwUrbofVYE/il4YXeQ DuPjddY1CMA/MJE+Ku+ZsmiL38meEehYr+m9LeSbCaora4KyxAbTe7VTPp04U6Qhr99C JUwHmpIQazpk6S71owD4d7zWRBO8VXX3IOggxTqk1iHm2To9TxPIVI2npiDNLIs7m97D lWxQ== X-Gm-Message-State: AOJu0YwH9te/Rz0OoTM7J0J14Rfibrd8YJUZ5FRbC2UADz/+NpAVeXwU E2Gpwk1fTnNtc2z/HdndIfhOjr5/e4yc6xjjMVM95awvxxJE7qlcXADWEfgERDAAWNY= X-Gm-Gg: Acq92OF+qIozWgzEeSHu1cHze72le5HO5OT1jHcwErxkVtQNddMbCiULBBZFs1nJcpv ixmXtdEBlMfIm7uzJOoOUD007Fxkrtl1lz8Enym2rmZKiUy7Ege+l3ImWjUPgRwkEYQWp5RlJe1 RCfF3Gba5byJrAivaezPuNDilzUEfu8So3nqQF1nz2XhxPh3WxOOStYSDT+juvwAoshXT+K770i zJhZnKQ024Z9isJlWqVfcYdM5t6bChZNufPbeNuJrb0HRjqiEQbRRcJs2Fzg9MFBB9M1n08ASZa Ls+ZwT5/F8UTvT+1s41TufycniK2280RKuD/DDHH3dNl3yLudTq3l8RPWOf/0MDs4TTMCmpre48 PYDZKQJAh5ogiT3lXKfaaSb24LTL4CHZftTQm9kxgy39VvkpGDYh2PK/5v4FJqX5j0zTWqHVvjs 9LVfdI6ipvOg== X-Received: by 2002:a05:6830:70d4:20b0:7de:9b99:a8ee with SMTP id 46e09a7af769-7e3f14c8d26mr3430889a34.9.1778880015410; Fri, 15 May 2026 14:20:15 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:13 -0600 Subject: [PATCH 14/66] 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: <20260515-misc-2026q2-v1-14-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=7195; i=imp@bsdimp.com; h=from:subject:message-id; bh=u/iAconNAsAY4vmVhMWqgaztouQLoWm+Rg/Z9CJihN8=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43iuGsBjh/pvF2UCy5z4TNf7lV7L77PzIZYC MkUaIsYeL2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR AFSSD/9ts09zUufdCsetunX9e6SbA6HmpGA8+1NuByFp6R0qpiFcIsB6PbUllxzaQ1WRjrvykBV vpsFo/veYM5Mxt8B0HUnckJQNGOxw0HO82A0TKwgatIXLl9bEh/b+ggzHISo29TFq/tlBoyLsS3 1bkgEvlK0YCPErclqlR4Q+7/DZEl6yPY2zkoI0C1b5Ejf0bxDDdnkwfF9xrdFrbRx5WkhG7OjFE XAO7Y1K98yZu/lp0Ms/JtpaonEfez3osCyw2qxtvdtNt14yA4gLlIHBBdcXbfEpzHcsHyXN8vOA vZsGWNm83FRWMjN2eq2UzGp6pHhnz+mWqgurYpaRt5JRBX6UrsrKnQsz0HFSXJ1rElZG7ml2mv/ lbx5kYnjgn1k6MeItMkowKGKNpsJOemWp3aEvsV3Gb71w/ujy+va4DAKiKAJ8matNf1VnWR39UW 5j59B21xf3qLC7AnK4IRTJRvk1Gy0iPE0MSt+HajBgctHU+ADrWFPeHbKRNy7RecSzwiORa+Axw WLfm/GoDbOHOqx9OPLLHzD4e7lciAF5hvb0lbKMfBJyzjDHQmjd878JaYPTucCRdPfNuRF/5dCC 7oJP4Xt82YYGgZMcPSHBP1RulTQ6nEiK6Q7k4KtBXlFQE4WBCwjEiEkFouuKslYH+o5rpVY1DZt 5biU6F61rRzqGwA== 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: 1778880071682158500 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) --- bsd-user/bsd-socket.c | 98 ++++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-socket.h | 80 ++++++++++++++++++++++++++++++++++++ bsd-user/meson.build | 1 + bsd-user/qemu-bsd.h | 8 ++++ 4 files changed, 187 insertions(+) diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 0000000000..5c85131202 --- /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 tswapal(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 cd85d9be8c..05c22f2f0c 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -680,5 +680,85 @@ 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)) { + host_to_target_sockaddr(target_addr, addr, addrlen); + if (put_user_u32(addrlen, target_addrlen_addr)) { + 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=1778880227; cv=none; d=zohomail.com; s=zohoarc; b=H1nQwdpyYk2VVio2QvRbR4lDX7x12z083j2QKgUWtaMJCp4B418zlZuO/Z7rPXF0qPM4kDgOq1HX4uSJYkF4Wksr+0ZKnodwJ2rT7tphfT5cniDScZltoHolOuWJP//ECIscwHcbtUssBx6oV0zBab3yvpUor2Tkrs35UTIQ4UY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880227; 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=eWEMp+EulfjlanvuHGlMABpvVLKlelZghJdgaBSbgVo=; b=V0yWxRMczM224FCm+cky/abuvF3mSk+LL9G5Fc4lMmST/yHVnC6S/qJuPfZSkOnhkCrdwVKBDzRVKp2ng3efbDXEmTJwchRiMxgwsvCBcbuLSKGi2qeM3zAtodC8DbmJUSDpgkR24SgvsZzstTeOFbXdejDFi5Ulz47K0o3t+b8= 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 1778880227337532.6405524828289; Fri, 15 May 2026 14:23:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxE-0001Lr-Vj; Fri, 15 May 2026 17:20:21 -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 1wNzxD-0001La-WA for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:20 -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 1wNzxB-0002wb-W8 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:19 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7e568ab0bc5so343842a34.0 for ; Fri, 15 May 2026 14:20:17 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880017; x=1779484817; 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=eWEMp+EulfjlanvuHGlMABpvVLKlelZghJdgaBSbgVo=; b=AkxXuzsrbDdMcrzNNYS9pVhdrdqyZA6E/NyRs5/IbzHvdqklj3iNZ/hhrzDN9TJinP bGBuAuWfBo5T4vUbaiEtn5yDSy6kuzElbN1PZT0gOJK972zqIJVPr5KIo41WMhGiaISl 7+VomhSQKv6Pig5oPgAa3cMhwmwGLNQCX50EaYKEuytLfZVo9oiNR9Fae+2/Cd8xF6QG F93ghjTuxKRx2WAKFqpn3/T/lWD8d6od7WZZalGhfNjAFJk5kHhFMhhgDl6sqPCX9okl IPJ2gV4PncOjE4ui1Sm9FcHkT1z4vM7J4DLZoWruMNzjomllgsMvZeUB8WrZCDcRJDBz eGEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880017; x=1779484817; 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=eWEMp+EulfjlanvuHGlMABpvVLKlelZghJdgaBSbgVo=; b=GuwhS7QUC/s8VTzyrPtPyOjiDtjlVNIk+HY/iKRTgJdMJDC7buES9r3ATIPfTqPYZT mypgGOgGbiGvcqGkf0zWfsGBSh9JotcsDCbAagtVrJpnqsCspHB+2MeFBeN3hXA9snno lQtPdPfL58V1wv0NWA27Ho/9DN5u3Z0tm/Nk3mEzrxlSHWPTdePCKpg80sHE9xzQcCO2 G6jPIHIdl8/ZFifjvtLnQLUKJMlIHmGbh4AiwuTUHPST+8Ovzia+H03V5WZO+lFI+g3H 08srdxa6sbPnyK9Y/j9J/Q9HL/dslHjjkWhGat0U1ShjNhXRgUvJMwcaJss6ZhxFG0d9 qbVA== X-Gm-Message-State: AOJu0YwUtFb/xGaQTpc7bG96JmAcmVR4D2Ihylcec1so491sLLeuYru2 H1t8Qowr1GhCo1Q6ovT73gzWECIL+psml0Q3d9AY7U4UW32L8CVrVZblPKH1FxWDooo= X-Gm-Gg: Acq92OE1zsES+HHwLT2oyDQHh245fzx4v5Rwx9pKmudLG75FQC7aTzi3M/bcf5UO7xz NyTsNt7gMhNNMZk6GHGBPRYaGG3wMiCO+R1Itql/vcVfRfV2QvTsIYVMZFrdgl5IYRi1cKukgCt Y+v3cPx0hb635E8I4LJ6O/PhwryFS/3V5I+5IPcTLT95qtFgfqHQcHzdsGAJH6LdF4eJM54cDUW 6QZ90hqlRXB1DR/mNc3FXJixP1TYphCmXqvJIhLwPiKtvhZ0BoN5ztnbwZniQNX+MjAwaeVM38S dgIyy3fHqKztvB8zZwzgOApJpCWqmKYWoCqT3CuF2vNoDSrbO0Huc/EXywfPbgom2rK2b06ROlh 1Wx17qCTIIDzTqKMum4ja8DeL0Qcp1RyFAYFYuSF7NJxdK61M4v53wJc6dSHXmZ1Vds5Pahmdtt Zsj4fbawASow8bjWH2fAB7 X-Received: by 2002:a05:6830:4412:b0:7dc:c501:afbd with SMTP id 46e09a7af769-7e3f14becc7mr5760884a34.10.1778880016810; Fri, 15 May 2026 14:20:16 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:14 -0600 Subject: [PATCH 15/66] 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: <20260515-misc-2026q2-v1-15-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=10175; i=imp@bsdimp.com; h=from:subject:message-id; bh=GRbi9hs4fneyJlRiW99omuykY/76dCQ7oE8fK/Gd6Tc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43iTfdRWtK6PX7VHCOdaK7t3wzvpI2Xc/fZV vA1ES6FOPCJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR ADFxEAChXRYFGyPh2EGR/0nrfrrJqUDk8WSbE1s/rnjYXTh8uA7mC6NXWZI8p+mzPHtSvyvppHu HDHVuzQwhx+/lwmb6aa5WSQ5Yt/OA58Azhd4uhYgp11WIUF0WKfmgtWkCFce/yxFESanGQg91K5 pxB5KifiwkKkjLpuVhvhhQE2fbbTGNKTCkLDPo0vKZkwXAnrfBJFz52iDkBxwMh/4jVyJWjhC+U pOm+DPD3G98lo6CsbMkzr5NNe3qDLPj1AAhw8oBgJlpMGrWgD/GYqIQb7fMNXLVPqh9aqMVshX4 +BjTDnVDBE+L0KYXKSsyQsSxJZqDuoUfANwa349ku9EhMckngZ0IcV0FGuR9qHY8bYWINCoYmrW SVnCdGR/Z78aFxP+xne7NZq+Dvxz5eaJ3cgMrS/uCEb60rfgyGJvjLqag3RMdWG/P4c2RHhpDWH LP7JuBmY3ZnggbPvVjS4S2XFw/wXcPs+cqVL2AcOdRZrx07R0pxX0YhGUKyqvIQQiabqvJUynRS VpEqh6tRYS1svO2QbWXPra30fILrVxydrtVyDFvQytBkBAoYk2WvvP/rXnpREpWPQTNxnY7hw9M F/T1xa5tn0rhaaHThPrhSHOCkLe3+PmMtv/rn/3SNL1Q2fky3hv1nnmoPK3xkKSwjyH49AVKCrf WDL8RmIfLruJA1w== 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: 1778880228868158500 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 | 235 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 241 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..543c9c10a6 --- /dev/null +++ b/bsd-user/freebsd/os-socket.c @@ -0,0 +1,235 @@ +/* + * 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 TARGET_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, 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 SO_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, 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=1778880024; cv=none; d=zohomail.com; s=zohoarc; b=C1nC9yMruFNdLnkmJ3nbaL3chzBVNwaoRo+1aM7i4g/gPzVgKX4gflOitZC1KyM0BWE+UR3c20tmSz+VI7bpsXVQr4MI0BmLEdcGgf/0/O20Rf57bvX29Sv7iNVOfwLUpRDzJjX4BRYzC6s8foA47zcrubuxdZcAb4+uC0xvDhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880024; 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=TftivkvVLmhq8Qh9qV7gzTzq87/tLV0HEXo8E68f++sv9YhDtIV4PKtI5bHPiZgEZVibMmPkYFLsUvuZ/387QEcBzgBlFd3+k9MqouRLWik9mZZCS3WyTbQ7m9XMAb/gIwrMkkZcBC7vUyOSQcKCzYeIQia8Y+ly3gSQ7Xr/5ak= 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 1778880024241169.5556100815935; Fri, 15 May 2026 14:20:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxF-0001M9-Tv; Fri, 15 May 2026 17:20:21 -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 1wNzxE-0001Lk-KS for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:20 -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 1wNzxD-0002wp-3Z for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:20 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7dbe07d3ec3so166762a34.0 for ; Fri, 15 May 2026 14:20:18 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880018; x=1779484818; 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=Gssso2M3E44QiPXz5NfAghjxrWgVhJ9C8OSLt2ZW0ltqlMh7QH8pAkpS5RTLYVVVSQ omJeStze1cqReNZkFZn2geyeMXVHfyPigfnqpkc+Zz2+P7F25gyKMpiE7onK8o6mYdLh fz39SIevBKCc80YsD8l8dyvwHNDQetZTUw69qf8mdqZE+za0Jr2mHPIW1ERU/wTX5GTL L1l917wX76JPcKb/ej4Qb3A6TzWiYaWAVfQsUwKJc5cA4UcMEW/iNJVqfA7kGuMhmsqA Ml8XALBxOLYVOemME4kk7ldlHzuc34Qq+5rQDSSWCluuWtBWGBM9D42PgTTNso6WRyOw NO3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880018; x=1779484818; 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=feYwckIKCOU5AtMwUdZPygX4RtJy3lueRn2HVdKojfrTsf7u1NsSOOSJXXaRlQV924 bGQXJBLzwW7DJ+3CovXwkjRnfJvptEs219fy4uVb/c0smZH/vx7N30+yKJulvMhs7EkH +9t8Mnk7F/EUkD2VZ8EKZ44gDYozKFo6z8P7PmQ2rLBJVHXoX5/vqKGEF+cfO2IN6XSe yCnkngQMfcg/jF9Pqu1yGb/td/dE8unlvgKzC7MioX2CtgsVrswiaTLBKOOc2hOdXy7t eWn2hEUPABT2Eo16e5SkMMgr4ooL17H7MdYWkKuGBSz143+pWR/XKjKd8s1d9Q90nI2T Bc8Q== X-Gm-Message-State: AOJu0Yzs2Q004FO25/zoggHeh2nwFIq21LgAy+5eho2ZTCx2fuf4I02n BVjzITlM2ECsgWehGoSn5Sx0lnj4fSFx7qnBOKT+3BnVrEOP2k0lX6eOPhF1wtuQqDw= X-Gm-Gg: Acq92OFU9P8ye86RWbf6TRThu0Cw9/FWaT8kbsRlNmAteW5s3djcPc0Y25U1EL+TS/Q KO8A/EFq0O1QBP1wcmUpToTHtre9ml0ewMfoKRhPJT4b7Y76Z5o5gh7SerWVg+jolHrMkLOXhlc iBjBDOUvnwLrXeCcU1AaCi15PFqHmVWZiH1NKVBsKWaxlOCFgUYjVw7JIsImV78L8chMpY/iEvW aR8pFhHLA27iYiVJxPQxqzsMDHWMR0Z325e87bIu1LUKHZWJz/3xQHj1kdvKP5w78geGcdxqP4C kJZPpHCqMqcQXWkyTEF9KT2k6puRxi3GjAXCNenHzH4z9KydjN2z7FTHdzwPx/wcltFksG8MAuK zYFMv/hzcTRwlWBsLSPApb8MKZPJIaJmn4LK9NhB313o0Ijyu0/cgu3xfupNFJhN6+HHzLF/zkI Op5URSZ6lVmw== X-Received: by 2002:a05:6830:4387:b0:7dc:c43b:9599 with SMTP id 46e09a7af769-7e4ea07a52emr3810494a34.7.1778880017884; Fri, 15 May 2026 14:20:17 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:15 -0600 Subject: [PATCH 16/66] 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: <20260515-misc-2026q2-v1-16-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43iw4Tqztg6wqzMPbD9c5J9buQYCQgN6HUss yNSjs/etBCJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4gAKCRBsHNEofbAR AMNpEACC+dRCJPA0TeBnBGyXVvYMTEUYRvtOVasiJ+z5wMVHx95vrS225VS/7t6lM46658GmGTR MUcJOKfD5XESAo9oE1vCsCX1v/nkU8OCHyeBQw2ImP8MEBP1u7N7WGRdORO6x9EM7b3va22IhXL 7Jclxl06wtioXBygLc4g4G4yQyl7WnJccsMFiRAul1AT6ZKwefVgbJb7wzEV4H4A4zalMiXyDrY SFCxKDQJunV9s0dnbphuSJYBAgJyrUeIXgVsgqIQFlkQYzuDRcNXrzh9Nra2wkEf/A04d8cZ3qd 2JrZp819L6At5tYg+MUvgVnt0JCEFSzJjBFJOR5M/y5XBGRzEFQG8vZaGRXPLM27bQwGAytjHHJ RoUjnycKn81oJghQDd0MgWUfDC4KyzJ1A3/1P7mINGVCRhJA2EMcNgW4S7470SeX2+k+/M8+QaN bOKADMttwZ8zqOZQ54R6joMHHcilVau+w8YWfgJVWbfRd2yvE1tIQypo4gUvZzA8warvfrrwt1D /UWMdcBmFcvK4RmSGO5bjecTMMSHmxUUej28igP8a9A8q+njr0Of/IRYMxlDuBd+VW8rVmf3+WL /h9ldWPhIkbYARGKlTASehTjHDagNfjtmLoRnx0tdcj6i3Kbsn+/ZQUPykLSzB3oxYgYXYeppKE 75c71BI0jD6nTFA== 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: 1778880025759158500 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) --- 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=1778880267; cv=none; d=zohomail.com; s=zohoarc; b=dA56XIMXjRgQi7OvlhV9r1RclL+IFqHvZJqzWjv+4jGcdi15KTz24molHNKEODNvbTfuMgGVueDX+TkRhLzlVcKOiocH/ABB13oh6KaTIKbRSZRZ4cd3VL9Ij83AiHECVcNHpUUcGaDhIZZywdXGfOGcWOXkQY6pvjMbcBldEa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880267; 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=RWzXl8z0F0/BpkJkUiOb6BsTfXQiEc7EgS1wk+2asw4=; b=P+mDhODLii3NUC/DCGz1Ffp4monQplOAcJ+0overft5sYVrokjmwtU3z2vyojKWxSuvGhBKDjw3OFc+9USasxlLs+R6gvB6ccLKJRNiTvsGhm2A6vnQa2i6QXaa24wb40fZYcX4ZyuQdnXWoiHP7MnIreWi53jCV5+vfgUVwdKs= 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 1778880267206272.7593566764807; Fri, 15 May 2026 14:24:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxH-0001Om-M9; Fri, 15 May 2026 17:20: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 1wNzxG-0001MV-O0 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:22 -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 1wNzxE-0002x1-SI for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:22 -0400 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-7df05fc49e5so347679a34.3 for ; Fri, 15 May 2026 14:20:20 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880020; x=1779484820; 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=RWzXl8z0F0/BpkJkUiOb6BsTfXQiEc7EgS1wk+2asw4=; b=mu/Wgx+93vkVu3YSwYnYFYFIAXo3PP8ow3rFafLrd3E99+4NR1BsoAW/ZRw8iqk05g T27NWezp5Wj/oGuxsH/bdb03fCvcEbb2J98zx5ZGyvoP0CO4ER6Enbx23H/Hfv3OjaPT AwhMuV4RzUqJLBkXv1zxdMpbqLR2p81edPi/mYv2QLOf6ZmQQM5meY1zoX26q8UPp29s hgo+Zd3C+OhVVADAUEyzUALIvdTjPWPaHyM+USdRZ9SBXRt47OKFMwtQ5ZbA41WwHR17 IPKS6uZApGXygE/VTn43NUhTYBDyoUkqN4fhl3TaEodHNNPax6shJZaeZVgaq0sOfiWD o5eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880020; x=1779484820; 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=RWzXl8z0F0/BpkJkUiOb6BsTfXQiEc7EgS1wk+2asw4=; b=Prp8f747lfaP7DDCZRDzmuQzHOcnRAQhZueqnriWUINPpHvD6cPZqkEtqvBde3ssP0 5ew8TFeZmB8OuNWQl/Uv+X8s+ptg/6cx827HpFqI6BleukQ5NFnJ7o+R3S66BpdEF8tf POohXHgMwgawwo+G6y3MNuPkCjj89+88v0bkqwYVXTZobQuUmYxu9vJPD3SNCc5ofR5D DKE6aTXoITFp5qyLf+2j/uxRtjz1Xb52uFVyTct4vxnAIl9bdfOeRyxna3XLf+6HkYr0 vVvxWt5kmeXEEPjlai11d8J0AWAKZtT4wcITCaVFhCIu73xCW9p9KAeNLVNDe7GiKBqO UJZQ== X-Gm-Message-State: AOJu0Yz7X6fKHWAhSfWvx9pO4yogeJTXTy3aq0Yiu1Wa5+W3342RX3n7 qEh9IeLjkwWlqktja6X/Wd8oKUZUbkqtHKbh5azOkxT1FN3IZcvOMNY8Np78A5g2Hyo= X-Gm-Gg: Acq92OFhL//FXHjGwYssY81INDht6BSwL6OymYMnIyvpavqtiZscfwb68PAbcBvRgTG xAyZAh5FWG16/XOk7xcZBlh3VXdKq6GcGtAPoRJx3Q+v3sjmiOMfxplTSpe0YfQ/tJipYg3YUzw jo6ye+gIAxvbmei0ypxqQkxj3ETcSoi87OxGozAur/kAf7UbFgWDAITCNn/sS8nxeugmKRk4fhi oM968mqDZtxG1K3IllPdoupTPeJnL6kMGDRpLcqdqtdNeOiMu68UepGDLhCQL9yvz2Ev1AaNyQx Bk9+wqhDMqWeVJHp0wX05uHX8LsfIr0hwqgF+nOiify2tznIPpMg7l+mm4QPzGyyjsibm5t4CAe D7Fq6jMBx4odqnxI9U5C458BPLPDGvVCz/bfRh5Pm8JD8uiGbdc+ZpH0jL0+O433nkH/XLIH8TS tO2h/ZJSckyw== X-Received: by 2002:a05:6830:3805:b0:7de:427d:34ba with SMTP id 46e09a7af769-7e4fa0497admr3928159a34.19.1778880019683; Fri, 15 May 2026 14:20:19 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:16 -0600 Subject: [PATCH 17/66] 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: <20260515-misc-2026q2-v1-17-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=7787; i=imp@bsdimp.com; h=from:subject:message-id; bh=AFlGlSLn0rd8kDgFR6S0jI8BaOlmMLpM6WEIvrSyrmk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43j9wzeSq4ycwysNfP1boQNIPT5I/sNeKnmk bcxIiBZjQ2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR ACzSD/9/MNwoCgAER/Sw3d9dW92AGHN7eH5pCEHquDET65iIsoQKpbwexk0a72mDCbMdT7leOLz Wn3ZaQWI9KKsAki/SnhkoE+kj1HViaq32hKb1xBtx5xkEPuKcDfe3hB78h00np9zZ2xmauOHiXu urvWOeogMte/wGeGjjABdgFxwSNBO9LhFqKwO/w2Lnb1fIwTFY269J99Ry0wUGDN60NfXR6bG2A OABZaxJKNfFO5R/vFDs+cop7frn4WNFnIOxu/Vht9ocGelHHJ1QQsAk8etYpyHgoULDnoFaE3pk /iZ9IVVBgPZQ9q63KgkIfhWvhcSqZ/3K5UI1jLgzosIJKmrdZHKK2zzAcQ12ee/FCX1u0yor/UU bZ25qHn8KRG9zUzPuBVym1LKUvvfAFrFAaJLrRq2k2CQ8DBRINvvNJSPtDuK5stffTYVg5wHcWS VgvK8PrKfqXRhmTj7ccZmw/PefAkU9YRR/wyZ+B4LTGqfXeqGE4PePYde4B63JB6s1VyBnhyUM3 WInHaNsVfMMQ//oU9UnbJfrzitBltR+N9I1EjPZBVRkSdk5cNvnlooAPKJ//Jt51UvokXhr++U5 RDmF6U5HFR3hILC8pkUQfh9AT1YcBa+rQZ5ezz0m6beM2RQanI2op0D6v8avWtKW4nRGwspizCF V9uvfiLW//++AiA== 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: 1778880269095158500 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) --- 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..bcc1a826a7 --- /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 (ret =3D=3D 0) { + 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=1778880092; cv=none; d=zohomail.com; s=zohoarc; b=SzCIaxAWxCCJVn+ZZnFY/tYoob2Ee4o5kaMrXbbTFkw5LLnb262MG4jJ95BNAM9RTbo0KNFkqU77OOhGUcBC8B6Pp0Kgboc+v9rD+uFAReChVpw+cdsKeEBkcV8yi0BNyNODpcl6K6z2fqUD8QsX5nX6AsRctSngxebD5VC00sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880092; 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=DPsHqsgM5qsQSZVTM8FhflRo6WprK7RH5V6D51O329M=; b=mzv26GN0lajwEPW4wopJCsxZWU0Y/1zTtkHO4hlewZlrxp0Ww+1wzJNSwvFo+ruHvpO2l4vvUe4L1+T0HH/uYjg7roOdGWoPMvxfCvKq5rhwHKvIwIcBepimQ984/YGldiIka8D34yM/7hNUAtNDGhWqh0doVCqB73J9OVBrZTw= 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 1778880092617568.8226698087856; Fri, 15 May 2026 14:21:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxJ-0001Sb-L0; Fri, 15 May 2026 17:20:25 -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 1wNzxH-0001OY-HI for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:23 -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 1wNzxF-0002xA-Nt for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:23 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7dbccf6a23dso289421a34.2 for ; Fri, 15 May 2026 14:20:21 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880021; x=1779484821; 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=DPsHqsgM5qsQSZVTM8FhflRo6WprK7RH5V6D51O329M=; b=IOVCaZuZEBv4mF/IUpcETBwDPKdJ4oxjxEgA/NzW5uFBj1ObIFaAZaiFz0xmhWxOl9 uLRREHPA8qYBDXhy75VwsBhUL8Dy7c8pe/OHEsOIRm+STuHJ6sEmlDQ//HWi3gMLq7oq SQSKElF1PsFhbrV7DCZ2zU3k3/A2hpPZ/YAH8XLGM7QBqD1cTTVWYzJSZVngGJQi0L7Z 69jbcBrhMtj5gkXp/Hb5y5kemb8TW1Roc99LeJD+UA6QioaDzMxOA0spdjr5LWoKTS7U l8ToIHKJ77hYL8idrYFYfa33nxhqr/rBJU/4it1saAr6bqB60yrJgxLznrvQE5X9l2Gb 5ziw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880021; x=1779484821; 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=DPsHqsgM5qsQSZVTM8FhflRo6WprK7RH5V6D51O329M=; b=FFurDqThBjnjG/mIDa5FyOK3ioxl8JUrvmnYE/2DbUUG+ixTRZ8ABQq2Yd9OGi3Fw3 TcfWUZYzMf0l7a2bBvCkxP3R8HAhzzn2lFt4TeTElBcT/ufw7d2wGc0ymlgnRugXXVCr YseAkE0ypVTi1TyGFl6fN3IBmGGWeLQ3BHhs1+yemA2BLST9GaQMRzjy/KCpYtlF4UuL OqxHr/XuNVAF0vvrJiDQ3qVD7pklkUwa9eFS+m6meGc2wLWh6PKBxW8eQH0oXwrUSQif yPxKZ1Twbi4uaWLAe89PQYQ81OfdZpX9q6iG3+r0WIkZ2w8uFj+hYWSRoODwIm0EJWz3 akbw== X-Gm-Message-State: AOJu0YxiQZUYip3Ou+wYdxO4c721d3JFsQoUBUbLwAJ2cxuHAVCVGB8z 0aJKqING0e3TlgdqMgnarVx+X+/JKHwIAtLdu0kzxv5bxvDH02xsZsHvzGiOHHspB+E= X-Gm-Gg: Acq92OF0Q5vwz+5Z1HqvfjRWyQvzLcloohwQ9wRlIBHFpQoaW6mfhsu4zrO/0b9DSE4 xsp9t8EDqvMB1Z1A0ee9W470gJfnHTrcapNUnJNUrZTUrag+i/ug/s1fU2V3+IsKZxzDwBxetvS 1Kotm+4GUeOQl/vcEXRcb2jiTYVUd+rfa6F7VUCn8JQY8nhfEIsAEd5rOPa1TidbvZF4v7eCOLO SjkMOjbshTD7DRH6yvEW/5vO2DgexDo7gmrMQ7o+t4pPOQCUAPUoiHahnE9IinzA+B8Z7XpvCvB T3uyN9UplMfJ+4TdXitdB6K8iR2H6lMEskeYLLTEcuP8cFQDk3EiRHGRIsyZwk5oudMQwF8Bx1c yTZTCXAl3zIHizVHCwrXkQRxZwizIRcmHhCN51m77N7oFhywafE3QiyZD/S/jHoG/fbnlCMpQOw xi/PcigHAvcAYUVUxevwTy X-Received: by 2002:a05:6830:6515:b0:7dc:d2ad:fb29 with SMTP id 46e09a7af769-7e4fa057c32mr3819764a34.24.1778880020730; Fri, 15 May 2026 14:20:20 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:17 -0600 Subject: [PATCH 18/66] 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: <20260515-misc-2026q2-v1-18-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=oHe1KyXwOdY/6MGM1QGr2O7X5tpWFQ9x6c3hVRYAZrA=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jyoAx/KXTMX66id16ZP6PB2X5D50MFYZjH aB4GGF6QXGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR AKW4EACoZtgcmFrX2/IpOHoMLiBcMXh2UFUaJs0OuQsWSQ+YEPqplWvMWWCTwyO4qmh5gX1PSYR tw//uKJWp+/dBazYk3x9H7YOf71LZEgIjM4hq/X7C+MgUlaZJSKP5ibt655pKTfEFNTR4VLxD3x yPS6t5wWK33qwVAUfuVCvgMnPbGBqpmsMK6nWWk6SYJVPJoBrO/fr0qkLhPHJB4t4Ov4J66ObMZ swbYNgiWF9tzBKdHuLxBpUvjLaZpkujpoGbWlySz813CROatAZ4ARq8Aaxnyu4lsm9c1UsZVuzX AVwNhK661nDZHp25KBjHRJXkcSLu4pW3aokjnU9GGym1McY4xaJeXenWYhaywTYqE/ppWBovKcT i6HtnNf7aejC0xLOE6o/Eqxmt5fIS8V4sOOT8YDI/T3TKoAECr95Qrjl2L11sscCCkMiSK4y5Th 05zIR9U1i0cNt+N/83pmUNRwA7PKDBgs8GJ9eXToWHgqu6vMEenlenCH2P+jRm+CURFyrZHUbpl XQMbDt6qPHa+/j2SBhp5kXKSJk/JG3qL1CfVg4a0bjsvEHiDtDN7ojITylLh7crILDj3uvt7OS6 q5AwG8kpr+kDgrExpKcCWFATrhcnxBO06kIzpBKnHl2rwtr7UAHdeRkJBubB3znW0QCLgSrNG5w Y6sVl0yNtrNnfBA== 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: 1778880093877158500 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 bcc1a826a7..f1f8da90ba 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=1778880047; cv=none; d=zohomail.com; s=zohoarc; b=ZR9LrWWu3casHulNz2GKBYN3gFJ6cJ1N/zEL3h4qUe2e+yNDJcV9tW1MnK9HSas0Dj9b/ZdN/SEexPz6CbUBhAK5coXe8LKHdoeYNkOgedvD3kXi1r4lO5+DAOJHT8Tz5qfr0aXpu61B+dcEzxeblEIE7D8oTRtCI/fOdLIsi+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880047; 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=d0/bJ/fvDzngMRNYmuaXAMSOnqAu7xsnIdTO46mvHfI=; b=MXxPoHb6gifRJyMJlhaR0KJbYuYgq6gIkn5bA4LTI3RrI3x4g9JiPR2wtU5jlL7ekMp69b1U8+JeieGjCwEWQJJnl+WjTtARdY9qEbL6ehaBHahcswwSozH0hhVQnIlPc3kWjlM+0wLDn8TY1rEbgIvih/4zLPPPfuPU3Qlc23A= 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 1778880047687873.1194404183668; Fri, 15 May 2026 14:20:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxK-0001Tw-Lf; Fri, 15 May 2026 17:20:26 -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 1wNzxJ-0001Rs-0b for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:25 -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 1wNzxG-0002xH-VO for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:24 -0400 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-7df05fc49e5so347712a34.3 for ; Fri, 15 May 2026 14:20:22 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880022; x=1779484822; 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=d0/bJ/fvDzngMRNYmuaXAMSOnqAu7xsnIdTO46mvHfI=; b=rRdZupzuU3F02pESBv4r0+IpPGLb8DvIq3XWndE5zT7elNb031GXXRVIB1oADdAU+G frW9+lXXbMa9JxK6K0QsyS47GNqVVgk+DggA9rpyBRzfnlIPKivj+YqmO3hp4i3/DPoM UF1k6IeBhHy81J6P+glIChrDcczmffjT1CecufAFytOPgE+oiipbJl0fvm/YgO0rBR7B Gwt52y9aAl+reOexgC0AHrRQSF4zHwzTWobsTSttexLPY6togTm7pn1E9pM/ubLD9Q7h JiJ+mGzCSnqp2ZN9M8kttevbS+qwWzUj1rEjTe4SyZkUdyTzGzur9h29iN/sYNEBKuEI R7cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880022; x=1779484822; 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=d0/bJ/fvDzngMRNYmuaXAMSOnqAu7xsnIdTO46mvHfI=; b=BpWBM0q22909M7WGxrg8KMrRy0HCebx/Keq/pkFokPx/vA1az0xD9FyQLbrTvfjTTg R0u0Kr/lvrWhwTeVbk8UZSC1r2xPgP5y197xjG/Vr3XAIUx1Ocp3jKKvnK4LVsLzJSMH gejOg9lY+DBwtu7gv1b11uwiFlrFOj0wXIK/YfCEa0klSW6Iq3VPmVHsyMU3nED5PJ3o D6qZen0W1UjuXT5LO9N/WNVqZFXbEbBTRU1JPjycGOo9NkjgSvgxPcf0YgOCpLeoM+nU csbj/fGLeCsjxmLBjLErdYNYXmNXLx9F6nWODeZAuSOctm/z5xlmFgWQHCdndGHH47Nm ENFQ== X-Gm-Message-State: AOJu0YwyChBkOaDGDZ+x4Pgi0L8thOKOLHyLj2oIa6i+IBS1h2CkJ0M8 srRbU0RmvHGTcOkt6MlbOMnbM/5/zQDgYmnCLQOudITm1jEaDPyG4FuEPRXBAs3q1sY= X-Gm-Gg: Acq92OHM/Sn3XoE3/0Qsy5FMLiqO10kdxPcNZoUNgQvHPjnbQk8sANXDKiOgkvS4eTM AGjeC3lyalwFINePuGv4AR8T681Cx0mM9JsEL7yTVAXrcJ9CUBXrVX9OeWAOibF7SAQB+bQ9pf+ j4ObCL7pi05nIVelrfLltAFx5TWl2HXYEQ10+BASHBOBqlOSxx1CccUkDgT3dTCNRotK9ctMM5F qrwK9i6hA208z36CBjiPzAOjeDPKBXLYsSpDhqmxRf17xwXhWuV3aFNUdEthuYIkNcVwpIb8uhu cictwiXJVzQTpg/GuU8aGmuq8iPTrfOy+LUXPgkv75DNPbAY/4MCbA1soDNFubA6+jgioWIHNtO AzG2jF0hVx3K8Y8nRlytWMJUmVM6RaSxBJvBCmauvdWf3F9JVN4Btcr1hz+O8NT+6NuSwlUf4TJ 8x+kHXFk3lVC1eHtTGJhLc X-Received: by 2002:a05:6830:3688:b0:7e3:9d19:1e47 with SMTP id 46e09a7af769-7e4fa0b04bcmr4354925a34.25.1778880021763; Fri, 15 May 2026 14:20:21 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:18 -0600 Subject: [PATCH 19/66] 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: <20260515-misc-2026q2-v1-19-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=hJ5CDrM6haAQECdrugV65nZzHU/y17UdE/xwfIVi3MU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jde8TsRLqAaGG9dmScuNjoPkRNNZ1v/xVS bOVZ1SjMbKJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR AHJeEADclKbk+98LPJEDnWAnsdWhV4cWaa3NOjdfWti2wOp1S/N2VpYanBdEJuyvqDbKOQMgPud 0hgtfP8CEo9shaQO6rRZS5sq3qYGIjkSNVutC78yKKvmY2YspllYUGiGBhyc+Tg9s6nLIl+ohqt zgu2QozJrI/ac/HlpmiDCQN4QBoMHIsOFwlQ7rMFOIaDwDaydR0hkEB2/TiwxautU+EBRO+qyqM momrPtpXJPe/MrRvepvTeYK4J/BqM3Pa0yqOvXAUah7Im0v+235ZH3jH90k7XLPumGkvZnrzUuk O5CBtiyr3mzeiVnPv3cr7GXASryvnu6T9hvo50wCSa6PJ0pJOTRxBimVkwjORys/2TdUae+350N R3EHiDYuuSa4LNIhib9LXa2OTKBpunITmH3mFQAlhPW9NTbM83ht8vnmSnW6yxyZNSNNSPg4nMh OrsciHVFaALhaluXPe8PqPFiuYeQAnAPfxy/J7MNz0PKDiLe/zZcxxC3bFsPLxWM2NJHc3g0dgC REUbfblH2XklrkV0ek3OChdhRwpdpv9woL6kI6voBOQAhkIGQCchgRMDma4JmhnS7YnPGxysmx6 QpcZtbepemIkFr7U/3AZwcGeh2eYrMsFfuN+LXemFVoFVI5lgWB/2DJHJEvumvnnskfOtcVyHvq l34sgCrA+EXu2DA== 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: 1778880049575158500 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 f1f8da90ba..51f84c31a1 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=1778880168; cv=none; d=zohomail.com; s=zohoarc; b=HvTDdJzWy8rU2XfNFRDzJe8aaxhkqP9GFTIDxZ2rZ++Ku671Vk9EU9htWvtu/rf00jv4yzJUHgS+61Pl3NFxwv6lvRk91TBm3P22MRiCpfM1PiMyoDit07rGVMpmSbBMakx6kZM1DRYGOlH1iB4FjhtZlkEONcfwOXeF+NrVytg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880168; 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=MtMAJvJ9gtsHpg82pTb9T1Y8653dSSHM3WKLgtSNkEA=; b=fXRPdkN65ID1XpktmMiuUF13rAOqPu+eLjk/mqhUK0VqWdcp5CP+d68oqgnFYXRLBsbw5PNYZ53ilDCcqnZY8mirm63g3+7GyUDCzegiD+Rlln7VlCHStx6zGBS0TWk08wbgQBUI+uWXnD48FYUe8dLA3E1vkfeIXg0+aOOsp7M= 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 1778880168028695.8192308682815; Fri, 15 May 2026 14:22:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxM-0001Wd-9y; Fri, 15 May 2026 17:20: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 1wNzxK-0001UD-Sb for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:26 -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 1wNzxI-0002zE-UU for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:26 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7dbca22dbfeso156174a34.1 for ; Fri, 15 May 2026 14:20:24 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880023; x=1779484823; 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=MtMAJvJ9gtsHpg82pTb9T1Y8653dSSHM3WKLgtSNkEA=; b=QZIiOUwlWlgxtNvijDUOGUxZyu5iAW9wB+fAEZ7sdKGkLosxC9vHYR2jGbLV4ZlwBm Q7RV6T0J/KVvwlQLKUA0Xz/u+F+WmMJDwMA0ajnb1vaVaIJnlO4XUwmxP94yT4BDVaXY nHFpEt9qP9fyoYCoZqg4vMRYFyhtM4kmF4SujERL2w6BiEnnbPzZOM825+IdXVdOJVKo LSqV9K+Cj4aLF7ujLv44I0eX1fT1PrST9G4HEhEe87GZBgywGEK/VqqSqgy+ws7xtD93 G8D2wI+NaYNbMu8n57Ayj6n4mrc0dWRFFgF6WV1zx1G6pMnUM0PdvtwqmxWHDvM9oD6t UUEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880023; x=1779484823; 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=MtMAJvJ9gtsHpg82pTb9T1Y8653dSSHM3WKLgtSNkEA=; b=Vbb/bmef8CNSoxEsXIA9kQIemctqMxZLJ+Skwh0snf3yXqbS53V7AeWGz0qQM/0N88 KLSEZb0ED8WdrpwglG+tGoyIhMkQyfBUFK+EHUGDkIrKYhnRN1Ldy7OOhZzm1cYB0Un1 Qc0v/ahwWBi7M+cMgiwzdQaS9Jd66W7HtzOC1Zp9NQ5hOIbMWsZLKsj+ucRW+lxHZPSl DZy7PNt4RokkW068s3CpGkBy8+BmS6bik1sBGQKqzErSJnY7xoIxdurTtGsDsdD341Rm cTo2mMCoe16mPuvzuZZwbeqBqsNWeo0qqFYF35xXvJ5uHNyDocDYKUjH8XHi3oRiy0gi jzXA== X-Gm-Message-State: AOJu0Yy3PpdWfY1ugv99jw91Tz3ZdxV03AchkXZLcxGqxyW736Kj6zDL qZ6LiN1p+nIySwA7QpaiVDmSRdqNxkPjk5Tqg+nZlvLRPx7C1wzJ7JH9F4n86VicX+I= X-Gm-Gg: Acq92OGHowKpAi3ME9P56yM2SB8nVL9RPh88AfDULS0iJscb/3RiyZR5ML3xdFoghz+ KjqtIqrybuaX3TFVKdW9h8DbWO9zRxwUQa9upZ7qEpPBn7IMWaCQU2Zhy3jpvoMIFdrSn1C/Z8T /WHx+oUFNDUrueLgE+SRGRLm2/BKRmcfH93L/Dg54aFwrnB+IBaJIJ5NQYAFf+XVYbkUxo+m5x7 HUHnOv3Ai3zwiDWQwONcOUNMCceZ7Zahazfx9Ys4iqhjPCK88uCDx1PbdlKoSi80BunXg9NSPBS NIiWHDRxCi80yVeJVTEOr0Yq2BrkotNGWyM8/YHGwvCPp+60AA/xw1cIcimzuNTKeraKRnqWcAf V7ocNUy5tafdkSWXThRr6saHL/9+pYjm5FOLM/UBljrYZEVnWK6XZzvB08pKhCsKCUkunYJh8I+ zjltYXp1FLdA== X-Received: by 2002:a05:6830:6408:b0:7dc:c7aa:22c7 with SMTP id 46e09a7af769-7e4de65c157mr3604477a34.0.1778880022705; Fri, 15 May 2026 14:20:22 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:19 -0600 Subject: [PATCH 20/66] 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: <20260515-misc-2026q2-v1-20-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=8195; i=imp@bsdimp.com; h=from:subject:message-id; bh=Ow8+m+yEs12FhD/+xURX9PAkMetNt4xQX/CrgqE3TTo=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jhcLmUqlu/FwWW6O8wrthtA0Osh/AgdZkw keu7U5WABaJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR AP37D/9cDu4hwFs+3ghVRMA/JpDMJU3P4xoOXFmcGH6gtk3rljqEEqHPQgO8g1piwHaH4F29u+l T2zc/uzZRXYGu0ZcoFMmHTfM2NVi9r/qVimDD1hqy7Tga/n2Q/M272fHrrY6EkkZsbeTOYRTWlC iPoHjTS48BVkqog6RLvCG91/1ia9V5xguzm+HBMAGjBUE+RTSKas2qh9nB2MtaQhhQa9DhmIvnj AciONM+8Gqx/Jqe96RkBJ4QMiGEWzCwgafAAAATBh6HM9zkMVpyqvecEU1IKNRwyDyAiHMCbz4r 2QfuSCKbhIKbiGQ/KxF1++VBBaHi/CbwgVrigGrweSEd/w8rceKpupEiR2wJTcg1qLHBy+wMr5a M84LWnXUrxa6V1yCrmJrOPsgrwIyuZbtaqy6XAba/y2s36HqgHsbZkgW3VnfUYIPMKvb8f1YeN7 Kq00/jFrkVY8vnf1FbN3JV9L8oxsQN1H8XBCGxDcZQqmQiN2TFN5GwpT6VznWiQwE1RDis1Ua8s RU0bPRniwcMx01xjTyHVbfzxgRPNjlRkD97VIEtUByYuFav6h6b4EPCLh/gHITuicOGIGIsDCtJ CMtHgyALc8p9iwpzGYbQirmowKNJgdQwAUlQlmUZ5+Nbj1HcDI7MlkMrutbd8u8wrS/2jGZzWyy KUZtTXXSnokHKRg== 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: 1778880168365158500 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 | 174 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 174 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 51f84c31a1..f724acdd0a 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -629,5 +629,179 @@ 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 < arg5; 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 & 0xffffffff, + &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) * arg5); + } + 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 < arg5; 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) * arg5); + } + 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=1778880099; cv=none; d=zohomail.com; s=zohoarc; b=haSji4Ue57g4//Jp9Zb5Trl2svsk5DXYdEdfzYWEipWQZgS0byzKwZ86afBtjdfsIKcxRvNIWWMoZN0LhPo6oy6w+LTUXSloo9nBLHLHNknzW2Fyu3HnR5UI10qlr8iOvG1ZPUf3CTHLUq/Wsx0fRFjJNZdDAHT2DHXTD2lxpC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880099; 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=nsywyvrou/nifvOPzoxYiCCFY2AVnkqkPANe7KEMhOc=; b=D+ldA1pGnBnzjS06PzlM38ySbCS49QQfF62xJnWH6JKEbE/6TsfWaPKVdO8y0EAq8b8hdIi97Re4qejporU6gKr9Yj2cP1F2LG4SwNbYvWl4bNA0S90aQ+edms0QToTtQwbZEiTy7mo60bzcyhIDZIntV9lIiyXrxq0SU3vxOGM= 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 1778880099390310.6411939009788; Fri, 15 May 2026 14:21:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxM-0001Wu-M1; Fri, 15 May 2026 17:20: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 1wNzxK-0001U0-Kr for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:26 -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 1wNzxI-0002zC-UT for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:26 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7de431da8fbso321052a34.1 for ; Fri, 15 May 2026 14:20:24 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880023; x=1779484823; 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=nsywyvrou/nifvOPzoxYiCCFY2AVnkqkPANe7KEMhOc=; b=fQbWFaTQOmRpWUuUuhbec9Or9mHshlMiA0Lf+OSZNODrpna0t6x2N53SPPCFmifmVx h39amY5env83IZjDIiKlaQYeL60s5PCSxRCtQPhNLhAF8A/Rhx/smiGRmjf2GZ97zbtp 3YS5uzbmY5Ij/FB3c04cCUatb2EavG8kQnNQdYJ5GAGThOu8xy8fXGem0iLGPvQHXXkn hXTrc0HcKNwEU36BpHMDo4c6SCMHpZcqbk82pYDVW65BhYBO0X2Tv61TSd7izPBhUOtu lA2sMSh8GgEGSXhF+sKMvhgscUQAYK3s69BR+0EK8OvdYSD+D79hUr/BhX5vUshjPXtg d4yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880023; x=1779484823; 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=nsywyvrou/nifvOPzoxYiCCFY2AVnkqkPANe7KEMhOc=; b=fhgVEX2l4Zj+5mrZNbWBtQ6XiBOaLBbkk6cfv+DfPN+mGNNI6FRMBCAivvdB2OBgib /JY7EzjbEn4KhwVXXLMtQh9jMoFVEatN4Tav/jj4wqpOaTK4dgwEUv06yEib5/VueW25 C+EhyNglanv3oUQA54zOAPWJcuT2qZWuJSIhU0mITOHihlycFBOuLeuqyi+XwnK9P/wa UEJ02mGyPrir3hutUojsgziPffVCBfxf4wjMyEXVt8UsWHxpeMH18WxtvCMGQkXKGlzu Ve0ZavFSSn/o/B+TGaFqwFTP53z2IY9N7TvzgoH4B8ol42cSbDfePxS2fqQwjo4w7h3z nDQA== X-Gm-Message-State: AOJu0Yxf2RD4ILfWChK+B8IdV1siGDOfcN8jpwE2ZCj5dMUblXS2mGsM XPunF6Hg2/d9/1slyguokHmtJCecFxWoMFXTlDmHwTFMqSt1wyf7CPgVBC3l27MoVIU= X-Gm-Gg: Acq92OGA23ti5Cay46/005EK6Qqgqlo31twSxsPzn9VF/0Ko/nTdki5NWdqPT0k5+JM lgWKnxK02dySu8AFFm6tgMzeBqMkQzuCWq9a8WBn2FOmpYpAEhZTW5k2Iv4B+rVuu6GiwtacoEb c5bjBASxj268QBfUcjZQoz2sQA+RKLlKcezd4nV49elgmIV6gHBKDAYtXBwG5jeVCKHXZU1Ivkn VRAsANxg9tWTOXgJN7bEdsX3SWMKsLSsuuySSNWb4fPQMJJhdz5+dzV1Q7F0NXUI6HYy3Rd0Gn5 kBbPbp4+nXRqe6XlKD26vosfC2tGZT3e5ZMg+XZlDNs03QMRJzFQf7tkwCGv+cmNTYx+1UBaDOf VlFlzzzT3DNFQ9+pvWAkccPoUbkbhC89bUF5JZiHNUatdu05tOCPT/05MNReAMtT4MVNaT0He4l shMyyzIgZgxg== X-Received: by 2002:a05:6830:608b:b0:7e3:7dcf:9d3f with SMTP id 46e09a7af769-7e4f2b80758mr3918862a34.16.1778880023616; Fri, 15 May 2026 14:20:23 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:20 -0600 Subject: [PATCH 21/66] 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: <20260515-misc-2026q2-v1-21-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=5571; i=imp@bsdimp.com; h=from:subject:message-id; bh=OezK06KQzfBQ8sP0O3UBskrUbtUhLqlbcFGitRzC+ps=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jKvYQGL8e9ELougghcnwvBdLQ08BOR6Izx 3lwHrm6mRiJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR AL3pEACHbZ/H9QUttPM2/67awInnk6YDGscD/Psrunl4J483LNf9QL+FVkQRwIUsOtPebo7UywO 5X0U4Vuv2rvzH2vVI0NW/mlaMct1NUF3AM55F2wAgyrTATIx44XQSrDn3q1gQuKDxH6G+W+knBa 7DrfYmiEdQL2hhHvPvEM7HQhMrLZDQ2iS4FwmrXslxmVIZZHiNUmwRNzQxOh/IxNmMHbRyGhGPs 89cKB/IxKZXJGvJxrVbl9MgecyYigZFmO/XyDlrHHg+AjVtP6s8s3S+2pjeHEKHM0pEJITvLblg cVe4vvibXhCcmNukNuyab3pzNzZ0xROMI6WpGsJjhTv5q0CHpcEiJF+L1YwQvukQHBN5Jx5dVyb KCq+JyHRenKblDFo4zhUHfPPJ1aSl3LE4QS2W5hrfHdPEKk8/O72JmKjjVOJKDw4BMh26Syqp2i TCHWujKin2LedurWf8Ts1jtyV7RBC+BnjQoPh4dDZUPTUeanDK1LcHGSQsikAJuQqN1Hu4cw0zv GLkdvSr6ioNpjN+tupjD1ERynsG9ZTGBQ+dj/uerYkch4ut0Vy4t7ayw2eJ6aTRqdWxoS2SBi/J pSMefoRTPuD6LwbkydeIfJyttspZAmv10kQgenx9xktA2aUf98uE93mp/zt+7RVW+d9Mat7PC+Z bGdwXgDXPX9f8Dg== 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: 1778880100017158500 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) --- bsd-user/freebsd/os-time.h | 169 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 169 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index f724acdd0a..d838994742 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -803,5 +803,174 @@ 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; + t2h_freebsd_timespec(puts, arg3); + } 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=1778880277; cv=none; d=zohomail.com; s=zohoarc; b=jbTnMJ1578BbIoTXU9LZ5s8kaVbQ8mPhBg9dV3SZXjkmw/oRh+20MK7eG1+Gjz03ixkozbsx1vmixa8tWYw6HwcB6UhkubBtT1bQH5erQanoVT77xpbtgod+zOjg98KuiCOM43ZpFniqPWZ8cRf0UtwjyVaBSUbEHJ20gG2bBDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880277; 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=XA2VapCdTmhzDnbqx3LnG0YGhwZKj+LcwAtR9i2xat0=; b=chyRnyffEGinugar3sK3YGsruK1zPa6jZISSkCROZYgVsTYcyHiXKhnf0ZWdWDbQR8Nvhr1h+e1RCMTe3+b9j0kdKOd385BfWPX0u0KoehABMXxAgjDXTQFexQPyFeFOjZjN9FDXL8sAgr3OYGyfRysimGcBeJN1aSZA06wrqdw= 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 1778880277568305.78320864721104; Fri, 15 May 2026 14:24:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxQ-0001ii-8F; Fri, 15 May 2026 17:20: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 1wNzxM-0001Wl-GM for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:28 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxJ-0002zV-Ns for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:28 -0400 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7dca4debedaso351556a34.2 for ; Fri, 15 May 2026 14:20:25 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880025; x=1779484825; 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=XA2VapCdTmhzDnbqx3LnG0YGhwZKj+LcwAtR9i2xat0=; b=kHikg3Agwhp871m6BxpcvmU3Fr7FU6rh4bYdjwjSxYWalKJPxZ5k/LGv86QHIZmKs+ UY4iPXNU61kh5RxXYrc45IM3gbHe8F7T91my4m9zOXwQUriQXyApjR2Cuw2dsDMXB7g0 d5BGhlx+iLQ/Zitd8spy/vrAyFyJCgNRjKvZvU8ypdH8+xeACCvoxu0qYvUdUOIgX47d BT5r9SkZEWPY63u2LFviquo6foVvxfm8//nf+jSnRmdGI1G+lNlIcLDxkz73aEnhsXh3 aPzS4JGI/H7zUo39COE8Y7ifgMiawBTjHV/19zDliR91IG+MdeB/X1Ol1+cfRcP7jaY1 fzpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880025; x=1779484825; 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=XA2VapCdTmhzDnbqx3LnG0YGhwZKj+LcwAtR9i2xat0=; b=CFwDZYJA7YW/pUNLNby7RCCS9hLBsKXXJ76NZU+8LqC29PJ4gtMZWkghPLhWCWs+az wPkK2sa4hNcw/CJnYQjE0BsI2tc3EGItiKJBDYAQSRV1NmY/jfNuWXmn+lM2Nhv2SE4z 7VaOqYBzKcUn9mRFBmw0bKxGQdSV4Ebn6sIabmqdfH4/Mpr37awfKM1Qf8e4So70ICwV 3aiMmiFl4QeKiLPKGGHPRIWpO7wGcZQ1mm84dPI4Macu1Pporf88KtKmXvoivEbM6xBg cIKzfJBQF+KtFXkHzg5+WS9rDGlOH7h6szyrAljvFcVu0dyl53hUzcFAcLhPNx20yqq6 Ps3w== X-Gm-Message-State: AOJu0Yy7SqSfwr2aL7qqem6Sk1s0hy/OZNycqdm+zDCUP1d2hzdsdu+4 qUA/OocVRFMa4kEp/rq/gBm6FVsoUB7B3fTIYROcLjDoqsvjMtPXE/7v81k4hv9USzw= X-Gm-Gg: Acq92OFQhPkQoTM/yxPQQq9Xbn+E/mYUtV+avwv3NwVGSG3kauXdM0px95GNNpD8I+f KgAbyjh3mLa4Zyp3F+otiNA4yy6CSlGq84LtNe9y5dtwnNOmjuwFSTMyFLwXk9Y2k0kTu0KiSSl mbKJsmjx8taBWOI72ahDTKbU9emcwl0WW1fW/2NBlo2d1FaqmbhAeEBo3HgHXXxbIH9b38wPyxu uiY9YbTxHI1iQEfCibX+/TWSNzJtBJHog3Qf2QJo+cbGqOZnG7FmK5n+1H9gZlZR3PIfO+kGTvA /Sodw8u5VROgsc/2vJPhCbvO0Bfr5yY7sJQTZCWCGPSSZDRh0SgPgyHXNJUS3mKU8+jtAPGF18e s0AN3UdlJHaeC0bT5Jim2N/Cq/nQYA6iN8mnTCgaDNhzrBRSQmC3wgn0oOubf182Kpnz2isXaWs F4lW7Z1AlX3g== X-Received: by 2002:a05:6830:81d7:b0:7dd:e032:3ce5 with SMTP id 46e09a7af769-7e4f2bce60amr3751278a34.17.1778880024611; Fri, 15 May 2026 14:20:24 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:21 -0600 Subject: [PATCH 22/66] 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: <20260515-misc-2026q2-v1-22-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=11185; i=imp@bsdimp.com; h=from:subject:message-id; bh=8FJBhfUKzsQG676Z40f+0IZ90MIMLdq8HQ2JCFqGk4U=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jQY/EaDZmhUj66oFmMdAUBy3ymXMMZhF1i IazlFA2D7OJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR AOibEADXd7PzDvXWWsAxpbnt4LCqQ5/w9YFJ5m+UxqGV09bLi4wudRBvaXeIwoi/b7xP2BzryJk 2mhRJbNSVfaWXMe+PEC5357cRSd5r4DvaWS0JXN7whu05p44WRaKBq1WYL9TgmvigOBi5lo5vJK uXaC7MUJbSIt9rzRdhh9jcXOdCUJJNkA7us1C4tO96Gh7JpyhQpJ6YA/2FTB7pbRwTdP3QuYOO2 kwC6a+EpWD1/Ltr8nsGzp6aX3yBw1k4eBrfUHR4M6GyBQAMm8bUIcagmq9UhyRe976GA0DcOucX oPtZPWp3pTNmHUs5BdK4l4YpkdfDtLM0QAmLofg7u6C5P15lj4x9/xltDCTifrZc5k9Xwl1M0WT 06gP4FGeMtkT7kHg0SY+IAsxzzLSzhohw9iWuT0P972+odJPjUS1UYEJHrBC1IEm/gGAw5KHb8I mPjcmyywmJXmyoI5SRp+ClhlFPou31fGS9rtNRkKYg1yhAP0ONb0eavDL8UJTPYTVawb+I86rH6 KaIDgXYxjsHKqvRTbN5VPdMz0NIwdKxMtay5iEYsGV3meCdPfKfG4PYS+zs/YR1u11awnKHrqy3 j+XG8KOyzwEnpHBencb4caFzMUDz8sXAIFD70PfZzwPIoQ8pRzU+KTzmXtuM++bS/dR944J4xhv nyd0m+lA8Vs/R9A== 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::334; envelope-from=imp@bsdimp.com; helo=mail-ot1-x334.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: 1778880279223158500 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 | 315 ++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 317 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..4333d7d30e --- /dev/null +++ b/bsd-user/freebsd/os-time.c @@ -0,0 +1,315 @@ +/* + * 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, 0)) { + 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, 1); + + 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, 0)) { + 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, 1); + + 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, 0)) { + 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, 1); + + 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, 0)) { + 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->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, 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); + + 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, 1); + 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, 0); + 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; +} --=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=1778880253; cv=none; d=zohomail.com; s=zohoarc; b=iLTABYkx1TzzpEb9AUMyZJWdf9x1L2/G/vIF3VuGAHWXefB8WuK2BTGZQU7wOchp+wua/9X2qP2yrLaCDhHBB6/v1t9EtjT2pAxzXAj/89jTVrAyc71X6SNHEOJ5gu+OovjkP0KRyeBEWXILF3XQxU8UBkzsSGbZscqJdQRUTKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880253; 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=AcV8BH0ssDuc4MiYx1bUIWeDySGls4Z27x8aYXyinlqsn+ZogGTTGFhw1gpASxCz9YZ432dSpS6700UujOUe3vjX5t1nBvFRzXAPkua2JIs9mWz6wPLnTd8Wd3tyg3cex296q/vw2pF+bNlVAnF8KTypKZE2+0gOsZvZP5TbM6Q= 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 1778880253675711.1247951805622; Fri, 15 May 2026 14:24:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxP-0001hc-RH; Fri, 15 May 2026 17:20:31 -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 1wNzxM-0001XB-OT for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:28 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxK-0002za-Ts for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:28 -0400 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-47cbd445021so260338b6e.1 for ; Fri, 15 May 2026 14:20:26 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880026; x=1779484826; 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=KYQxR7ERD3u3B0QdzKIfKTg9gSYZeqgrfQnBy0WU0A9B3GqGHQjeN6mrnK9fb3242J 3OXpOMFP3FtrzjqZ5h1yfBEkAJcct8p4D8ASAODKt+I6sC76Sd2L6Re5l8HDDXWrcokK 4XnNa3cUp2Y0QUd+/HLBFOmW+n32OK4V7nhaGM2U0/kB87Ex0+SFlf9bFkJkXbBvjh03 obU503YtzofqP5TIAZXtoyIWCQisXiSA0qC6IuuqrXidw0sFDFg4NZF+qZ/la++RRWaB 6nb45ewIfi38gqS7gCed/sfGnxKGDo1FB3rEFkut0jlz8qO+Kz1mxg5HESJ1vUiU1pMI yxog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880026; x=1779484826; 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=iqwbJCWv3vQ9BeQQaaiigLZwb1+HzzeyecVp3F3sEXbSs0EJKLNqe66Al+7jVkYLTz 9XgmbbgtydpkvgE/YFcEVuH9HXnS8KjkwKqXxJcTTJhN5YbVASKYu+5XT0ahyLowDA/c QVf0DxjqK+lbvMuaDMdvfcWY0nHmOEGkycQFq5d8/eg13i7DW1+PbZm2v+AKVSkKwWLV Ce+VqovBYVQSWIbfB9oj5qGDXZe13Ce7lX6Mr38hmP4R2Sa8BaF9i55qxg3FNlFjHqIw Hk+hPC2TS6tyeqrLO0js6ttNM2VVgbM5uR+hQl3iNVhty9BO9aFx/JzETcfBjVFE40dH ocFg== X-Gm-Message-State: AOJu0YwoO6MUGP++1sYZqzb3gQOplZMviJAOdUUGZmZlAPVgcpPNUCbz BhQby6h84zhf6X/58Y+0dxy2u+noNbHWNS6L844BaCFziRIVvpysVcec3bZYuqWcH6M= X-Gm-Gg: Acq92OF3Ebtf4Hb9/UMQZpyDESIJ5XBguvrL8iN3PnQS7lKAwFCcN2d5QmjwnxTErlm arHBpXDC5JBrTJhBFFV3aqBRqd9vdiyp8Q9vQd6INmCyyLaNprRvar+j/fsG+gb18HWhEOlcTsH Ox3kunwalgYtbqtGmd5SpqiR7bd06mkSdQ6Y9Beud2AjBTvZkUFtsyAZ8/voHBk31+Btq3gjODl eXKOgU+Z0go3dUimhtwVI9yfL+vGezyxmSRSOQtJnFihAp6VNREvhgMR9ktdRCM/mh6H5/j/jf4 0Jhn/49pSLKhsEiF9d8dtV4w7sksCGePoP0pk88Z6aJjvn8OVEsgHRlgzU58sGlRTpOHzUsZGPg BtEpffullqezcSuuFWNIg/t6B8oalqd9djzU0oqeiO1y3AvEAfhObxRoBG2bbUNpDXBg7R+1JeK QPswLdGW0Y66JlaNSbvory X-Received: by 2002:a05:6808:3029:b0:462:aa0f:4375 with SMTP id 5614622812f47-482e5789699mr3502449b6e.39.1778880025679; Fri, 15 May 2026 14:20:25 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:22 -0600 Subject: [PATCH 23/66] 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: <20260515-misc-2026q2-v1-23-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jUAbt4o89J4tBcZHNPMwBha2BpiRTP5Bxq kz1WAYcCaiJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR APKkEACo/WMlOHpMs/74M9a/W9kSP0v4Y45BLU/dwbq9ULe++Jm39iGeXWd0fRPWFSfb79AcTyP z+cdjIxRxdHfOEhy8J+n3LJvq2Cqz2jnoATK/nFd9pUjpCNqKH+n6/u6sGxPVvlOKDAIcOKGS52 9db+kJuIqKjf5JmwUPuJKY80ILIrT2CpEE/nIiHwDjbFSKiD8mUIbpBTgdx1w+mQi8xgtrm37Ju Vy6vW2phwhPZ2ilwuSUboBqjclyVeuAp1eXJ8h1FgN0K5EeY5TtSznsNNXwkGyIy7MWu/GAMPW7 llhWAOwJOYVlcQisuCpnE2J+ppUllDANukj7sbkIQxXOblD+Dn8O0ivZwaQRCAdnNHhhxcOknqd 6cLhy/QaVHABL86k1cFY9hgUufIlJanxUeqWmD/CW83nmEwlfl60ds5PKV29UUUh/NqOnCEsUbF 778bbBuEAI71ZhLocsD/NgN3jIoEnhmjlWKxOO0OLkyvpk/b3ZNbN+yXpkFnhvl7s9Jc+iFrBWI 4Md/dnZUmRFkncYz7DDCgQiapV+RiuhVZkEVj/N96JjjP53GWxhfC0yk1o37/Xbr2ed+B1jW+74 mI099mdMYszzSAw2qZ44yDjiYNo9Qv/TJws0s55gw+EBSNPkOD7hwLXhrjX4HeeBPDXCVZQMcdr Ip4yarOeF8XRcaA== 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::22d; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22d.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: 1778880254905158500 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) --- 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=1778880269; cv=none; d=zohomail.com; s=zohoarc; b=NoYm4y1HgLASVWMDTQT6uqW9Kj3vU9JkN7w0mp4ual7u9xwnGg43BjyFZ9N5yxAwOT74e+B6mb738RWeo6Md39JOUxxUAy0K3hfdmEtos4Ldu++9Y4xN4HWXhL/qqpbvHS+H/Z3+wLWuLFyNcm4EBkw4OoCQtIZlbuTVQIFsmxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880269; 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=AoHEtuYMkVdqIlfawsmYMiZ+fZ9BGCllJjcLT+LPjRQ=; b=WV+Rhc21DZRF3ArvaY4QxrIcU3ZeTP3JRmhH+LyWKatV2YMFih5TijQXsFhzgdU6Xxwk6h9ZQj2F6QgUTdKUHHXdSiL9MNqTExQfsUtXL4HWOim7sbmVcDtdexl1hhm3qqfwltUpFjAeN+JkHYcacqGLT4C/GOzovGYwQwe4VYs= 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 17788802697901020.9598411565088; Fri, 15 May 2026 14:24:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxP-0001fr-7I; Fri, 15 May 2026 17:20:31 -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 1wNzxN-0001c7-Uc for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:29 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxL-00030J-N0 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:29 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-47bdee5bfc4so170518b6e.1 for ; Fri, 15 May 2026 14:20:27 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880026; x=1779484826; 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=AoHEtuYMkVdqIlfawsmYMiZ+fZ9BGCllJjcLT+LPjRQ=; b=BFoC1Tr7YigCIjnBLaQsl21guGu7GIjtg4XMRxU2PHlrmPwE5Wa5Vfod9RrJh6u6bh 0Pm+xTnrz5OPzpWg2ZF5y8BN8bQwJRGjFGzHErjkfeNzcgMT80xGZAyc8KYeCcxUz2CS VpTr+NCxDgj5gg/dbbQCWy+7JFdag0xbjpYoyOlYPgOTPUmQewrLC9EpgFAnuCxBI3QL Hi7C9n+/cyDd9PICqDIN0OQ2WleOQSw9SRmKVuQ9VUL4/BoBgC3w7NG2dhgLk4AVICbN CZKMsGgRJ98TpQPK7E0M2/Wem6uZiFgpddPQR3/GKa5GEiHAND6wtQqm2KKIC5id9g3z 3c0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880026; x=1779484826; 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=AoHEtuYMkVdqIlfawsmYMiZ+fZ9BGCllJjcLT+LPjRQ=; b=p6wDRl9GQjyIKSuWd3vPVF1/Y99CeR4b9ajHZ49zt8xGLtImV26XBXwSCGVRCOxAwp IKnHxC4sN8HuKpOHfp2xUHez3pbS+LkQgS1vrXpkH8PRwNWSAoexlVrDyRpEIP0wwjAf eCZCv+bwjW56qBpL4bBKuXJfj1ZqWWpOfkRKwWkdm2Va5JL9Jd0rfu5pKnRheqnRpuZP 4AoFoy5JhyL2vRozABTmPbx4jcKQmvQJdlSZKVm6FnuzcBqdCqoDGVfDgDjp94yola/6 bivoEsfQbtaFFGaIkehmF+OYb6rfT+Mzg9mBSrRyQg3Ib1qTof+UdPaNCcHWXcuWtWxC PiIw== X-Gm-Message-State: AOJu0YwGR4xETZtH1OfnuDtAURFkO1U0oq/AW3nQ4oLJrWGbxOiUgCeb 7govETC9nVjhtXcnk5d0yhkJxXKm8XEoBvX1/b6qXX5TBo8uO5PDHR1JlXbBCbANuf4= X-Gm-Gg: Acq92OGaRKknsGXzEf1ok0lL4wIIxO4g8Tu73sedmtXEuIUz9yzu6a3CmwnHxejSxXD 23XwYN4BVGmI+szxPYevpUVGRDjTF0SrRH9D8uoLz8nnBrOmHAg4kDQHvR1Vt96qCMVSHNLr3PU MtfXaXPb90NFYX7pb406mVRo/BRRrIYbx4uK2ccBVGOflLQfSlwpLFiq7Iq6MyQVBPG2BEhAog/ q+TfGSA/A/rotflza0OOeZU6u0eQxezDmvuFbCBLK7FLRZp9JPSNpjTxnVUxkY26lLyIAHbTiCW TByJwS2vbx+dDBMs4+YSd3FTR5N02DpqFjlqls5Ti/bm/DnNtK+eVs8T+v12y6wD0BlqcB7kvZo Cd2w/jBA97m7BdnSOWcI3h9xh93hxmrMwLuUT+KsojInL5J8ycCdmJ0tlnc30+bv8hyn/e8rimZ 1h7R9i/tu2XPyAo3oefB3V X-Received: by 2002:a05:6808:118c:b0:47b:2b67:71a1 with SMTP id 5614622812f47-482cb7a8b93mr5365817b6e.14.1778880026609; Fri, 15 May 2026 14:20:26 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:23 -0600 Subject: [PATCH 24/66] 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: <20260515-misc-2026q2-v1-24-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=5796; i=imp@bsdimp.com; h=from:subject:message-id; bh=eYcd23KlONZHr+bUC+1S1HGMVw1Rm4rDf8qWIjZHXxE=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43jjvkLmrnpASqmHUWN63ZsuRkm8v7w8vRko hSVYvuJeRiJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN4wAKCRBsHNEofbAR AJbeD/9sjJ02pp9Ws/cQbdSRtQh7ksryslngOdJ1xZAWlM6sdo5FMoZuZeJAz0GIU80YeqzYvEN rBiBjBxYxGYoxLJZ0r6UpMT3JFT2LsB37fo7nMm2UD/uU4da+8nfLfKZZHNtRHx2E3TrrHv81AY xq51oqQZLabqj67VEab36xotLBKdT5rjuAYeyOX9rqnmzd/+4WP2qPPhpGKeic6oiwVgeG47JRI oCHec1ZaLYUZ+pzVkVCdzdMlStV5H2BxTZFD1LgnHYiLeLgCMPxXSy3NcrOHqGkRxS0iTnhA07R DAoGzN7/Gdc5Ou4lILWEz8ThD7JHItFRcfbUxxPvzXg0JMHrQb4h+jWdoxYP6Jkknvd07pfLCWe VOcOtC92YykH86Wh3TJqNK3p+SJhOjpA2uz2GTq3vv+5DVNS7x+XSMzA3VA9z4juZi3/pk96dM+ OzBukfUkzppahFOIdmTdGj5bXIveBsrLvkZoVUdJ0nVsJMx8cyFlKz56w7wP0hdnp5cpbZqtgN+ WH3CZOFt7i3/TPGQdyBG55Rs4rNkpQM6/mNERq51x7TV+VrlH/L8lTK+Xdc6P2yfmE2Xu1FlD1F 4dkz9QN6zNZLyLdYykz/JxrD4FL8h0HPv7l8j9EXCjDfnWew3BHtLBGdMOVU0Ga5pUCz8qfKM3y /lLk/tmebS9bXQQ== 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::22f; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22f.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: 1778880271337158500 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) --- bsd-user/freebsd/qemu-os.h | 47 ++++++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/qemu.h | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/bsd-user/freebsd/qemu-os.h b/bsd-user/freebsd/qemu-os.h index 12adc50928..bdd28f27a0 100644 --- a/bsd-user/freebsd/qemu-os.h +++ b/bsd-user/freebsd/qemu-os.h @@ -32,6 +32,53 @@ =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_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=1778880262; cv=none; d=zohomail.com; s=zohoarc; b=BvOKYYKeXFAV+hidbK1sUbrfbgHAeOn+4R4zoy8BEsUQyxnREMZUipq4FEW7met+tHrM+IoczEZg4smG2Ae90MvaGOCfITLaQ2L4zIGVkasWKsOXYJcnDb9FDyT0w53edAbatZrE7D4OaW2j0QiMvx4jqwODaxQjJZC0oZfGahA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880262; 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=5nC4k4a0OZgulCg4sth3HQUSa5b3mq9IfQPexGkN1x4=; b=G7wYKz+7V0TkfwIBFDT0wX7QJBMIfVJqsJnDJNQrpSx+/zwZXBz3w4S55J9f7SyDvMyHIqfvRURpHmnzD1+4PS2F9Ww1s8xb0y5NrVeo1cr6UwSBlr4Py81boyx9cLCCJZeSTip0rP0yWkDPY0D/J7Iu81oJk7tlNhb5yxpinMo= 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 17788802624188.974975197239132; Fri, 15 May 2026 14:24:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxQ-0001lQ-WC; Fri, 15 May 2026 17:20:33 -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 1wNzxO-0001dS-F4 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:30 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxM-00031c-J3 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:30 -0400 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7de44ed7a11so383342a34.1 for ; Fri, 15 May 2026 14:20:28 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880027; x=1779484827; 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=5nC4k4a0OZgulCg4sth3HQUSa5b3mq9IfQPexGkN1x4=; b=iLRI9APrHrY45pz25xE6EK1E17P5dZGjkwZylQcN7636gQ8KDhUUG3svVOCKs9VGIK sB7Ujq87tZ+P+jluw5w+rWisCb5CF7zR7LCWAh54zPt4pl+Qb1eWqQTAWZAtTJxjMQw5 2nf1+Q2D7Uh2vwlQXW/tQXPvVSyAax8DTFTmkJbeRWzKQCrICrQ8SyDwD4R15kH6h5+j XxGiR+MROYVoBWBrdzSxIgtQx+kpu9+C1r44phzVRF4P2HrkEAFqVcN+iLxF0LuAOLUo GAgPwDZuslS9pTNi/eduDq8hSaFHyTgqF3IIdZdc821FsnDbJ7gubTRIQobLmFx1kExK 8sHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880027; x=1779484827; 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=5nC4k4a0OZgulCg4sth3HQUSa5b3mq9IfQPexGkN1x4=; b=Gxb+2i7hoi8gXw8WpYtoByIFGrUgXO3Q66EqB/ma++yEnNWulcXrbBRl2r0hT83GP5 CANz1kTVEHz/WejJjpuoGsUmbrbf2cj0bVHskLQuKT3qLEV1d/EYa+biWVngwNnEu0RT vkwfGMBbaUl/T9zpYxVL1bC0TIwNiD8j4QayJdbi9Kgrj24KtN+kaOVruTd7O3eYjPHy JFNlGbSgYOMgxZwyaAC6g4YFLnpWoTSFeFhojW5+0WjSMsvzzTwzv7r5bjcW9NAyCWqo 2smMN4KHa6mS4vr+B/a+/W3C0IeTJCGb72O7eWtu95jSdRGeZa+nmQgjJyFKH0be547p vJtQ== X-Gm-Message-State: AOJu0YxCFXWxSgzcjyxjZpiF9CE+G7GcCXb5eURTyjTji6LNjF+Txub7 hmUQZG04UtSYslg6tt4nfCQtw3hCZSozMozwQzkPk55FlN9eFBrDeMrWnO1VQ3iM5Ag= X-Gm-Gg: Acq92OETlAGE6QhbIRsbtDs++CrNq2ol9TQmZsJsC/hcsa6JGxycoDLLbua3/x8FvX4 pkx/Fq0CY5acVzaeXHe7dnAbhQeTVUeqGHV30o0WcR2SO8yG40pyXBbKnPzS9zS+LRp2cjpPnqI B2QX8LGTG2/1iQAEpAHYUN9jJbxkhHK+U3pXOZeG+S4zuS0Hm2xq6wKdkN69Pzt+BUVh63QDvNQ rhT5PsoVAI/gstClt4C8Ej9l5Midip7Xe0n0iQ2ijtn/4bDtsQPcjGoVNHBu6j4vZPXl3c3v1Mb D7YZNF4U2vX8lvI847L9xl6KYq2kWy7MXjxSfkeRTInPaF2b5tbdQSDal0CRcF6sKxFa/SckYL7 AN+aSa6BBKYxLXU26M2nJhBKmYY1ky1iqN4mj+Aj5lAsGonsC0HAbCGa3rkwm2XjfdkdnTbe9C/ myRf6TN5wqKU2PjN8Ci2pk X-Received: by 2002:a05:6830:82b6:b0:7dc:cb67:cb67 with SMTP id 46e09a7af769-7e4ea04cc70mr4179072a34.5.1778880027499; Fri, 15 May 2026 14:20:27 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:24 -0600 Subject: [PATCH 25/66] 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: <20260515-misc-2026q2-v1-25-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=2949; i=imp@bsdimp.com; h=from:subject:message-id; bh=zAas4XPKJk5ZjTPrSwO0wWkCzVH0W2AWkE5I1mEiKz8=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43k/W5DaNHkDb/MsZRwrtuv/wsTLJzK/nv12 J2I/EWAICKJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR ALTyD/9aNj4SU4srcg/MBWBe05Y338t0AHC5dWRYCaPeQUuqPXl8MM9t1HIBFRtFRQP4kKHujge jQs8hL0h1tphPz77+G8ocf8JklARh/cV55VWQFP331GlFcsimtqwhsvzsaSEZqvw5xRPQr7tD8N kFI4P61y77Xe2iFkzH45dIL03YwP8vNyw/jPH+07Q1diVRQYqYPK0kEzkn6WNrNVD2capCenL2I 1o/wTjpkNbd6zPIiPycfbajAjVpWGmHCqA2YGdOtc3qI7ctGKFex5mWEjmYM48iUU2j++n607uo D2gv8c3PqlzFPN1KXETF7rfNckyEIMxgFeDsOoSeTR8/sGS/R2WfCOhWhn8Ypa8PvqUrHv5O8kL TWwqFaBdgofebrk0TxGNbzLsafq9qHQobPDApaA5ViHbjxvqhjxjfcRaONc28r+FixrdAT1j+Ep 7qvlA/SsQwXA4HcOf0qeRXi+6mP9N5aYyxDOamG5ilsZlpLrptizkDz+hOkTBIWiGvP35HeaDtF oVX6uvvrtofcGTQlXUWzHGv9O2+NLelq3xlr8h6SgpIrSeZOFC3wha/d2uiqlz0lEC/1TIUOdlE QeexLM3c7mAFikmL1+ta3Rr2o0XSTqFOHHA8GsP4CGcbwZSBfPRSy2bibotu/xuGok6LKbIFmn7 9ZLzsP+nl2ix7AA== 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::334; envelope-from=imp@bsdimp.com; helo=mail-ot1-x334.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: 1778880262976158500 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) --- bsd-user/main.c | 37 +++++++++++++++++++++++++++++++++++-- bsd-user/qemu.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 73aae8c327..415852d88a 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,39 @@ 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; + CPUWatchpoint *wp; + + /* 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(&cpu->breakpoints); + QTAILQ_INIT(&cpu->watchpoints); + QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { + cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL); + } + QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { + cpu_watchpoint_insert(new_cpu, wp->vaddr, wp->len, wp->flags, NULL= ); + } + + return new_env; +} + static QemuPluginList plugins =3D QTAILQ_HEAD_INITIALIZER(plugins); =20 void gemu_log(const char *fmt, ...) @@ -256,7 +290,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=1778880200; cv=none; d=zohomail.com; s=zohoarc; b=ZXCyubnqh7ZAXMv52LjnXJ0/c29HYUd6pE2CweUYMiO5G0ZQxg3yLH5Y0poaMxTrzpz7J2d3vui2u03T+sPNydMhLPKbLjiQh7qIbT1Zr9QamNGQ709XjmQXL74+44gs0LJ93jY8J7NaYBRZMbzVJpjk7/+Zb0c/AgWzP3nRMa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880200; 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=8tkVLpax9YF+0bcdoU8w4zYIme0vzuVmf3yEPa2DXjo=; b=nTTqfnW2AAx0DxOwwKN6wOX0vKG3y2of9cHO8F6B2UcfpslsOpIYwJFDCegOOmbMG0sKaQ+0AEcFNHe0UxRAlcmCOB1vHmGzcHrXmwc8cff1V0aVuGv38PVoa97f53IvTxvKpCIIEgLqiDvP+bc52AdgfzIMPxUDnjkNfp8MDhI= 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 1778880200062190.04013800676637; Fri, 15 May 2026 14:23:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxS-0001oe-KR; Fri, 15 May 2026 17:20: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 1wNzxQ-0001jx-HJ for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:32 -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 1wNzxO-000326-Ee for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:32 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7dca4debedaso351651a34.2 for ; Fri, 15 May 2026 14:20:29 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880029; x=1779484829; 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=8tkVLpax9YF+0bcdoU8w4zYIme0vzuVmf3yEPa2DXjo=; b=K3yvrWRFQK+HdjaGPtoCzBHO+EpGEGaFUNJqZ6o0Y6UV34sxJxgh4HKQQf48Ta81/5 pogAzmygmo2XcDjTKpKiO4poNaq1N6k7kMvYW9VqNZcxOHY5c9E6lirhe40LPJ2/BUat Njk+xmVz3d7lVs1GPZC8UEAhQ/bIByJ5DmEgXO30nvQ8fuopHr1FyG58FIVwsb96HbvH PrivZZ4eb8+olgBEoXmksDF0jiDn6XdqiCnFh71aeYzQAF3XCNp+aht7xy1fNBjWY4TJ IOmieuckULgj/lceEIjETLvJ0Thupr2T6jtLPdaM96RtwDRNGA7A62WuBjETuOHytDT2 frzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880029; x=1779484829; 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=8tkVLpax9YF+0bcdoU8w4zYIme0vzuVmf3yEPa2DXjo=; b=j+Uj+fmHn0CwieZZNJtayYh1XHg1qaFHkw2+6p72t2hJ/wnFpPriR1ZwWJlfwYMnOX KJT4ISentZPfRGgXXDlHSotE1j8+rtVwgaejwgxvzs3ZzeaJ1A65wikXwa2DxHMn7vFx A+w4IOtMDF4sxvBss3pqBhop4hURi2dT2SYjbdfDgabEao+0Z9Q4u96mWd7Fl58htXtx AshaSCF2EzIQFlbrqT9R07REWRbb5p64sixOldEoGSbPkrXSu0LuK01d+OVY62bCBBl8 22PW4DZGxltT+Cr8EN0RTom4v0r2p8pF9C/73xJVXHG6H9FxGhB0lPaY5USzY06JpzJB 1kyQ== X-Gm-Message-State: AOJu0YwvEPl5vKIP0N4zh/L0fERjQLATpxO6L34Z6SEwannv/NdSPiS7 8DjCJvyWsn+4Uqe4KJ3QxQ62wKDIrUGLy22e+mtNwhNsCjfhPnMlkNCeD7ZWsrK9QZk= X-Gm-Gg: Acq92OF4NFYBKuLP6O2aEKl+piG1DeiZMS/SoExEtHqDrnUJ8crqC9GfKdlfV7u74rG CyrTy5VLotBJvOYrqGWG4LaHcwY0Di6F/8lu6P28XHb+kEvOjziVQw7t8rrE0vQPpiwukV2Oui3 8nXNSMVqJa+77KBdNu4rLPTklFy+OspYdeUnO0lhD6o9O2+EzqxSm4p0Qts9s46KT4V3+9UwW6I YVC3hKIKfi5tWG1S1UUdLuvlH62eb4iIzbdGoZFPSI1SZstEy5Nf/IpDPGgrWUzWIaSUG7X7thM tueU84+I173biJZ5ys2ybpgyblkOMArj9FgGNJvC25CyV2fpy7NpsO0zaSt2p50UCHKACteONku rY/owRSWm6i5Wb+Gq/j+dMOac6dxA4svatMirYxj3fCeQGWFpN29LMUhekwuH6KiWCF9lR+Ydqe hQk+WsD154z2fYxcKw+RsP X-Received: by 2002:a05:6830:91a:b0:7e4:411:7ad with SMTP id 46e09a7af769-7e4fa0afc39mr4230017a34.24.1778880028893; Fri, 15 May 2026 14:20:28 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:25 -0600 Subject: [PATCH 26/66] 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: <20260515-misc-2026q2-v1-26-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=8569; i=imp@bsdimp.com; h=from:subject:message-id; bh=+uAoW3bPRS/NVFT+C5oQicSpiAo2hsPqpobk13lE4rI=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43k68MOpm/xwwkv/VxBqif4nv8lJF5PciuDi xKz0CcPwISJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR AKLMD/9ROAm0FbshCK/r5pgrOfeztUvtfluv/+8UtjZ56DmPVlIz8kCBIwIA15Hj4Efh8JkBps7 EaDqDTR5h/6Y3YSyBjWBHKKuWuLBnOKJ/KueK37tzXCzTuWRFeLkA5XcRhdAVrUFI1VsvlJHFd3 5HyuK9097PciHt+stad7tZPNjYUHIMh07P7A6oZ5LvXuji8WM1dbOE46gSesWR9hAqSFqotwM29 e25TyVm9h9wpNiY2Nrb+Ik0ltxE6Md2NHlMb49yTe73XY1wx9tT6yC2yseY0EPZ/DaCUJp12FRj 16Rd1fbWBTwFg5N2K1ucuCdCIFqTtYljh2lTc9EftuT+D8yZD/jhaE1e3FYc9UJlplzHnRggvkg 6MxjlDMbzEfiRSLNVX6WoJrGgtVCTgpVZ/qM98jPij3xFS/RAOOf/vcI69YZvl/aTUM30QtUe5y 9nHUlAMdr7fxw/SvBUv5+taZaGpfwesOeuTWE7X/Ke8QLsTAVv1/NiwVvfsrEYwYVSz6n2YeR49 h/4wLBWGJjrnkbEE2J3NVUnoDW3DgtFuJQ3QNRVheZpbMsbshuaUTojtUJSB4NLxJPE5nZuvcVv OAuCgpVUbaXMp7gnGZIzqjO2fdzbI8QB1YnJxuyd/KkA9CfeJgsmcgAB91fMxvoGRLL8g1wnPTN PDDcLTh1UQ/N+tQ== 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: 1778880200712158501 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..d063ea1b05 --- /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 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, sizeof(target_ucontext_t)); + 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, sizeof(target_ucontext_t)); + 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=1778880216; cv=none; d=zohomail.com; s=zohoarc; b=GYP5gYMoW5vdMCjc9tNADtCtCpDEZYIfKeZgkvk+e9gayLe32gQFb2XCyaE4IBr87yCN2ulj5uCCTBVbLsTllzWRWnXfk+7aI4Sg/EqghkoKW2NNDH4zEx1MvTlIpa+BmMZUti/DRRQoNOFGZZPafEwqUE0KBPpj9TZPKpY5Lqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880216; 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=lnsqIOReTKaIY4sP0bp5MAeqJ+rJm9GnOiYsfaGABBk=; b=dZzPwg5ZQkSc/ClX6noNnNRImnZqhPAiB6aatIOJukyPYXeXXsSZ8Ex7cmE3aG81mTzwS2RUC7K24IcC1sC5duslfAMImPb4+h4rcIRS/iXgpB0iYpz2BilFCqYYg9Kd4z/mZ2GjyuHcqKV/xX+psiK9nJakuDaWEVNlKY+FPMk= 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 1778880216099797.1813412394572; Fri, 15 May 2026 14:23:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxS-0001ob-Hb; Fri, 15 May 2026 17:20: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 1wNzxR-0001mL-E3 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:33 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxP-00032L-7v for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:33 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7dbcb467f2bso313237a34.3 for ; Fri, 15 May 2026 14:20:30 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880030; x=1779484830; 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=lnsqIOReTKaIY4sP0bp5MAeqJ+rJm9GnOiYsfaGABBk=; b=theJtp6i2cXJzVBzy83MKdcGHMJVxC8pNm2BYW60dXEGnkKSwI32qyDGP34ftJs5FG R1z2ddfAqfFJQntzr5vLOnPt9RoEvJ6wwVycz0xIZ+h/lYotVzF4z7iWBqGENXzBbfu9 jxgu9fd80vawx5OlV/pvhgdWomGnOyWNrfl/R2rchyQqEqCfnYiMIKwskw6wxdr42trT sp4+gWOCuVKzmci7VHc5XUBn54E3EyN+J4mf/2D1OmYElIToAsy0z5U81uBjOwbukXIO 3SXX4EcVfrJUQJes0wrb3Inn31vkzH512UlJ0TOszmeEsqiFH91g//Onv/exsxhYNMEK pMDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880030; x=1779484830; 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=lnsqIOReTKaIY4sP0bp5MAeqJ+rJm9GnOiYsfaGABBk=; b=kNLoDamly+0sc0JEx9d1oUfecZNlOG+kUuVX7/ag6VkszY5QCyNeryyEYB4+6sfmE4 YKR4IoI9XZlUSY3F+UlzID3t3XtjH6JUZDGlul+A3c+COzMScRNuaTJTsWaNPCYMah8d XukYidnSM+G9H15H3+rMZi6/nUQfMoP3LvvL0DEXnHKj4O74cgK+XOMUrFZ4iFC7Xpxn BrKhJPs0QPuEKy/oy30LYLxQX96ORP10ypA0D6w9ioBLzjzmD7Ss0he+QZm6ikPWNxdg 9F5U2QrpDWLYSkAGPIA1qy34Hm1A/qx0iYErIvaz50kS4isPM+DDtLPvqFehE8ZP3ynn 9PrQ== X-Gm-Message-State: AOJu0YzxsGD8Yhrp+2ZURbXo8Qlz+n4dihWcuoFQV+PB1M7PA03c/1mH XS44GfM+s3wKcZkz1q8G4JOyl4eP7HkN3RHwUHmdsYPND/15Ty9q/hHIxC9PweIIlsU= X-Gm-Gg: Acq92OHvcAGqQcnOocsg+N/vDAxTaLjaMX/GI9bxkzvMA/nyCM6/ROIVXy6sTbg6d5H VTcVnpaT7BkdlGhYjqUdtsBOMvvFENj7tBGjW3mWMTmy/lBs3mA08UF7hABF98oXrlATDvAM2tF JUwjncDSgkGOqcCiUE6VJwa1ybMyG1fB57kDOXIIOZq1dUVuWyJKrFxbj8nGOActX7sPkemTBrL K+Op8RatoYNOBuFjJH6bdMSWZwboNl75oaSbPS07vAZyfrrAdXWihO53RE4lqeVc7KAKBNkQslU Ds2HNVDMq4Al7UK27oUJDJVokLYVp9Xd9d6dmne97oasSyy6XZNPg045PCJyN3+Msb09aiFzicK 8zyCyzuBRkv4nZ+hkVJ1fAzUtbMpVQh3Qq1owtj+CCri+uh+9XgKizr0kLrTww5wDn6oq+ONsHY pJVPfViS4Hog== X-Received: by 2002:a05:6830:6d29:b0:7e3:6b8f:1e93 with SMTP id 46e09a7af769-7e4ea01c97dmr4064175a34.5.1778880029980; Fri, 15 May 2026 14:20:29 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:26 -0600 Subject: [PATCH 27/66] 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: <20260515-misc-2026q2-v1-27-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=9kAnlJsg10tbfgn9qQZW4Ig7TCn5tTeM1ijrU6ZeE00=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43kPETLVuUIZLLbrfDTdFZJYRN8TT/9//tIR wGiqYYncDmJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR AEb3D/4hUgmx4XIl2nGlUiK8f4rPc5djjpM8/A99ObP2z0TkOUpzKwbH68cq/qmTMs78mosKl+O fQlgicSKmBmhjk4Z7XSnAQ4L3y+WdteiTCyfSInHPbg9Id5XXhNpSGrjPjxelKYBocZbx3fkMeE 1ZPxYZ8dYdDnMoW28paenns7qUrNM+T/B2mV04GNwnn80W05wUbQsWxmhpQujO9N6ZOeDMOuQa4 P/NxMtK+qT9zp4af0Zx2DXTekoYr9T52+eMfUH9hu4RApMYcjd2Y7lKhCVu9gYXs0W3cMzBlW2u m3BGc2TqFssDP20sbdnvyCHDngVYT+THH0avdglmfqOFhZlTk5CdQcqOWkWf8+xZ30II60p/I3a p4YMn0Ci/mdFRJEgBpXk96WW8w2B/jqm1it73RS/G/9w7xuURBPwDlOMwRE0wXcNjkCkvKL16uC E7AKk/UziwgOGHsRtZiiOxKk+R+kJXMPPr4NNZhJ5bw69rWltzeexQde51EmuaNuzP8SGphz1ey E/9cfwW0jdHBptw6m6lzdS0JsB86yQuMzmmVGVNjmXABGjVqhUjSn6jDnJv4kvfgIpweC/bkDlV Dm4MQDh3CLFTwoSVqOFe8YbP4pyuPeC59QUA/OUHB8HS29v7C715wtFIx3NspYl1Or8NEfqnOSn yvuucJydZ+bzzpg== 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::330; envelope-from=imp@bsdimp.com; helo=mail-ot1-x330.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: 1778880216846158500 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 d063ea1b05..c9a5e76338 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=1778880253; cv=none; d=zohomail.com; s=zohoarc; b=BIITjQdPZPl7Mbj/AHzLCcaf6M6UdZoDOvzt+FlF4XGqQrZAAnhNNenyWjd8IJ61Nepx/L3p1jta8tAXWYns3SIWwBtz8NPKyVeVSvIhswGNE25UEMF9YFV7ERyxBjwHhpHgai6NbUiKyFeuf/Fe4WNsfJTcC4Vd6EY56byqV6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880253; 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=7TViD2tPL4blxHHCsmvAQf/RkVIfYXQejm2uO8k/G2M=; b=mZU4bvieD/0QRRcPNlOiQIvNuzKEDSTe5wzp4Le8Tb42gkNxNcFFFzzWnfrLqfRBXU+WL4hO2q1NXvXLyhEzxKO51GQmK1DGXyH62hxY8zMHd0Ji8J5A3yS8uB896jlk6OGKivM8IA3NUilOy2mRx6zHKlJW+LfGOVeUg0SnxHg= 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 1778880253955846.4188127076386; Fri, 15 May 2026 14:24:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxa-0002Jh-Sk; Fri, 15 May 2026 17:20:42 -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 1wNzxZ-0002EO-8v for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:41 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxQ-00032Q-Nh for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:40 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-47c7b282d73so278147b6e.3 for ; Fri, 15 May 2026 14:20:32 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880031; x=1779484831; 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=7TViD2tPL4blxHHCsmvAQf/RkVIfYXQejm2uO8k/G2M=; b=CnxmcW5N1UzoV2tAI/KKeaX+niWqCY7j2GlaJzM970QT21lkbu2g4mka8v73SZGBlg KFQE40CX1sKUNgdFS42wiluwUuCaI5ujDmZFYTMBRwpaSymRlA3p3/DunOOt4+ow8YlV hemnxROItWtmemklVeKHuk5xU/aTMNPosFQPU12TNg+1/fSSg/HzpseTXo9vUf2B6fD+ Y7qxyhTr/i7OQ+6vcGLWhHWOaPYOqhYtyBvEij35m9RkxlZWXp5TqShB09jS3DM/stCR TdZ99FjryWkylFvcLqMUNmkxLTES8DJwa04O2Wj5xy+iV+BPBI0OH5BsT5MJappmx3LW A/Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880031; x=1779484831; 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=7TViD2tPL4blxHHCsmvAQf/RkVIfYXQejm2uO8k/G2M=; b=A6SkhJEPZg+Rl04Jm/M8gN24oQnPIHWC2xH9tCvhRsY+NMYbaGf3W7jJTRDsDi2KSH 3/eDq2bkmIZTH1WuHGde3ok/cdl479wddMldUJ6DB/vPGaL21HY+AMmipqXDyV677Jn7 sjFFxbH5kZv77QvGEKAvZATEKdwFUx83YR4xM93cLrmqFWgOIZYVPlb5FYpTOekXLb5/ cKZzL5MoA1WCZp9SO242fxJs2TpXMwP04Fsrg3wcb/wd7hU+klcKW+GjRsognu4TbOrY Beiqsj9N9s70VLN/QdHn/9z6vhbItYSYskm1MkpdDiGncQYp/wOjIMiBmZd/UgoRHxWh 5jkQ== X-Gm-Message-State: AOJu0YyZrnImGMGWI9UR7fEqTaK6QZdN69j0agjJYSGU3LnhZmBkDizt +3zg6+zFZsKu4JngiLGjL+nRwHZWskgOSgnKO7d8MKvtbife1aJv2LbZxyaJEBUcirTk3/ER+0r JO0ixDGc= X-Gm-Gg: Acq92OF3cYwpQ8Yz+xhH2TTB24BEkc/2iDFOC4dOzkjRPempnW6x77Uad2WyT9hw9Iu ni+Veq+jmVriJ3EyATsH9noR4OUTuzk43OEZbj1stPnZwuEnlLW6lwMlfwRG8ahtxpTTrQIaUUC j1Lp1F6wXoZ0YSh6kGyMb6T1COn84kUdNpeDvRJ7c2RNF9X7usrE204/ktj7k0rHaoLVwsKvV1Y DJkFiPA+kaK45dUaAlrEB1xi7wGIfZSi1fZNC267Mv8EelA6BVTd6u6V9j1IrccIYq1TjL6llxr LpHMxpdrxtJtA6pOTPDzBeUhrifgvUlGMGncNRixDCnl4fIYPZDbIGiupjwCJaiNoiCFXWzTdNB gBDzUT+clUVTqzhYlPo2e2tCkX9CEy4U5iPM3x4t7jWssg8PXyxUDQy3MRp/cZyn9m+kI2/z1SR V79seRrdFBEw== X-Received: by 2002:a05:6808:d51:b0:479:d57b:83b0 with SMTP id 5614622812f47-482e5943730mr3883134b6e.22.1778880031223; Fri, 15 May 2026 14:20:31 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:27 -0600 Subject: [PATCH 28/66] 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: <20260515-misc-2026q2-v1-28-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=58645; i=imp@bsdimp.com; h=from:subject:message-id; bh=mnMK1Re7QTxGv2AcC+QD5NnWQWy/cKlNBi7tG9vAPno=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43kmRwGteiycUDU7Db+BBVb8R2XxmQav0dRc OQtymL9ttmJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR AEp0D/9/MC0rQ5XY4hHz2u+bEmUfgrx5ixMLfz56LV1deJVdj/LcXHkSZnYzo1NzCJfxxbIXwub S9HKEAIffuPOHTyaG5up8RJL5KI2W6pv6sKR3adyrqVcyIquDMPd0BmuSouAdF/e1P7Gi1APFlZ +2lGAfEwX9jQ3R0t4iF1rObGpTBKMPY/BWH4Vowj+R9YQVsTNvwHAijCCMM/+++EDArObMPSPgn gOvl3rMbRff1DtyVw0OvxmV1JlLdFxB8+8tBdLOpqA4ypBaSN7aBzHtvUi8WU03cXsZr8G/U5Vf X/jSW2wLk3ipquJSs8Miq7viDSSu/BwFyyzEpcKnI+A96qGnNtiOX52k5ThqQ5Eu7X76wPqplUR Tyc8uTTQa2NFBZQEP+oU9hMmXneOwD018vxrP3RrqWin9U055b3uwZF7tLB+D1fgxLfIpUUlEic bJFNMjCbLyuOODuixJBo83KY+2dP2akkhgV7TXLKZySjzICgGS6F7dBA0Bs4gvW45b+53SS9tub 1By1vZAj4imGF/+Txi3/z1urWK4huVbWRKPtlJYptCCIyB/MV1Mt501SLJ1uJrmG3Lq4gAnSVo5 aOcqaq+wNuj5D52aLLTwCZ4rpJfa5wGo0ObuKuaL/a0vT3157AAQV7iAwngwouEOhQOnrTX7Cyl YfT4huAfQ1yGhHw== 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::22c; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22c.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: 1778880255042158500 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 | 1654 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 1654 insertions(+) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c new file mode 100644 index 0000000000..1d88ee05e4 --- /dev/null +++ b/bsd-user/freebsd/os-thread.c @@ -0,0 +1,1654 @@ +/* + * 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 g2h_untagged((uintptr_t)&target_umutex->m_owner); + unlock_user(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_WRITE, t__usem, obj, 0)) { + return -TARGET_EFAULT; + } + __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, = 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_count); + } + } + + /* + * 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 g2h_untagged((uintptr_t)&target_umutex->m_owner); + + 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; + uint16_t 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 g2h_untagged((uintptr_t)&target_umutex->m_owner); + + 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); + } + + 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)) { + return ret; + } + 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 */ + __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); + } + } + } +#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)); + 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 */ + 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)) { + return ret; + } + 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 */ + __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; + } + } +#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; + } + } + + 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(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(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); + /* XXX Free new CPU state if thread creation fails. */ + + 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. */ + 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=1778880239; cv=none; d=zohomail.com; s=zohoarc; b=Mf7haKwyNSZqHaOPSVe/2Dwc/4tCAa1NfRYoeUZnMnkiQpi1eVHIIoTh5Wt1S5V6+A+8InWhtwCRg/NhfdGVudOP6Gxqq/pTULK6RTpQiFSgOx0o1KVshnwijJfGiG8q3JndLgphQtpnmXDvBCNvi8McwrTsfAhlLDKfZ9YqrSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880239; 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=F9WRrDBM7LI4O9ZVgPdq91rMlaVwL5Psozwa3F/PLeY/nLUUdw/bCiId8HI/M3bESOUyr+iHLPXnscCNCzLDyX1cT8yOX8Xw/B0SZhYG6z9+f2M4LP9dIohNhE6y9NpJnbxBCqmUIr9LDp6wRAXuT2Ea1hgGe99pdcnpm9RHcPQ= 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 1778880239729341.3743406426804; Fri, 15 May 2026 14:23:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxU-0001ug-9m; Fri, 15 May 2026 17:20: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 1wNzxS-0001og-Kq for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:34 -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 1wNzxR-00032X-5A for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:34 -0400 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-47c6f914617so193517b6e.1 for ; Fri, 15 May 2026 14:20:32 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880032; x=1779484832; 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=JtKjS2PyFbWItwKHdsT6skpew5DqIYLIMi60HpeS0SDtUSv0NIF0yy1WuGfpJcZk9Q wbM6jITxlydpafj3XaJVOKnY8L10W78FgnWLBvmdtuyRxp3vgnXiW8X0GboozBzChBpy 3SwNJAW+tPO0lZyedSwMsuVfQHNNMf4qedQFWi2mvHCpPWhL8HRt/DnRxuPWFWBqthzd YXLxYmFK9XOKLD4Q6/7Bm6h65bmJiMq2TeOKuuA3p/ZfBqEEc8qIiy29w16I8s/cpGjF IPpF3a+YVRtwfn1btGxj8Z6EcXD8OG0Y5h5NoKSU0Chzxxy7GgcthR8FlyI06aCuk1ts iBZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880032; x=1779484832; 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=R1iekopbum3JPsPorfDbkghebgz3fiDydC5LWybOqN7UiUbIVMr3GDD/zLlxMyZq6s XwjksGnOX8mkMtYDU9Kkx1TdS4+mLvtNhxc7ik8XO/B5ostujnI53UWi6JdKSNC8TFbM Oc0pp5Qr4uNc5r86mz9KPnVhcFCRlVb0weBGuIUIS9wN9yMBCc+ogobe/xbaQvu2atkl lokp2tdd8rfNYwcLFdLOZGpHbOXqhgeAhkfc3DASgsx36APDcYfxKHuBQYoQsPwb4r2c 9WBl8c/OLJriBn3c3U8p4LLdJL/lSeeI0CvlfBzrrcAF7IdtfA26J4TOeZQSkyAm58ar bFUg== X-Gm-Message-State: AOJu0YzBfj6+eGjgsG50aGhXJMQCg5+nfKTn1q9Fe4nuflywk4WwBEhb UzKEeDxndqXa4nQRj4ltQjTL81AWRp2x/4lROaNuIV00e0k2QiltyYJzC33hvfK1EFw= X-Gm-Gg: Acq92OFgfyNJ4np9bIMVziqJuDVCpCgE1gXwBpg2xzf6/sH8XOV9Y7nYYPXK/P9VJ7r yDUb12+nCObWK4iQCXB2jbC65EMgDD1FvnxMBCvolHscFDeqR3gD4LJOkTurbeYBKRtqa5g1IaO MkRmRhEkoe0ioHBccG98UuQ9SaiW2djpbnAMAygZYUffrKRxWzx+iDprPm1BPo0yzAjRCxD9ulm XdECGZMTMVR/rjfgtt1BOiWAut0zbYhxoKZ+ozUwNqgWUWoiikIcfKe1Zb+6jGiFFeXiqXZuzBv yyX3wxfPunT26AsHdaBLmin8+t+O0SYlVogvV2FzyGFWXBIzXTI2gOeQu3dlKDPisu+s/VjHjOf Np5QaZWYBeveGnLFvStR1CZv/1/Ho2DyQwfpkebIkNmRoPcLdZsJussik+lwUAIcqLXR5JtQIgi NHrrIR3wm4zg== X-Received: by 2002:a05:6809:2c3:10b0:482:ed84:1a25 with SMTP id 5614622812f47-482ed843efemr1940390b6e.47.1778880032078; Fri, 15 May 2026 14:20:32 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:28 -0600 Subject: [PATCH 29/66] 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: <20260515-misc-2026q2-v1-29-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43k6JlRcRKDxHwljYHvshj2chGIxHAbznsCj ddu4iA85sGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR AH/VD/0e1iVZsePfw5GKvnFdV4DdSqgbci/868qPQ2fifesSEVkRp59uli9GuD5Os7kakqfyMvV 8LabKktwg/4o9h//kZuwN6/3Sl/GAD5bpc34RdVYltWpkBFjntUuOc3Wa1r7rk7ERgmjL0XXfOf udYfiDsGAPQmy8gK35xaJn9pynPPWGDxpN0vwBnrGfq0LHGrzzLcpYsUlD8OpSwibig5Cu6lQ3Z v/PIMaYsIb/ma6LZFx/qt9XYwTt1BC+XIR77drjAldoMM//tji8AW0lWdjW/T2Tl4/iA1dzEHLR iwOuT8kji0AES/xcQdS/f1TPDjxRZchq1EsvwLXhWzByzhRvETQvLvA14LYKWKqj1h7lbJ7tbr3 SKgCa3CP22YXP6DQt24hnCP2Alus4wEIjUBRuLRhaxYO9+uM1i+IeDZuW9EX3tGFPrNf3WCmpnf Tlj/MX2lZOnh/phijl4t8RZDQrqHfJLe5NGwHVUPpbfhrFvRS0NLHxKf0PQ+AP2ylD/4RTacjRj JdKxtav/HjEyI8spxChfkrd/OMSY3gOIMN9uxsR2dLSb/CaqmjYzzJrByeoRzA1DvjlAwplwXtv qYfDn1SVWTUb1XGkNUmHKRHpLEuJvmlbg4eoGgRe10+hVAHeFLFitMRg7IclQ3LzweEqCceADyx CcP0MyKtfGVIFkw== 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: 1778880240849158501 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=1778880074; cv=none; d=zohomail.com; s=zohoarc; b=kgPnH0g9HbI8onrcQ4ba6khh3mHX6VLjNe/JDPlpDOOTE9kOdwuhqlKVeZiqv9HS+Jhr5pb94Vo8LHcBr2PuPw9doOHQxvaWfWvO6GAMdUudm1ScfwRK+3kknDWmuC/IY4WRdpQyj4Z9YlAETVoJH7VulLZbrAyyAjXoI1+MeAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880074; 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=ESjtx8dniSYFz3kTmeJXVCkdlUhQAXMp//vJBaaB8CcL61DRWyODIr4XVFNfbmHV87JDD9yXaN1ApHOJ6KlXUlqWKZWX9lPwbyKW54pXrmQuxCnIL/0XRjJgAt9lUlB6fJFjFRMOn7jWFjBvFRmHqU2IjopzhER+pj0EAeduCFo= 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 1778880074296557.1374063950683; Fri, 15 May 2026 14:21:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxW-00021I-3Y; Fri, 15 May 2026 17:20:38 -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 1wNzxU-0001v7-EY for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:36 -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 1wNzxS-00032n-9A for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:36 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7dbca22dbfeso156259a34.1 for ; Fri, 15 May 2026 14:20:33 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880033; x=1779484833; 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=Z6pwwVObwQFHMnkJXCv9yaEsFb2E9tMy7oiIYMvMiSrQDCFyHyaXuJvJcstB7pMVdG Yd8goKLotV4Dup9WNeTXkucwnn9UAj71qVPV3kvrJCJrzIUG4iYFyElqHbTKvoWqQ2uW viuiG0TLWBognyExc4lfWG7YKHVEbB1J81ZqJXyC/4bLoevzmQCS3wj/fTKrTIxatjQu 3lcOF6O4zUKQ0+76N0nkT9/PJlejbHfJ8MAdgKJZDOD05DyBfXOn8yVq6UQ/LM+8jlpM GeRs4DdlUxFpxMcuW9Lh6wmdkux+tYMUsDF6SjEjWQT+itVoihptASmrKeUhM/1SkFls //5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880033; x=1779484833; 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=ZyUHlZsg73KHY1iiykiF/O/GhJkr0U8PRwm+MlXg54Dw01PCFttrzOfoQXmfOpn8rI SpscqJf/VflU18lpCsjt8aKuMwRAaPuL2ftP9p4BIKeUp5/fFzKsC1cFBtG0Asssdb+X UoB9geL4WCWSlHN2v9oygIibnY9mm4BMmOyN5kNfdZPpOJ+AJIsuFx+4EtBK6vHaGLIu /QCzvWZ8MbcZNblacNnfRALZN3chrLT10PEyIiAlSVUrIPtflDvckeSDMar/FoqXoHxW JweoOPTN3wWghaHmOYTxzNGwqy6SN4n3GJAltPq3mEUTAeaF/mQSEIjenccqJy/t87wr iLFg== X-Gm-Message-State: AOJu0YwyrbWlGu+gBR05Djt5CT3tJkZy0+0nz8ggKIEIZlF873QqVNzC eOrBsAiTNQkqbuikOKwmPR6Qqg5Dh9+9rJ/8IcnqmclTaqfDzC7F+KfsWnelycR9CzI1ZMjXzDH zyzPhpiA= X-Gm-Gg: Acq92OHi0ZULsqjpUHiMxOgVYynPvq34SK8L7Yrrrh8CePktSNb9MQDZgsyY8WwZy+1 CrHvDWuc9kNtoV++TFQm/9Q/sdpPyihnxA+rw8e79RQDK0kD8uab/BRrKqHjJwf8CY2UpEWyL7c vuugZ7Qd8rrtL55petdWsl7xnD2JEdnUJ7JGxxLUeDUPspjiiKG50PIfX5d3y2XAz0xSc5pN4Z4 nwBehB+LQOrCMayayX7yAv8AQe38dWls5GaW+dxOurCUvDaZ4yjsb/WEYHSHewUxPc2kI4tExGg RRuljGi20SfU/c48rv/9cOzsoh4WDNVVN6qFIrTpx3O/3QUzpIvp6w38j0nEPNpNgxhvXriBgOl KhvV40LU2AKeUmGFwnT+dWgKRSPrfVZkTMqgrmTDSIZIswnkwWxFKiqtOpveVsRGa0B2r5aO5Ur W/Ara8NzaIMhmEpqYl74Qv X-Received: by 2002:a05:6830:82e7:b0:7de:4fc6:a588 with SMTP id 46e09a7af769-7e4fa0477ebmr3839760a34.23.1778880033274; Fri, 15 May 2026 14:20:33 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:29 -0600 Subject: [PATCH 30/66] 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: <20260515-misc-2026q2-v1-30-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43ks1dMqyj97dJlx9/0Zg8sCYqiMnoH6Nn1V Xlh6TW2JwmJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR AOxHEADkP3wkejv9LK7Ur8sSw4j0pPr3S/Bq1Kp6dRN7fHGUmeeev/JV29AXNLWykHpAkKZM530 oMv2A+xlVe+nX4H1efPpr5yCXtvfwxAzIrT/FjOzclLXdVoKwrDNiy2ueKmlbSX/4uaCzQ8f88s rnmU8nGk3COUlMTuBQYo13Y5lU55/Y/4WUaJrwnOgrgsiB5tkKFYtsHkkVj2UTvjKy5Euq+HbCx PPxGUki6CN0BPXZ142OES1hfIIbAvjJImcizYT5G8EsPKRO4uktpGBlNpI10zZsBMcmXdAsDFbR WPU7n3rJ1UZfsp/EatZdRmG2Sw+be3SV9KdOgodps0pin/umS0RbCEJPrKDhwPfqt+3TsgYsPcZ mAvnn+OYui+/EhJag+zcmsVXIlqVFGu5g/1iKxzAACPDNFaz1zS/sexVwm3TiZbBPuhrGeBEHFx 6C5LfOtlVLJu9PATcbqtq/vyaQvsQJe3NsgNYRPo2dYJ96ZfZ++gkNd738jRBdnRNh7VFG/asLG cDkwe1NqZREoGhG/8S9Lze4NCGmw7ykvnWX1mLXIY+oCIe3eBbwEGOHZmihBo+VWrz5JzHkI4Fm sHM1wTvXLzLG2Z4Qihnmm6RdhTAcsAIYPpx38Wtcs79yGd3yVoU4Uxj9c67o9s9B3/bFd/YJn8t TzojA8KC7qCyv6Q== 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: 1778880075779158500 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=1778880305; cv=none; d=zohomail.com; s=zohoarc; b=PGy0JgfCa/v9fORHJVWkXVEny0L3KV+JMG7nI3ndOFEzsi2IA1SAqQzdP387sfH+HazTeVbIUlFpq6SHCK7rKFABVD22GF0+DE5YEMRu9jV7zi54/SQuropthQjMQAJpwOrBxS2fnEdXfZ0Ky0P0bGtTEaWB4wnJyRHEp/LX4rE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880305; 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=TBSzlaQIyOkpP3bclQCw7Yhw3Ww1UrUiu/9O4MtapUInLduHM5kRiu19kRYjuuJHavTVrdPrN02dsO+pusYkBAkKGfFMzpkC16C6iiTz/e4Pbx6OsrS2W9o5dZ3D8uaao4GLOpb5tOCmJvaXMqzQByIA4O6AEln6+LgGF427Vus= 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 1778880305555746.5333456741369; Fri, 15 May 2026 14:25:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxZ-0002D5-1x; Fri, 15 May 2026 17:20:41 -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 1wNzxW-00021d-51 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:38 -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 1wNzxU-00032z-1V for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:37 -0400 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-7de7dc85b74so332493a34.2 for ; Fri, 15 May 2026 14:20:35 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880034; x=1779484834; 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=w/hTTCD7PqSbPKVP1wcU61KyDBV3XAJFt9BzKEMdI3BTBDKOoRtlQ8IFhNEo7Bkct3 U+UM9/2rimjBEN0VSF0H4Wtj6aUV4szD47bq3A+Ew1NMqeoPuyYKtG9ausDJQniQgMPp A2n6ao8xC1mpgkdrD1m7OiGPRg8PtIkBuGqZkMQZEBdodZ3YyfLDROdS9xTsyiP8MeV8 P8AzAAmOFc89LCj2ZoHrlqHZK1bW19DPmrpJl1ALIw4f2l5Bv1Bu85+K9SVHt75k/AIc wZtf30HdXDQqAZdSTwQvelogRmVBAU0Gx4qLipoNU1MULEKD3KmEG17ZY5WvLvZAPMR3 Tmww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880034; x=1779484834; 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=BJe4FASIZS3slfpzxlDX9D/XPXkxxpyG9qHotBgpHiI4J1NnD5xF3e4Pu0zzZcRhgk D9raEAz18WwuEPxMpCkDltXjYgX89uK2eWuOzZb+F6ldEmszX3HTFx67TsCY6QK/bMBB t8zVSBUABQvb5jF3NFsYaWIohGYYhXOOkx86o4oJUPRN5MFCUNOaQpAoUFofSJBqiO2r fDc5XGI+3g/oiZrkurCgrbXn7xaWp3hUATyc0HRruWeRnlKLUKAtGjQSP68tOC8/1Bl2 S0SL24D1ZjWSpaml6V0IPzXppkxEQM0FMmFjAbGzIlvdqIQkWFJNGC/9t5L+GsFPo8cJ Ewaw== X-Gm-Message-State: AOJu0YzEvvQ8/aGPKcowQiE9ZYsI+OpFyW4sDJRRMJ6Xw5Y/0T9beXfA LW6h8WvB0MGz/sWJdGRxhpctlUmGsYkzpultikMyxy7bNWkZ1pbUzn7eoCEgPGfz5a8= X-Gm-Gg: Acq92OGyaqiBRbTWIXVdL9+wSTB5ATk/myomI7A9dD9835WXO6V/dMJ0bFBSchGIcNK 6i6NMb8r7uS2wyNcSDFCL2VHwpnvi/LtyLiV8QVLac04H2Wf9bzq4oUwcXpiSy2fIROEToXPl/s Xd/DIa6euUj1UEM4HYsulvlqGI9g0FCWHZCjyQ/l4ua9wveGwoMJyuQvBg7gABPbWM8jaWCs3Cs sX6r+ABdz0v5ZEJegxtt54Q9A95HVDoSc/siOyfHMsnAQjrnoKBOqvvGuEiuVUIAx4eileuiDfI IKjwZj2jHWDhi0KhL9kqLt/imkT/Dv+H+TlLlhgKQRdYM76khiD7h3wofAO3vh2z/kqWQpP2KgC /rYzeaLN0QJFpzlXQ/nlo4uKdqSTNCwxkzf/zxeGys0G6dckAsEeL+f7PM3dKME1kcJ4ziMtszk Zl75F9GKwjGg== X-Received: by 2002:a05:6830:4c04:b0:7db:b7ae:ef0b with SMTP id 46e09a7af769-7e4fa06446fmr3965295a34.24.1778880034467; Fri, 15 May 2026 14:20:34 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:30 -0600 Subject: [PATCH 31/66] 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: <20260515-misc-2026q2-v1-31-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43kZmdlzxUwwxCsBRRp5nEzZUe0YCh8dmY+q O0lsq19aDOJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR AMjzEACLOr12epv26/BVVZn6bW91utDSfDrWoR04qv3Y2ugccezm3Cru2IdHuzl1ww6w8btfU1R 18Vb4S+H7YygVeifVuEikmf08ddsL+cBLHXYq28fbs/E8DISQVus9Dgf9+kzNcqRsmH4P+gz2S7 wBP1Yg4gEVh6x4HiiLnAU8lMpH/UscIGVtHyhdsXz17IF2BVs3ZKOCvxIowow6F3Ax8W5WysVoD mzJzR+riPnbYYVNgjk59sRPk6jSCpxJODuZEBgkiKrOWP8kDNayTbBeMq7rilft+mEg0lMm+TX/ xF7Mv73v7Xr5CG3gaEEwxnBPNM6w0NX4ULeXsP7yKQT/+2l4z4jvCbJd9u05QvHnAuGY9h31FNV CIybZvr6McY3tYNk0KaYvaU1yFQcHpCAaDRxCPT6+H2QMKUUZ7Fw1QFDXQew9AqaaMZDqUMogEA 0JW8irh/YoFCp0xuWViNl5U8UlvUJs+eaFhUtVoFnGTZ+F1lbdwU5B4UhUDPkjAXsHWMdzZCxIr BBhFniWohT3QqMQhAMm/2RnOpesI/hp5xULMQ0P2ST0brp+HHN6RJirfd7MkKh/zq2Ss68jQd0I Z6WzvD64SY9DeMIaXse8nA0u5Puq07h6rqbWiX3qrOMkc3FrZn0kcpa05RLSHhPl0i6sKEvies9 4syv8bSHPz5nTGQ== 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: 1778880307346158500 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=1778880124; cv=none; d=zohomail.com; s=zohoarc; b=K2cFHGawiTE5ot3Vjr0ZTM8L6fmQ6tT6C71pM1YGSBTGUdH71rlzp+PC6+TgZVSXstoOoag87qM7Xm/hkHV89mBRsMOP/oVOIx3CfN0xIF75hirewlgzYW6UUuaZ7qV+ZUH63lGX5dnbcQWdc8UOIdao3php07qL9A1KdF7AXuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880124; 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=LEyrDN/IBIHTJn7j3nP53ANeCHIGq8E/2DXezzuEf0A=; b=oHEjLyAARLljDxb76siNI0QE9N+PZ8OtoAZdjU/j0cALXMPC39XAKasv0W1A/n1sL/ukzfqs+99d5669vpRh+4Q6megYC/O9i44RiH3tnjMbtkjitwktgoSyC4Uzzp4JkM4TncEDhw1kVo4QFtevcMy002lxCm88ORaG0vfZQbM= 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 1778880124789132.23376752477634; Fri, 15 May 2026 14:22:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxY-00029M-1V; Fri, 15 May 2026 17:20:40 -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 1wNzxW-00022k-Fo for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:38 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxU-000334-FQ for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:38 -0400 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-484a2090205so821790b6e.0 for ; Fri, 15 May 2026 14:20:36 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880035; x=1779484835; 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=LEyrDN/IBIHTJn7j3nP53ANeCHIGq8E/2DXezzuEf0A=; b=uOCbLU2GfR1pLgMe4+2CNSDTTqCwEvc8khVLEBw/pcJ+BBXaxdQmQ79Qh9VpihaIEb OjLMue0LT2vX9IRtQAxjR54Fjo1m1VRJ/1M43s5+HQB0vDiv84YkM8yUYLJ4C+ZlMt9z 79U0pbZsyn83Rs2F2UHGd/ORqAixaViHL6B5gngJ9mg72XWh9RohPJo7sf5VDunwRaC+ lD3Fw2mnbp+5dm7rZMYonzU3sKBD65jZiJs6wjPuxRKvPCSH97qEkHm38gAwpalNmmmK d+RNGLBWH4cDO0wqAoO4AxqxxFj5AypT8TRGa65iaYFfMfFdiXpO4AeW5bZ0D3g7G58w dN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880035; x=1779484835; 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=LEyrDN/IBIHTJn7j3nP53ANeCHIGq8E/2DXezzuEf0A=; b=NzKDR5ZJBZbIJzXQTZjZQCvlreNGweyQJRN1J2tDNkhtRUuN/9setYfJ76BKyq6u8I QktUmJPouSDuZ/epV95IgaERrksTjqskMnK5jyYaNdo0tOerLWpI0ngfcV3D+yBbvH+J z76S7VO2BLGN0LO1TuEV3KAAN0C9woUPY98OeoXEoHsXeENXWTj6CRtWyxmR0cZ2z2gX hkj77cWr8uVaVi8z003g89hj0Plgbys7b+PGzB7yirHbL0JdC5JLiljzKxPspHEswPqX etAQXkzp30q8rRdhys4s6jVgoNpZz25AuKHNo93RD/LRkvsUpLNklZtTvsLlQDZfLgJ9 RpIQ== X-Gm-Message-State: AOJu0YwySjFAEgDNbLGVsbcskhcIUoqBHhHjB7Nx08CmhPd9Filf3X4y pbcuURCxnIvGDtIoFVw8r8LmQQym6IU6JFHj4vRoa4ToqTi7TGvwUx+a5aD6m44L+is= X-Gm-Gg: Acq92OEb/AumuuGuwL6/m3Ylgy/ai+y3sYf4ZlZdYsTu2ZsopJKuSDqdVKY7dh2oEjS cGTRVb7BkNdTj0caj5aMfvAz77f6EQOgRTonJjx1TCsMhH7q2Z6Yuef50icRZmsJLIOCdB5fTQF 5+Z0eszLG1cb4OWwhAJsXCg2PNqqXlBNsXkuodkcj0bV5GE71UU+pwtdwLvk1CT62Soe/UoOIRc Cvq+swaY6rLvRXh/7p556cWuuvqJHMJVIA9nUy2Pi/+Jdx+wQi36Ks7TjOJq8aB3aLzESj+imVx m/HA8ABPWH/fE90eJhRiYPXRotBP1b6rDx1jT5M/dT87Yd0ef0yO5mGIcviP+Eu0J0Mk3yAwCmd Mg4LnDFY22CdiO08Pg9nwbdSjTOcZGHhJxaIwnTY4H6H1JENImbKKcN0jRloB6ZK/7oYhoX5lS/ zoC238DWKhdw== X-Received: by 2002:a05:6808:1b22:b0:47b:884:b6de with SMTP id 5614622812f47-482cb721377mr4993727b6e.1.1778880035393; Fri, 15 May 2026 14:20:35 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:31 -0600 Subject: [PATCH 32/66] 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: <20260515-misc-2026q2-v1-32-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=8901; i=imp@bsdimp.com; h=from:subject:message-id; bh=3EhHpbtiZLtv0+J2hYvv6EauzGt7ru5T+ynrHvxg67Q=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43krz3ScwPG9gSb+abwM98gYFaQzHyNy/PCu kehch7NE9qJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5AAKCRBsHNEofbAR APcKD/9ebZiPTE02qKh6ASZMMHwwMoxtnS4nxK71HQOdSN2E0MIqAQqni90mYufTvO08ctbITzR 3GTe/UmQWXrLPQJ8SEuabi3LMZaZ9sSc+6QiZr0V/y3Yj8DKt+5GrweoStUMcPKtZCV91q02u9R YTAd9MDGXc6MFFpJQlvgiVOkZ8DwwBVB6EkU1NC4lOmCDMXCg21S/jfTc0Ho66En+Dmxdg1wDjJ OWNiOKpdcIxunrTLkSGSbOotOB7HkiP+E+MIyd155oXMh3RXjEgR9tHEjXtFTvhvGv4EXRLz2Wi w9utJVxLCyo1zl3NNCI0wYGFgWx44x9sxXO2aK2m/xyW7DIFhqbp1qQbrJuYyxBF/eOerwebPiZ xMIaKgQx0jdUWlBKt4DXBkvt+v0mzD1u1dr6H1MmMauX8QDLUj5sgCCInZI1HuAc+gi++O6q2C7 3SMfS8Z2F+l2BYjzy1jXFPICxHGJ6lHGnvYQ5Qq+LnGjNT8fUoBDWPQw6JgAyqiothZ/+cLcaQe kTo3/G/ExLFstiTAJz7v6VPpsfwAvMBxc0U+Daq8I5r7E0sPVZlN1Ux1K9NqfSXnhWbgR9HNG9u kWlkXyWkDny/JKY908zkk/t7Nl6+nTNZMHbV9zZVyO5NUMgdwUv2uDjIjrmO2/Ltq593gDg61Eq KwpPq9i0DizTCnw== 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::22e; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22e.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: 1778880126156158500 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 | 281 ++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 280 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h index 788e40ef30..70446f9a54 100644 --- a/bsd-user/freebsd/os-extattr.h +++ b/bsd-user/freebsd/os-extattr.h @@ -376,5 +376,284 @@ 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); + 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) , arg2, &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=1778880231; cv=none; d=zohomail.com; s=zohoarc; b=MjXQeAc6X986W3l8Oq1FDjIg1knTOjUq2FWILdYUSFkTvc2NPPX2OeyT1aZjodQ6bwZBhOZ8ebRr36sKiVqrwFGNmH8iMFyLagbwZinm9386R9+wNOuY/r8HBJcQ3c+YXXQn4IRqN5XLCzRH5nQDnSAOlsAjFwU6qf59EKkERTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880231; 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=9Tsh8lm+LqQy4W3ldmlNqx+xWEUkmkQXWSGTTg0z9ek=; b=klGVdbjOzczrq14KFoTMTHkcdTn0MX8NEgjtvBagIMZFmvuFnWZ1BkasGcq4SA/fZOOC0AC7qBIQoyHQeLrPuhZebMsuBODyT1So2AhrhDP7iHYYnRp5eOO0kvc1Q5rsA/f7RUT98NppAJAo5X76iFujEfhipWX0LHmoxHx9xc0= 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 1778880231061805.175349085283; Fri, 15 May 2026 14:23:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxa-0002He-9F; Fri, 15 May 2026 17:20:42 -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 1wNzxY-0002Ci-Hu for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:40 -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 1wNzxW-00033S-Jl for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:40 -0400 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-7dbcb467f2bso313348a34.3 for ; Fri, 15 May 2026 14:20:38 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880036; x=1779484836; 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=9Tsh8lm+LqQy4W3ldmlNqx+xWEUkmkQXWSGTTg0z9ek=; b=jOMhuu8wOBsiQbEFM8R7bjsVaDHueX/ph0+D60EWKAuDmIkOVDCTOH7gXzIDxnGOEB zXTtWmFDz2fBywcnYiZz6V5aP6eymDGGbtnN8H0Pj/N9Ai7WgGlP0jUsB991zKtHYcrn hqEDvEg/uJ1TYtteDV0LoWegOoBQiooLZWiRZJX4zNjoPawG2eIn0p862VKmUf9sNqTT 31zIXA3z80TT3DaPib1bJqC52q74ri4v1oeLi2LymzvpKlGWYbAjibq+qgHp1y/dfBzY vA2iEl7+9v4blq3dgD6gDYQQ6X2Bx2jti9ATdFGJfaZK6GEWjEv3PNxfmNxTl8hTVw4V eK6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880036; x=1779484836; 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=9Tsh8lm+LqQy4W3ldmlNqx+xWEUkmkQXWSGTTg0z9ek=; b=Lha9WRD75ntn0wA9QTrS8RVWXqJQ89bB2/7eLytPORKkUqgoFhdg7c7UgJp0wGCYrH AzDTta6lBx2l8SwbxdPEJXae5SqSoiHPRjWBd6ZDtF1suzhzYAEvDgcyjpYFNlWXJ6A9 zRD5Q3QzsGJdv3eAugArEXs4TLakS28GEes3zKgb7MCAOHw8zudGKvgEnrBVm0LuLHuR OYB7NW60wC5OKCO/ij8cXGPzEFY2VtrCXrDdr6rnhviaTYmRdP2RdfwwVlTQNfHQIu76 mE0MXYysGSn3wu93A2l8Mh5KALc8jIdff5gTzL7wAwmZPydKdsEQQoIubPP1lP04BaNr F8pw== X-Gm-Message-State: AOJu0Yw2si/j7gBON3j8D7GMlHZwEvVx76hUCmTgjTivPNS1Ur5Sz1qB E6r/yQxB7iNvAls5B+I9ozDEFGuA7o0IeYsj40c6u1sV/GcxTxoGq7dP69hKmMZHSdg= X-Gm-Gg: Acq92OHzzM98IqD50lQ1UHVNcrp5UQ6zTSVLbzQw0kUlSGDMJ11GrxiXWEW1oivd5tO dwN82TwSbuNCmjJi5ZbcLvxwO2tsx5Ru3NklN5iYgsNPV1e9z15uyvvWWAcp5efbxtFZUILGG/B qD+SQtrVOGR7tSnZirWMy6fu6LCu/y/C9SETiv0UYrDRLrpESQQAN14zMEGgbDhyRdczCu7qyqU 4RYniqVPg1QhP1OHsT+zLmm0UUeZSty6032qpXksNWNLamWq77M5dLBdZ7971qD8CtJjmpzZDN4 8Tk0vTvwrk3cS9jNxu9s1J/HVboRqZqj1kAKNyd5KaX0msilKwmx0+Pucjg9oPaLqiXOzgpg/sq jmkajuJ8pl8OOqMxgvHAvgRbs2ssuozeLoaZp72geV1Lfie0X6kGkAC+KP7TT1SFqsZm5fQ1qoU NkNJ1srfPQyQ== X-Received: by 2002:a05:6830:3812:b0:7d7:eab6:fb23 with SMTP id 46e09a7af769-7e4f2bada38mr4107959a34.22.1778880036516; Fri, 15 May 2026 14:20:36 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:32 -0600 Subject: [PATCH 33/66] 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: <20260515-misc-2026q2-v1-33-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=4528; i=imp@bsdimp.com; h=from:subject:message-id; bh=6svb8ssm9ozon8n/fFZUWOe2tBLRcZ2f+HXF4WmJ+cE=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43lDaGThytNysOLMFbiBEBxNR8yGIGZud9IR GYnURYkFwqJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AFzqEADdDay63IYUAFl/EUg7ic383xZnKohUHsLLA2OkK3jnLJzfPsQvqxpjdupuy7QXa70p6xw oov1eVprkyxCFVk5yB83vW39xxGD4c6iCLc/B616gxiDsVVDzcWztIHHNI9YjT3AfuoCBFKJ6VH 7asmOFPnXAWP9R+SOioO28PCARcaR2BMsTlj1CjnSgbyIn3krV0StID0g/wl/8862gtiZnHQXZv rWIAYsvagOnISj+zaLKkQggoWjdGUKebHNM2mJ/IDgllrzFK35CZDNf+CwiOZhgV7fhzFg2qTQU znjjKVdNiioqrOSZBBOuFrSMZF9870a6gQWWy06tyMrUJvs0miFqH/Joa8WNUR13KnhFIB1QJHX vjy0h6mwowTmV/zE8bcnHM1RF16Po0a/BqqIkuqHgNeUwVb4H8eXVoNpxjpaZtnpm/9SrRBlYeE y9oQ3JSJevB2eyxNoby5pT6h+tTNVUFLAQ+c+ndKiNdZyj14gzHvCAidN3mAFqeGH8FnnDDyh6f WNJkhal8bQycQ/ST1umC5XECtBgliR+zBhmrRrVqp3g89Ry+cjgiqxS4gxwqPTpWylfXUx8mrS0 NSdFeBWvZ3yosUxZ9GfdVyl52ge8HrSXLbmcfMo1zljrb9dWuYsyvREiY9GaGpGBBKjj2cnDWF0 iV/Svug5WimiEgQ== 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: 1778880232838158500 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 | 107 ++++++++++++++++++++++++++++++++++++++= ++++ bsd-user/freebsd/os-syscall.c | 2 + 2 files changed, 109 insertions(+) diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c new file mode 100644 index 0000000000..a30d513655 --- /dev/null +++ b/bsd-user/freebsd/os-extattr.c @@ -0,0 +1,107 @@ +/* + * 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); + + 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 (!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=1778880100; cv=none; d=zohomail.com; s=zohoarc; b=Q+bV4mdhbOs3Zx37GgT588j8cJokvXbuG9A/SgHSkQAGuIyg9iuVSSw0VzbxvgfQ/ms6B/Qo7wDjui3M2TMcXnU/2rIZoPiK5Mu3Z+7VD7qMDmvr3D6RdtvXylPlVJxTW8J/AmyfOEoWvxkpvO85zYBCyrSp9/hh8WL1Mqoumi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880100; 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=JxCHEpWdTKzbppd7r1QDM0xHPXTmqKz1cq1HvWOAF6ycdVFhHCORDCp3DdMC+/ZtFatrjzkKZO4hXmmfmT11LIAHNoWNkFaBA+17GtXRO43sVAOkuJOv93IYXjo2TUwRisztk/TLORODpCKd7QSrD8gtF46CZDLzQmbVg5QZSQw= 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 1778880100785960.2197191242616; Fri, 15 May 2026 14:21:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxb-0002KH-1l; Fri, 15 May 2026 17:20:43 -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 1wNzxY-0002D1-NT for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:40 -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 1wNzxW-00033U-Mb for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:40 -0400 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-7dbe437b072so150477a34.2 for ; Fri, 15 May 2026 14:20:38 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880037; x=1779484837; 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=OxkR31njgr6xxgLBy8uYSNl7lr+J/UWYY+2DTv9PX/Uo0vAYxkILPtYkOaShHP7o7+ GJu+hkizaL6Eb/lbmjUzCVXgk8tEXqIIHLU+wfhpYPIWWFNWlUyfRvs9i0xA9ip3HTtO 9YxEXt0loHUvbPg/t0GpZstk2z2CJ9S+0GQj6x+d9HsYooztThV3tyBQVJdcAEdzArRD EjW/jIRqczBJ2Wf3q0lsgYfkXriy2QWfWIpfLwUoUgDR4vkvM3Lzbv+RuEjREl1C8BjH 2EP5k7cUO9LxagMEjxSpGMzFCjKuqkSaE4bTPzjy6ukK+J/8NPl8l67CAkJSKyLsi/Ir 3JXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880037; x=1779484837; 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=DZhQnUKYztRopl8Oh6CCW3wdXuYk7YYFemm9Oe9MyFHTClgfxY6hKh+esv649LZ0Lm fWZutfv3L/uM6CrQQ3rhcyJ1cV0uLlnvoTeM0rGozQf+MX+CFkPOxMeQZHVusc0c1IbT d+FQNzuj8L8fNy1hHwziER7WThQPV/AtScEt1gecjtIo/eWUUOIiagQ60fSP5h5GCNLa 4fSYMEA5+6rZuYGLATkDLc8N7ntZPMQheLoXHDhCru9+TeFCEauSDHDd+fkSz1jEiJYQ idzCvJj7zN6LTVfYy7hvPIEQYiAtYwa0TZ/KZX0amtLKWiwzswhoSW+06hqeFiNhZhH5 aL6A== X-Gm-Message-State: AOJu0Yw9P6+Imd4o7VV9XrnHF+qgHcVIp6XWvp11ob0kMOe4bdDh0zyb GhDsTZs9c8eSyMAdyB5U64ylj0YvjJWHFb3CmCkl7hWAfXd13R/z/hNyS9cucMqqY3+G8shADVJ 4TIaxtDw= X-Gm-Gg: Acq92OFWB6+Y5DaOYd3cA/HRo4w3sBnmzw+9gZtqF8ZhfoiyWYUwmIJPyLGgsGmufqs xSWjJjqNSol0yozX3LaTTei9Dj9pRcNUuviFxWRBDtHszL3NoFSOHGX9fwF5LaxXANCfjh/zn2b GIz9mfYD446kz4n+EbRGrlhMYPwSrTcBIK0xCM8clUxdQ6sWjC8cnRHxc2zrJUMrD9Gdp7ix2aM C320ZzUzA7JPg3iUU/vxrYOvCzzNTenpJHZyzaJ1hVRNQM4EZiMideGGczrGICHGNhkK+YbMl4f pNg6J8pGJMzQ2HLDm0fD+QcJiffTEdY6DIlLDkvkVJBcm0bfGZEETBjrR3ThAup/LThheBFUR36 ePiDqdEarA18jpUPMgN1hiI2y4yc/mJLdlYOsIneEAAxebtjiyFnQDgy/HyJIo38XU5QFc9y+/6 /PjFoS40PnGq6A4f0LKV1D X-Received: by 2002:a05:6830:6187:b0:7d7:e6cb:836f with SMTP id 46e09a7af769-7e4f2bad231mr3607094a34.19.1778880037546; Fri, 15 May 2026 14:20:37 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:33 -0600 Subject: [PATCH 34/66] 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: <20260515-misc-2026q2-v1-34-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43lGRR2fkxZdmMvitUnb1MOLegFRjMHCDP/f nM8jWVHKyaJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AO4KD/9Wkh1SzGrlfrMVV/NJAXuOHCxG69h1JoqD9o6FgYMboHQMMMy9IhRPqVxajGTaj40yU0/ kBYoYNUwWdSxRoPGxyb512n7pSpXPvguteUNNEV1uZpvng2DCWUpzk3/xeTrpSM9F5l8cB1U5Fo JOR0V3bslXjtateuH3RX9kAD/tqkL2aHgd5tp0jelV+EqshKlaAhWP7MyBcr8ezPGRDzYzw0T/x KdMTQYc+rZVsCU8ZwYvNWi0tLzuj9Pm2QbyhdPq7jeNR4zvS/KGDIxOFdJ4WIJIIElJ8EdFOjCr XmIR6yn7NX3vvqyE7YrjkSGRSokeIp0YAtSU5ruJI/oJQX/BnZ0VONtbkSOccEPp6y2aCLdgOiL qsZnkB02PMxZyuAyo2vMBITIKA9BwJlxDc30RCytPhA2G2TVpRebgNYUOCpMG5DOvSGxVotPbN5 PHW8cTeHZjo+MK/8hURqrFK4i5eA/1H6AugoobtlBka6rOvqyzWeeJ0dhjboNvjVAS4Ez09v56t OMjySmWR8NnascnX8ARq76X9cCDdo8DGXPAap5Fs9AE64BduD3M3zLhZaPI5X+1XLkA/8IcgPN1 04bT5IUxj0iPQS1YQyXe8znjSbYwF3IKJatb4EoEt3VV3wqIHcGz2dtiUQlZ8yTbq+wImE5R/2E FOuBJz+AVFfw3Gw== 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: 1778880101890158500 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=1778880165; cv=none; d=zohomail.com; s=zohoarc; b=MUk1i2ZvbQy1SFS+6d4GzVqGMUpdCFH0OF6hezSUDJMezou8QlwZ3bxPZt0bnypM/Tl4CXAOY5UFFuy4vEZuz+IZtb+x9z7mYP72THAKTUtt80XToj7XF6KVAt4fPzSFMIiCOJl3d6lO0MmQklhVYOryfKcRTPl4Yjp8FBnYx8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880165; 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=Uz3z93DP6+TIklH5pOMlb3rTcEH+Mp6rHemgJWODVfvIZEf4TpVoPiszya3P+5PMBJ4HR3KpRkqUc/JbhzqKyiLzJ4O+46nxcxX1wQyJtsqrn8Df05O2caSrq6a0QJTrJAyq32u9ixulOQe2uhdVOXKgnvqANIMd4Pj89sZ460I= 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 1778880165167794.0090402198613; Fri, 15 May 2026 14:22:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxd-0002Ud-Kq; Fri, 15 May 2026 17:20:45 -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 1wNzxa-0002IA-C9 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:42 -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 1wNzxY-00033i-2e for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:42 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7dcd9061b1aso292226a34.2 for ; Fri, 15 May 2026 14:20:39 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880039; x=1779484839; 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=m9e4Nqx/nKMdoTZzmnU3HqmbROiKLoB3kYm/wpuSg51FamuUjd1ruzOMjtVtcv8GmS 7Mp8jdwkMde6QTggCqbhz4LT0DlGfcM8OSPMtRUDmWIFkcjCtx3DnwurpXGsYf9esMVe RSP8ma/a8/6UDVrnhyIqaUav+S4E3rqjeG0LHK2NctOWGhrAWOD7C+0Y3EsKG2lvKHoU ZmWym3el7rnW4kbawRZmfFyV/foP52O9vYPMfQqXBoH5RvXYi2iB8EJaBzA0jGUSNexZ 9zspB1uTx7PUGgCI2H7rD2ZqIw9lyeeR1vl+R+P76UTY3jWXfsxnCIKc1KDEx2qsQX71 cHWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880039; x=1779484839; 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=MBZq1EkzdHud5JDw+sBGoi/qnu8o8AX+Cod0rgHJY35GCCpVf57Ocg3PLVmhs2kUoo wQypsuTnM16WK7jUXXFmANTteLulVWRtW+uyuTvuS8/onZh9JSYvdLDRDSDk7VpDd+ul 7HzssP+Fas33pk1Za2yRHyoR1vm6MLqaI1Oiu4PPnYryg80eL0gSIhmQbL5TqEn4DohX Fu54rWfNz0G8PStAmvtrDMmfW3453P4NTMnD63XBV2E/Dy8+z52F1lpbZmZoYTcf4K4w vryaz9WDoUXJk5qahTvHoMs9q+43BtvoCN+Hrpn8TvsN8e4c7lugcORlKrXHbcEqnqcO zHBQ== X-Gm-Message-State: AOJu0Yy+qHSTSRr0IbTlwVpWwG1kLhx/WB7m0eWq8+YkgVUggbExB6sX Zkvj1z34DfvLzTpu/uj4ln/Hx8CM/z2pWN87cjgPWuB1QvHiW5a5cMtgRHoyxJM/bzM= X-Gm-Gg: Acq92OEe9/pYm5tGS5zkF7KqB4EmWk0hn5Gex3zourCnYX/RB4JyYmHdr3o6RSh7g1a opzOzTouam0Wft22Yx3wgNgyhizxBzXnLyUR/O/eHk17bsyLIr3CmhZzrKQrVKGjkEXs6EL67xp BnKfgHQigO/1cNiStgikj0JXdS4gqZmT06VTsLSbATK+pM86eMZ38NVZ5zjNxPpRaJutP2aeymP 7PZfG7n8tfNmDzh3SZOBQbi+ilmrDaycxJH0NHBO+pMrgrELiURO8dtwnaTvhGS0H2GHn22gNjm A12rPVa0ZEZ35HDaW+apcYqbCcjykMXMRNFDTXBlsmSp3e+LD4pfdVcGRp0h/aYb/GDUbXJ/53z 9tCLQC5x1uUHBw0IYNXwW5ZfLRLnwzIzXPORpwqjVRnsZ4+S2WR7EVs6peO3lM/P3U5nBVCJFq1 Cg+IZ4LlmcCQ== X-Received: by 2002:a05:6830:349e:b0:7d9:f50f:9691 with SMTP id 46e09a7af769-7e4de6b026fmr4117542a34.0.1778880038783; Fri, 15 May 2026 14:20:38 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:34 -0600 Subject: [PATCH 35/66] 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: <20260515-misc-2026q2-v1-35-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43lPMEjCGk6g5LBMPoxa+NX4dwXa02odDZ7N 7ICLAELUOuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AMezEADbqh4gADSJLo6riPGnGzFlsvfv9NFq1n50YtUiH4g1Nk5qERPO5KuNoMH4abpb8yOB5ny D5pkzQ4TtUt9xrXljzqma7LIhL7hb1AhKjB+wzPGHGZ4N3asvYsxxBRJO4VwLZAlfkRv8JzocdK NB/fQm26WW9dwjVwvx2ntIXiC+yr3v3Lw2vhqHrqHCEI/Tipf6lBrOAuxl//uStVVgivGcljCHK oaBGUr6jt36ZifB+EjIhyM6nJqZiAKeRYvq8IdAxLt3HB1Za+AOx31hS6YLe/upVjMzrlyEeOYo 19R/ht0lLnXD7+yjrQTmIr+eGiz03jvHdNa9kmPxIbjXw6TK7QEJDINHskO2BEXP+35YPeQXlL0 HVj8lio04Zdg6AbuaFVjBr7DS0wtQCO1E+b3/Ws93BuU0qe16CxOlazl0nSEjKlXtbNMCIT+4ob mXR6GUYJK0yS16wzx+2kUr/DisHBGJZKx/z4kCYB5V6BR+Aw3WsnAJrJUko1g1IPtBgk7VHaBLk Gm1R2le2ABUlOR02qP8JWyFYaXbxy0WN45mD3sbeCGWPWi6fkkuIlq9cCjrAYVyH+hSmoXYY7CG qfd0pGJzMHblv3vOxcc+g8opG5mlOrqE3pMcZ4xegDamGbxOavFv1GTuiy8+L4vrmweicZMq8Rr IJ4gEDmGFgLOoDA== 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: 1778880166546158500 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=1778880177; cv=none; d=zohomail.com; s=zohoarc; b=OH2b2l3GjGBwxKkB+PEWLGoBnjSX5U6WSliJJvbkzkdnJYY072QIuZ3vRwH8UMdjzueSkU0Eehp4+pDQ6oR5tz4ajAiwsGtNupgaIpzwql74eFC9aS09Waj2dbl5lDJixv5N83pjxB+v1w2SxIW9I9Ct/cbVdmL1bPOc3TkzIGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880177; 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=IrMMoabXD1vDy5mBiaoVZ3/U9UO0LZTkgVKpr6QcPFs=; b=YfLbHLWFXu5JEoF+rlM0kJzjWd3IKmORCJ00jr3wVo8nl9xS1asakt7crDM/TOrDsamxjhLuK1vOzZNWE+dQO6M0KrvqenhhouX7+wwtjMJxJTBsa4iSOT2PHJjzLA5d5slgXJgP56T20itVZwn8oc1R1JeVCqHrtLVftmRlxH8= 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 1778880177598335.6861768263043; Fri, 15 May 2026 14:22:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxd-0002RX-7m; Fri, 15 May 2026 17:20:45 -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 1wNzxb-0002Kr-3y for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:43 -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 1wNzxZ-000349-2O for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:42 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7dbccf6a23dso289717a34.2 for ; Fri, 15 May 2026 14:20:40 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880040; x=1779484840; 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=IrMMoabXD1vDy5mBiaoVZ3/U9UO0LZTkgVKpr6QcPFs=; b=Ru0dn+RYYcuXS6RZUTNbK8HeFcE/cTTEV0I052gsg5w5xbLItyoP2wZlqkpBVhXeUO b/+P/kdq5hT6Vfcy07HCcby79T0qiSZr/kND9rDgTAHDZmrE3MaMJN778wIg8AN/T9rz soudX2Q+gf/Xywqv+jTym+FKSi51cfQ8wBV8574bRY+0skY71nILAV5uD++Qh84h9vpl LE73sLvLdiYi7tU+WUAMZ9XLyc4jWbeuc1pBON47msCHqk+dMVX9TyI/LKaU9XVtGGfb EsYJJLU8cosQDJzqBiPFrTmqSw/+iyKLYOShNR2f/PVKLrLiKAy3TUeIj2Wgrfjh1VDm xMAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880040; x=1779484840; 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=IrMMoabXD1vDy5mBiaoVZ3/U9UO0LZTkgVKpr6QcPFs=; b=ik2ALQK/34nJoBnMYo2d9KaBPP4JS0sLmEryZ3FFM+pTUiB/UW7C/j+BSj5MXTqeA3 1KGnUDm9vg+c9Nd5BDNpdvwcfiGl3kFAqojsKOVjCae+oJvibZD0E7enAAlxKaHESVrN ebE4iQYoMDHrzdGEJPkxBWszCw78vLASxghazO1VMcH9wMiI8q+WMGS/9DF7UnLosSID G04AAV8WDQmr/3BG7UlgauBUfY4Kmmu/hZjaBJsltB0Da/HoP0qhuDlCiPGpwf3XBqdG TSb+uOwktZ7kOzvyqEmm7dgS4j2a6ch5WBjApfldvGm9tT0+UI4X0ZgXXDMzn5HDHGn9 HQ+w== X-Gm-Message-State: AOJu0YyJAHTFpP8WMq+jxU7nvf6FG5WPMMp7JKFjqAEQ3fh+7/qkV1wY lvQ7Y1dUuxhdzDNJTcYKfPzwxqTufnS9K6fKm/M90zt6sCrfHTURZaq8gJaDvPHgkT4= X-Gm-Gg: Acq92OGUxi+X1wuJF8TAhhKWTAoBJgQeV/ZPh2q3eseXovYRqGOrsoZswo1EH5yxuZ3 kNZp7xCbAsEbFAPxDFd3+it+CNv9ieTWXpfwKiqRIA/DcV2VJz8jm4z0ZRKUoT+YqlKYRfU4yEY 5mHVSD5h76/fs5byeuUY07AtvxH1ZJTTayvoT21CsP+YUgtACfGZvTLzLajGXqQwX4rzt5d+daD 21UINzkNAUokQutfbIN3l15XHvdk+By+ycbXV6p9swm73+ORUfA0Q9ETGBXoDWDl4lQ1lx/E5AU 1Wd7pX64UiCJjGQmJnugq0l8ibSduruLuMPu9QTl3Tz9uSWRS0ce3onZFmlHKCwS+q7dnBHXHNo /7TNLc0+193fIzFpyAGEl+tSN58OmpdNibJhoZEnCrdPkKsZPqgtUYs9mVWAXf6lr/i1vu2yZLo y/633cgMpDR3WtbTqvVFEk X-Received: by 2002:a05:6830:3697:b0:7dc:c4ae:a66f with SMTP id 46e09a7af769-7e4ea19ab40mr4059602a34.7.1778880039975; Fri, 15 May 2026 14:20:39 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:35 -0600 Subject: [PATCH 36/66] 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: <20260515-misc-2026q2-v1-36-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=7992; i=imp@bsdimp.com; h=from:subject:message-id; bh=GtRJkZ1PLy4FUdfDIt1tXU3qtIhL7bL9aQtGKWWJegw=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43l57CJdo10+ghFVSZd3CHGF5Ldw4yjzmrkv qf/fXo9MPOJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AKp5D/47K3s5gD7E4kz8R1V14kGT374oOWNs+VKwC//UZamULGseWw8lPrXXXnUsOm9ZQm/OBdt Z0s7USqhk1E3ztqEAVU0KZauG298nGwB0u/BFUvHvHBknntI1lMUjnsUEt9i7jeRyMp52UNGP0r eRvuH3PD8nVupc0DdK9SEW8csCCJH2FjJcKwwRdLjRX1+HkrByVDbdW8RBsimgZSqBfGNR1w+9r MvX8mNQf4R6bIHdIQzeHAkT7nqf10rLGBA9rjhhskyu3qryTWwKD9vxOBI/oXHWivD1jg8pX3oT mED2+m2cCkesX6ncccd2daI8BI4M3CxyKmtLHXI0jPWpqiWei5pC2v/b6RyhoUkWCPzog9qV7p9 NqVt8/UZHnlDZS0k3oxAuJZzkHEFavKU/1UqIeiQFoKL0Y6Jg3UnBDQPsU04I6fQFwZs7YaI42a FpnePIKzb0kje7/MRTOUDrOvuHaVdU43mr9hF9Y3+E9qvUJCqJQ34Kwqd8lHnwUHW7QYjvzlYG3 kau/0AtYNuDw2utK+SpPmhmFLyVoImAYKxYV3/H3LfJ6CGaA5Rbf0BeYWrn1CD8i9Fx+yPl+11H YQe+3Tv/Ocr9/CFEkJnAobPPfAxBjKaT0EE1RQpoPH5IDK5D2wx138FLYsHIXK3dTZBpm9U1vN0 6v/A1Ln7XMv1Yxg== 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: 1778880178547158500 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 | 268 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 268 insertions(+) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 74ed1d2f47..7ee903a5ba 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -270,5 +270,273 @@ 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 kenv(action, gname, gvalue, len); + if (ret > 0) { + len =3D ret; + } + 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 kenv(action, gname, gvalue, len); + 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 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 kenv(action, NULL, gvalue, len); + if (ret > 0) { + len =3D ret; + } + 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=1778880338; cv=none; d=zohomail.com; s=zohoarc; b=PMB28ulUEWx/G+GqiKAsS1xYUJUmMSlrVRE1lTQytINJGX6eGKhmnq5j7Nra+B6XQEnxXHErfSlLM3IQrDB4TsYOQMeUET1CvzGtVD2u0TdhT5O9YrE7zufzfVWmHXsdbePJqbbx2Of7OZtARnuPv5RImYpDDVd50JGLBIt0HYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880338; 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=sIi1UsWlJyCFYlU3H3U6IZuU9kQD8zJobGIa63j3vGk=; b=gA3gG7K+edhjYBaGo1ek9/OW8zPonU6goC8Cgmp3UfTUW3p0vlC6lPnONkACHflk+5DM2CtjOC+t6En0w+gZhA7bwH6gkE0BZDKS8Pv67SPty03IbeZkjqbCyMfQOHfzwg6pkmKJDclHY2NsfShv5Kw+HSCMy6WtaQA/1PMKCYo= 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 1778880338596993.6900067088067; Fri, 15 May 2026 14:25:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxf-0002c8-A4; Fri, 15 May 2026 17:20:47 -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 1wNzxd-0002Uv-KA for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:45 -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 1wNzxa-00034W-Il for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:45 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-479d37e7d7fso127850b6e.1 for ; Fri, 15 May 2026 14:20:42 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880041; x=1779484841; 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=sIi1UsWlJyCFYlU3H3U6IZuU9kQD8zJobGIa63j3vGk=; b=B5NXh1/cn88scbe7FwMfY9gh6zfGjVM8teEiQjI9Qti+Qu+xhC/k6NJ4HppmA+nB8I KUJgy7wGI++TE7CzR0h6O5CjoPWcX2eIFlBSsdFlsx5vYK4BS3yHqmEP6u2fzcPwjHst eQW41WGdLr1JNk5C6aRLdWkxZmyeuLlDKkIjJfPFvmqZ8uPhXnPdqCI3cHBMDs+vuEG6 1MVzc71n4LaaOOFETaAIVi3rLfyB74YG3fz2xfMK+otHwY9t1u00WNV1vZer9j0qkzJ7 5OkuCNUQnT2ifGlSNTyBewE+UBpqJfiO1oQ37akdoZp7c61enp+/7MBm90KjT9VoCcWH EqjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880041; x=1779484841; 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=sIi1UsWlJyCFYlU3H3U6IZuU9kQD8zJobGIa63j3vGk=; b=sYE1cq8tIlMTLc2Ql0TusQvJ/CZWZrRk9R8S3oSRFh49peHJs4UkJOCxOzb/DZhsm1 we9ktRYqlRpjccMrwBd8EooyC5XsOmR7jwMaI340WDZ2jjAQovZN7BLnPQufBI4Jq5CR TGHye0kpPePm30BhaLANqGGRKBlkc5auyTVdPukZ1ZZEui1fJQWLXf9cvb1HBBoxWWez zfX6CNQAY2pm1TZP3dQ/Ja2TNcnnnEREDV5lfXlBpKY0opQS4FcnoCQwVLWABEie+Ll6 M+i6gi+4NdcP7ccT1BQpubdqciviHBNbvHIr3aQnlusDcaZPNWBGgZbscAp0rzWuLliC nLRQ== X-Gm-Message-State: AOJu0YyBJHDSgix2yausiM05l1eOMZySZ8mSuWaDXitlotM1EgNbD9B9 RBJyw9ZU8j/7R3lt/QcY6g6YMSpTW4GrXAPCWoV2A0XTmUgExtk+wHX/sf24YnZjDyc= X-Gm-Gg: Acq92OETR7nfoI3Uqqj2wP4kkJKo3QrdmF7l4cufcPbFkBtFzyVC/e4Q3v4J3sF5EXA 3nIY6t1tBh5Nsl7EE/U3gNYKoJjejYAwg3aD4yC26zdcqM3nim3XdRyv9Fyc1JaS01AOqLEOSwW aIV+NvNqaNba2A79bXlhG21pdLiI8E8+RJ8Raa0kU55jCJGTrjyaSPQgDuVIBRFjhD2vIQ6e3mp ENDkjV9U/+h3CMw6wM56CXj2Az3DYndeFPJYkXhPNUq6+uvzB4lqcf1l/mS0Y7wMDoTaDK3qEg0 FEsinAmmHfhgcp6GAj9u3VZIHzw7WTbx6YMwKt6CvC9NNQNG/LzkH0XbdJULmXanSIHsYYiA9ag bBtdXXLVVeFgoyuDXewNKH31liD5syVQJqxQohLlmeDvVkVMuQSXupfUabf3J2lfvMgjX+xvF+r 7txdHbfhFPyw== X-Received: by 2002:a05:6808:2386:b0:482:4df3:91cb with SMTP id 5614622812f47-482e57b46femr3487235b6e.41.1778880041150; Fri, 15 May 2026 14:20:41 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:36 -0600 Subject: [PATCH 37/66] 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: <20260515-misc-2026q2-v1-37-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=21379; i=imp@bsdimp.com; h=from:subject:message-id; bh=WDl2YGjpzZEoyL14XSiMRL6h4Wk0vHDVJ9yYwBs6QxA=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43l5VcK6hGWbVQkMG0oPBpP2/zknad1OWeYZ eQ1tBQcVOyJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AJBjD/9x9O21v7Y4yLyCFAKb5sC4NsCG0AohK3D4DTS5bRip9DJfMckgRZujOeSKLu81dL+gH5F WXKO7h35ZzSi452i0rF9yT+Bt1RqY5wZH61ZX4zpDpJmSMUwpmc9Ct/r6VTJSjBtzLnLFrCxYe1 ti/zWkY3pstk3Ip+h1v1ZF9Bxc3K6sMrtnvsD0U9BusuGBTUSN3ur86jOHqdTHku/juy40t8Ggs 0ZtIOiO+nr6FdtEydX+Vu6sJO8UuYoj87Vbfd1glUkbwyMzZAIrdmnTI1hulpaLBQCSFr5KS1g6 YvLxei0AUunI2b/8z1WM4S3jJ40zc1vj3quFQ3DaBhsth4S+DsQTAPznIDWacXGYLiOGMdoCBZV L2bjvcyAh5QAIoIuJXgHNutgQ3bDildekTR9DJY4cLjxqesXweZxZLWLIK28ZihNlbNgnil/JDN TLoltSvZmg2I6M/kuhO7KGpkkDQs4A7b0fFDkMZ6tfqHU8Qw6uK2/HO76bHWT93WkUBbQceTSKC AixqUqEUgDKH8mLiM7QXKlxq0WoCeCN3rH+x4tPGz1C2Unr9FanQHEP0+zmFcsBVVM4uIofKAuV /XAi5GFOqJGf3BKbb9phHsT+yEg7NpHsxbWGbjwIVQxk/jR4ZcOF2YnMzHRbRjR0QMkB1IKdVce ICiqQVo01d14BEA== 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: 1778880339461158500 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 | 513 ++++++++++++++++++++++++++------------= ---- 2 files changed, 325 insertions(+), 190 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..f430806e05 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,8 +1303,14 @@ static abi_long freebsd_syscall(CPUArchState *env, i= nt 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); @@ -1468,6 +1412,197 @@ 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 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 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=1778880139; cv=none; d=zohomail.com; s=zohoarc; b=Rl5efNCkpB/hV3BqzxS43bFMvN5Pj4vwcbwpzp+y/1pyWWkrajUkxVAg2tabccnlpqR9/r/NOS3IecOKmrz8h4RyIjTH8CDYimEFdT4YOX62Ldmvnb9TCJ00Sr0uyP3pnxqDEcN3a+yIt78Crh02pMMWAhm4kGXGCmOAubK1yl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880139; 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=h+NVhjFIiLtaVRihGXIH9ttcpzwmJB5APMopVO0qrs4=; b=S9R+UozpkWcdSUC7VbS5stkcSo3nCNkrk6o9ZQwfyitpC+ez8k7MdiGGwMQrefq6gzZdwvmnevi4O0Yuy7x9l79CmS/5+vu+mwxyjX1Nrhg4OPmdVIT6EER4WHVye5J7PVo8i2mG1z5T08k+qLaQq6LPTZFXrt/6ahegETjSp40= 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 1778880139715376.38403637842816; Fri, 15 May 2026 14:22:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxd-0002VS-UT; Fri, 15 May 2026 17:20:45 -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 1wNzxc-0002QO-Py for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:44 -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 1wNzxb-00034r-7X for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:44 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7dca4debedaso351868a34.2 for ; Fri, 15 May 2026 14:20:42 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880042; x=1779484842; 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=h+NVhjFIiLtaVRihGXIH9ttcpzwmJB5APMopVO0qrs4=; b=bkKlu7rBz3FSY3+PHt5VqUWvxcmWzMbVZcqZmYmes1jv7RdU/A/B7vJgIAaPcGCx1R 8cG9RczxONq8b5rT17G5bgfoPyyYqMG2OPyvYfQTQ1Lb80pu5PuTxV3DEHnj0fybJkXj CvuR5AwZdSUZucBYmHI0M3flE3aAtlHR3CpHYtMqcvfGlvliI5GsLlpv9DBPVoIBhRW9 noYV+6g2c9YwNkHakOqTfzny9FtnYqN74OXeKN2gTqhYvKAvsGZUf+J16q9KkOZAhr/C KjLcUqEQEQ8pyoln6vo4Pt+WJXVY+46e3T5MURQcHSxdBJ7YdWqDE3pIb9nrkTRQkgri koRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880042; x=1779484842; 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=h+NVhjFIiLtaVRihGXIH9ttcpzwmJB5APMopVO0qrs4=; b=IQz2rExsVSB/mQdPO/RQb+dcUzeTDBM17kVqRPVi0uyksvt5s2ELAQhya2WMlJpZr+ MdArEOzMW0EBIcEisVVCHyxiljrKTyTsyYVSgApYaN8yssLBW/jNCQNrg9WzyNquI774 Pz+8TxOSfIzKb0frWMp6j0oa7FP2vdmbUTcd4u0IhPy+hGe/VCNIgkz+8WPk9fGwHtBq L8NQPRn3YHF+QSSTPYppzeAz/e/UrDXyjAyZx+W+mwkorRAdaVKUqfCN/R+mmqqRyfu+ uIMJBsVTORx/MCfZ5uOn2ePCpxnp7MmZ7uKA7HJYXodZBz0TAyvUIwtqBSMk2Yvfwwx1 A/kg== X-Gm-Message-State: AOJu0YyVBcZVAEXNhycjjovFOBK98ctI9gbTWy63EPgKKnuf8iA54AIK Mydw3QWGRrGT3/d48YH8StV4UGKMqH49gdoEKUXS7gPTefEM1QmOoUco+yktpBZaPiZrMLIVpiu p7P6wui4= X-Gm-Gg: Acq92OEbLgdsZ5cF2lE4QR4ze9uYz+IQSO6JdqRgbrdS4nwBbEI7sUeXOT97tf63SMv On73JrhISABVcMZDYgvL6ySk117nacHIir9cZ/+OmxbHDoFL3rimhZbPBkkYC9CDT4GmNdvrSLj YXxN5nNWCfIw/xidnsOXAGK74zDDw8AWQ4TEo6MmzCUcv95TZsyPAE3SDSJDVOVcGEZRpWwnLdA MWZryLNqUGALC4u5FyxAHWibuefSVQXNK5b1yYTOfSbknXXIfJHXvxJ7OVUNbI78ipPhsZcCYI7 5WaqU0faAhYXyhhV+rorpHY6YACEhY/L1/V0+klii4COQ7qYTgWsC4BuR/nJPszFYnqi3yq/QpL /nHCHmeytR9VetR9R49sTznq/x4fFbz3FgCcfSb3aEFABYGkfLBeTwpE1Gt95/Sng/+Qs4xiBeZ 4l94Qp0MxwZg== X-Received: by 2002:a05:6830:6183:b0:7d9:7201:1acf with SMTP id 46e09a7af769-7e4ea06d27cmr4105805a34.5.1778880041864; Fri, 15 May 2026 14:20:41 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:37 -0600 Subject: [PATCH 38/66] bsd-user: Remove dead watchpoint code from cpu_copy MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-38-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1245; i=imp@bsdimp.com; h=from:subject:message-id; bh=/Sr1aqgifLh2JvKGGCVN4hEJgEcNvipkIFC3FyYSfs0=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43ls7NH2S7tv+dYyxCU9WlAZugwLnTY3ngKu 5Poboh7m4qJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AB4OEADA+wQpo9/dusIadPDFPmRWzLgqlNbAej7LSQrVJRyueAYwx3BBwdimZSYLrIWvDFEFZzM jiNJBk8CS1CQpFFnO+3zAtPiuNRts17859kzhSfVWllGxAamorjV/4QiN7QCz6vy4pqcAxwePnf ueeWepmGERjEBrM9QkHgAhYC0t+LfDx+xqpqRYVc4qT2v2fjo/0M8mYgZV36I4PfRUkMJIAQXKN lmCdTr2y9w26YZzzO9chJ2bSjErQ5c9in6KLrFVGiR/j/wPWGYJfFE8q1lq3ga825ZWpm+Ki31h 09uMWE2VQt3TQBd33MgFVvU2k/hVmbWkMc4hsmqgxRWBiSeSQwPsVedMW92rCQLmefEGntFa/oB dUMX5fIhNAJl0FdX/LyI8dyQR15aFNgP+lDiOPUYxWHJL4IiSkVy4me8AEWYlWZDHA55MaGBTIF T5eC6kgT1uiFbZnd9I5JZBHB63BSnJ13FroplGjXzP2iEbEH/+GqnAm+IKgKHwyoeKTDcZsXraL F4Jp4XQYFdkxBgmDEeaD6dLEgUedbrFs9uXhcz0jEYCNQhSxEL/W9kQUNSa41ZLzjNEFbNNCO6N kFBUvKaeOCKdh/bk8yn0TyFETQ65LAfu1FYH3yNq/fDPshyjyStieYYny+KGIjAgKcU5cgqvTL6 QG7CQM912YEUnrA== 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: 1778880140168158500 Watchpoints cannot work in user-mode emulation because it requires the softmmu slow path to detect accesses to watchpointed memory. Port the equivalent linux-user cleanup from 48c8c5e886. Signed-off-by: Warner Losh --- bsd-user/main.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 415852d88a..a79ee52cc1 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -233,7 +233,6 @@ CPUArchState *cpu_copy(CPUArchState *env) CPUState *new_cpu =3D cpu_create(cpu_type); CPUArchState *new_env =3D cpu_env(new_cpu); CPUBreakpoint *bp; - CPUWatchpoint *wp; =20 /* Reset non arch specific state */ cpu_reset(new_cpu); @@ -247,13 +246,9 @@ CPUArchState *cpu_copy(CPUArchState *env) * BP_CPU break/watchpoints are handled correctly on clone. */ QTAILQ_INIT(&cpu->breakpoints); - QTAILQ_INIT(&cpu->watchpoints); QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL); } - QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { - cpu_watchpoint_insert(new_cpu, wp->vaddr, wp->len, wp->flags, NULL= ); - } =20 return new_env; } --=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=1778880239; cv=none; d=zohomail.com; s=zohoarc; b=gnwGIjjkRA57VdloR5yF6Vn1d+XIeCcnDfD12Ml9IZ9MDl+y04g3p7mF/KlwwHCtdDTjoz3m+w2aDNgwppvTY3RHN8ORPpAFzL+nHDpNOJcq6LdXKJoZaZUog1wywIMceP3jrrLieDB1XDaXuR5b+FZPVkSo0866OQ7qojl8BGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880239; 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=we2oIIQTPMntmYxBOpZLrJMRZTsa6cAka644OX43Zvw=; b=glcosomvw8icg0b8AR/45ttDguNtudboDZAa1izIQvkZ3mmsZbMQpa2uwBEIgAKJfY8ZfznyRYk4JelaoVcpvgqFR5gD5t1Dozxs6rvDxM6JvPPwbTKBlzXqo3KNTf2lnMyBztSUdt1Cgth+EnyT5CBLoUGVRtEA1KDruGMq3EU= 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 177888023993782.33977449239217; Fri, 15 May 2026 14:23:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxh-0002jb-DI; Fri, 15 May 2026 17:20:49 -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 1wNzxe-0002XF-1d for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:46 -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 1wNzxc-00035I-FN for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:45 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7e4de538f83so252584a34.1 for ; Fri, 15 May 2026 14:20:44 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880043; x=1779484843; 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=we2oIIQTPMntmYxBOpZLrJMRZTsa6cAka644OX43Zvw=; b=sv5Et9X6XS9z19Gk+Vo8n++MGP81NqqFffTTFpoNVTRXHj18OIX1tw9Jz5MfLIlOcI ckl1ZNvQzIF3EpCX4u8rWyqokx/T68om8XPCfR1RRJovkG81qJSLrxMemsmJJQ3/AwF4 xEVHrjLqvO787/7FnF+tAtmyyxK2vZoKUTyXfvgiX4MmZr/QQB86irYZTQMmb00+QeFv x+t/6sXYYvaXmD346yJYSXiKLk/sA7TunZXYFdmoSoBXhvD40tSnEtm4SFmAwJfcsWyn TRcgCsHHsNFueb1wqPGdDUtUr5vnc0I+tFPmNV4GIV3HfQY6x5g0ZO0/vrqvv9V5vnmx Rd3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880043; x=1779484843; 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=we2oIIQTPMntmYxBOpZLrJMRZTsa6cAka644OX43Zvw=; b=fhfCieCMFiPHyEAB8IR9p08p2Yt8J7XqwhSnYBKD8/J8e0Mim9lUMxiPqvOHNiuHK5 HQrjSiDtpZEmZaOFQ+fWpPXzDMSxL+wmVvUxH2uWJqJ3fVeep87ad4/eCRjzHn3Pp/re wLzbf9DA1oFrhmJutMqMv1+v0KdPGNcQxrDcqAmx6MXo3JoA45W9jty8YqVbMnWgtkWT LELIdoqzL5GW/UZsfGxl2Udyyg0Xrp00RdVYip6/RAFcZTHp5445FZ3Y+ScKdeqg6y82 WtIMMMd37sUdyXGnjQSsnDw/rDiCn6UpKC48mSDzpckJv92lVnAVfQguG+M8JU5VpVzc QwpQ== X-Gm-Message-State: AOJu0YwzfTBRyNE+WIeMBHLMt25iqW0UD4yojk7QaYc0Zo2K4cOTo39q lFbGL5atgzTKe3u0KiicbKy2YApq6H9jrTQi0Fmnz/rtv2b/incUUZuB6GlQfupOxvhMPuTzOQI vooiOpi4= X-Gm-Gg: Acq92OG/oDPUYqq5aGzMJ/J2EzkqTmKkQaMN4bEzzYOwgg/JkOERJRAIHy/RuDLg49b Q+SX7xIoKjSCnSRvNjG/d/QlAUvCV6CvnmuafhUx3lNU94Eiqjp9UQvbzXbDSAsJns3VQRa7zCd zcyCVi4obyqgOr74YWlCZsXZ/GvuOD9MP027YqBzxLV0r/+BTrFHNGi3Bv61OqI8sQSVwH/IQXS 5rY7UG4cHCLxL7uJULJAMkFaAL+muXj3210hwJozxBlDHULu7T6wsTOnAj67tTTfxYQAt9uTOkJ LuUtA8wxkCXEPgzZvDjfiykbRIPFTfnQjy0h+BNLkO9gBs/3UdGWnwUj9NMQ43ztCBAIGUc79fb 1pehXiEDzn3Q6ZeEI356k8nr773IPYuWoBwG8f2eWjcbPET3XyLje9TadxBkVvEYpnjsOt6DE2Y rnyqqR4M3JlQ== X-Received: by 2002:a05:6830:4704:b0:7d7:4ee9:c39a with SMTP id 46e09a7af769-7e4ea031993mr3996876a34.4.1778880042828; Fri, 15 May 2026 14:20:42 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:38 -0600 Subject: [PATCH 39/66] bsd-user: Fix cpu_copy to initialize new_cpu queues, not source MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-39-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=912; i=imp@bsdimp.com; h=from:subject:message-id; bh=zFG1nVMGVX8DcNWN3HmIzmpxd/HxOHBG0XiG4kbWLQs=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43lnWGdW9vuxmFNKEotemhaDbSpVH+sxaZkn zmsywBdb/uJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AHVsD/42xjP/klfb6p2EJ7rVXsjad2HGw7KNi6v+RGzFPMtco2LaLPfCg08B1ntAONWxbF6r8vC OCm2gCKRH34DKKTltDiSI+HKtBd2o82GT1tq39cnWBBlMo0qXRNxX48cYNb3MT+wM0iZUO+7KCe qF03qLVzdCYYt9a/6Elp9+9ez1eUozi0E9Ul7512r9uRGFXT8EJEYroirhCqUNNCNlhLm76X82r RnbA83sga6YpKy0cHaZq0DIfI0qLvEZyHK/Voc2Fc8b3wpde8cQT0xhXR4rMKrAGk54u0446toM jtXIsL2OraVroJbOs3hTsWByN5EHS0tW+sO2fYHXYf6AsWh4NxEgzt4o0it9xzzOyS8L3Wd7BFJ SlSS5thpYdcy6vraESI4Sgny/AsHt8ruEnjiTYCdrKQZekNQ+A9q8qNFjFqeSE7KFkgJvogMAd+ 9LeAUXTQ5LbxlyaWvugfWEbT5jtod6FNpLNkwkfmN1zc+rRA9ahR63Lvm6JbIsJiQXmd00IV+BC LvGcgyIXzOa5mhepiyP3dgVxQaGdQ6IjxEJZdPVPs9l+LMGFGY/2PH4MpnfTSxEP2Vpu6VTVoP7 H0I3BkIozcmw+0Gowonyre/zf7j532Uc3kWJ5p30+wtJEuhmB7QNaG9DosIjqYyfcA1FKcuYh+i 7VH7vDoZIanP/rQ== 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: 1778880240829158500 QTAILQ_INIT was called on the source cpu's breakpoints and watchpoints lists, destroying them before the QTAILQ_FOREACH loops could iterate them. Fix to initialize new_cpu's lists instead, matching linux-user. Signed-off-by: Warner Losh --- bsd-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index a79ee52cc1..3c150b54cd 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -245,7 +245,7 @@ CPUArchState *cpu_copy(CPUArchState *env) * Note: Once we support ptrace with hw-debug register access, make su= re * BP_CPU break/watchpoints are handled correctly on clone. */ - QTAILQ_INIT(&cpu->breakpoints); + QTAILQ_INIT(&new_cpu->breakpoints); QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL); } --=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=1778880181; cv=none; d=zohomail.com; s=zohoarc; b=miwzHymB2DfWfXMDYpuAHEv7tEnG0oEQ15D4zOapEc0DE0dyjhuKunImg3tUbyYqwEIyNqSDq7EZfw28jWLQXDZc4snq5WmH+mxl89UPqqXixwuPQcSZozEflOeezqDbx9iekLPPUrOhMe0bDwoKuNlPfWO9vGaNt8D2cXLkKaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880181; 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=ZZgub/ePDDWE5FkQuF8yjkRLktGlum9Bc8Z4CY9iTsc=; b=HkwFuDnnTJ7r4uDjIABiL4IJkAeq9UZ3MDkqSsdqEx/0SgAH6RESWEGslFC9/Jlgo+7QCBlUVOaOkCnL7AfmwaNzFfg9VlgUwFT/mlNpQwFTUCj2X2t6MWUDq474hVaYHN8iSQyHHBXrHgGRgLOfxVxfyZ9w35vlb/cbA0f4Js4= 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 1778880181408112.43262405293342; Fri, 15 May 2026 14:23:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxh-0002lP-Hm; Fri, 15 May 2026 17:20:49 -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 1wNzxf-0002d1-Dq for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:47 -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 1wNzxd-00036I-Q5 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:47 -0400 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7d4c383f2fcso323080a34.0 for ; Fri, 15 May 2026 14:20:45 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880044; x=1779484844; 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=ZZgub/ePDDWE5FkQuF8yjkRLktGlum9Bc8Z4CY9iTsc=; b=xIReD9bOXR6vSVUYN/a5tl+BI89TxYTQqO8KRyctNaUQHVi0PJZ3kzCaZoVVfAdLTp h5AYIAu4oGOH7fCav/BFPIlCOHmYku+Bs8xTG9vo/eeYHnn4bdMoxjSiJFBT+2UPX+16 l9YPZV5Fai/Z1V7MX1t4vrxs801eErEvG2eRLZ7NuakV8jgxGpHBWVi6TAJpJUqjEG0n HCXnx7bslNW33DBd/ytTHfHmRhlN8fzVOSF9Q8dItxXAB+9Mf5ac1S5mCOrGoxg5O0TG f+4V7c8XGay0LowDBdhUqnApqFR6hPxAZCoWns0ps6kNAcmiPNsEaE+SfGfn0Ug/SDh9 zTNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880044; x=1779484844; 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=ZZgub/ePDDWE5FkQuF8yjkRLktGlum9Bc8Z4CY9iTsc=; b=oRjrYGdlRcrg/rOC13X64QT6zaWv9BG3J5C/Htg4defntHUeQa/tu6xkhRJ3s4qBjF SWJCD4KDQz+7b90Jjf/vh1hVLWtqpyqaK5XGewj3Og/3nwyWyW0jY15HN5eRvL6O+QoO qhXXfClmAwJ6HF9eJ6cxiQPXqq/TYPORNdQnnw9EW4Cr0OHL8Z/8SJv96EzinHHT7HbL czmJ5cZ3n9XB/XR0a1FeYcrD/YvrltZG33JZTQANzH5yTCgi6kbJVZ39xI5qSNvu/ff7 ypkBnA2sPg+QSck47DUmEeuznMGQ3CCAaq5J8cnQkt2dAz5lEfuHttyobC+aEpjFVunn dSQg== X-Gm-Message-State: AOJu0Yx+tdMf61oQzKgC2tVjjyG1eyoMbmuHwwybSzk85VzRlyYShcSr BSH6FLZmYGnksyt2yeTR8GYCkciTRwKBNRquBKkyavTNfOyWxgojD5nxqh5Wkjq7WfUc4iCfB4o UrhSlNP8= X-Gm-Gg: Acq92OGq+cdagES3zqoHzoKO0EcmXqH85z5EHxxoDihV7huq17gAbOyLoLWl99Ylz09 V7ctGYaiu716nOws4skQpiAEKYEfKWkFCVH395QFl1CDeMrKGbqR6WQ4JHPNvO+pXacysqA08is ObdVWSeYA0vXqHv/Lvi1DATlmdAcGBEgDUOHq7VBTFRr2wc+9PPk+itnOtdq4Dlq3tNUaJ+Fv/p 8qSOW3uBo9mHBdEDWg/NBGq1GsBB2ptUis+cTaB44BKzX87nlBSOmEqSYir7DLI/xXcBExcTwXh PG5NsDupnTIj6N6Ozh3bNyWj6F/I3TdyZXBaWKc9epZwoE+43D4ZO77v/RUGow1x32AFVwhZn5q mJ9z04ARL8Ml8x5w5fKlAdmiNgg+/jcTZKHPytOE5j/XUJU7xVIQM3RHC2CRytSrsql6vvQGoc3 LIqecS7GzDyg== X-Received: by 2002:a05:6830:488f:b0:7e3:d29b:fea4 with SMTP id 46e09a7af769-7e4fa0569e3mr4204608a34.22.1778880044066; Fri, 15 May 2026 14:20:44 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:39 -0600 Subject: [PATCH 40/66] bsd-user: Free CPU state and TaskState on thread creation failure MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-40-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1291; i=imp@bsdimp.com; h=from:subject:message-id; bh=6zH1P/EfzAjKwYbXo5qc1t1pTr0e5VpKM3jOBHc8mPk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43lDJ8iIfjt9qmgALG7gHoMp/QgNSAiZ+8F4 WlCvZg+PvGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5QAKCRBsHNEofbAR AJt+D/9ckcYy5nQeHZw/9rgVWmSU0SzTOl/TBcuEitvElFqH9N3WFC1/anQtRPpg+kWsYlNl3Ni iWDYseS6gzRQ2Me4uTrNWPRV9VNNb4j6rYuGItzjZNxDVrit3W4s4WflAygz/7e2GT7ZefLmjM9 qV3zt+PWISglhpt2uwx8t+1BUagmg+gGA9M7zLfTZT3/Ho/lTsve1o3Z4lPN7xioU4AMyrLu5cN PsV3BzYU+3IqCFoL/IJByplfz73AiA7UgoJRYHz8esU1HpdD4tVkhBUO24+BWXJXTbBL3Y9poTv sSyGnmw/RBRtsmJCbBocChTw4QxgatKdMCVZUBkARehe5nz3/+nQ7k3RIbKfd6bGfZXxh4OhqBZ SQRs3daAPYfj05Z5JLXdoUkeserSmUddd4RXDhJ8G+ZZYDSMJC9c6R71gCwuXUqnUlqNZ3Vglg3 Cyr+n+0e8Zdv4PAInKE2kRFA/Og7qnTfmh0o8EgGecYnF/DCmL2fnrpZLztw36zgNEkU+WaD881 bUu+q5QsWK9te4QyiGca/PkHv2Ifnt3Oa8fq1dGXeuN/tNxO9stOQE4s99c9TVFXXcXpkj5pY3l q67kscRloKcE30aNUviCFK3+0zwzdUSelVIjlEl/6cr4nZL77qRRExBKDdRc8jeosKTnp/j7gak yDla+xRcS3YekJA== 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: 1778880182462158500 When pthread_create fails in do_freebsd_thr_new, the allocated TaskState and CPU created by cpu_copy were leaked. Clean them up using the same object_unparent/object_unref pattern used by thr_exit, and free the TaskState with g_free. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index 1d88ee05e4..9e6055a040 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -1633,7 +1633,6 @@ abi_long do_freebsd_thr_new(CPUArchState *env, sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); =20 ret =3D pthread_create(&info.thread, &attr, new_freebsd_thread_start, = &info); - /* XXX Free new CPU state if thread creation fails. */ =20 sigprocmask(SIG_SETMASK, &info.sigmask, NULL); pthread_attr_destroy(&attr); @@ -1642,6 +1641,9 @@ abi_long do_freebsd_thr_new(CPUArchState *env, 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); } =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=1778880091; cv=none; d=zohomail.com; s=zohoarc; b=TOVheQLElrxVO3A4vym+pGqfZg8kp590xVRhC9Vy9j0wAgXMf0R7zAoLsrCYtYPyzTkvLTC4dY4YBiWI94s9xOYZqW72ol4fX8ZJZIQ4qdQYwOKZUdXOcvxTTVEJKf0ig776KBtZNcVVJh7/IU7w5tJkl37ZTfOYrauIXjarl2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880091; 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=0LliE3/htyGU4OjwLNQCoU+MeAEXhlDoXWc5crY4U9k=; b=njV1t3OUGC3vh15ezMQHPDNTtZ/X28VktxuaS1ds9pOB8XfTsdhSCNY3MletuqZcE/fh5PCtO7g6HLR5ZX+8Dbp4V43U2Ez00uvAPsw61GUw1m2t41fCutwxKGzeqKhJ8XCEFaiWnIFeZMXybgslDnc2q/A2Cm2c8y7JaX9Dy/Q= 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 1778880091066979.4501349051961; Fri, 15 May 2026 14:21:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy1-0003BL-TZ; Fri, 15 May 2026 17:21: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 1wNzxg-0002h0-DZ for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:48 -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 1wNzxe-00036Y-PW for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:48 -0400 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7e568ab0bc5so344440a34.0 for ; Fri, 15 May 2026 14:20:46 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880045; x=1779484845; 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=0LliE3/htyGU4OjwLNQCoU+MeAEXhlDoXWc5crY4U9k=; b=uqWtvhSZWn7psSwzoLrKriYCn1ELgF8QZDybONsMNHsmU82MQkcSMqwKRrAwzxKIu/ vXCWsiH0kymwrYeAuy+L2yHg76UiQRMJnA/rYb+tzbW8O8w+mBNeKrUr5eY1gkZF0aiD 7tGZ93rhQ/vf619xTFJUGYbqXnb3gBPF1sV2E1cYKmd50ZMnFw8HKDePmVntUGrNnddz DcerPTpFqpkgtHEeCfCKikvXM7QaEHR8iHdKzSteVL5Lz/Sl01q9QJuYynZ1N7W49PCe gA9iGe2PO+Bi6QwqiY4ZK6d4iIgnRVwwlou3hCPF6Q2osp4oLoDbv4CtCbWMvpDHTFYv maBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880045; x=1779484845; 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=0LliE3/htyGU4OjwLNQCoU+MeAEXhlDoXWc5crY4U9k=; b=fWKy7CT2tW3B+7fZ/OLjo3UD78KcIGZyYEPOmdPtLslO8tvxKVmH5sl1tBs+d6OYCG QSJFIAHGoyiHtUEQ2PsOipYHQPaaeHJ/Zs0ByPjf9wV92ymCtRE3NmZ9jkFz1FHTubZS O4xM6J3hUeXj2BiqI1AFgFnbwnei69/zeWIOzc0Vw/ZVc6+Ukc+2/O4gfZypbSBTYnEr fcG2qQ6Z/2BSpMBHZ0hk2uKx7kmtmCvs2V1c2lrVfb17FbGJ0dQUE1GhqqHZUOQ5D3U/ VARvQLxHpRaiPKmk7yLQyhHgP0CQhz2WWajGQKBArqd/189uqjZLIbVGRDxS8GPTKzRi PnRQ== X-Gm-Message-State: AOJu0YyFpX67zb3TKepxj6TvY34RZn/QpqU8/PfO8HjHX9Ipdxh4IjXA 81NQaN0dvFmm+8H/+PkM5ms5SNnWjrWEeTBGtD5nXtG5vlVcKTaWykDAcKzwTgP9xESElZA/w52 fVVEu/XA= X-Gm-Gg: Acq92OHyTBrXu0GWBr8ZEB7moqxOHwuG/WoMfQ5NpIHqf9ayhrod6iAnpKBzUxd1Eq6 I356KxVT+Z/6yDLD81eMI41QOtoiBGgrg9CnY8kBVRGYpLcLN/W9oFtogsTEHipVx2FwTqD8QbQ vFf0itr/mT5bA7SeJTDYlw+KIqP4Gg1OfXH9kXpKM/XAWfFIH9XiuR6Xb+nzXWXACp/p0dJvbga LUF4IiSNzkbt53KbCjcicaUqMgzhuA1ceBMDWGQaBHyGuiog/jUJUjg+ZKLDhd5B2gu2hoGG/1n uDZLWa2wRvzNswfO6JqUBqgHXfqhrR3iXzMqHM3v6sbwQbQcX9IxbqPRO5BaryXKL9rdxXAfwhW PzAD4Uyux3lNtsq8cnRFq2U7LEIiQfgYntxmPXnRahtX2tAhQVjTp4Av3leWGizyBP9aq4wpeeP i4lN66lCdaTg== X-Received: by 2002:a9d:6ad0:0:b0:7d7:45b7:ed8a with SMTP id 46e09a7af769-7e3f1014018mr4400651a34.5.1778880044976; Fri, 15 May 2026 14:20:44 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:40 -0600 Subject: [PATCH 41/66] bsd-user: Fix kenv KENV_SET to not write back read-only buffer MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-41-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=915; i=imp@bsdimp.com; h=from:subject:message-id; bh=3EM274dxNtc0cbsRdm6rHs5WLgeCOj1JwA4lGKjXEKM=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43m7yuP6a5ONQ0r9uswWBghLD0iZe52zdzfw QtUpbArjDaJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AG0QD/9D8awpbE5JzYhOPvye9RGdSeC6AEt/kBVT0NKVqFwo+j/FCRAfEjTOVJS2ni0nfycx/kc /llFKPmguMkfasGKHxifOjh1Xd/uc7hDMxGQ9yxLchcZUGC9lPq6axcHve7vtQCTnPj33bZk/EK ADNu6av05BgK7h9RiN1JBJ4ijHWOkAwBtmax4qrqBPjrB0BGz3ETu0LTrjDWRtGS8MWV8tMYIYh X7JX4hEOACBQnDRkbgd40ccYdl2wAQT2994SBesVlyj88NIjQrdtSxEMV56jiUQ0SxLp6kSq0qn 4jALmBHS+ff4L5QVueydBg+/T3JytlZJYmZ++6JPSBZFTKyqQuzlTFkPqeso2ac4kgT+e+U0yvQ un7RdVouHlHRT3BxbNkGf5zy1IO4gbslm6OjGMq2Ie5uiA1mqRV9vV2CVm2VYIKf8OV6JfOWkmr BnNtUy13akGguznhiWvCUn3DB8uU8UJed5kHsU9730LtfstlbJyah590N7chQcuCWqkotQ82hmI Pw9o4Jcj5FSgkZPD+rPLSTFnqSrOiVCkMt4H02ASO3UBK5cfQqS3Dl2Tz1ts8P5ZDJAX/OPtTdi vc6kNfRaSh4TwGKaai2U75iRukKaXXdbmNy7vHYr9r6Mhfu2FJYO+pbwSxfgEbgjJoEySLIlZOu Xd7fY7k/o6Jr7hg== 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: 1778880091873158500 The shared unlock_user at the end of do_freebsd_kenv used the (potentially modified) len variable for all cases, including KENV_SET which locks with VERIFY_READ. Unlock the KENV_SET buffer inline with writeback length 0 so it doesn't spuriously write back to user memory. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-misc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 7ee903a5ba..204d8ebd3d 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -495,6 +495,8 @@ static inline abi_long do_freebsd_kenv(abi_long action,= abi_ulong name, break; } ret =3D kenv(action, gname, gvalue, len); + unlock_user(gvalue, value, 0); + gvalue =3D NULL; break; case KENV_UNSET: gname =3D lock_user_string(name); --=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=1778880074; cv=none; d=zohomail.com; s=zohoarc; b=S0deYyh0nMgnfYuR6Eabez2xnJk/V6CLYbFBapL5kjwHwzAP0dMSjTM0MR4+QEKVrpKUVqAo6hoicXQONUqqNeT9QFh1t2kHNleCjmk9I8kjrDk6Sk6ScRKkC7VPkZeZn1oGEHgqDSPSsIig3eUBvP8rLnZjXdNgRfPk8PsJSyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880074; 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=huwi1I/ka0iZHPtPiOh93wv71GhTIIWhwbkGbSgPwjc=; b=Vrg5hsT2DhTD76ikFYLPJTJ/fYUwyGv5PfhTrac1Myjyyai+IUBt9ndJYIEiM9mefHj0Rlc8jkSvGM7AiWWjQlR4v4Jl/3HnITx26BYICbR13J7wVtW7C8HtfDgNlI4aP0ee/v7mBkEKMK9go+c6dQ3h8FGzitbCpF2yRWT9V58= 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 177888007456611.773298159588307; Fri, 15 May 2026 14:21:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxl-0002rb-0c; Fri, 15 May 2026 17:20:54 -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 1wNzxh-0002jL-4e for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:49 -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 1wNzxf-00036m-FJ for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:48 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-47cbd445021so260577b6e.1 for ; Fri, 15 May 2026 14:20:47 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880046; x=1779484846; 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=huwi1I/ka0iZHPtPiOh93wv71GhTIIWhwbkGbSgPwjc=; b=GO401yidFkK7NlvhCA9pq3A7xh36J3rQbbjJf0WlKcWS5/mGcf3KibQBKrGAhdxiuU KipwlBJV5hn5ZWlkL2Y+y05flVjk55IEU93BS9SUxWMfCOSPR9i+AGyp8M2hjgL3j06z E7OKEAVxr1yDLTRKzC0KsXrKKQwmE8syp+7FRrgoKZMYeQzyySvsN9I1jgppkd/COVV+ HSel1erGbLPL890xy9JjOw13dilPvAXHN82mDXgxEqKner+vYgwyt4XZn3hL2gZTwBYv gtAKI4YxmYLT6WtUlDbfYX7pgYY2p4q9WUlIJplSX6XDMeOaBNuxl6maOdhC0RIIyO52 D98Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880046; x=1779484846; 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=huwi1I/ka0iZHPtPiOh93wv71GhTIIWhwbkGbSgPwjc=; b=BnPPI4pCh6G12TzH1adwy+SZhAM2kCfgJqHe5SRkLTkoakC0RGxC7hV2ViKbWgRDUA R5l3ikIb2Go4C+PPd62ErO1LdoP+TXfaJ6ju0ig9+zDbW3uTdQipDPuNuHq7WMB0R1rg JTSHdLO5+8/D3jTdXAqa0yeaPavHILEbLJAEd3UG8bI4Fmc59OGruWkcR8hZG6cmiIDW dfcUMYOilpnXC+kovJ8yaFiytddBT0to23PpmbYma6GMKZybh1QslcKtte78ghQxYw5d LgCdmMV6I0urOv0yEiBbzAGU8Bo1V6e3WrBQAdJkZt2OL1Saqd7ef/QgT7oVscS4wAZ5 h4Og== X-Gm-Message-State: AOJu0Yyty+zKyL9wkav6saLKXtBb3lBTeqCqDEii3ROvc+Y/4m0Ih9yE FQQ8fMXpXzarBdU6WQEnWKMIexTVPLtXKVghi/ScSThfWI2QE95w4kXMlaz+bkqVbUdjBNy7ros irBIloK4= X-Gm-Gg: Acq92OGRQcmPlQ6ErbBjQvhy6E+wGb8dpvxMwwSiEaihUYE5vymgFGCGSrFZAjeVkMB kBMNLwPpP8j3qFyVdtw29Mm93OOHYtV0y8AtrsCH/XWdlS3UGJrwU9I6AveBwNORfQT5gMEAmp3 /i39XVRlRrLAXE2o7NTvG3CkHNJQv3wu9AXaSqyvaIcPRvEly2RpDoMqXqz7E6IZKCf8w5Gp9L9 DzMbq79RsurlNq5/05CRoh4vE5+AZmhTouma/B/GE0MH+lPE20iSecWwEy8tz19t0ljwFZT2auy Rb2fQLpIso+OykdJEt3D9skrvj1VzcHBHhH6R+T1JQ/4hm+MeNYKlownkl90sa5yPECNXZAgfGZ N2NHPGBdjXgiQydVczxuVU37eOHS6/NkMYqWj1koUj0ZAqdGRpC9f/F1Jf0WPEuDJ8WfTF4sUDf gNj8p5i8wLnw== X-Received: by 2002:a05:6808:5383:b0:45e:ecd9:652e with SMTP id 5614622812f47-482e55ae4c4mr4064717b6e.5.1778880045895; Fri, 15 May 2026 14:20:45 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:41 -0600 Subject: [PATCH 42/66] bsd-user: Fix freebsd_lock_umutex to re-read m_owner not m_count MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-42-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=806; i=imp@bsdimp.com; h=from:subject:message-id; bh=26DLjvIfcurHguoTpL1VROKTnCLKVIS1WBZAmmR48fc=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43m1XvIT0hxgB1wf1DJ9LJRfYps1SuLKNERW SLQfCS1fCuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AEvHD/9Y8gvKVe+4wFS/zvVMXiX6hUuf8MMVn630NpMCj9lcqnSFs2qkd2nVwsp/ozHRXOxGLGe OkdzQlHwt8UL05weQvZAPA+h4qYMpcWmsVzRkBIooC8m+hTb2Qaw129s1EFaL8Rg28U0RAanNz9 CK9M+SvJnKL8tsR7C+KGqRaKvAq+tohdjaw+vnz8454IiF73YOV1CvvXGQJ3wc4I2P0ksV25gc3 z1jHYSFhuu7SyZgiaBRYhw1KmqGkLMSQ9dLNX5lRKR7QE21oU+XbcxX1pPs6wRAHVWNW/ZrgCU5 +zHSL074J0PvsvgSedErcw3JU5Mk76gCjsL+cEwdYW34kRGfEVTxp0xMZGcXMKl22vYQSjRRdh4 P5xkNPgNpMct/DMnwnO16o1Pj40716iyppT+3hxxzdholDbaJXugvZVqAw3BnOBMrTBZxurNABD 0N2FENVrjaFJahtYznRtE5ASWxZcS5zeRaopyI1yCo5BrkUHPexWtgX33HLH1WrZdljynl2A7Mw S4rA62kT6224gIGG6cl+OrdhCvilaJ2WOZcVVHQbR3rYk4q+TZkUA4wOVE8C/3zquN4pWWAwV7R f4/4aBqiTCuciqVDI/LG6iELc0Bc2dOpdul6Mj/EcBA1B7o840yfY3rUADBYI62fOd1FMbUHSwp vjtcF1Lv57rK6Cg== 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: 1778880075837158500 When tcmpset_32 fails to set the contested bit on m_owner, the retry loop re-read the value from m_count instead of m_owner, causing the loop to operate on the wrong field. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index 9e6055a040..b91e0d32b0 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -978,7 +978,7 @@ abi_long freebsd_lock_umutex(abi_ulong target_addr, uin= t32_t id, =20 break; } else { - __get_user(owner, &target_umutex->m_count); + __get_user(owner, &target_umutex->m_owner); } } =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=1778880254; cv=none; d=zohomail.com; s=zohoarc; b=K01hFt8bUZf3z8QQCSfFjgalthshERWb92DhLKKrOQAbPRKVKAm906EBj7BKc+SplztNdxmu3tax7KKs637VPiSH5H4xSOU42ly/JyBarMy9N4OGvCB+5Y9aF28+EoYb7zC9LhmWqWFUL4QeU4zfVFeZn1N5WMEBfALpw0mTKkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880254; 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=G/KCzsg7x5qFZl3HqqhMHWlp3AjaXSHyyYoipw2u79U=; b=ky3JTHXMuilkUk4lPCaw/tMDS3q9D9ll9OhLFJedzmq+FI0Yo6BMsysZvEOeDy7VlGCjb94g9DO4/sxkwl+AUUy2HMn0m+LAs8dgbMLc0AsvO1ZqIhKZoTlZUEmPMr38zjnZUVrO6xzRYGeu+iMzTYjmsYxUHichtvaytlkTnms= 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 1778880254013612.2006702325357; Fri, 15 May 2026 14:24:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzxp-0002vW-Nx; Fri, 15 May 2026 17:21: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 1wNzxh-0002lj-HY for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:49 -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 1wNzxf-00037G-V4 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:49 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-479eb8bcacbso289553b6e.1 for ; Fri, 15 May 2026 14:20:47 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880047; x=1779484847; 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=G/KCzsg7x5qFZl3HqqhMHWlp3AjaXSHyyYoipw2u79U=; b=zJhlLUSIBQnykcX4jWHTJFr9riDvZYHviRanGBgHIxYKc/PMYX3BAjCU5v+ta9BBKq /o3X7Lxl5RdQk9KhZ28b3bvm3OM+e7Ss15aSzBKpHOMeJWKuZ5u6n66cJbhYuZcjYBwT hm8Qw6caT/JIZPcnfMKHWOEwW7bXHQAFEjyGOfr77Ipcr6GSyp3I6tqtn1u5ViKsk1sC h+RH14DsBp5gRPo7RpY0+XabkihBihOyS58ciD0UyCuvZxqHJ8kra4xVBZskfZl6xzK2 N/tqd2Nh/1jcplFiQTPji4nqLmc697VnmUpYKvjTEY0x83oikDxnDyhyUqI1AlMwyG/A 9HOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880047; x=1779484847; 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=G/KCzsg7x5qFZl3HqqhMHWlp3AjaXSHyyYoipw2u79U=; b=p+LhMBnrqw/7IBCY08RAxVyH7+e+bzNpFBRNcfBrCJzwAF3dpj5Lioivcyhu0WU71U eVj0qj60FADfWD3D2Sv6vivtUXngKLtYNpdXe3I1hK7qm5BMWTcLobNMcmSmXN75BVnp GN1rDjsRfvKmaSRpF3dA5fu/FhJ3RE6mQ0DB7/XEW8m/3033XqaZYW+GeqYjQ8KYQWZK Ju7KT92IAFYSiHOrgVOOtgLsho1H+LJkorX4pIBKISF947+Rwd0JqUTySJA4HGUFbHrF rF8pCYy/UsYJ7ZHD2MiGjs6f25BitVVrhkMf2oCikVAHJorp6S5Kdp3OXqc4F78GyjIR VpLg== X-Gm-Message-State: AOJu0Yw+H5pyIfLyBE3dAD7JX3F/gorMtFeoaHfmbDyaJBj1+JRkCAHD tiNKk6jWsojNKK8h/Jyy11DaKWQ9f0E51CXuwQSZgSYOzOau+O0POyBFGcO1pEP5TG/vra2Ixag gOqz68yc= X-Gm-Gg: Acq92OHzJ7R2VNmHbftJAfPABSRjvIp6DiEyQ6rMdQVZ29Cc+Voty6TCzLnbXjfAxoW z0ctb09eIt5FnomHrIi/6VlFu1UP8GEhvt9+Vmegzsct94Ba0OEpqmYg8DgO0QvgZSH9o5flEjv Kj+vHfAA6prmCSzeR0iWE2hAHl8cdD7K8x4SGHPaRrXRW9FFIj4QbkQ8GfDwJkj8HnblIhYzWPG w6aqDr4M1yGTzeF7KfaSyWn1gNUdbzdolcvsEL4S7psy94r354n3ITzRpKdZ+XXPYv1ox4Ex8Ck Qo1rCmVQv6N/AJWYACHJRDfQjQXSORxFJaXkXGvDNv+6EonNrHf+GoNjgCJOr1gf+Q4bvu12w2z OQqFEflPSsymr0XI7UbIHRuBRKZC0UsRhYVm5Ff1FEOK9UB/bw+260eE8fV8l5MDRtlkG2GOAuV YBIWa6PKoNRQ== X-Received: by 2002:a05:6808:3a19:b0:479:d57b:838a with SMTP id 5614622812f47-482e592cc7dmr4181163b6e.35.1778880046897; Fri, 15 May 2026 14:20:46 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:42 -0600 Subject: [PATCH 43/66] bsd-user: Fix problem with extattr_* routines MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-43-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=2265; i=imp@bsdimp.com; h=from:subject:message-id; bh=ndqCsfqTyWWD0s+vY64gwhF6zYhR3XOoViCCufD0HCE=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43m5XDLlSpQGnXELK0zPXP275K+3heS1ldNx HDANwSQzsuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AE5qEAC1tBpbSaHNPkZ5Pp8temwx1Mdm/gIH59z0+YwwpmRmnik3huqAy4XOFsgfR4kYUB9VLyN MLjVPIyeChGL1kTL0gbfMT2VsVRFsxbCJDBexPKD1IoSj7GM/Jlxw4Cuifj+v1QCP8oTbX5VbbI Z2UEdekVbpxhExGfNsxiU2URUdW58CW3tgOf5Awp6yeZtben47CDMtLplYr0y9TzpK4cfPRzQWK XA/7WpjbDviCdwQ7HcxPc9cGy6rsJqs8lr63SuTaW/4d6ZfCGEXM6n29fJO8jYQ9dnb6PRx23Jv AKU3hbLfUCNOBVMtDqNdbyCjRlwuH5kJRHtZHpXKzg28hh1ObMY+Zp9smBmJWBoDKYRuGMx8Sjs vpgSxDkYbsTSev93K5vMEmdrJnvEOAcu0fnuCplivYAc8cjemt+d3sBa1GuNjUiKjLG4jZmC+ZX UAQrp+8QWTlHn6NJQxhW8YrDijQBoJx+s1jc/mf25zhp7BhAilnSnD2QKybXc+I/ZLCsFg7OUH4 yzwB5uqWnSznSMU5YtphH6Eyfr8yhQKGfsAs3faDuRgAj8yHzn+Q8s3IbbZ+WSdit18MFACvRAw 0desTrAU1OD7vLVJTHqwNsXrf/pZ2GAwsGEttacPpf0WrMlKj74JGVLuruRNWwBaSAEe8j3eYDp UbxSfUDfD9DnWsw== 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: 1778880254908158500 For the 5 arg routines, we need to pass arg5 for the last arg, no a second copy of arg4. Claude noticed this. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-syscall.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index f430806e05..f1a49ae423 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -1317,11 +1317,11 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, 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) = */ @@ -1341,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) = */ @@ -1357,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) */ --=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=1778880079; cv=none; d=zohomail.com; s=zohoarc; b=NjJu12baYYctNJxDshcEDE0VKT86pYe6zPHdLe0c6SBg+I3Xqc/yek1mN/AoCxSBWwZuDzTRIfVCiNOH3xW4+6SwbAt2KejGwOQSBpT4fjLPpDHZFuUbrwcyr/F7aIx/qs8Hp3fWbk/naTA6d3vHUXHvOVBKZfQAHXEWdEXM6YE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880079; 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=AHuj+qCYqadp/YGZmDto4OnuQZ9s2XweTIlNAkwUkxQ=; b=iOAsooIeybNw+Q6wfVNdageTWxXHyt5HbzY53dPNb4SP8jsDTnZ9l7cg6S0oa6txu1T9tDKW2ptwdldnvW546wRaW5nJoOMCxIsIDuBJjTfiUxS8ILqvfdJ3oVqe62ZNTq2cZXFYl9fPWseq10he1XlAsF/WkA8thm8ngtQbnoI= 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 1778880079066947.3294142263592; Fri, 15 May 2026 14:21:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy1-0003AS-OR; Fri, 15 May 2026 17:21: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 1wNzxi-0002tx-PI for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:52 -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 1wNzxh-00038u-3y for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:50 -0400 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-7dcd17e19b6so159590a34.1 for ; Fri, 15 May 2026 14:20:48 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880048; x=1779484848; 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=AHuj+qCYqadp/YGZmDto4OnuQZ9s2XweTIlNAkwUkxQ=; b=FrdHX/XLE2bt5Oij06baw+c6o3su5AXb1rO4q5H+mlx/X3T+zKSVzEP6oBIFUaZYwt WY9oMh1l26xeubG58k3JClxP2+IDMG2Ib8VvGvFftMaIcxV9sXQ8IPTePV9EvSNZiwUH QCvbKa8iDrhJTIWFjaeZ8J9Yp3kjGXrX4yU4979tmBi5LVlnDYkUfw2rqEAN9tSwYc5v WDEb705eCssKumPJirJBivvSeNRDh6DZ5KOShJWigQtQhxovziSQwr6PieCfNVtKmg0m Z0SJV4lRqY4b2FxqAc3dapLSmqOOhG7Zkbv4FSPI7Vxbm3TP0IG5x7MTUoL/8lS+KAKn Zpig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880048; x=1779484848; 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=AHuj+qCYqadp/YGZmDto4OnuQZ9s2XweTIlNAkwUkxQ=; b=cYywstts5QBpYbrPUJLXXhIzntr7sLVBX3WVHycfUObyL+qWvJtu+Qz2KchWqC9Amh F4qybyJfthBH0ipQ/Vn5iXyasNa157rWgyXU5T/gBBw8w/DpGMjatPbZVgxxqK9POQA+ SO28GQ/e/Jf0rKn3CQSSUGjAnyVW7MI7G73XeU00Cd29JyrSxdAKCKxULPW6IkS1vorG xXpOgv7zNk5o+KRWgNee9T+tU/8sL5/xVxrlHlvFbh6P4kV2J/n5dtWkKCgVMQAMaH4e IDrJJ8hm8kyzhX/vcALQ8d4UrnxeH8HM7LqrdKfFRRnZBi1GYvGw8XoRqLgintgn2CLC bAEA== X-Gm-Message-State: AOJu0Yy06vbwHzZAh+Be1ptdP7M6wzUiCafgY7uJEn1PqQmbS3k5AMwc 8wDC8ortHELkF2B3C891cho/M127BazjOam03Ob0i5dCNPu/GAzLqM+PyNSyLU2dnQ8oZyvezcm yGEvmeM4= X-Gm-Gg: Acq92OEfUyPj0cFJmlVL2EunB34bjAgHYldUhkqrDj2UFLaffGyvbBGE1mQxeE9Nqg+ a66xz52+Ouw4HWoGYYGAZdQvqF29aRIMsI70OjhDeuQagO/Kf7ZxSm/aMY9rOR9gcQQ5p+vk/NK kciGKvGStFCOXfmMTUuJl9un9nXZPYwHHdVyvfhdHuuAWzGD98dekRYdS2hCffEAVgMuzmvqxZB xH9YVmIwRW06M51dVjZXkweX2nO43j/F/QJz9P4d7ZpLPvnx1HCUsSb26fbPaFowPSkZDASh5ok En8kDWqPmhp+UgKjTQ+oI6YFy8tW1OlnZoU9OQ+j+JCi0mB3Xp9wpOuDOx45q3nn53u0fNX/xfV qqxlepFeyZTAFq3rFfOB4GPh4j1CYLP3jPTVDSxYPHEir7sMjcyS8KhXAIuwYFj9Ys9hO9Ym92g brvXy/b6Y24Q== X-Received: by 2002:a05:6830:710e:b0:7e1:90a:97c2 with SMTP id 46e09a7af769-7e4fa0a3502mr3884746a34.23.1778880047754; Fri, 15 May 2026 14:20:47 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:43 -0600 Subject: [PATCH 44/66] bsd-user: do_freebsd__acl_aclcheck_file pass type to __acl_aclcheck_file MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-44-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=843; i=imp@bsdimp.com; h=from:subject:message-id; bh=N75KZU3MHRQqN3yIHwU+t1Zd5+ya99JKhq/+3G3/YJQ=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43ms9rIuQx3EOyF7JKhPXCkGedMHBtzqLZKk 4aZIa/ntm2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AJjHD/9W1UpEFoYFTdRD9TXFukPq87ylMoprqa8yIHPtd9fftYo2J+ERDMiPKP/kGw9P+M8HUsi 3ijclRIGbZrajAXRHJfevnLJpXQ06z3JMiFmTY7f4RvuHeelOz7WZMh6Ut8R0VAjkJiLFdC6T5p DVbxHZrHEEL6NgmdOIbQX2qwoT5JlyaJ4AdSEkxsY0ea3UC6UgpAJpGOy31bXJMvkWCBjmfrXv9 I79Y/SoqdYMp+kbVevMeql2ISsP+ze+u8CrfwLaqAWCT1YlNG2NUKDyQCQ14qNTOmt7DkereVfG xMOh7jDcdkJ8o+IPx0+i7W9cQ9bYt32G0rVb4lfK3nqJCPW++Di0mUMqCjZkHtGoAp+4P6FxEU1 X9QaXDcXKyMLafYCdJATiwPmxczi3Y+qoAA4dbDg7/g3qUu0VUecn103QDxtCil5yd7oWLQlGxI s738uQg+70QPXiMMGSVkvVrkh7Zo4zuMRfM4TbIn+bQY9xZSkXwM2zLlX+CtjmgjmIsY1LuT9hl QgKsJ5Hkwob/0xC5IpEZEleJPp9wS1yXCjzbVXFj5GoomNSL6plvOMN7MjVJCytEgY/VJjRXd8I BrMU3sgktILtZ7rSAyhSBT2NfOcy123qOklsxM7ltPMepZYNsYxQD2y90zU+AR2Z1viNQtQgfJE nvChY7bMuL8EkcA== 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: 1778880079994158500 We convert arg2 to the right type, but then pass arg2. This a logical error only, since target and host types are encoded identically. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-extattr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h index 70446f9a54..0414a2e479 100644 --- a/bsd-user/freebsd/os-extattr.h +++ b/bsd-user/freebsd/os-extattr.h @@ -413,7 +413,7 @@ static inline abi_long do_freebsd__acl_aclcheck_file(ab= i_ulong arg1, } ret =3D t2h_freebsd_acl(&host_acl, arg3); if (!is_error(ret)) { - ret =3D get_errno(__acl_aclcheck_file(path(p) , arg2, &host_acl)); + ret =3D get_errno(__acl_aclcheck_file(path(p), type, &host_acl)); } unlock_user(p, arg1, 0); =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=1778880381; cv=none; d=zohomail.com; s=zohoarc; b=k4u7jTBvOO/ifJY1QQUW6eUuf+XIuHwbFEZsLGBBp+U2Q9CzjMWlYeE5frw6/XtltgwU4WUq2qtSD6MEnhkOw+2FpCAXIr0dE5oWPdfuPoV1oDdqb4z1WX2KIZVZNLDpc0kuaD2WvR14L/siI1RoQdGRcJS+mSxBFMnp7Aasuyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880381; 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=UKtDoegR296hWUFPVeKD3N8X+wZ1+wnI2qTMFP6ZpMM=; b=HbSLIpb6VsFSphvnD92r9RaQST62hVMYyI+vnmwot6ugWUVGM9g/IrqLxc5YpNvhqjl144MyuNlJdxaYOzkqjKWaPofKyqMgyURcu9qMDOkf1lG2/EXWJ8mCXf8n9xltIRQ7fKh+g2ec7hSbtXDR3AjVnFhUzTB/5KlKXBvwFZI= 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 1778880381832345.6929953735231; Fri, 15 May 2026 14:26:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy7-0003sb-8c; Fri, 15 May 2026 17:21:15 -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 1wNzxj-0002uW-RR for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:52 -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 1wNzxi-00039A-8a for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:51 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7e55b95ba13so176021a34.3 for ; Fri, 15 May 2026 14:20:49 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880049; x=1779484849; 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=UKtDoegR296hWUFPVeKD3N8X+wZ1+wnI2qTMFP6ZpMM=; b=YwEo7LxcGr+DQar7szVN1Xt+o3ncDV7EX/tG7xVgMK7Om55z3sZAnKvsm1S/r+QZln gsBVcwnKqXIzUWGxt2NrvvhZh9djxtJnxz+JY73mj8dh3BS3UPezOgTrCyo7Yut7imwZ Nd+MvN0NIMjGTksqzheUDSI+3J+oymXJYfpwh7mrqg+nAloJayEFFIPWMBtMo9hOyRCx 4Kv2UlqU8i6gIytp1Ng5/6YhN+vsvpDO8c+FETfY0kgl1WxeXmJY01R0PW8dc3uBicUN YdwehjKrQHl5M7jLA//ZWss5h3kiI8JRMhPvVwGMhV5LwcBa/tPlQMqgwM/tmP6oxSUH 3QcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880049; x=1779484849; 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=UKtDoegR296hWUFPVeKD3N8X+wZ1+wnI2qTMFP6ZpMM=; b=FoVKlu2xMM8Ht1HqTK4GCWUPaAq93hRV53O32KDsxPbMxc6wpd6l9d2l5zc4tojgln sZdvTi08rDpRwiSSeuWRd+0dcgU2BOKEiMKXN2RAUWdM5Hxo4mdmTUqRQYcfhVdQJTC3 eFf7wKQeUL4cx96BhBkO1yQ1CRanaayjH0auUecHFn1mDNQryIfPvzbrgHFZXhvtyNu4 +zKHmOSdcYBVVO7fJeu3vfxBFA7NaNjSXPjtRjkMJknSKFof5LIvn/H5/kSIVePPyka5 Ky3NoHd+ZC5huE60DEWUH7j9z6YEpQhOTIYiTwFtG0x7FSWBxNVLxwwfXAWJu7fQxhkI xPTw== X-Gm-Message-State: AOJu0YwRiQNSE6MeISiVdtceIesgEyylt2bZ5iSHnyAX5HgNIKfH10FH rba/JGElra3KLaPDZtC5B0gUtQrTfdVQfSNxV6XbK9bnYv5Ik4M7bXQUXkzztflhiEVsr1gObNn HT64KTCY= X-Gm-Gg: Acq92OE1BmqhYjIMi5wqiuUVBc5KFPYhuPrK66DlOPTiMkNK+gAwGmbBi/HUkNFSByk B3KLC7oCORqvj2yfWPYS8BjcOx3/NFZKwySf8c9UCmsHDjIr8ZsdKEJUu8aZLCVQTJYJoPupM/n OxXhROgIL8qu9REtdmcB1PjG/UDHzLx+XBQV5MnhHjGBlH7iTgRYwZKzWXbm6hJuDhUR20aZ0ey kigZJO6eiDOEuWapr4YEu89d3Clo0no6QYHz4gIooi1Q3dD/m9PiT07yFRxY7gOjpO+HfXOSBV9 ONe3VOxjcddXj6EMEOxDX4gt6LaM5rBChcXHhTXxMG67W3/D2Ldj0dMyrapdcRs+4fCWWPy5yyj gSN7yTbJwTALDbHjCYbLEcsPqF5VSkjEjJMzhy+7c1MpEmngK+huQSDXoCTDUE4O9Jl5dfKiweh KeJiyhTH5ZlG2ETPDpVUqd X-Received: by 2002:a05:6830:4989:b0:7dc:da06:c0f0 with SMTP id 46e09a7af769-7e4ea087f57mr3681690a34.4.1778880048797; Fri, 15 May 2026 14:20:48 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:44 -0600 Subject: [PATCH 45/66] bsd-user: Unlock in h2t_freebsd_ntptimeval MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-45-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=700; i=imp@bsdimp.com; h=from:subject:message-id; bh=ME/cgvxbJzgLPnmEKnWFBKklT0dtyN+EMZjFoeGHenI=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43m5JaWTAkr60WsvxuzKBjA/I9kAa0LqqXgC F8TTT/X5EmJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AGZUD/9pJpUnPH2XbVTMNrlOy0FaDObZ3mih8IOsq199YJ2ibKXEidWO7nE2a1/fNKmbWuS0UqT Wy283vPp5hSziZuyo3jT+bjqgOJEEb9l8HZQkE+WErHPqI2r0XMP+3zCjDDJWki7UpX6ZrAWefL Sy7r7NhdIu8+HwGLimazZ8PzYRk9WeR91N/x/RQkM1Ef/n3cBt5VG3cGqF1kvNuB7REKRdUL7oT Stza0JyxkkswlZKqANCyr8sxh9uV1Z8cN6WoK//10qsywW9ZO2GIScaH0ME1TVMCuPrVMueNzCW +mVLkrpkb2tK5UE57A0MMAktU/2ppiDVCpHcA7QsdYBkRWbDZ7V0CavwlhX6iGwbCmxjMbFHW+n 0ayCiUAQuV6HQHPokNQ9AvyU87IFl3VIWvX50j/PqXZxiG9TL92iBiExngA2wyScm90VOQUB1jU 90pu0S0czE9WPKF8seLnBgMslO5pFL18WPkfrMxqo/x4wDhP+KUIrNAlCabDyGK1c9QvLKAJZ8v 0Rn/e/6Na1g6Ap+PX37UN6fdscbVlOjjlUJsxHKl9MLyGn64YhrMJE7RaBlMYIcM1drztWU6ukT xKcXU2T/QoC8wrHi6uC2R/ycslW+62aJGw6DqCLoajZswkISibtTAfzNM69Hl+4MwuLyyQ0H54I QCmqI8xb+TcWpnQ== 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: 1778880383840158500 We lock the structure, but don't have a matching unlock_struct. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-time.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c index 4333d7d30e..2dba352b2d 100644 --- a/bsd-user/freebsd/os-time.c +++ b/bsd-user/freebsd/os-time.c @@ -153,6 +153,7 @@ abi_long h2t_freebsd_ntptimeval(abi_ulong target_ntv_ad= dr, __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); =20 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=1778880109; cv=none; d=zohomail.com; s=zohoarc; b=nRHVgfUHhe0UrqHtPJtpq5AEcUmGtfbvlUtvLtoulL6XnN9DZ82RDQOkLAjPlh55BdblXUkadwaJQGuIk6Me3eUQb9pgBmRybHdb8lSxd2cu108ndIWjC+oK5dZf1zhJf9CTq7rW1fMK6zTYdORF7b14YxNplSf+IL/qvaKM4Ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880109; 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=2EsJKY6wRKyUAHQyJydxItZiWMuRqA47IYT8gmTrP+8=; b=Cq7SBpS1VpEUVu6NRzNEsJ0MpBul/Sk9xj52rIwYUywU8yxJL9Inm1/851K65QtEihrRN2q0Gby9Hl48PshlYwSxwd5ru/Sq8Sl5Nk3tGwfpriMnXvLEXdSeu+zWQoIjg17g0wN/PIU26D/658aE7vpK37UtsYxd3W16uzZy1SQ= 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 1778880109398268.84041860390573; Fri, 15 May 2026 14:21:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyG-0004hR-LT; Fri, 15 May 2026 17:21:25 -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 1wNzxl-0002vj-W0 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:55 -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 1wNzxj-00039M-UR for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:53 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-479d593a0c3so236875b6e.0 for ; Fri, 15 May 2026 14:20:51 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880050; x=1779484850; 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=2EsJKY6wRKyUAHQyJydxItZiWMuRqA47IYT8gmTrP+8=; b=Y372ZVEmV3/pledt6K2QlfmSEA+OqCvMINFHEyPTB+OWMyegvabxBU2CZkrlRkfO5l TrY2MBz5mKJd9PlNmeamFARwTWncib4WpWQ75wmwlnjzteHoEbVV3C7YcJfp7/zxfmR5 hwZSVlW/uycKa6ncILmSSwYWdDWoj+S7W+GH3T3qk02lNJZe8pnRY/cKB4YHmg32hqF5 gh/tkQq8QAc9WME7bXd2NLznzbwfgciRwvsm3JZl4v2i5HAv8xUT2xF7YAjKsUZMSMIV v7ABjjNcHE9gucUcw+HTMBymIumRvjGJqwsUgDxIqQGG29K5dnvk9pbMvnK9jfsd01Sc xJfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880050; x=1779484850; 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=2EsJKY6wRKyUAHQyJydxItZiWMuRqA47IYT8gmTrP+8=; b=GM3+shzI5vo9VG44aXISVCu2w45xXikvstMXfBow5RPP+FaY5ftLnojDIY/G+/bxJv Dg43YdzfCK3jOCAfvsyuqttf8vGzDSj5ohypJR/5I+wmYS2OLSFiSwF5SykYM8CMZNuJ 8+Id1qD9OW0a1LdedY35THpzMohlV5OdEwLYU2in5pIKKoj4ebGZVSMipLk0gYaWPToj uM9ac+DH9NvZ6wQ1JH/ev+mulnwIoy5OdcjQwd4a6hEaDXuB1NsrMeyDzY8osLrpxpxI HmcjdIBU4xN0OXulBY+H/BiZMj+mmsKsql3ogYv/ooRpYaM9llWRRHYLbYdpQeZth2rP Q4Mg== X-Gm-Message-State: AOJu0YyitI1Q2j27KuOE9xbRdJ/fUqV4E8kCcZkiSppLdOi8UiDXMlaU C76jAHvfbKlekh3HNwYR6O+EMxHJNLALyrsMAU5Tt8MAkHQDlL8EoGe2apLrC2y9NY3wBMTBccC WHwZkY0U= X-Gm-Gg: Acq92OGeUPALQLZBytTMSRI+N3BwxYkcCfYAcvdYxw4qih2jEOjgOJa/pdnq6T0zAsn wVI0kmexHmMRgIkIgFGuMiRyGiQbN/98RaXp5XzGjdzjme6BGMKYHrWi1CytNL8MTjVcfd0aNeb u46DHzWnsYkMPUjQDvIuWYBAshhLNAeLzEYZWcVoycJZ9VylIdTU9sNQqfEqr9zakPT+FMxoLkx /Yps+TxLs3F2RPsqxmjg24RMTvmakFToWlpjwS3gS4KX4AcBvzfSUeA32nGzoYxX8auRS4I+BEt HS/jPgBPKFBMt8FlXl3cLD+XTphZQIaF6P1Vwxa6AK2YAXyY9O/OV6gReQJcGREKQ/CY6CWB9Ya PL7IUjGHl7DrG3HKmM7X+ZOak0Nw68bmpJAFJYpNDVUSt2923maiH9hakWOBl95Eg1KrdSTTXdc wCOFTPE1b7FA== X-Received: by 2002:a05:6808:181e:b0:450:b249:71bb with SMTP id 5614622812f47-482cb927ed6mr4928338b6e.19.1778880050243; Fri, 15 May 2026 14:20:50 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:45 -0600 Subject: [PATCH 46/66] bsd-user: freebsd_umtx_mutex_wake2 fix unlock_user MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-46-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=934; i=imp@bsdimp.com; h=from:subject:message-id; bh=+tJeoK0ng+exvyjMVCcN8K1cXKYqQMT9ULR0VIbAmwA=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43mYYem8x2ZCvbA7/xqzzsyf0DnSxrK+lCIT jNXnbVzTdCJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AHb2D/9qO8P0CZDs//g+O0arEzB1EKhgwO56dSOh1drObpTx53aHM5HURCosF03k70fcX7ZQy/J craBzJ9m8mdg0yoNtDiqR35I2A7m7Pvh8cLpf3hwIMpz8Xp1vwcw9RsvHmrtYrDwpQFKeUt27E6 iU1JKCh9CHkT/WH+GBeoxziZ8MsgznmZ5sR+YgNP1xNL8k8tLsVkijAXU3tBxWWX4xhF1nGyPzb 9iIymDZ0+zmvImNSma/4zvMLKahNSjq4brl3DV3/HlO5IaE61U9lb7ty1rDfPdEyqYJ8pOuIuXT IQmw/twzMRnRDYUxyqGYGjZTAiX8BezCz/g8+XPeqKFMf9halztS2vJMniIDxHe0F+XFUR/IS/C kiOmIQZPC/sVb3f0ClUGxsl2FK1HG/LodRPQTcSbLzV0C91JN2NfAzVmnX9V/P7boXh/rrTOKXd C6rqcWFUPu5Af5F7Qc072GbHc+aLgXCV4d8JlGnnqUOrmVn4RgBBhVfQCYBO4orrZgJV9zxiQu4 Hq9imJDndh1HoJOUrclF2FldCY8V17r3nfT9Kp5uudua6Y2vect9IB16krGraweKDSlPhql6LjY o7vHdmfDqsh6dmnhf2xtUjh7I9IZx7wePwvB56jBjFjfVKcHrguWzZ8inB0uuWnxQxvp11szptA e6u3qoZK8cGdJoA== 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: 1778880109998158500 This should be an unlock_user_struct to match the lock_user_struct. Didn't change the writeback to '1' since the tcmpset_32 writes to target memory and we don't need to write again. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index b91e0d32b0..7c3256a87e 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -474,7 +474,7 @@ abi_long freebsd_umtx_mutex_wake2(abi_ulong target_addr= , uint32_t flags) } pthread_mutex_unlock(&umtx_wait_lck); addr =3D g2h_untagged((uintptr_t)&target_umutex->m_owner); - unlock_user(target_umutex, target_addr, 0); + unlock_user_struct(target_umutex, target_addr, 0); =20 return get_errno(safe__umtx_op(addr, UMTX_OP_WAKE_PRIVATE, 1, NULL, NULL)); --=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=1778880265; cv=none; d=zohomail.com; s=zohoarc; b=b0tV3Pn9w6BYN5H0W56lGcLILArbN6nyGAjwSNAjVttrVJtkPAk0MObvVgniV8JNZ17dE9i5DZGaSuuayCZ2Rzk4FtoZeTQVsFtHn8PfWtljVLfHhiCM8HkjMFSJG2KP7jVzd40DU0bw2Q6Hc2rc9zi47rP7XmqGImjolc/xu8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880265; 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=tYvRaepDtsbFXwl9GsgUjxQ80JPHa+QR0l1FXg4rYR0=; b=n/uC3JK51i0HAOq9jw9bjmlEeI2TXpJIdfXOD1qjIjFwdbeR8GGxWXbHYkyONOhpLQJCjEAzZ8TEH8M48YAftwcWHWL/xp1v3Xe1bDdoqJuvE6ecQP/ucEwc/s5xO77sfBGEzDis5w6xZxSuH7RcaJ5OxBVqfnhGDCBsrkTqRqE= 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 1778880265536719.4243453999287; Fri, 15 May 2026 14:24:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy4-0003bQ-UC; Fri, 15 May 2026 17:21:12 -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 1wNzxo-0002wU-2V for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:59 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxl-00039f-O6 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:54 -0400 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-479fc1fc048so332317b6e.1 for ; Fri, 15 May 2026 14:20:52 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880051; x=1779484851; 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=tYvRaepDtsbFXwl9GsgUjxQ80JPHa+QR0l1FXg4rYR0=; b=AxOQPcscFBu71QXKmbv6YOtE3kvsqMrsUnJx11cKEujCqa9G+OuhD5O1b7C7H/20CW +6x49/HfH8EOzZ7c7UHkPeZMGIwtLKPbuTPXJukgqGAdNs/u3mqOHMowfk45kSpoqrc0 3+KXqGMqaknxI0bM6Hc+4yA89B5AMWXQu5WN6QUnLqk0UwWCujAR3yMaz14P6sTVIFZ8 YZ/VqQyDO3BTX3PGIylmkYG3Od5rP3QECMiXvjfDGVALXnNXR3dJhxqa8c/ZZlQ6q8FC JeyaViBxxQP6WEZ7ZbISu/nCW+fI1Z+O9zItt4HIYUnCkJQozrgjCMc15U6U+x4f6gJ3 1WiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880051; x=1779484851; 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=tYvRaepDtsbFXwl9GsgUjxQ80JPHa+QR0l1FXg4rYR0=; b=WziESFkrr27x24eHfL2Nt5WNBAi2xvz+fycCtNBZjSSTOQrBSgmWxGmCrXGqS5JUAr aTosgore2C3Ex37gaiZAbhd7QT42TkevVa6Ve7Rg2gf2auZ1J6K4RKjMJibvUAVeiYB+ yj/CuQtf1oeQlncdzdYK1t4yYfjUPl/hvWSWm8AEcRu7set1ZWzT1t0fzXUzOJQs+3Ci PnrxGhJtF2xljdf/q7UN9W8zkSOzkLEcRF71jXoCvVfM4Knui96MzWSdq0HGDJYJF0Lm VlgXbzvpESepoe71Z+G5dXZIQM4VfWiJxraznerAXk9FvAkCuY4upMY3ryQZOAOTqMbK MVkA== X-Gm-Message-State: AOJu0YyNY+2HYGK5TDQAKknnvcV3qypsGzijoE+T2De+LEwxvqW2Z8m8 P0fkhgPF6Ry8UzBj/iw6z1XeR2S9RV8RStDPk0/kZqrl8AkMcO95bw57PLqcxOjxPnZmZmil4Fm IGbSIKSU= X-Gm-Gg: Acq92OFrWsXkeQut3zDRJudPHF3JK9YYBpmkaNBf+sQbrrh1LX4xzyJ8zj9YRwZ77xm 8xNKHmrzec8OmrvXTxiN2iuT+LL23fAQe019pQxbV0LZ7VFB2uGd7qD2cS9XDIeLwdftj8GGWkZ 9ZRauDDSo7UZJSpKjAOPj3nWgGJkkvHop//2YMYAKZkrs7PC50mO6/BI16AMVrUMpRrAhTGFlqg Xjyx6nr+LMlu3Tmd8mmMMVjkYTp82oT60jv3uWiETqUaLrWQTwXfrHqj2VlPPnwWRGkl/ldsaWv uIJdTGfrbA2loHZ6zYHpVm3tk52kkPN0S+2jS7lo7K3iCNzfmYO9wpb+mNInSbd4KI+QCyR8vl8 v8Rz/6OKnkLrVgbnfvLgWqomwCbiz4VA0s+2LFLVXJUmbNMSRCbsdRBW+/7fxabyDGmrYyoHoXs HoB/szrd1yVSfUCMSJWmmw X-Received: by 2002:a05:6808:c195:b0:47c:be49:cf74 with SMTP id 5614622812f47-482e572ca95mr3757763b6e.23.1778880051256; Fri, 15 May 2026 14:20:51 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:46 -0600 Subject: [PATCH 47/66] bsd-user: In do_freebsd_thr_new, use unlock_user_struct MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-47-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1206; i=imp@bsdimp.com; h=from:subject:message-id; bh=9UHRe9EHyra8Hq58p66IxlYqg5jJrk8hXeWirOuHoEk=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43mj+NE6Agv5n0YnbGyjL5EeLkTB6+2xRTE8 XX/MsO7Y7GJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AFU+D/9ZSjSXgGRo4BxMZ1ntPideccaRFrT12zg/0Db6PNtrF1ITD5BePsh6gPZrI8I7dQCiM9E 7gbWQKopmUEhA22rh7sq4CggHPHFe7dpEmdzr7ruIPrMdqBdnqltm0tTW7eXQFWOXXxBgG4jqrL cJY648FIVRXkr8KySDuoUpENR24Ux+nnA0DBUkLVuOGWX6OSdKtj/RcuPzceV9pPHhGOZexCqXN hHoLLiCTpQcFK3BAnoJKkJ2pkg6O3mfwAIuM+aEvKmstOmChAuGydeImQZql9UvaO+LLwyf2LBv kfxIOVyDsR5qP735a9y8Uil6CpnsbYqby4padFEjcWGs9AjNHuXcS58SjMn/AFF0QUE1iWjX4Ft NAr+vQO3gQm9k/sj0VHOfGGe70ZFInjmfqFWNLoHEgJf7D2S5QJTgte1mWChDpbEqHwi4A+SFQV DCyl9rWUmXRrUyZKvVuImOxtGOPegLVU+LCB5GkS8kzf+YOywE71SHlALMp8MKKeS07fqa+Zq9y JvncpIntDAKs0+EBvgWjcOn7VoycOnyGxEOou6J6EiFlZY2B0zPC7nU2DztX6eBGCzcxXqeWVV7 DQP4hc4m1GsAt260unl1SNH9++rzvvwMXtWJIaljYZ3GvH2dmiydukbz2h1RiiZb1UWsa1Tyr/Y 4S++LuDTlOZaD5g== 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::22e; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22e.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: 1778880266997158500 Since these were locked with lock_user_struct, unlock them with unlock_user_struct. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index 7c3256a87e..f90f13076f 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -1567,7 +1567,7 @@ abi_long do_freebsd_thr_new(CPUArchState *env, 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(target_param, target_param_addr, 0); + unlock_user_struct(target_param, target_param_addr, 0); =20 thr_self(&info.parent_tid); =20 @@ -1577,7 +1577,7 @@ abi_long do_freebsd_thr_new(CPUArchState *env, } rtp.type =3D tswap16(target_rtp->type); rtp.prio =3D tswap16(target_rtp->prio); - unlock_user(target_rtp, target_rtp_addr, 0); + unlock_user_struct(target_rtp, target_rtp_addr, 0); rtp_ptr =3D &rtp; } else { rtp_ptr =3D NULL; --=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=1778880122; cv=none; d=zohomail.com; s=zohoarc; b=LaqyclABjnrDPnsPYGXPL+4QIVA9V4AW/SOaN4YRWRfdqMLwQfaYEu9F0YGNw41Hjgw7mw4pogy5apowcR7lxUKBmnOgVdu0mAQpUdMnQ+Pbq0/JrcrU77bWADCkkNGuvg5FYeZxoo/O6QaBOtXqk6YQGQ/SfhkAILybUH8gjTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880122; 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=A+5aUwpxsBxmkp0v1KRTDP/3FzgnZ1zbfgxvhFFILBQ=; b=mDnsn7d+puh40ct6e171cCp3teLVzEQAm2F1+H/3Q28vdP97uolZ0pDeP7r8yRI20xeDqvCQiOcNIHLvlWSUQ5i1vL8JPbzt1tObf2K/niWrFgH/8WCkspj1Az6tqWcG/F0BFs4xha1lMgijfAmxSPp4CITSc19Elx4Htdq+Bws= 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 1778880122532819.574371380719; Fri, 15 May 2026 14:22:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy8-00042h-9m; Fri, 15 May 2026 17:21:16 -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 1wNzxo-0002wV-2V for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:59 -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 1wNzxl-00039p-O9 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:54 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7de4a9cb8eeso362111a34.0 for ; Fri, 15 May 2026 14:20:53 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880052; x=1779484852; 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=A+5aUwpxsBxmkp0v1KRTDP/3FzgnZ1zbfgxvhFFILBQ=; b=rEsFsl1PBAzpnzLlBNvw2uCNOInvmBcmSYLQYfZdUZ5DZoye9R9LtXr1axabuWl2nZ KO3UbbMy5C1C/Q29fIVcxFio2ppw2MrD0dRTS42Um1RMJFVC3rC3gv4KW1LBUA6cxBGj U7ocozaY1JRiZIdhKQxGmPNvWSOOEvOmxx/VHW0OU8NEEvlZRWlf/OiCSXDDfYiFUK+e /ZiSccY0NNol3v+iupCpqi3i8TrwtsWxN2UMaVY+9y6+Tt3/nhfvbwnOBipKtHoLpGzL cqFzr9V3TGYPpOh1pzZh7HP+ilBwQn8tsjtwWtOJ5RXfyjvpa5ij3383N2f5tBI418pJ tzcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880052; x=1779484852; 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=A+5aUwpxsBxmkp0v1KRTDP/3FzgnZ1zbfgxvhFFILBQ=; b=A+YM+aLJckvTK51N+gnGHpWNCFQHWxEjVFtCUwu2JY9ZUQ/3y2FWztzPUD+bd3fnTo KWhsc22Pyt5ZpVXsLF3cnz5whSc4t8O/6+l8uQy0dVAPaoD6jERCE/eZTOUciqr98HiP rdEnVdezYcxOTeHCM44mqQoPffYnxH8vB3Jhj62bMrYbd9mEkUZg/C2PPFfTMD/Fcg2Q LSjloy/Rx+S4yS9K5zF3RYIDsDZUqYBFmSCLqYv8cSTeylsTB/60fIjGU/eTBenZ4mM2 uFwhMOH3ZaBKh0mFVz8Orb7/YLCl5LlvosPtq2mhiLd2XV1jhapMIuAKxiGjdfDEC3vY xtkQ== X-Gm-Message-State: AOJu0YyTtM4YMYHa/6POOuWssbg7z5+pu8tWjJd9gBlyImveRQZQXqMb JV5l/fDd5bWmx3W4vQQ2ycNdGjEdrkUpcMT9f9Xmo5lT+A+900QONAX7cMNHwvB6LY76hdDZ6Cg cwsdJEo0= X-Gm-Gg: Acq92OHaCVEdKZ1Mfa/BAUEnfPBFlIrPO5RgamoFFSfJJYzeiXUN6LV0MiGHj3Tp9Qw 4NSjd1SVJxYc7Kv8EV9qB54Zb+9e3g9flxlDIbpCt1xt4yObmeyguUb330MvT3HcC61R7Nc395b QPD7Gk2Kef16DlQuQtSrecmD2mEW+qUBFZ+aZnrpbGZoZy/akPIpMKueHYHfc8wWK4QQIWLgJe3 WAnX52NOOn5BUlmgcpitimNx+NP56qC5VVHQ5XjgkJEZX8Gn2v7n3rk2adv+0OS8PGp5lX73uUV pwrF26SwtX+JG44GQ3Ua+6q5VbsgfUlk1DMmV62jrHf/sL6NlWCCHzoezUyICVBLcKO60Pdi+4G U5wJO7R/VtBlBpjWivDNLZs3fPd6AIcWqkvl2D+WUxInyboNC+P2uTO1lDG01nzI1i+8KeboOvx yWC3WJiUv9HSFGTgAPdOHs X-Received: by 2002:a05:6830:6010:b0:7d7:570b:6800 with SMTP id 46e09a7af769-7e4f2baf0fbmr3889761a34.23.1778880052179; Fri, 15 May 2026 14:20:52 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:47 -0600 Subject: [PATCH 48/66] bsd-user: h2t_freebsd_cmsg should use SCM_TIMEOUT MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-48-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=803; i=imp@bsdimp.com; h=from:subject:message-id; bh=Y7XfArYy0pNn3Hvj3eWUBI8iL0EqWHCP022vp3Eg9FU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43m8Q2jvZypBe0S79pqS7zPzi/6tBKRX9mx5 6LeNyDCJCuJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5gAKCRBsHNEofbAR AC2iD/9iT4nQicK0GSjRS29vwyC21MujYZPYrJ5E77Qp6+eSMC/pKoourZXlp4IudWlYCGXwCaV 51eIX1CGC0xqoJ6xItYZsdAt8uleDL3ad4kjSmPKNqqAzs6rSz+5mz7BT4WwcLqXl9LDVoEQXLE aExyhZvgSA/xblSYMZy25VddD7O1jBG+bs7KsvMF8bGIz5dSS0Ep+s2Gp2vhgMpIkTS20SxrbQT gqNL8LVNGVdmg1qkSiVNzAJnspxOZDKxUYlIIx18a9tXyVr6Qdh6VLEuEcQ2q8T3j0k/lZckDMX TSAoSQINzdFv9qBKbLrD/mTGILiwBHCFRiQPNRRcdz7vFDjGYwtSjKxnGhOE+eXrnuE3MrNYzq3 vduA0Qn31hi/+DhqTvs5PN/ha0KRNHQ5EBBSwwIMW+42V5OfAdC5V+kg5aPGC50i97smlWu6ePF qgWsAHKIywHvNdyu44b+u3rzuKcF5q6IuVyLfvhU33zJzVRCSkA+RFlHQIOCS0VCq/4QsV3ddcI tXfEWP6W4zwBYfrWlPLL5rnMtkfw04X+XH6M5vnAwYoS4jYvmmWvprfL37r5+L8GlQDCu1OfCNd 1OOON3ze9FOJWqCBmmlwu7ze/9l8HhyurmoLFz9bFKOIpBE9Wg+x4tx/oi8TT7smwzVxQHqqhTH jhfPjZGIMshchkA== 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: 1778880124011158500 Logically, this is SCM_TIMEOUT, not SO_TIMEOUT. No change in behavior, however, since these values are the same. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-socket.c b/bsd-user/freebsd/os-socket.c index 543c9c10a6..41e40d2913 100644 --- a/bsd-user/freebsd/os-socket.c +++ b/bsd-user/freebsd/os-socket.c @@ -186,7 +186,7 @@ abi_long h2t_freebsd_cmsg(struct target_msghdr *target_= msgh, } break; } - case SO_TIMESTAMP: + case SCM_TIMESTAMP: { struct timeval *tv =3D (struct timeval *)data; struct target_freebsd_timeval *target_tv =3D --=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=1778880104; cv=none; d=zohomail.com; s=zohoarc; b=aRFU0/I6qYVUcA4t9+cbEahNyyAH1z5QMdRgzsgCf0yfsXiuFBRLRCIsfZ0EH666rSLhprP31AMX2REKEVv2BxFutOjWBWo7GNB6pLm/l/m8G0MBO2zNpfs7AGePTRaoCc+LvLilnFTj1JUGsxtGudD4LwOG5C4WDnn0ZC6e+GU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880104; 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=3OO0Hnh/zKjyFfYuyvc3qo8c9ME9eHPWV3ninOtzGOw=; b=d748HsWXo/Se/xDAz1zv4f80ePk7E90trISMG5ZfViPdSptsj4eXyWQAS+88o9czWz7EXBWa/5iyO4yspuOg0OkImMIg3W1VW2iKJ5Ks5gMJCB7DjVaQsgh60pATTfZaHra0Mx9/qL0Q1z9IUXa4S08xtuOS2kw+33hotxlKADw= 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 1778880104064368.3255736094259; Fri, 15 May 2026 14:21:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy2-0003O3-W4; Fri, 15 May 2026 17:21:11 -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 1wNzxp-0002we-AE for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20: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 1wNzxn-0003A1-P1 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:57 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7dbd23bc684so161034a34.2 for ; Fri, 15 May 2026 14:20:54 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880053; x=1779484853; 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=3OO0Hnh/zKjyFfYuyvc3qo8c9ME9eHPWV3ninOtzGOw=; b=XKYRCKoFam52r2ue7IseqqLMV2dJICPj3SU44pj66jO8ODTUN9GWp4xD5E6lbb4s4M F8aiy822yrWw0eXq5limixwQfvcC1ML34ApC2LTM89/zpyfnAcyIPLhj19druTFbfHan fPAqlBJQAhGsvDWqChSLSiE9UT7TDaQ1ZV4Ch7/B+XBUUkU4sgOHS4GwbS3FXux4Zap5 Xm4xis6vREOYSAEuSIxGHHy8JaXUlnQZ5LEVJmbOhQkdtl/ogHSdLze0PBFlST5z8FPN Dcbi2Enq/XFsP6Fu+tXXpfhixQLmD2YrWakq/DZlCgvKIZGVFsoqnAbu3niuR6UJjKPT s7YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880053; x=1779484853; 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=3OO0Hnh/zKjyFfYuyvc3qo8c9ME9eHPWV3ninOtzGOw=; b=XbCI3+YeuajFlFidC7LyuG33R3sSvAAM8Iqb6VuY09+6y8TIOgbTwOj22+ezcp2S5A pYlnhsMbJR5rCpc9J4lhlMoTSak8ieRHPYIf/BX1ndxEnJ5mXTuSscZZMQQiUNIJOcLP 6MSc6n2sMUZVF1Nz1Qmj8Vu4LVF3hV4RC5ns3IoyMC3PvZW85NZV7gObMtuwyiO5+tHp ENLCipLHkstnFMxHTyun33LuivnknDENBu89ekz5eG5kpcgDbo60t+0322rx7IZ75xJm l2tadIk4dVjzaTg6BWgkDdMsVN+axRE2G1ajhBF1EwLTdbfGdzLMIQU+2d4dF+9bw/5f 1WHQ== X-Gm-Message-State: AOJu0Yw3+Yu65c56737wMGMqp5rtoGXZ9i1oUTqeJ2PHkB/7EWC0FUDp oUGfRiZlwhfe9q0huJJVoM2B4sFz0zkH7Hg0bMNG33E8MaLhP7NpXLqmcRuzIVIWxYkALOTQfJV TzUNqHA0= X-Gm-Gg: Acq92OG1IVzgmGESJzm4w4iinFfCunMMNWgbGR/boQWS78/DSMdJgWUU/axaw5Y6OMm 4jJm0C0jpKDbVtWkAn8wUhSKiE2SYZaNxTbShSBCRzVgUJPiC4OT0Qn4FIWMhluJEgiIdb15yq5 aRxL0OA3bw1H3CQUl6wxSQXQR9yw8CtsBzNBUjO6fHn9NV5m1zKseTUKOIQa5/XajmWrJOCTY8V rzi00ecCDyZBdlz3FKNIWIYag3k2tFlszI10fLwLaAMlCTnTwUVgEAWxkqslc0AYucbEiVQmkYl aXEybbXC2fc5mdnrzFX9z8X16i+W2dr+pgEkCzCqS1ecR7eh/R7ybvGzmYFRIBgbovJovXCDxwi b9XHlVFNbkC1EW8MidlsWfthN84JZuRoJBhn4I25TY2qUmUjKBv5fvdNcdnvwPMrdSR1jIo81ei 53GO7joD5jmckqOHvTbRGJbmaBsnTBFcg= X-Received: by 2002:a05:6830:6d27:b0:7dd:5a21:2246 with SMTP id 46e09a7af769-7e4fa0bdad4mr3976418a34.25.1778880053231; Fri, 15 May 2026 14:20:53 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:48 -0600 Subject: [PATCH 49/66] bsd-user: sendto/recvfrom need + 1 too for addrlen MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-49-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1320; i=imp@bsdimp.com; h=from:subject:message-id; bh=pbDXi5M7FeJTx8g/bOe21hJcf64XImhdah4CYd8ifz0=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43nL+I8U1WS4nxzHOSvJY9Qn5HY9C5BUK29V StxZ3Ce2nmJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR APYVEAC9tRIrw7CIjCkIJb7Ly8LB1/asfEUjGXy8dPJiBfsh9DkS92UX1iJ3rkuyUsZvf5cji2a EHk8HqnTFaLRqDKzog1Lhf1VHMeycxpQQLXYMKkilryajCn7nTtS+fzgoyZf+Hjh4GkkEmuQmAH tAc/3WCmVclAW4VqIJt5+aTJkhj6qpjd1hmpF8UR8gNXPAekDwKZ3Y+WAbjIIbrRp8Y2+dHrkqB ShM6R5AnBuKQaIk4LISfcZ6fJ+s6/B8uRtQYJDl/LSZd0jwAtJNYlSiBeQwRS/4WPma45gVFcr+ f3UYkETyhihvWJbeaRxnjho1Lf9lxqoS9GA4STQDb1i0amM/tMu0kBm0XI4CKthuYzZbcB/l/7B jBeL6KiHr0l7vp9PodZF7YInLqw1zpO35rgo4oQUZ2JaVL2WjTmYn9WmUBS5c6Sz+FBtNVPulH5 yxpww9EcPz+LFWN3RWEHgyFbL81jhSkn8mh29dIegcFbs+cPbtg1XMYeYgZEXgCFW+6fDd6095I T4zeuPXawNZquwZjSsvrOTp4iAepZdcGDmKkpeAtjmh9hDVJ61AlzQUlsCTCRnu3PMb4tNwRMNk D6TvJ1kFyBJlr0b1O3cV3DrtZuY7Ut7A6tHIzB6uWWQ6i6A/s3y8Y6I5k9u/qsX+Pk6NHDZRwSk 7c14beCYOC2MI7w== 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: 1778880105944158500 Since we adjust the length of the addrlen by upto 1 to cope with the off-by-one errors that plague unix domain sockets, we need to add 1 to the length we alloc off the stack to account for this. It's not common to sendto/recvfrom a UNIX domain socket, but it is possible. Signed-off-by: Warner Losh --- bsd-user/bsd-socket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h index 578cc3959d..d85dec59c0 100644 --- a/bsd-user/bsd-socket.h +++ b/bsd-user/bsd-socket.h @@ -198,7 +198,7 @@ static inline abi_long do_bsd_sendto(int fd, abi_ulong = msg, size_t len, host_msg =3D NULL; } if (target_addr) { - saddr =3D alloca(addrlen); + 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); @@ -235,7 +235,7 @@ static inline abi_long do_bsd_recvfrom(int fd, abi_ulon= g msg, size_t len, ret =3D -TARGET_EINVAL; goto fail; } - saddr =3D alloca(addrlen); + saddr =3D alloca(addrlen + 1); ret =3D get_errno(safe_recvfrom(fd, host_msg, len, flags, saddr, &addrlen)); } else { --=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=1778880252; cv=none; d=zohomail.com; s=zohoarc; b=iQNJ3sbghKZv0r9mSa1r9luJHsiZlMhPq4cKoRCm7O7FtCDC/wBURhrzy/g6aFmOdOhCfnbYh2rF1VkSKPS51Pbv4wSiR/XJ62/0PEvZmQmbFnQd8MFPasQ66GWforWruKpyiO0dag1h1nb0gZDkZ/ZJ0N7MQT+HjNGSuSOOj6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880252; 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=RrguVS2mRJ1rnG7tfp8gdtbrhheg6nSgGQTNfMClxT8=; b=g2hCDepGeAGjJwjRFnwAlOClv64NFiKXR4bFv7BkmU8mAHKqWQyLkyaadIVZ+3Zp3L7cR5tV4E41hAO2rWQx3Fqg9BYR0hvM8JOh8kdOEt99blGc+Xy5fpb3wTfFFQ9ZOgSSnnSSaa5t+tADKFkKUeSfAhJvNIDRsL5E0hdsSjA= 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 1778880252338978.1085228258622; Fri, 15 May 2026 14:24:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyH-0004iX-Ur; Fri, 15 May 2026 17:21:26 -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 1wNzxq-0002x5-66 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:01 -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 1wNzxn-0003AA-Qh for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:57 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7dca00c1591so112150a34.3 for ; Fri, 15 May 2026 14:20:55 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880054; x=1779484854; 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=RrguVS2mRJ1rnG7tfp8gdtbrhheg6nSgGQTNfMClxT8=; b=wCzj75BHQzulczpGRkga69GmwDkoeihUr+u6LSJQdvdAwj7h/q+8zEXyFGQrhNI60F 9aYotjecu0aGxGIcmGYDg8tJWgjWncqBN5TWhyYERTSnx5xBOTDcvPuN8ehnJblg/OyR sNGm8QUNy/fAGSU526wHAl2DYcMAfmWxx6ZLanIxdSvRV+Q1G2E6PboMU/QiOko6Pbki v5FqxbVKVIQSy8+kAvMtUsnakS/DqCi9Y0fa1JGH1dlFc0LCp9DrBYB40g0dEW7HPfHt NZRdUG85mueMz9KR2P7GSzHLoAglEufMBuxZLI7A0DpaLPZSfzqIiD/fhcr3lI8TaN1a JZvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880054; x=1779484854; 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=RrguVS2mRJ1rnG7tfp8gdtbrhheg6nSgGQTNfMClxT8=; b=Eb0Y9xpUsktSz61WZ7nBFy1fQAcDLt6x+X2cqp3WzZxQ/Wd8ncDxJhTn4DyHj4cddm npCwkGKO3Wmui4Oq3Qhe/Rhwc+fIf3N5BGI4Ir7PzW2kLVPuaXULePOPRlHKkoGmXrXv y6oEflp8y3inC280b9vYK4iaTVkqIY/o8FxYIWmwTsAh2TKiTXIRCxas5SZXVJJn1PQl N7wduICeFMr8X0gAKtZ4u7IsPx5HEiWubq77pjRA+0Hsp0fbSi1HJG8E7pFCBb/ekmqb uj5K5HLVp8FsBlXMt2SU5oFnmwlriPujuulHuwzy1vlt/t0mEOTgb5xdEuysBSfWjqX3 fvHw== X-Gm-Message-State: AOJu0YwxpMhDGO9qnIoy+5kO3mU3sikCXrMzFr+S+XxNSG83Q5A5tMOW A+3o7gzESkeMhCF46VRtertcDTNUuK5frI92NXYLIcp3dDd2QBcz6Pnj0xNuaj1TOm2o19xz/mT MhrgShOU= X-Gm-Gg: Acq92OHI9/Q11GVpB684W6gMsjaVg+8jOwDWHCFmYQIX/YyVNauIfgAGMomg7s/qh6v 0siy+IlBxUTYmBkMuzpoT2AWZ1B3qm/OLRu65bHbQvbRLlLWC6Dszba6BNgTPJSETtKNEg4upKp 11pMAUQpwm93O5E2xmonKrRceyuwZdewZ6YzScIA7YgnQx1NtQ9fUw9MpI0hjK/0SdAIueA2mvz Kfg4s7HcgbI7WK1C/Cc93edD2avn8SkwPZj4LMv/PeEkLJaVy4Ryw5egQN2bwIk4fNsgtgrLnhm lz0/MzmpZ0s2HKVKLU6dtNsNG0GM61WLFtxm4Shv33vquThOElomid8s3b85BwmAhVW2vuvSZeS iO0JOSly6q0QKtitL8tVd/xaDOCFIEeChx9foBCChVXZX3ojqsIE+PYa8JAHkqHzhFX8mqfMT8r yEamDp5zxOMA== X-Received: by 2002:a05:6830:6614:b0:7d7:d615:3040 with SMTP id 46e09a7af769-7e4f2b865d1mr3961895a34.17.1778880054191; Fri, 15 May 2026 14:20:54 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:49 -0600 Subject: [PATCH 50/66] bsd-user: __acl_aclcheck_file should check t2h_freebsd_acl_type MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-50-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=712; i=imp@bsdimp.com; h=from:subject:message-id; bh=wI5CDqmTpikk9GFJ92lcU8HxCzddz0RdGXIAsa87IRw=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43nHlgD7/d8rgCfFtpO36emrD642/J5QoMeJ k/u31+9Q9mJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR ALZuEADTT83vvQnlxTcSMPWxyCT6qXILFskzM7XZZcdxUDKVbw9Ks76c1oJoRvG9gWus9l/N1R/ 1GRf6wnV7guHFNuwjDAqvetN29JbwL2HuxyOsoOi7fNT9sBeRa/c3M7GEVRHCzNqs6vWQCJRaEZ Rwg58jmZEpErBSvB6FXiWY27cIDb2Wcesw0Svs//2rmK1BmjEjZabOwSApCy5qvPE0dy7vTl/WQ JBKWLIJcKtI7OYU8IQWyA27rx0lAi0efsgiN4WVI5IeHeMwmz3TIpDBIeg5fLdM3bF/rx3nLeYw t74h0SgRhQX+Llmvw5HyM0DW0XWOQbCI1jz3JrK2KtLXLmeQUzwvpRiUPoWXMO538rUEUOZRCfP ZacUJjKt6FUY/iQzzLYNU7LY887daXfsBIGA6sd36W+5jktt7Tur1TstfU3TUNWIk3Fb7A2L+1I eR4wMKYSu67qkoNKJo2a16yAFE8T8WtCkohCYg+FiFbj4rARmGOndec55C9OzuggdGPR92jNHMM Dk6wmJ/7WKVlEzufiz6Jl1gLkMITc2pLO+qM6AUcGcKMdfXkPmsEL7UdvJxJ/T7vTJCLPCuuWPV NFJw2F0LT3IxNutijlrK7OlUwxRU71JrurV4YSHF83cQ/Cjk168xeA55WIlIL5Ar15KpY7MCGTv bflhjvWdA71nOIg== 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: 1778880252900158500 Check the return type of t2h_freebsd_acl_type so we don't use garbage. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-extattr.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h index 0414a2e479..97c0f76559 100644 --- a/bsd-user/freebsd/os-extattr.h +++ b/bsd-user/freebsd/os-extattr.h @@ -407,6 +407,9 @@ static inline abi_long do_freebsd__acl_aclcheck_file(ab= i_ulong arg1, acl_type_t type; =20 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; --=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=1778880246; cv=none; d=zohomail.com; s=zohoarc; b=Asgvyt/9w6AgRvfoXZc6c4Df2ZE0aJkkgGQ4nCyxRWgOGKJePH5h/6y/zQCVcsEmJZugvtKSz/SWZk1aucB1ApLtrbmlsiFcTuwbhJ40z6PfDeameVL0T/NRlItODdfmBNm6+1T8+pNLi4NsMbBdzcO+Xb4lHyOv9OshYi3gD+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880246; 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=Njs7wIR5DF4xPBft8B1295A2iuXF4T9ZCX8i6CxKtW4=; b=mszZABjIrKBGF1WBt0v3052W4TPxbaU5HxR0FcWhcViDby8zy76zMKiS1TVx3sGH3Za5PO68YxhNsw7OZAb80verW+REQyA3HpHx+Ddq6stvfvdx8JrWFLHxhawnscrkHMcgJcTs1eDqDRnEylqunucJK5jds//6fWD7wDWHoRo= 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 1778880246035562.6837189214765; Fri, 15 May 2026 14:24:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy5-0003fR-Cc; Fri, 15 May 2026 17:21: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 1wNzxq-0002x6-AH for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:01 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxo-0003AG-SK for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:58 -0400 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7dbec19732eso372351a34.3 for ; Fri, 15 May 2026 14:20:56 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880055; x=1779484855; 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=Njs7wIR5DF4xPBft8B1295A2iuXF4T9ZCX8i6CxKtW4=; b=z3rB3exUWDO3/hBABDIYgKcOvpgK+2sBakckOJwQC6uDKHmxh3c3qt189eAgCEezd4 fjMg89qDRUkJvR8dw6zBT9UG9b7nBK6L+X+bjBbiehNXl9/HfqNDHyAHfmRj2undXNWC 4rO0yr8bIcep2G8nU2C8dGG2V2pxsu0M9pZQrwiC+VLUWR6m+zw7qA/ThERIuhzhBHMq ecfH2HyjiGSsPhBUbnM4hS3017EltQKNHQriWskOZs/I2ktcc3H/rMPQ1nH3nApzGvWm LAgKyvQeVvoRIfdsavmPPE+gtus9p9lYXj+7Liof4EBzmEW+j17thNKnbc8/G2zEsBIG ielw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880055; x=1779484855; 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=Njs7wIR5DF4xPBft8B1295A2iuXF4T9ZCX8i6CxKtW4=; b=VbAgMa5hkVs2PLkD8nQ59DZPlWIe9bhbdW4+DtqvY1yaqTY74MiaCo6kau9fAFnjqT RT2iqNNZdwjXfmtSKQlNUoUbhrh7aFyT0n4OtIV4oU5p91njHW0RGZwSTAJA+lquH3mC dBzZa0HXg/SKPMdmfgUEm7MQWGwumwqfyUeMQLUgihO0Y7dENzlQXUBDxfE4rXLoP6MX bVBaT+5A7FRBpuuHY47gDXikIctIfT3YrjYGMeDJ/RVhG2tWqV+uXbnKqlHZ4+QFNtYm HOLwCO+6LfyICd/U2F0AVQhvjGCoqqZCSQU55rMGg0mdh7CkaDd4wYf4qzYrXHo5MOvC pw3Q== X-Gm-Message-State: AOJu0YwHPcCmmD6xOUdXEm6lPZMzqItLkHlOO/lKcHMah5O3v04NMAuI 2uqIYQ7CPDkQ6GuWf0Bqgv1pRRAWcXMaM+dJ70JNxZ1JxItYUdkA4XaT0Wacik6i18hlgmWh+7b 73eXNStE= X-Gm-Gg: Acq92OHC0QB7so4uZRMs8MRKigexoUPKqxRwgoOIRMD/METQdSamzB1gkOE1TMHycEe Kc2ROOseN1+DkmvopIUfLM07PMZjPLvVLCZvqwRoqgtztUs1N5uMZPV1VLAmG8vPwL961WyWEtF lrcPJ5AvAVPAKl3Peitaj4UPE2rlpO1rTevyLlnBBEV7j88+CODyG15XatrW14oPR3ZkY+HbJWU MOW/kCFORLEseUFZaUyh/zE2q2jMTxxSIwgY4JZOalYggHKvjOoyZglBYWeQtd5bGvq9qz/2irw InD7Jv/Yylp9VwCjKJD449S4JL2gD8Rlxl/kaK8O3olYLpHRSPM6E5Wze3clGiiSsY+XkzKqEbm LgwIFVXL+oWiuTuNJomVgQQ/iLwCxW7/3j3jvnKWLlNyhwDmzLhFNr1x6anyeRWhmGT67eu7ETU RbxB3WE/WXTw/DLHZ/2o9e X-Received: by 2002:a05:6830:4489:b0:7dc:d601:a69 with SMTP id 46e09a7af769-7e4f2b8e71emr4250453a34.20.1778880055286; Fri, 15 May 2026 14:20:55 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:50 -0600 Subject: [PATCH 51/66] bsd-user: do_freebsd_ppoll: unlock target_pfds in error paths MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-51-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1028; i=imp@bsdimp.com; h=from:subject:message-id; bh=Reco8f6NIkhhdCqPoh1VTSSeLM9+lRdTbFAd7ff2l9A=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43njWFKLYP180TJ+rCVtnC+0AfWCQoWbgTBV b0OzMMIcZiJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR AHSGEACRQWYyNKuOvK73K1udWVfm2u0knjSIoBqx0hnxZaaqAGagCMpaZBJYD9Azx5+63Q2c3f5 Q58Hi+5nlHY7Jrtwl/L7gTPrf1PPE5o9xVejoNVwpvj9qCoFnryxU8NrTjOrd6CEiyTnlZHunQm bT17cNe7MdMZ6/0oIYnZ9AeSX3C/opd/zG29MVzQGt4KVkv6IGZY/LGnf9Z4lgPz3Y90Pr3g9nP cRCXRIAYXvns01mlhTBbmz1Lik0sugPIeqVP88vSudiwwAOXKc71NDV/FFLn2oTyzpDkCAJctFf aSGCHHAXehR6NwyclfGWZLUDL2uo6Bba8H43bSLGWeeTRSofzy0O/l3gAe5xrqyEoj+ZU52BbEc qs2CTZigr+ukaJ5l/uGBFqGveYdLcvw4zkxC/sP/Q16Uqz0J2iTE41nRSL3YYYfIHRliE9VsBwo Kz2lu0ZZNZWbca5SxQrd6LrKvowLq5V+0g/8DOibFJJeFz7oL4L0sQz/Zcg9Bm0vYx4gi+jxr5G XIosB0DjwQbioPqKupmcJrXNgKcj7BYIhHldbVu0zwTBxsnS/IZQT5i0jrEaWYR2OjdI0YKc54r 12PfESuQazYulxf5LxQChTdqMHGqWXAAl4U8kZ5lu14mvPnwKGkSqA7+zlfMGa5fdsP49X+N2LX 4TnU6LXwERB0m8w== 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::334; envelope-from=imp@bsdimp.com; helo=mail-ot1-x334.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: 1778880246948158500 Signed-off-by: Warner Losh --- bsd-user/freebsd/os-time.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index d838994742..ed075b7df4 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -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); --=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=1778880347; cv=none; d=zohomail.com; s=zohoarc; b=HYG8BY97SefZogRBHchcmY3e06sGA8/I684IGxx3i/iTUm6k99v8Wxe0pUIEYanpBR8A36j+WE+bsMDwWPVi4Bf10/iYSqTuVYv67rMJYhwtyPQxVFbHL7PASGUAq6ezPM5O/+z/DVW0Qi5tH8waOHkkRw3boOz5yyXamuSkdK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880347; 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=yEnwcLeGpg8+Aatds6AxT6Eb+Y85spWjquA4JTnuWfQ=; b=Un3Thy1s5RBHmL8TXKw+xUj+/8aHMnlB6gcoYInBRFzoN3Z7EEjYFg9GtaOAAIgZFbi5AuZBwy8/po0V/ydt/QXySjg0dnvvhamMDhQbWbD5rEzq/cRRDF5dLUiuY2lnyyU5iKEp43bLsu5nUOCGDZSw1vRrFK7UDj/k0f183m0= 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 1778880347165580.8342691020594; Fri, 15 May 2026 14:25:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy4-0003WS-6v; Fri, 15 May 2026 17:21:12 -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 1wNzxq-0002ym-QI for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:01 -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 1wNzxp-0003AV-Ef for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:58 -0400 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7de431da8fbso321506a34.1 for ; Fri, 15 May 2026 14:20:57 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880056; x=1779484856; 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=yEnwcLeGpg8+Aatds6AxT6Eb+Y85spWjquA4JTnuWfQ=; b=U/H/Lgs+0o4Gf9cKuGeNco8OAELVVIlL6dRlYBZUvhbHarhg9GUgh8htoDJ6Vf2JkS yMocwKhc4KVF8c/NxMbK48DTCJ7LASsJmDNPq6FuLEYnTMfFExwjU5oIuUarvfxosSdb EAdFzAHzSthnuJ2KvTu+IxHI3hU82ng+qo5hPXCyxKQVWgaYp3THTKgIxCO+A2S0U675 TkTLn9NsihrrN5rrmiS0u9CEfCKCBnwfGfZ6UE+1JBIWtSZz4c1+6fg52Oii2fWM4/hP QQCy5Aihb4nDg4RzgDaaODtV4CtwVh5Ezvg+9QeuUubrIc1ry+2TME3E6NB9UHHKOr3N HjvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880056; x=1779484856; 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=yEnwcLeGpg8+Aatds6AxT6Eb+Y85spWjquA4JTnuWfQ=; b=JS7vL3xGG9Q9h+1GqLNPS1aMKPU0PAsZWHGZzelut9teysM1eWdHwyogLy3hsBNSKp M0pmE6npBxLMtW9XfLfuPFNSdKobKQo022QVbAqGTdvB5Vs2+B+m/+VznA+Dt+ksEL9x h1zHuEzRFWBxiB2egW8UM3JFc5jWDFZCtOO4ukUFQHPPgbNYc54+/iNbKMpaq3uTdQL2 QWaBoimhF2f1zfGYnBJtxvRkdi2rle8FltHvP6zQrqgblSeqyJ0h6VTW3iTPkRazM5OX xyLfcvkSzdcCH2xa3dUJBDhp5ObJceRXMK+Gw2wGDWl++N86SEXZEUHkktYoHQNPu6dJ 8tHg== X-Gm-Message-State: AOJu0Ywbvsirmie8QM+H1XS5SXljQ+oMJcfRLQPUPbnxqm3VMgLYIP6P vLH9jLn7FV0tPBGgsuoc/QdK9JXHtDfPOXb5cqiIiEoJbgYCmZfy8NiUgHDSXl3KcxA/oAfUT5m dMo2l4gg= X-Gm-Gg: Acq92OGhFcFPj2zdW0LhJDkvFKHmKOMmpxbyK/LO8yAk+6qpfpuXGgpYWO55orMhGU1 6YRCLdpEc7hySAhzfRZWNYVdEHLRCDGocyZxMm1khCYbyJ0XhBXwnbUNkK87LGKXyGTm01vg7ah wX4TihhpJcDrYWxurkYcqTrUWtNB/Aj/18zUHddmzIUaV8iu4X0EprnewMtEakdOe1TsqIU+BR4 dKFH7wxURgkbXWYetvk66VqYDKiDTPhimmH4NdyYt4/ok61IKlq1rgenti+5S7mp8RkAPcjZ4XN AafMiAl4DA2X+bADOTa6//ah8cCFYz20A/mbtX93g6d4kj6QrS5LNgAshIqPwsOxHqInF45qSfB 9Agl0E5wQY0hySYiQlHhKtYbdKZ0p9LWRzn10DiJf2lGg1uuoOvWdj/ks5Z6lZyV4l3sJwEFKVs Ilmh2jBKpg8w== X-Received: by 2002:a05:6830:81d7:b0:7dd:e032:3ce5 with SMTP id 46e09a7af769-7e4f2bce60amr3752255a34.17.1778880055978; Fri, 15 May 2026 14:20:55 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:51 -0600 Subject: [PATCH 52/66] bsd-user: Return -TARGET_EINVAL rather than EINVAL MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-52-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1187; i=imp@bsdimp.com; h=from:subject:message-id; bh=ZAOx7TZKzDpoWv9sI4ywL/Z4sDbvUZIM2czCevWXdMU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43nZjWQhM5Zq+ViU269WZMKY50NbaN7oC1TS tyUWJCku2mJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR AAxpD/9avKwc12mD7pmLumVBjEuxlSgsBYXqFnYP6gOC3zPqoyqv0JQJC23BJ4q60g3jH70+hZ1 BhaPzdbLCIg3VC+N47fEF1VzzIk3tCVtHvV0/bE7ITPtCP0SOb8BVeRhO+JbhbpTwAhwdZDveyo 5yMcEceO/PlIOj7RaGJegmDAaXdCdWGyYrwW6qU3ot9NIGePq5nKXwCQVYvaRXTZTMo7UuyX91/ lgFa8M/HBjaywN77PaHKVZuIspV+XtlnCdDW0WWavA8+GHo9YJfWV3SsTiD2KDbtG+ndJ07bfYn n8k8ot54rqsZ6vSFVqi94ybQVYdLbY25iecYvYxWWAnprzIj7V79iRT/Nzelq2Mb9PkKq7U81vh OjCgOGJLy8/P0o9WIS5nYtGCgiq95rpwrO6rWI2+sLeAy/6pPvY9ERTSkpuP1S4JFfaM5FAUBy1 XjXRNqoHa2Tw2JDpsYC78xGH6f4tMBskIR6zZ6AbrR8hE8vcrBGptY0uXD14RCW22FTxc0PyAFj yB4Tyh5//z1PGdr5nRVuX/k/34Hy5jp/7ikPBUL8sh/MA40gW7LWKsSwVkTLMODSXkCzPrwGjs5 I6jiNbpkfXRqM3ORSdkG1+RXQ1+M0PbNwqLPwDm5gdMcWGXWnCYmMavdeIGBrY39MZW6pPxJOdL Gp2hAcZhUSEyHJQ== 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: 1778880347557158500 The convention here is to return negative target errnos. Plus fix minor whitespace diffs. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-syscall.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index f1a49ae423..c8f88efc6f 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -1589,19 +1589,18 @@ static abi_long freebsd_syscall(CPUArchState *env, = int num, abi_long arg1, break; #endif case TARGET_FREEBSD_NR_kenv: - ret =3D do_freebsd_kenv(arg1, arg2, arg3, arg4); - break; + ret =3D do_freebsd_kenv(arg1, arg2, arg3, arg4); + break; =20 /* XXX */ case TARGET_FREEBSD_NR_cap_rights_limit: case TARGET_FREEBSD_NR_cap_ioctls_limit: case TARGET_FREEBSD_NR_cap_fcntls_limit: - ret =3D EINVAL; - break; + ret =3D -TARGET_EINVAL; + break; case TARGET_FREEBSD_NR_cap_enter: - ret =3D 0; - break; - + ret =3D 0; + break; =20 default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); --=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=1778880347; cv=none; d=zohomail.com; s=zohoarc; b=PIoh/LEBc8zuQumo961lPr6O7S+eK5F3BhF9C902zvmXMoFs/ZjJWdqRAwj53owSbEUzl17ZaKkfsS5gQTE8hXuLSZYBb6EuUWUZ3DGqL08B/e1js6uuIcpCoQe2b2UW7wzzaSa0ZB3eYbU94nBbQwRhk5mahqWfczV3lAv9k5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880347; 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=gFqYuCOagyvuZh2S2MgIc7F7ETVXOjL3dAQdh4ur94g=; b=GS9+J+hPDakkbjfTC+hB3D7s5kUn2qr4xqqsrskquIAS2gai0xBomxKBl+vM1sGranS3vo906qz/L2WSfHImK27ROfHixNLgCBGf38Ybun1zUpUBMDkiFDOpr50Tc4Uwzyhbw2Fyw1EOwYCXecMh8GC23dmgfOFn9bZkkLNkg9s= 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 1778880347641393.60526204735095; Fri, 15 May 2026 14:25:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy6-0003mC-DD; Fri, 15 May 2026 17:21:14 -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 1wNzxr-0002z0-P7 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:01 -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 1wNzxq-0003Ay-8Z for qemu-devel@nongnu.org; Fri, 15 May 2026 17:20:59 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7dea1272943so204332a34.0 for ; Fri, 15 May 2026 14:20:57 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880057; x=1779484857; 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=gFqYuCOagyvuZh2S2MgIc7F7ETVXOjL3dAQdh4ur94g=; b=zmU2k7YKHZEAMVVrb8g0cSQZk1cR66CovpLa8lxNODqBtA3k33EyO2A8P8gJXvhg61 vhA+JCk48k8sx+GC68RumsB6cqMzVngpF1oMX17Yt/yI79tSPFaI31OroOc823XSLUaM acsFHkoNPLDTTxfgHPFEiaphmBMGGqd0irLB1/nEC0ICRDmS4a5Gp2PCSNb9iZoJ5rHp aGBcksSpbfpyN4d1bMZ570OqiaRNV9TURAnxTEhhTWBtk8QYq/RRwybpBSeFcrSkTGEP f58AAPO4B7pr1xyyI1fBC8EtKDZoOeYI1BvpiSCCU0KH7Uyca5lYFWALsn/1jPp+7Xwz Nqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880057; x=1779484857; 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=gFqYuCOagyvuZh2S2MgIc7F7ETVXOjL3dAQdh4ur94g=; b=CSK3o4lmcy6At0qAEmCVG7z0i8heONAGvIWJWUeLO/TyWwH3QjAbFciRSeDqLx1RA8 6BzaIbe50MvIz/d8TbLRT4QKqHrPr5LLs3hN5MRzd+Rclwpb3KttNhdWKq/0GdEEbHFT NiD58FPHHbEaaZWij0mz22X9xDNpHYOh06SqqfebZqBRjBDwWnNvPkWt+IUkR6xJE3GQ pK93zjF1LAePoHtCtfiECr5pdc4QmctEH5Up9aNRaewFwV56Xlo9HMGWSihjeRIb/fBd tBP7ePzXO5nK9qg9WLd8pD1kqOyNIPezEqSMEa5X04IQIoyfwMAHJU8ziZjQZS9FaPPu v4gQ== X-Gm-Message-State: AOJu0Yzu7Zzsfo0cxvG/O08lMRpnE39zNM0zLfpttWXg/QLDSlHJhPVe aDApy/KUZjDysabz93n0SwySx5xXXYdRibWa575qHdh/l/MSFOZvdTEebLt1frse7gd4FQJTnSE DBYD1Ehs= X-Gm-Gg: Acq92OEyWTmUhwXgjnCIEdkIOiOxCJIW2btIGNi2Zre5TbDofRoQIC8+JKbyqIzJaOv Q9Z9KQwF80O3VSUsP7/ubibYRzl248btKY3kLmH2LoeyQI4CTL0J5rHsdK1l2rsc57uPKfOO1WI FJHj8oIo0OoDi3V3CtCWIJ20IjP2TuawPH7MkwW+o7TwFL57621it7YXcfWE0bD20sxDdJCOfut HCO9TWghwAr7n0m9Cm4AqJpRVNF5BpJUpdQ4qaPovqnl9jEK6hKoGDva/WAGmX3G8pHHb/tB96K YXMq0TvPk3fcIUEmCeDkTMBcwpkxWtHBZLLLYnRhtfj2rkF7fE9APpz7zCfYpwCloRMgQsgkLv8 GJLJuN6xUE3uMrgzC9OW/Js3XXmfaclGm8M/OyTwmzVoPCh4RRgLC+GLvzZnDKghXazI8L4SFYz M9v9tMdevXow== X-Received: by 2002:a05:6830:6119:b0:7db:a8b7:c565 with SMTP id 46e09a7af769-7e4f2ba838fmr3518293a34.20.1778880057040; Fri, 15 May 2026 14:20:57 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:52 -0600 Subject: [PATCH 53/66] bsd-user: t2h_freebsd_cmsg use host not target values MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-53-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=879; i=imp@bsdimp.com; h=from:subject:message-id; bh=SpBKG0tv+Wg5C/eSskf9s7B8l9J2QHCroTQkYqI7CPo=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43nW4OyvH5ai85fVB6a46/BrDMTj6kvapFNx 8MrO3z7v4CJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR AGUQD/9U+AM+CtF2R1apArL1HcvG37DhtZdJpKUr6PFlEUzEUdrLB4BgRoRtFRoJsfXJ+IHEEuw S7315FUDPFuRbdJWNYcG/NLDWe4HExaeY0ImJgYC4r4Ywo6q8lmagD5D2pAiNwW3uZIj/QWdc1m FJqF8gGLRMfk9endqi7l4hZZE8yMXUtyYfIrf+i1I0xMFkMICrlFcrd19JjczKHs7fY/xCrd+9Q Sz5btjhf3K7wGpeDKOHwO4+on3r4J1SAzqVijSE+V7qd9IXCVOh6DpOMaN2Na+TtSRCtalWrJu+ 0weVXWVTzwhyZL0Tm6PtVpLIhCN5NAVkEESS6eW7RRwDq8VjMWcR9nu8C0TsT+xyB67pgkvy3yK lkcX+Ebv66OBY1j8ov/MI6BTffake6QUoSZaDjuQGZ0tUpC9MUeGC+mH/SIRBh2ZvP+H32t9gys bzhbEOAJWl3tVskmXQvcvn08F/AQGM1lqPjkF1a6oNCgue45ZiuwLOsKLULM5BxhuG1wQXBJ+mx im+R08lJy5vgYkKSyoCmS0Fjpl2nkib5o/3xS9E2KbS9AotmxGy44nkf0NLM9fYksbOyW0cf5jc Mr6G1XrUCDakHgbBbqBnzkpvTl1PxtTlmlC6VxBA9w77svta7zwgE1mGxliSq4gMxtGv/pApugl YbZOFjooEtqdZVA== 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: 1778880349534158500 At this point, we've converted to host values, so use SOL_SOCKET instead. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-socket.c b/bsd-user/freebsd/os-socket.c index 41e40d2913..968929c2fd 100644 --- a/bsd-user/freebsd/os-socket.c +++ b/bsd-user/freebsd/os-socket.c @@ -72,7 +72,7 @@ abi_long t2h_freebsd_cmsg(struct msghdr *msgh, for (i =3D 0; i < numfds; i++) { __get_user(fd[i], target_fd + i); } - } else if ((cmsg->cmsg_level =3D=3D TARGET_SOL_SOCKET) && + } 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 */ --=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=1778880375; cv=none; d=zohomail.com; s=zohoarc; b=BFNKxLlzriQBrgFBPZN7s6/jArHiYCTLQVt5fTMQp3rL1tuTDg96xkvuhZ34moKFIHb3ZWtZbOlW5BOeZozbIRDGCBBT8OtQ9xQoUd5xs/bVw7XuhXZCjhAwxbmz0Wo/kAgo8gXpIEOGQEY4qry8f44mGifamOufKWFwZj5AG7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880375; 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=juQfj3VTOQN20k/nloCMS30VhzLzx4/oq0LQ6H/kJJs=; b=BmyycydP83voCsZzw/AP+rIhaZHvqzdqic6KAbDPGDW/Ml5d3vZaJEfvheaUyQDOQvmKoNP4jjIgMX4YAPE122ZT4ZWPZ6JWCy4FZsmYk+mx0REbo97hNKKneNw0Svw0s2FAUoFv6P1iXrIU9M017JX+MV6Bj9FroybcoDagGsQ= 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 1778880375229424.6622303624547; Fri, 15 May 2026 14:26:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy4-0003cl-Vw; Fri, 15 May 2026 17:21: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 1wNzxs-00034r-TY for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:01 -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 1wNzxr-0003BM-2b for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:00 -0400 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-48270f099d5so376622b6e.0 for ; Fri, 15 May 2026 14:20:58 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880058; x=1779484858; 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=juQfj3VTOQN20k/nloCMS30VhzLzx4/oq0LQ6H/kJJs=; b=Uesg+miGXWDm+kY7Hy+1iLzQaXRVXIxsnEg7DVv2oE4SdALG/SkNDy6BrcvVQodby4 ZKv1CaMqLGXPiQ2/59jQ1xkXIJDof09x75j6cWKt9DV1sBz4nLCJr+WGn4mP9W3acCok WBVEVzqN11PWH9VVB5n2SE+44somhj8JzWakYCOhZAjtdrB1huRSlhmSRhyD/4ASWlBI ClcyweQJuuBtskVBPI48tAF78CtaHqN9Ce3HPML2MqGKG7YzMsP6ccudhUsSJ9Opd7Vo KMkzRivvOAlgw+ix6kp60EBnZhRKYrgnBdacomAciQpyZ+DGgtvdPgvA17fXyXqvsMnJ 0lrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880058; x=1779484858; 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=juQfj3VTOQN20k/nloCMS30VhzLzx4/oq0LQ6H/kJJs=; b=RAOdMMkFiewnyAgtre0Ei64qdD5vD7E8I/KhFtP7CzwIftYo1ORXjPVmv4zsRusX1N 3Lncz1nQSkaipiO8pYgZakdSFuo+uoP6N0GZU3q7xNYSavByphiQS3PTm5tjLcj0GNnV wQl53zAcfLgg+Aow/HvpeG+ez1h8TiSZ3fI5C+x9/T2S8ref9yjsHjhaUzQb+1I8z8Jw LE2AsWqCFypA1kjSZOXPZR983OVWas65MiJzUvejc5sizOIM6gF4OIDSJ7tB3rrVD0wU TjyDZ9xOkLTYqubEbh3eVu3Q5iY2lxjyzfbtxX2MGtm4g5zLxOo3FPlji7NxA9+Bt4I3 C/3w== X-Gm-Message-State: AOJu0YzkfCPj2DYB553/Qu29TQxM7jo24R0NlTX1kQfjMgQPZylKAvEM SsIaxWnIaUNkscxiS8KEOrP8vLpJxx6F5mZqDmRAFXJtNRQaF94iD+JMZXU7FGNu607M96ECO5O gde8N9D0= X-Gm-Gg: Acq92OFAy8Hg8VUuJngX4MI/JZ0rD0k4/bLuRvvl041sQqz9e/uEx/WWpE4KkXsgoRz hAbGCD3QDYmCzHHz9Y+Eury+bB8O0LGyLl/F5MVdXS94WrbO+JtHTBSBqiYs41uBDyxKSZf/n9S /p+Kg0iwln/Zwo6pmDXf1Ia+2BhnNHxEy5yp2ljhfLAg8giqgH1Umj6ftOODIE/9ENpqd9wm2r7 N8rG8aooQINQGfQBMWaHuXCB0XysE/W8dIDv0IY7aTc3m0If3vUGixbW3CImyjK3vL6i/ffWeK5 laTFFmgoj8w0Mjq790DPclmyVSfDO/pGnbZNK/qPvjwrBDT2vehlnfVPEWEpAkEikUcQQ0uAg9Y z+z0UfKjW+/c5TJWYtvAV3X9qn6AKj51hHlkU/W4TnkFdYi6S/1x174DXkaj/VbqN2bAgH+q4g5 TzPoI45nwV1w== X-Received: by 2002:a05:6808:1705:b0:47b:c2a2:1c79 with SMTP id 5614622812f47-482e55c66b0mr3426607b6e.1.1778880058013; Fri, 15 May 2026 14:20:58 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:53 -0600 Subject: [PATCH 54/66] bsd-user: Validate acl_maxcnt MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-54-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1275; i=imp@bsdimp.com; h=from:subject:message-id; bh=ya5y+Jk/LAQ+I8jHspERUJwk2JeKRe9Gy4dMj6ZOljU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43nN/pYKvTfwuFp7WVYgj3SBh3FQ7CoSSyQo v5C2ogrSv2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR AIB+D/96HG4/R7jBKpcmm+FfcE6c9ryvVpfrd8DePqMEBfgx/zIcqy0dpGEJMYyRxFZsgs9racz ZZRbhqnOSMhk+XV+jTQh02yIQNJS9Rbkl0mXlEyk2hhBmUMlPh1ckV6J15pr4ZoeJrZEmKt6uhQ K/MXjjs/PpQ3ef8hRtVS2Q5pyxq2LDKcq1TH25S2qSmFuc/OeJQxrGLju5Kl3ZoRGCER4GF1Tzc efWOSSzmxzVkDqpS1VpQK7MAtX7qPXCUVgJ2g1EoCt9FKd7okXeXR8j+DlUQCuM18ItKOR1OsRy uwL1DWGJd7kN7q6Ok0iLvKtcagBR1zlZUX2/Ae7EPwCddCFRdSMueKyh6Ef+ulyyyS2FFLfTbVP ql4HSAxx8XIzZBuQz2AJzGYtfOyJvDJpjMe3KoOGITO8eDA+cqRWQN06WjGebJz6CyMcef7s9dQ 2ZgS99X51H8LduUgTlwrg5Q7Nqnuy1XZp2qhZj0mIfseBH+Z2gJOxsytgUMmgb/7D+zJj571fUB A1qGx8fFj5N8q31w6TGJ+ZzaVbVwMcJx8XORGKh5WRK6S5WxYi933b22P6drqTPbpearNZ2+Luy onQZGjV55MhM/b+IVBKGBi0kODCTU7JkDzCuAHGdOCZjCiP4GwyGr/EoDv+sWXytMEuUE4tRMYc 2e3n4DkjRJ2ohhQ== 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: 1778880375809158500 Make sure that acl_maxcnt is <=3D ACL_MAX_ENTRIES. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-extattr.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c index a30d513655..0f0c7123dd 100644 --- a/bsd-user/freebsd/os-extattr.c +++ b/bsd-user/freebsd/os-extattr.c @@ -29,6 +29,11 @@ abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong= target_addr) __get_user(host_acl->acl_maxcnt, &target_acl->acl_maxcnt); __get_user(host_acl->acl_cnt, &target_acl->acl_cnt); =20 + 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); @@ -51,6 +56,10 @@ abi_long h2t_freebsd_acl(abi_ulong target_addr, struct a= cl *host_acl) uint32_t i; struct target_freebsd_acl *target_acl; =20 + 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; } --=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=1778880266; cv=none; d=zohomail.com; s=zohoarc; b=LVOZSxKDHgyipwGtgIlZutC9FGu2mctsZMhi53ciHTfD0m7Oq/WHUF/jcXmw8HiEvlj75/mvTiJkaH7ejdsDJ6TMOhEqSKV3j3mBbqyuf6fiWHBLH/fMv/1huQrdzv71Rmb8tQ2VUGX8yjKnEszkAkEaCSSNNVedIuf9q4pVFF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880266; 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=9E1Cs+9YzSmm3WBGPknJAKNKqM2g2pEPkRw+0Ns5p+Q=; b=dLqzPCPuAoOmaC92lVYsTgi1ZE4qJYB5ASi9H8tXVMz3EguiLZMi/Qro75+BL42JUZzSrI9INCD3VP7Tfp9+J/jRsZt5168cHgBFzzL+glmgv3Wlh8rPX5CVEvOKuWVI+C+k2+xMGY9JnfK5AY1IlQxmlWUbjBeSLPhCTOwmmlY= 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 1778880266541765.5324109421313; Fri, 15 May 2026 14:24:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyA-0004Pr-Ls; Fri, 15 May 2026 17:21: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 1wNzxu-00035m-1t for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:03 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxs-0003Ba-JI for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:01 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-47c7b282e21so153826b6e.1 for ; Fri, 15 May 2026 14:21:00 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880059; x=1779484859; 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=9E1Cs+9YzSmm3WBGPknJAKNKqM2g2pEPkRw+0Ns5p+Q=; b=0reIoROFTTFTFQvMn7nqG+5xUWnHOVB8HYtio+c+HKX0RfXyAC+ryHgdBHTtelQrWx ur48QNYWayyFPNB82BkZaAtyJ6/FLJHDlGLtGc9WZk2aj+R3+YL+LlLh51q3roKHUBeg c63F/bJ661m4xPV0IkMPbWuygbGpjVLHjWb7bv25cBN4xI2iWzpxVwtOY37maxy6vWrk z2nedAzhpvd7M117eCRTcp4KZi6bfrdVK83UG5rDAz0oNJCy0teiRls3/jfwqo+Wi4xN ADnPCIkAFql8Fe6zyEaHXpdZlyAacW7o3g1Mfy+2O6wyWPLpdmTKw+zN2mD9DnzTLhFZ brtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880059; x=1779484859; 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=9E1Cs+9YzSmm3WBGPknJAKNKqM2g2pEPkRw+0Ns5p+Q=; b=AwPjuFsZ2XZS7SXrJq2CvR3AI7VeIsacLoSUp0UbkMaRPXJWMkqcU/PSl9S0ASf0j0 ymP1BuKKt4FenEuMe5SqfKjgdLyX6MoN6kIiveX46fX5j3pWXXic5UQHGRpQwQQssl46 1QQjGuT7Ly7RnsKGaE3x8FGDzUMUN9GzmJArR0bEnJjuu8OlQp9aYBpkUGPV5/7tamPt 73Jg79aeyRA7txxEuYlrgR2JS3CXgZUirBWZVcKwFDPIv5ZDrrjMtKA2NQCw59p++N0l z5qbwMqZsayYDRGdOigs5Ia4JPbR08WLLF4xhOh3E6gDnLB0w+DH81wJTyvl26P3aIYq 0irQ== X-Gm-Message-State: AOJu0YyiJKmS3luVk7QWLCecaEQ4wxWUJhb3QYCcYTnQm3DxoBjDe1FQ UD/R8vogPvzatc5AxS1IyAlt8Z+dt1ucP2frUWojS4ZrVn9pyFuMGYI1Ct6C5RzAYgDKd499AP1 HCHfmlG4= X-Gm-Gg: Acq92OEDMkxuyKN9fosUXSY7Lfa4pNdrkoV+hdnCKer+HiZSgjK713iiDMFgvQ490iz LOddS+mT9Lqkzkqk7M1x7pwKT6/ErixB2uRh8uRkQKWJzbLOG4M40ST7m74gFPzsmY9tfZd4fH1 v8wnAwqwriUsGt1ITi4Y7QyrQ+Dxjla3h2cIHKtVjkuxSNpg87Env7ccXtb23L07cFf331JfnkJ zqP/TLY8v1Bi5XDFndPqWr447CB89jQHG6jHATttzpBjCEaamAUgYKe3IbdM0ENYpJU53G8HR8V TcGeV2dobQAv+7fhNoqo5zLvyQUBadp6doz4ORxyooMBBeP2YzedLfjtGjatRlisq34ICXH3HAw cHGJ8xpZnOJLpIDtxxp64OH1cDo/TFTOUbReqxJh8mg4BfHGi6pPUFFQfpjSopfhpwJT43/Mtdt i5XwAFd8IqQg== X-Received: by 2002:a05:6808:c298:b0:479:d4b5:c19c with SMTP id 5614622812f47-482e564d3d5mr3578659b6e.1.1778880059091; Fri, 15 May 2026 14:20:59 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:54 -0600 Subject: [PATCH 55/66] bsd-user: Convert TARGET_SO_SNDLOWAT to SO_SNDLOWAT not SO_RCVLOWAT MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-55-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=626; i=imp@bsdimp.com; h=from:subject:message-id; bh=xgPDcJukIu9icYY+USe9Z7bonFomfnsBoCz8xcyKIKg=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43nI8XhFT5vgdi3nswjUpOBfRZXRYIJQM0Sr gjjMKN3ljOJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR AFRED/9Bs+/MkkxCScNhLQsA64tpgSZ54RxEr+y8nLXGGE8F1tXblL+WU9dZOKJSsz4gh4NXIXg dTSeqGLn22RTM8JJBQLczzssg3J6BeqJb7uOrcMz+bQG1WYtSp5dScsm9BVSZMhz9Z75pP6LGI/ HSVFCUqLg/f26/6ltYmRxga+yNHLs2XvUGtTnhcVdhJN8Pya+PakabSOoYpZpXykbqHofFiCbhw L0EsSlpZbaykUrXqKRnQukCYP77701z79qgQWhedgrZhHBAGnRBjjm+0HyOKlE5L3Ln9wnOa5lm rP+fyDFiZAkdMbIDFChg0t3qcm10X2Fu31ZFRXn1rorRTNJvQFhKYKnoYsc+FSPq5oXgsR/ungg apPful+4OfMrY/2NQIOVbzlwAw1+oSsTCvzoC4m/VzPgfkUvr8gkBmlrWSfKyL3exXr+CODjbTu 9v1HAZmJqNDf/4nVAui4zuZbMxyTmRIyZND5orFqyb6/FeReFyu8uA8r0PvcLvAjOwp1M7upWjy 1Uf14ipcOBjFTI8dVnLRiPW6MwbAmLoJe6MPW2Ad4wu5d3M4DsOiG1A7DRQqugXH3mSHSE8lEA2 H22rS6neRp00cz5kheruaVVl9FMWSCZKwo8MyltESxwGyxZ6Wdo/8VkEqu8ZcQRqOVFZG81GrPY P8cWY6GLEPgq8kQ== 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::22f; envelope-from=imp@bsdimp.com; helo=mail-oi1-x22f.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: 1778880267016158500 Signed-off-by: Warner Losh --- bsd-user/freebsd/os-socket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-socket.h b/bsd-user/freebsd/os-socket.h index 05c22f2f0c..01ef5912db 100644 --- a/bsd-user/freebsd/os-socket.h +++ b/bsd-user/freebsd/os-socket.h @@ -331,7 +331,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: --=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=1778880161; cv=none; d=zohomail.com; s=zohoarc; b=Z7myU4ZE+MG14Uww3aBt4TX7sBY2QTrHIkTAlLFE4wcXZsYSo3j+dJQegxSbHNBZARohsUI2rvGwEt73O/1AQllEY+ieo3W1cFQYAKgD7YGxsnwNeOLG7QIzGwFB4nU6HpqpHJyFF/1jPn22NBer0pXOCQdH9ab3BPnD95XnRyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880161; 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=PW08fDBi+WkYVgPnXuwlMTIGJ/Vvzyv0nYTxtfJ8C20=; b=chMvTYLHDPjn6xm1IjEiuWEiWx3dHUw4xfQM3FGLzR3s40gZ/rZ8bssgqPAAczv9YKINKaldfCx08h0PP/NGX3gJBqoBSPHV+q6Ljj0UuktC0YGrVEZTr1SMk3FWONwNU/n6hFlfssIGgdtZu5iTf1qpYhLrFoSwLh7A/kJY0bM= 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 1778880161540834.9698699259037; Fri, 15 May 2026 14:22:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyB-0004WY-MT; Fri, 15 May 2026 17:21:19 -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 1wNzxw-00037Z-FN for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:05 -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 1wNzxu-0003Bk-RF for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:04 -0400 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-7de7c57b52cso298918a34.3 for ; Fri, 15 May 2026 14:21:01 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880061; x=1779484861; 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=PW08fDBi+WkYVgPnXuwlMTIGJ/Vvzyv0nYTxtfJ8C20=; b=Swl6MDtfshtRovw4+hrujajurPjPShFfAX1Ha9m5IYfQHfaVfFPmGYlLdMorsG1hOG H/xDV4oIoZL6vw+0Xyo8uYhRNv3TDN/lB2KkfDos/3ymquP7idNu1B7UAF806DhufWM9 mRYdnofzXD9I3FRinLZ7949ZgfPf9DuUws0MnigOIz2iKQQzwtWOmVQUsf+0V50hCVQg JHP1yHn/Me31mqcTKQ3Xz5V4z7cfiGpvBWDTg8edh0YUJY3+EYooHERXkgzhAMlJCuTC Uzlnzmk3rBawuyD/1p2/gT1pwK/5QF16h211GR8ndAPWC8ilYLzCgRsNWeb/SH+IBVtd kmHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880061; x=1779484861; 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=PW08fDBi+WkYVgPnXuwlMTIGJ/Vvzyv0nYTxtfJ8C20=; b=PO6/bfrU0sCjKw3aogaU0yqR9MJJV6Nn59ImYJfMtVkO6CXY2aqZgPa0vyNfJ3ORc4 8deBgM4Gu02ihaR4gcl5Ei4XaCRyvDqYNJQx0LAqM0WPjUco3uFJxrX9OfV9FicDulCo 0wB9TGZTQ2hHP9Ed/IasMie6Yo44uHm8gk8+P5wAJJhoaFUphKP4Gfd5iFZo3zGODyBP XkF4sHByN4vSBIqfx/Sz+dTcFiCr+g09uiu//DxdJJ7LBju0PYNIzS9xJHMwgxEKmFEg JcSzI0YtjwBfUpY9NScdz/6CCe9jUo2j0tGK2RVZyuBwDQsRMjHA/7JHMK4VMqsZBvQI MI0g== X-Gm-Message-State: AOJu0YxAZ5dmy1JbOqH0NCOfLJc8HeVU/6WcOlRPziN3YVkYbvTNcF5p 6dnJFul4LMDTC/xidpLfTm32xyFJ3Z/KT8pEQ3H79wm3230Zm1OeiCevrfk5V6tDJIQYjS5JGGz gVWfuaSg= X-Gm-Gg: Acq92OEA/JWrTd5FHwm+Xrxx4J43yd4So/cM92g/6f4C/2CIQ6cP8PuaHg9jsECHOB2 Fc6yZnfKqpNzH0Q4yhvWISViC2SsZPABUbCcsMVP3X5ql1cCnfWA8xpxRt4gejMAMGG7S/uzN6Y 7phy1vNKnDFn1GPQMXwy2enCjhh1Kyw92d0qDLwwYvEAjSfwABWiTv5kDXLRwPlKKYFkQuspzy8 8r9dASFPaXdeE6ASUlaJBxnqz2EuGucRnxOJvSqs4oKLGTPhDa0wXBBHfTogv9fGMJDnIMzP9oS hJEY+MnlScuxLHRwqMAJu/H1vs++wWIRF2ehIe5czxeIHZt+2jiBgR9Mm/U2Du1AZw6Ik+cbWte 6408x0CmhCcL3mWb8srdJU6SB7KxaQnT/ZGKy/Vdgp/wxPK/RyxDU99zoz79908ltSWmlU9xpkr 9WStUnlsAEn6abYIDVdCvM X-Received: by 2002:a05:6830:3812:b0:7e4:230:96ca with SMTP id 46e09a7af769-7e4fa05a5bfmr4300228a34.21.1778880060493; Fri, 15 May 2026 14:21:00 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:55 -0600 Subject: [PATCH 56/66] bsd-user: os-time.c -- Fix copy in time conversion rotuines MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-56-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=4164; i=imp@bsdimp.com; h=from:subject:message-id; bh=UpHDOK/W2Mty/CuHJEzgqpBYAYvdVYEYL6hNdUT39t8=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43ndrohkmdIAfupQvp+GJpKjY0urHnIFqn5N QI8kad4DNGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN5wAKCRBsHNEofbAR AFR3D/49CXgFQuxUxgdc6c3v2Zboqd/prqJRCoayAEb7pE3KC9W07s82OjD3aN2HWZcUZx+KgXb 6GrPBM5EtQ3uni0C43VRvyn4zQbXdpTUbL8uNkrB0tHITbb3DYVeVCa2cdFarR6SKSSguimxO6x bKWlEqMmsrsipc7qvIMHasyDZQE7hlwcX/K5Ax7Kb5W6MzI812Z6mWjIa3yUPuZO9IJMs1mLLBt 3SDuqLAlnHMWkONliIHDkuZewUmgT38F8rPmtkgojEsz0Tye5u7gYeVj4goVmu5UhsPuyw1bFLO 3A4aTi3iOUxJHk+/8VcMFn2iLl373SslMfeLOee4oGOVy3gEnVEiLXNsdoZ2uBsOHHDMfN8l5Rx /I+asLW1WWsUHlAfeIWMbMt4y4X0D/e6xADeDcAXMfWPiyjS1jIde3A5z0Mo2Nfv61djlKwU7qW VSAvmA6o6kY8fcA9XtDnRMQI/9DW6/tSEA55wyDXFcGiWgB3l6JsuDFv5DBHLO5b2YerEEV3Pns JakdsFIom1/FzAANtlZiloK2KkVqNEU8/NQS5dEcSAlBrgMk5rt3H+Xrlj49VBsoH3JwnlKgRuv 2utI0VFrUB/p4fQbUfJiwhEFGzlGM/sP2LNkvUFPnLjXq7GDlX2kAIvH7F0fkIzLMnjKTl0gb63 k676Kwvts0KtV6w== 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: 1778880162419158500 Many of these time conversion routines either don't copy back or don't copy in when they should (for reads) or vice versa for writes. Correct them. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-time.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c index 2dba352b2d..5b7c05ceb6 100644 --- a/bsd-user/freebsd/os-time.c +++ b/bsd-user/freebsd/os-time.c @@ -24,12 +24,12 @@ abi_long t2h_freebsd_timeval(struct timeval *tv, abi_ul= ong target_tv_addr) { struct target_freebsd_timeval *target_tv; =20 - if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 0)) { + 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, 1); + unlock_user_struct(target_tv, target_tv_addr, 0); =20 return 0; } @@ -52,12 +52,12 @@ abi_long t2h_freebsd_timespec(struct timespec *ts, abi_= ulong target_ts_addr) { struct target_freebsd_timespec *target_ts; =20 - if (!lock_user_struct(VERIFY_READ, target_ts, target_ts_addr, 0)) { + 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, 1); + unlock_user_struct(target_ts, target_ts_addr, 0); =20 return 0; } @@ -91,7 +91,7 @@ abi_long t2h_freebsd_umtx_time(abi_ulong target_ut_addr, struct target_freebsd__umtx_time *target_ut; struct _umtx_time *ut =3D (struct _umtx_time *)host_t; =20 - if (!lock_user_struct(VERIFY_READ, target_ut, target_ut_addr, 0)) { + 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))= ) { @@ -99,7 +99,7 @@ abi_long t2h_freebsd_umtx_time(abi_ulong target_ut_addr, } __get_user(ut->_flags, &target_ut->_flags); __get_user(ut->_clockid, &target_ut->_clockid); - unlock_user_struct(target_ut, target_ut_addr, 1); + unlock_user_struct(target_ut, target_ut_addr, 0); =20 if (target_ut_size > sizeof(struct target_freebsd__umtx_time)) { *host_tsz =3D sizeof(struct _umtx_time) + sizeof(struct timesp= ec); @@ -115,7 +115,7 @@ abi_long t2h_freebsd_timex(struct timex *host_tx, abi_u= long target_tx_addr) { struct target_freebsd_timex *target_tx; =20 - if (!lock_user_struct(VERIFY_READ, target_tx, target_tx_addr, 0)) { + if (!lock_user_struct(VERIFY_READ, target_tx, target_tx_addr, 1)) { return -TARGET_EFAULT; } __get_user(host_tx->modes, &target_tx->modes); @@ -134,7 +134,7 @@ abi_long t2h_freebsd_timex(struct timex *host_tx, abi_u= long target_tx_addr) __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, 1); + unlock_user_struct(target_tx, target_tx_addr, 0); =20 return 0; } @@ -274,7 +274,7 @@ abi_long target_to_host_itimerspec(struct itimerspec *h= ost_itspec, 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); =20 - unlock_user_struct(target_itspec, target_addr, 1); + unlock_user_struct(target_itspec, target_addr, 0); return 0; } =20 @@ -293,7 +293,7 @@ abi_long host_to_target_itimerspec(abi_ulong target_add= r, 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= ); =20 - unlock_user_struct(target_itspec, target_addr, 0); + unlock_user_struct(target_itspec, target_addr, 1); return 0; } =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=1778880118; cv=none; d=zohomail.com; s=zohoarc; b=e7NDum53Rb1GYPjg+fTcFS6wgpTORw8bU1AgHTjzuadadsHiys7mnJzzEgSwrLb0YZcqLjt1TQKgMdTZqxHy0zg9RRvvqTjW8SdR7WlU1KOYiPe3btUZsWCZ93IKIJNsqZIKIngyQpVWtQLgB27N5xnCSwff7IFrNlj5S99Qb0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880118; 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=Hea3vfuymH/462A29VI3zQPB/i83Cle/iCROOOOr29c=; b=IM8iRiN7m1wpL3NtoY3qRHxCSvVyKIfeqAWlmOe9WwiUgFe2teVUE7ISN+bGfnURseqItKhhzlD3Zr3X5OI0qxgkV+1uSk08XUJAItrb5fMSte5D9CcsvahoC2ZUt+4JdzrlBjjQYSWkmhA9EUYsT9FrJ+tY0GGJnt6dvThRRBM= 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 1778880118858740.0402434539219; Fri, 15 May 2026 14:21:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyB-0004Te-6D; Fri, 15 May 2026 17:21:19 -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 1wNzxw-00037Y-E2 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:05 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxv-0003C3-16 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:04 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7e568ab0bc5so344789a34.0 for ; Fri, 15 May 2026 14:21:02 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880061; x=1779484861; 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=Hea3vfuymH/462A29VI3zQPB/i83Cle/iCROOOOr29c=; b=p3HoEDHmmDO361R1HzaNWnQbsKaYc6oY6EIxC6eNuRXVuE0smpcJWLV8hUW2P93CgM orYUqW5UseS+88GTRz/YePr/3+Gn71FedOVWn1Jl2D9EH+wEw84yQ68jJBoji3u1WTz8 cp4SWzIRBV+FthG31t79U77G8jaAj2ED0/k1R43htjFS5Z659OWK4pZhsiu8lhMR/SSf PieGIcm0inQY8B6yFjH5S+VKIiI2QJXy0PlS7bpHJFEs8WR75plWHDlbTP4peiPsWw8L 1yaupjppb0a4tTIzqOvomfVs+VEaHRcxyERQk8rDMaxcGybX9gvVP4NfBsLpo7HOHha1 YbHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880061; x=1779484861; 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=Hea3vfuymH/462A29VI3zQPB/i83Cle/iCROOOOr29c=; b=ACLK6kIzNye/v1zEBxF6BVMU4e17YqkDfrBd02hZgf8Y1OX1O8YhuXCiAFbT9vxlV5 Da1+1ewhi4MAmxS1k5iYwnw7XjVwpaOt0BiAyu6uy11lONmVSEchHttGeVNMn+bWTG/r Menv2Sul4Q5lKhBg5TOnCChYyg6fOuV8CxIir9h503gH3wLD4PMnyjwB/1+U2XseDBvG hAxZvR7DcFlUNSrecGMUd4TKyS6CBnmr7/jS23feeCHNF3LJ7PxVe/UrpG3JQoduwBRj Cx/zlitrU+5uvf5AGk/9iFbq/atFg1E3SNandkHwgzwdDbZU1jTSZvSI8O30xd1luc53 3Gew== X-Gm-Message-State: AOJu0Yznpb2XZEMo6y1WD8LGU5tYmTb189nv3kchUINynLGTr8O68fj6 EkMFbNThuweSUMCURlSjSnhxKw0JPWMFprH+46juiiDrkUP7aaMmdrobZusn5TZtre8Wfs9Cz36 l8EKWt40= X-Gm-Gg: Acq92OEiqa4oz7OJcrPuQ/yHTWHm9QVSurthIIn9Pdwes7+3jv5H2SINTjtzRSXxPAp FAs7GZ5n2GHnWahCHXSB5V7/f4hrR6DbW0+BxKWZ5eAMOGruzEBscwb24tXKxpmueJxHrwPsEmW qm21xDNCQXKeXJ696DxIXSsp+w/ZnHvjZRj8O3EQQOAuHhppz/TMJx4BLDqcUf8PglSfHPoqh25 wQ8ZM0/yzCIRuavhy9nv4papclEEAMfE8EPz8SzNGqR/Z+lPkO26lXmXY58s2lSAm5S1X1E9OMP zKfpPAOEzkxK0xstJy+B9YPW4pHNM/Rpv/1j9t1cgvoEZ+AKqNLdFPD2n48pPqSAm6lPMEhmdfx 98eAQbrj5R4uWyvmUhNKer8gIg9/v6BL+57RmsW/g+45h1v/u5wBLrYX7JeLHnuXJbFh3altRFe aJkkHawjRbFA== X-Received: by 2002:a05:6830:631b:b0:7d7:dcbb:280b with SMTP id 46e09a7af769-7e49a881a10mr3653087a34.1.1778880061635; Fri, 15 May 2026 14:21:01 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:56 -0600 Subject: [PATCH 57/66] bsd-user: Fix gettimeofday's writeback to tz MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-57-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1558; i=imp@bsdimp.com; h=from:subject:message-id; bh=CzoBqHHHLiKb7y0UDPvs+hHkuyOVl6iTOtVPzpPOIR8=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43owb0bd8qTlHP6YXUvvZhXtyv59sxcMg3Zh hGt2o6/mBaJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR AOoDD/sGvKuqJ11DHTberZCoR1566Koa2KnBOLJWV2PDgFiTFUm3A14Zr6fdKvn07WyS9dCwt0D ZQTuEuxdibEV/0lQfkEjx79qQos9VmBgbMoxf/OL94vpSY+5kw5iZrBN1g1WQIRnzYVqd3V3/kT Gn2ooX1TekbvtW7F07kHCMNxoVSAnJB/JwSIlz40jrw0hmTMXkywOYIGbNAV2i8NSXZcYg+oKmk zj5Oq4ZJalI5UQl2ZH2ZTdyBczj1Hvwd5megkhuO1X4UsSlQlpEfMq8ov3Wwhj+wJvvxBy6t9gq W2m9uGQlYN0oh9ldC+maCM3hXzzRkdmrP9CfkhJ2C7OZrCBl3Uri2J71TrxJDhFmhXEgeRtxqDO vCMr6NgZg8W2nJOo/ta53fThNXNCDwBZuAD5lvxx/cTv234h+BAGllQuT7zMkYvsYRdrdQvEEmv texIMatZ4tPNE01YDCSkV+yJwbVWGjr16Kl2v5oii0N4j86hkkHt6KtkjNFXPCOocw+/JoLipVd CrG/y/R1xTrgSeHJbt+qboFnRiyv/xXsEKOj+W1XvjGDZRiGoySuOE0eFyXrc3pFEWfTjNBIEri RZU1YSorKEB4bpU5lmCaA5ac1pttpduEn3aMwk7Cj6jxAt35e5hrhrIAKguUwOM1MdJarOGjqKo DI2BZno4PfItgmw== 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::330; envelope-from=imp@bsdimp.com; helo=mail-ot1-x330.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: 1778880120003158500 While TZ normally is NULL, and we normally write back 0's, we still should write back rather than read it for gettimeofday. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-time.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index ed075b7df4..29436997ce 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; --=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=1778880133; cv=none; d=zohomail.com; s=zohoarc; b=llOxV7apP6p6MV3cv+xtkBsKh3qqQYA7Vzm/mIOS0X9BHrS3Mfz204AlHzqaPA3m1m1KfHYvGgJaVPBXg0eo+nxaYr5/QqMEJT+E3si/3mdkiBqfGClrKpGWgZVi+QXoZUPRF0hUDBUuW0Xn1cl5MpzOp/0i4qvSG6EA7261eRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880133; 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=MkDCvLx1YmIMhnQzW256KXrvrqxkaXCRad8HV/Ubdis=; b=JqRulzJDU04Q+ME9EOPIdT85Z4ap88wr7craCL+o0ZwN/hCdNmoAl2I/V5glpwxVz4yosaBwhatHe9mIrCU9XgSFECny7NFiKRnDV17iImNyQr89u0BxP/ua8bCRTngTpsuYQk1ay6DewQcfXHuWi0hNXeOyEfygatZCX+mlvQI= 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 1778880133220615.0901847407497; Fri, 15 May 2026 14:22:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyJ-0004nH-Q0; Fri, 15 May 2026 17:21: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 1wNzxx-00039q-Pm for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:07 -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 1wNzxv-0003C8-Rk for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:05 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7dbec19732eso372478a34.3 for ; Fri, 15 May 2026 14:21:03 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880063; x=1779484863; 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=MkDCvLx1YmIMhnQzW256KXrvrqxkaXCRad8HV/Ubdis=; b=OApDRZnIeGGl9uTUvuy/HDiCGMIz5RVeIV2bhItDov+iKmRg99r8Csd0nk7G/ST3Ds ZtDE8ifLcL6qrVDhex5To27VSXmGc6NPeIrT9FEJ3JhtDMeJCAxo/xUVPoFBHhLZRaKP ckSYRjNj3aRPBtYdJQ+5SIXDuiAfqgse+lHQhb+WtD5alyxy39OJ/Ti+9TGrBAPyiMuP 4JXiJPZbNSmPPFMry6q/IJElWO4z/VjUhIUDdfssowQd0KKLAYnSyyOnLqPnFjbZqLKv CHzEvVa8fTJCzLjSKq4mRVyKB1O32SOw6wghz04vnltNTGaCc/PsJFz05RObfFFmVMR4 SfpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880063; x=1779484863; 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=MkDCvLx1YmIMhnQzW256KXrvrqxkaXCRad8HV/Ubdis=; b=b/eGy0AeGHJiDRzbLr7it6Yb6kGivY9xJQGlq/amalyq25un9UiAzM/Z6VH0SYyJPl NPzkl0pMYaM8niGUN0sLPxtrYgbZhK438PLssdIeAoZ17wt9ng4narNb8vaUY/+qRvw6 ExYvfg1q1IuEGhDIDunvL0BmwHfhXGQ/0dWxTonBadKwMqqYcetsM00F+hZeZdnC+am9 u/3qJUh4DHtX/8dNY2ZMh+FdehQwYEmOMXF+XUBW5UK2EzYA/LyTE08olva8NTHVCpkM Fjf7Sga/WG/vZJ5M6Bi/PWhmjF8yqfUEgznwCNV1p1jhCVmN9O2bSLnAsVlOnALfa1Hg MH7g== X-Gm-Message-State: AOJu0YyUpTtmutNgVOgyfJUsUyS0qLweJXquL6uprB4JAUSO3t1Zwx5z 5TLFHFtBK+E6bMKN/s+pmpgCv4rJReKja1aRoJVaGRtuvJg19VXlsg3ceIvGGi2ZgHIgG1Cwu4z yDfh649M= X-Gm-Gg: Acq92OGg9VdfCGsavQMycU1e+vOACogtKlMTV5/1t/fph/lcgMO/C2eThSvJ7/eCNSr qu240ct3NknygU0/O/sYvdqN9aazC78D0x/t8FP39iqn35RSDgwN/sRL5CnrS0+s2M4LrQIL41D ZvVhPVB1BrV5JMHB9K0sz3teGSR7GuOT6ieIMlgcAossvHthHyWBuixz2XY4nIyB6I+peuC8mf+ skvvJjC1nseBAlmbbJy82gtUcj+pZ1MEocRTYIshP4VRnk3N7rvaBumyPpkc0Eib/NWRtC7E5Aj Xcz0nbYSzxLyrb8aouKI8v+1e9UargE1ITX9uqtwwO67zpY76o0+ZJrqPo6lrb4OYo0FKhPZRpt o5OFlToyul2FUj8E/RgU65isnW3UuDZqqBx9XHzgvLPr6hORs/ujWr6fqtJVhMCyrYpdaJl+9Zr Jbd2ozJkkwtg== X-Received: by 2002:a05:6830:4990:b0:7dc:e37b:b5d3 with SMTP id 46e09a7af769-7e4ea057345mr4035114a34.7.1778880062726; Fri, 15 May 2026 14:21:02 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:57 -0600 Subject: [PATCH 58/66] bsd-user: settimeofday should copy the data in, but not out MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-58-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1080; i=imp@bsdimp.com; h=from:subject:message-id; bh=hqBMQ4tUXP5fH65qKhCXQAlD1x+TbgD7xpnPUEQvdAU=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43oTSszvYrCcDoy5A6G1XaRh0krgL8xZjAM6 BWYhEGMSISJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR ALllEADcwMDccFeTUZg20NSSkxjIBtBbJPqDnJNFxYW2QthmSFlkSm5PkmVVEzdrHjLq/9/x9oL aIX7sg/XsHui39ehs6ZuAzULkBg1YAg5IrPglvePUWKiNm2qKONB4C+QxAhkA2ZIqcZf/1SroPi 8L9ledT7DU6blXPHmPEq8cn71SLlIhP9tZ7FK8P5GIF1IdluFUl+oBTdrRaSgLcRqIGR3fAwY8S HptbrIETbUU7RRgbwKYYZzJL4RHAGRyaJzfc1YkcuEidbWaYKoRasbBpxZDy3FCeZ4+3TBEuTtl TbVexNDZCKnay9ujGzCmshYwDD5Jr6ZFjV2PUyEpk90HoqaiR1VBM6/Q/0mLRs1+e5xXGJGWUMw zdnEHY1ARsC2YQDPZF8OvFENi4tPXWJFnM0QUJdOrRLhbcGOk9MSg7W6NxS3FR68DtZfOiFyXCW jQ3H6SyWv9cM8ZUt1gNvGni9GuvuARnR3xbitB9fKtOUDO4Hk7dhgKGL71K7NaQXlr/7ehqqX48 UINR6/R3CKXd3SxOTnBzKi2oG2GKcuEtGAMdKzmclzHBiK1N27Wm/NCYEg73suBdpz8lti4NzJv FzOTOslcTIde3LSJsxTnUy1JdMk41qFeWxs58QEpMz3SzlZKsFbE3T6FsoBLTPzIJLhjL8CRQJt 3vgphBeDXowjIwA== 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: 1778880134110158500 Make sure that we copy in on lock() and don't copy back out on unlock(). Signed-off-by: Warner Losh --- bsd-user/freebsd/os-time.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h index 29436997ce..ec379b6927 100644 --- a/bsd-user/freebsd/os-time.h +++ b/bsd-user/freebsd/os-time.h @@ -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; --=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=1778880134; cv=none; d=zohomail.com; s=zohoarc; b=Q5SdbAozkR8qBJkO4Y2og1x6wR1CsMYIk0c3vxtG6L3bjYRcwtLVsxlMeytDXJnyZAHY4RtTAdKBDebmBnSAt86YEH0aukjOR6j6YUD/GS28eEfibuPa/yzipG7+tt1qN057/ssxat4Mx4FJYYKV3z94uvp25YE39QY4NHMiCFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880134; 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=402MI+eMAC2JN+aTXLkZ84wCkhgwaRFbSZi0tBBQDsQ=; b=TkWfCqPil0HPFWb68tes15+5WdoncVZxfriCZm6bnJny5/HhvbHCCWm+9mIzbStztyU1pdr4lxj3WlAbv1MxXKhEvUDsnNXJMUf9QEE40cNfmAt7Hv8TjTfIGu8XIm2YjVun3sSPwk8kS/fMZenEXi9hlsbklCkI70Gy7wA9oPY= 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 1778880134924508.2328185621726; Fri, 15 May 2026 14:22:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy8-000482-Tm; Fri, 15 May 2026 17:21:16 -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 1wNzxy-0003AT-QH for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:07 -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 1wNzxx-0003CT-Ay for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:06 -0400 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7dea20cf21aso363765a34.1 for ; Fri, 15 May 2026 14:21:04 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880064; x=1779484864; 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=402MI+eMAC2JN+aTXLkZ84wCkhgwaRFbSZi0tBBQDsQ=; b=ma/45IM1TgM8WMhRUyihsTgVjnCMSDTXYCBQ3FQ/V7hysxCS8GdZr/pczm/8ic0VNz 5cK0k9GP1CGka7DkKwZuGjcMmp0owkADdxEf6lRQbxjC/jvCrM6vs6TKdUqy2OObWNcv mC8jNUkqVb+fnGkt1V5hITvf7G6R44qZrNDp0msdT/8w94UsP7ufBM3XvFuHRaHuQU8Q hq33ebbnj5gJ3a8wVl9YzwTQiT+0Htnck3bkMJ1TFa7npWVyJ58qSQ4WC4dOOpvN12BE thQxgmZxZqPWDjuJ969ct9LukwgWrWS0YwA0DwiY+QrW418N6lWC9sDQM1GfDrxOjjBc vAaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880064; x=1779484864; 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=402MI+eMAC2JN+aTXLkZ84wCkhgwaRFbSZi0tBBQDsQ=; b=YpLfAVlf7o+329UVAKcv232haJy2gNd3XUf6OnUR4rvMAeBoTDq0tyBSoioB/IBiio xr4t5wEv+KGk8sWQKX8NPqLKYQRo7Etps9ZbYxyqvASLnAkyBODRVyWQITITElawHva/ RQoGidmelfZEA6oHtnhFILG8oCRsysWsXAuOBPbpWWklaIhBPt1GGjxjXgn7Yzb3yLzk Xya5Jchs1hHWaGi/BQsS7tATmuhth7jdeqzeEXwlKpg4laV5tNtnHMMUEtHy5X7Lm5Fz onE5GB1cwgY7bLwH6mnMaxxmYWSRLkA98UIfLNHNG56OGfNuPJDyilzD6Do/3djrFPNb i+eQ== X-Gm-Message-State: AOJu0YxCgvQWDBQfyAV/LJHMGIsr4ysui5W3jFgvswSEBxXDbW1OIaCz bKCuDP+wdg8ONPleqenb342n3LWM+bjkx2y5ukgzZNy/8/vgR2Q2nta2ksT4LOOS8pSpIgjhkzB lE45KblM= X-Gm-Gg: Acq92OEfO7Kq7a+xyzIlDX3ybHdWMTLZnFOl3pdhNXUJ0s3sAlyo+wQPTPIzjQqxyNQ XkBihZJHUHMlxTygAC6v2/wh/jGRooXeERoRmkLuAIJsdF8jdkqzTMYgYcbVdQNd6cl6Dc0L9n2 neCMs8jxw9wZUZejlCJOygSfL/MgP7A/K/lwX4H0BvnEdPymKJevWvnb7dVFA76+GHOVRVOriFt bXC1rawkS3IPWQcin1wfblZmP3IeP3LGZ1E/psRDAdcUlPvHuzeIJdLCEm5QjQMmofLGBL15pyc jveWDE/DdVuEQDbSKejyfQzASAx/MdzKy57kiDocYfO2RyO3aqPfEXPYBk9z199bb2JU+/RXGOO YZnlvCpvjyzUsxd3jiQlY+wRXEcGrhm7ZGsiD/yjDPJDtD+McBBxdUBdtaqGGLgqRkwd8tkxbom 1zPg2vsRqVJg== X-Received: by 2002:a05:6830:4128:b0:7d9:b2b8:e06f with SMTP id 46e09a7af769-7e4f2b6f1f6mr4036431a34.21.1778880063891; Fri, 15 May 2026 14:21:03 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:58 -0600 Subject: [PATCH 59/66] bsd-user: unlock the start of the cmsg MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-59-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1273; i=imp@bsdimp.com; h=from:subject:message-id; bh=iHTiAs0eo+GfPoYHIYv7+/2ntDeMJMG9gZW+S3lWJyI=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43ozZyN/xMUaYHas5P9yaMfCyh4kUULClrIm kRyvYmB9j2JAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR AIXKD/93FdpOPo1nROZqPraVZ/rpIQDsup2MEYtEYPd/UzK2le5hGSu1iN/YsCifqOtYYXpPyO4 wCeZ0DOz7rXOxNCPWdH3xflM94D506NbRuF0S2T4MxSo63tKAlvle8nP8vcY4LFZNZI2IqAHNZQ 2mgnWumAs/IWA6vhDwAHo6nY0Yp78ryzkGuTorltSQ2Xh1ZIFPQItMRbR3iLnTD+pX/x8rFeZNN XcfwUdt8g/khc8iqMhhhFE/Rs+NRWfODPO5LvdbzVUNZrLneDgtEfozbKHseS/JqvG1o7pBEi7z OdMelYrok8IORm4E57lPpQOujuM1yjznwdztBercD8rpXUw3Q9udGoQ26ijv80bGGLUU2Kkf1X7 P0av2+qAF1bdq4+JmascbPA2uvKgAHcjJCd9bgjqhmcG5ZzUBy54xORkO0Cu9KEgJDHt34kBmUj d1FG46rlKNIBkjsVowPzrOBwWuykfoMQ9EG+RD3QQmhPTxjBjxQC+aBXaCd+MMrlXYPBKSk7b7V Qhh8QqW84QmczeC/YQEgIQ0AtaWAHD4hEQBveLR2+D+/WkGUYd1TumpXZBvW29lJAbSqAs7mt1u mus910BvEnxQ02zNj6knEYAvE4gX7DEaEBFWmFPP9MCFci7c5qkBvcnIwFmg08pT2W/AiGaT3jt GT3O4oDfRPIh3kQ== 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: 1778880136120158500 We move target_cmsg, but save target_cmsg_start as the beginning point. We need to unlock that, not the moved pointer. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-socket.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bsd-user/freebsd/os-socket.c b/bsd-user/freebsd/os-socket.c index 968929c2fd..8eb728240d 100644 --- a/bsd-user/freebsd/os-socket.c +++ b/bsd-user/freebsd/os-socket.c @@ -91,7 +91,7 @@ abi_long t2h_freebsd_cmsg(struct msghdr *msgh, target_cmsg =3D TARGET_CMSG_NXTHDR(target_msgh, target_cmsg, target_cmsg_start); } - unlock_user(target_cmsg, target_cmsg_addr, 0); + unlock_user(target_cmsg_start, target_cmsg_addr, 0); the_end: msgh->msg_controllen =3D space; return 0; @@ -227,9 +227,8 @@ abi_long h2t_freebsd_cmsg(struct target_msghdr *target_= msgh, target_cmsg =3D TARGET_CMSG_NXTHDR(target_msgh, target_cmsg, target_cmsg_start); } - unlock_user(target_cmsg, target_cmsg_addr, space); + 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=1778880215; cv=none; d=zohomail.com; s=zohoarc; b=PbCQdhszjFRdKVJmLUn1CGt2r66FZRcfEBvzIp1qSvBVzfE3s6rOxPkX7mdaRMs5z2lnb4aqy4A32rgMdfMzCdnGm2HJJK0f02TLgjaQ+uTF9EHYdo1in3ip7nZE9TXBB7Hlc2PvQonjzJuG+49bgs5l9GcaMhnoVluhgbwliAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880215; 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=doWUqhLZ0XkK2oAH1laIExT1sLr//X68uA6DuBdHRVM=; b=OoNaSuQteUHa9tQ8TFlx3pRFLlYV3gm8JTcXTunQrwOa51clPBr04muwbkvsb+X4ss1dQDBwRU8uR1cJfKiCqsfMBONzpieYFFG/p3r5lop1Flr4OmjFXMqkMbXNiYBWN47/oFvqsYR2qZSFb0AHfvtf7DOQYVeIIaSOuPEJl/U= 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 1778880215946699.50183319471; Fri, 15 May 2026 14:23:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyL-0004sX-Sa; Fri, 15 May 2026 17:21:31 -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 1wNzxz-0003BM-SF for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:09 -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 1wNzxy-0003Cf-Cn for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:07 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7dcdaf06498so206138a34.2 for ; Fri, 15 May 2026 14:21:06 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880065; x=1779484865; 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=doWUqhLZ0XkK2oAH1laIExT1sLr//X68uA6DuBdHRVM=; b=C4r9tTBnONvrCrzDTUMCwDZEoZWTukfl0VLDPgj9E5R/lSabweAxeVTf4v0b1csYKF xV5ZT3tgnJwjDrb1IuTrdyqBDgltngfgXLQ29vFIbjmrt6N/Jx0freJ7v6HO8dh9Uhq+ zIhlmEQhjqGFvanvVEPOpi9WRdiYZBXWJcZ1rdYJLatK3HYitp2QMhnVapzOSvn3s8pc oiFyTp0cHDouZYxxTpFRQbBxqRLp2bVWGpQNZdFPLGkvV+cTQNxceTmZXEolvunJ2H8e hJbQXPBcyP3yxnFrhKm3E55leK/M7Zoax4bOBn0s+BJTOTB7DiWMsy792ja3EUNGr8gK 8HoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880065; x=1779484865; 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=doWUqhLZ0XkK2oAH1laIExT1sLr//X68uA6DuBdHRVM=; b=M13FFpeQXnApTEpUhGBRovNQjidQq8rGzq4DP0CuwFAL5ZkxjpnsMWgq4MneWq08Sy OUnUw4tSy92fkr2g0bJoziMQpGv1UniwWQ9nvI1gnTSvvzYeYQTYspY/KBEOugAqz8M8 30xNoyHA5LL+PoN5X3LOrMQaM5RJ7LIVzhbCM2NwSycypPjmCSmHa4i28GHvVn5GQHsX flzhfY3LdmzVSta1HJFQliXIZPPCz5QA0SsFsPySP8YRVqTz9P9f8cWxFOTn2wxa8T6d vnnY8/XxpiJwB2gcVVJuOS7hRqHoV9tPZaaBrVMzhlVKG7YiiTytZPivWWcm0EmOdiEY Vvpw== X-Gm-Message-State: AOJu0YzK+Oh7uCxaLyhg/ty2waYqANjOiyiHptF8bOx7gTElcMgkVxxU 4PfFaDIXVnmkoiKM5ayCNejTd2/kIIZGeKo4STNT8P0trtOc8Z045ujDaLM8S0bUB0RSoe5ORja SOddZYHE= X-Gm-Gg: Acq92OEb3yrHpRDw4HFkUXHZtkRjimTGqJQzOCEFEOTkWb4E4Alfso5xe+mP2E3nscI ZKw9igQJGnoDSBE8QbyOz+D+184D38zbuf2ldg/6PQpjLjT/FGcaENgPYljgpPaaTquh7P6sA8t X8ZRQ4oiMrmZ9NxcgIQPPc6Mlw9//fx68AJWLe3yuGFjzsZDUOEF0TiSHq5gmgi3s/DPr3mT6aB VU6o4hOjLxrRY03bd9aq21CDkSXRLRzs6y3K89/R8GrBW6fo0kfL1NimQoajgMYH2ijBDAlCGuB FVCrwxYpINkp5fimssZaASMUXIwOnyf1gmR50jzhIYsrYP5A9nvmxB1djdpXp4PsfJ3UfL8y2jj cWIZLpjUzzdM+Jb/H/PEETOxbXwW/W5rKG38C6IdQ9Ls4RuZcs7qVmlKYrHsYLhJKyRZekP9avD uEjQZo0c6xZA== X-Received: by 2002:a05:6830:6f4b:b0:7d7:d0f1:a132 with SMTP id 46e09a7af769-7e4fa0455d6mr4225338a34.22.1778880065089; Fri, 15 May 2026 14:21:05 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:19:59 -0600 Subject: [PATCH 60/66] bsd-user: Don't leak fd's when we can't writeback in do_bsd_pipe2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-60-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=758; i=imp@bsdimp.com; h=from:subject:message-id; bh=oM10BvModYCxqmK+8TD64lP93U/kbr+8QGoH/74327w=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43olNGALQV7MprBXXzERtx3K/LHoaurjKEHT g2q7BE4g+qJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR ALPTEACB8dqIskijP/QvKpplubFZFV5qfYnggOlAtndUGOjfapbmpwU9TMXq/5PDzIQXh1G60aR gQGvsB4NOBgiG+FazsoRpuIOuaaRGDGXZ18IHY7mFIMnuDVG6dKQJzTIlEYFmCJA7D2FtCYGHP+ VQWIqBMM2Qe1gWVKPE0T3191FRmjd5OmxyG5dP08oB9Xvvu5sZkjtXtxN6728B8OtuNDpaZj3GT /cJ9mX1lDb6gh3cMDhdfPtMUyCX35411yzIFHXJ9vBdejGSUdXKxitNWzbUfY/W9OYohQqJ3Bup jYCRvm48vloCt2kozURDAa8vP74aZy+m1TEJh9f9tbCsEAaTVW/JP5RbTHWNug5g5fELCy+d8Y4 jhOTlUlXTuCXkxMQ0NdmqagPrQaG2UzjpH+Sg1UNhMdOJLDxWGLT8tr0JUv+0iM9IGvYyGo9cqm Q1Gfzs+YvvCP1f2pLbnO9OKUc5i0MVxfSG1VuuV0lUkBXl3451UskstHl88sRNNcBOuk40j84xg I2sgoUG4P2cZSYF6ij8avMblS8et5ciNS7gLkPl7WwHFIokXodftYTHJnauAE3Q8K4D9AGghete KV9+bvZ3VAMl+G+QnnYo1NoX/pm6OdRUXtG0SiuoFdJmXN4H1rCQqSJdGpQouGW+72dcj3PdkBl oozMQ55KSYvijdg== 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: 1778880216691158500 When we can't write both the FDs back to the guest's memory, close them so we don't leak them. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-file.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bsd-user/freebsd/os-file.h b/bsd-user/freebsd/os-file.h index bc31064a50..aa8d8bda74 100644 --- a/bsd-user/freebsd/os-file.h +++ b/bsd-user/freebsd/os-file.h @@ -34,6 +34,8 @@ static abi_long do_bsd_pipe2(CPUArchState *env, abi_ulong= pipedes, int flags) */ 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; --=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=1778880346; cv=none; d=zohomail.com; s=zohoarc; b=QQFeQeSReuWDYrJXZfgAxLy/5GfDCTjoz/3/2aTF9fdI3gMVQOj0lwaUzmICpS4pG4tyL81nsstQVxKxsyv43+XS4D2hoiMAAOLmw1ssaWVCjgAHKI40bavxgi0wwlh82L6e9t7ihQ48XYdXT2wYTgHW+61oL2Rwx1YePBW2ca4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880346; 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=xfIdAZa/61ftnRZpLmFUfpLUwk5YAIKg50gmXCXnAwk=; b=QrXMexjgGO1jheD0pQbZMDUtRpplG8OI+h1tnedyLxUWyw01tATUhZNgQD1N5x6BQ1Edqr/Q5SXyNakLr3sDOhJ7lJ4Zxp7JznkzgqzPVTv4n+sWZjN2yzqVKWBFZKpFC1Y5hQDOY39l7HsBW9lxLmf4c/A74A/Z9bi/4z1Y8Bo= 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 177888034653683.36527463090238; Fri, 15 May 2026 14:25:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy3-0003Tv-VL; Fri, 15 May 2026 17:21:12 -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 1wNzy1-0003Fs-Nx for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:09 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzxz-0003Cp-Kp for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:08 -0400 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-479eb8bcacbso289833b6e.1 for ; Fri, 15 May 2026 14:21:07 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880066; x=1779484866; 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=xfIdAZa/61ftnRZpLmFUfpLUwk5YAIKg50gmXCXnAwk=; b=Ui8s7lHUsoSdupqTdfDhJlPvb7ozHgcjCsPh++sE1onHfdhqv7DsAUsx1X+qoYh+iR NsNEx+4Up/T6ZiafK9QpDgUYggMDpjaUna6EQG+8KLlwOMFKb2CO4EHDd65aZz+6OJEl CZ0bYfdyHdFhHglyQfsnvMPqpSuDVzyxivnK+yCRle85Hoh61TtXB50uXIH461MXKlxg KMK3qdj2bo4KAtKS/Rs9jtU7msaOmFOcQ/eSp2LnsgVA2eENVhUMZQA1KAbtJZPZk7yx AyftI2VrNIklT45aFxZNpjSdJzRLobOQL0OCZsH9AFIRYoQjOjSAbnjcqRmApyBK4Ygh 3N9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880066; x=1779484866; 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=xfIdAZa/61ftnRZpLmFUfpLUwk5YAIKg50gmXCXnAwk=; b=DFHVYQKQTPpJnZLBHJbpojXj145Z/nrzrLJ2rQntejzyAB1R4GC7QR4EAmykYik6G4 xaeZNtGDqWaU9TuWnB16eocfOwl6YRkgMfywBwkNB5L8Kx/Vv5osb46yAjizjhx33iwe 5BBjHPF+Ie82WkiCPDYrVEb+0Gypabb0ZgIXQdJ5Vi7kwpf6gqIpdK/HRb3YYVaFXENo +uEbx0q4jqq6I15HUZbvkdU4bevNpmzlRuj4YS1sZn6gQGJD4jrHyHQO6IysrDo1NREI fUAXS2ouN8JaPb/K0/ZMPgh6VBv84r0gLzfhH4ErPHgH1MDKYQx3deKszBR/GHcjvtq9 a5dw== X-Gm-Message-State: AOJu0YwMpBARr3WaEt6a+lvvJbF3np8bvnPUjIn98r88BFgYLoXG39RB RUHjmzXU6WXQh3bYBdmF+ZKTsCfu5kVBXqn3Cb2aTtH37WSZLxX9BQZ47SidTNM6wEvtWFTJpOM MOJ+qc20= X-Gm-Gg: Acq92OHp5NwKH2tb2CqKk69+o/I5IBnHeSjW5MODV3kjtwSTDIvAOZa5hFK2GQij9Aj owvKBzPKU/jb5YaHlVJqmayLoaGvBtzcrbtS8WpgtSym4lRUrEp9jGvNCey6DGtUZbrCeEBYLtf S3QBZpH0W4OhQVpKRtS2LKSgCJSYL9K2KX1yJYz1TNbet/ABRkh6mbxDv1YViMKAnO4y0zDIP9o CbHVkv9L1+x8ZiAi5vFQ3QDNnzC42ueYtP+MQceBfXLB0DnYkuU6W34zABKuVBt2XHYO/qsGOKg XUtbyr6z8LyoYLSblchPhO01m5BegEnWUn+Fg6rCsSF/51BplCKTkDgR0TUo4NGRr4Qm8TylF/H zBVUwMR+QHIkpYeVjyuw2FPLxZYIXkjEWIExoqLgk2GSzTCSv1SJS8qrdROpzgyMxoS8/bQ6iN/ MvIb9UVJSTjo1nVz6NmprP X-Received: by 2002:a05:6808:d4f:b0:47a:4fd:9606 with SMTP id 5614622812f47-482e57c665dmr3943275b6e.23.1778880066475; Fri, 15 May 2026 14:21:06 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:20:00 -0600 Subject: [PATCH 61/66] bsd-user: freebsd_rw_rdlock and freebsd_rw_wrlock fix missed decrement MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-61-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=3778; i=imp@bsdimp.com; h=from:subject:message-id; bh=D53YgxUSSQOw0EYmx8h0jJgKb6MEpMryLTgDI8lySks=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43oC8PzfuJ8dsr8SOW6MsMA4y0bDXQ553b1L kfhrdcnfnmJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR AL7ID/9iFtnzeN7O1onz8D7JCKcMlliuydaTS2tDC9mwEeECYeZioNY0vtU9zMjaW/ZiDICX4jM tmvG3AUq764r+/esWcWtAiFEFVNwCwEeQJ+w42rYnQWBk69rCdrTcu0Oy11V/yOVQGCrZGOWAZ2 SVbVACMfty5Hv1MhGWtdjLbqdCfXiRUiy1JcP7kXlV1kqz4ndw4brDYDZZDgZeO69Pbp9aW0koA wKYyyya/bgzrF3/U6RlvNdk2DCtVYLfs7XtlBiH0QVBU03M1MVx5fLHEntNV/mXBEQVzMxStGpN ZbaY+EZc3KYpY5gRkF/CGhLU+Pz/VCrKKkCbmpx4aEQ9T1/atGDsM46xFjEH/NxneR7xAQ1KZ55 n99VY4kjtbo0EIfjjBXVutbuZCtISAKJtPXX/kENjPFhbjM/SnwecZ8IUz2bib6cS5lVL2ICDkW Yn5luFgvfONaDt4bv+8hLqWH+FKB4p/1EsWaJ7PC5YC161BI/Gb+PgRc9fjAlOyODwwOUMgg1X6 rdbjAcLSJD7hHGuoB2v7PFbAmxai1cES2lFKWgaJnPtbAeqpTp6YAd/g3L/dvgUEZ3Q3Z1Y5dE9 V3sCvFfqDeCOkSIREkNjaXg17ZfLRYexMTFo10+DscihNZvXR1t5WIAqjAVN+ZT5HsYdKdSSNGI rkTRD6Lg94gOIxg== 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::231; envelope-from=imp@bsdimp.com; helo=mail-oi1-x231.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: 1778880347591158500 When we get an error from _umtx_wait_uint in the !_UMTX_OPTIMIZED case, relock the variable and do the decrement. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index f90f13076f..a36c5ceccf 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -1264,6 +1264,7 @@ abi_long freebsd_rw_rdlock(abi_ulong target_addr, lon= g fflag, size_t tsz, __get_user(blocked_readers, &target_urwlock->rw_blocked_reader= s); } =20 + ret =3D 0; while (state & wrflags) { /* sleep/wait */ unlock_user_struct(target_urwlock, target_addr, 1); @@ -1274,7 +1275,11 @@ abi_long freebsd_rw_rdlock(abi_ulong target_addr, lo= ng fflag, size_t tsz, ret =3D _umtx_wait_uint(&target_urwlock->rw_state, tswap32(sta= te), tsz, t, __func__); if (is_error(ret)) { - return 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)) { @@ -1284,6 +1289,7 @@ abi_long freebsd_rw_rdlock(abi_ulong target_addr, lon= g fflag, size_t tsz, } =20 /* 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))) { @@ -1297,6 +1303,9 @@ abi_long freebsd_rw_rdlock(abi_ulong target_addr, lon= g fflag, size_t tsz, __get_user(state, &target_urwlock->rw_state); } } + if (is_error(ret)) { + return ret; + } } #endif /* _UMTX_OPTIMIZED */ } @@ -1365,6 +1374,7 @@ abi_long freebsd_rw_wrlock(abi_ulong target_addr, lon= g fflag, size_t tsz, } =20 /* 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); @@ -1375,7 +1385,11 @@ abi_long freebsd_rw_wrlock(abi_ulong target_addr, lo= ng fflag, size_t tsz, ret =3D _umtx_wait_uint(&target_urwlock->rw_state, tswap32(state), tsz, t, __func__); if (is_error(ret)) { - return 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)) { @@ -1385,6 +1399,7 @@ abi_long freebsd_rw_wrlock(abi_ulong target_addr, lon= g fflag, size_t tsz, } =20 /* 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))) { @@ -1401,6 +1416,9 @@ abi_long freebsd_rw_wrlock(abi_ulong target_addr, lon= g fflag, size_t tsz, } else { blocked_readers =3D 0; } + if (is_error(ret)) { + return ret; + } } #endif /* _UMTX_OPTIMIZED */ } --=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=1778880120; cv=none; d=zohomail.com; s=zohoarc; b=VUaQP9yTc4sE629ysZuRlFQQkC04dfjzl40iig+Y3868nwp7gRwGhVNVv0meJRMgtj8v+YsXBh5I7Q6KWFMDdHCFWuuP/viSlEf3+adP9r0iQoDedlOiX9jc7h3WTVypF0q0BKM2X12gp5Z1f48DTMTkjCiK8U1uYdCnA1zY+IY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880120; 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=NY2OqudA4Z6H0iIcF7VAVXA6z448HiczTLUV6Xd88TI=; b=kV2RvKGC6nHunEOwkICcDuGOahkxQyGDwB9DNSdAkPMa95+bRhngTNc4vQbQqZMZuGloiPP9DOb2wS4S2BhSfFpWI4VwMsIJYg2Y/KQt9/tYreCnb7e98bUV1xV5lU8d421a6uHv6wY2DxqRE76j2Z8YCjVbWCH9lvUEqIlIhFo= 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 1778880120371110.86996752241816; Fri, 15 May 2026 14:22:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzy9-0004F2-Nn; Fri, 15 May 2026 17:21: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 1wNzy2-0003PL-Tt for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:11 -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 1wNzy0-0003DX-J6 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:10 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7e4004a4a6fso337565a34.1 for ; Fri, 15 May 2026 14:21:08 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880067; x=1779484867; 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=NY2OqudA4Z6H0iIcF7VAVXA6z448HiczTLUV6Xd88TI=; b=jTErZEbEUAiKkqX7R3ZJ4EilPcOGEFnQU8xCwhWQhUXDr9tMvcgRWsHz5LI7+UEIPD 2zMEmzqd0ye8SDht1hsFETdK4WwZPvphrLuoGIaPlQRiJuwbsediwFOVx2Rzl5Er7SFv ApOOdC40EWgaRYMfpv8DqFtcI1tQy9fyWF/P4/TCtMAiTRvbG7SYQK0fUhOblPCW/Dqn ItSOfGiPUfUsoV7ztoTAEIA0Mfl8KfXUK2go20LYHHFVEe6g2Tp18hVSIqeBVwKWzgI8 4qOvpmRKV+M/5Nq5Hoo/j4sAKdFwC4GZFLHbNbiRJjkslq2MACl8K/eNvhZX8/n8T3Ua 2nqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880067; x=1779484867; 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=NY2OqudA4Z6H0iIcF7VAVXA6z448HiczTLUV6Xd88TI=; b=N6tmhXoaC//EUHW1r3luk3MXHIUnXdPoI6/QZhjtnDqf7JpLPbPPZrY9a+ilpSuqBc t/UHOfSY5+3911UJCkQWT+YRsH/rr5fQvVlzrd/QTaWTbv1pjD2iKCPhXNcRvufSGydk CEVjXbmCQ+IoDPg9o+aUspVV9hBGPwaAtWih9wKulmCUP3TdKRcXrpzyA0VZUg1mLbkD RzLYKsbqh+m3Sy8wtR21gmU+ZM0Sdr+ssY7y5u3YXNM+WSNPpW2qIxSJ3hpquSlVo3ch b9kTHyNwiJDYkMd0DtVkL0wJNmpDR6xCZxUp0DUkszDjEhHWaC1I5zZf4Jqr+dwoYu1a scGQ== X-Gm-Message-State: AOJu0YzX1eGbmYjJZ5oi6mNRS8GV5phvikx5GyKdDsu7BIkMBLR3wf5o J+dOzbqShp5+F3RosMHdHJoZyZRQ2wai7gccsHg6lS8MSrjWBaaW9xtkD1soBOSOV72RdhuYBSh CKffEZf0= X-Gm-Gg: Acq92OES9dF6dbuO/3Byl+mQaztKNp0UEOR6G9M/b6WyYGfrO7SW+JT0rpbQJFeSD+o lwjF4PcwGWyQh9QPjqA0aFDhn3+INz5Vlt/DYAVeM80zA86LeMNJpsOzOX9cP1ErqVtwYNobSvO 4wh6vU3iRW07HQ1FrEJIFfnZ2GxWZ4GFZowcu0K1lnuBjAEwHWvHFXepTbcO2XTVWlQYEi7L5je VG5uNTpUf+5vKY6SsAtKjT+uDtZ3MHvE//1YlzHU1RbXgEhbhIXwxyvn7R3Apk/n/apVz+TKiat bBNhMY2d3R3xKrcuqVd/x9iRu2plxZx1kZZ16M3ZLuwGm4iVugehli2WX6hmbE93Lfbx9ujBDYS 311R8yXOGQdivN9QpAO04B9IfKeEv7Ymh5oxWXcD2YvMbGq/hPXIFuLQpNZfKlJhdb+XdWbu+bF ToVkJcyZFVwQ== X-Received: by 2002:a05:6830:82aa:b0:7d7:e844:7f4e with SMTP id 46e09a7af769-7e4f2bd75c5mr4021296a34.22.1778880067599; Fri, 15 May 2026 14:21:07 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:20:01 -0600 Subject: [PATCH 62/66] bsd-user: freebsd_rw_wrlock needs to unlock_user_struct on this path MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-62-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=804; i=imp@bsdimp.com; h=from:subject:message-id; bh=rhRfOt/9sDKD5ZAVEtT2L9CyIfY2YRZQwnGS5qh5jwQ=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43odwgaxrwrrGhDG8dpG31tHujmZJD3VvFef cFnRsZYDBGJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR ABGrEADfQAhtGZy4063tIBxR9HKLGLzzrgoh3Pd9NxvWEP7v0neJrNrghNsiI5CZC1qtyVI7fEd Gw2R3BKeKRRZiD0Q20RroOQdoNUEOqvxnbeP1fvW+kv1zCPXHo3nRZutIqhPw849My/M8Chi9Ij GDNEfiesjdsRI+u6oVst+nM8pqwNweJM2i8kTC8HRjZpFf19/gZP6jHG7IAttIDxoxIHcDeoadk 8tNf6uRTGSXE6c0G9Q0on+Xc6A3EgR4XGiTG736RTgzwVMC5eoyfrVUka1oaaxtyORpcuzJPwjh aDGsHC3iuYDzp17QjJpYtsX+0JvBRsI5ATWZ4+vaF7Zd/kLGle7PJiSpIJhqfCbldvU8Htc4kr7 Uped7ndvKEEPqafC5+LG6Eg6W2A/uvLxYd3bJU1MpUH6dXmVmbW0AjQEFB13kcg67p0NWos2nZs FiUABdAHwovbE21w6bJCxeQAysKV1ptgdKK6e4nD16RsNYEHDMhwAIM7eSmXWxbbxyo1VzOvaGa 5hYgSEBoE3dQd+tAwWCmggcONJVC5sejb82hW/zdZk+4JrbUBvvHSVBL1wCLW82kliwa8CnMcql WvvrjXh9nDE0nbd3d3WxJ9O1BlfODCTm+8hAdbk9mLe+yc2a5E20IbiZ6no1irUsvbUM2xyuTtT gknTm6amH0iZCPA== 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: 1778880122001158500 We need to unlock the struct on all the return paths. We didn't on this one. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index a36c5ceccf..86dea0aea2 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -1350,6 +1350,7 @@ abi_long freebsd_rw_wrlock(abi_ulong target_addr, lon= g fflag, size_t tsz, 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 */ --=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=1778880144; cv=none; d=zohomail.com; s=zohoarc; b=QQdEs7ErGlc5r35WLakCNtjXt9yk+VTtRjtHI4l3WAuORiAzY3BD+SO4FyL2617DUYskAZTssiHl22q7RcWumAmVqWtgXEKmWQJt4Wpj8BXQwwsRSbT3sP6kjmKvv2h2RZkKHFtXCRTjA57+juJLBCUNpqKY0Ucm36KXDNEduE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880144; 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=AfoLGQH/u7vouWUL8Ri209Pb6hWKCDmVzWrUSAo9gzM=; b=Azj439A69tJSwhIsoQRTpiDg7PYybR6VXtIQrmq4CfyFWVtbXXrdjeyBsZEJoNltB8Yie7B4Swkv+yOiDnnOG7TSc7LyHWszyH4HMbuYfOnSELa+dCMwTNqlSjUToxwNF5ATcYb97+bDCDI4G4Azo4d3alcTZ0yyzX5zP9KeNLU= 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 1778880144385445.92384209712293; Fri, 15 May 2026 14:22:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyJ-0004nP-QA; Fri, 15 May 2026 17:21: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 1wNzy3-0003RU-82 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:11 -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 1wNzy1-0003Ds-Jp for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:10 -0400 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7dbe07d3ec3so167151a34.0 for ; Fri, 15 May 2026 14:21:09 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880068; x=1779484868; 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=AfoLGQH/u7vouWUL8Ri209Pb6hWKCDmVzWrUSAo9gzM=; b=psRoek3+e56fAgS9/zeP2+as71hAaQM4RwEkyFHHEMHA2qedFb+lTCj8+t1s4H/gPS mADjlEHFvOdaTG25kIMbY5zxRFq/o7R7IOVEry2DqmatmKE4ZoOLZfJguuIwNXZJUSd4 hMPlGZbeff+UfiwEfSoSW2u1F/aEKun02mVPOclVofOq1A5EsAGvrfW9lGFUlS9dF92w J7ErBzLEODiyuUpgjszEzUAHx/stvW/GgxcsTgCjW58ireeubcckG3CzIPggShEAAr0H bduqcRsElwbqXp6VmIwE6mEJYw6YJjZSPkQyr97KHcqgWhgNMTeFCDZQhTVkLTozoJuT 6S/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880068; x=1779484868; 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=AfoLGQH/u7vouWUL8Ri209Pb6hWKCDmVzWrUSAo9gzM=; b=UU907jL58vB4ybEeanAlqJm/MGuGnGshlq05gnQkyCJrXa37eM3BsDtvQkcXOrsxKL J4++bKz4tyD3xTAL0Fat83NBA5oaMPoxaTLdQ7cc7Zg65Q2V0Ud0X+nGjr+/RB1ceSFg EggI9IiZqlN03R2SszeaLtBHtzv62T/ZvsWg0crCyqQ0nEJFTYsLEMSRcSZzqqqXxmJ6 /ljFwOyFhzTmOBJqw+X6rJ8lzUpZX65u+Mph4tzV9g41/6eHDCscGLVIFoG4yrAiVA/r cZs/gvF8+aqeyVpFR74G1EvnetHqxeL0iNQ5BH+jgAh8SzSLjK50B5Oxr2J2ZnGKcSSH z1og== X-Gm-Message-State: AOJu0YyEYHjpuSKntfJUMVXBp91Y/Po1+ucf59Qajft4fmXzQh4nfHt2 ySM5zxiQNHtD3G5woezvtSpVa6snzN2U9I1Ee0dQaYgqRr5YZQ/lyU4LFDZGjOsJWWnaCyTJ737 oK+HcSqE= X-Gm-Gg: Acq92OEOnQYArehuKA3W7G6ffC6v5oREbbumbpPhtLW8wl5eT6Bvs2skT7mdFFjhS/i msxAtY+QwNkCcaBZ8zL+tEaGdObbyRlT/0crYn82/VVyCnhh9kOkN5LUGSxr9TbZ5AQDVVeJDSv gbVV/yda4w7VoOfZGlqjxeqlWLlFF4zZ/91XyPSh2AlfXcqyVZ4lyZXcWtbDkXYKf5ToifZRA/w rWdjeE3tZqdClr39lxB+WbukKTTKnaV8Qc+Y49QWygQe0o3PwyJt15jQMz+OM6uO1jDYZvxgy4s IPLcVi1iK/uysyCDHc44b4IQKB+pdV9C+OHrQs2N7er9kGyGeDQkhkCOyywJdV2d7Zdk2hJ2p/c F1L1RVRAl8Vnb1hAlaEuxw/BmbZ4aBas/ZhZAcw7WaYkLVmIEYINxHvYwr5LCa3AnZh0YTJmrZ8 Fm1ZJMXsu6sw== X-Received: by 2002:a05:6830:498c:b0:7dc:c620:aa12 with SMTP id 46e09a7af769-7e4f2bb65f2mr3768169a34.20.1778880068276; Fri, 15 May 2026 14:21:08 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:20:02 -0600 Subject: [PATCH 63/66] bsd-user: Don't write back length on kenv error MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-63-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1106; i=imp@bsdimp.com; h=from:subject:message-id; bh=i2JQpkPEoRHvqVKbgLgbPyU3wj5/vSQRplY9z+GdfhQ=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43ono7Dcpr7/myBhDdWB20npA5KfVQg5b9Az rXV+w/exoeJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR AKgGD/sHikg4R1pVhnuKlzptjeDLcIbgZNX4bufl9ehE0OJ/r1TQypIzEVHPcKzO1on0hEY8dlG bO4YYFO1JBf5HYy9Hy1bYHnUqgl4o3XbC8938w9WtHE8bFf3x3suKHRLPPKNyrmxlglAQlH3Vcy 0Nrkw4e8J0+tOjSrlyGBoGWq5vL0L9NAZAujPnTVYuVFlfcYDzNTfgRe76YqAzCBrpBync+IHqk H3O3bP7HLELR/U9I++DbCA6adKiAlA5r0jRd+Ch8A2jMNP8dJoJr9tpqritDPLvxrjo15g6kGxb yg5Wqz5TIACDleU6o1qbBEsNYhCMKj8NyWdUvqOJQkca342DQHvgj6qG41EXVwupVOjFMjI/QAZ 8wNDrFs1ld4h2NCk3XJ8rlcdrlvKeZQK7Hwx2MmRlTeQTdf51GDuYqlW6V1WahKdd0NY/1upOZ3 BqU8Nm+rOQ7+WTYaryqPk/FhHihLKekSbiuxSqyJt2+zIGbsMwurSYAptdSsTS2wU09oryLA6B3 iAZYus1PEBdqu4divo2R+qO23IHNZwkGtGvCsgjmzHD0DlaGEbZaV1KmZy4AMcyGcR+p67nHEXU 9muaj1IjJt2LlOq3Hh4e1bErwDy++Hr6UiCkFWQSxs+k52kN5tpBFAmqjDGvRv6dz32RcQxE8wV mR04tyBgTe6kjLg== 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: 1778880146225158500 When kenv with KENV_GET and KENV_DUMP* return an error, don't write anything back to len. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-misc.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h index 204d8ebd3d..92c0a5b4ca 100644 --- a/bsd-user/freebsd/os-misc.h +++ b/bsd-user/freebsd/os-misc.h @@ -480,7 +480,9 @@ static inline abi_long do_freebsd_kenv(abi_long action,= abi_ulong name, } ret =3D kenv(action, gname, gvalue, len); if (ret > 0) { - len =3D ret; + len =3D ret; + } else { + len =3D 0; } break; case KENV_SET: @@ -522,7 +524,9 @@ static inline abi_long do_freebsd_kenv(abi_long action,= abi_ulong name, /* name is ignored, per kenv(2) */ ret =3D kenv(action, NULL, gvalue, len); if (ret > 0) { - len =3D ret; + len =3D ret; + } else { + len =3D 0; } break; default: --=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=1778880251; cv=none; d=zohomail.com; s=zohoarc; b=QmhO1oAbsVEISMnPn1kj9oM2QqbmwDlHQAzmX/zg0Fg6OnNW11+3ch9LsGH0266SViDYLuI9slCDNQBtzB//mYCc+r9027y7hlQD9U4pqN4IDIHA3YYvjDyTrUx7U0MxJ2bJ8H9+BgKMiWXeO+kBF816V6Pd7mKw8TFsajmmpB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880251; 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=D38eO8lh1/Hmm7MWyiVfG7ePSFfaPqvbJ6JDxlidPfs=; b=AWUemN+WeD0gYhMOTnsTu+VqS3N4fSW3pCbspdTSXL45EaNm8RgSb9oEjMye/2817Sb+gv3W3XbJk2sjZ41RnMLM655YoaE76X4g2mrkzpzKpGrp4Au0GCIcRKwn2VOQ0yjXYJMv8Z/4W6urlu7Ruzs0aCRC/LTTyN4OuYw/spI= 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 1778880251920861.3351037666586; Fri, 15 May 2026 14:24:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyK-0004oV-1H; Fri, 15 May 2026 17:21: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 1wNzy4-0003Yf-Cl for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:12 -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 1wNzy2-0003Fh-QA for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:12 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7df05fc49e5so348554a34.3 for ; Fri, 15 May 2026 14:21:10 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880069; x=1779484869; 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=D38eO8lh1/Hmm7MWyiVfG7ePSFfaPqvbJ6JDxlidPfs=; b=Cz5tpxU30Go9lTgRa4lEwDu8LIzixNiW+8DVb6iPANIEx7p/Pyk4pUemCUb6hApCxR f7caL8QNVmTU1UXUVObnZRVWeBdpufZ1IU5cZqX0Xku5CS1CXHVzstJONgQejBVyKZId 4XCMQKoh6BmUWDfirBM5rT9CI4bgGMVY8BvvDfBZ23QoB1/CM/oGmwrabJcd9zGwfZbg t8Ap0cv+VOGuDfjxgQFEhmnFZBOnlqJa/3jjt7mSQTHbBZ4Ppe9bdV0rVztg9kLDE9Ft BycS47h3inhHoT22ckQxmCRW8MHpSj2H9fsKXcsMAmmeaiM6CD1PWAobm/Vk0FI/SpiV e3hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880069; x=1779484869; 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=D38eO8lh1/Hmm7MWyiVfG7ePSFfaPqvbJ6JDxlidPfs=; b=fLoKCn6DGueHgajmTAjnmhv5CVYip+vZPfkM3g0Ubm6YoLep9HjF1Vn+68XHHpf9ht raAN4xUSOfALnmAiyrA4edmr6INxlIp4t1RLxPI8gRa7+exkviChb5OCBkHxwh7a0ZaJ /C1dBrAd+kSdWrrUuRmIiDWl1gsJLIcevanI18R39v5/LjlnySyg2U9yU6XvScV5Bfvn vwaW31qlvOnfqBS4ryrAdpeK+iK9cQyAJzGkNE1tDfWsysy/IbGTi/K29Bb5OqmK8ZmN HwY+beTG818nln3cnKpBhGg4q3NoqsiwZmLYI+1fD9tupwsR9rGWMaZ4kf9tU+F96INS gaYg== X-Gm-Message-State: AOJu0YyhM6l7uBQ3baJrI/+U+kM/WcsE9xESxenwht/JApjrls0wdX3d q13hw41GXS2J8XXISWLjETtbraT3me3AsVAxaUHCTcFwbz+rIBIVMplACgV3wa0roM/ngZ5YhjQ HqYtbnW8= X-Gm-Gg: Acq92OEuZ6mKtFNo8v5OwpsNknFVKbcatEjTWoTaoTZXUBafbkoB5QNQDwzXHMKveqK xkXdxnPFpMymWT7+rw4dOVEBTeKBDxccMxexW4kBAxRWY1bPQXyyOT34czh3E417LdPfaufIogF /4KfNlBeE9cGxwcjV6p1OvrxnqSgT3Wj9+CWXC26/XCeGe3+ok0ByDF2rC8Dlkw6KQkm0yjuNho 8E7ro4CJhJ+M3zEFWrWHW/9h3IEGjTdWJ+mSZazXX/gEGsttlMKL38VlSyBmM8KAhsbyBwJzWcD VWUi+BZtbwlwjATSx5F+8YxKbxWpNzyEd7AT6hiTmZIoV6ap5+9hNsXYV+mWrul3RODS9i8whOQ zKoUKtmoj/F1c3XMhx552UsCz07Vb3BxxDZXKMrcUryu8xXjS+aJwshHeuY55vXP2X3dCk0lnLv XbwKjrb5uZtmdjD6kAu1oD X-Received: by 2002:a05:6830:668e:b0:7d7:f146:8738 with SMTP id 46e09a7af769-7e4f2b80067mr4070093a34.12.1778880069377; Fri, 15 May 2026 14:21:09 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:20:03 -0600 Subject: [PATCH 64/66] bsd-user: avoid writeback in do_freebsd_extattr_set_* MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-64-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=1414; i=imp@bsdimp.com; h=from:subject:message-id; bh=P0PmncDAKqIuggMfkd3RkG1LhSxy4JsgHEn9y6uwGwY=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43oAA5o/RuPISo0ZWVRnPIje6Qcah5NveUPt rjWpcfmi4mJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR ABapEACfu1lbHR5SNoMLfoCuTdCgVYrstb5edNpeQDMSEOgTJMGkYukwV7epPi80/UP14pagTfH 5ceISCAdZYk06/GOgOs274CUqIbfQDHJ9qYWroS8reC8A4v6DCHWK977I++hPOjHW2HwXfnalMr 4wQhjw+x0fpw8Cuz54U4jZhu2X3NxdL4pxZATCnAFe4ImCx8kbbdbHv4sgvg2b6v4eylnms/4LQ q1Tm6Kx9FzboDLvjRRe4D3N0f/hNIUBXY3K6f+GoWfGcNj/YQiUouBAvVf+hMmIbIrST/mllCs4 tDDCqKOKkwz63kgKmh45v21OTtYmcZ5yQvRLBS+okiPV488Za+Vd9gO07Kf8B6JUJc80woGkX6T qHO1xhpLJkUFX5z93XsCM7C8DrnUpcjzQaISyPRJkAF2TXXsiKVMWGgcDpxp0HC2lziZSFpFSWX cYehcCMYjpzcPM4VcbKT8V3qwM/oeiqCsyZz1m8o/VjZwiKZ6vur++JGZTAukeUFLzbFTvEPg0H 8gDAVApl9YTXAPAYd8Cd3B/UxYUnUcINNG0pLhFd4lBp+sR2lBtwwudXh5HIKUjFILMOQO4/XeE ia7S81wxJxDrPJxjlYPxzZ+LiAU+kqo+p6NfTVaeiPsm3kYrgdpU/C1sysmJK8VGDyPp+ffVgYC ZD++KlERGTXTuUg== 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: 1778880252910158500 When we unlock the the data we've read in, there's no need to write it back to the guest. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-extattr.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsd-user/freebsd/os-extattr.h b/bsd-user/freebsd/os-extattr.h index 97c0f76559..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 --=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=1778880223; cv=none; d=zohomail.com; s=zohoarc; b=dACNpZdwvhGYSnjSeV3WR3wWVgn90fbmlrfvqI3QM6CxqG23CXWc+2PTRw0m2vGgmabZAV3hZq1V92oDkMpd9eg8x++4ZYrOfwMoUpAARty8OiOTxeQ0kgviLgOh6/eniSHzTAp+1ESA7STN9XpUlQAhh1Vb5kZaEDwQ8snghAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880223; 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=aD3/gY2TQlala6Osa3hlpop/kKt6yv6iIOvXHix6Kvk=; b=Z63BmwaEWua8Do4VxatQbP1PjBau4KrqFayXib1lw6wfq+LYOlZo9Pp4T6p0AMqEExeuw3SuznX6m3wWaeq7mEx6In8lbta6GhP7jEWke+AP61EjztRzgqyUSKfUlLWf5QJN2SEZPHE7Kp83uQXAf8WRHC4Sawpk0X8L3VriCRs= 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 1778880223074436.2198795176794; Fri, 15 May 2026 14:23:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyC-0004b5-EW; Fri, 15 May 2026 17:21:20 -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 1wNzy5-0003g1-9B for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:13 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wNzy3-0003G1-M0 for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:13 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7dcdaf06498so206182a34.2 for ; Fri, 15 May 2026 14:21:11 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880070; x=1779484870; 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=aD3/gY2TQlala6Osa3hlpop/kKt6yv6iIOvXHix6Kvk=; b=06hJAyiP4c0bJt3VmB56jlV4RMD83neGO70AqRYvo08/c8Mb3/mYLXr7bFLGJvTF0U Z9lDTAIHSqjWIDIrQwPzsLqt1oYqvhNJnC/d4uEL/GqVUSdLDpRoA0EmPMWvcQ/Q3pSm jhozoKSo4nXaYxaL84pGz+91C4kQkL4k+CwVBQoE3sL38vLIhRKo2NBKFVbLgRcRl7hY /qqcvn0DVLVG/Maqo6jKbYlKhJNGGDnUCeWSyAc/o2c75er9F90dmg7adu18e7XprZZa ROSAYd2RTfUUhssUI748MIs1YFI6Y0JTi/0KNdGE9HWo2Fwq94bFK35bkferVCR8CYHx UR8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880070; x=1779484870; 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=aD3/gY2TQlala6Osa3hlpop/kKt6yv6iIOvXHix6Kvk=; b=XyK46G6oTNUJtA2YVFMVfoz7Mcg4jhdvhSdAsQpsJJ4KX+POCNhaCU+8rwnavvXnfb Mu2Kmwp0yQ7YdapRfoGYqVai5I0eGMh8HTepDC3R3XpXkX74m0zxO7U48KCuKwani1ZL so0rl7nTc337+qgTuc2qQHppEDoT1XjhmzMbE8pX8u7RmE5I5OWEu9o28bMmniTHwsIT wosrL91pomRNGsa8joP6JdDTVtAdSy2DTX/FLeOF68dwY72AQ8wLD9hsEYVHhzMN9d6u ZfuKAC+D4O6msg98UpQoEue1Za2CZacKAEUNe+hCLWnfWiE3fHt6S3cQ4c/5511d5+nb MeGw== X-Gm-Message-State: AOJu0YwmNox4kCp5D3j/VNYChUraZTv13sFL4AC/LRNJzz45pH9Z2mur uvtb2mT90FKX1ifFE3/DArdUKFJ4WRho0PF3uyynPIMtawjPLZz7Q0GgOK1C2CBueJMaat9EPkh 042G+iN4= X-Gm-Gg: Acq92OEqgz61cTo3ebw+a1bZczJYvbWJv91sLwYihuW8jquF1XfONdR+LwfmZ3leaTT kg3/NaiV7FJx+iKVHXEUzrf14wV4TUxA16avw7AtnhuMsh+wc0C3Ok53W0Z0ByfLBUG2xoVDQQX bBaOH+OvwC5oNCx/EUszEBZan76Gbr9TG1fQXkF70EkjWCnmTsbu4PX1tSc4BmHw8Ncko1xZ0SF s1Y0VPY/8fR0/cs8JgykjjomvAGWGnW+xYfbVdAxQCepbVTv49OiVmXIP4yzpouZ2D28fhYDg/1 xnjU0XR2XgfXHm9jCe7E3MsGez0WAcGK29tRpldQEL2i5CdNyaq7MdxKPVa9NL8yUZ8cXlhPa/J cP/yvpJEJJw5TWIuqJIGPwBOpoq6R5ZbCw/8X55JHpiYxkhmzsfdFkEagWIc8iHZDrPjJmcLsWh 8k2CtKDSf4aw== X-Received: by 2002:a05:6830:6017:b0:7de:c87f:53f4 with SMTP id 46e09a7af769-7e4f2b3e96fmr3791516a34.15.1778880070332; Fri, 15 May 2026 14:21:10 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:20:04 -0600 Subject: [PATCH 65/66] bsd-user: In specialfd, we need to copyin target_eventfd MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-65-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=717; i=imp@bsdimp.com; h=from:subject:message-id; bh=tkRSEuvAKbcL4S51GHOcEnMrv89VGiUdfq+mIx3htAA=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43oYUaqZAvHhIjigHFuScMiSqM+v8io94a1a N6graQ1p6SJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6AAKCRBsHNEofbAR AAedD/43nHGgTq7jJju2eAt4Z5hpsASW5FM1EZZMuYiAGh3Ms582lAsKSO0G7ZJ8YlizRoUaEmP Utg01ZawH/MBYd/bj01oB13dnNgO9S770LuhWFGCmp4CvhugzzKlLfz2xBWGsFQL4iPtrO2DkKe tVCsCWO6hcywVcGHRuCHiVuQhXUe6tNRsuh4y8Cpa5YGIAMS1DzqnK9jx2CoYOgd6ZBJwr99VCJ k7Qiu1HU4GAjzDeOy7BMw0nivpaUgXfTNXdkvQG86o0LRvu9sfOFh3SXw0p5eUonSHnPsYXn1Vt pobrfv7JsgXzKU8xBN+HeXzipoYKxuO7Oc+06WGV4SwyC6szml6HjUV4ssrwFmIRd8sIvbIQ5u5 l52TtPZ4K57VMk52ztZXaaYqKHKBK+ntv6JnNBOcsRClAhUH5wgbmcXPRQVVGrLcQncWr32wrme u1cVem0W38TaGczgj75rZgamQABOR2v2sV1uwl/bfc8DsNix+lZJ4/fvIDJf4yXQ30dWrvN2SVv Et9T1ZGdbHFTedZl9xk0eXGmCrYqw9WxYjGgM9JxWFEXVKCmj1QA6670TOfviWeUGBMiTmjwpOs UA/yUatHCFTvFDy2oQ5d6Qep3nv8PwnIoG5cPKb7XuUruS2ye7ANgGUqLEOylu8fXUu27+CqQQ1 GDUZb+BOMpasFQg== 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::330; envelope-from=imp@bsdimp.com; helo=mail-ot1-x330.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: 1778880224769158500 Signed-off-by: Warner Losh --- bsd-user/freebsd/os-file.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-file.h b/bsd-user/freebsd/os-file.h index aa8d8bda74..ea15ab25a1 100644 --- a/bsd-user/freebsd/os-file.h +++ b/bsd-user/freebsd/os-file.h @@ -110,7 +110,7 @@ static inline abi_long do_freebsd___specialfd(int type,= abi_ulong req, struct specialfd_eventfd evfd; struct target_specialfd_eventfd *target_eventfd; =20 - if (!lock_user_struct(VERIFY_READ, target_eventfd, req, 0)) { + if (!lock_user_struct(VERIFY_READ, target_eventfd, req, 1)) { return -TARGET_EFAULT; } =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=1778880354; cv=none; d=zohomail.com; s=zohoarc; b=Qhcw1OUBP/FvcFQCX/N7XLie7j8LFaD5xz4JqPni2vTHbsztmv3+OeMl9vpQa6IimONi1xlXaj9DpG1tlKUD7wIYuR0PWAGPpT/aj1VuOMbxbF090iVvamyfUkGqgwNYEVIp5ETeMs/guIAhnDqQN//UuOxNlwlrH1J0hMxtyko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778880354; 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=5JKTJrCCQNbgurNMjNugqjzzYIjsw8VYwvORH6EEIMU=; b=CQ0/wlbUpwSVTEdMIkNjYu2fBlfoXEUzu/bsJUXrf7R2nVjA6g9UDZCLCwOzIJ+B2Mf+BGxdcshe4B3ajSPLXsRDKfr3P2FVW1gtikfPhqb4uUVMrrBEoTFSAM0/d80saqBpjL6x44eCA3CaVQIYrVG+PCi5jWuf1D0UVf0JEzM= 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 1778880354812539.9572904332421; Fri, 15 May 2026 14:25:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wNzyD-0004db-AK; Fri, 15 May 2026 17:21:21 -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 1wNzy6-0003mg-Ai for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:14 -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 1wNzy4-0003GE-Od for qemu-devel@nongnu.org; Fri, 15 May 2026 17:21:14 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7d55b97f358so222361a34.3 for ; Fri, 15 May 2026 14:21:12 -0700 (PDT) Received: from rebo.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c6b29sm2185612a34.1.2026.05.15.14.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20251104.gappssmtp.com; s=20251104; t=1778880072; x=1779484872; 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=5JKTJrCCQNbgurNMjNugqjzzYIjsw8VYwvORH6EEIMU=; b=XUyZE4Z0maUrfxRmeueghzCy+M94C4f60KVXhz3mXEqPpvP9u0WD9/0627ZjdmT0qE OE1WnA35fiTKwRCTVduHUqv/o0zOKJpcPmGC8gTVVsdHhun3lpOIVaMR7k/68Zuhx2Mf 8fb3pBO71mmgdn4yXp4uh1g7CtbsRvKqi5uMPehCjiRLfEjz1/htPeofmxNK9yqspw4N KEceWNl/TMPiCczHQH3F1vyGtBzM1hF1LdmoBvgdCg5eskE+1x3xWU34dTO3Kpz3xSWJ AYiMhb04eMxaEyv6b7GIxLkUiCEiLsllOeK0C2C4cmZFbEY2deKu6wkySV6Kv7xFZCBw xDag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778880072; x=1779484872; 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=5JKTJrCCQNbgurNMjNugqjzzYIjsw8VYwvORH6EEIMU=; b=BBDG1AXGIipdkez3XK9HvDYkr7oWyZx66mEH0u1NYxuyoZSw+OdK2W9cl9f0R3cFsk +6gSN7ENK9HGJT/jvHP9WDMbPbgZCk0nhgsNMqBCio2LnLPf8AYcuasjBXo+plKrNs9t bxrLv264mUtcO4Vv2Z3takL4CqiSBuC5fwtQcAsCnBsmE2uVFsL19riCG3BDBT99G8jT uuUN6+0nEKXzD7/U5Ro+98MV4xvrVQXBQaDcJsTiPyZWEbb+gFyFBcvneWffQAg0Y4WU nxgndXO+XN9K/iRDynwOn87No4x1OFHysvhyMJ8yOeg3xLvVoxkktQxdCiVfhTyDBkTi 4JtA== X-Gm-Message-State: AOJu0YxE4a/KVYG/gZbR5J6LY/XrvXw7DAzIXGNfaScUJsntC61E4mTA nHZAAKF7dOrKi/esxE9UsWNrjHPzwAnb6r9/p0tudnhvStU4BQ+i+FTXEmaK6GorN4pvicUg4h7 TOLJnP6E= X-Gm-Gg: Acq92OGbsjhZxVHKtX2dRMjC/zBoxVFV8TnlEsEboXqUZLybC1o487y5H0UGwlfuXKx UKR9WyRWzr+RavLrG2oFppvZv0T5z2npl3ZGWo76eoL60AC+XFI2FntmyIsYtaDNgDHrTs1URbB MjkZq5NcM+tJ3HzkvoFMdcJ+CPsHoCsrC7HQ6QRyQ94vrdLvpgs2Psi9/C9Wcr5vrPMsspjl88N axL2a+KssijQQaKmD63gZnE0pIeKWQmWIzSASaa44wKmJj4qnz2KhnR8rzMEhFkS9Otz4/4gCMN /SC9cYgT+AhHPp/rE301hM+QsIv2aCeOcMVLvMXB4yvAYWYYlpPzlYAL+AE7ZCgqHpzBKcri7Pd riGnNJMg4LGAkXzlEpITNMqAjYh4igoXRGxSDjKjF3sknuTatcOh7/B0E6qpo2hu0tzriwXR92z 9pu5csIZpgVw== X-Received: by 2002:a05:6830:658d:b0:7d8:7d95:fa59 with SMTP id 46e09a7af769-7e4de6449d1mr3878579a34.0.1778880071683; Fri, 15 May 2026 14:21:11 -0700 (PDT) From: Warner Losh Date: Fri, 15 May 2026 15:20:05 -0600 Subject: [PATCH 66/66] bsd-user: freebsd_unlock_umutex: make flags 32 bits MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260515-misc-2026q2-v1-66-5438ca41b27a@bsdimp.com> References: <20260515-misc-2026q2-v1-0-5438ca41b27a@bsdimp.com> In-Reply-To: <20260515-misc-2026q2-v1-0-5438ca41b27a@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=985; i=imp@bsdimp.com; h=from:subject:message-id; bh=C2mdZ20iYFOeIHPDW/UIb9Tu4284XyAJBzHAKXVXiPo=; b=owEBbQKS/ZANAwAKAWwc0Sh9sBEAAcsmYgBqB43pfxaWkYqpt6w2/c1yFbkTuaFfPm/WlprPd lLUDloqP3OJAjMEAAEKAB0WIQQgNfiUsAqjz3zN4bdsHNEofbARAAUCageN6QAKCRBsHNEofbAR AFd7EADdBut/lsnGMrUhfpFRKR55XgfnW2HEBDNGEDYfiGexKuXO5Ex5RuGhMNxOo4oGGP3brTs WE9cxT9gMaypIBLuKJ1RbF1Ie76GnqeeHJ51LsxhkOpqsLXacj4UHDiJerivYx/aoaba0HJrVSc LM1oAcQ7DyERyKMV6PjiSe22B60Pll7etCb9M8b+1yiC3ykGv3Mly5pXAaAQGoe4OSlMdm3Ewdl fhMi6UR9Qbfsne5OCpKBe2AQo4DMVkRCCc2scvBfKNcKUtnj8297ioq+Luwvg5BLkfbdZ0k2wN9 BSYHIGH9ys+URdk1j29olB/k9l4cmKlwwa6Q8Ncbz7qRs9ab+ui0kUE3fZM/m+R2T0h48WHsbA3 ldLFAdoOdCj5QJpbH5luEfWafrmeCKeQqxz69GPu17Sff0fv/GzUZdJsgRrbvbrdAZxbQlXh3FJ Uw2BX9x0S3lFE5CTeT4cLWR8ZL2wdu40IneTpPl2UjrlcVkeBzexRIAgU1eUzCc8r4UU1hgZVsO GwZuatC36nJ7kyHxGKsYNe3LNlPvZ5q3bMlOom3poV892/a4rjjun0xGoIjRx/HACg69I481AVV vcx6dGedsSObp0imWbaSDFijA3ZQM+rsH6Mu59Vf/jJDpvWcurat9biV1EearBTm1XSmm2vc8rj 30xLFH0xmGqs9Hw== 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: 1778880355685158500 Since we're writing flags to m_owner, which is 32 bits, we need to have it be 32-bits. This also fixes the problem when we were trying to add the TARGET_UMUTEX_CONTESTED flag, which is bigger than 16 bits. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-thread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index 86dea0aea2..9ed5fade41 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -1033,8 +1033,7 @@ abi_long freebsd_unlock_umutex(abi_ulong target_addr,= uint32_t id) 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; - uint16_t flags; + uint32_t count, owner, *addr, flags; =20 if (!lock_user_struct(VERIFY_WRITE, target_umutex, target_addr, 0)) { return -TARGET_EFAULT; --=20 2.52.0