From nobody Mon Feb 9 04:44:15 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=1676590531; cv=none; d=zohomail.com; s=zohoarc; b=XeNGZhcZ3JAB7FrBz084yhT338TYX4A9WUPyg/nHbHtMd8M4pqjf2vmhDNgey/0kgk4KDWJfGDtIWPHaCfS0kXJDzz2UMIpvy9AS4rPBimlv5w0t8fo6d3DkXLMebK8eIs4Jl5OZi4E7ImHVFUR1E1AZU8SPINyq1UfnmEb7pRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590531; 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=EvM91y79wsNlj247LVT9SBZIPzmchHvn7spP1Bu6T5s=; b=T8GbZ3UUNnWUiXLqgiyhSRV0G3E3gwgd5XZj4AylQTaDj4DtNnxLp13T0nL5/DLgny63or0KeuhwcbMn5Svv2kHnvIqvRzqeTYi1nnofa3HN6yaldP/a4YrT1Az9Q1rk4a8anyaiIPS7X13ImoH0fWJyIm1i0W9JL088jRmVYZg= 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 1676590531733499.25453991124834; Thu, 16 Feb 2023 15:35:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006w-TG; Thu, 16 Feb 2023 18:34:06 -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 1pSnlK-0008UX-J8 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:02 -0500 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlI-0008Pc-Qc for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:02 -0500 Received: by mail-il1-x12c.google.com with SMTP id m18so838346ilf.10 for ; Thu, 16 Feb 2023 15:34:00 -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.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:59 -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=EvM91y79wsNlj247LVT9SBZIPzmchHvn7spP1Bu6T5s=; b=7k5QiAXq0ticqh0qUPNXOHL9z7p0sH33VJy//mIRmfuaX9ldG4uRgveEjGno+0J1r6 B0wAg9Fp3tmuJF64/RTZDh7iH2Y0SqLTG39eQ7d+38yuXbetTXlGV6yuFNOlEK9KnCEI qkk0P4DCgUmGonrk4fkicyr9ovtugtQw2ove1qmE9KcIipk790SrG7yq3RUaztq1kLB6 lP9nheqFqEWzrW7atmFlbtWc64uvUZfIlHWITSpeghOxYcjGgbHfpvHQFUBjMkJEwwBx dQR0Ig1D3RuYNZlTd0E3+ndUJWc03cO2N4KEFfM6Zgx3pwzjhu6PExb5cywsDmXYRrkb npvw== 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=EvM91y79wsNlj247LVT9SBZIPzmchHvn7spP1Bu6T5s=; b=1F71MNLfc57Lo3phgmy1dtYyPgrk9WgIjJkHyFQCjLazZnU/fYGynbrtVwYQkoSt9q YMVYFtibblrYi4ab1hRSgh8SEJ2h8ESGqMA4R4OCIgdu8StXpGmQOqPRYqf4y4UaORlN yh68DKR52GfUmMen4aRnKFfK+XDNSu1Xpu0+GoYL/RXZtpVNuirOFkgfCvIs5P98Wyob Tvx1igO0mbtzhqMzjpmb8sRZAdjHzGeo82T4xFBvcxFAPN9AKYg/qEk9PK+xNyIqaO96 iJUhUp+Wmt8pgPi1LEkB3y4S8O/La8XB6j2G7z/r30by1lZ600IHCdkoq50GS0ILAH5t /2tw== X-Gm-Message-State: AO0yUKXqEp9Il4k8vrmFJ2+aX2kPpY1iM4GCAa3pKw+xrXlEEFDBLm2z 2wGzcbXHZscAQIGuIvuvlOx+Qoeas/FRmJPi X-Google-Smtp-Source: AK7set+2jeVeS8E0fpEov3XM8ov9lY6os41vEyxDbuZHg7pFdrVftUYIvzjeY/jBqXkPEwp72ZKMKQ== X-Received: by 2002:a05:6e02:1e05:b0:315:4b70:8370 with SMTP id g5-20020a056e021e0500b003154b708370mr10223697ila.9.1676590439866; Thu, 16 Feb 2023 15:33:59 -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 , Stacey Son , Sean Bruno , Juergen Lock , Raphael Kubo da Costa Subject: [PATCH v3 05/11] bsd-user: Helper routines oidfmt Date: Thu, 16 Feb 2023 16:33:47 -0700 Message-Id: <20230216233353.13944-6-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::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.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: 1676590532026100002 Content-Type: text/plain; charset="utf-8" From: Stacey Son oidfmt uses undocumented system call to get the type of the sysctl. Co-Authored-by: Sean Bruno Signed-off-by: Sean Bruno Co-Authored-by: Juergen Lock Signed-off-by: Juergen Lock Co-Authored-by: Raphael Kubo da Costa Signed-off-by: Raphael Kubo da Costa Signed-off-by: Stacey Son Reviewed-by: Warner Losh Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 9b84e90cb32..1bf2b51820e 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -107,6 +107,38 @@ static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long ul) */ #define bsd_get_ncpu() 1 =20 +/* + * This uses the undocumented oidfmt interface to find the kind of a reque= sted + * sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to + * src/sbin/sysctl/sysctl.c) + */ +static int G_GNUC_UNUSED oidfmt(int *oid, int len, char *fmt, uint32_t *ki= nd) +{ + int qoid[CTL_MAXNAME + 2]; + uint8_t buf[BUFSIZ]; + int i; + size_t j; + + qoid[0] =3D CTL_SYSCTL; + qoid[1] =3D CTL_SYSCTL_OIDFMT; + memcpy(qoid + 2, oid, len * sizeof(int)); + + j =3D sizeof(buf); + i =3D sysctl(qoid, len + 2, buf, &j, 0, 0); + if (i) { + return i; + } + + if (kind) { + *kind =3D *(uint32_t *)buf; + } + + if (fmt) { + strcpy(fmt, (char *)(buf + sizeof(uint32_t))); + } + return 0; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { --=20 2.39.1