From nobody Fri May 17 12:14:54 2024 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=1676590496; cv=none; d=zohomail.com; s=zohoarc; b=WsPLibuu6KpfexAu2015Ucd2kcJD1SGB1K2EDh/VDBWLoy+BhWpUU9INH0koETappfRAASavYOAVPg3qFYkGrBRNCaDDgzKbGIa/HZQjC//Plz9StQjF+hlW7DyMqzrJsKR79KqDEWR8pG7i4hxpjFtgSZM1nRGRTzDtv5KlQfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590496; 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=v82U4AeojucC3DQqhT5F05E7FmGdLYXG/H9YwykhwGc=; b=lRQxybWj0DwjGdZ75aXrzyTs6IAZwskJ+WrJ3KIs1N9nytHBSFokgB5E500Itx+1JhI73D0CvKbzIXQHqiiRfRODUmKBSAw1kE9zoUIAFzWCF6ENaaDhZP+klV3PcIgdoyWVpSRMDSShMhQwIC0SDuhCbX4cbuv5Iw2L349f69k= 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 1676590496779457.18412931462274; Thu, 16 Feb 2023 15:34:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlL-0008Ub-HB; Thu, 16 Feb 2023 18:34:03 -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 1pSnlG-0008SQ-Ip for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:33:58 -0500 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlE-0008Ph-Pp for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:33:58 -0500 Received: by mail-il1-x130.google.com with SMTP id v13so1422503iln.4 for ; Thu, 16 Feb 2023 15:33:56 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:54 -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=v82U4AeojucC3DQqhT5F05E7FmGdLYXG/H9YwykhwGc=; b=zKdv/Pn8yayE8JFx3+Wz7/lkpVBdRFXuRrc2u5CAet2xgnWEts63iGIpzT7hvaB0zG 9LxgJdiTZ9KJi35LvBYycgPZEu/04i6oG1V0WGX+6vciOjd4mcTylqeMLrdupvKtJfqm mCdWC/b9bjuNeMwgThAJoRcSOo+QH0oO11z1R/1TSu/BrXjTAdU741Wcg5+OPiD3qoPz 0qfYvoZGzzzdmHLNd/PsojF2OQv+y3A23WtiCzvr+t+2d4ZfJMGRvoXHQQbkYUde9ebZ h25j5qt+ST33wbNyj1MMCAGLfcIzR3DCNq8G6ln35tRLDuskosTCrW2lcoM+ennr6jeR bzdQ== 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=v82U4AeojucC3DQqhT5F05E7FmGdLYXG/H9YwykhwGc=; b=DYWvauv29U3b3lb6GCX5o7TOuVjfAegTub30KFNWY8vXr+K06rC9RsjzPoA6aBiyul keHeWvDspjIL2KTLNq7VL+JrCUjsSy6YQy+1tSbSXN6ZDTtnM3Awn0BCGQr8plRObFHB gggjhsKs11qjX2h9x9086Wi5svlywyV0k/IAjhnmscg8+PU3VvsliTHhOKlHbKsCTLdk OBAy0KHDpcjbA0jfmVIiuNZMNjUTkBaWmnO/tvxCx2EA571Xfdpnnz5KQftiXV5ZZemZ Skvjz1mtOXui2apvexpRJdhlNFR+n9D1beC9OsYUsla1bpVFlXBcNkx+eqxsilCO0Pjn 9lAw== X-Gm-Message-State: AO0yUKVkN/Fx1PGWnPk4Bj9I4leGmLpweqe7ZvxScZTeD9+tbeGeXTJb dhojAuaokDr4Nq16nwAOqnPYpYVRnp14bRBm X-Google-Smtp-Source: AK7set8h90//KLnQjJX+jwtTUl+OZnEIQFk2uPuD3qwqWYnMWtfDVujWRUTVZLZVIni6D94H7QtbeQ== X-Received: by 2002:a05:6e02:1e02:b0:315:29ff:da7f with SMTP id g2-20020a056e021e0200b0031529ffda7fmr7591716ila.11.1676590434945; Thu, 16 Feb 2023 15:33:54 -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 , Doug Rabson Subject: [PATCH v3 01/11] bsd-user: Don't truncate the return value from freebsd_syscall Date: Thu, 16 Feb 2023 16:33:43 -0700 Message-Id: <20230216233353.13944-2-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::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.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: 1676590497547100005 Content-Type: text/plain; charset="utf-8" From: Doug Rabson System call return values on FreeBSD are in a register (which is spelled abi_long in qemu). This was being assigned into an int variable which causes problems for 64bit targets. Resolves: https://github.com/qemu-bsd-user/qemu-bsd-user/issues/40 Signed-off-by: Doug Rabson Reviewed-by: Warner Losh [ Edited commit message for upstreaming into qemu-project ] Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 57996cad8ae..b4a663fc021 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -512,7 +512,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi= _long arg1, abi_long arg8) { CPUState *cpu =3D env_cpu(cpu_env); - int ret; + abi_long ret; =20 trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,= arg7, arg8); if (do_strace) { --=20 2.39.1 From nobody Fri May 17 12:14:54 2024 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=1676590515; cv=none; d=zohomail.com; s=zohoarc; b=JrVOKY25F21NIRV0YkqifruUM69UV6oNJR4syekznOqn82tqkW8miMFCewNHBxnWzFXsmXLO0Bcb+oRLsBJuTjocqyQhsND57ZAto4oyavlX5M9I8j7I606Zi0h3ZgKCCevp4gs4D08iZygsA7l5s495H6UzS9GDkUwHxGiR8y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590515; 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=i/ho+o97t3oUvsCX6/tWPXAhBUu89VuwLZO+3r6EySU=; b=ezxFZ0D5K3NsoyHtmgWOZiA0hFFl/LUlT78SU+yzfmwF90s7FNv+5VA9u79hn2cFgj2L+As22N6jJjxmM5L8p/ue1X3BSMiOngKkKONI6aGLrf/ZPAiIlBwEYXlMY1IUtAVt5bZaqwvCYU7CrslDGM9shpfsO2kyHPLV1b1XzpU= 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 167659051533139.92168106746965; Thu, 16 Feb 2023 15:35:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlN-00004u-4K; Thu, 16 Feb 2023 18:34:05 -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 1pSnlH-0008TT-Uf for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:00 -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 1pSnlF-0008Pt-Mq for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:33:59 -0500 Received: by mail-il1-x133.google.com with SMTP id v13so1422522iln.4 for ; Thu, 16 Feb 2023 15:33:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:55 -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=i/ho+o97t3oUvsCX6/tWPXAhBUu89VuwLZO+3r6EySU=; b=wiE0LN3y8BKkKs8xy87FAv2iMZzyCAWmNAs+w3jnfDJ1OSprBEW/4DOqf8ugdXKveX OPITdnidZM5T/j6m5KTSX/iqzj3sINr3E3yJK1NxM6Ly9pvzBv6OkTXVuY09kcNoQEFr BUEjD/HnZz6IYeUqTnS+oOo5uMy70N4Vff5u/QPcQcXtGUv4ydL0KIHCTyyAzCUiyV4L 8e1pQptIYuluzQBFXKf8R6CIJqFcXuW4OITyLHkKhiCw6mZ8B3Za515ICU9OvFZ//v/p GhMUfdes3+PVblOUNMHQPUPCgPP/vti8Ou4MaFT5L/bkQwfPo0WcimcDIB/o19rRtY3s ZnEw== 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=i/ho+o97t3oUvsCX6/tWPXAhBUu89VuwLZO+3r6EySU=; b=LAGXWKKd1xwSGR5tVaZJyVFXGvdUYOg+EYURKSGkgNUCBanZHFPPW2tSKJlY6MPde5 Nk2DBGj9Y5F6KD1R/icrq+uAztz+UmZunyaQ6J2wzFt6QiAso2TlI1AFN3FLbIGHvkzH 5LsUe7mu548+HQsOSimF1YiKhXhF0T4Ek/f3VTJrv+sD0nYBA8I/faWSCVKqO6AlLoF1 bN+T+H5fbA1yu8dIx6nvcObUZ7lRQBOt52U369gL95dr76lXUDxhO0XWMwDqiGjgCWJd W+OQywFso+73mfGb6LUU5YUAVzBVoLzzooHPGcioHTTM4DDOKTzRz8Yr/Vahi4EKJlA0 h4Gg== X-Gm-Message-State: AO0yUKW8nl/mtitCBUvptANR+7fUnkf8G0HloHtuktG2PczqzccwJcAe +y+uVDc3sjEseJmL/7fw+noiRmNHq+5NVJaX X-Google-Smtp-Source: AK7set9wFCc8TRtXuUC/5Ce+IzLz9p4AA+HzrtoHvcplp4BTsm6ZkHi8/pqD/Ca6Dta1Mm98EGMWig== X-Received: by 2002:a05:6e02:20c4:b0:310:fd98:1cc2 with SMTP id 4-20020a056e0220c400b00310fd981cc2mr6832298ilq.13.1676590436230; Thu, 16 Feb 2023 15:33:56 -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 Subject: [PATCH v3 02/11] build: Don't specify -no-pie for --static user-mode programs Date: Thu, 16 Feb 2023 16:33:44 -0700 Message-Id: <20230216233353.13944-3-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: 1676590515875100001 Content-Type: text/plain; charset="utf-8" When building with clang, -no-pie gives a warning on every single build, so remove it. Signed-off-by: Warner Losh Reviewed-by: Alex Benn=C3=A9e --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 64960c6000f..eb284ccf308 100755 --- a/configure +++ b/configure @@ -1313,7 +1313,7 @@ if test "$static" =3D "yes"; then error_exit "-static-pie not available due to missing toolchain support" else pie=3D"no" - QEMU_CFLAGS=3D"-fno-pie -no-pie $QEMU_CFLAGS" + QEMU_CFLAGS=3D"-fno-pie $QEMU_CFLAGS" fi elif test "$pie" =3D "no"; then if compile_prog "-Werror -fno-pie" "-no-pie"; then --=20 2.39.1 From nobody Fri May 17 12:14:54 2024 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=1676590542; cv=none; d=zohomail.com; s=zohoarc; b=B5t667M3CDFcUlGnUr3kWWRdEIWTYnwOmb3V69lLaIA/DGaXduUnWXYmz9r6WkRclSDyXNs+Vs19qj/CILcFiJCfZaEc3itlbno9bIKUyRYmv9uFn9GxzQ3UwhoHoWgJppk+Fu/z9oSD8wUPwxCD5sLKSwDcR1bvMAdHIz6Pa6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590542; 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=UDKo+pEqLr25ECZFRWghhYmC5CZ9G4l3ZCThpSQaZZ4=; b=aL0s6i/lSHxFYVf4IPAA7p5TlTSQvpOqZ2rhv+Aq7vqhNyMZa1hukTBWxAkuy4FihqLGCMJCH2Z53BfH8SHe0kZbNA6lqUNaUGQIYQd0JDcvQX1BG//5eGbL+zWnGQ7Nk2zAFJ4yCcZQZIK4VFM6wmzae1E2R2esvUB2b5/FXTU= 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 167659054271680.63531768296946; Thu, 16 Feb 2023 15:35:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006C-4y; 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 1pSnlJ-0008UK-A1 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:01 -0500 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlH-0008QE-CK for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:00 -0500 Received: by mail-il1-x131.google.com with SMTP id j12so1075454ila.6 for ; Thu, 16 Feb 2023 15:33:59 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:56 -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=UDKo+pEqLr25ECZFRWghhYmC5CZ9G4l3ZCThpSQaZZ4=; b=41vk+tWM/pdvJBVS6Iyh7OGaTVfZ4wD+WXTssRJ2pHuzV83CFgwyBc6c9+Y8BJ6fjE y+ILjYfcaOaFd/AXqhKpeU/QUMvqlSG5b/6XqF60rJg3F18rxojhlEUEx3iTirIo9UbB ZHNVXv/e2os7ULMEk1fT3OV1hb1w2sknqPeXs2IsAkzRYPr3Wi7JMMC8plTpLzEon6wM ABqVxJdRXtMPRNfOOHsUyUDJVtURgrTHtnwl8ppJUOM+94wJB8r/nouqeWpsjnXUwrLW +3LzOWXU0aAuIS4JUwrE4p4pTgMkjJR1cSnvguI37Z70m3cBFghvxxgLScx2IGoMBXnC hOiQ== 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=UDKo+pEqLr25ECZFRWghhYmC5CZ9G4l3ZCThpSQaZZ4=; b=gER+b11vIITOt46L2JfiL+lz+2MBob+eSXf2hyeJ0Dks3wJkqhgDOZyBiiM5KyK24n dRWb8icEUzm6Mkheo0Stpt9T7CZz0PljXwxG5bdPesnbj/waQzVmEkmx5mWQIzQVnCoR of83mEobj+Y3dWAD6NfV2n40uBYWR/H0KnZdQ6a4kkCcAv4tCG2tsAZ4Bgll6Vjap13P +G10dNYvrAAXOgEzR1B6LrK9pxdKl5LiQFTwddKl9pl8+OOivv6qBQ05hV8qe735kdNv vX+tZvSSe4LCLyG0nX0bbOCljOjLKa0OEW7xnsQh4FGihoUWl2S30Z3Ys7bB5cH1WJ5I 5FfQ== X-Gm-Message-State: AO0yUKXJWMAL8rYTxsp9vZIW2HQxEgE4dR+ZzYmHIs+sfelZEv6kLMKx vxRQ/0RNngK8xRFdBc4erqrrog3qXP2YW2bD X-Google-Smtp-Source: AK7set8gomZ0aX49pS5dFfuZUrBCsUz9anrh6NHck/SlKGEhEjUqEIV/+HnlEwV+OqHwiE9I9N4dlA== X-Received: by 2002:a05:6e02:1c29:b0:315:7004:3e69 with SMTP id m9-20020a056e021c2900b0031570043e69mr7183896ilh.13.1676590437659; Thu, 16 Feb 2023 15:33:57 -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 , Juergen Lock Subject: [PATCH v3 03/11] bsd-user: Add sysarch syscall Date: Thu, 16 Feb 2023 16:33:45 -0700 Message-Id: <20230216233353.13944-4-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::131; envelope-from=imp@bsdimp.com; helo=mail-il1-x131.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: 1676590544121100003 Content-Type: text/plain; charset="utf-8" From: Stacey Son Connect up the sysarch system call. Signed-off-by: Juergen Lock Co-authored-by: Juergen Lock Signed-off-by: Stacey Son Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index b4a663fc021..e00997a818c 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -491,6 +491,13 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, ret =3D do_bsd_undelete(arg1); break; =20 + /* + * sys{ctl, arch, call} + */ + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ + ret =3D do_freebsd_sysarch(cpu_env, arg1, arg2); + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret =3D -TARGET_ENOSYS; --=20 2.39.1 From nobody Fri May 17 12:14:54 2024 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=1676590533; cv=none; d=zohomail.com; s=zohoarc; b=DljP5JGX7q61afxyIuJbF/T6GZhkzr3mHcvGATKmASMe2Vsv+Mgwx731ydV9UMxIW7Q+nVTGupMTE7wOUdR4XMHhy8eFUOy0UXzHZ6LGl884g9A1KJqbsqy0GYQ/Ra3gQSBLqbTTdXAFkUUP9gDgMtzVQC21o2j6LQ7SwoSeNDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590533; 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=jcQ3VoTbe+79hYfj0QV+d8UTWb9sjCudpysXyieHUGQ=; b=GDZGZejfaMDjcu4WgdNtRWMGnb+k2eRCuJz9W/LSP9yTq/oaCNcV8PYYkYIA8+RatK/7NN1lf63qbtROSnA53Iabb+2r3hvHsbNPVYpKF/UNELU1/p30JA78Wm2cwSAxN2XVxM0PV9zXtuanHMztKPi+modIrJxmvtsqlsJp5I0= 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 1676590533022853.9329570452103; Thu, 16 Feb 2023 15:35:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlR-00008g-3V; Thu, 16 Feb 2023 18:34:09 -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-0008US-4i for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:02 -0500 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlI-0008QO-9a for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:01 -0500 Received: by mail-il1-x12f.google.com with SMTP id h7so959166ila.7 for ; Thu, 16 Feb 2023 15:33:59 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:33:58 -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=jcQ3VoTbe+79hYfj0QV+d8UTWb9sjCudpysXyieHUGQ=; b=ET4p04pioKHHyivHk3PnLifrt5iLPOfCGyessSvMZxwauirg+UYemDvcPNqTriKbCb Zcu/dJZQYe+YG8OhILYT4bK62QKdget3skbxT8fGjTeRVXse0rgrGxKntRpD/POcfY7V nRGFJfhotG10bNyTM2eotXVXOba4sGcWtAzbjKDBBZHxJHAXx07s12gB556EJufpHuSh yu01a7cMSpsxawR8w2nNjNaIj4iLnKs9S27bqB/tPwTPCWGs96sFXxzdMMGvUFCZj8q0 0dddxHx3m9+bKL1nM33siNoZnJb2pvHwCtd7vZtT+eVnuxLf5TpyAL9Bed76wimr0D30 F56w== 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=jcQ3VoTbe+79hYfj0QV+d8UTWb9sjCudpysXyieHUGQ=; b=OCF3j8sGxA7UPUb1YtbRGBIMlhiE3iEeV+Ej/RdsMbxb5Fxocw0sCGvVFhxuGg92z4 M3QvW/x0XGh32T/xM9fogminjbKHNvEq3iDGmoYLyLRG1U/zSe6z6mkg1DZsmS8vXBz/ Ev4QMgC8mjML1455q5MhBpihQUCXnw49FEC4ewyo/79ih4MSC1cAqSIwm3e52eCfFbj1 evKxkLSFjCM8rezxZNhvKL1idCRQYsLogMU8UfsZCG8Ra3JVe44QgEUw4bZjKuUc1QaY d/ecTNQDajGwaAsb0RXT43FAA4YvPOvH9ny2zyC8QG7O/4nlOEcXm8E3A9A2GE3SSnJi 8n+g== X-Gm-Message-State: AO0yUKWxu3Ofl1FIK4uAEtiO+H6X9wyozpTyHD7BAavLTlFHsB8Tn+LH zMDVADklELpHQykRXgZoqRAq4RZc7FHefRsy X-Google-Smtp-Source: AK7set9uJhXEm4wFj/x/Qn+uvdYQYK6AxAridUptvbE5NXBLaYVL7oageCszHnjesufsVliSY+mUng== X-Received: by 2002:a05:6e02:19cb:b0:315:9749:7a25 with SMTP id r11-20020a056e0219cb00b0031597497a25mr1288022ill.17.1676590438667; Thu, 16 Feb 2023 15:33:58 -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 Subject: [PATCH v3 04/11] bsd-user: various helper routines for sysctl Date: Thu, 16 Feb 2023 16:33:46 -0700 Message-Id: <20230216233353.13944-5-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::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.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: 1676590534030100006 Content-Type: text/plain; charset="utf-8" cap_memory - Caps the memory to just below MAXINT scale_to_guest_pages - Account for difference in host / guest page size h2g_long_sat - converts a int64_t to a int32_t, saturating at max / min val= ues h2g_ulong_sat - converts a uint64_t to a uint32_t, saturating at max value Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1676ec10f83..9b84e90cb32 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -21,6 +21,92 @@ #include "qemu.h" #include "target_arch_sysarch.h" =20 +#include + +/* + * Length for the fixed length types. + * 0 means variable length for strings and structures + * Compare with sys/kern_sysctl.c ctl_size + * Note: Not all types appear to be used in-tree. + */ +static const int G_GNUC_UNUSED guest_ctl_size[CTLTYPE+1] =3D { + [CTLTYPE_INT] =3D sizeof(abi_int), + [CTLTYPE_UINT] =3D sizeof(abi_uint), + [CTLTYPE_LONG] =3D sizeof(abi_long), + [CTLTYPE_ULONG] =3D sizeof(abi_ulong), + [CTLTYPE_S8] =3D sizeof(int8_t), + [CTLTYPE_S16] =3D sizeof(int16_t), + [CTLTYPE_S32] =3D sizeof(int32_t), + [CTLTYPE_S64] =3D sizeof(int64_t), + [CTLTYPE_U8] =3D sizeof(uint8_t), + [CTLTYPE_U16] =3D sizeof(uint16_t), + [CTLTYPE_U32] =3D sizeof(uint32_t), + [CTLTYPE_U64] =3D sizeof(uint64_t), +}; + +static const int G_GNUC_UNUSED host_ctl_size[CTLTYPE+1] =3D { + [CTLTYPE_INT] =3D sizeof(int), + [CTLTYPE_UINT] =3D sizeof(u_int), + [CTLTYPE_LONG] =3D sizeof(long), + [CTLTYPE_ULONG] =3D sizeof(u_long), + [CTLTYPE_S8] =3D sizeof(int8_t), + [CTLTYPE_S16] =3D sizeof(int16_t), + [CTLTYPE_S32] =3D sizeof(int32_t), + [CTLTYPE_S64] =3D sizeof(int64_t), + [CTLTYPE_U8] =3D sizeof(uint8_t), + [CTLTYPE_U16] =3D sizeof(uint16_t), + [CTLTYPE_U32] =3D sizeof(uint32_t), + [CTLTYPE_U64] =3D sizeof(uint64_t), +}; + +#ifdef TARGET_ABI32 +/* + * Limit the amount of available memory to be most of the 32-bit address + * space. 0x100c000 was arrived at through trial and error as a good + * definition of 'most'. + */ +static const abi_ulong guest_max_mem =3D UINT32_MAX - 0x100c000 + 1; + +static abi_ulong G_GNUC_UNUSED cap_memory(uint64_t mem) +{ + return MIN(guest_max_mem, mem); +} +#endif + +static abi_ulong G_GNUC_UNUSED scale_to_guest_pages(uint64_t pages) +{ + /* Scale pages from host to guest */ + pages =3D muldiv64(pages, qemu_real_host_page_size(), TARGET_PAGE_SIZE= ); +#ifdef TARGET_ABI32 + /* cap pages if need be */ + pages =3D MIN(pages, guest_max_mem / (abi_ulong)TARGET_PAGE_SIZE); +#endif + return pages; +} + +#ifdef TARGET_ABI32 +/* Used only for TARGET_ABI32 */ +static abi_long G_GNUC_UNUSED h2g_long_sat(long l) +{ + if (l > INT32_MAX) { + l =3D INT32_MAX; + } else if (l < INT32_MIN) { + l =3D INT32_MIN; + } + return l; +} + +static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long ul) +{ + return MIN(ul, UINT32_MAX); +} +#endif + +/* + * placeholder until bsd-user downstream upstreams this with its thread su= pport + */ +#define bsd_get_ncpu() 1 + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { --=20 2.39.1 From nobody Fri May 17 12:14:54 2024 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 From nobody Fri May 17 12:14:54 2024 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=1676590537; cv=none; d=zohomail.com; s=zohoarc; b=mFDKpu2Mc4O5BjczRJ0NyowU1wfRfFc2ZtSFzQ7LqFGKoRX8dIA8kJg9HtDj49bzPI1Nif2uqLIKRdFAnPiVMQgJ9g0zyrSNo+lHzrzF+vt/BVDUn8JfcDXT6GbVi0BlK/6NjSVbApMyD71b7E+Weq6dJUPLaRazmWmZwzOzf5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590537; 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=t3IWrnGl4pF51ODc0/WxLp2uU7S+u2cBX78xflQCoHA=; b=V8BqSFLrXOp9ssYVRMB82Lj1YkJm/DNnEuHB+wpHk4sooNSJjokKMHmLmqk7hatkGI+S5SNonkOY1wVpe4ad3lr5bzM3ngBcCE1WddIbRTRRne4LX3Mt9FiL0EvlZ2W2QQejgKa2Lc9mjV9bgjXcm0f0SmZ4F+SVOe9GuIH2KhU= 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 1676590537034140.90920331266273; Thu, 16 Feb 2023 15:35:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-000065-2F; 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 1pSnlN-00004v-45 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:05 -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 1pSnlL-0008Qr-5z for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:04 -0500 Received: by mail-il1-x12c.google.com with SMTP id i26so1403059ila.11 for ; Thu, 16 Feb 2023 15:34:02 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:00 -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=t3IWrnGl4pF51ODc0/WxLp2uU7S+u2cBX78xflQCoHA=; b=DiwPs8jihFTx5+GePfqyeUDwULxgSMb7AHc1of+K6oYuukB+mHKk8P3wUhgIRTmnuL lpxhxc7bK6GbZQ5GOMb4g8+kK/L7O+lCHnWKq/g4Pooo5gzDKLE0cM3EMYLgoTNPius0 UPGWtD8+D8lT9lilETDwoJnPXqhk6OOg4/wtSYGEPleVT0G1LwENHya5WyojoaEyzrEZ H0fNAiWm49slIozlL+p4roiYctkhJlY7dxMG75QYciaM99sUDVUpMeWM7vB9JYVFb2al UObOIufSJz3WFJdaY0NLV/LobwcXVvfpoX98gnUUUViXcxUQRyODl8/P6Ib2/IdqfGul FDhg== 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=t3IWrnGl4pF51ODc0/WxLp2uU7S+u2cBX78xflQCoHA=; b=54vxAWIlSzuNbeI14s9GvDyODyDFq94FEj47S7n5JFSISPKuHAeH2mCFy5S6e6Qp0K bhRiyX9W6X9elmmBxy/nDe1flwPVb1105q4RZJd08LqnfuzPHoHupKpwaZosISbhw4vv GZVGKHgo8pkbrcHVBOY24OqAXaefTcp+GeXNrY0cZJWMHaiCVhKmtEqho8Ex0MTi137o 6QXOU86GM2lXl91w3qMIKQvFpk3T4bVR4xrBezcLz/AFruKTWdo1fOOiU4g/SDS+gTu7 UmaKUMqlrv11pi5cd76FwmPcquWczmSr08/S83KkhEXDEUuDDhNmMzyQIxNQioKCHY6D aIRg== X-Gm-Message-State: AO0yUKWtdsTR+PEyuDouhj3uXiczEFNwBuih22VYqXOofXymLNXV4wQz 45vebjd6tw6wR6baoIr5SIjbeIvYKTIcBkW3 X-Google-Smtp-Source: AK7set+aUbNiJ1SciV7biOJpk2v1vbdg0U2Ig6Ctdu91BmV9bb9FhSpuyaxIiSCgTrhS79qL/80KAw== X-Received: by 2002:a05:6e02:1488:b0:314:fa6:323c with SMTP id n8-20020a056e02148800b003140fa6323cmr7514382ilk.12.1676590440963; Thu, 16 Feb 2023 15:34:00 -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 , Sean Bruno , Juergen Lock , Raphael Kubo da Costa , Stacey Son Subject: [PATCH v3 06/11] bsd-user: Helper routines h2g_old_sysctl Date: Thu, 16 Feb 2023 16:33:48 -0700 Message-Id: <20230216233353.13944-7-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: 1676590538025100001 Content-Type: text/plain; charset="utf-8" h2g_old_sysctl does the byte swapping in the data to return it to the target for the 'well known' types. For most of the types, either the data is returned verbatim (strings, byte size, opaque we don't know about) or it's returned with byte swapping (for all the integer types). However, for ABI32 targets, LONG and ULONG are different sizes, and need to be carefully converted (along with help from the caller). 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 Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 100 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1bf2b51820e..77c2b157c61 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -29,7 +29,7 @@ * Compare with sys/kern_sysctl.c ctl_size * Note: Not all types appear to be used in-tree. */ -static const int G_GNUC_UNUSED guest_ctl_size[CTLTYPE+1] =3D { +static const int guest_ctl_size[CTLTYPE+1] =3D { [CTLTYPE_INT] =3D sizeof(abi_int), [CTLTYPE_UINT] =3D sizeof(abi_uint), [CTLTYPE_LONG] =3D sizeof(abi_long), @@ -44,7 +44,7 @@ static const int G_GNUC_UNUSED guest_ctl_size[CTLTYPE+1] = =3D { [CTLTYPE_U64] =3D sizeof(uint64_t), }; =20 -static const int G_GNUC_UNUSED host_ctl_size[CTLTYPE+1] =3D { +static const int host_ctl_size[CTLTYPE+1] =3D { [CTLTYPE_INT] =3D sizeof(int), [CTLTYPE_UINT] =3D sizeof(u_int), [CTLTYPE_LONG] =3D sizeof(long), @@ -86,7 +86,7 @@ static abi_ulong G_GNUC_UNUSED scale_to_guest_pages(uint6= 4_t pages) =20 #ifdef TARGET_ABI32 /* Used only for TARGET_ABI32 */ -static abi_long G_GNUC_UNUSED h2g_long_sat(long l) +static abi_long h2g_long_sat(long l) { if (l > INT32_MAX) { l =3D INT32_MAX; @@ -96,7 +96,7 @@ static abi_long G_GNUC_UNUSED h2g_long_sat(long l) return l; } =20 -static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long ul) +static abi_ulong h2g_ulong_sat(u_long ul) { return MIN(ul, UINT32_MAX); } @@ -139,6 +139,98 @@ static int G_GNUC_UNUSED oidfmt(int *oid, int len, cha= r *fmt, uint32_t *kind) return 0; } =20 +/* + * Convert the old value from host to guest. + * + * For LONG and ULONG on ABI32, we need to 'down convert' the 8 byte quant= ities + * to 4 bytes. The caller setup a buffer in host memory to get this data f= rom + * the kernel and pass it to us. We do the down conversion and adjust the = length + * so the caller knows what to write as the returned length into the targe= t when + * it copies the down converted values into the target. + * + * For normal integral types, we just need to byte swap. No size changes. + * + * For strings and node data, there's no conversion needed. + * + * For opaque data, per sysctl OID converts take care of it. + */ +static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, size_t *holdlen, uin= t32_t kind) +{ + size_t len; + int hlen, glen; + uint8_t *hp, *gp; + + /* + * Although rare, we can have arrays of sysctl. Both sysctl_old_ddb in + * kern_sysctl.c and show_var in sbin/sysctl/sysctl.c have code that l= oops + * this way. *holdlen has been set by the kernel to the host's length. + * Only LONG and ULONG on ABI32 have different sizes: see below. + */ + gp =3D hp =3D (uint8_t *)holdp; + len =3D 0; + hlen =3D host_ctl_size[kind & CTLTYPE]; + glen =3D guest_ctl_size[kind & CTLTYPE]; + + /* + * hlen =3D=3D 0 for CTLTYPE_STRING and CTLTYPE_NODE, which need no co= nversion + * as well as CTLTYPE_OPAQUE, which needs special converters. + */ + if (hlen =3D=3D 0) { + return; + } + + while (len < *holdlen) { + if (hlen =3D=3D glen) { + switch (hlen) { + case 1: + /* Nothing needed: no byteswapping and assigning in place = */ + break; + case 2: + *(uint16_t *)gp =3D tswap16(*(uint16_t *)hp); + break; + case 4: + *(uint32_t *)gp =3D tswap32(*(uint32_t *)hp); + break; + case 8: + *(uint64_t *)gp =3D tswap64(*(uint64_t *)hp); + break; + default: + g_assert_not_reached(); + } + } + else { +#ifdef TARGET_ABI32 + /* + * Saturating assignment for the only two types that differ be= tween + * 32-bit and 64-bit machines. All other integral types have t= he + * same, fixed size and will be converted w/o loss of precision + * in the above switch. + */ + switch (kind & CTLTYPE) { + case CTLTYPE_LONG: + *(abi_long *)gp =3D tswap32(h2g_long_sat(*(long *)hp)); + break; + case CTLTYPE_ULONG: + *(abi_ulong *)gp =3D tswap32(h2g_ulong_sat(*(u_long *)hp)); + break; + default: + g_assert_not_reached(); + } +#else + g_assert_not_reached(); +#endif + } + gp +=3D glen; + hp +=3D hlen; + len +=3D hlen; + } +#ifdef TARGET_ABI32 + if (hlen !=3D glen) { + *holdlen =3D (*holdlen / hlen) * glen; + } +#endif +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { --=20 2.39.1 From nobody Fri May 17 12:14:55 2024 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=1676590499; cv=none; d=zohomail.com; s=zohoarc; b=Oa5MZrBh1P4J4IEOw4X7SybZ2/VmT/w+G2YdIvcjz22Gh4oO4bDjB7MVk2Nyt1BmkCEZf/FU0eEpp0H3ppky5UcvQHPQhxvujHqhYbGGcZtoXh4fHx7/DUAeFh4CcthLYbOptMw0H8uRN8iycLhdDyM/78etGPjS5lFGM7TnA4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590499; 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=FhVzycqE0CnkRK/EllKXUUS5z7C/peztHUJhIU/Hd5o=; b=gVTzMs2ht2iXQKoBiWv05fdpd780onsmvOusC+u5yUtJMmq7vrzwiYtqA/Sya/cVJ4lhfef3c1vXkvOWKR34SDcvEud5uNbZxpo8c+jgA4qlrtg0TCr6O9agvy18yXcb8Qo4MW1Qa3DXFS2X9QEWD/XFaSzGc7OimlIPLzeY0Tc= 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 1676590499395940.894963406673; Thu, 16 Feb 2023 15:34:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlO-00006h-RT; 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 1pSnlN-00005s-Pg for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:05 -0500 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlL-0008Qw-Fa for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:05 -0500 Received: by mail-il1-x12d.google.com with SMTP id g14so1412724ild.8 for ; Thu, 16 Feb 2023 15:34:03 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:01 -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=FhVzycqE0CnkRK/EllKXUUS5z7C/peztHUJhIU/Hd5o=; b=TyOZIoQ2Be03RZeOpwiC72Vso0MZ85tBYyYbewXtKz0yk+4UX4RhCU/YY2McmVlMNX hR7SqcrD8lI9ZujLiUJyrvxUHxM91gULiJcM6cHgbKCN3o7btaAcp+HSwoZAdHvlTutd 1SrZaISyI0ZwxRy5f51/vHREUEjaVjWyiRgvEz5rvnvx4G0FCxFlKOCNkxnjskuusqDx 50MksYSDquUVnP6YPJYLrQBRVfLS8f8ZUiHHK4twX6StTysZOZWCnEK9+eZAM75YypY8 655q9yaajhPwFLVkQU1RBdiBAg+MJD3Kx1fmZYDAPplxI8FxPcvsl7rIZ/++p7u1lnZU Rhvw== 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=FhVzycqE0CnkRK/EllKXUUS5z7C/peztHUJhIU/Hd5o=; b=Ic2d3X0DotGIDGtZ+gA7TYt2/qA6aEuMNX/0Z5i6JYTMt4hZZJbZoo/W8+FohNPoo5 QLrz9g26He4RtMrOyahMGUJPWagwUBlfL+6XJvLlc8UIKCck+eMEdYuvDBnM4QAZDi6Y z+DMBLb92ErQ8LVqZ48UmVqb4ZrkdXDru7dgMKgaLw7EJd9BKz9SvaqxAqi4QIEUiMp0 SvVWYw7E/XUl8v1/83cH5VDVRrzLQ5Yk22yxtZ4aUDIg5ZT/b4AHFL4XwVHWc344QZp8 qEe+OaY6pWl8sx7SToPBATs30OHPw/7wbFKb+3ZTiNTjAFQT4/N1HbJPvFj5cxBHVCC0 VsaQ== X-Gm-Message-State: AO0yUKUiOLpurzgg09eXoLjscTtfwjGvR7xKWH4cHWzIwCmHbWSJv5C2 kuU5/zNwYVH1yg2Yud+bB4E+TWiAI7FAQoU9 X-Google-Smtp-Source: AK7set8r4KOVpwfVLZgDbZfEDee+iOP/zcw+jEthp5xqTxbujf6PPFHAWNjRJ629LmLyKoaV/REzQw== X-Received: by 2002:a05:6e02:1525:b0:315:851c:279 with SMTP id i5-20020a056e02152500b00315851c0279mr3095212ilu.1.1676590441833; Thu, 16 Feb 2023 15:34:01 -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 , Juergen Lock Subject: [PATCH v3 07/11] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Date: Thu, 16 Feb 2023 16:33:49 -0700 Message-Id: <20230216233353.13944-8-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::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.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: 1676590501487100001 Content-Type: text/plain; charset="utf-8" From: Juergen Lock Helper functions for sysctl implementations. sysctl_name2oid and sysctl_oidfmt convert oids between host and targets Signed-off-by: Juergen Lock Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 77c2b157c61..dee8c92309b 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -231,6 +231,24 @@ static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, = size_t *holdlen, uint32_t #endif } =20 +/* + * Convert the undocmented name2oid sysctl data for the target. + */ +static inline void G_GNUC_UNUSED sysctl_name2oid(uint32_t *holdp, size_t h= oldlen) +{ + size_t i, num =3D holdlen / sizeof(uint32_t); + + for (i =3D 0; i < num; i++) { + holdp[i] =3D tswap32(holdp[i]); + } +} + +static inline void G_GNUC_UNUSED sysctl_oidfmt(uint32_t *holdp) +{ + /* byte swap the kind */ + holdp[0] =3D tswap32(holdp[0]); +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { --=20 2.39.1 From nobody Fri May 17 12:14:55 2024 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=1676590555; cv=none; d=zohomail.com; s=zohoarc; b=NlCCptc3MFiBkb6Ac3bKreQA3BcMluBskNX5nqQBqsQmwh7Bw6CEf7Qxzb8z9qH41jg9LQ7w1ozZ8Fotn2hJMH74OTARG5Cbx4AVeGv8EAQm5NUayiJ2k9vxpngzsMqTLU0ANxoafFei5uiSSrxw9mqwVaiOWkGGXJM3GdhaUEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590555; 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=121msZ7BQw47YP3HHlZFZiV5/sv+6Qz3v9vW8ncVL2Q=; b=ModmjpPp9SvMdXE2XUmLPNJ0BxDjbXtvxMivAyQk9JukNBNwNTVI8bfOUwfvO42+JUk5nkiY1lagt/yAX0F9OLqJfra94F0cG2A9iePOyUOIpe3aOY2BALJPrJuJdhDWLJHpe/SdCHrs+HfKLgMaYrwQyKa1zhbHaeG1CMvPRiw= 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 1676590555930538.8168240970398; Thu, 16 Feb 2023 15:35:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlQ-00007x-Dl; Thu, 16 Feb 2023 18:34:08 -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 1pSnlO-00006P-Ju for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:06 -0500 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlM-0008R9-SM for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:06 -0500 Received: by mail-io1-xd34.google.com with SMTP id j4so1322461iog.8 for ; Thu, 16 Feb 2023 15:34:04 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:02 -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=121msZ7BQw47YP3HHlZFZiV5/sv+6Qz3v9vW8ncVL2Q=; b=eHcCFiqal+MKDi4p3P9Yeyjpy3veTZVhdziRks09iocYe8F+QKMwVngQ434sCPcJGA i2D0OAyGZMs9e7a1Q5d0tA1U6buKWxjbwfDKuYWZhZ6SJC58d79eoPQJqADaJWw95prw 5AhErwZPfuJv6oZ/4WKmHtDFpwKVhTR5PK/9Av4Gv/WlsZ/GD06mOoGaOjY7rz74kDoB hvxapf28mzaHj8+dvXyaiVIoVYd5AYnmeuFIITQO6KEYnoUPvAF4pXbAViXrz+ProYat Y14W0JOFV8veLcuEwUy/zojQz48RNK0ANIkRxfm1ZMTUAMnHaYvPGd54SWL22pC1bluu YErw== 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=121msZ7BQw47YP3HHlZFZiV5/sv+6Qz3v9vW8ncVL2Q=; b=FYGilxZOsRMoefiAxuAR+MYpMtsMnHLH+AiTzjDq9bhPpGXLTalzRT4pbyDHtvl0GG /8Vn39QHGXtZ4DvN4nsVCnROL8UehSHGR9QgW8thgsUIPTKSSpBZvVhU1FbzqRXWoqO2 OwHmjGVdpUGhviefmklpL76TnzH0rHaIhYOuFBWRGHU3GH/ke9Tk1ikxFH6VBVv3S1KY SuSb51AQXeRhr2M8exijCAYUExCoZw9LdDHaj3DeYfuBkDt6b9qBrdYetJ2AI2W4/T28 8nKtTmDCyzNUOSEmsJraKrasEHrn5+dFUBhFZfRdTh2fC/Zl/M6guRB6Qjt5d99YFk/7 fRmA== X-Gm-Message-State: AO0yUKWQO/wQNpVvdcxaZVw18ywJsaF3oBkukr7GFWCxF/Petawcv0iL /9XD80b/yjskxKCRNfBSuRDw+pXnZwlGCmOu X-Google-Smtp-Source: AK7set+VTQl28qPjtZZqyDW4dfkz/S2vIzwzZkAismv7qDSKG+obg8LhNEnSNiF9XRZ8+hsZxSIGXw== X-Received: by 2002:a5d:8896:0:b0:717:df30:e56c with SMTP id d22-20020a5d8896000000b00717df30e56cmr5602538ioo.2.1676590442915; Thu, 16 Feb 2023 15:34:02 -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 , Juergen Lock , Stacey Son Subject: [PATCH v3 08/11] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Date: Thu, 16 Feb 2023 16:33:50 -0700 Message-Id: <20230216233353.13944-9-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::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.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: 1676590558192100003 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. None of the sysctls that have to be translated from host to target are handled here. Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Co-Authored-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 90 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index dee8c92309b..42f0cc82279 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -112,7 +112,7 @@ static abi_ulong h2g_ulong_sat(u_long ul) * 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) +static int oidfmt(int *oid, int len, char *fmt, uint32_t *kind) { int qoid[CTL_MAXNAME + 2]; uint8_t buf[BUFSIZ]; @@ -154,7 +154,7 @@ static int G_GNUC_UNUSED oidfmt(int *oid, int len, char= *fmt, uint32_t *kind) * * For opaque data, per sysctl OID converts take care of it. */ -static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, size_t *holdlen, uin= t32_t kind) +static void h2g_old_sysctl(void *holdp, size_t *holdlen, uint32_t kind) { size_t len; int hlen, glen; @@ -234,7 +234,7 @@ static void G_GNUC_UNUSED h2g_old_sysctl(void *holdp, s= ize_t *holdlen, uint32_t /* * Convert the undocmented name2oid sysctl data for the target. */ -static inline void G_GNUC_UNUSED sysctl_name2oid(uint32_t *holdp, size_t h= oldlen) +static inline void sysctl_name2oid(uint32_t *holdp, size_t holdlen) { size_t i, num =3D holdlen / sizeof(uint32_t); =20 @@ -243,12 +243,94 @@ static inline void G_GNUC_UNUSED sysctl_name2oid(uint= 32_t *holdp, size_t holdlen } } =20 -static inline void G_GNUC_UNUSED sysctl_oidfmt(uint32_t *holdp) +static inline void sysctl_oidfmt(uint32_t *holdp) { /* byte swap the kind */ holdp[0] =3D tswap32(holdp[0]); } =20 +static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPUArchState *env, int= 32_t *snamep, + int32_t namelen, void *holdp, size_t *holdlenp, void *hnewp, + size_t newlen) +{ + uint32_t kind =3D 0; + abi_long ret; + size_t holdlen, oldlen; +#ifdef TARGET_ABI32 + void *old_holdp; +#endif + + holdlen =3D oldlen =3D *holdlenp; + oidfmt(snamep, namelen, NULL, &kind); + + /* Handle some arch/emulator dependent sysctl()'s here. */ + +#ifdef TARGET_ABI32 + /* + * For long and ulong with a 64-bit host and a 32-bit target we have t= o do + * special things. holdlen here is the length provided by the target t= o the + * system call. So we allocate a buffer twice as large because longs a= re twice + * as big on the host which will be writing them. In h2g_old_sysctl we= 'll adjust + * them and adjust the length. + */ + if (kind =3D=3D CTLTYPE_LONG || kind =3D=3D CTLTYPE_ULONG) { + old_holdp =3D holdp; + holdlen =3D holdlen * 2; + holdp =3D g_malloc(holdlen); + } +#endif + + ret =3D get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newl= en)); + if (!ret && (holdp !=3D 0)) { + + if (snamep[0] =3D=3D CTL_SYSCTL) { + switch (snamep[1]) { + case CTL_SYSCTL_NEXT: + case CTL_SYSCTL_NAME2OID: + case CTL_SYSCTL_NEXTNOSKIP: + /* + * All of these return an OID array, so we need to convert= to + * target. + */ + sysctl_name2oid(holdp, holdlen); + break; + + case CTL_SYSCTL_OIDFMT: + /* Handle oidfmt */ + sysctl_oidfmt(holdp); + break; + case CTL_SYSCTL_OIDDESCR: + case CTL_SYSCTL_OIDLABEL: + default: + /* Handle it based on the type */ + h2g_old_sysctl(holdp, &holdlen, kind); + /* NB: None of these are LONG or ULONG */ + break; + } + } else { + /* + * Need to convert from host to target. All the weird special = cases + * are handled above. + */ + h2g_old_sysctl(holdp, &holdlen, kind); +#ifdef TARGET_ABI32 + /* + * For the 32-bit on 64-bit case, for longs we need to copy the + * now-converted buffer to the target and free the buffer. + */ + if (kind =3D=3D CTLTYPE_LONG || kind =3D=3D CTLTYPE_ULONG) { + memcpy(old_holdp, holdp, holdlen); + g_free(holdp); + holdp =3D old_holdp; + } +#endif + } + } + + *holdlenp =3D holdlen; + return ret; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { --=20 2.39.1 From nobody Fri May 17 12:14:55 2024 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=1676590517; cv=none; d=zohomail.com; s=zohoarc; b=UuXNWDvLnkXCD4gaLy0MadQqKc2e3psWi+mJ7ULTXPrlHEmHGn4btODKEbpgGvKSkkRSXwj53eIN+LEKJJkNcwUAn73bQ5xOKiVzZnIekfZZ7OKTyqLDAkcvrpZbRWkxHumzXZNQm/e+iwm4JQHpjt5Zkjau6zSKIiPBF7DAUlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590517; 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=rQSSYyJH9Z4zIbAHEAHA5MUcncm7KN1aWBx0s4v1VyI=; b=mosJ1H4avo76vNdWWZgZsVsVhJwBqm+S+Yv1VkDdfY+6w3B3pnx2WNDvEOckQwunt64c3nGlbIBtzi1yHVGdWXczcBZfDMW5RinieZU3tre2ZsJslKurkgz5j4sLsTTBgEt+LKXx+watrU0bN/jzAuGNFy6HmX2ISqaKdJVZkS8= 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 1676590517024588.5018003582028; Thu, 16 Feb 2023 15:35:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlQ-00008Z-UI; Thu, 16 Feb 2023 18:34:08 -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 1pSnlP-000072-14 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:07 -0500 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlN-0008Ph-5x for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:06 -0500 Received: by mail-il1-x130.google.com with SMTP id v13so1422629iln.4 for ; Thu, 16 Feb 2023 15:34:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:03 -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=rQSSYyJH9Z4zIbAHEAHA5MUcncm7KN1aWBx0s4v1VyI=; b=QFKPf6LFTWauNR7a5SKlFcoS66l5aOyjGkPfvZNOyaT7S2Ng28N1soV4g9sunIQ1X7 OEyPJu55py12/wOWd9YAivThJaPQgcE4abK+/B/yVC1AHn4DEOAcI+WfTZfT6upMgP/G EamHmT4EdgKO29gxcbgbPwyBTnQBNzcsFXWPGpB45LWHKtFWey4nGYiSwo1Vr1yaAsAf 0CbG08M2Ozw/rYsn+/096vXlYWI22hmrUIPuvBcGYdx5AE6s5eAVIrSbrIWO7I6qVPTG 67QWl9MMd4v9S2kUddS9qqKUguFcRs9WahqIPwYpzTVbttqgR06W8JJ8UCxUDvISnE1Y 9BMw== 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=rQSSYyJH9Z4zIbAHEAHA5MUcncm7KN1aWBx0s4v1VyI=; b=AMD/XC9HrlAgND+eECxi4n3YKNUfQ4zxyoMLq8H3ak7uZDb05uikMtAe4uqehEYkx9 7PhVsueJ/TgMH/3MKH9G/LvSpKhTtXx/2ojmkga4YWHVf3ngNEajipAdAZFS5/Z97LGf TuZgiqrX9bOT8HGW46EmJzhrJtxTUmrjuYraE5R+OP97e+Wcqknv7WwOSTRpw1zil9JG pI2V1f1k2P0riKW3QTruKsEK/hskBsl5VheJWj9US6J/QJ0sSY0yoPaoXhzBEQZggpWc MNRa1wwyIpSmxe4oeeGLjU+t0S6dqvPV4yNktCttD+kggoMD8qqDBu8sxzPjXCfV13CB tQhw== X-Gm-Message-State: AO0yUKUCCvGlpf8pyFkAN4Y2rrzMgC4koOjDCxkpI3MfrPoQp3dQAYkt 49roxddPA2LvgJe1MyA+6Wu/ji9W9mvCXxXc X-Google-Smtp-Source: AK7set9xGgBu1yLRiY4g2xXOSQseB6T1pn4ReylPte7Ya2x9ItyCzl85jqE32qbOOHpJ0XnPh1zscw== X-Received: by 2002:a05:6e02:1a4c:b0:315:9a9b:9b54 with SMTP id u12-20020a056e021a4c00b003159a9b9b54mr658353ilv.12.1676590444115; Thu, 16 Feb 2023 15:34:04 -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 , Juergen Lock , Stacey Son Subject: [PATCH v3 09/11] bsd-user: Start translation of arch-specific sysctls Date: Thu, 16 Feb 2023 16:33:51 -0700 Message-Id: <20230216233353.13944-10-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::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.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: 1676590517905100005 Content-Type: text/plain; charset="utf-8" From: Juergen Lock Intercept some syscalls that we need to translate (like the archiecture we're running on) and translate them. These are only the simplest ones so far. Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Co-Authored-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 145 +++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 42f0cc82279..1464e64428f 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -67,13 +67,13 @@ static const int host_ctl_size[CTLTYPE+1] =3D { */ static const abi_ulong guest_max_mem =3D UINT32_MAX - 0x100c000 + 1; =20 -static abi_ulong G_GNUC_UNUSED cap_memory(uint64_t mem) +static abi_ulong cap_memory(uint64_t mem) { return MIN(guest_max_mem, mem); } #endif =20 -static abi_ulong G_GNUC_UNUSED scale_to_guest_pages(uint64_t pages) +static abi_ulong scale_to_guest_pages(uint64_t pages) { /* Scale pages from host to guest */ pages =3D muldiv64(pages, qemu_real_host_page_size(), TARGET_PAGE_SIZE= ); @@ -264,6 +264,146 @@ static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(C= PUArchState *env, int32_t * oidfmt(snamep, namelen, NULL, &kind); =20 /* Handle some arch/emulator dependent sysctl()'s here. */ + switch (snamep[0]) { + 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) { + (*(abi_int *)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) { + ARMCPU *cpu =3D env_archcpu(env); + *(abi_int *)holdp =3D cpu_isar_feature(aa32_vfp, cpu); + } + holdlen =3D sizeof(abi_int); + ret =3D 0; + goto out; +#endif + + +#ifdef TARGET_ABI32 + 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 { + lvalue =3D cap_memory(lvalue); + (*(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) { + lvalue =3D scale_to_guest_pages(lvalue); + (*(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; + } =20 #ifdef TARGET_ABI32 /* @@ -327,6 +467,7 @@ static abi_long G_GNUC_UNUSED do_freebsd_sysctl_oid(CPU= ArchState *env, int32_t * } } =20 +out: *holdlenp =3D holdlen; return ret; } --=20 2.39.1 From nobody Fri May 17 12:14:55 2024 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 From nobody Fri May 17 12:14:55 2024 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=1676590503; cv=none; d=zohomail.com; s=zohoarc; b=k4pOoZC3meHtGLDY+PauRj7TArmWTTEtUKWWA1AdozN692ETQ/RVfWAAVZv3lPxhiEac7Y+pBbM4dmuJhkiwRgvtp9SMO8CA/QEP/vsr62Swy/TFR/XxdESuqtX4qab+bfORaEexRdK8h9H06oHbhohyZPoIavMvx1bS9Lh7qMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676590503; 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=BzF5n/1/KVwLC31ZXtP5Hy3esjXH+09jTaZZtYxZEo4=; b=WvgdI0V1AULOIsIZnFOmnC60cnXmP8V8Bzu3RgAOV6zS4FRaDjO4omN7xPPx/4B2IksOAPcppIl4YPvfrCY7Pa7jKhof7ethZQMZxx1Sbx5xEpQY92wRhIXEb6G7YHHboZe/hkR5VkvQcy3lB5YR1vsm+JW8th1HlXnnXot0nIk= 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 1676590503752338.05880949816435; Thu, 16 Feb 2023 15:35:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSnlT-00009l-3s; Thu, 16 Feb 2023 18:34:11 -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 1pSnlR-00008h-42 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:09 -0500 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSnlP-0008Qw-EA for qemu-devel@nongnu.org; Thu, 16 Feb 2023 18:34:08 -0500 Received: by mail-il1-x12d.google.com with SMTP id g14so1412788ild.8 for ; Thu, 16 Feb 2023 15:34:07 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 15:34:05 -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=BzF5n/1/KVwLC31ZXtP5Hy3esjXH+09jTaZZtYxZEo4=; b=IrTPshsT3+9BU58xGEDEA10k66GUqKBeRVGZHn60DURMU04Z/wykdJVZ3goJn3Qwjy 6o89UuRoe3FAgHIyTqKcTSVlcAqvgmCkZv+6ttlCjzulm6aMGtBURR8LGSHBqMBy/f2A 0uXzstd2iD9eTBpSuCwwFtej8Y5XhEWxgbPXeFPosSRbMbhkDk1IMiRQQnAI8eW51pRL QTT/yDggS4/OjnDqcDamZCsR1VIYdrKA8Z89WvnLV1GGiopihIM16Pxn8gLKZ+B0UJJp vaCYxtDwZNR2GMqiQNgSef+nz3rX5XrCujul+XgrZOi6YxSOnqyl4lPRhIEPqlOVU0wC ZXsQ== 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=BzF5n/1/KVwLC31ZXtP5Hy3esjXH+09jTaZZtYxZEo4=; b=ofTZ3G7qgTQmr4a5fGx9T05YVcg5WMZpyTQNksCjwaWfy6bkvypXPoqnI6C/WHADGc 4iiq9SqfYEZe+yuRTgp02pgQz65ZjTsLZIC8rZekiQwmKYUVeFGOHiTzVRxkDKAKzoUe Ka3JUkGYJlf9btz6OxtAkW109DkSIN8dzoNuVkalOoFrTy/A1DYI2JcYQpCklLsbcY1n 8VvFHBUgGbyrHN4YloCBR3THh2O7ekuartVzi70z9/AKUv8bnkAeG1FlUQ2x7l3zfUaz Rq5ae73MRtrbA2fOwTIZBytUBEL37wXmgqy8zLSl3nHsVNO5lmWuP1KXWHiKEjmOE6pn 6NRA== X-Gm-Message-State: AO0yUKVuDo9qtwA8Gu56Tn1g50KfRdkp9FGYFbBXoU8BrS3mvxidKtPq z8f6cXzBrTlJcRN8EgsAQpPdHkXHx7AVQYAh X-Google-Smtp-Source: AK7set/uPg3BZBoXrx4Tq1aSn8GGHDLyGEEi50Zdd7g81durcAzjDPtvJkSyRBbUmN2nwXMHYhFsfQ== X-Received: by 2002:a05:6e02:1c4c:b0:315:4350:9c09 with SMTP id d12-20020a056e021c4c00b0031543509c09mr7755952ilg.16.1676590446334; Thu, 16 Feb 2023 15:34:06 -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 Subject: [PATCH v3 11/11] bsd-user: implement sysctlbyname(2) Date: Thu, 16 Feb 2023 16:33:53 -0700 Message-Id: <20230216233353.13944-12-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::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.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: 1676590505761100001 Content-Type: text/plain; charset="utf-8" From: Kyle Evans do_freebsd_sysctlbyname needs to translate the 'name' back down to a OID so we can intercept the special ones. Do that and call the common wrapper do_freebsd_sysctl_oid. Signed-off-by: Kyle Evans Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 67 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 +++ bsd-user/qemu.h | 3 ++ 3 files changed, 74 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index f07ae7da740..d9386d3e7ef 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -472,6 +472,73 @@ out: return ret; } =20 +/* + * This syscall was created to make sysctlbyname(3) more efficient, but we= can't + * really provide it in bsd-user. Notably, we must always translate the n= ames + * independently since some sysctl values have to be faked for the target + * environment, so it still has to break down to two syscalls for the unde= rlying + * implementation. + */ +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 ret =3D -TARGET_EFAULT; + void *holdp =3D NULL, *hnewp =3D NULL; + char *snamep =3D NULL; + int oid[CTL_MAXNAME + 2]; + size_t holdlen, oidplen; + abi_ulong oldlen =3D 0; + + /* 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; + } + } + snamep =3D lock_user_string(namep); + if (snamep =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; + + oidplen =3D ARRAY_SIZE(oid); + if (sysctlnametomib(snamep, oid, &oidplen) !=3D 0) { + ret =3D -TARGET_EINVAL; + goto out; + } + + ret =3D do_freebsd_sysctl_oid(env, oid, oidplen, holdp, &holdlen, hnew= p, + 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); + } +out: + unlock_user(snamep, namep, 0); + unlock_user(holdp, oldp, ret =3D=3D 0 ? holdlen : 0); + unlock_user(hnewp, newp, 0); + + return ret; +} + 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) { diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 20ab3d4d9a1..179a20c304b 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -498,6 +498,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, ret =3D do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, a= rg6); break; =20 + case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ + ret =3D do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, a= rg5, arg6); + 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 c7248cfde6f..e24a8cfcfb1 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -254,6 +254,9 @@ int host_to_target_errno(int err); /* 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