From nobody Mon Feb 9 04:14:13 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=1676071437; cv=none; d=zohomail.com; s=zohoarc; b=Vhf5k4cvJx2uxxZuJM5Yl2JQNytzAjRFq58gzoeWSKEjEVFS3GrS+P2qbMih+A2+NJSzYZ37KsYSMN0cCpxoHegWGBHnGMF386Ma5Tw2zz7pcDQq75+uUsPvVRjRrX8KnrWGCzSFHePOARm0fst2SDUoAr6LVmoHie0wxYhOC3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676071437; 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=tDw5vzZ3WF8Nj3x4pvbSGQIQ3uW/UgV5IIjQeiqfa50=; b=jFosACui4PtZyMn3fTWUOMkUnM3YaiUdtCHNPlwENcdk5YkAtlwF7+pCX70INWin9qmRFVvg58ACK/9xpk8aCHgUoyU6lVd7i7Pm8ulKj0/7elqR2abvxKds/HSohqC9Eg4LAGec2D7CJHr/8B6p1H4vloF9ilVO0TmXFqCsUiA= 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 1676071437067149.74201032314795; Fri, 10 Feb 2023 15:23:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcjD-0007Bl-OG; Fri, 10 Feb 2023 18:22:52 -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 1pQcj5-0007A7-RF for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:43 -0500 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQcj3-00052w-NM for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:43 -0500 Received: by mail-il1-x12b.google.com with SMTP id v15so2901772ilc.10 for ; Fri, 10 Feb 2023 15:22:41 -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 k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:39 -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=tDw5vzZ3WF8Nj3x4pvbSGQIQ3uW/UgV5IIjQeiqfa50=; b=kCGDjsUWQekmddRA6EUkNZiJ7u/9kTeCWCWZWms8k5yIKa+kIf2SgQQoGzY+ubNu2I SyCnJi8YvZfzMIMQXLukBHLyqe8fUSfUNibKqzp82Oxr/0VEKYrbRkCWydoZ2/zcnmiT UfZm2W+ZIoY8B9ATkH0AWi7ljH00ZoKSaZxK2GAEsqCA063W+IaVIUFaybHul909VMk5 p3YnU/7hSLTYUzDbWhJhdEu/GoxrUnj47XQ470Mmjq8jLS7q5TZpTqyTqFMz63yF6imj S/wBBIF+EkBtyuJq3+jb7VdltyMy16bVzDjWrOkHSfS4/+N3LxlHcxAsUCqxf8TGIV54 Xy+Q== 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=tDw5vzZ3WF8Nj3x4pvbSGQIQ3uW/UgV5IIjQeiqfa50=; b=YF1vdKYZuvyYyuTQlx68uU5CnddzXA8EIoqeCE9e1lD1fkn83KnqisVdFgo1avpjIE O1N5jfcg5j0ePDWHwGMRCqy3oNrBIPfPv/GLs3VdUR2OzT03zQK3y2X+Jy0EhnIXxJnT h3IFZx+q4xEZbRZ+05Ck5Lmbox4eIZzsAECGLI8HClE9BBEEgoBC7ZazCqqwT+ePYlce +L74RTKp6JokWMFPUjZOo16+jKbr94hhbOQIvD8egKENhz+VjlkVJg0VGPUpsb9UY9M3 BqWm+P7LNN6XO+aVsUrNoIis3GOek1UCh5VAQdGpGBJY/jjrqiF1wbcq39i35mdbJWjw spMg== X-Gm-Message-State: AO0yUKVJtlZYhtpCNeUhqDQMSXNsEGUxOhQRAod4twyLpZuq0bDaal3R EaMHD+KLGYffNED+Us5g7ixGJZWywbCsf2js X-Google-Smtp-Source: AK7set/8WY2+Y1nKq2hf/c0LCegKVPhkm9/ay5CNfvIA6cu1mdNV04Qw8PFD5CfhFdbmbRPSDtkbgQ== X-Received: by 2002:a05:6e02:2141:b0:30c:2b07:547c with SMTP id d1-20020a056e02214100b0030c2b07547cmr19315922ilv.26.1676071360020; Fri, 10 Feb 2023 15:22:40 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Juergen Lock , Stacey Son Subject: [PATCH 6/9] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Date: Fri, 10 Feb 2023 16:18:26 -0700 Message-Id: <20230210231829.39476-7-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-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::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.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: 1676071438807100011 Content-Type: text/plain; charset="utf-8" From: Juergen Lock do_freebsd_sysctl_oid filters out some of the binary and special sysctls where host !=3D target. This commit focuses on the simple sysctls that can be done in a few lines. Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Warner Losh --- bsd-user/freebsd/os-sys.c | 212 ++++++++++++++++++++++++++++++++++++++ bsd-user/qemu.h | 5 + 2 files changed, 217 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index ac5ab9b17bc..a8fb29f36b7 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -133,6 +133,218 @@ static inline void sysctl_oidfmt(uint32_t *holdp) holdp[0] =3D tswap32(holdp[0]); } =20 +#define bsd_get_ncpu() 1 /* Placeholder */ + +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) +{ + uint32_t kind =3D 0; +#if TARGET_ABI_BITS !=3D HOST_LONG_BITS + const abi_ulong maxmem =3D -0x100c000; +#endif + abi_long ret; + size_t holdlen, oldlen; + + holdlen =3D oldlen =3D *holdlenp; + oidfmt(snamep, namelen, NULL, &kind); + + /* Handle some arch/emulator dependent sysctl()'s here. */ + switch (snamep[0]) { +#if defined(TARGET_PPC) || defined(TARGET_PPC64) + case CTL_MACHDEP: + switch (snamep[1]) { + case 1: /* CPU_CACHELINE */ + holdlen =3D sizeof(uint32_t); + (*(uint32_t *)holdp) =3D tswap32(env->dcache_line_size); + ret =3D 0; + goto out; + } + break; +#endif + case CTL_KERN: + switch (snamep[1]) { + case KERN_USRSTACK: + if (oldlen) { + (*(abi_ulong *)holdp) =3D tswapal(TARGET_USRSTACK); + } + holdlen =3D sizeof(abi_ulong); + ret =3D 0; + goto out; + + case KERN_PS_STRINGS: + if (oldlen) { + (*(abi_ulong *)holdp) =3D tswapal(TARGET_PS_STRINGS); + } + holdlen =3D sizeof(abi_ulong); + ret =3D 0; + goto out; + + default: + break; + } + break; + + case CTL_HW: + switch (snamep[1]) { + case HW_MACHINE: + holdlen =3D sizeof(TARGET_HW_MACHINE); + if (holdp) { + strlcpy(holdp, TARGET_HW_MACHINE, oldlen); + } + ret =3D 0; + goto out; + + case HW_MACHINE_ARCH: + { + holdlen =3D sizeof(TARGET_HW_MACHINE_ARCH); + if (holdp) { + strlcpy(holdp, TARGET_HW_MACHINE_ARCH, oldlen); + } + ret =3D 0; + goto out; + } + case HW_NCPU: + if (oldlen) { + (*(int32_t *)holdp) =3D tswap32(bsd_get_ncpu()); + } + holdlen =3D sizeof(int32_t); + ret =3D 0; + goto out; +#if defined(TARGET_ARM) + case HW_FLOATINGPT: + if (oldlen) { +#ifdef ARM_FEATURE_VFP /* XXX FIXME XXX */ + if (env->features & ((1ULL << ARM_FEATURE_VFP)| + (1ULL << ARM_FEATURE_VFP3)| + (1ULL << ARM_FEATURE_VFP4))) + *(int32_t *)holdp =3D 1; + else + *(int32_t *)holdp =3D 0; +#else + *(int32_t *)holdp =3D 1; +#endif + } + holdlen =3D sizeof(int32_t); + ret =3D 0; + goto out; +#endif + + +#if TARGET_ABI_BITS !=3D HOST_LONG_BITS + case HW_PHYSMEM: + case HW_USERMEM: + case HW_REALMEM: + holdlen =3D sizeof(abi_ulong); + ret =3D 0; + + if (oldlen) { + int mib[2] =3D {snamep[0], snamep[1]}; + unsigned long lvalue; + size_t len =3D sizeof(lvalue); + + if (sysctl(mib, 2, &lvalue, &len, NULL, 0) =3D=3D -1) { + ret =3D -1; + } else { + if (((unsigned long)maxmem) < lvalue) { + lvalue =3D maxmem; + } + (*(abi_ulong *)holdp) =3D tswapal((abi_ulong)lvalue); + } + } + goto out; +#endif + + default: + { + static int oid_hw_availpages; + static int oid_hw_pagesizes; + + if (!oid_hw_availpages) { + int real_oid[CTL_MAXNAME + 2]; + size_t len =3D sizeof(real_oid) / sizeof(int); + + if (sysctlnametomib("hw.availpages", real_oid, &len) >=3D = 0) { + oid_hw_availpages =3D real_oid[1]; + } + } + if (!oid_hw_pagesizes) { + int real_oid[CTL_MAXNAME + 2]; + size_t len =3D sizeof(real_oid) / sizeof(int); + + if (sysctlnametomib("hw.pagesizes", real_oid, &len) >=3D 0= ) { + oid_hw_pagesizes =3D real_oid[1]; + } + } + + if (oid_hw_availpages && snamep[1] =3D=3D oid_hw_availpages) { + long lvalue; + size_t len =3D sizeof(lvalue); + + if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) = =3D=3D -1) { + ret =3D -1; + } else { + if (oldlen) { +#if TARGET_ABI_BITS !=3D HOST_LONG_BITS + abi_ulong maxpages =3D maxmem / (abi_ulong)getpage= size(); + if (((unsigned long)maxpages) < lvalue) { + lvalue =3D maxpages; + } +#endif + (*(abi_ulong *)holdp) =3D tswapal((abi_ulong)lvalu= e); + } + holdlen =3D sizeof(abi_ulong); + ret =3D 0; + } + goto out; + } + + if (oid_hw_pagesizes && snamep[1] =3D=3D oid_hw_pagesizes) { + if (oldlen) { + (*(abi_ulong *)holdp) =3D tswapal((abi_ulong)getpagesi= ze()); + ((abi_ulong *)holdp)[1] =3D 0; + } + holdlen =3D sizeof(abi_ulong) * 2; + ret =3D 0; + goto out; + } + break; + } + } + break; + + default: + break; + } + + ret =3D get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newl= en)); + if (!ret && (holdp !=3D 0)) { + + if (0 =3D=3D snamep[0] && + (2 =3D=3D snamep[1] || 3 =3D=3D snamep[1] || 4 =3D=3D snamep[1= ])) { + switch (snamep[1]) { + case 2: + case 3: + /* Handle the undocumented name2oid special case. */ + sysctl_name2oid(holdp, holdlen); + break; + + case 4: + default: + /* Handle oidfmt */ + sysctl_oidfmt(holdp); + break; + } + } else { + sysctl_oldcvt(holdp, &holdlen, kind); + } + } + +out: + *holdlenp =3D holdlen; + 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/qemu.h b/bsd-user/qemu.h index 0ceecfb6dfa..e24a8cfcfb1 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -252,6 +252,11 @@ 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_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); =20 /* user access */ --=20 2.39.1