From nobody Mon Feb 9 00:42:29 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=1676590495; cv=none; d=zohomail.com; s=zohoarc; b=il3QwQAIg4P/5Wi4hVUq2AThZF8qmT+WojryutiibN6eELbciXCnvCXd4TrEwUJJW7NWnMnyoicQsnTRA3rwli/XYJAKTtgGc1WzNQuXh4AyvPnxJlbcpgqe4xhOIZ/CVHKb8+SpIAwtZWkT/nfEG11aZe/E0cNzjcVDoK9uDTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590495; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O+xNG+XIxDzZrfUzAM1AKP8QRLGF04ZsNMQklPyjAdQ=; b=O/DxAF2S13ylb19uMRQg+S6n6QM8Md976fgaf30uw+9RGsIr2jcIGA6cvDTV4lx4RhWPXfuq0SWpXR/18b0goRlQVmYi65hB15EkPLRvTrvDL6LviENj6aQ2HBWBpzdObgC9UVgfIRnIVNyZVZGHQLGPspA7nbtmJ3+1wKQ6Uuo= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676590495144249.87581816026; Thu, 16 Feb 2023 15:34:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlS-00009Y-43; Thu, 16 Feb 2023 18:34:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSnlQ-00007y-D2 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:08 -0500 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlO-0008Pt-8G for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:08 -0500 Received: by mail-il1-x133.google.com with SMTP id v13so1422643iln.4 for ; Thu, 16 Feb 2023 15:34:05 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id y7-20020a02a387000000b00346a98b0a76sm934816jak.77.2023.02.16.15.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O+xNG+XIxDzZrfUzAM1AKP8QRLGF04ZsNMQklPyjAdQ=; b=r1X5vjJOspIs0Fl80DHWrWQz/WLfbjM1rjYRKjBSjySclUPpGOlWfiZ2Vh/9vG31Pz dtcUjU2lfMksAlqhUN6JbBU6u9b0q2goqDyHOsDwIW4mtOUnUnlYqsGp8DYJ/6NmeUim JEscLLJ1robmb5VgTmqTKiYd+t+9yVtbnAVetsRLtlHBIU4JBLZ14cibkk/H1RLOqVq2 E0j4pRuSaBMsIamM1iMSEQRBqtTMoSHlcXatx/12LyeDrILwxod+oVLalRG8ceG/OisC IXRQVe73UDz3glfvk497LXP7rQLievdG2Jy/IWLx6QfXBs3chu8Fiz3Llzw00Ub9VZuM c9hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O+xNG+XIxDzZrfUzAM1AKP8QRLGF04ZsNMQklPyjAdQ=; b=rQL1Dh5INzHmCh7vQarebvRyh7JrtN9DY6JuhG2NwrcmpERQTjOfn3w6UItlET5UFT XCySdPKg/mnJhP7Mbv103JYEptd3R4DFCb2WmJHmfRzQq9u/eyvB4Q/a2YEsOFCg/3bl QyInM7r4c3Uuojj6wFRLmpAFF+CA4sRD/WeUMSiItMWvLPAIRsf4Rs25erl9QRIX5hzh Zc4EIQVLwtKnSYk8rNeFQ+z8nCpeSCiE3qyyqF9JewRi4ofa6FZqICCIrR57+5PYi7Y0 oXfgMCi/UFxdJxv4OCr7FWcc2JyhmgKJTO11uMN60I9grGN3Ir3ImF1hWO7aIeD7swwO Lz5g== X-Gm-Message-State: AO0yUKUtBjdZpKK+vitgu+51b3w+RumD1X49tuv3V5ItAyZk4zva7pPt RjcMpr5SsWhK2JcaxSEMLundqvPFokeTN4yY X-Google-Smtp-Source: AK7set8+14hLGUJ63avHF2f50tpGcP7pqeSg6ce5ZLFtRPmUZUx+upnLZPJoXAIUxl3cX2eqK5TmIQ== X-Received: by 2002:a05:6e02:2185:b0:312:7bbf:94f5 with SMTP id j5-20020a056e02218500b003127bbf94f5mr8473610ila.3.1676590445233; Thu, 16 Feb 2023 15:34:05 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , richard.henderson@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , f4bug@amsat.org, Warner Losh , Paolo Bonzini , Thomas Huth , Kyle Evans , Juergen Lock , Stacey Son Subject: [PATCH v3 10/11] bsd-user: do_freebsd_sysctl helper for sysctl(2) Date: Thu, 16 Feb 2023 16:33:52 -0700 Message-Id: <20230216233353.13944-11-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216233353.13944-1-imp@bsdimp.com> References: <20230216233353.13944-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.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: 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.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1676590497481100003 Content-Type: text/plain; charset="utf-8" From: Kyle Evans Implement the wrapper function for sysctl(2). This puts the oid arguments into a standard form and calls the common do_freebsd_sysctl_oid. Signed-off-by: Kyle Evans Co-Authored-by: Juergen Lock Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 56 ++++++++++++++++++++++++++++++++++- bsd-user/freebsd/os-syscall.c | 4 +++ bsd-user/qemu.h | 2 ++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1464e64428f..f07ae7da740 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -249,7 +249,7 @@ static inline void sysctl_oidfmt(uint32_t *holdp) holdp[0] =3D tswap32(holdp[0]); } =20 -static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPUArchState *env, int= 32_t *snamep, +static abi_long do_freebsd_sysctl_oid(CPUArchState *env, int32_t *snamep, int32_t namelen, void *holdp, size_t *holdlenp, void *hnewp, size_t newlen) { @@ -472,6 +472,60 @@ out: return ret; } =20 +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t nam= elen, + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newle= n) +{ + abi_long ret =3D -TARGET_EFAULT; + void *hnamep, *holdp =3D NULL, *hnewp =3D NULL; + size_t holdlen; + abi_ulong oldlen =3D 0; + int32_t *snamep =3D g_malloc(sizeof(int32_t) * namelen), *p, *q, i; + + /* oldlenp is read/write, pre-check here for write */ + if (oldlenp) { + if (!access_ok(VERIFY_WRITE, oldlenp, sizeof(abi_ulong)) || + get_user_ual(oldlen, oldlenp)) { + goto out; + } + } + hnamep =3D lock_user(VERIFY_READ, namep, namelen, 1); + if (hnamep =3D=3D NULL) { + goto out; + } + if (newp) { + hnewp =3D lock_user(VERIFY_READ, newp, newlen, 1); + if (hnewp =3D=3D NULL) { + goto out; + } + } + if (oldp) { + holdp =3D lock_user(VERIFY_WRITE, oldp, oldlen, 0); + if (holdp =3D=3D NULL) { + goto out; + } + } + holdlen =3D oldlen; + for (p =3D hnamep, q =3D snamep, i =3D 0; i < namelen; p++, i++, q++) { + *q =3D tswap32(*p); + } + + ret =3D do_freebsd_sysctl_oid(env, snamep, namelen, holdp, &holdlen, h= newp, + newlen); + + /* + * writeability pre-checked above. __sysctl(2) returns ENOMEM and upda= tes + * oldlenp for the proper size to use. + */ + if (oldlenp && (ret =3D=3D 0 || ret =3D=3D -TARGET_ENOMEM)) { + put_user_ual(holdlen, oldlenp); + } + unlock_user(hnamep, namep, 0); + unlock_user(holdp, oldp, ret =3D=3D 0 ? holdlen : 0); +out: + g_free(snamep); + return ret; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index e00997a818c..20ab3d4d9a1 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -494,6 +494,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , 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); + break; + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ ret =3D do_freebsd_sysarch(cpu_env, arg1, arg2); break; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 0ceecfb6dfa..c7248cfde6f 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -252,6 +252,8 @@ bool is_error(abi_long ret); int host_to_target_errno(int err); =20 /* os-sys.c */ +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t nam= elen, + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newle= n); abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2); =20 /* user access */ --=20 2.39.1