From nobody Tue May 7 23:20:35 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=1677695214; cv=none; d=zohomail.com; s=zohoarc; b=ZR7aupZjYuGozJiBaMC/0K22PTDws4eOxVnH5+7SAIX+kuUxZHA/cfSC+VGrezzkYkIVk87fSC3BmFdDay2fuPeGkLrXGAwgm1kaKvWWM7WFynjKdvWOGb21b0uK7HL8XqMxRtx6HZj1Nm3LpO15B/LQnb6H69yB8UdPX+VPI5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695214; 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=GRptRBFaeYt1ZLcdDyqu85KDeQBYaXGuMAUxaAx4BPOIYpOWTQlLuKwCfGbtZ428j4KXr7tFksQ58KAkt7Bb3rFEfeSWdrLA5njmd5mwubB0hhyr7AQN5WHyWtOGCmM+V+kehcW60AMiT5NjZb/16MFLcumSR9Lo9f/Z1T3lKJg= 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 1677695214156192.82791676463637; Wed, 1 Mar 2023 10:26:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7d-0005Lh-9t; Wed, 01 Mar 2023 13:24:13 -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 1pXR7b-0005E2-8G for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:11 -0500 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7Y-0006nX-EH for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:10 -0500 Received: by mail-io1-xd2d.google.com with SMTP id bf15so5741158iob.7 for ; Wed, 01 Mar 2023 10:24:08 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695047; 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=BVPpqWymWuk7edRXDORaOk2vs6tNZiJMrtX/Se4knI/eVtf2/voz35B/52cyu9vkuL RaMS06ToE9pxnCEXHvCTT1ui0qqQL0RgZAakkE7xq6333u0v0miEuxL2zm27KWow9652 0Dl9DVNtU6taZA4Iggrv2aLEHkFgCKD7YCj3tSLFzzVkvhY1OWjCbRYSKXotSqwlgi4h iFQE+kWqCD/gm3VDzmVJSgabh/I3nWKuNeZbKGcl66HqML7R9ac4sNCAQSFJhq6XoTKj ZiSgZvLyy/IdTQ2QTj2xOkn84ttDaAL0o5uiGEh0Q0hOS23IIOA2qvDnppVfjHUWMqmw xFcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695047; 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=LKG9Ns/xmHOAnjFiku1Gk9JiBm9oc9jojzJmAet1eguH2gI6Qi0VeGqxisFnnMPUm9 JmVblnWRvmZuWgG44AlOghGoPjhw6be0agcayJ7SYTgrhBmswuTbaaasM0xtrzqTBNlK 0ny3VnsYnFKUCoKO96QkYLu6HFowODZ/0H7GPBk14lCFa2cZZHrTNjY/Io+EHhG0fUn5 3tnVn8gX1bO7iUDE5hl6DBTC7sN7XDmYwP9UfIo7wy2meMlrxjo7W8SakSQfl5QjnjwG GSq/ZQVPFVVqyjI9uJk7pCP9p60uGKomzhrRtmNLdO+MJqbaNAMDA0f3ErROhx1IltmC 7ieQ== X-Gm-Message-State: AO0yUKVaq0OR1amVkiejbDbKcqo2lzJBjYMOaXx9WXbrFYkCIaINRh5C nEP/1MeREH8r4Uz5lXhjdcXuSu/uIZPsOTwl X-Google-Smtp-Source: AK7set+FzNdJv5JwGAzX1XctpnvYm69KK8GR+mKA+cyMaCzJoMejfTtnAXwSpzj9bFuTmIhnoFTuUg== X-Received: by 2002:a5e:8e07:0:b0:704:b905:e652 with SMTP id a7-20020a5e8e07000000b00704b905e652mr5470906ion.11.1677695046808; Wed, 01 Mar 2023 10:24:06 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Doug Rabson Subject: [PULL 01/10] bsd-user: Don't truncate the return value from freebsd_syscall Date: Wed, 1 Mar 2023 11:23:44 -0700 Message-Id: <20230301182353.21559-2-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.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: 1677695214990100005 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 Tue May 7 23:20:35 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=1677695148; cv=none; d=zohomail.com; s=zohoarc; b=i3KKv4IdmIc2hMHabzQdjK84R8xGDC9pK+bajogAmcQM/RgcL3OsM2sO5U+ndGIsg02W52xmN173DtYalDa5ReR+iMDrRt7dTY4R+l9EgG66aEcSOrTMtoXFCoWCqXqGUvKuqq0JPoZ5mIYmGx8bzDfVLZ7bwuF2OrxHqkYg3U4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695148; h=Content-Type: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=HyoNTDTr1ptMH6svOCZXN1cA+3jNNlRrvcRLazIEkVE=; b=eftZarbNQ/sCAvKhC/P283GinNEwQ5WMhPWErRqy1e9nNuaijfhzma8XebJEuVROHabh8aIt95cfmbSsqE1Pfuy24bNmfFUpBUW34KFkpHZSOk978AEMXzRHjSA2+7jB+3p1wjFQgAAfeLN2AiLZcnzq4iF7lMfaEcJ9MneBuX8= 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 1677695148890396.1341292259624; Wed, 1 Mar 2023 10:25:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7e-0005R1-4t; Wed, 01 Mar 2023 13:24:14 -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 1pXR7b-0005GF-LZ for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:11 -0500 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7Z-0006nk-Au for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:11 -0500 Received: by mail-io1-xd2f.google.com with SMTP id 76so5742339iou.9 for ; Wed, 01 Mar 2023 10:24:09 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695048; 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=HyoNTDTr1ptMH6svOCZXN1cA+3jNNlRrvcRLazIEkVE=; b=hXpxCsztjCQwxS8WiFX9EXn8zbBVjGO+lt1g18uaoPvQm8OJTkmOWsPrjF7nDqjYyv UU79/zkosxYNTs8DxE8amF7sgOKiImTLDRhEgs0gwMJ3WeD4CJoRSU3uX2jVvDRV2goj yJX/u63pW5REJO2K+iDw4VlOxtY7uZkicCv2XaBfl3/ST0KGMrWOyLj+57uf4bjxB0dc FyGEcavf1t6U+EreAZEBsHDlLk5tn49bNzWAIsmjUD0ZG2dA/EMb3A2DHxtACz4baMNe FkIk9IewESsoVho7uNaoeCmBw8/B7PZebcXoZM0CcAg0fj1mJ3CoCmSrRGBjGOVatuHm xw6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695048; 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=HyoNTDTr1ptMH6svOCZXN1cA+3jNNlRrvcRLazIEkVE=; b=ADV61NS7AZxeBJTNH8f3BVqEgrnewtNbaQ913BCeHbwkx65wG8NawzZQkV7sTTtxZw jWbE+PdjyxGCB2X6PDuqBLcU2RfE/Ibfa64atSUlENxwPloN+HCBVZX3leWTWNQ+ltDN VwNt8bwrERn0JhLpria+/E29M+HvWmuou0zJKs6PIY8FQIu24373RkKz4USqMuooHapE eEhvZKUXlT25N7SKjTTBOwBk4CizUYDTppSP/BmOquriC2cAorkMXrGlTKAjJmzL7Rov 3fsopUI+F6S4IWefn/3Q8163rntd34FkkmBQudEGBbh2An892M54WVu/tnPsUg65hTQz jBmQ== X-Gm-Message-State: AO0yUKUt8W7Hh0mHAyb7M6azgYkZQHpvKRO7tceDxqdSFpuHwiRm70VW yu+SV0ok25neA8L6a+mLRe9lCvTpxQ9z75JH X-Google-Smtp-Source: AK7set+cWcDYzVCfW1MS4MPHP29EpBa0UGTZRf2L4Y718Zs8rlt6PqH45Xh9q5932nV/qf4OskaH7A== X-Received: by 2002:a5e:890c:0:b0:74d:114c:8331 with SMTP id k12-20020a5e890c000000b0074d114c8331mr4679957ioj.14.1677695047816; Wed, 01 Mar 2023 10:24:07 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini Subject: [PULL 02/10] build: Don't specify -no-pie for --static user-mode programs Date: Wed, 1 Mar 2023 11:23:45 -0700 Message-Id: <20230301182353.21559-3-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.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: 1677695150244100001 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 2a8a9be8a18..24684f47b6b 100755 --- a/configure +++ b/configure @@ -1347,7 +1347,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 Tue May 7 23:20:35 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=1677695119; cv=none; d=zohomail.com; s=zohoarc; b=SDadusWY6NWY1hPBQJTJPR7V4ZsamVYhaeMjLK8LajHzxi6zlma8WzuzSrJ712T4gIY2f1SO3Ay3sPJdwoa/D9Dyy2kXuGGH+Six1YCOeTJLnJZl+T/S5EekyqRJZdyS3m2jw2GVvgv839MnvWGcxS35X9nZQRpDY8xS75tj1uQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695119; 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=hOc1Vp0W+/iZ29aFDVbKdm8B/JVOtlfGUhYPEZ1+tCw8UTmVKBcptDE9tgK6p6CbKSPwUWvBiRG+EVILSL1uceFlvmSr1uw36pUZTZoRzEG3RykV2JzqHabzgDGGQZaKH4OJ3tjXOsDYfgv0d/qMmb/U0LKk56BceOIY6ZHhjac= 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 1677695119127397.3687163894738; Wed, 1 Mar 2023 10:25:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7e-0005T9-PR; Wed, 01 Mar 2023 13:24:14 -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 1pXR7c-0005JT-LI for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:12 -0500 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7a-0006ns-Ta for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:12 -0500 Received: by mail-io1-xd2e.google.com with SMTP id y140so5745650iof.6 for ; Wed, 01 Mar 2023 10:24:10 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695049; 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=qX7eGIrRItpdTrClA/kXJpb/cIdP6kfCZl+Y2P9uDtB+kePJOaAu4BtIIqT2U1e6u1 FokiIRQiG7HREBXrpept0+Zk3UgnGhVmuOYvS/np6353f7rvZmuYobicYRWGa7Syg67Y KKyT+af1pZmbVYOhH3jfRm0I3GyTaswUwAufeG/ttaxaI8/jN/lk8fMiSTFLPXW35/Dr vBRd7N43+DxhRwdyVrnL7qAYf2LuzylGEFJr5BDVRnnhXeI4U1C8u7jiWxvmUoREd1ui fSaEdJhNM5A6nFmtb+bczY09RhiZvWDLCuKMjLwpMDfEmnt4aqB39jS6OUReqQkA7bDK urWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695049; 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=AEqbbksrjRxcI2MGgwFjTVJ5tPZfVLYXMT8VFmxscmYC4JwoGb+PH63lL0uF8WC1pt 5+S6pPQ8MWgMCmWEkNGtQbWWdHM9jY3V5QIz4Kt515fWy/Gq+eCDuUjHD0hQIuItY6xn +sVuEwhrjAxs1060ZvecTV9HIt0qH1SVrkM2nbzzqdZDwXaB6Y48NdY6V4xNCflQAKsq 3SzaD6FdEQKFpAdVEHkrv2wGZOTxtPAKARlenDftXrQwPBu5a2bwHE6GcL2e88mLMu69 kwOOxnvK2jwoN+kaEC4JP6Id/oh47byABuCYiCBur1WYl6SSmVeCn5A6Bv+yENZBMERn ha4Q== X-Gm-Message-State: AO0yUKVS6FpfOEHlRY61qxkylb5FZTsxdRd74RrgnCgflVT4NUXTTpCY kUrb09pxsqB9BoBCN5ShBUJAzFQg+EtlkCjW X-Google-Smtp-Source: AK7set9D42skVUUaz9EZrC9JbSjHqbQkgGIS/MNKv/9efGl0nzl4K3b7m7iswwDfM5+73Nj5gEbD3g== X-Received: by 2002:a5d:844c:0:b0:734:e7c0:2058 with SMTP id w12-20020a5d844c000000b00734e7c02058mr5137379ior.9.1677695048927; Wed, 01 Mar 2023 10:24:08 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Stacey Son , Juergen Lock Subject: [PULL 03/10] bsd-user: Add sysarch syscall Date: Wed, 1 Mar 2023 11:23:46 -0700 Message-Id: <20230301182353.21559-4-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.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: 1677695120496100001 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 Tue May 7 23:20:35 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=1677695130; cv=none; d=zohomail.com; s=zohoarc; b=FxGJsf6/6bT/IahlyqGksB+rPB6uBoP3ID/523ZCkUY0kXfmrUXiH3Xe2IpaYwlORwaB8eiJ4zvtkPUIJOYpdpwpzMx32cRLNdXMwiOXufsbjY3GNSEoUMKS+y8FK6N6bmkWtI1zjDVvSJRpHmGDEkYnSLB2hmyGRc61AvQhmuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695130; 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=qS3B4XxCtOnwr9umuPwlWj5mJg7Wr0+I5HiEP4TPEHo=; b=JuzzdruzrWcPWP+HFpIbNFmwCYXPrMGdFh/BmJuLdh6SoPQBpalPu3v3I/DG4MQ2DkVKwnGPWbG4/EyvryxjINl5cE5yUKA19cP5g4wmgaXdCxejJLKibOp0xIZC5c26YxiqaP2BlyM8I85KQZpAIxOK2mMabABTzlvpacQUGGE= 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 1677695130091731.154687576582; Wed, 1 Mar 2023 10:25:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7f-0005Tj-Ff; Wed, 01 Mar 2023 13:24:15 -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 1pXR7d-0005MV-46 for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:13 -0500 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7b-0006o2-Cq for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:12 -0500 Received: by mail-io1-xd35.google.com with SMTP id d12so5746291ioe.10 for ; Wed, 01 Mar 2023 10:24:11 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695050; 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=qS3B4XxCtOnwr9umuPwlWj5mJg7Wr0+I5HiEP4TPEHo=; b=ec4v1ib+Eubog1MGJ6PD5+1ltVOW+9acWaNPrj9INDgwN7PYU9sSe8n8HgdzWlLOuI wrrv+97guwVzulzn8ebAMsgyIm2RSqHr1ssDjh29AUbUzF8uz+bF5syMswfKd/NQfipm st7sk1T/91a5HwHwTuWO3l5iNlBONFyOkq6heMPHhTQAQyRCHlGlOoMtlx+rqEex3ewe YU3laDkNcjlK+wD6eyZVBE3ssz3aeLYLv9wUEFaOYhRcwLaF+C0KJsvDHhhhmfHAJ+19 RV1rCIptjlIxs+vYZOWYPCrkuVH1VXgCtTXr4P+fNldHkUn3RnuuzELLoGs5fRmbwSX4 wlkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695050; 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=qS3B4XxCtOnwr9umuPwlWj5mJg7Wr0+I5HiEP4TPEHo=; b=FBDEoiRX923AJf7JULDbZmAoS9B19wrkDJoPnqJXEVu/NNpBp643jX6Wuq1AdiEe8g zZhnJF2tXE29EOdxhVw53tH1J80wAIPwV+y4+sHZlDfZZpYdqpRetUrbE6WjedtuNOjG 1R/8DzKE9g7K2L/cHU4H0ZVLytSxDV9qpv0KUBnxVsPTPBcwzQQyYtBiDTVFn8FcbIQ1 0F/VVOLkyQA4lOIIMormDegz58Cu+GIhZhmvQHEGH1mvBKDtjHQkeR4ls7pofGTF92yv U0tp5r13faMV7Qgx51Oad91qlzzT/fC1arZ8+6aMN0wXbQDMyUMHzB3/Alp5mqw65AYh RiRg== X-Gm-Message-State: AO0yUKXRUIIR7xOzTvJeI+ytf0GrtazEnHr/Uq79mAr4xNRHWHDaaXdm +5gNG4rNLvg7MxexEpQa4jtUypCf4WT2Pn+F X-Google-Smtp-Source: AK7set+tD0EQXdfSQZNV4QKo6opa3SchPjfBKJQxVjy6XuBtUhUwn1ZV4U4ekArk89DjFRp3mfxh2g== X-Received: by 2002:a6b:ee0e:0:b0:721:d759:ab16 with SMTP id i14-20020a6bee0e000000b00721d759ab16mr4712118ioh.18.1677695049752; Wed, 01 Mar 2023 10:24:09 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini Subject: [PULL 04/10] bsd-user: various helper routines for sysctl Date: Wed, 1 Mar 2023 11:23:47 -0700 Message-Id: <20230301182353.21559-5-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.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: 1677695132191100003 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..a4f3fd8091a 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 Tue May 7 23:20:35 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=1677695119; cv=none; d=zohomail.com; s=zohoarc; b=W99D3lLhkjf+rYeQPSwcNVwoJ14cpT8VHvOdwLfLcnW2XdCYwpR/Nq/AmGMPlTnvQ4xfl4oZrjo8iND6SAWOgAFp14ch8il+svdS9I5cPrW++vLPHDrv099XlnFtP43dTtGOpLwimVwEWvkHuCu7PJ7Bkiqx/0zz4682VJjaxVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695119; 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=ZHZZAEauaqUmmv34opJ70pPD5fSPwd2yVcyCl/DdvEc=; b=Oa1o11vSmB5AcvBhHZdsImBqQqOu3nGcJYzDPo2gOFTbuXv+/pVNMFk2GQbgw/bRm7RrRuvqbu6V9tGxPzYPjqmtnqNbAQGLdIh5Ow39TVHrmqi5LVrlr3Hv0zEyzvcIkCCbL9jHlFWy7wJty6DRNFNOV38O1WVfWzNHjhzcDX4= 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 1677695119167818.068605797542; Wed, 1 Mar 2023 10:25:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7g-0005UI-61; Wed, 01 Mar 2023 13:24:16 -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 1pXR7e-0005SB-Cr for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:14 -0500 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7c-0006oS-HH for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:14 -0500 Received: by mail-io1-xd2c.google.com with SMTP id t129so5732779iof.12 for ; Wed, 01 Mar 2023 10:24:12 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695051; 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=ZHZZAEauaqUmmv34opJ70pPD5fSPwd2yVcyCl/DdvEc=; b=CB8JfYLrIvLFgMM4kJJdrve54T9cHS/SIO2nzoaI36GO51MX6CMfee/vf6Xf+PjA0b kazdZC5ImYOpy9Zh09ytTEOkU49K4bu48r8aMcbdvE5gn5zrCeDjh0UgdOOqgeSM4QFn xfJ243Bq2V060lraLlxerPQ81YDVsFRfxwfaN1PAGbBNQ6Rj4zPf1DKp8421cIsJzZ+K Vpi8jbbgjC3tgZGBdB/hpm1SGlyhCwT5YROmZc8wlMJ8r0xqmELfG341/ZvzMfoE/2OR n74O9ex/9ezINI0e5Zgw8815Uq6k+HE7BxQiMnLCYkbRui6a1390+bWtoRz3TzKkjCfO 9xqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695051; 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=ZHZZAEauaqUmmv34opJ70pPD5fSPwd2yVcyCl/DdvEc=; b=W5ikjBA2af5Nxr9FauVLiaSQ5lHgOU7noXy37q++sedpwi4Ilkj2WX4QiQy15727iN E0jz9kI3Sg3ryTqCQ9NWomwJMR045XJmSYAWLeq2GF0SQcNT8HT65AhY8cHXtnRY1nP4 Ljr1w3idVIwiQbDbb3O4WqI2EkXRkzCGhghl/RpMZizd6vCSsPfMrX12RC1ceWn9hjw6 gwlqtAIuja41siSOVTn5xR2m8DSLM5Ka0sUUQ52LZEhgYwt3/ax92fQJFXc05g98WMfE TpYcuRGE5Ap5zJ+wkxiXHodFqukWCIAv10uiizIkCqDwYoIU3fqpcq4SS5qHL8TpfFah qv+Q== X-Gm-Message-State: AO0yUKVt2gImErvRLA1boR4Ca/aIhfnizdhwI/h9dHRHwDHe9AdgNPHe Th56jVduFNSORbbgNAUXw/LZvo84SJtDHPE/ X-Google-Smtp-Source: AK7set9EpFiRwO5qgscitDFroenHkqQ0N3PV6qAnqHleG1Ot9e7EqKfNNAAPA3/jBKf5QcHbfvwDjw== X-Received: by 2002:a6b:ee14:0:b0:74c:91c2:cb05 with SMTP id i20-20020a6bee14000000b0074c91c2cb05mr4705663ioh.9.1677695050840; Wed, 01 Mar 2023 10:24:10 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Stacey Son , Sean Bruno , Juergen Lock , Raphael Kubo da Costa Subject: [PULL 05/10] bsd-user: Helper routines oidfmt Date: Wed, 1 Mar 2023 11:23:48 -0700 Message-Id: <20230301182353.21559-6-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d2c; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2c.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: 1677695121371100011 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 | 131 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 127 insertions(+), 4 deletions(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index a4f3fd8091a..2e0a6c058d6 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); } @@ -107,6 +107,129 @@ static abi_ulong G_GNUC_UNUSED h2g_ulong_sat(u_long u= l) */ #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; +} + +/* + * 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 Tue May 7 23:20:35 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=1677695135; cv=none; d=zohomail.com; s=zohoarc; b=HSFHSZhU7KPTq7TlbF1dpgviZt7GUN8S+c4GFSJrgnXPd7ERjCWMohWwIYcN7+tygZzG29jqMpY9skXpALU7ZOtKtC5O5E60g7iMigGjO9+zmk/iEjNyzkhPiZfqiBqK8DebGKOKRW/IQymTcGfHWcPIete+d8OwbQss+42htps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695135; 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=NxoN5n4N6BYnJr2Y6dOT8glUld4sqkDOsis39Qr8eQk=; b=He71ksIzwDTJMN4jjkSBQPNdZUjJW5s3PkFWRtpFbJBwir5IeGVPtxI9IcDrx4lbI7yxAoMHmG+9eY76A0Vsk9K0sjX9a/9170gMTZtyMZqz44WjyndQqwOsCKDVzbkazfWF3oqiJ/2CXzrSTFUWrVW2cjIWA+9cMVt8A1coW9o= 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 1677695135408750.9699734105277; Wed, 1 Mar 2023 10:25:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7g-0005U7-3H; Wed, 01 Mar 2023 13:24:16 -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 1pXR7e-0005SK-Ex for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:14 -0500 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7c-0006ns-SQ for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:14 -0500 Received: by mail-io1-xd2e.google.com with SMTP id y140so5745692iof.6 for ; Wed, 01 Mar 2023 10:24:12 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695052; 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=NxoN5n4N6BYnJr2Y6dOT8glUld4sqkDOsis39Qr8eQk=; b=1dHAgrzMGWyS6kF1nnIW9sTYbdsVnu4uUGZhl1p8t8Fh8oV78qk41eUe4Mj6C53MPA E+HEKNq7x8NPawGUfqXaiMFMys11EHxRUrWVa9I4PCfabW3rghZ3wcAJ5vdEx+vQNyfG aJYUaHpEIkgkaTsZCZisg9AMXYM1I079NMdBA6N58fJqKR6YO8O624fqpu0Z3OzKnygG v4701ebawGtHXZCqWzQsaLqeozd5PoWP2E25NaEbpcouslgX5HloYyhV9B+S2f8q3kGG YMahN8BVZ9Q3WOEaVrXPxbScIl4tmrd/muFei6FNBHJCXrQraP3UQEz/J5rvdWMyB+hK tt0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695052; 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=NxoN5n4N6BYnJr2Y6dOT8glUld4sqkDOsis39Qr8eQk=; b=znF3ufJJz5z6N1XNoUBRDoUhPM0BQ+VDMcBtTlxYudso0dCTMs2ifgqONbx3/2TfYo nKedS99hR5OO2spAs+emGuCTX1HdAaweFdpkuxizEzSzadsll4L3x1ODV/EQR87JjIjk aNtSz366MGAf5L6K0oTzS18JjfashkKTwy4NyAAOPqTOwZNNAgVwxTuUh63pWmEL2Krl BQoFQo8/Kup2k2B9+Qc/cbaw1JXzWFfCnMwohyHXW6ria91pYNnKfZDO7LXG7uylHjUH Xuq5gYXdh4qT7TcS90bLM/TwACKNx68HDPQw72xLnxle8fALgPISD+VxnXFmbHz7Ev3p o91w== X-Gm-Message-State: AO0yUKXcLXdpdq1yKInK3bYo+PFPm/uYpTw0owTRcHHOUv/ubHUuRNV8 lAjT7VcsreGG2C5JSDKEUUEXIAq0uYe84csw X-Google-Smtp-Source: AK7set+vv0PtGi5diedFrG7OqojgOUzZBPq2hRyd0sRwFOrAIJ2SO5JZ4xGM2Gsl1RB4ni4SXnwQrQ== X-Received: by 2002:a6b:7c4c:0:b0:74c:8cec:548e with SMTP id b12-20020a6b7c4c000000b0074c8cec548emr4630005ioq.4.1677695051752; Wed, 01 Mar 2023 10:24:11 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Juergen Lock Subject: [PULL 06/10] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Date: Wed, 1 Mar 2023 11:23:49 -0700 Message-Id: <20230301182353.21559-7-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.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: 1677695136140100011 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 2e0a6c058d6..8bd1db69410 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -230,6 +230,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 Tue May 7 23:20:35 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=1677695119; cv=none; d=zohomail.com; s=zohoarc; b=Ctcse8SJlGHLXOg6FArQZCm2XH/6NaDai5gaERuxH837S9ZHjwusLnuIlpd4zkBUF9MYLT/UPrRiLxBbjPMdAVud4PY6fSUyaVfJYBHOOfE6yBSkRQQGwqF4/tu6MB3HuIXpJVW10d7UjkzeHX6AOk1fJXOUNp6N15RlPEN44QA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695119; 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=OIkm25uwqQeX2aVGvwwHhPrwHXZ38WH54KZn0L3p7RA=; b=bpO7V+pqz8ljfuZSHRbOc5kKKscEyW5NrxTERZODqgZBdIyGvO/Zt2CcLsN7pDScgNBYz08D7pAXz4vym8PChSzQBxeIXfrZ5DPNQ1cDZa9F7rlFl5RcVnkBpbytIiHSyodJlCqRpUgqzreN5nqHJvEyEC7fFqg/WG8bg1Tm+Xw= 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 167769511916939.98471864609394; Wed, 1 Mar 2023 10:25:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7g-0005UZ-Ni; Wed, 01 Mar 2023 13:24:16 -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 1pXR7f-0005Ts-GT for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:15 -0500 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7d-0006nR-Qd for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:15 -0500 Received: by mail-io1-xd31.google.com with SMTP id g6so5726269iov.13 for ; Wed, 01 Mar 2023 10:24:13 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695053; 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=OIkm25uwqQeX2aVGvwwHhPrwHXZ38WH54KZn0L3p7RA=; b=Lff79s6HUU/eYEYZ1okomML/VpKtB2eDhygCh6CjppwleO9eby7yBzDpWwAMPHrtoD plrb3DOu65jc6lgfCGvYgoWlJSB5+mIEq2SFO7keiuLIFf9CXbFFWJpWiDu5swyOZLc6 J50CiEiOw6QuY5bDPboBmY+tKGONIp/enNos5/m7t6ov4umokaBOs/1Wq+oPhDKimxBB WHRzWi/ONC+b0mSwRoJ7JiTeiFpGLZg1I8M/6bpISChDqfgEn/inCTqyEEx1Xd7PEpMn c6SE6hUf/OYeKIMWMzcxK/+pRtgMA+1T2i46IZ9YVYDSLQlbTF8y4zd06aJY7wG5K0hS 4KXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695053; 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=OIkm25uwqQeX2aVGvwwHhPrwHXZ38WH54KZn0L3p7RA=; b=h7OsIyRzXMSd03dIoS96KHpxofBA4nughn4cKxpwJn1awYVnGw2Br56WIjzu/pLcTQ MRyKCPCBl/AbmHnRZaIYvbv90ev64uYnt52wpfCpkfArZlZ1Y/B4yYpp/PV1036x2oro wEhtS9rnXmfz0d+SKH29bBYQSYzGBrR5PnKlIGlrXU8Glp210zjK7OsB+1NvPXumkoOC VQZyIvXA9eoQkAbGkRTrFcBHO/TEk/DFsS/mNF6YDIKN+aKkC/M0kIZKQjtRdzV/2Ytd IGJnmIklcE6MeoHXKceKS3g1ZV+qe4z5w8ZAjmV/GMhdNhKUDxywRSpjyEIX/Gi597rm VifQ== X-Gm-Message-State: AO0yUKWtgJhSUGwS9lu7/qgvzsRq24yLDr4flErgcP3/dlmYlJl6UfOC gQBIm30/lq5mmk5gJDhaTdzqZ4QvV6bgMCog X-Google-Smtp-Source: AK7set9EUHI7av6S1kAT4q4ABmxaxhPPgqo5CEOo66euqIi1X80F+eovHBMyJkuxtHCbHFMUHly9Cg== X-Received: by 2002:a5e:8b48:0:b0:744:b2c2:2642 with SMTP id z8-20020a5e8b48000000b00744b2c22642mr5342273iom.19.1677695052667; Wed, 01 Mar 2023 10:24:12 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Juergen Lock , Stacey Son Subject: [PULL 07/10] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Date: Wed, 1 Mar 2023 11:23:50 -0700 Message-Id: <20230301182353.21559-8-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d31; envelope-from=imp@bsdimp.com; helo=mail-io1-xd31.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: 1677695120598100003 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 8bd1db69410..625018b185b 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; @@ -233,7 +233,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 @@ -242,12 +242,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_sys= ctl + * 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 Tue May 7 23:20:35 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=1677695130; cv=none; d=zohomail.com; s=zohoarc; b=cpTRHyILaXr/52uDFhdAQKNjfwqNRlTpTc5UxUyPdN2HdEGr32LTk6jG4WcKzml19eZMPRpwAvQD2thFh+KDnsjXmp9zMz5nU6rvxaNoAX8gsdtvcsROajMAaPDErecAO2iZD5Q/mqb4Hs94wRKStwoKMPdrEngxPIwP6ONx0y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695130; 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=LeG5y+LKFT9Lmm5LAxfaRkWHoGaakH0jIgaTmEbfdPg=; b=OPDVF90qG65pa8MplgBY63u8xprhP790vgSfyVGXstJV+eZVgluOSsR7Q9ZOeyyORRxqWs2SY9+ICpyiFnvtVzL+uJA9uSFcXLotYFKixzwM/m73qhd16osUwzaBpxFcrLRV2hH/MOjYwpvXKToISBzwmTJsKHPL3s2e5FmxFSI= 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 1677695130977795.0064954621552; Wed, 1 Mar 2023 10:25:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7j-0005Xq-CR; Wed, 01 Mar 2023 13:24:19 -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 1pXR7g-0005UQ-KC for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:16 -0500 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7e-0006p8-Ui for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:16 -0500 Received: by mail-io1-xd2e.google.com with SMTP id b5so5770454iow.0 for ; Wed, 01 Mar 2023 10:24:14 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695053; 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=LeG5y+LKFT9Lmm5LAxfaRkWHoGaakH0jIgaTmEbfdPg=; b=4uqLZ3usCa2Btp+P1Z1FgTHGS9sa+a2QLJF3uLjEb6opdduag5KH0rkJYSUpo9rmoK qGEUZiFF2OXZcM8p6X1kUJkDPIVSFKQV2mazJ5Jccs7odrjqL5z20JYmpABI07F29p2O edpbYES81D1jTyOF/9qiB0P7Sx30RQDCb7gDUaUq/igIK9JsmHi9nEHXKGJgxOw5NXUc 0iYnEO/Mh+9CDQZ+OaNunckHjQBnOynYqHd3CeGAAVyP+JjB4EQbGZymgi8NDuVDDyM7 N3Pted3JwBgHQCrXSej+4LGOGJvZgXC9LOtp0/Y3/cWv9KpfPQeBSX/nGtmHwUL2N97Z XIcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695053; 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=LeG5y+LKFT9Lmm5LAxfaRkWHoGaakH0jIgaTmEbfdPg=; b=8FLOPyvwDV6mH6dAlo/xf9HtMbpm7os2ulvPhMkTqeSLXfq1jzNnyTYz0BXe89PB0S wYTnoDG/4qleZAj2Fc85BintfIWAq96Gc9i/3imySZRH8RaSH4lcq/6dB5fz3N/oPOHJ MX1PEQRtPobepKljokBrmh5u3Yszl4yjz2YYhiCIShO7sBFZX8Hoc2CxCynbhFU8LjwO ahifV18rmyNCeGTTHeIYY29+4nCP0dSYBN/g9Yrbt5nMSirrq5ZJX/7WAU/Z+6ybdtuz sejkLRcSyt1iSakrlQ8nYf9Wi4hkCm3jop8qgKggAUazJyKb+1/BvM6tY9c1CGr3UT9r UYoQ== X-Gm-Message-State: AO0yUKU1/AtYJkZXBpvg3WiuaojuFxGTrRiPnMgIhrGQthzHkQYwYBl7 ghV3H0ZVYwdVfE+41WMKoTXQoaZOeToULF2l X-Google-Smtp-Source: AK7set8iSEn/HJq7Q6m6oXlbljf8m9kqn53mGNLzV83zAP7p+sGJlMA9doaRFLnaPXmDNtt1pnApwA== X-Received: by 2002:a5e:8f41:0:b0:713:7b7c:46d7 with SMTP id x1-20020a5e8f41000000b007137b7c46d7mr5224239iop.21.1677695053591; Wed, 01 Mar 2023 10:24:13 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Juergen Lock , Stacey Son Subject: [PULL 08/10] bsd-user: Start translation of arch-specific sysctls Date: Wed, 1 Mar 2023 11:23:51 -0700 Message-Id: <20230301182353.21559-9-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.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: 1677695132392100005 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 625018b185b..6c9c2f8fd0b 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= ); @@ -263,6 +263,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)TARGET_PA= GE_SIZE); + ((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 /* @@ -326,6 +466,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 Tue May 7 23:20:35 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=1677695133; cv=none; d=zohomail.com; s=zohoarc; b=I7ludYiVhIfH4tKHiBcnw3dw/p1Le1YwzGP871w6SllzG5djR7tWz4PV22eKBTh3J33U3AZLYciow9+PIhd/DvpoLkSahOhWqwH2c6znvrfChvh2oLrgOgB8jami25p4P7ogeAsSr0cCWauE2f/4VDatcVKHvy+2ADPgiGP87GU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695133; 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=oVAFST4RrlFu4AcDhd5jEFTFoa+9vwKukHM5XKdcLo8=; b=LggYEaKYF6cm18SAkdqdiGwVothEJa4hhFYBQTtf+wQaj1g/12RfiZmXTnF7rVG0gxzJsikuXbi5jVuHstkwErOyeYkBF7mS3Wy+/Tbxl+lyipqGT2QDRq8qhmIHl6lQjae5MkCFDRCKVQ0hGd11pNG35dTnqGQmNbQCz7vc9xs= 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 1677695133135847.844804531644; Wed, 1 Mar 2023 10:25:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7j-0005Xn-29; Wed, 01 Mar 2023 13:24:19 -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 1pXR7i-0005XP-0x for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:18 -0500 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7g-0006pN-BU for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:17 -0500 Received: by mail-io1-xd32.google.com with SMTP id k17so514188iob.1 for ; Wed, 01 Mar 2023 10:24:15 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695055; 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=oVAFST4RrlFu4AcDhd5jEFTFoa+9vwKukHM5XKdcLo8=; b=ylSv5wMM3dTGykMhi2mJFs3RrAAtZZC4Hgkp9GkbUsCOJ053BuZryogyDsUanMeUbH SCXxNV8ZSU5K9Q2yArGhIZAMVNQealFwfRxDUiXRUjYWqUqsmMlffWEKlD8G81wJb5cp +D3paO4qBqADSHpWMhNAuEjVuKehEaMk/OHRXa/9Nb04iWIt0qoetoohKg+mTJRZ4cfy EExhMzu2UjAJD4B912l3jo7K52WiDdEEZl0XozUCJ8toxYZh9G18Aw5Aa4Ox4ydZ8gXz xUqQD+7WPRrGMtXQFAMnFFNHwD1zy2rt1IbMpW9vcmXe4h6J44UhzAhewiy/NChBgEwa 4Yxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695055; 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=oVAFST4RrlFu4AcDhd5jEFTFoa+9vwKukHM5XKdcLo8=; b=R3HupwoATEiLB20YIiDAN6hssc1U9RCCOxKje+puGf9XLNQ3gppgs+sL3+tBW19ZMg h0QvSMOHPg+rTv/WlrjVDAb1/Lpp6D3Sy3EtJJ0FeZO5IJ3cS7fjT08r/+YxsHzPKSB8 w/IHxhURJHL1afBRkrc9TmIaIvLgv0Zy+UVEbABRMegjpdj5nQluDEZcV1qr8810vygh 5N3ldzZtTp24tWfWL+Ah1h5y+UZ2sQHiSP+2J9kRD1IVOsTGMX1/omnKNggSGvF0huiW jdiygoZQxuREmkCe8fg6BgqZs564kPH0AGAbgT40CL7gSgTTn+iSm508sudNnt6wwSL7 e1Ng== X-Gm-Message-State: AO0yUKXRLvB0Y+dyrZvd3lTbPr3xInFtSZTQsrqZicUtwSqto9QRIcH1 diqrD9vZvdwWcPxxWCO6zKnQyu1c6JCM7zy6 X-Google-Smtp-Source: AK7set+tx7cbdADFT2GGg9ERMz7Ahrd+6xSqFBVkXJ6IUslb+PDuJM5t0ivF79cr6hxCXEPX3W2yhw== X-Received: by 2002:a6b:ed16:0:b0:74c:91c7:8794 with SMTP id n22-20020a6bed16000000b0074c91c78794mr4462610iog.21.1677695054732; Wed, 01 Mar 2023 10:24:14 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Kyle Evans , Juergen Lock , Stacey Son Subject: [PULL 09/10] bsd-user: do_freebsd_sysctl helper for sysctl(2) Date: Wed, 1 Mar 2023 11:23:52 -0700 Message-Id: <20230301182353.21559-10-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.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: 1677695134213100009 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 6c9c2f8fd0b..646b8e3f74d 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -248,7 +248,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) { @@ -471,6 +471,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 4e7b8b1c06a..208772d4ed6 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -253,6 +253,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 Tue May 7 23:20:35 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=1677695137; cv=none; d=zohomail.com; s=zohoarc; b=m7fshrziOcLGWy/wKkGEFMsmBo9/cZPihQJtBjVMDKWVajKHUbNX5CO5r7m99kffL40ogzdyDcyYAWInHNoZd5EwFv1D5JY6OE3cS3GWj3yQmYnbr+M3m7Vfh4i+hLIghFRXLKJX4SkE7yh80OBRAwIO/bRXZ+gV8lQ/iwKp+bQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677695137; 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=izUUSmVMMLad6kw3jAaqzTh4DzadBB2bLLAowF8XXvA=; b=KrV7RUB85zb5Sj1CoDQqrXPW4UTIGzxYs7XilePNwO3VFgMDSQBHWM1AfqslQw3eejSo/q5lMTZgHa7bPdPiIjAgjTJVyuDIiR7ZD4Ilb4q3bo0fJPPq5jUE/pRZKh3+TYrrBdSuY9EmfM8Vyn7OYf+M/RPydXOZWQ375noD73k= 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 1677695137250801.5513924241183; Wed, 1 Mar 2023 10:25:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXR7j-0005ZJ-R1; Wed, 01 Mar 2023 13:24:19 -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 1pXR7i-0005Xf-NK for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:18 -0500 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXR7h-0006pV-4c for qemu-devel@nongnu.org; Wed, 01 Mar 2023 13:24:18 -0500 Received: by mail-io1-xd2a.google.com with SMTP id v10so5743765iox.8 for ; Wed, 01 Mar 2023 10:24:16 -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 l5-20020a6b7b05000000b0073f8a470bacsm4169316iop.16.2023.03.01.10.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 10:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1677695056; 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=izUUSmVMMLad6kw3jAaqzTh4DzadBB2bLLAowF8XXvA=; b=Cx4Pm+hQ+2KR5pMe2EXrKniIOU2q0A9yYEuoBdqNkElyrF7bKREJn32gN6lH4A4upi 5Av7JaWb3F1HdEx9WuEjjNHf8FggEtVP9IIn3hYvWRPaIImQOtaFgQwInh6qRxwS2kqA 5TbXC8NNanyyqg1paQ/JngH1lPuM0WXt1e5QeAfVrk3hYsO7avzU7Wxz0ji1u+JcCDSK CHN77Qr6deyBwfSjJHsmyJ9f98yU2qwNKJ4IRGe9lLp4lfcPlJUgmrOW5F4sWKMKdHL3 GyX2OHPH3m1CAaxdfFfMJZCB9GHLxDVKhrsWf6zd3QhDJueKA18c2i1pwDbtTaafZWBv M52Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677695056; 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=izUUSmVMMLad6kw3jAaqzTh4DzadBB2bLLAowF8XXvA=; b=Bhzmc+lQDUPTTbltdw/JzQ8zRMeMArwRWD54ONjxofh8YprLjqcuksUImKmT1jIryX R/e6GNEzfP3LEKrmPlICyHq0L2Z1nFHUeVY91iu5tWiFelZ82rwbH5cAy+Vc/BlsQzfY OSQN2MvS1Zb9BBJJDr2qu4NXLX/IE/mxM20VEwxmgJcs7RVWSD/Z2qDISbLIULLoRrTS IDjXQZcv9tXn6tUqmPISjg8TxjGgggkxxg3u+kP+Axrd4PfLBwsXms8bBcdcwh3zL3u2 n9+s77Tc1I5dERoSFGmkdek1asP6fGT8UjdlG/0FWbFV7rdADRI2JuRPPh1eFgwdwalk PpEQ== X-Gm-Message-State: AO0yUKWLl5vKSPbExpLh+x6HSmr3NfN0Rai8+SauIPzmnzXj0wUzoT6A hMEnXqzjm51AmyH3CaoK4nAYbvgA391RLbc/ X-Google-Smtp-Source: AK7set//HoG/rzR6f39nmr8PpbuSH7YwchLIwPbdfb5TaIE97JtrA6HQTs/JQUwHHFGtOHg2HH1oXA== X-Received: by 2002:a05:6602:22c5:b0:74c:8b1c:239c with SMTP id e5-20020a05660222c500b0074c8b1c239cmr4472109ioe.10.1677695055613; Wed, 01 Mar 2023 10:24:15 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , Warner Losh , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Paolo Bonzini , Kyle Evans Subject: [PULL 10/10] bsd-user: implement sysctlbyname(2) Date: Wed, 1 Mar 2023 11:23:53 -0700 Message-Id: <20230301182353.21559-11-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301182353.21559-1-imp@bsdimp.com> References: <20230301182353.21559-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::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.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: 1677695138180100017 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 646b8e3f74d..df317065587 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -471,6 +471,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 208772d4ed6..41d84e0b81b 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -255,6 +255,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