From patchwork Fri Feb 10 23:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=mWlCYK/a; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8v84mV5z23hX for ; Sat, 11 Feb 2023 10:24:04 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcj5-00079s-GW; Fri, 10 Feb 2023 18:22:43 -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 1pQcj4-000790-5Q for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:42 -0500 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQcj1-00051W-Ru for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:41 -0500 Received: by mail-io1-xd33.google.com with SMTP id w24so2537219iow.13 for ; Fri, 10 Feb 2023 15:22:36 -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=YZx/cesf8ubpxj5ZEsfC2inUjsK/fycZyKobQ/kbFiQ=; b=mWlCYK/aqno9hLIXbtFLEXgknC65/WPlzq9zTG1rNsqmlL4wM8GgjxEZlUUg4DZVuG hLye0wSfXJ38oNMD37OFTTGaw3ey52+iAWnOzxVEym0rBiqEahQGULa2LvTlsWzYbLOW rzSUkdSy/VOprMAP2Ua9EOZAxKoMVYCwmWo198ydoRgdPRfu6JkxY4BfWYnbh23hnEls 9hb1j+zI/KlPP+K7Tb8tYd3wQoIAdCaMxrTZ853cOAnwVYLKnqkpQtbY8m2ADvr+VWxE Pwr66xmA3L+57lethKq3476nzpUjrSSEZIUSW5B22BR9vAKVsVb3iBWwcUqRFQrwH+oS uMrw== 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=YZx/cesf8ubpxj5ZEsfC2inUjsK/fycZyKobQ/kbFiQ=; b=Qswu8C6/tfmfSqRR1SfRi774VYgUlNfhF0VjzIgx/G9GHK+A5OgeSI23uvLW57P4BY MzD89wdqip/oQMYR0Fw2ClimmCsR1rag508weiwoj9PC8dtFdqz2oH5+uWWeF8IFsp1H NmY3bjZ4ucQdYxw/eUB+/+pCR28YV6+WdYrQwuoSZSQ/MZpGJnso+uIItn/8MGDezXo5 zMPhTLp0IO4kQs/mW0C3mlizj73d5QsAffWWvFtrENfBCWjQ+GvfiOG71tzsDMFLCMaH SSOtuPYRNO6+19ELt3Q8SpPT6zOPpMHiaNwVbUwwmHs6H8Kl/XHZcyRK4WyE0Fc7hgke HheQ== X-Gm-Message-State: AO0yUKUyC9zpi8nn+iS1FzH9AVdAShtX8ZbpzseVX0eV+ythuQ+miNvr VGqp6EyY3tVI+1xMV0gHxrsOQtlKV+ik6GqT X-Google-Smtp-Source: AK7set9rclTjQQcVV5QRzUSC2JNZ8pi8C+E4oU4465MbdZR5v0O/dFqa0Lxc83wbAU1x9u5DMwxIkA== X-Received: by 2002:a6b:6f14:0:b0:734:87f8:8d01 with SMTP id k20-20020a6b6f14000000b0073487f88d01mr13469072ioc.5.1676071354921; Fri, 10 Feb 2023 15:22:34 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:34 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Doug Rabson Subject: [PATCH 1/9] bsd-user: Don't truncate the return value from freebsd_syscall Date: Fri, 10 Feb 2023 16:18:21 -0700 Message-Id: <20230210231829.39476-2-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Doug Rabson System call return values on FreeBSD are in a register (which is spelled api_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 = env_cpu(cpu_env); - int ret; + abi_long ret; trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); if (do_strace) { From patchwork Fri Feb 10 23:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=oM0W7SAa; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8tV4xkFz23qy for ; Sat, 11 Feb 2023 10:23:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcj4-00079O-TA; Fri, 10 Feb 2023 18:22:42 -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 1pQcj4-00078x-1N for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:42 -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 1pQcj1-00051k-Sd for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:41 -0500 Received: by mail-io1-xd34.google.com with SMTP id j17so2538291ioa.9 for ; Fri, 10 Feb 2023 15:22:37 -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=oM0W7SAaJ27tWn/wmtYpN8eFV5izsd7Aq4JtigWEkxqkB+pGTU2GrGpH3sx1v/pOHb iE2Xztrm/s2cY1sfvY3mOo9oqmI8+Tz3l2Nj8NK0aFzyRY3ikvF4pzm9YecxoMOcGOLN NSCbGZa3M4GJ5IbaRAZBJgnHkskhzLwd6JGBVn3+dPV6CtUIlCfdI3ZtEqcbboZMyd6H xloUnxULt3yzLpUJv0C0TWk5pOn+yjzQ3JCpjJSpGQmSBUfCvphk9ZgBpLiJgioJMCmM gH1DJQoLqTf23IhLilAhz382UbwaIHrl5rchRNHgdzera9rSueCg6tJfgSCnkdHX9dnh MDqA== 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=dkYMHNtcqO+aVBIrlLhtScDMlg+RLgwdVLHrnvViJxoFvKo2uuQAu4Gcwuk6xvWpO0 qw1jE/rt+mr9lkN7sKmPzijrjmZErHgH/8nYzY0V74PC6E2h9Emmw5PNAVUfahAH13w9 P9g1U2i0Hdlyu6OxyAHMhZkvpn2+EEVo7MBV6+zZ8nniQjV1sZTmA/QezM3rH8EGMyQ3 apM562+CgTzMChxX2J1NxnaqWNNqtZPXbAndAEczwDSfWErn6u9AFO5HrSHho8VtnYkY XMKhYNcJK6li/OSdfesZzudTsbVrqa/Nbp4cUnRbG84oTGsxVCiByIbfaj/L5WaLEjRX XCKA== X-Gm-Message-State: AO0yUKWdmvBSt5NqUWGx1YdXyxTu9G+dpinXpogg2wz+uYUHPEQTMg7R i/IJui0biTIxcquZGdxr2pPTYs3Lu+TC3P9f X-Google-Smtp-Source: AK7set9CPWrvskOWCAWrtbbImUVFItiZxjwaHpdeezOIRTRlFFQXcUx8elhcM9++Szej9X/Ho2xgzw== X-Received: by 2002:a5d:990c:0:b0:73c:459b:de72 with SMTP id x12-20020a5d990c000000b0073c459bde72mr523903iol.11.1676071355931; Fri, 10 Feb 2023 15:22:35 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:35 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini Subject: [PATCH 2/9] build: Don't specify -no-pie for --static user-mode programs Date: Fri, 10 Feb 2023 16:18:22 -0700 Message-Id: <20230210231829.39476-3-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When building with clang, -no-pie gives a warning on every single build, so remove it. Signed-off-by: Warner Losh --- 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" = "yes"; then error_exit "-static-pie not available due to missing toolchain support" else pie="no" - QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS" + QEMU_CFLAGS="-fno-pie $QEMU_CFLAGS" fi elif test "$pie" = "no"; then if compile_prog "-Werror -fno-pie" "-no-pie"; then From patchwork Fri Feb 10 23:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=hQ5h1pK6; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8tV4rsxz23hX for ; Sat, 11 Feb 2023 10:23:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcj6-0007B0-Re; Fri, 10 Feb 2023 18:22:44 -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 1pQcj4-00078y-E9 for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:42 -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 1pQcj1-000521-Sd for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:41 -0500 Received: by mail-il1-x133.google.com with SMTP id t7so1235238ilq.2 for ; Fri, 10 Feb 2023 15:22:38 -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=UUn6fCDhi/Gm5iX7/obKBuiF3I78ANSryTgknqIzZhk=; b=hQ5h1pK6P1JFvJDbJDesxRiOSfUnb4S6z9jGMymfLqV/DBxgnUrjuc+xFeNpzPbMjN HVUpjHMqovUlugDHD78WDk7Y3l1X6OO3egjhxzdqB7myW0BNmE4CNMMGck+NEAqPbsqX nIzO9WmpfdBvhviokBXSItON2XF3HqsbTukmiUB0c3Tt2pLQ08LpMN37vQC9y/w9XO0U J+fWX83valZDY9+zVy1mlceMENGY0L4ov9tirjnIUvVIA0UEetSf28OL410aS87jkuAK 5T7FiHs772hx3gzWMD+vYpM8uZoBzLd/39cQS5JsEoelG5yaJySyVJe1sIM39MHM3sdD S5Ew== 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=UUn6fCDhi/Gm5iX7/obKBuiF3I78ANSryTgknqIzZhk=; b=1W6FZNVH7xqteo4q4ONSL/++EE7GxC/4Mtjh0hMILhp1ag88PBLz2cWdLHTSYiBnmq Lm9Xjl7m2eYFH8j/1uKKNoITF5Yu8xSrsNEQ0EM8ystGhVBKOs9fT3tvwQItzAdK1MfI 6jDUuy1WHDaetCkmwotyqqa/PfYRSNzvZtXi6Oy3T58b/ru+PxSaWrcjCiHXwijIkIkK 3lOo35N0DXZMU1ij5K0nTiHgRLBJL11cdTKXBxLLqgAx4t8YNC3O2gtb50nedV06zpXm 9exot1CBzqgPQOkGksZQDu0C1gZMzQoPKUQ6+jxkunxKaLdll7I7H1Q1W2HG77D1H/m8 ae/A== X-Gm-Message-State: AO0yUKVV1DdKd7y4engLmrzhHTncGgh5vR/FvXe1B4FILhcNvT4KeGVQ rUGYRPSqxyT65dGWaCwQlj54sJc7Prn90Vzh X-Google-Smtp-Source: AK7set9UppUjcDRVmWR83D/AFjQD0k8CNZE2Ey8XCHhu5iDdcH2VNF2BOIGDI4J0MtmujpcgBNHGjA== X-Received: by 2002:a92:c243:0:b0:310:e816:8c8c with SMTP id k3-20020a92c243000000b00310e8168c8cmr18901303ilo.3.1676071356953; Fri, 10 Feb 2023 15:22:36 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:36 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Stacey Son , Juergen Lock Subject: [PATCH 3/9] bsd-user: Add sysarch syscall Date: Fri, 10 Feb 2023 16:18:23 -0700 Message-Id: <20230210231829.39476-4-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 = do_bsd_undelete(arg1); break; + /* + * sys{ctl, arch, call} + */ + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ + ret = do_freebsd_sysarch(cpu_env, arg1, arg2); + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret = -TARGET_ENOSYS; From patchwork Fri Feb 10 23:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=4nN5IOvt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8tq4qTLz23hX for ; Sat, 11 Feb 2023 10:23:47 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcj5-0007A1-LA; Fri, 10 Feb 2023 18:22:43 -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 1pQcj4-000797-H3 for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:42 -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 1pQcj1-00052I-Ry for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:42 -0500 Received: by mail-io1-xd34.google.com with SMTP id j4so2541820iog.8 for ; Fri, 10 Feb 2023 15:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o/PfMiTwVI7mqWAuo+VTzIgWf7FM21PP6lXlcH7i8/I=; b=4nN5IOvtORrsYV4RpL9QVXQzKYoK0s6ydF4KQ+cNibas2rUQvgaf2nTZwQid4I9QES IAKLAahy14LsIGkSV5k+tTX7OSJkpnm9EY0fx0/Sylk7gU6SG96kSXSQ97Yc3oSJWMRm ug3TWoVb+2w3wsU0Yz0ZH4CIbpkfG/S7kFitRgQNDl8rU7RT12dx6qEotQOL6bv4l8Wy RkwBmkzCaUs/DTeJk8JqZfQO+YLBIRzPDPU643FCcJps6+5w0cAVjkMLD5ZJbu0Pqktb zlfWV2/scsS1mvod0RZCeGAnZbw9Vy4z+P9uC68ZoWnyv0FwP4p3MtHyHBUAJHBN+LJr WxoQ== 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/PfMiTwVI7mqWAuo+VTzIgWf7FM21PP6lXlcH7i8/I=; b=N5AjN3P27tceSSuYlCkXOMLX64FEMYnyOtW7NIm9PHG1bxzdfqkBmnfClLKZlIanoK r2hOjP9InEKWRUitr7XTwZ/lF4fQrjcNh1016iLLIh0WYBHmGeMIAD1PDjzCpuhADtfr prZ8kJ2vFAsHUyZuMgL+drbJiwoUQ4dBUzo4UhR8lNb/SfXR64TrvF3x7kJzq7RzeBf8 HGc+dwN8dljOuIzfXA+16cf7uoamwScLcShZbRzNkJcKb5mHAiwRNE9y3gmxYu05xAtO pD5gYzVC28G9gD4OENYQ1p+h7BYc1qKb7ls3+k+iY0X3mS9dqRJsQuHxzS4zIsdWAmmp qCsA== X-Gm-Message-State: AO0yUKWTaugESAKu/IcEuGFiyilQZjkv3ZONj+bqpPeT4nqAQ+Pesghn 09zxq73DHZ+TnLiJgHI//J01OS69Zhzh7As4 X-Google-Smtp-Source: AK7set/RtXkgflYJ7HvQPbcBVfV7FhSbSwRHqIhbEe8C1Nkka73xyW9znfpBzlJDA6TBiXsyTf5vag== X-Received: by 2002:a05:6602:3404:b0:719:99e7:4623 with SMTP id n4-20020a056602340400b0071999e74623mr18995780ioz.18.1676071358064; Fri, 10 Feb 2023 15:22:38 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:37 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Stacey Son , Sean Bruno , Juergen Lock , Raphael Kubo da Costa Subject: [PATCH 4/9] bsd-user: Two helper routines oidfmt and sysctl_oldcvt Date: Fri, 10 Feb 2023 16:18:24 -0700 Message-Id: <20230210231829.39476-5-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son oidfmt uses undocumented system call to get the type of the sysctl. sysctl_oldcvt does the byte swapping in the data to return it to the target. 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 Signed-off-by: Warner Losh --- bsd-user/freebsd/os-sys.c | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 1676ec10f83..e3b9f168a2b 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -21,6 +21,100 @@ #include "qemu.h" #include "target_arch_sysarch.h" +#include + +/* + * This uses the undocumented oidfmt interface to find the kind of a requested + * sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to + * src/sbin/sysctl/sysctl.c) + */ +static int oidfmt(int *oid, int len, char *fmt, uint32_t *kind) +{ + int qoid[CTL_MAXNAME + 2]; + uint8_t buf[BUFSIZ]; + int i; + size_t j; + + qoid[0] = 0; + qoid[1] = 4; + memcpy(qoid + 2, oid, len * sizeof(int)); + + j = sizeof(buf); + i = sysctl(qoid, len + 2, buf, &j, 0, 0); + if (i) { + return i; + } + + if (kind) { + *kind = *(uint32_t *)buf; + } + + if (fmt) { + strcpy(fmt, (char *)(buf + sizeof(uint32_t))); + } + return 0; +} + +/* + * try and convert sysctl return data for the target. + * Note: doesn't handle CTLTYPE_OPAQUE and CTLTYPE_STRUCT. + */ +static int sysctl_oldcvt(void *holdp, size_t *holdlen, uint32_t kind) +{ + switch (kind & CTLTYPE) { + case CTLTYPE_INT: + case CTLTYPE_UINT: + *(uint32_t *)holdp = tswap32(*(uint32_t *)holdp); + break; + +#ifdef TARGET_ABI32 + case CTLTYPE_LONG: + case CTLTYPE_ULONG: + /* + * If the sysctl has a type of long/ulong but seems to be bigger than + * these data types, its probably an array. Double check that its + * evenly divisible by the size of long and convert holdp to a series of + * 32bit elements instead, adjusting holdlen to the new size. + */ + if ((*holdlen > sizeof(abi_ulong)) && + ((*holdlen % sizeof(abi_ulong)) == 0)) { + int array_size = *holdlen / sizeof(long); + int i; + if (holdp) { + for (i = 0; i < array_size; i++) { + ((uint32_t *)holdp)[i] = tswap32(((long *)holdp)[i]); + } + *holdlen = array_size * sizeof(abi_ulong); + } else { + *holdlen = sizeof(abi_ulong); + } + } else { + *(uint32_t *)holdp = tswap32(*(long *)holdp); + *holdlen = sizeof(uint32_t); + } + break; +#else + case CTLTYPE_LONG: + *(uint64_t *)holdp = tswap64(*(long *)holdp); + break; + case CTLTYPE_ULONG: + *(uint64_t *)holdp = tswap64(*(unsigned long *)holdp); + break; +#endif + case CTLTYPE_U64: + case CTLTYPE_S64: + *(uint64_t *)holdp = tswap64(*(uint64_t *)holdp); + break; + + case CTLTYPE_STRING: + break; + + default: + return -1; + } + return 0; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Fri Feb 10 23:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=mXlBN2Jr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8v03Y8cz23hX for ; Sat, 11 Feb 2023 10:23:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcj7-0007BF-IF; Fri, 10 Feb 2023 18:22:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQcj5-00079f-9R for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:43 -0500 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQcj2-00052c-OD for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:43 -0500 Received: by mail-il1-x12a.google.com with SMTP id w13so2917998ilv.3 for ; Fri, 10 Feb 2023 15:22:40 -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=sMGqedAh8Ans+v+hJJSpSqEHhstJlaRxbkoS1A21XV8=; b=mXlBN2Jr9FVfellGhEpCMzsQuiMqDPvSO+uGPTVldVJKLdICjeY0mIy59KmnLAKdZL 4DouulfDb/qsgFU3o0/c5r2t5Sv5l/IwRt+r7MRPVWMk9XAnJEm3W5qM/Y7b+0Zaad7m 7gLPZg0np5/UGoEBLO/F/9Vqx5zxMsvsGrMUwitnzzvmNirC+SG7U9l2EWN0p6r/ucmS SkqXC5WlyCnVFmvYavjuoFcuHgoWErt2VSx6pcn6OZma3fInKYUbZ9kJp28mwo9tieTn IrW1WkwlLZeGOcYzM1ImmSKPA0fi/yZj0i00vMImiGNngFwtx5T1XLWsjmjieg/7Fe80 1Tig== 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=sMGqedAh8Ans+v+hJJSpSqEHhstJlaRxbkoS1A21XV8=; b=493ZNT/d+0HpJrkwaOW8qgxU5a/MuiiWA/WGZXYwhs1Q4CEDgynatDqXMqXb+mDpin GvRU5G775AQZi8CDxTL4Brojqm7mdTW0AdrweTBvDDBN0WzruiPphn1ziRBNG2/7DGVb /CxxWLQtH6gkEQugXmNZ7ukn0jnGfeHSpGreQ9aaRwar4Xn4YjuvP6hi6SckM6+cKfxD kfed9UnzV0up3vnxXidCj5tVSs60SqIJqqLRoMDuULJ6rIihbsTd4QlK29AbhorEDztb OhdUTO+XxuMt1/vwwamRL3wPxCyRxGVS2ApKYOHOTiH0qRDZVO7f44qopjs7wc0K05tW CRHQ== X-Gm-Message-State: AO0yUKWmQkFAAoQKpJbs5o6yEpJWvgU52MGxZwr1BTMwBKA7ybFuQHK/ vDHm8L+GH7/wR3Cxif4QJ+IrrqhkSKAZsUCg X-Google-Smtp-Source: AK7set/8vuS9+ug5uJSa2BoM4AMF1FkYdC1fgCZ6Ne0Cpt/xG272ogHgBrwnj+HOY+8gCx/8MuzB7Q== X-Received: by 2002:a92:2611:0:b0:311:e48:d64a with SMTP id n17-20020a922611000000b003110e48d64amr11896249ile.17.1676071359109; Fri, 10 Feb 2023 15:22:39 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:38 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Juergen Lock Subject: [PATCH 5/9] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Date: Fri, 10 Feb 2023 16:18:25 -0700 Message-Id: <20230210231829.39476-6-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12a; envelope-from=imp@bsdimp.com; helo=mail-il1-x12a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Juergen Lock Helper functions for sysctl implementations. sysctl_name2oid and sysctl_oidfmt convert oids between host and targets Signed-off-by: Juergen Lock Signed-off-by: Warner Losh --- 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 e3b9f168a2b..ac5ab9b17bc 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -115,6 +115,24 @@ static int sysctl_oldcvt(void *holdp, size_t *holdlen, uint32_t kind) return 0; } +/* + * Convert the undocmented name2oid sysctl data for the target. + */ +static inline void sysctl_name2oid(uint32_t *holdp, size_t holdlen) +{ + size_t i, num = holdlen / sizeof(uint32_t); + + for (i = 0; i < num; i++) { + holdp[i] = tswap32(holdp[i]); + } +} + +static inline void sysctl_oidfmt(uint32_t *holdp) +{ + /* byte swap the kind */ + holdp[0] = tswap32(holdp[0]); +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { From patchwork Fri Feb 10 23:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=kCGDjsUW; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8v40QTyz23hX for ; Sat, 11 Feb 2023 10:23:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcjD-0007Bl-OG; Fri, 10 Feb 2023 18:22:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQcj5-0007A7-RF for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:43 -0500 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQcj3-00052w-NM for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:43 -0500 Received: by mail-il1-x12b.google.com with SMTP id v15so2901772ilc.10 for ; Fri, 10 Feb 2023 15:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tDw5vzZ3WF8Nj3x4pvbSGQIQ3uW/UgV5IIjQeiqfa50=; b=kCGDjsUWQekmddRA6EUkNZiJ7u/9kTeCWCWZWms8k5yIKa+kIf2SgQQoGzY+ubNu2I SyCnJi8YvZfzMIMQXLukBHLyqe8fUSfUNibKqzp82Oxr/0VEKYrbRkCWydoZ2/zcnmiT UfZm2W+ZIoY8B9ATkH0AWi7ljH00ZoKSaZxK2GAEsqCA063W+IaVIUFaybHul909VMk5 p3YnU/7hSLTYUzDbWhJhdEu/GoxrUnj47XQ470Mmjq8jLS7q5TZpTqyTqFMz63yF6imj S/wBBIF+EkBtyuJq3+jb7VdltyMy16bVzDjWrOkHSfS4/+N3LxlHcxAsUCqxf8TGIV54 Xy+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tDw5vzZ3WF8Nj3x4pvbSGQIQ3uW/UgV5IIjQeiqfa50=; b=YF1vdKYZuvyYyuTQlx68uU5CnddzXA8EIoqeCE9e1lD1fkn83KnqisVdFgo1avpjIE O1N5jfcg5j0ePDWHwGMRCqy3oNrBIPfPv/GLs3VdUR2OzT03zQK3y2X+Jy0EhnIXxJnT h3IFZx+q4xEZbRZ+05Ck5Lmbox4eIZzsAECGLI8HClE9BBEEgoBC7ZazCqqwT+ePYlce +L74RTKp6JokWMFPUjZOo16+jKbr94hhbOQIvD8egKENhz+VjlkVJg0VGPUpsb9UY9M3 BqWm+P7LNN6XO+aVsUrNoIis3GOek1UCh5VAQdGpGBJY/jjrqiF1wbcq39i35mdbJWjw spMg== X-Gm-Message-State: AO0yUKVJtlZYhtpCNeUhqDQMSXNsEGUxOhQRAod4twyLpZuq0bDaal3R EaMHD+KLGYffNED+Us5g7ixGJZWywbCsf2js X-Google-Smtp-Source: AK7set/8WY2+Y1nKq2hf/c0LCegKVPhkm9/ay5CNfvIA6cu1mdNV04Qw8PFD5CfhFdbmbRPSDtkbgQ== X-Received: by 2002:a05:6e02:2141:b0:30c:2b07:547c with SMTP id d1-20020a056e02214100b0030c2b07547cmr19315922ilv.26.1676071360020; Fri, 10 Feb 2023 15:22:40 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:39 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Juergen Lock , Stacey Son Subject: [PATCH 6/9] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Date: Fri, 10 Feb 2023 16:18:26 -0700 Message-Id: <20230210231829.39476-7-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Juergen Lock do_freebsd_sysctl_oid filters out some of the binary and special sysctls where host != target. This commit focuses on the simple sysctls that can be done in a few lines. Signed-off-by: Juergen Lock Co-Authored-by: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Warner Losh --- bsd-user/freebsd/os-sys.c | 212 ++++++++++++++++++++++++++++++++++++++ bsd-user/qemu.h | 5 + 2 files changed, 217 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index ac5ab9b17bc..a8fb29f36b7 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -133,6 +133,218 @@ static inline void sysctl_oidfmt(uint32_t *holdp) holdp[0] = tswap32(holdp[0]); } +#define bsd_get_ncpu() 1 /* Placeholder */ + +static abi_long do_freebsd_sysctl_oid(CPUArchState *env, int32_t *snamep, + int32_t namelen, void *holdp, size_t *holdlenp, void *hnewp, + size_t newlen) +{ + uint32_t kind = 0; +#if TARGET_ABI_BITS != HOST_LONG_BITS + const abi_ulong maxmem = -0x100c000; +#endif + abi_long ret; + size_t holdlen, oldlen; + + holdlen = oldlen = *holdlenp; + oidfmt(snamep, namelen, NULL, &kind); + + /* Handle some arch/emulator dependent sysctl()'s here. */ + switch (snamep[0]) { +#if defined(TARGET_PPC) || defined(TARGET_PPC64) + case CTL_MACHDEP: + switch (snamep[1]) { + case 1: /* CPU_CACHELINE */ + holdlen = sizeof(uint32_t); + (*(uint32_t *)holdp) = tswap32(env->dcache_line_size); + ret = 0; + goto out; + } + break; +#endif + case CTL_KERN: + switch (snamep[1]) { + case KERN_USRSTACK: + if (oldlen) { + (*(abi_ulong *)holdp) = tswapal(TARGET_USRSTACK); + } + holdlen = sizeof(abi_ulong); + ret = 0; + goto out; + + case KERN_PS_STRINGS: + if (oldlen) { + (*(abi_ulong *)holdp) = tswapal(TARGET_PS_STRINGS); + } + holdlen = sizeof(abi_ulong); + ret = 0; + goto out; + + default: + break; + } + break; + + case CTL_HW: + switch (snamep[1]) { + case HW_MACHINE: + holdlen = sizeof(TARGET_HW_MACHINE); + if (holdp) { + strlcpy(holdp, TARGET_HW_MACHINE, oldlen); + } + ret = 0; + goto out; + + case HW_MACHINE_ARCH: + { + holdlen = sizeof(TARGET_HW_MACHINE_ARCH); + if (holdp) { + strlcpy(holdp, TARGET_HW_MACHINE_ARCH, oldlen); + } + ret = 0; + goto out; + } + case HW_NCPU: + if (oldlen) { + (*(int32_t *)holdp) = tswap32(bsd_get_ncpu()); + } + holdlen = sizeof(int32_t); + ret = 0; + goto out; +#if defined(TARGET_ARM) + case HW_FLOATINGPT: + if (oldlen) { +#ifdef ARM_FEATURE_VFP /* XXX FIXME XXX */ + if (env->features & ((1ULL << ARM_FEATURE_VFP)| + (1ULL << ARM_FEATURE_VFP3)| + (1ULL << ARM_FEATURE_VFP4))) + *(int32_t *)holdp = 1; + else + *(int32_t *)holdp = 0; +#else + *(int32_t *)holdp = 1; +#endif + } + holdlen = sizeof(int32_t); + ret = 0; + goto out; +#endif + + +#if TARGET_ABI_BITS != HOST_LONG_BITS + case HW_PHYSMEM: + case HW_USERMEM: + case HW_REALMEM: + holdlen = sizeof(abi_ulong); + ret = 0; + + if (oldlen) { + int mib[2] = {snamep[0], snamep[1]}; + unsigned long lvalue; + size_t len = sizeof(lvalue); + + if (sysctl(mib, 2, &lvalue, &len, NULL, 0) == -1) { + ret = -1; + } else { + if (((unsigned long)maxmem) < lvalue) { + lvalue = maxmem; + } + (*(abi_ulong *)holdp) = 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 = sizeof(real_oid) / sizeof(int); + + if (sysctlnametomib("hw.availpages", real_oid, &len) >= 0) { + oid_hw_availpages = real_oid[1]; + } + } + if (!oid_hw_pagesizes) { + int real_oid[CTL_MAXNAME + 2]; + size_t len = sizeof(real_oid) / sizeof(int); + + if (sysctlnametomib("hw.pagesizes", real_oid, &len) >= 0) { + oid_hw_pagesizes = real_oid[1]; + } + } + + if (oid_hw_availpages && snamep[1] == oid_hw_availpages) { + long lvalue; + size_t len = sizeof(lvalue); + + if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1) { + ret = -1; + } else { + if (oldlen) { +#if TARGET_ABI_BITS != HOST_LONG_BITS + abi_ulong maxpages = maxmem / (abi_ulong)getpagesize(); + if (((unsigned long)maxpages) < lvalue) { + lvalue = maxpages; + } +#endif + (*(abi_ulong *)holdp) = tswapal((abi_ulong)lvalue); + } + holdlen = sizeof(abi_ulong); + ret = 0; + } + goto out; + } + + if (oid_hw_pagesizes && snamep[1] == oid_hw_pagesizes) { + if (oldlen) { + (*(abi_ulong *)holdp) = tswapal((abi_ulong)getpagesize()); + ((abi_ulong *)holdp)[1] = 0; + } + holdlen = sizeof(abi_ulong) * 2; + ret = 0; + goto out; + } + break; + } + } + break; + + default: + break; + } + + ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen)); + if (!ret && (holdp != 0)) { + + if (0 == snamep[0] && + (2 == snamep[1] || 3 == snamep[1] || 4 == snamep[1])) { + switch (snamep[1]) { + case 2: + case 3: + /* Handle the undocumented name2oid special case. */ + sysctl_name2oid(holdp, holdlen); + break; + + case 4: + default: + /* Handle oidfmt */ + sysctl_oidfmt(holdp); + break; + } + } else { + sysctl_oldcvt(holdp, &holdlen, kind); + } + } + +out: + *holdlenp = holdlen; + return ret; +} + /* sysarch() is architecture dependent. */ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2) { diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 0ceecfb6dfa..e24a8cfcfb1 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -252,6 +252,11 @@ bool is_error(abi_long ret); int host_to_target_errno(int err); /* os-sys.c */ +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); +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); /* user access */ From patchwork Fri Feb 10 23:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=sqkUKkWG; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8v03dxrz23qy for ; Sat, 11 Feb 2023 10:23:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcj8-0007BY-BV; Fri, 10 Feb 2023 18:22:46 -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 1pQcj7-0007BG-H3 for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:45 -0500 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQcj5-00053r-TI for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:45 -0500 Received: by mail-il1-x132.google.com with SMTP id v13so1349733iln.4 for ; Fri, 10 Feb 2023 15:22:43 -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=N1kTTQBkTJkPrcjFSf8LeSCgkPCLAZN38tRqgAA8ZV8=; b=sqkUKkWGq0X96B4K/hYfXdl4IIco37tK1ZeIN9Lo13WPVOL2WXJaP6FtOhlnYSffpa GuFEbCeRjGImkohTTM02iLxvspZbrNRP2KnXZzkX8RpLidUV1uuKJI3A7Xd90DHXqhUn ikQOrHznTLho1WACodrbLMJ456gfY2JnL5dk+FXjGYFVxed0Z5+ZDmzBcWtP4EMUNuSb lgxRD48sm10W6ixPjcBKJXC1CX5hz5+H4XRS7Z/Nh+9u84s+iWRjVHEtase9ODm6DBFz u1tueZNGG+sXCiH49aSXvxIe2d7Y/YMIWrkJoPN1O8IUSyO+025CFAeJ1D9MoohOobo1 tIUw== 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=N1kTTQBkTJkPrcjFSf8LeSCgkPCLAZN38tRqgAA8ZV8=; b=VMkoocZ3krSILMM78fXLEgSGV8s7IHiFvITSupYN6jU8uPx2AH6GG7C+OVUQYHodbS wEnKBSWmpL97n3Q2iwJtPknxRoyhC4jda2p7AG9j5/n8hdX1+fvOjN5KHmc0tho/1YiC 8v1p/NkXIHoKaeR6gAA/gEUfWRswUAWkVSq7Nl67s8yHRWxtgjqTsMeVzLxPB1TScqkv /LCbyjx+/gFWhWAnOZBDS5b/pWoZIEyIs3lpOnIYTNLsSM9FZQfmUJCeR7kCpRvVJLxt tEXZZXK8bC6SJ3O96B/6KWC82/P0Bbu49LoquEeljJd/35W1Q3cBvLTn6rJ9hvNiWw15 UklA== X-Gm-Message-State: AO0yUKVbSsSY5D5jHpGu+TTx18Uxx2e4b9MrJPPolATrfCCJTeA6Sqte Drbj47H9TZcdxRJWeEYSwi73hqQWg6IQk8bt X-Google-Smtp-Source: AK7set/U7SRtObqY2RIGNwJgy9OfKCH/13yNoV5Tp+XI7UgFRgPPUJphs/39KWP5WWS1MECXqZEcaw== X-Received: by 2002:a05:6e02:1a6e:b0:313:d8a3:9e6c with SMTP id w14-20020a056e021a6e00b00313d8a39e6cmr16832682ilv.15.1676071361015; Fri, 10 Feb 2023 15:22:41 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:40 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Kyle Evans , Juergen Lock , Stacey Son Subject: [PATCH 7/9] bsd-user: do_freebsd_sysctl helper for sysctl(2) Date: Fri, 10 Feb 2023 16:18:27 -0700 Message-Id: <20230210231829.39476-8-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Warner Losh --- bsd-user/freebsd/os-sys.c | 50 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 +++ 2 files changed, 54 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index a8fb29f36b7..13736936e5f 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -345,6 +345,56 @@ out: return ret; } +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen) +{ + abi_long ret; + void *hnamep, *holdp = NULL, *hnewp = NULL; + size_t holdlen; + abi_ulong oldlen = 0; + int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i; + + if (oldlenp) { + if (get_user_ual(oldlen, oldlenp)) { + return -TARGET_EFAULT; + } + } + hnamep = lock_user(VERIFY_READ, namep, namelen, 1); + if (hnamep == NULL) { + return -TARGET_EFAULT; + } + if (newp) { + hnewp = lock_user(VERIFY_READ, newp, newlen, 1); + if (hnewp == NULL) { + return -TARGET_EFAULT; + } + } + if (oldp) { + holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0); + if (holdp == NULL) { + return -TARGET_EFAULT; + } + } + holdlen = oldlen; + for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++) { + *q++ = tswap32(*p); + } + + ret = do_freebsd_sysctl_oid(env, snamep, namelen, holdp, &holdlen, hnewp, + newlen); + + if (oldlenp) { + put_user_ual(holdlen, oldlenp); + } + unlock_user(hnamep, namep, 0); + unlock_user(holdp, oldp, holdlen); + if (hnewp) { + unlock_user(hnewp, newp, 0); + } + 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 = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ ret = do_freebsd_sysarch(cpu_env, arg1, arg2); break; From patchwork Fri Feb 10 23:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=xFvO5sUy; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8vM4hjDz23hX for ; Sat, 11 Feb 2023 10:24:15 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcjO-0007En-Hn; Fri, 10 Feb 2023 18:23:04 -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 1pQcj7-0007BN-QM for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:45 -0500 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQcj6-000517-7D for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:45 -0500 Received: by mail-il1-x12a.google.com with SMTP id h29so1085144ila.8 for ; Fri, 10 Feb 2023 15:22:43 -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=XfM7MPIhx5UEM8aS55+Appk5Bx6FRMOBwHmKVdc0eBg=; b=xFvO5sUyqKVtlcpFEXXWOfAKCLETsiOOEryAbdytAvBchVdhbcnB3YrYLGMtdzGDVA hk3Q0g96OxKcE9NLzmyKSkTVmHGHgSkzyXPYuk85iQgIsiyB/hP0q8+PhyTBH9srn16X knvDnJeLQT4v+PN4OuBBZJXg91VrUePx6Msca//rGjWOLv/ZcnglEuLy05tBkpBEXDDW 0jZndhWnT2IELd4ndoOEFWd1sCqU6D6AO+jfhn0RQojEFG9bMqKvsPN25iSDILNrUBwf z0HWq9rPLqBWx9mjvUCMnou9yx8uDwjIAgLUMeHBK7TgdDmVqGBVnkELnttUnlhFLlny WhvA== 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=XfM7MPIhx5UEM8aS55+Appk5Bx6FRMOBwHmKVdc0eBg=; b=Yk28DiQNPCEe70X1Lnpw9rAtqbBTcoZI02DnfvxnfEVvB+H6eF1KG58Sgxq3YPkJuQ XiZswsucVpWKt4ihcZNMpuq/MKeFP4cJC3YMiid2YDfBDc/4LS4QOSVtzpf+6dzwof+q vQPcsaTAzy8jhHeMkmV1eYSXVFlMJjzu0hqN6Ca9ZCdif6+zEh7zHbZOufFJvnQzKyLy +T1XsUkfUZVbFnMTryYgnr8l/eHE/sNPC8QquVq17iku1rw7saTxL/ZIW/vUJwX/B+sI YID6p4wM4trdAQGKeiFKG7OBHRITIB0j8EjCsoITDEA65RpPVzbRskuObhze0LL26rZ3 tcLQ== X-Gm-Message-State: AO0yUKWPUg5ofxrdnY6SIHF5ZOehvijk9s3b5a0hvE07QscAqZD8Pqfs rEOdH4iEuGXlkkeTygzVZelU/JHoh0NYLmBE X-Google-Smtp-Source: AK7set/5Og+q6EyFSso5lThoAEZTztjJHRjzaOykDFUAlDXoOKglM52/Ptzml3rfX/iinq4XTUVqkA== X-Received: by 2002:a05:6e02:1aac:b0:313:fd3c:6439 with SMTP id l12-20020a056e021aac00b00313fd3c6439mr10204478ilv.23.1676071361910; Fri, 10 Feb 2023 15:22:41 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:41 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Kyle Evans Subject: [PATCH 8/9] bsd-user: implement sysctlbyname(2) Date: Fri, 10 Feb 2023 16:18:28 -0700 Message-Id: <20230210231829.39476-9-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12a; envelope-from=imp@bsdimp.com; helo=mail-il1-x12a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Warner Losh --- bsd-user/freebsd/os-sys.c | 58 +++++++++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 4 +++ 2 files changed, 62 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 13736936e5f..62c729dfe47 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -345,6 +345,64 @@ out: return ret; } +/* + * This syscall was created to make sysctlbyname(3) more efficient. + * Unfortunately, because we have to fake some sysctls, we can't do that. + */ +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; + void *holdp = NULL, *hnewp = NULL; + char *snamep; + int oid[CTL_MAXNAME + 2]; + size_t holdlen, oidplen; + abi_ulong oldlen = 0; + + if (oldlenp) { + if (get_user_ual(oldlen, oldlenp)) { + return -TARGET_EFAULT; + } + } + snamep = lock_user_string(namep); + if (snamep == NULL) { + return -TARGET_EFAULT; + } + if (newp) { + hnewp = lock_user(VERIFY_READ, newp, newlen, 1); + if (hnewp == NULL) { + return -TARGET_EFAULT; + } + } + if (oldp) { + holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0); + if (holdp == NULL) { + return -TARGET_EFAULT; + } + } + holdlen = oldlen; + + oidplen = sizeof(oid) / sizeof(int); + if (sysctlnametomib(snamep, oid, &oidplen) != 0) { + return -TARGET_EINVAL; + } + + ret = do_freebsd_sysctl_oid(env, oid, oidplen, holdp, &holdlen, hnewp, + newlen); + + if (oldlenp) { + put_user_ual(holdlen, oldlenp); + } + unlock_user(snamep, namep, 0); + unlock_user(holdp, oldp, holdlen); + if (hnewp) { + unlock_user(hnewp, newp, 0); + } + + return ret; +} + abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen) { 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 = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); break; + case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ + ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); + break; + case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ ret = do_freebsd_sysarch(cpu_env, arg1, arg2); break; From patchwork Fri Feb 10 23:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1740748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=eywvpvJU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PD8tr3zCMz23qy for ; Sat, 11 Feb 2023 10:23:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQcjQ-0007FK-QE; Fri, 10 Feb 2023 18:23:04 -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 1pQcj8-0007Ba-Hx for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:46 -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 1pQcj6-000547-9P for qemu-devel@nongnu.org; Fri, 10 Feb 2023 18:22:46 -0500 Received: by mail-io1-xd35.google.com with SMTP id y2so2554836iot.4 for ; Fri, 10 Feb 2023 15:22:43 -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=bp7wIC67rxl3rARTv1dR7WnW/q65KWMxrGAohWha+/s=; b=eywvpvJUVRMC2ZVzCoD55ukwq7RamjI1Z9T85TM5kIld87GaHFGnCOdHQylOnSm4l0 vExNoRSUDu83YwG6yeW3whci8CUrr0MkVTuzf12yVsRfYKK0YRvpfqfJcQdZ63wAencL 4xRi5FT63+OCAS9zSEGiTab4ZUbLkb7Fr5AbWxM/FLmPvAFHIGDuhzfq7ozE4rYja6Ay 6nWaN64dlfWDFLw9IUZjro3FIcjX7AyhnqLL7AXU5aY4kJ8zXFzPs0bgRVqMvGTZOfzg Bg3bg2zdscTlWrDJG8jEnuhSPyV4H/Kjo+lCid+1ZdXyT7et10Peq2sI7iqx3FhfIEPh uBiA== 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=bp7wIC67rxl3rARTv1dR7WnW/q65KWMxrGAohWha+/s=; b=dTNpoAjCoRwJVSuQU0IBI+ZFZq8AK+DxOhS0KkD4wGnq9NHq+cnoQXETEfUZ4wZfGZ VcUwt/AhPuc2awLCAwyqldcmDTUVv1b0zsNj9Ufo72KqZ3AOweIV1t6KpGqkvcBh4kq/ xKnqi/CFAwZjxPb54etWOY/iLIMADHWTS+2FzAqR/vBZW5VRRpNVZTXUXBPECNCeqQS6 a6rtPchmZyl9VBVOg2vy7hRdGjjhcREfdYKsrqJAeKhZpy2FHnSPJ9CNBsFv5/pwGpEr D/0u4Y4QvWaLVrJJp6vjwOFzBXLZ0HpLFbD6KJDtKs4K39CrK//MF3cKFp513KRG3Yd+ slCA== X-Gm-Message-State: AO0yUKV9nhGWPR92Sc8i+fZtVjp5HsBZJVyFpnxaBC+rwDiioAlvVmxe OU9wjpdT7MOZ08T0hvmLUqhx19675xnb75No X-Google-Smtp-Source: AK7set9IfbUH1tT3MbBpCWd3wzcKW0UL2x1P56lEWiBXyavfrObC6RvwsP1GUIe2MveUCI0eDrujTQ== X-Received: by 2002:a6b:db14:0:b0:722:5927:c9c0 with SMTP id t20-20020a6bdb14000000b007225927c9c0mr13317983ioc.4.1676071362740; Fri, 10 Feb 2023 15:22:42 -0800 (PST) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id k18-20020a02c772000000b003a9418e89acsm1850995jao.23.2023.02.10.15.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 15:22:42 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Cc: Thomas Huth , Kyle Evans , f4bug@amsat.org, Warner Losh , richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini Subject: [PATCH 9/9] bsd-user: Add -strict Date: Fri, 10 Feb 2023 16:18:29 -0700 Message-Id: <20230210231829.39476-10-imp@bsdimp.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210231829.39476-1-imp@bsdimp.com> References: <20230210231829.39476-1-imp@bsdimp.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Most of the time, it's useful to make our best effort, but sometimes we want to know right away when we don't implement something. First place we use it is for unknown syscalls. Signed-off-by: Warner Losh --- bsd-user/freebsd/os-syscall.c | 4 ++++ bsd-user/main.c | 5 ++++- bsd-user/qemu.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index 179a20c304b..e2b26ecb8dd 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -508,6 +508,10 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); + if (bsd_user_strict) { + printf("Unimplemented system call %d\n", num); + abort(); + } ret = -TARGET_ENOSYS; break; } diff --git a/bsd-user/main.c b/bsd-user/main.c index 41290e16f98..ba0ad86ad28 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -91,9 +91,10 @@ unsigned long reserved_va = MAX_RESERVED_VA; unsigned long reserved_va; #endif -static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; +const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ +bool bsd_user_strict = false; /* Abort for unimplemned things */ unsigned long target_maxtsiz = TARGET_MAXTSIZ; /* max text size */ unsigned long target_dfldsiz = TARGET_DFLDSIZ; /* initial data size limit */ @@ -396,6 +397,8 @@ int main(int argc, char **argv) trace_opt_parse(optarg); } else if (!strcmp(r, "0")) { argv0 = argv[optind++]; + } else if (!strcmp(r, "strict")) { + bsd_user_strict = true; } else { usage(); } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index e24a8cfcfb1..22bd5a3df42 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -113,6 +113,7 @@ typedef struct TaskState { void stop_all_tasks(void); extern const char *qemu_uname_release; +extern bool bsd_user_strict; /* * TARGET_ARG_MAX defines the number of bytes allocated for arguments