From nobody Fri May 17 02:03: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=1681233053; cv=none; d=zohomail.com; s=zohoarc; b=K9+aHurT3yNKYLoPP0cdR60H1hNxAyYRDwl77jTT8Ruj81eGku7x50zl8Llq8H2nhs2uhpB5jsvT3VUUW6THdFwD8o08cNsQv7/TTFvxcUoxZDq61avJYWp1vIAwfdbB3xaHNbbMPWObd5LU8N4r8BdSrEXxO9DD2Pvt+RkEZ3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233053; 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=ZT5fLQSNvwvtBf2Szoe2FViWNomI0FmkPHfn6pZOtis=; b=juPEJjJGQ3gSbkOObH5ffx8lZAaphNQ3DhKAMKWFH8sV0IDTzRS9LX9UsEjJcc4seHSRrFUzSIJWAM3/kuObs8b+QsguXU8vLWT6Vg3uzj2jjI6Lyx8MvM7QMKAxAIMvZTh1DgyxmZPmZeXKB98XEDtgZUwdxREvaXhgcyXnBJs= 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 1681233053222936.6330228215853; Tue, 11 Apr 2023 10:10:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHVr-0003q0-Ay; Tue, 11 Apr 2023 13:10:35 -0400 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 1pmHVj-0003oo-H6 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:27 -0400 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 1pmHVh-00066J-7o for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:27 -0400 Received: by mail-io1-xd32.google.com with SMTP id e22so172715ioc.13 for ; Tue, 11 Apr 2023 10:10:24 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233023; 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=ZT5fLQSNvwvtBf2Szoe2FViWNomI0FmkPHfn6pZOtis=; b=AEmtNKKrq0fcvck5DLkfczuUrLmnkbeU0w7ZC1Yr3p3wpbL5kk+I4Y4ow4E30V86ob /h2leh2vcvCTT4hQhUeFyvSOdo2NugLUTseBiQhwnMBcJZmFEeuTxzTRAN+R+Pcd/nkF PQMTsMYa9k4OcX6f9eM8ci2nAVnCtAgno1wLHuECnjUyjp07SzP+FfwpgfpD4x/qHGoH m9lZJxENA+114wRK1ymILP2YGZgGalG0wbHOq2KxPt1UvGupO82IB1JRYoi+cwG/reRe zCA1A++XbNruLFhsXrSBgOSGpzGIoHyIMjy23k0wzUrVZoyTQ40b1TjV4lRuo1uc7Dy+ 0z4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233023; 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=ZT5fLQSNvwvtBf2Szoe2FViWNomI0FmkPHfn6pZOtis=; b=DUEMws+wdb0mSDPEcBgt88q/mdRH2TstuxD8eAZxG1paq1EEu2yGoPe2pqsj3D+NlL npwB2LaZPIxHzjIsRIJUjxtzfWYKv0iGn3M8qimBD7ioIOXUYcdOSH2JiZIJNavxhA3k G6xPoQAGx8bgSX0r7ZgwwUXru72k/ky7mPT6tWjIvb/lxh1JZiwYDVumEVC1WuVXfZTl h9SVPmCREkdX3AgUd8WtrJi0n+z+Aa26ztj+Gsrf4Q3E2HuhCQ43nnV7xQwWljU8SuXa CFLgVw1K6mY/oRP4ob1fc4bQe+58384E7Jc2A+yHIbLMYWUw7ro5HJHEl4KiCOAzUlF+ hy3g== X-Gm-Message-State: AAQBX9dujkbt/7do/oW7kGlE2rsYLPiV/IDZFgAySDbsZMEi0p5FF8QU v4HVCFVpE6EzQA7a47JtIeTqwyipR3Tctzp3fWE= X-Google-Smtp-Source: AKy350Y9605LtOxSyiorYWDkk03/dhtILlruYIF9mTmlPIC/F/VdG6Jvd4p6NdknOZBam6jvAR/qFg== X-Received: by 2002:a6b:f402:0:b0:74e:6f06:d5f5 with SMTP id i2-20020a6bf402000000b0074e6f06d5f5mr1940646iog.8.1681233023042; Tue, 11 Apr 2023 10:10:23 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 01/20] bsd-user: Make print_* public Date: Tue, 11 Apr 2023 11:09:36 -0600 Message-Id: <20230411170955.17358-2-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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: 1681233054594100007 Content-Type: text/plain; charset="utf-8" Make these functions public. Due to coming restructuring, we'll need to call these from *bsd/os-syscall.c. Add declarations to qemu.h. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 20 ++++++++++++++++++++ bsd-user/strace.c | 29 +++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 41d84e0b81b..22e16816a9e 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -211,6 +211,26 @@ print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6); void print_openbsd_syscall_ret(int num, abi_long ret); +void print_execve(const struct syscallname *name, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6); +void print_ioctl(const struct syscallname *name, + abi_long arg1, abi_long arg2, abi_long arg3, + abi_long arg4, abi_long arg5, abi_long arg6); +void print_sysarch(const struct syscallname *name, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6); +void print_sysctl(const struct syscallname *name, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6); +void print_syscall(int num, const struct syscallname *scnames, + unsigned int nscnames, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5, + abi_long arg6); +void print_syscall_ret(int num, abi_long ret, + const struct syscallname *scnames, + unsigned int nscnames); +void print_syscall_ret_addr(const struct syscallname *name, abi_long ret); /** * print_taken_signal: * @target_signum: target signal being taken diff --git a/bsd-user/strace.c b/bsd-user/strace.c index 96499751eb0..e45909b8688 100644 --- a/bsd-user/strace.c +++ b/bsd-user/strace.c @@ -49,7 +49,7 @@ print_raw_param(const char *fmt, abi_long param, int last) gemu_log(format, param); } =20 -static void print_sysctl(const struct syscallname *name, abi_long arg1, +void print_sysctl(const struct syscallname *name, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) { @@ -71,9 +71,8 @@ static void print_sysctl(const struct syscallname *name, = abi_long arg1, (uint32_t)arg2, arg3, arg4, arg5, arg6); } =20 -static void print_execve(const struct syscallname *name, abi_long arg1, - abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, - abi_long arg6) +void print_execve(const struct syscallname *name, abi_long arg1, abi_long = arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long ar= g6) { abi_ulong arg_ptr_addr; char *s; @@ -105,9 +104,8 @@ static void print_execve(const struct syscallname *name= , abi_long arg1, gemu_log("NULL})"); } =20 -static void print_ioctl(const struct syscallname *name, - abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, - abi_long arg5, abi_long arg6) +void print_ioctl(const struct syscallname *name, abi_long arg1, abi_long a= rg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg= 6) { /* Decode the ioctl request */ gemu_log("%s(%d, 0x%0lx { IO%s%s GRP:0x%x('%c') CMD:%d LEN:%d }, 0x" @@ -124,9 +122,8 @@ static void print_ioctl(const struct syscallname *name, arg3); } =20 -static void print_sysarch(const struct syscallname *name, abi_long arg1, - abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, - abi_long arg6) +void print_sysarch(const struct syscallname *name, abi_long arg1, abi_long= arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) { /* This is os dependent. */ do_os_print_sysarch(name, arg1, arg2, arg3, arg4, arg5, arg6); @@ -136,7 +133,7 @@ static void print_sysarch(const struct syscallname *nam= e, abi_long arg1, * Variants for the return value output function */ =20 -static void print_syscall_ret_addr(const struct syscallname *name, abi_lon= g ret) +void print_syscall_ret_addr(const struct syscallname *name, abi_long ret) { if (ret =3D=3D -1) { gemu_log(" =3D -1 errno=3D%d (%s)\n", errno, strerror(errno)); @@ -159,9 +156,9 @@ static const struct syscallname openbsd_scnames[] =3D { #include "openbsd/strace.list" }; =20 -static void print_syscall(int num, const struct syscallname *scnames, - unsigned int nscnames, abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6) +void print_syscall(int num, const struct syscallname *scnames, + unsigned int nscnames, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) { unsigned int i; const char *format=3D"%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," @@ -190,8 +187,8 @@ static void print_syscall(int num, const struct syscall= name *scnames, gemu_log("Unknown syscall %d\n", num); } =20 -static void print_syscall_ret(int num, abi_long ret, - const struct syscallname *scnames, unsigned int nscnames) +void print_syscall_ret(int num, abi_long ret, const struct syscallname *sc= names, + unsigned int nscnames) { unsigned int i; =20 --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233052; cv=none; d=zohomail.com; s=zohoarc; b=dNhPsuKmDEv3un0Fww4XuicYTgly0MLtU9pvUd+Ab22jD7+6xGLfyIYVcppqo27743cNKFoiWB6dkioOL+jg1m4LFaG2n1HN8gWE2MVo5j8NOlaAPL+UOtGyuTRe9yyXp5+/pxt+DTvDzl8A5sKkBLtaVuDx2NUx+yJ2uRmaaw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233052; 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=WQaAp59x+Mdyu1iJVILNhFfK7zDGSlhnzQzZybq8o+A=; b=S148Ei+u40RJhQxGCkeAWJph4IEIkd7dFadMMwDQKGU0BAFFaOArR1gwqrepN3FM4WoxNbuJmvryXkmyjs9GFxomto1YYiXD8TfPWz9cuDAR+mYcOKH7zuN6p49+F7r+QJIBUhHb9PfgNKok7mSOfmV97dk0Q7vrY5jeDIeUy4s= 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 1681233052956511.071865021289; Tue, 11 Apr 2023 10:10:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHVp-0003pt-VE; Tue, 11 Apr 2023 13:10:34 -0400 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 1pmHVm-0003pE-No for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:30 -0400 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 1pmHVi-00066u-5C for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:29 -0400 Received: by mail-io1-xd31.google.com with SMTP id k13so14469590iov.10 for ; Tue, 11 Apr 2023 10:10:25 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233024; 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=WQaAp59x+Mdyu1iJVILNhFfK7zDGSlhnzQzZybq8o+A=; b=Ry5PmTX2P2HQx8DqAxKB4PnQ1wdtbgDPY+UokNN+QRtJHt4VAWn5qP9KD+aMJFa78B nUvOYLnN9hfV+lLS72dOhR8vYtWChNovgX7SB8vPVGcQTvQTXLpaKT6rCrpec0d+K7Ry /OY1ljhDr4ry04344PojoNe+jHlyNZF6WXEQ2MuPPYU92gcRW5qrU/kNkbsOz1i/sKOP pdVQbHJFw6RyMSk05JGZ0QNbWLnfLAXmETX9RUbR3fJP3f0Inz5V/51JVDKTJY33Ra3n 8WdRCJtoc8PzekCikjHTDIkyp0YhtsJEp6sTKeQynalqzD+z/rQ+y0ZuywfchIYnucGj 4zGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233024; 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=WQaAp59x+Mdyu1iJVILNhFfK7zDGSlhnzQzZybq8o+A=; b=ZN+cbWhxV0BFEJiiGwQXX/QS/H2deNraJm4SQf6KkXXX98WGEkaGAwaCLMdLjDs2k/ UYn4fWQ2UIb62kLXiM4/fFizXKToAJUn+lA1bQLKk38HKVDSXLBgWHNYWrh0kqIob30F W76rHxuT1seV2gCmTy9lcxtMxrtxpLzegqNbnWEYQl9KH4x56Rz+gO1koXGv5hbGqdVP xwtaWUruUB9qgEyeuqOXeMQ2b0JRSoqdqBNah4XGDLYbIaYKaDZjzrSSjl09iGCwr6zw tU3F5sTRsWGafXGoz99T7+7suwVS90vNNvH11BiQ4RIFkazXM0DRm94TSNQyDwcI8wcI NOUQ== X-Gm-Message-State: AAQBX9eif8NqsH7tTHAN8GHeXu2+2UbAQKfDGdqgw8m3QfDfUyA6l/HG T+xeXh6vGTbw2p+Q/uPB7YZc/SSpACrGXXRAybk= X-Google-Smtp-Source: AKy350bnJnvwB+blHXQcJTYPI2zyiZWBWqpn570D3VX77foOunJgsd0Gg3CyY3KqvsoOuJvbMIA60Q== X-Received: by 2002:a5e:990a:0:b0:74c:822c:a6ac with SMTP id t10-20020a5e990a000000b0074c822ca6acmr10169096ioj.15.1681233024228; Tue, 11 Apr 2023 10:10:24 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 02/20] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD. Date: Tue, 11 Apr 2023 11:09:37 -0600 Message-Id: <20230411170955.17358-3-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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: 1681233054533100002 Content-Type: text/plain; charset="utf-8" MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Define them to be 0 if they aren't defined, and rely on the compiler to optimize away sections not relevant. Added only to the top of mmap.c since that's the only place we need this. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index d6c5a344c9b..2d91e8e8826 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -20,6 +20,20 @@ =20 #include "qemu.h" =20 +/* + * Not all the BSDs have all the MAP flags, so define some of them to 0 he= re and + * rely on the compiler optimizing always false conditions away. + */ +#ifndef MAP_GUARD +#define MAP_GUARD 0 +#endif +#ifndef MAP_EXCL +#define MAP_EXCL 0 +#endif +#ifndef MAP_NOCORE +#define MAP_NOCORE 0 +#endif + static pthread_mutex_t mmap_mutex =3D PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; =20 --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233150; cv=none; d=zohomail.com; s=zohoarc; b=AcEwbm68qcOhq78iNoqAIkqETby/PxuizkMOpBQvr/DjaxD0b+IBYbeyYlZIfbPyAQhmRKPlGL8P29XUciVxCUWokBlrt8kTp4os8pt0/Kbp/sFuSn7Hadbxwcq5m0T+/7zTi4OxaxKG6zHhYKh7jlWA/2KlNmXrbdzPHK9zfb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233150; 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=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=ExOcykWrwXt4mW8iS1yQK7e+XMb5l6+YIRi5uiKMMfZT+a1n/pwMHAYva6tm9Yo1uubgunawgiNDZHaJOKkr768uDwA6u+0zVkz7QbwOkPyD6A+Zwmkxue8r5T2LIIhZJnp88wiKxBgJW2RgfkEXD7CTm0XWyoBdR/Rjjg/RvAM= 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 1681233150113643.4369596318433; Tue, 11 Apr 2023 10:12:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW2-0003sC-AW; Tue, 11 Apr 2023 13:10:46 -0400 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 1pmHVm-0003pD-OH for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:30 -0400 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmHVj-00067C-9K for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:29 -0400 Received: by mail-il1-x12f.google.com with SMTP id o12so22672328ilh.13 for ; Tue, 11 Apr 2023 10:10:26 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233025; 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=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=duLxO/6mnxFuXt9QUHXrkX09gWmPaPOx6dGKH4qkNG2kKLHOetaTkGsRNSItc32n56 DG0TWAvCvlNY4Esjt5rZf+/XGzJ+FUyIQ0rqhM2wNPqIhpft8DY3W0l8UhYG/+77xfpL 4/3a/gOGM7xlb1ZEH/XZfQa55qfVadhyc7vv70+bw0feS3feHqWebtrGDusZ4GMdIu4d ybe+mTSSyAU2y9WAbJH9/YiJurYpTxHiSda8jmoyc8AYgXflKK8gTYBZWItzZZyZDgpx LAk+cLO3Z0rBylCXABuHBF33ThZnVb98/ebJfjgNksC+et8V+QxY6cUUzfZ9XCFs0+K5 e2DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233025; 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=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=Xz3eMUtLCt0RbV6Dg6eydjsywHl0r1b+bogthN7iwSyMKL2G46gRdwovo6Yhsgl9GM ZktEOlsEo03CZS92wa43UK9x1221d/rlkzNOePiuXhSVdhTeJnLjltcD8DAgGMCoqJca jHZuPYBBo27IHuUI9aT4+31r3eaBhhHTYvwNF73pFOoyQ115xl9ULwhZn6n+nPKPbUs6 mphKNpqjlZXMse4vaANDD056L/g+bbQZ98SYmweC/deQSi5t6m2Iz67SjVaGAmVLRIqy UCjjzAuSR6stGgh4Ru2XuUPqFe1PJnkhdcQk0u7rCOqWlDoWO1QcmSvW1eUEtzXZUUyN z/CQ== X-Gm-Message-State: AAQBX9c7Rjpowk5GtHTFG6sC6wnUfDatGjg6X8gP0ROLXhfdr+Q6xchZ DNx39Z3eOFQiSLCfteWHlDMutTiqBhRiD5aThfo= X-Google-Smtp-Source: AKy350axTqMQ0K2G5U6GOnJsiRR8u+BCFzoGKavw6Qhmg41enebzfmOtRFucGaNbfkzkfH8nJ7ebCQ== X-Received: by 2002:a92:dc41:0:b0:326:2d3a:c770 with SMTP id x1-20020a92dc41000000b003262d3ac770mr9841257ilq.26.1681233025193; Tue, 11 Apr 2023 10:10:25 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 03/20] bsd-user: Cleanup style. Date: Tue, 11 Apr 2023 11:09:38 -0600 Message-Id: <20230411170955.17358-4-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1681233151096100001 Content-Type: text/plain; charset="utf-8" The only diffs between bsd-user fork and qemu upstream is style. Make mmap.c pass checkpatch.pl. Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/mmap.c | 91 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 2d91e8e8826..d0ade1b52f3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -59,17 +59,19 @@ bool have_mmap_lock(void) /* Grab lock to make sure things are in a consistent state after fork(). = */ void mmap_fork_start(void) { - if (mmap_lock_count) + if (mmap_lock_count) { abort(); + } pthread_mutex_lock(&mmap_mutex); } =20 void mmap_fork_end(int child) { - if (child) + if (child) { pthread_mutex_init(&mmap_mutex, NULL); - else + } else { pthread_mutex_unlock(&mmap_mutex); + } } =20 /* NOTE: all the constants are the HOST ones, but addresses are target. */ @@ -83,15 +85,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int= prot) prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); - if ((start & ~TARGET_PAGE_MASK) !=3D 0) + if ((start & ~TARGET_PAGE_MASK) !=3D 0) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); end =3D start + len; - if (end < start) + if (end < start) { return -EINVAL; + } prot &=3D PROT_READ | PROT_WRITE | PROT_EXEC; - if (len =3D=3D 0) + if (len =3D=3D 0) { return 0; + } =20 mmap_lock(); host_start =3D start & qemu_host_page_mask; @@ -110,8 +115,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int= prot) } ret =3D mprotect(g2h_untagged(host_start), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret !=3D 0) + if (ret !=3D 0) { goto error; + } host_start +=3D qemu_host_page_size; } if (end < host_end) { @@ -121,16 +127,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, i= nt prot) } ret =3D mprotect(g2h_untagged(host_end - qemu_host_page_size), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret !=3D 0) + if (ret !=3D 0) { goto error; + } host_end -=3D qemu_host_page_size; } =20 /* handle the pages in the middle */ if (host_start < host_end) { ret =3D mprotect(g2h_untagged(host_start), host_end - host_start, = prot); - if (ret !=3D 0) + if (ret !=3D 0) { goto error; + } } page_set_flags(start, start + len, prot | PAGE_VALID); mmap_unlock(); @@ -175,31 +183,37 @@ static int mmap_frag(abi_ulong real_start, /* get the protection of the target pages outside the mapping */ prot1 =3D 0; for (addr =3D real_start; addr < real_end; addr++) { - if (addr < start || addr >=3D end) + if (addr < start || addr >=3D end) { prot1 |=3D page_get_flags(addr); + } } =20 if (prot1 =3D=3D 0) { /* no page was there, so we allocate one. See also above. */ void *p =3D mmap(host_start, qemu_host_page_size, prot, flags | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); - if (p =3D=3D MAP_FAILED) + if (p =3D=3D MAP_FAILED) { return -1; + } prot1 =3D prot; } prot1 &=3D PAGE_BITS; =20 prot_new =3D prot | prot1; if (fd !=3D -1) { - /* msync() won't work here, so we return an error if write is - possible while it is a shared mapping */ + /* + * msync() won't work here, so we return an error if write is + * possible while it is a shared mapping + */ if ((flags & TARGET_BSD_MAP_FLAGMASK) =3D=3D MAP_SHARED && - (prot & PROT_WRITE)) + (prot & PROT_WRITE)) { return -1; + } =20 /* adjust protection to be able to read */ - if (!(prot1 & PROT_WRITE)) + if (!(prot1 & PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); + } =20 /* read the corresponding file data */ if (pread(fd, g2h_untagged(start), end - start, offset) =3D=3D -1)= { @@ -207,8 +221,9 @@ static int mmap_frag(abi_ulong real_start, } =20 /* put final protection */ - if (prot_new !=3D (prot1 | PROT_WRITE)) + if (prot_new !=3D (prot1 | PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot_new); + } } else { if (prot_new !=3D prot1) { mprotect(host_start, qemu_host_page_size, prot_new); @@ -560,8 +575,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, */ p =3D mmap(g2h_untagged(start), host_len, prot, flags | MAP_FIXED | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); - if (p =3D=3D MAP_FAILED) + if (p =3D=3D MAP_FAILED) { goto fail; + } /* update start so that it points to the file position at 'offset'= */ host_start =3D (unsigned long)p; if (fd !=3D -1) { @@ -610,8 +626,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, retaddr =3D target_mmap(start, len, prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); - if (retaddr =3D=3D -1) + if (retaddr =3D=3D -1) { goto fail; + } if (pread(fd, g2h_untagged(start), len, offset) =3D=3D -1) { goto fail; } @@ -634,14 +651,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, /* one single host page */ ret =3D mmap_frag(real_start, start, end, prot, flags, fd, offset); - if (ret =3D=3D -1) + if (ret =3D=3D -1) { goto fail; + } goto the_end1; } ret =3D mmap_frag(real_start, start, real_start + qemu_host_pa= ge_size, prot, flags, fd, offset); - if (ret =3D=3D -1) + if (ret =3D=3D -1) { goto fail; + } real_start +=3D qemu_host_page_size; } /* handle the end of the mapping */ @@ -650,8 +669,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, real_end - qemu_host_page_size, end, prot, flags, fd, offset + real_end - qemu_host_page_size - star= t); - if (ret =3D=3D -1) + if (ret =3D=3D -1) { goto fail; + } real_end -=3D qemu_host_page_size; } =20 @@ -659,14 +679,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, if (real_start < real_end) { void *p; unsigned long offset1; - if (flags & MAP_ANON) + if (flags & MAP_ANON) { offset1 =3D 0; - else + } else { offset1 =3D offset + real_start - start; + } p =3D mmap(g2h_untagged(real_start), real_end - real_start, prot, flags, fd, offset1); - if (p =3D=3D MAP_FAILED) + if (p =3D=3D MAP_FAILED) { goto fail; + } } } the_end1: @@ -736,11 +758,13 @@ int target_munmap(abi_ulong start, abi_ulong len) TARGET_ABI_FMT_lx "\n", start, len); #endif - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); - if (len =3D=3D 0) + if (len =3D=3D 0) { return -EINVAL; + } mmap_lock(); end =3D start + len; real_start =3D start & qemu_host_page_mask; @@ -758,16 +782,18 @@ int target_munmap(abi_ulong start, abi_ulong len) } end =3D real_end; } - if (prot !=3D 0) + if (prot !=3D 0) { real_start +=3D qemu_host_page_size; + } } if (end < real_end) { prot =3D 0; for (addr =3D end; addr < real_end; addr +=3D TARGET_PAGE_SIZE) { prot |=3D page_get_flags(addr); } - if (prot !=3D 0) + if (prot !=3D 0) { real_end -=3D qemu_host_page_size; + } } =20 ret =3D 0; @@ -791,14 +817,17 @@ int target_msync(abi_ulong start, abi_ulong len, int = flags) { abi_ulong end; =20 - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); end =3D start + len; - if (end < start) + if (end < start) { return -EINVAL; - if (end =3D=3D start) + } + if (end =3D=3D start) { return 0; + } =20 start &=3D qemu_host_page_mask; return msync(g2h_untagged(start), end - start, flags); --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233121; cv=none; d=zohomail.com; s=zohoarc; b=U0Cylh+ryGTHD2lcmQCYD2oRxH/ljb8Srnno11Xp9oGjFVvSkV6/6Bte4ESpVrUuMtWUP/DAy+PZQFUP3mawiyqkG58abSPmBWqJFzxeOxkFz1iR8Scqm34n5dyc9waKtJn0nybH3MtFytqBvMN5pyTfnt1gq+fxnBYjureLXYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233121; 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=YqE0cOIeNp+kyq+c5+Esj5WEVDxO+dIWwYCwGSiBV/o=; b=G/DcYOmfb2QCbKsZU15h8HnaZzGrOnp7SHuZctcP9eNY8mIO54OAGejsIDPD8iQ7Thy7qWkEh+fgnGG0gkWHPqwy6zgFvgNekuDRo6ZH6JWkfMAAX7sELjtxxC3s9nNLX7KTUPIpPxuCjKOQtVgIy1yi4xqsBIA2hZvi1tW3Z8U= 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 1681233121509495.69179069300947; Tue, 11 Apr 2023 10:12:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHVx-0003rR-Ic; Tue, 11 Apr 2023 13:10:41 -0400 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 1pmHVo-0003pr-TI for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:33 -0400 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmHVm-00067j-F2 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:32 -0400 Received: by mail-il1-x12e.google.com with SMTP id q5so22313657ilg.12 for ; Tue, 11 Apr 2023 10:10:27 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233026; 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=YqE0cOIeNp+kyq+c5+Esj5WEVDxO+dIWwYCwGSiBV/o=; b=S5iUUKPly582HzqulVWJXs0jYRWCr4wQ/us0TfsGI9qXg7wl4DhO1ASFcJSEGXW6dt 9j1FR+ema1qjXMF44pVMdaybk4Z9jjx4OZ5347wMaILFtCCToVIP0r0PbN/A9Dz9y4ms bO8ADEO8bCmN035wNhymjdOSwhU0vJGB/kZhuMfoW69+xxYeDmen8W1pPA/soyW+SQ2N Hpn0/tLjWA9yb+BQN4+WQjniC6dX5+f3/4hMQOnul/h2/Duuk1xcy3h5AC1utBkhBMs/ CjOs4ABu8TEwtEWV6/zG8QCRohT5Q/RLrFAPcZXI/4cH8p1lrdjBWFAnXiFrs9VNP38k ie0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233026; 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=YqE0cOIeNp+kyq+c5+Esj5WEVDxO+dIWwYCwGSiBV/o=; b=4srSMLouahyoUI5unu9j8SXTiSN90LJdztyJ/Haf4qNwsKNFSI7fjrga/yhxTuDjCe 197OG+OdPH4XnKtNSMM/wXf9dzuYUrtAkpPRk3fkjQH+xjJB6XdtCQK5ibKwT0rivZKR zOfdSqrDM87J2FuUqiPd84uOuyON5nr46Kn895wQDQkM+Q13NUrM7aGzR0THoXrgrDnF dAjs/HG0nNUcbQ/PvjGG6F/ztTQZbdWZHJMujq0Y4jghhkPD2voTwhhbkILKlwYXNcxp H9ey4lqL7WvZWsrbZrA0z8xmlA6hV5evEGyxXEGjUv8n+dA6UmPOYX7ssHcx5OE52/Bl iiWQ== X-Gm-Message-State: AAQBX9d5vPYsMaUr+eDPi9bOKSAlIvPgYnR9r4NuTKVTA8lUYTgESKqB c7fh5cTBu4Zy501ExG6lKmJNgKl5/9s5RcOT3po= X-Google-Smtp-Source: AKy350bHjVd4uSBvfm/xCUUKWG6yx4gQ4/afnRYOgIrXIFgyMRsUmIdu5XQ37r2wIjgNIyChcbSozg== X-Received: by 2002:a92:db42:0:b0:326:2b4e:1f96 with SMTP id w2-20020a92db42000000b003262b4e1f96mr2091784ilq.21.1681233026220; Tue, 11 Apr 2023 10:10:26 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 04/20] bsd-user: Move system FreeBSD call table to freebsd/os-syscall.c Date: Tue, 11 Apr 2023 11:09:39 -0600 Message-Id: <20230411170955.17358-5-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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::12e; envelope-from=imp@bsdimp.com; helo=mail-il1-x12e.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: 1681233122907100003 Content-Type: text/plain; charset="utf-8" Move the system call table, and FreeBSD helper routines out of strace.c. We do not support multiple BSD-types in one binary, so simplify things by moving it. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.c | 19 +++++++++++++++++++ bsd-user/qemu.h | 5 ----- bsd-user/strace.c | 17 ----------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index c8f998ecec1..354a38943e5 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -517,6 +517,25 @@ static abi_long freebsd_syscall(void *cpu_env, int num= , abi_long arg1, return ret; } =20 +static const struct syscallname freebsd_scnames[] =3D { +#include "freebsd/strace.list" +}; + +static void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long a= rg5, + abi_long arg6) +{ + + print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), arg1,= arg2, + arg3, arg4, arg5, arg6); +} + +static void print_freebsd_syscall_ret(int num, abi_long ret) +{ + + print_syscall_ret(num, ret, freebsd_scnames, ARRAY_SIZE(freebsd_scname= s)); +} + /* * do_freebsd_syscall() should always have a single exit point at the end = so * that actions, such as logging of syscall results, can be performed. This diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 22e16816a9e..c5240938da7 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -196,11 +196,6 @@ struct syscallname { void (*result)(const struct syscallname *, abi_long); }; =20 -void -print_freebsd_syscall(int num, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6); -void print_freebsd_syscall_ret(int num, abi_long ret); void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, diff --git a/bsd-user/strace.c b/bsd-user/strace.c index e45909b8688..7d0117fd3cf 100644 --- a/bsd-user/strace.c +++ b/bsd-user/strace.c @@ -146,9 +146,6 @@ void print_syscall_ret_addr(const struct syscallname *n= ame, abi_long ret) * An array of all of the syscalls we know about */ =20 -static const struct syscallname freebsd_scnames[] =3D { -#include "freebsd/strace.list" -}; static const struct syscallname netbsd_scnames[] =3D { #include "netbsd/strace.list" }; @@ -212,20 +209,6 @@ void print_syscall_ret(int num, abi_long ret, const st= ruct syscallname *scnames, /* * The public interface to this module. */ -void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long= arg3, - abi_long arg4, abi_long arg5, abi_long arg6) -{ - - print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), arg1,= arg2, - arg3, arg4, arg5, arg6); -} - -void print_freebsd_syscall_ret(int num, abi_long ret) -{ - - print_syscall_ret(num, ret, freebsd_scnames, ARRAY_SIZE(freebsd_scname= s)); -} - void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long = arg3, abi_long arg4, abi_long arg5, abi_long arg6) { --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233146; cv=none; d=zohomail.com; s=zohoarc; b=Agukm/asTCIL7YWqiBd9j9qwFX9QAhq1X1yAA5UDsVhp05cZxo62UrTtEwY0Ze+13iNXf2uVzyDge7dFCstDjvPj9Vjw4gg1YZrZs4U5VYpQtcl7VG3EsE7VmR6sv/tUnfR8xU4q5wPpZqacQrnIqz4TcM1Ir4fpHR+j0OruwQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233146; 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=tWf8Mdc3sABcKlVmtCGZhLXeGei83PoA0g+BtXKSJpY=; b=eMMbgOZ2OQAonfa2vwXs++TyxSuV0qS0QfajwqlyE+Rwvy927yLcF/N+t5bU34hxQv+0V2PtOXtMsT6FY5nNZECiZNScue+pRSUrAIpW27MrWmIFnYtFa3mbElVCkOPbwcwTVA+a0Ygx2V3E0WNJqWeMypSmyoSd8zEjX8+h6WU= 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 1681233146874622.6404777453027; Tue, 11 Apr 2023 10:12:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW2-0003sH-IO; Tue, 11 Apr 2023 13:10:46 -0400 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 1pmHVo-0003ps-TC for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:33 -0400 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 1pmHVm-00067z-Kr for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:32 -0400 Received: by mail-il1-x133.google.com with SMTP id t5so16356144ilu.5 for ; Tue, 11 Apr 2023 10:10:29 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233027; 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=tWf8Mdc3sABcKlVmtCGZhLXeGei83PoA0g+BtXKSJpY=; b=rrtvlqSRVA6eZFL/+s46HqIfpEiTMs6vbmcTkJTiJhMUVp+y1DKb9E7qfbVPYBzoTh a1eHUMizmLLwSsGdWCtaMyHv8B2lfZZcc6FOGmYQ8hCSi7v350mQuH2DtEeM7LQCfol3 UI8KoBU3noX5fa7HCPdfhTQWCbHBV1vniqqBEW6bBVwEk2KXPa7JgjI9sQ/usOK7RTYh Lgl9CYguq/D4owJulGOV55hOMrliK0CE8JD5AmrsNWAILP87G7pnmClaGVi/FpLV5rg4 KGVIZwszNYySv91MAPWb42DxQc9x79mVf7VZ6DwNwfPylHJ5lbDs+bDZ6TS1vEbufleU naFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233027; 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=tWf8Mdc3sABcKlVmtCGZhLXeGei83PoA0g+BtXKSJpY=; b=xEObS/k/Vh8oKBtjli0SnYvZWevLUsW6J6sVLQj2/W86jmMvpFSCMpU2JLAYxZK4Kn es+Q0Ervbm2YbPdG1utb492EiUHTOPWlHbyGfRyUqw367L8ThDab4BqEfwg97qh/xWRd qkXLFUGyDygI2fYM+5uxZPvsMkppAqpfTHonjjnlHhuVvrl0wCneD7D2MZ/BNirGLLHb k2y6xspjmuBRp1+QfDDbBK2brjF5scglzZKN1sEkHJfII2qbEs9hh0f8EideiX128DOM /9VznQKZVsaV5SW9Uq7oGBO8ycpqlQEFPFpYyRXxjdQ5mJl5oLG0Bs02UCHVlqXfStGV P72w== X-Gm-Message-State: AAQBX9dfWipn+hH9I99EkOzzjAbp00rJaQq95UOEPp/ogsb/KKhTSa8r wLXHDhqjObSblRPeHW+H2bW8By/nmhW7xSWJD2w= X-Google-Smtp-Source: AKy350ZpAsbsLu7BE+T8LpFhxI6lhz786aeHKsLFzXrF/6Aj57nbsG9rlJhIfoq7VDiO1TaT4rCvoA== X-Received: by 2002:a92:b05:0:b0:325:bab7:cb17 with SMTP id b5-20020a920b05000000b00325bab7cb17mr2149088ilf.24.1681233027557; Tue, 11 Apr 2023 10:10:27 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 05/20] bsd-user: Remove NetBSD specific syscall printing Date: Tue, 11 Apr 2023 11:09:40 -0600 Message-Id: <20230411170955.17358-6-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1681233148949100007 Content-Type: text/plain; charset="utf-8" Nothing calls these routines now. In the bsd-user fork, though, they've moved to netbsd/os-syscall.c, but those aren't ready for upstreaming. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 5 ----- bsd-user/strace.c | 17 ----------------- 2 files changed, 22 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index c5240938da7..cee02d2a0ea 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -196,11 +196,6 @@ struct syscallname { void (*result)(const struct syscallname *, abi_long); }; =20 -void -print_netbsd_syscall(int num, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6); -void print_netbsd_syscall_ret(int num, abi_long ret); void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, diff --git a/bsd-user/strace.c b/bsd-user/strace.c index 7d0117fd3cf..8e76caa3c3f 100644 --- a/bsd-user/strace.c +++ b/bsd-user/strace.c @@ -146,9 +146,6 @@ void print_syscall_ret_addr(const struct syscallname *n= ame, abi_long ret) * An array of all of the syscalls we know about */ =20 -static const struct syscallname netbsd_scnames[] =3D { -#include "netbsd/strace.list" -}; static const struct syscallname openbsd_scnames[] =3D { #include "openbsd/strace.list" }; @@ -209,20 +206,6 @@ void print_syscall_ret(int num, abi_long ret, const st= ruct syscallname *scnames, /* * The public interface to this module. */ -void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long = arg3, - abi_long arg4, abi_long arg5, abi_long arg6) -{ - - print_syscall(num, netbsd_scnames, ARRAY_SIZE(netbsd_scnames), - arg1, arg2, arg3, arg4, arg5, arg6); -} - -void print_netbsd_syscall_ret(int num, abi_long ret) -{ - - print_syscall_ret(num, ret, netbsd_scnames, ARRAY_SIZE(netbsd_scnames)= ); -} - void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long= arg3, abi_long arg4, abi_long arg5, abi_long arg6) { --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233152; cv=none; d=zohomail.com; s=zohoarc; b=CAWLthNvb0LbAZoxcAwJNCr1gZ206lnfEm+645oLHeZHMcswtdGkJZp9vu0WkntwpXNRyFFcmpBhS2JuNra8MnsMIpyKtyUUJcPIBp9n8sCj40nJGYLrscInEnKJCHx/7bcHCQeT2VMlSSOG3UTfbSUE2U7aG9VII+trsZ8/l1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233152; 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=CrJ6hQ7Rt3y9iXgYz6Hn19qcli8MJnG4NqFH7qfo5u0=; b=CTU6SGyZMB+/rBprkFNeQr7qM6S8YLTb1u9etT832DeqmOm54yiH1twDFgsR7NWPNi18x3YA3U/OpU9RorbVjuYL9l428b4QPKi5p87D+ayADCY3wC8IK3AYF2LfBZiyC97cbE+Q2m0oq7WBgcuTzaeCXinIrBA+qUwNRBufzHY= 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 1681233152169187.57318380670017; Tue, 11 Apr 2023 10:12:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW7-0003u2-Mc; Tue, 11 Apr 2023 13:10:51 -0400 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 1pmHVs-0003qX-6B for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:37 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmHVm-000689-MW for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:33 -0400 Received: by mail-il1-x12c.google.com with SMTP id a4so4311751ilj.10 for ; Tue, 11 Apr 2023 10:10:30 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233028; 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=CrJ6hQ7Rt3y9iXgYz6Hn19qcli8MJnG4NqFH7qfo5u0=; b=iykA1KYxTfgjwewZvl0P3FRWH8diAiK/hcmhWdzCz5Rh+i+1R3Kg2kjV7ynxDFI41t dqZCY9rj8VeoilLTxczDZTRUH5h5gA136lsfZAaQu23bfRFHfYoLwk1rBdIEg8VoQw1F UPMgrJsPg2f3WqzEQ9PMccOTogqQZjxzcmaVRcjRaolNWRxB7hqf4nngrnoBQc30T05M 0Svcot8U+3hCgrFhEcTGUM1KTXFuP00DSKl8csH2AYLQagGY1At0DV04Chw2LqqwfI87 C4s1CAU437Tp15Sudg7kSbFI3ahwyJgsmhNv5K6+J2zMoH+lxj9eO4tEY+hxk56HMK6a /R+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233028; 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=CrJ6hQ7Rt3y9iXgYz6Hn19qcli8MJnG4NqFH7qfo5u0=; b=Kxg3GvyqlmkOGjUS2vmfb5KUv7j1X/XJIYwK4zXWkacipLXwM/yfA8VbEWKdI6rN3N d/NirI7qT/ynHUhBqTVg2pLMAj+3m58fkdybXFGXTGJsAEuz5UUmnaDg0GBgMT9O3Ed/ gtWdtsbuSYeAz+tX1/xa9m3676/g6oglWQnyXM2uop7tGgnVB6yGQ669gwJMF71kRrUB IeO6824ezEfB1VLAgauw00iQ/NFRtDo3i0h6Gl44chZ77xNsM986fv9Larp8TAKVVPGZ uS69TYt2QPjrf1YWktZ8I2N2S1R38vlsEP+IQ41KhrLpvOV5M+QiLOL6Eo15xuS6DFCw VZaA== X-Gm-Message-State: AAQBX9fveOyvTW04xZLkXfE0gLV2pBeUF+scLvqskJ0q6b3pS3PDVCZp hJMXBLJkFIdoazbvz/p5wi2xeQXqa3p09vhKgfc= X-Google-Smtp-Source: AKy350Y6F+X8WyBACC1iMYa2bTDwFuTJLSPZncrpz9tBscyzmVT+Rj37AMLEUy6KJ9F8GVxMqF5nVQ== X-Received: by 2002:a92:60b:0:b0:328:9a54:3bed with SMTP id x11-20020a92060b000000b003289a543bedmr5784535ilg.29.1681233028552; Tue, 11 Apr 2023 10:10:28 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 06/20] bsd-user: Remove OpenBSD specific syscall printing Date: Tue, 11 Apr 2023 11:09:41 -0600 Message-Id: <20230411170955.17358-7-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1681233153118100005 Content-Type: text/plain; charset="utf-8" Nothing calls these routines now. In the bsd-user fork, though, they've moved to openbsd/os-syscall.c, but those aren't ready for upstreaming. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 5 ----- bsd-user/strace.c | 25 ------------------------- 2 files changed, 30 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index cee02d2a0ea..49468734d44 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -196,11 +196,6 @@ struct syscallname { void (*result)(const struct syscallname *, abi_long); }; =20 -void -print_openbsd_syscall(int num, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6); -void print_openbsd_syscall_ret(int num, abi_long ret); void print_execve(const struct syscallname *name, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6); diff --git a/bsd-user/strace.c b/bsd-user/strace.c index 8e76caa3c3f..b827acb2477 100644 --- a/bsd-user/strace.c +++ b/bsd-user/strace.c @@ -142,14 +142,6 @@ void print_syscall_ret_addr(const struct syscallname *= name, abi_long ret) } } =20 -/* - * An array of all of the syscalls we know about - */ - -static const struct syscallname openbsd_scnames[] =3D { -#include "openbsd/strace.list" -}; - void print_syscall(int num, const struct syscallname *scnames, unsigned int nscnames, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long a= rg6) @@ -203,23 +195,6 @@ void print_syscall_ret(int num, abi_long ret, const st= ruct syscallname *scnames, } } =20 -/* - * The public interface to this module. - */ -void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long= arg3, - abi_long arg4, abi_long arg5, abi_long arg6) -{ - - print_syscall(num, openbsd_scnames, ARRAY_SIZE(openbsd_scnames), arg1,= arg2, - arg3, arg4, arg5, arg6); -} - -void print_openbsd_syscall_ret(int num, abi_long ret) -{ - - print_syscall_ret(num, ret, openbsd_scnames, ARRAY_SIZE(openbsd_scname= s)); -} - static void print_signal(abi_ulong arg, int last) { --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233145; cv=none; d=zohomail.com; s=zohoarc; b=ZlvAOf/IDOi8vAA0fQhpvf2Eb7NBFphBN1+VmExFjR3Jy/ue4AV+0/Oja4f9CkDffr+9TEchDCB9ElcxoAERV9gn01Wrpqcd4QfkQjrk3GtyqBzUqtCtrNG3sbvmAdWpCIkxbaD6wYkf8+KF5K+fIz/PrffSqAnv9+QZaYgv2m4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233145; 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=jwIHVc41F1vGdAlrXUv6Uz16Se8rtJQuutqsrYhY8XA=; b=b+iKs4s0tdXICCe0joS4qLodmqDvmetC/hXthJjTlUz/wWGtiHVX6+Up+gIhN5zdBkD04PwCfIoWR6sVRWM4Hc3UdZ6xpnSkwjDwZTyG+ELJ+qrR83to6rQnr/dYhWbWPAFR49t9HHYUMeSXcpnJg0BZgbfWW0i2iMhPY3eTv3I= 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 1681233145799225.1826737540648; Tue, 11 Apr 2023 10:12:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHWS-00045i-0i; Tue, 11 Apr 2023 13:11:12 -0400 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 1pmHVs-0003qZ-6n for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:37 -0400 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 1pmHVn-00068F-O8 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:34 -0400 Received: by mail-il1-x12a.google.com with SMTP id j28so3888071ila.0 for ; Tue, 11 Apr 2023 10:10:30 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233029; 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=jwIHVc41F1vGdAlrXUv6Uz16Se8rtJQuutqsrYhY8XA=; b=La3vSUs5iC5tB7EzN2mizJAN09znFJdbWUOSmkCVMUy8Aw8s4L0Le+/pt5f/0A6NFp w+w/3bTCAwChkLSwhEgnrWJ8lngnJds2iirEe++jLo7yervsfZ4SANpoMjlUtmJ8PBcz IgvY7QxISKLWes/5+bT1qFokawLUuoh6CI2qlI59GSFbbMA4HpuCM03XMYa28fXnuakR jvP09qIiRzyNTmWgRjPVCK/YHcZcxLA/qxmEL8Uce1WJpIPmp/JXyaxmwGuMMNuZzGC2 76oFwqj7jnn0T5q+KbSSvpm4+YqwCXKeehReGzarEMFWKukFwiw4JvG3+NOWqVm4XOtE Cztw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233029; 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=jwIHVc41F1vGdAlrXUv6Uz16Se8rtJQuutqsrYhY8XA=; b=BEIRAwJ8PHYuLSOc8f3Cu/g43SBPJMG7/ZSFIlWqCVoF3KA8fwCQQYY2hXYlPCEFXv HEWbGFwsuSTR5lbXRyvtwv5vxY0j2O2+ZS1dcQSDm7QW6PjiLMDr2dQ/fQq6ts8ahzln zEVbUxCv0j4WNU1wqs5eyTjFp9zrkGncA2rMFFwpeZEMOybRb4/kHIJlQ8CxncHdlzUx hAjb8J72F70jBb3r56hWW8dRDyADtbBZ1LQFpqKhBvN+k9S6HBpWmkm32hVb0zXEgZll 11qZ48aVpA9Se5+RRHQpIhvTZxD9/WXxic+057TlA7kJV/siRpz2St8eclpeEFGFYb1E 7AHQ== X-Gm-Message-State: AAQBX9fYsL/yU2vi8y+x0PLKlEwgIhYNGMYqjWxAqHfBwx42b/0LBtN9 h3OZ+SXB770UoF9gT3HfAhuVyL+NehYOQTvqhmQ= X-Google-Smtp-Source: AKy350b4+G3QknlhYDreK2CJk6eDVFjfYc+vI+ohvaCYijV5pgLIahJqjDxjxKpLpCeTsc7TXpaMTQ== X-Received: by 2002:a92:ce0a:0:b0:328:95de:3549 with SMTP id b10-20020a92ce0a000000b0032895de3549mr6069109ilo.9.1681233029514; Tue, 11 Apr 2023 10:10:29 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 07/20] bsd-user: Move system call include to os-syscall.h Date: Tue, 11 Apr 2023 11:09:42 -0600 Message-Id: <20230411170955.17358-8-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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::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+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: 1681233146810100001 Content-Type: text/plain; charset="utf-8" Move the include of the system calls to os-syscall.h. Include that from syscall_defs.h. Use target_time_t and target_suseconds_t instead of the variant that has _freebsd_ in the name. Define these for OpenBSD and NetBSD based on comments in the file. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-syscall.h | 21 +++++++++++++++++++++ bsd-user/netbsd/os-syscall.h | 16 ++++++++++++++++ bsd-user/openbsd/os-syscall.h | 16 ++++++++++++++++ bsd-user/syscall_defs.h | 33 ++++----------------------------- 4 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 bsd-user/freebsd/os-syscall.h create mode 100644 bsd-user/netbsd/os-syscall.h create mode 100644 bsd-user/openbsd/os-syscall.h diff --git a/bsd-user/freebsd/os-syscall.h b/bsd-user/freebsd/os-syscall.h new file mode 100644 index 00000000000..1f2c0acb1c5 --- /dev/null +++ b/bsd-user/freebsd/os-syscall.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Warner Losh + * + * SPDX-License-Identifier: BSD-2-Clause + * + * OS-Specific portion of syscall_defs.h + */ + +#include "freebsd/syscall_nr.h" + +/* + * FreeBSD uses a 64bits time_t except on i386 so we have to add a special= case + * here. + */ +#if (!defined(TARGET_I386)) +typedef int64_t target_time_t; +#else +typedef int32_t target_time_t; +#endif + +typedef abi_long target_suseconds_t; diff --git a/bsd-user/netbsd/os-syscall.h b/bsd-user/netbsd/os-syscall.h new file mode 100644 index 00000000000..7507350d8d2 --- /dev/null +++ b/bsd-user/netbsd/os-syscall.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Warner Losh + * + * SPDX-License-Identifier: BSD-2-Clause + * + * OS-Specific portion of syscall_defs.h + */ + +#include "netbsd/syscall_nr.h" + +/* + * time_t seems to be very inconsistly defined for the different *BSD's... + * + * NetBSD always uses int64_t. + */ +typedef int64_t target_time_t; diff --git a/bsd-user/openbsd/os-syscall.h b/bsd-user/openbsd/os-syscall.h new file mode 100644 index 00000000000..191a76fa935 --- /dev/null +++ b/bsd-user/openbsd/os-syscall.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Warner Losh + * + * SPDX-License-Identifier: BSD-2-Clause + * + * OS-Specific portion of syscall_defs.h + */ + +#include "openbsd/syscall_nr.h" + +/* + * time_t seems to be very inconsistly defined for the different *BSD's... + * + * OpenBSD always uses int. + */ +typedef int target_time_t; diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index b6d113d24a7..489d3a2e292 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -25,30 +25,7 @@ =20 #include "errno_defs.h" =20 -#include "freebsd/syscall_nr.h" -#include "netbsd/syscall_nr.h" -#include "openbsd/syscall_nr.h" - -/* - * machine/_types.h - * or x86/_types.h - */ - -/* - * time_t seems to be very inconsistly defined for the different *BSD's... - * - * FreeBSD uses a 64bits time_t except on i386 - * so we have to add a special case here. - * - * On NetBSD time_t is always defined as an int64_t. On OpenBSD time_t - * is always defined as an int. - * - */ -#if (!defined(TARGET_I386)) -typedef int64_t target_freebsd_time_t; -#else -typedef int32_t target_freebsd_time_t; -#endif +#include "os-syscall.h" =20 struct target_iovec { abi_long iov_base; /* Starting address */ @@ -98,11 +75,9 @@ struct target_iovec { * sys/timex.h */ =20 -typedef abi_long target_freebsd_suseconds_t; - /* compare to sys/timespec.h */ struct target_freebsd_timespec { - target_freebsd_time_t tv_sec; /* seconds */ + target_time_t tv_sec; /* seconds */ abi_long tv_nsec; /* and nanoseconds */ #if !defined(TARGET_I386) && TARGET_ABI_BITS =3D=3D 32 abi_long _pad; @@ -120,8 +95,8 @@ struct target_freebsd__umtx_time { }; =20 struct target_freebsd_timeval { - target_freebsd_time_t tv_sec; /* seconds */ - target_freebsd_suseconds_t tv_usec;/* and microseconds */ + target_time_t tv_sec; /* seconds */ + target_suseconds_t tv_usec;/* and microseconds */ #if !defined(TARGET_I386) && TARGET_ABI_BITS =3D=3D 32 abi_long _pad; #endif --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233109; cv=none; d=zohomail.com; s=zohoarc; b=EO7zIrCaBuaOIaPHn7IzIV01B+HgYTLeu9rBS96rfmi9iwXmfhtxwVjiLIALmcuUN+qV9d7x7nefm7ahONFt/Tj96xwVhlayELpfUJgwayfFkUwTmxxFmh71WAYd0CvnWduPOoaOKkJ10Lb7p5wDXeHfwhSZAoYXxUdInj3mh/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233109; 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=p/770m3m0UuWja7n7zJRMdkcuTqSX6pSDmKn7o3gni8=; b=fcq3w4+vm2VyfooX0LPMt6W5S/tyYZBONpcZVZ736rXTKI3YabifYgGkVRoz2i1tLt8o0khkGKWgs1Nyzh9fwTU4V5TFGOTG0/LraHxraDUdtHWiOgu6M6kVXlP2xJjDxWvTXRC52VYzXQpyjztCcyovgufkS1XPUzaGAlaK3Vs= 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 1681233109889751.0670545271142; Tue, 11 Apr 2023 10:11:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHWP-00044l-Vn; Tue, 11 Apr 2023 13:11:10 -0400 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 1pmHVs-0003qY-6I for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:37 -0400 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 1pmHVo-00068X-LU for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:34 -0400 Received: by mail-il1-x12b.google.com with SMTP id j28so3888103ila.0 for ; Tue, 11 Apr 2023 10:10:32 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233030; 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=p/770m3m0UuWja7n7zJRMdkcuTqSX6pSDmKn7o3gni8=; b=bf76Dq0gYUvTKu88rdQfkSFy+gzHq0G7mXgiuJbhl1kyk62vFSV4K7poQ4I8A9xhbD c/D1zuWxTlMXng2kD2ktR0/0VEzPbcxMKnu2AyOI7xCzRwTQSL/3VC1zgbWfb1vmrjGw wznKv20LxGBLG1lr9LixJCn6M5WLJiHxFaBkvAE8okGHHZb4UDx3vDGHjhRVi7/73fuk Zc3366McqGQbubmYkDGv7wx+DZovvBGT9ygoRDSAfZNBtiS6id3cZokvZomecdtoXzaa pRUI7Iiao8t3GdH3S8bocuzKVja3Cu0IYM8tgsSrhIdfthw2nfPDnEouv+vqV0SWXiOH FKqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233030; 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=p/770m3m0UuWja7n7zJRMdkcuTqSX6pSDmKn7o3gni8=; b=QLd1Betl3tLwhUk2+K+wjT/uAMwmmDKy7hsr2MhPu/Zuyv90WYVn6Og4MN6JZ+uA7G W8Y4d1Id0QyBoYouYXEVF9d4M2HeLiztVv8uwwE6KEhk+A0YwTei9QcnAr4IhtJZZCM0 WwacECSZWH5KbxID2B4daXre0BdVxQNTdNH2UZcQ7Jd5DyQTV/HHItgfgUMxHaNk1AqV 9R2FxHzqMwQf5dIvKBzvL3JLQIwua/uZJXbfqicqYXu5yTrc6u7nEb7R1vKJKKfM/t+R fNPxokuO02SYZBGjnQOiDlc/3oiYS/9AmF0nn+wuQdyW6XfR+pHbyp0tDDgoR36wXZ6b Hd+w== X-Gm-Message-State: AAQBX9egWnJtNYO9n3kprr0//SAG1ZI4y9TMNAjajjoci6yfJAqUuHTX ScEjfhUGJGyGS+0Kh6Tw1sOqDaov7urC+GDaBBA= X-Google-Smtp-Source: AKy350bweKwr443Ot70W1rzL2U2o5mG/F0EZ/Lb1KnK1lRENHwPF9sf8TEHpq/rISXi/gvF+OR0YQQ== X-Received: by 2002:a05:6e02:1d1d:b0:325:f703:6e5e with SMTP id i29-20020a056e021d1d00b00325f7036e5emr15433230ila.11.1681233030528; Tue, 11 Apr 2023 10:10:30 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 08/20] bsd-user: Remove useless mmap definitions Date: Tue, 11 Apr 2023 11:09:43 -0600 Message-Id: <20230411170955.17358-9-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1681233110732100003 Content-Type: text/plain; charset="utf-8" On BSD, all architectures have the same mmap flags. Since we don't translate the flags, we don't need these defines here. We can't cross-run different BSD binaries. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/syscall_defs.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 489d3a2e292..0604e96973e 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -32,42 +32,6 @@ struct target_iovec { abi_long iov_len; /* Number of bytes */ }; =20 -/* - * sys/mman.h - */ -#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplement= ed */ - /* MAP_INHERIT */ -#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemente= d */ - /* MAP_NOEXTEND */ -#define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like= a */ - /* stack */ -#define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync= */ - /* underlying file */ - -#define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7 - -#define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained afte= r */ - /* exec */ -#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, e= ven */ - /* within break */ -#define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it= is */ - /* established */ - -#define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, = */ - /* swap space (stack) */ - -#define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7 - -#define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained afte= r */ - /* exec */ -#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't cha= nge */ - /* file size */ -#define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */ - /* even within heap */ - -#define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7 - -/* XXX */ #define TARGET_BSD_MAP_FLAGMASK 0x3ff7 =20 /* --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233113; cv=none; d=zohomail.com; s=zohoarc; b=iwk0OgQk6n5QxX2STxAkeRZWOMPHFBRQR3ZtPTw8CxwpgqGSQxjoGY3ouxteMk/pY0K3dXnZdeUTNG7f00m5ZK7UTNanE1y8nuxCE+2/CQViBBGAKKV2jB/M3lAqWQ1dc0Yw06jBzuSRbcdduyz5UMxm0cDrV+3c6WAHk80bSKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233113; 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=yuaGwqi8yehJHqn9QWm7paJs7txwchU6M9DMK57E1Ps=; b=ftajeGsQ3ca34xGax70nhCc1qtwzWuB6b1vmizXYJx4M1gimJqnyjkgVBgzRBBfnCZFexWwmufycfFO+Duk0VTLA6JcxCPWYmSQ2VcEbaFPQr+OFcbfCOr0WMZYUFh1ZiZTcUF2sOkzNaDriOfutD4g0/VkC86KxxbZaE0cG6qc= 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 1681233113316456.65663804579185; Tue, 11 Apr 2023 10:11:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW1-0003rv-GR; Tue, 11 Apr 2023 13:10:45 -0400 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 1pmHVs-0003qa-75 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:37 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmHVp-00068f-53 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:35 -0400 Received: by mail-io1-xd30.google.com with SMTP id x3so15802743iov.3 for ; Tue, 11 Apr 2023 10:10:32 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233031; 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=yuaGwqi8yehJHqn9QWm7paJs7txwchU6M9DMK57E1Ps=; b=0+GsBIZsYmNWHWWk410dUKkZXzs5nBeMkIRgdykQFxMmV9MVHnkGWIVlE0ZVuzehFM TUijoMncMIphLinh4bZlpbp3XFB8PN7nvHgYbz8VhzXA0XlK4m2HYlz8B5QWE18fxpOr XZGz9xQspGBlb/TJqWPk+P6UcowREGCMUu28MnxY8ebs2U4D/wMu7BjApczc/L6JuvKE Q6LS2WiAx9p3nbxZXIF379ZnQ9odiiT6J78yUsopPmcpKAaIPTijdyKLf/RcGbJoEJ02 ydls1Ec82VEor2CSERd+5SH+HQCzFHHueHoti82YOIikAfLuDR3yq7gNGEa0IC7w1vcO S/Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233031; 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=yuaGwqi8yehJHqn9QWm7paJs7txwchU6M9DMK57E1Ps=; b=UoPrN2qPWCvtvSDcZQJjhr5dnv5zW2zid1WZktbcaSpUs/x3MtMrI8Djck6MHXO1Ts oLHFEMRz4r2u85sIfMN+ZvciJEJs6OAD4voV4vlY0sh2j85Bn/zILihVtB9Tf7jqFPuB cBxK0pyIP5aK3p+syNJbPfFq8c/lqTuCJIyrYY3JUKAiIuORk7Y2l+oU99JDk5Eh1oTS 18Rv0Z1yM6w8Ka1loHWZXmS5/wTtFvpxMLZgS0d4yCPzjZdd0zBwOuCFIHn4o/BCg/Zg Z06dcjwTnfXnsSpGWDuwt8MYGELwFrUMQ6hqbfYAMGbrVlq5Drh6iyP7JgtK6gBgrC6d NNQA== X-Gm-Message-State: AAQBX9cZq6iu0o9/kbCeOKHiz0eWbb3FneFmMJoIWRiiERvvIh1MtdlY YJOs5u/f4O37ekmjY2CI/VjdMJ3o50Cfxb2VQK8= X-Google-Smtp-Source: AKy350YohwN5VBOhgFy0W5yZc5eijCi+mJ4Dxx0gTrl685yYThFcaKE/VPr3y1v82vUoaKkgTD1doA== X-Received: by 2002:a05:6602:2211:b0:759:1e12:ba32 with SMTP id n17-20020a056602221100b007591e12ba32mr6583335ion.4.1681233031505; Tue, 11 Apr 2023 10:10:31 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Stacey Son , Richard Henderson Subject: [PATCH v3 09/20] bsd-user: h2g_rusage Date: Tue, 11 Apr 2023 11:09:44 -0600 Message-Id: <20230411170955.17358-10-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.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: 1681233114630100003 Content-Type: text/plain; charset="utf-8" From: Stacey Son Converts host's rusage to the guest's rusage. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsd-proc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ bsd-user/meson.build | 1 + bsd-user/qemu-bsd.h | 30 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 bsd-user/bsd-proc.c create mode 100644 bsd-user/qemu-bsd.h diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c new file mode 100644 index 00000000000..e64eb958947 --- /dev/null +++ b/bsd-user/bsd-proc.c @@ -0,0 +1,48 @@ +/* + * BSD process related system call helpers + * + * Copyright (c) 2013-14 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" + +#include "qemu.h" +#include "qemu-bsd.h" +#include "signal-common.h" + +void h2g_rusage(const struct rusage *rusage, + struct target_freebsd_rusage *target_rusage) +{ + __put_user(rusage->ru_utime.tv_sec, &target_rusage->ru_utime.tv_sec); + __put_user(rusage->ru_utime.tv_usec, &target_rusage->ru_utime.tv_usec); + + __put_user(rusage->ru_stime.tv_sec, &target_rusage->ru_stime.tv_sec); + __put_user(rusage->ru_stime.tv_usec, &target_rusage->ru_stime.tv_usec); + + __put_user(rusage->ru_maxrss, &target_rusage->ru_maxrss); + __put_user(rusage->ru_idrss, &target_rusage->ru_idrss); + __put_user(rusage->ru_idrss, &target_rusage->ru_idrss); + __put_user(rusage->ru_isrss, &target_rusage->ru_isrss); + __put_user(rusage->ru_minflt, &target_rusage->ru_minflt); + __put_user(rusage->ru_majflt, &target_rusage->ru_majflt); + __put_user(rusage->ru_nswap, &target_rusage->ru_nswap); + __put_user(rusage->ru_inblock, &target_rusage->ru_inblock); + __put_user(rusage->ru_oublock, &target_rusage->ru_oublock); + __put_user(rusage->ru_msgsnd, &target_rusage->ru_msgsnd); + __put_user(rusage->ru_msgrcv, &target_rusage->ru_msgrcv); + __put_user(rusage->ru_nsignals, &target_rusage->ru_nsignals); + __put_user(rusage->ru_nvcsw, &target_rusage->ru_nvcsw); + __put_user(rusage->ru_nivcsw, &target_rusage->ru_nivcsw); +} diff --git a/bsd-user/meson.build b/bsd-user/meson.build index 5243122fc56..7d1b4de78b1 100644 --- a/bsd-user/meson.build +++ b/bsd-user/meson.build @@ -8,6 +8,7 @@ common_user_inc +=3D include_directories('include') =20 bsd_user_ss.add(files( 'bsdload.c', + 'bsd-proc.c', 'elfload.c', 'main.c', 'mmap.c', diff --git a/bsd-user/qemu-bsd.h b/bsd-user/qemu-bsd.h new file mode 100644 index 00000000000..96e7f34b27c --- /dev/null +++ b/bsd-user/qemu-bsd.h @@ -0,0 +1,30 @@ +/* + * BSD conversion extern declarations + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef QEMU_BSD_H +#define QEMU_BSD_H + +#include +#include + +/* bsd-proc.c */ +void h2g_rusage(const struct rusage *rusage, + struct target_freebsd_rusage *target_rusage); + +#endif /* QEMU_BSD_H */ --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233174; cv=none; d=zohomail.com; s=zohoarc; b=ASuMONQ6O58CEVCPW+xf1Ifrhv0dDSOJOtnWbnOqR46nw3iGoIcnOtnKtnPfuJ35UOR/rX9gMRQX1Q/JYleFH7MYwoMoHjwzFyAIMFOV9c5uRC3Hp9upgoRc3lln6V7QU/nrF+teWEsJTjo3PsURU2bED8vDAqgumvFF+yM3MP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233174; 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=dLPGsKZ9qU3wG8gg3c0pvYiD+HZ1kzhXINDhxubxQNw=; b=Gpj3Homqb3uhFPo4oX4DzGIdVD96FxPNgPls7QUTyiBMRSQ3SGMcvzqCER6wxKolw6XWpNG+k6DKc2ZsuvkUmQpErKq8JC9sTaX4p3yzg8nroyRYJPxhD71WCZ4EMAjur+ZUO9/OQBFISarvDv7FtA9OVjlzUB3VZa/YMmmMbrU= 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 16812331745011010.5492854288137; Tue, 11 Apr 2023 10:12:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHWR-00044r-8H; Tue, 11 Apr 2023 13:11:11 -0400 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 1pmHVu-0003rF-AX for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:39 -0400 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 1pmHVr-00068w-Vw for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:38 -0400 Received: by mail-io1-xd32.google.com with SMTP id b25so6172ioc.7 for ; Tue, 11 Apr 2023 10:10:33 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233032; 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=dLPGsKZ9qU3wG8gg3c0pvYiD+HZ1kzhXINDhxubxQNw=; b=Pw1b2G2fP3kaYcAm8o2MR2cB4Wr66O4u5lPRaMqMbNQ6YvpNm+XC/c6KEZTQR9Z1jJ BRzsHJRqWfbPUkUjuoqfhmzsmRvEwIX+gdn46J4/sjJNbkpknxDluBsstiEQ90yM1LKj B79xs84PDcPVVhTtS6keBYI5p1R1NItbO92c8qAKYeU/F55h25dOftpkkGISkQ94pMtv Fv2U1ecYuwqK1F/uXaJ+9zf04qbjcyV6XJY2yRqtLYYB0zrksmFzA+/dlITSQQdl1bgZ /SNlrDkHyGP3gWLz0tdRhHoLCRmziJorSN6OKDQWc3tPbfEvm33+/LPzC8vrdtZfaADk 48eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233032; 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=dLPGsKZ9qU3wG8gg3c0pvYiD+HZ1kzhXINDhxubxQNw=; b=ZkTIJ1t05graTbci7cbYYlfUswa2wKckm/56qjKB9uooNej7X+Fcb51Mh26cM6N9j+ l93HWdy4q+Y3l73FDVlvwlkX3ZhkfdhrBA2/fmNeyxMXxrvK8zuBV1XsSoIkW98Hltuy gNA8sT9JG2TygbaYYvLd0Ow1lApBd1WV0Zq1siHsZBWO74ueCQRTEVO408BOkhsSDNcS 6DqBbrzWcTJ4rXvUGKKBkoueTq41uzDmFrNv4ID4xsKayxEe+FyJXU4p62klderc4lWi 04BenaT9P6KbpHneQ3Nm2lNT5eLsT+FJ/5QkhUuiA28pQR3AeVuKQmfvV1KG7hxn7DTM DuGg== X-Gm-Message-State: AAQBX9fdQIjnHcPPPKsDC41XImONJIIkOXyprRkC9yRB+f4izV3SaliQ cHUpHCMnRRt0gK0jSdsfl3isVRaYC/TUvAUuIEo= X-Google-Smtp-Source: AKy350YiWanQyNVBH2FlfyDpLtxv+V4ncYNeQxa51fB0tQVP5gPIjRnH+TyxKONJeJgkqxBQZ6IOzA== X-Received: by 2002:a5e:d515:0:b0:760:8476:8717 with SMTP id e21-20020a5ed515000000b0076084768717mr3618430iom.0.1681233032525; Tue, 11 Apr 2023 10:10:32 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Stacey Son , Richard Henderson Subject: [PATCH v3 10/20] bsd-user: Implement do_sysctl_kern_getprocs Date: Tue, 11 Apr 2023 11:09:45 -0600 Message-Id: <20230411170955.17358-11-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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: 1681233175383100005 Content-Type: text/plain; charset="utf-8" From: Stacey Son Implement do_sysctl_kern_getprocs to retrieve proc info from the kernel. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 165 +++++++++++++++++++++++++++++++++++++- bsd-user/qemu.h | 3 + 2 files changed, 167 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index df317065587..d4a6dcc6c2b 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -19,9 +19,14 @@ =20 #include "qemu/osdep.h" #include "qemu.h" +#include "qemu-bsd.h" #include "target_arch_sysarch.h" - +#include "signal-common.h" +#include #include +#include /* For struct kinfo_* */ + +#include "target_os_user.h" =20 /* * Length for the fixed length types. @@ -107,6 +112,164 @@ static abi_ulong h2g_ulong_sat(u_long ul) */ #define bsd_get_ncpu() 1 =20 +static void +host_to_target_kinfo_proc(struct target_kinfo_proc *tki, struct kinfo_proc= *hki) +{ + int i; + + __put_user(sizeof(struct target_kinfo_proc), &tki->ki_structsize); + __put_user(hki->ki_layout, &tki->ki_layout); + + /* Some of these are used as flags (e.g. ki_fd =3D=3D NULL in procstat= ). */ + tki->ki_args =3D tswapal((abi_ulong)(uintptr_t)hki->ki_args); + tki->ki_paddr =3D tswapal((abi_ulong)(uintptr_t)hki->ki_paddr); + tki->ki_addr =3D tswapal((abi_ulong)(uintptr_t)hki->ki_addr); + tki->ki_tracep =3D tswapal((abi_ulong)(uintptr_t)hki->ki_tracep); + tki->ki_textvp =3D tswapal((abi_ulong)(uintptr_t)hki->ki_textvp); + tki->ki_fd =3D tswapal((abi_ulong)(uintptr_t)hki->ki_fd); + tki->ki_vmspace =3D tswapal((abi_ulong)(uintptr_t)hki->ki_vmspace); + tki->ki_wchan =3D tswapal((abi_ulong)(uintptr_t)hki->ki_wchan); + + __put_user(hki->ki_pid, &tki->ki_pid); + __put_user(hki->ki_ppid, &tki->ki_ppid); + __put_user(hki->ki_pgid, &tki->ki_pgid); + __put_user(hki->ki_tpgid, &tki->ki_tpgid); + __put_user(hki->ki_sid, &tki->ki_sid); + __put_user(hki->ki_tsid, &tki->ki_tsid); + __put_user(hki->ki_jobc, &tki->ki_jobc); + __put_user(hki->ki_tdev, &tki->ki_tdev); + + host_to_target_sigset(&tki->ki_siglist, &hki->ki_siglist); + host_to_target_sigset(&tki->ki_sigmask, &hki->ki_sigmask); + host_to_target_sigset(&tki->ki_sigignore, &hki->ki_sigignore); + host_to_target_sigset(&tki->ki_sigcatch, &hki->ki_sigcatch); + + __put_user(hki->ki_uid, &tki->ki_uid); + __put_user(hki->ki_ruid, &tki->ki_ruid); + __put_user(hki->ki_svuid, &tki->ki_svuid); + __put_user(hki->ki_rgid, &tki->ki_rgid); + __put_user(hki->ki_svgid, &tki->ki_svgid); + __put_user(hki->ki_ngroups, &tki->ki_ngroups); + + for (i=3D0; i < TARGET_KI_NGROUPS; i++) + __put_user(hki->ki_groups[i], &tki->ki_groups[i]); + + __put_user(hki->ki_size, &tki->ki_size); + + __put_user(hki->ki_rssize, &tki->ki_rssize); + __put_user(hki->ki_swrss, &tki->ki_swrss); + __put_user(hki->ki_tsize, &tki->ki_tsize); + __put_user(hki->ki_dsize, &tki->ki_dsize); + __put_user(hki->ki_ssize, &tki->ki_ssize); + + __put_user(hki->ki_xstat, &tki->ki_xstat); + __put_user(hki->ki_acflag, &tki->ki_acflag); + + __put_user(hki->ki_pctcpu, &tki->ki_pctcpu); + + __put_user(hki->ki_estcpu, &tki->ki_estcpu); + __put_user(hki->ki_slptime, &tki->ki_slptime); + __put_user(hki->ki_swtime, &tki->ki_swtime); + __put_user(hki->ki_cow, &tki->ki_cow); + __put_user(hki->ki_runtime, &tki->ki_runtime); + + __put_user(hki->ki_start.tv_sec, &tki->ki_start.tv_sec); + __put_user(hki->ki_start.tv_usec, &tki->ki_start.tv_usec); + __put_user(hki->ki_childtime.tv_sec, &tki->ki_childtime.tv_sec); + __put_user(hki->ki_childtime.tv_usec, &tki->ki_childtime.tv_usec); + + __put_user(hki->ki_flag, &tki->ki_flag); + __put_user(hki->ki_kiflag, &tki->ki_kiflag); + + __put_user(hki->ki_traceflag, &tki->ki_traceflag); + __put_user(hki->ki_stat, &tki->ki_stat); + __put_user(hki->ki_nice, &tki->ki_nice); + __put_user(hki->ki_lock, &tki->ki_lock); + __put_user(hki->ki_rqindex, &tki->ki_rqindex); + __put_user(hki->ki_oncpu_old, &tki->ki_oncpu_old); + __put_user(hki->ki_lastcpu_old, &tki->ki_lastcpu_old); + + strncpy(tki->ki_tdname, hki->ki_tdname, TARGET_TDNAMLEN+1); + strncpy(tki->ki_wmesg, hki->ki_wmesg, TARGET_WMESGLEN+1); + strncpy(tki->ki_login, hki->ki_login, TARGET_LOGNAMELEN+1); + strncpy(tki->ki_lockname, hki->ki_lockname, TARGET_LOCKNAMELEN+1); + strncpy(tki->ki_comm, hki->ki_comm, TARGET_COMMLEN+1); + strncpy(tki->ki_emul, hki->ki_emul, TARGET_KI_EMULNAMELEN+1); + strncpy(tki->ki_loginclass, hki->ki_loginclass, TARGET_LOGINCLASSLEN+1= ); + + __put_user(hki->ki_oncpu, &tki->ki_oncpu); + __put_user(hki->ki_lastcpu, &tki->ki_lastcpu); + __put_user(hki->ki_tracer, &tki->ki_tracer); + __put_user(hki->ki_flag2, &tki->ki_flag2); + __put_user(hki->ki_fibnum, &tki->ki_fibnum); + __put_user(hki->ki_cr_flags, &tki->ki_cr_flags); + __put_user(hki->ki_jid, &tki->ki_jid); + __put_user(hki->ki_numthreads, &tki->ki_numthreads); + __put_user(hki->ki_tid, &tki->ki_tid); + + memcpy(&tki->ki_pri, &hki->ki_pri, sizeof(struct target_priority)); + + h2g_rusage(&hki->ki_rusage, &tki->ki_rusage); + h2g_rusage(&hki->ki_rusage_ch, &tki->ki_rusage_ch); + + __put_user(((uintptr_t)hki->ki_pcb), &tki->ki_pcb); + __put_user(((uintptr_t)hki->ki_kstack), &tki->ki_kstack); + __put_user(((uintptr_t)hki->ki_udata), &tki->ki_udata); + __put_user(((uintptr_t)hki->ki_tdaddr), &tki->ki_tdaddr); + + __put_user(hki->ki_sflag, &tki->ki_sflag); + __put_user(hki->ki_tdflags, &tki->ki_tdflags); +} + +abi_long +do_sysctl_kern_getprocs(int op, int arg, size_t olen, + struct target_kinfo_proc *tki, size_t *tlen) +{ + abi_long ret; + struct kinfo_proc *kipp; + int mib[4], num, i, miblen; + size_t len; + + if (tlen =3D=3D NULL) + return -TARGET_EINVAL; + + mib[0] =3D CTL_KERN; + mib[1] =3D KERN_PROC; + mib[2] =3D op; + mib[3] =3D arg; + + miblen =3D (op =3D=3D KERN_PROC_ALL || op =3D=3D KERN_PROC_PROC) ? 3 = : 4; + + len =3D 0; + ret =3D get_errno(sysctl(mib, miblen, NULL, &len, NULL, 0)); + if (is_error(ret)) + return ret; + + num =3D len / sizeof(*kipp); + *tlen =3D num * sizeof(struct target_kinfo_proc); + if (tki =3D=3D NULL) + return ret; + + if (olen < *tlen) + return -TARGET_EINVAL; + + kipp =3D g_malloc(len); + if (kipp =3D=3D NULL) + return -TARGET_ENOMEM; + ret =3D get_errno(sysctl(mib, miblen, kipp, &len, NULL, 0)); + num =3D len / sizeof(*kipp); + *tlen =3D num * sizeof(struct target_kinfo_proc); + if (len % sizeof(*kipp) !=3D 0 || kipp->ki_structsize !=3D sizeof(*kip= p)) { + ret =3D -TARGET_EINVAL; /* XXX */ + } else if (!is_error(ret)) { + for(i=3D0; i < num; i++) + host_to_target_kinfo_proc(&tki[i], &kipp[i]); + } + + g_free(kipp); + return ret; +} + /* * 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 diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 49468734d44..fcaf794ad6e 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -258,6 +258,9 @@ bool is_error(abi_long ret); int host_to_target_errno(int err); =20 /* os-sys.c */ +struct target_kinfo_proc; +abi_long do_sysctl_kern_getprocs(int op, int arg, size_t olen, + struct target_kinfo_proc *tki, size_t *tlen); 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, --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233173; cv=none; d=zohomail.com; s=zohoarc; b=n52FwZbigzWUAX3UtCEUCeEoKRVZ7xyoMrSnyDhb2PFGK55FejbTTti/w8tFJEfw9qn15RZLE3F/iX9gy9ufXkhwxn+5KUxxjI6vEmDliMQwIXMP11HJYCd6evLKAxjzGYPoE8WLhdXQw8SikJZbszuFuvbIjLUrDsHTdHE6Rl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233173; 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=mO99b13qRlgHCWdPhSoOiqyC95aMtsRkFEpbNDXSAnY=; b=R+G6gp5OYpu16G4IA61TXFxbzg9tu6VwZ4kdM4xAFkpRoxEssRdZc7Z28JYRZkV6kWM1TVSV8tII/wI5cG0p6Yjfs+sVkcp60hyumBQKtAfnsUqNkzLmzJ3xfjMatYiJmmXexR/ApwuqE1WX278K2NA8XFSrq9OiZk/p+V4sHio= 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 1681233173682663.8715564358923; Tue, 11 Apr 2023 10:12:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHWQ-00044p-5J; Tue, 11 Apr 2023 13:11:10 -0400 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 1pmHVu-0003rG-Ar for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:39 -0400 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 1pmHVr-000695-Vw for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:38 -0400 Received: by mail-il1-x133.google.com with SMTP id k7so14954801ils.3 for ; Tue, 11 Apr 2023 10:10:34 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233033; 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=mO99b13qRlgHCWdPhSoOiqyC95aMtsRkFEpbNDXSAnY=; b=XA+nTkNuoJ/IRdvg5+dOAudm0mL0auajydllO+jSw27Yr3Rjsxet1PSgawT7eLSVca y3uDYQM/q2rG08tGz/sef1tknO8xzZWoa9/viZjKdxNMqF06kn+QjgQdf0BjktgVz7/+ Kn+ENtBIqaehk/2RtogZJafm82X0ZT+9m4LvJADmzQxruMSsF6QqTips538p+gdvoC7+ qvJ/GLTAZkKkIlNPopJmPUQWB5FXxzK91LOMJk6Gz0XHJqZu/Dj8iNTP/OcT1V9u3J2+ zCJ+MGvSNB+tzk7bH/8BXu55Hb6baB6KCb72JZUo3oZ7UNYuYv3jm4u16Y6A34trmYpc hHKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233033; 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=mO99b13qRlgHCWdPhSoOiqyC95aMtsRkFEpbNDXSAnY=; b=0F5eFDg0Y/KqwQDrMC3UMqSJe71/gDTKjVEjN9MMLUoNu4nuy2iL0X/2sbb11DZPyg ovOJdnjvL8zkbFtBfKjXasGnDep54cynYV7nVNnTpJGnMpugO3pTGTM3kZNqvzF+/3qP QzwyVgkAx5hNIV2VCMO3B9OGRxujR6grhtUAT6W0kUq+hTGyOO6D8e/7u8aEtCGw9y+P VvVsgjhn/XQr5JmL8go3quh39Ddjf2FON9fkhVDHL3qEpgCRHSRgbxcpMjNdm5eHU2YO 2n7CE8zzeIp+vJUecy8ChIXSb6ael/zEUK2SrJZ/9ra98+Nup29Oi1drGsFrBZW6jR5H w+Dw== X-Gm-Message-State: AAQBX9fc/kXn3RLdWAY02CzNwzW10fl3btm2Jp3VDeonCkfbJbGuwa+l Af9lWv6RoGzW0B9+W3IsAwWx/k9j22y8I5pMy14= X-Google-Smtp-Source: AKy350bnVLrRazpuCubAMTa2TCAwFWhy1PkmvrDFxju1VPY4JNbAwltY2r/5PtB+BVskYxM+HOfleA== X-Received: by 2002:a92:4a10:0:b0:326:53bc:7817 with SMTP id m16-20020a924a10000000b0032653bc7817mr8643236ilf.17.1681233033552; Tue, 11 Apr 2023 10:10:33 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Stacey Son , Richard Henderson Subject: [PATCH v3 11/20] bsd-user: Implement do_sysctl_kern_proc_filedesc Date: Tue, 11 Apr 2023 11:09:46 -0600 Message-Id: <20230411170955.17358-12-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1681233175406100007 Content-Type: text/plain; charset="utf-8" From: Stacey Son Implement do_sysctl_kern_proc_filedesc. This pulls kern.proc.filedesc out of the host kernel and converts it to the guest's format. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 193 ++++++++++++++++++++++++++++++++++++++ bsd-user/qemu.h | 3 + 2 files changed, 196 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index d4a6dcc6c2b..00b2dcc9641 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -270,6 +270,199 @@ do_sysctl_kern_getprocs(int op, int arg, size_t olen, return ret; } =20 +static void +host_to_target_kinfo_file(struct target_kinfo_file *tkif, + struct kinfo_file *hkif) +{ + int type =3D hkif->kf_type; + + __put_user(hkif->kf_structsize, &tkif->kf_structsize); + __put_user(hkif->kf_type, &tkif->kf_type); + __put_user(hkif->kf_fd, &tkif->kf_fd); + __put_user(hkif->kf_ref_count, &tkif->kf_ref_count); + __put_user(hkif->kf_flags, &tkif->kf_flags); + __put_user(hkif->kf_offset, &tkif->kf_offset); + switch (type) { + case TARGET_KF_TYPE_FIFO: + case TARGET_KF_TYPE_SHM: + case TARGET_KF_TYPE_VNODE: + __put_user(hkif->kf_un.kf_file.kf_file_type, + &tkif->kf_un.kf_file.kf_file_type); + __put_user(hkif->kf_un.kf_file.kf_file_fsid, + &tkif->kf_un.kf_file.kf_file_fsid); + __put_user(hkif->kf_un.kf_file.kf_file_rdev, + &tkif->kf_un.kf_file.kf_file_rdev); + __put_user(hkif->kf_un.kf_file.kf_file_fileid, + &tkif->kf_un.kf_file.kf_file_fileid); + __put_user(hkif->kf_un.kf_file.kf_file_size, + &tkif->kf_un.kf_file.kf_file_size); + __put_user(hkif->kf_un.kf_file.kf_file_fsid_freebsd11, + &tkif->kf_un.kf_file.kf_file_fsid_freebsd11); + __put_user(hkif->kf_un.kf_file.kf_file_rdev_freebsd11, + &tkif->kf_un.kf_file.kf_file_rdev_freebsd11); + __put_user(hkif->kf_un.kf_file.kf_file_mode, + &tkif->kf_un.kf_file.kf_file_mode); + break; + + case TARGET_KF_TYPE_SOCKET: + __put_user(hkif->kf_un.kf_sock.kf_sock_domain0, + &tkif->kf_un.kf_sock.kf_sock_domain0); + __put_user(hkif->kf_un.kf_sock.kf_sock_type0, + &tkif->kf_un.kf_sock.kf_sock_type0); + __put_user(hkif->kf_un.kf_sock.kf_sock_protocol0, + &tkif->kf_un.kf_sock.kf_sock_protocol0); +/* XXX - Implement copy function for sockaddr_storage + host_to_target_copy_sockaddr_storage( + &hkif->kf_un.kf_file.kf_sa_local, + &kif->kf_un.kf_file.kf_sa_local); + host_to_target_copy_sockaddr_storage( + &hkif->kf_un.kf_file.kf_sa_peer, + &kif->kf_un.kf_file.kf_sa_peer); +*/ + __put_user(hkif->kf_un.kf_sock.kf_sock_pcb, + &tkif->kf_un.kf_sock.kf_sock_pcb); + __put_user(hkif->kf_un.kf_sock.kf_sock_inpcb, + &tkif->kf_un.kf_sock.kf_sock_inpcb); + __put_user(hkif->kf_un.kf_sock.kf_sock_unpconn, + &tkif->kf_un.kf_sock.kf_sock_unpconn); + __put_user(hkif->kf_un.kf_sock.kf_sock_snd_sb_state, + &tkif->kf_un.kf_sock.kf_sock_snd_sb_state); + __put_user(hkif->kf_un.kf_sock.kf_sock_rcv_sb_state, + &tkif->kf_un.kf_sock.kf_sock_rcv_sb_state); + break; + + case TARGET_KF_TYPE_PIPE: + __put_user(hkif->kf_un.kf_pipe.kf_pipe_addr, + &tkif->kf_un.kf_pipe.kf_pipe_addr); + __put_user(hkif->kf_un.kf_pipe.kf_pipe_peer, + &tkif->kf_un.kf_pipe.kf_pipe_peer); + __put_user(hkif->kf_un.kf_pipe.kf_pipe_buffer_cnt, + &tkif->kf_un.kf_pipe.kf_pipe_buffer_cnt); + break; + + case TARGET_KF_TYPE_SEM: + __put_user(hkif->kf_un.kf_sem.kf_sem_value, + &tkif->kf_un.kf_sem.kf_sem_value); + __put_user(hkif->kf_un.kf_sem.kf_sem_mode, + &tkif->kf_un.kf_sem.kf_sem_mode); + break; + + case TARGET_KF_TYPE_PTS: + __put_user(hkif->kf_un.kf_pts.kf_pts_dev_freebsd11, + &tkif->kf_un.kf_pts.kf_pts_dev_freebsd11); + __put_user(hkif->kf_un.kf_pts.kf_pts_dev, + &tkif->kf_un.kf_pts.kf_pts_dev); + break; + + case TARGET_KF_TYPE_PROCDESC: + __put_user(hkif->kf_un.kf_proc.kf_pid, + &tkif->kf_un.kf_proc.kf_pid); + break; + + + case TARGET_KF_TYPE_CRYPTO: + case TARGET_KF_TYPE_KQUEUE: + case TARGET_KF_TYPE_MQUEUE: + case TARGET_KF_TYPE_NONE: + case TARGET_KF_TYPE_UNKNOWN: + default: + /* Do nothing. */ + break; + } + __put_user(hkif->kf_status, &tkif->kf_status); + for (int i =3D 0; i < (CAP_RIGHTS_VERSION + 2); i++) + __put_user(hkif->kf_cap_rights.cr_rights[i], + &tkif->kf_cap_rights.cr_rights[i]); + strncpy(tkif->kf_path, hkif->kf_path, sizeof(tkif->kf_path)); +} + +abi_long +do_sysctl_kern_proc_filedesc(int pid, size_t olen, + struct target_kinfo_file *tkif, size_t *tlen) +{ + abi_long ret; + int mib[4], sz; + size_t len; + char *buf, *bp, *eb, *tp; + struct kinfo_file *kf, kif; + struct target_kinfo_file target_kif; + + if (tlen =3D=3D NULL) { + return -TARGET_EINVAL; + } + + len =3D 0; + mib[0] =3D CTL_KERN; + mib[1] =3D KERN_PROC; + mib[2] =3D KERN_PROC_FILEDESC; + mib[3] =3D pid; + + ret =3D get_errno(sysctl(mib, 4, NULL, &len, NULL, 0)); + if (is_error(ret)) { + return ret; + } + if (tkif =3D=3D NULL) { + *tlen =3D len; + return ret; + } + len =3D len * 4 / 3; + buf =3D g_malloc(len); + if (buf =3D=3D NULL) { + return -TARGET_ENOMEM; + } + + /* + * Count the number of records. + * + * Given that the kinfo_file information returned by + * the kernel may be different sizes per record we have + * to read it in and count the variable length records + * by walking them. + */ + ret =3D get_errno(sysctl(mib, 4, buf, &len, NULL, 0)); + if (is_error(ret)) { + g_free(buf); + return ret; + } + *tlen =3D len; + bp =3D buf; + eb =3D buf + len; + while (bp < eb) { + kf =3D (struct kinfo_file *)(uintptr_t)bp; + bp +=3D kf->kf_structsize; + } + if (olen < *tlen) { + g_free(buf); + return -TARGET_EINVAL; + } + + /* + * Unpack the records from the kernel into full length records + * and byte swap, if needed. + */ + bp =3D buf; + eb =3D buf + len; + tp =3D (char *)tkif; + while (bp < eb) { + kf =3D (struct kinfo_file *)(uintptr_t)bp; + sz =3D kf->kf_structsize; + /* Copy/expand into a zeroed buffer */ + memset(&kif, 0, sizeof(kif)); + memcpy(&kif, kf, sz); + /* Byte swap and copy into a target buffer. */ + host_to_target_kinfo_file(&target_kif, &kif); + /* Copy target buffer to user buffer and pack */ + memcpy(tp, &target_kif, sz); + /* Advance to next packed record. */ + bp +=3D sz; + /* Advance to next packed, target record. */ + tp +=3D sz; + } + + g_free(buf); + return ret; +} + /* * 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 diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index fcaf794ad6e..5926bdcc101 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -259,8 +259,11 @@ int host_to_target_errno(int err); =20 /* os-sys.c */ struct target_kinfo_proc; +struct target_kinfo_file; abi_long do_sysctl_kern_getprocs(int op, int arg, size_t olen, struct target_kinfo_proc *tki, size_t *tlen); +abi_long do_sysctl_kern_proc_filedesc(int pid, size_t olen, + struct target_kinfo_file *tkif, size_t *tlen); 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, --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233101; cv=none; d=zohomail.com; s=zohoarc; b=JaAlTKM/HcrON+K2P7n5Q0MZ9qCfoLAisiw8MF7Ay37uz1cWUGIu/AOZvu4y13irTZYCl39mjZRu8v5+4JZ7ki/BkXjBEtQHk6QvHAaUYPoI4QyBxaghagtr9sZIWBN9QkGc8/Qp0ZHlbsOgDnau/GLIavCdFO52lah3nSUV1Rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233101; 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=7NzCz/sF8P038tTGJ2ITOmZzOTs2PdrJIGIXZvdsTJ8=; b=mFKVm8v63HMVa+bnBGrXXVErN7PwVFUUy/HBelV2/QsG2DQvda0FhnO5N4r7PKiOoQsomzU6+He2eAZuiJlg2qzaGJ/8Zw9oGvbjZXjMTYx0YBkmhRjEv82CshHvd6AmGtDr43CykFvljfBofkYjjrqnYJVjUPZIv0nqsI0Q4Kk= 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 16812331014817.61780502550846; Tue, 11 Apr 2023 10:11:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHWB-00040g-Ex; Tue, 11 Apr 2023 13:10:56 -0400 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 1pmHVx-0003rj-Pa for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:43 -0400 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 1pmHVs-00069F-Fc for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:39 -0400 Received: by mail-io1-xd2c.google.com with SMTP id d20so12563899ioe.4 for ; Tue, 11 Apr 2023 10:10:35 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233034; 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=7NzCz/sF8P038tTGJ2ITOmZzOTs2PdrJIGIXZvdsTJ8=; b=i3gPrcJvA7IHi/BFxDSWOEfGutw4/WjNYleO8F4TmUovwqLbHtgNTVhVHbDcQ4ekyi 2oOl2SdIxwdE2pEpcMuWFOFJvrghTArX4nrYHx+NXzXb1BlASFY4uMtfcEU5JXavRHDr sKF36npaRe3AEjMYE4cbVMUOIZh3axkinCvF/zGOC3pVHXslu0D3D6jWP3LNd7B2+dFT 9Z1mHexFA4NStEmeRRSmBXyQX9cWCn75ux+AE1qk3O6FIwiMcUNagn/qgHKM6jJZT9Ym BRemi/FoQI2gPrOPWUt3MBLSpIbh/wtGwznwrvj3r4hyLKXH+REJZjPDWbyjH5p6pH7e wJfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233034; 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=7NzCz/sF8P038tTGJ2ITOmZzOTs2PdrJIGIXZvdsTJ8=; b=L+HthUskMqtWs9PXjBWTFr6Gd0R2LME4w0N2QMt/1yAiBUkkLaEC1jeX7UEnE/qCSb +vXgGWkrKCoXCKUindqUAHjXXm7keSS6sijggMRzpch5vWsyDzPDxDCJWZH6B9wBW4Gp lyR1w/RI81GFCZnw5VuNAB9AHDuTebinCGpYCH3VKPoGc+IP1yXGdGfLPVlXv3+6foJ1 4WslERje6u8VUsQXcpq5Z6FJn5avQY9x4s1L911FuTI8t4lZ7dPNHTnJgHOcOwnLXTFz uRIhwZs/xb+ic+L6iiuBz2XDaSMOYAGCRzHY2Wf2yeRVY2XjeHCoFVPE2o5kCZDWKIla en3Q== X-Gm-Message-State: AAQBX9dXOhtf8tX625ByBLcEVCjYqBaLCE0lQQYS1kmMzmELRHTZ2qVa YffjKlqP5/eP2Wh8pMrH34V+DlwJYsPFgXamKKY= X-Google-Smtp-Source: AKy350aygik2amK6Cx4QMHHVSQVtRrX65LXIokH6xlCaY0VAOvLABOC/AdZ6z9gXD9G3YsiO11+mlg== X-Received: by 2002:a5e:d80d:0:b0:753:568:358e with SMTP id l13-20020a5ed80d000000b007530568358emr2037400iok.20.1681233034611; Tue, 11 Apr 2023 10:10:34 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Stacey Son , Richard Henderson Subject: [PATCH v3 12/20] bsd-user: Implement do_sysctl_kern_proc_vmmap Date: Tue, 11 Apr 2023 11:09:47 -0600 Message-Id: <20230411170955.17358-13-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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: 1681233102636100003 Content-Type: text/plain; charset="utf-8" From: Stacey Son Implement do_sysctl_kern_proc_vmmap. This pulls kern.proc.vmmap out of the host kernel and converts it to the guest's format. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 115 ++++++++++++++++++++++++++++++++++++++ bsd-user/qemu.h | 3 + 2 files changed, 118 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 00b2dcc9641..418358adc1e 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -463,6 +463,121 @@ do_sysctl_kern_proc_filedesc(int pid, size_t olen, return ret; } =20 +static void +host_to_target_kinfo_vmentry(struct target_kinfo_vmentry *tkve, + struct kinfo_vmentry *hkve) +{ + + __put_user(hkve->kve_structsize, &tkve->kve_structsize); + __put_user(hkve->kve_type, &tkve->kve_type); + __put_user(hkve->kve_start, &tkve->kve_start); + __put_user(hkve->kve_end, &tkve->kve_end); + __put_user(hkve->kve_offset, &tkve->kve_offset); + __put_user(hkve->kve_vn_fileid, &tkve->kve_vn_fileid); + __put_user(hkve->kve_vn_fsid_freebsd11, &tkve->kve_vn_fsid_freebsd11); + __put_user(hkve->kve_vn_fsid, &tkve->kve_vn_fsid); + __put_user(hkve->kve_flags, &tkve->kve_flags); + __put_user(hkve->kve_resident, &tkve->kve_resident); + __put_user(hkve->kve_private_resident, &tkve->kve_private_resident); + __put_user(hkve->kve_protection, &tkve->kve_protection); + __put_user(hkve->kve_ref_count, &tkve->kve_ref_count); + __put_user(hkve->kve_shadow_count, &tkve->kve_shadow_count); + __put_user(hkve->kve_vn_type, &tkve->kve_vn_type); + __put_user(hkve->kve_vn_size, &tkve->kve_vn_size); + __put_user(hkve->kve_vn_rdev_freebsd11, &tkve->kve_vn_rdev_freebsd11); + __put_user(hkve->kve_vn_rdev, &tkve->kve_vn_rdev); + __put_user(hkve->kve_vn_mode, &tkve->kve_vn_mode); + __put_user(hkve->kve_status, &tkve->kve_status); + strncpy(tkve->kve_path, hkve->kve_path, sizeof(tkve->kve_path)); +} + +abi_long +do_sysctl_kern_proc_vmmap(int pid, size_t olen, + struct target_kinfo_vmentry *tkve, size_t *tlen) +{ + abi_long ret; + int mib[4], sz; + size_t len; + char *buf, *bp, *eb, *tp; + struct kinfo_vmentry *kve, kvme; + struct target_kinfo_vmentry target_kvme; + + if (tlen =3D=3D NULL) { + return -TARGET_EINVAL; + } + + len =3D 0; + mib[0] =3D CTL_KERN; + mib[1] =3D KERN_PROC; + mib[2] =3D KERN_PROC_VMMAP; + mib[3] =3D pid; + + ret =3D get_errno(sysctl(mib, 4, NULL, &len, NULL, 0)); + if (is_error(ret)) { + return ret; + } + if (tkve =3D=3D NULL) { + *tlen =3D len; + return ret; + } + len =3D len * 4 / 3; + buf =3D g_malloc(len); + if (buf =3D=3D NULL) { + return -TARGET_ENOMEM; + } + + /* + * Count the number of records. + * + * Given that the kinfo_file information returned by + * the kernel may be differents sizes per record we have + * to read it in and count the variable length records + * by walking them. + */ + ret =3D get_errno(sysctl(mib, 4, buf, &len, NULL, 0)); + if (is_error(ret)) { + g_free(buf); + return ret; + } + *tlen =3D len; + bp =3D buf; + eb =3D buf + len; + while (bp < eb) { + kve =3D (struct kinfo_vmentry *)(uintptr_t)bp; + bp +=3D kve->kve_structsize; + } + if (olen < *tlen) { + g_free(buf); + return -TARGET_EINVAL; + } + + /* + * Unpack the records from the kernel into full length records + * and byte swap, if needed. + */ + bp =3D buf; + eb =3D buf + len; + tp =3D (char *)tkve; + while (bp < eb) { + kve =3D (struct kinfo_vmentry *)(uintptr_t)bp; + sz =3D kve->kve_structsize; + /* Copy/expand into a zeroed buffer */ + memset(&kvme, 0, sizeof(kvme)); + memcpy(&kvme, kve, sz); + /* Byte swap and copy into a target aligned buffer. */ + host_to_target_kinfo_vmentry(&target_kvme, &kvme); + /* Copy target buffer to user buffer, packed. */ + memcpy(tp, &target_kvme, sz); + /* Advance to next packed record. */ + bp +=3D sz; + /* Advance to next packed, target record. */ + tp +=3D sz; + } + + g_free(buf); + return ret; +} + /* * 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 diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 5926bdcc101..aed0d481cba 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -260,10 +260,13 @@ int host_to_target_errno(int err); /* os-sys.c */ struct target_kinfo_proc; struct target_kinfo_file; +struct target_kinfo_vmentry; abi_long do_sysctl_kern_getprocs(int op, int arg, size_t olen, struct target_kinfo_proc *tki, size_t *tlen); abi_long do_sysctl_kern_proc_filedesc(int pid, size_t olen, struct target_kinfo_file *tkif, size_t *tlen); +abi_long do_sysctl_kern_proc_vmmap(int pid, size_t olen, + struct target_kinfo_vmentry *tkve, size_t *tlen); 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, --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233180; cv=none; d=zohomail.com; s=zohoarc; b=N7U7MskC6OyizL1kJNKI4+9hnN8UvPTFHZEGOBkSRT+ntNyGOTVbrL017Q3TNadYc898+0KEGqSDQDUbQPEhoDnKcgAJYsigOyB9PSdZEQ2ijsIWq2w20mazT1i/54iAFJOBnQdCK4xYXZLvOHjFZNQQWWgRCbg3IDw/12nqO5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233180; 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=Hvg0H+jAXckcuN28KMVfXkb7fwvWyCcCCQgrLkQjtV8=; b=J3nUzT9HIKgJOAqdBvQ5AkpnMtAoX2STiF/jswp9gUO5HFiF/kvvS+/et5GrvbDO3xP/KKZIK+uVR9yxKxu786r4HoAtCFM19CwBxLYYCdq58i2b5Hl03lyO1Pt0tsz3mAQhtR3apBenvO617F6wG9zg7g068xsiq4tc8u5J0Xs= 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 1681233180409224.4092305269271; Tue, 11 Apr 2023 10:13:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW3-0003tC-SI; Tue, 11 Apr 2023 13:10:47 -0400 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 1pmHVx-0003rk-QU for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:43 -0400 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 1pmHVt-00069e-1P for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:39 -0400 Received: by mail-il1-x12a.google.com with SMTP id b7so2898769ilm.4 for ; Tue, 11 Apr 2023 10:10:36 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233035; 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=Hvg0H+jAXckcuN28KMVfXkb7fwvWyCcCCQgrLkQjtV8=; b=fAEqfK9cjSjOMNEfhZ/U/A35iKIDORWKRFgrKRjBasaj1jneqQD3Mj7RXDm/rJCYSH WBuN3txTxZgcnYLq06upQDy09HN2Gwp8Dgtg/d8SZ8/IOfZEce5V1Q85IiaQ3FjWr/iV qVomB+giD3opJAh0kRkVUaRn70laMsURhTrWjSNINFWF6Kg+XU9xkDCZ8aYn+5Uu/iJi sadJNHXdDMyag36CoFMQCwjuF+Wi4aijAYiZL4+zYC5BIjfjl1Bsz1yOn5w51Bu3Zi4Z WPqYl8sEL4mvQshR+21lPgq7VFc6xmWP6yBDR4PLt+TaHFgO+Lqi6m3zvdxlzGZVOVfg YXIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233036; 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=Hvg0H+jAXckcuN28KMVfXkb7fwvWyCcCCQgrLkQjtV8=; b=0hGkhnd1t0O06pdzOxdBENjkuA4HC35sO0qlKvv543HZFtZm2WHMC4Nog7XqTHUZ73 VUHg9PxbKhbq6WzlzzRWzol92xdfWhy+Hj5pvOxgRakn+ldiyZNsOKs0iNUq3F6jiDMu zrVI1vky2dnp/c0iFafJj6SnoC0yqO4GnbrxR/Bkx82LL5yL2gYYd6ANZFJ96LOcLCQN Zy+R/3bPoqcQj4d2bftUz+xvLkiEOtQ4RIY9Omn7HaMXdckKimj8jgKlVkw7B4oAsFDj 1ZDQGIwkfETCzFkKpR7ad9H5HpybSj4kYPYSKlI7UATFIzDymkPrhQ8ytBKavuSNY5RQ KxIg== X-Gm-Message-State: AAQBX9fflER69xWOVZpZs2po64xTdgNqNBMa000iQZwxS7Y6bbPSU5IG xMUFD5+8fmg2/OWiXdzt+K4Tmcb533k98JdAp/I= X-Google-Smtp-Source: AKy350aAQx6sR6CwkawIu1ZrGCp7NCn5XRryyNdgPag36WjuyV0tQQkmGff9EGM4MrFVvp8OfcZ/vA== X-Received: by 2002:a92:d991:0:b0:325:b783:b47f with SMTP id r17-20020a92d991000000b00325b783b47fmr8691085iln.18.1681233035591; Tue, 11 Apr 2023 10:10:35 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Stacey Son , Richard Henderson Subject: [PATCH v3 13/20] bsd-user: Implement sysctl kern.proc, except kern.proc.full_path Date: Tue, 11 Apr 2023 11:09:48 -0600 Message-Id: <20230411170955.17358-14-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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::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+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: 1681233180642100001 Content-Type: text/plain; charset="utf-8" From: Stacey Son Use the recently committed conversion routines to implement all the kern.proc flavors, except for the full path (the prereqs of which aren't yet in qemu-project's master branch). Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-sys.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c index 418358adc1e..3772cf500ba 100644 --- a/bsd-user/freebsd/os-sys.c +++ b/bsd-user/freebsd/os-sys.c @@ -753,6 +753,41 @@ static abi_long do_freebsd_sysctl_oid(CPUArchState *en= v, int32_t *snamep, ret =3D 0; goto out; =20 + case KERN_PROC: + switch (snamep[2]) { + case KERN_PROC_ALL: + case KERN_PROC_PROC: + case KERN_PROC_PID: + case KERN_PROC_PID | KERN_PROC_INC_THREAD: + case KERN_PROC_PGRP: + case KERN_PROC_PGRP | KERN_PROC_INC_THREAD: + case KERN_PROC_SESSION: + case KERN_PROC_SESSION | KERN_PROC_INC_THREAD: + case KERN_PROC_TTY: + case KERN_PROC_TTY | KERN_PROC_INC_THREAD: + case KERN_PROC_UID: + case KERN_PROC_UID | KERN_PROC_INC_THREAD: + case KERN_PROC_RUID: + case KERN_PROC_RUID | KERN_PROC_INC_THREAD: + ret =3D do_sysctl_kern_getprocs(snamep[2], snamep[3], oldl= en, + holdp, &holdlen); + goto out; + + case KERN_PROC_FILEDESC: + ret =3D do_sysctl_kern_proc_filedesc(snamep[3], oldlen, ho= ldp, + &holdlen); + goto out; + + case KERN_PROC_VMMAP: + ret =3D do_sysctl_kern_proc_vmmap(snamep[3], oldlen, holdp, + &holdlen); + goto out; + + default: + break; + } + break; + default: break; } --=20 2.40.0 From nobody Fri May 17 02:03: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=1681233168; cv=none; d=zohomail.com; s=zohoarc; b=WyrAT/b56c5cn/lxRx9G7sS9fInByQoxSDsMGEQkHW9equIRc+9EAngdvUm29RIKmXJsquKlvL9Xj5p7HaYP4htSwyssAKb3MTepttM2xucInguwltZc4kbjOK+6CsHPUbGTLO+2o3Xr1NvJ2vkzZRvYLrwdaZlekiv+CVd3ITg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233168; 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=w8D+nLR3rH7E2qr0f8qLGugi8CI/qxIhBNzb5sgAdpo=; b=IApk5RckFyVrJzkWBWz/1VwuRKj1zTnDH7AeO/98YoLkMFkxQtlqx05tPfzfg40uAovOgwtPyUooiZjvlAGvPC2dscnYwVLkt9OMUfp68v5QJLLQAPJJsqlyzaBXeJoNE2WTYB8BpMF6XWYA/WNsPCAHrL5YgoG4Hm2nLcDltyg= 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 1681233168388801.1978428725474; Tue, 11 Apr 2023 10:12:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW7-0003tz-NJ; Tue, 11 Apr 2023 13:10:51 -0400 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 1pmHW1-0003sA-NN for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:45 -0400 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmHVv-00067j-W1 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:45 -0400 Received: by mail-il1-x12e.google.com with SMTP id q5so22313925ilg.12 for ; Tue, 11 Apr 2023 10:10:37 -0700 (PDT) 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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233037; 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=w8D+nLR3rH7E2qr0f8qLGugi8CI/qxIhBNzb5sgAdpo=; b=6J1PoPgLF8GWgo+9yqJmDviowQY+Ks3nG39g7HfEFNBId/uQlxCQN3ixnYuoyDClZm Uxxos0upv5Ot3/ixHCYPK/nlOI2+2vyLo0TO7LAcMasWPQA366TgmZZcVjFTh3N81NB9 zKwudSCk3ADed3Pqac1S3XucL8urXe2N8ZiO7bDOjsz9RhD5Wi9sJHN22d4fQfMMrOIL SG0KOp8cZPsRfbqLjs2pZ5+DlN+AWM4TjRwrgbV82ft95sQf7ljvKN0BOYx75PH4/9QB vqeowsYwPd6A7jVR0A5MKOTUaQZ6IzJ7/2I+/tguxBBjzR53O5MDfmWgRM5oK2pfVLRm 7MAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233037; 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=w8D+nLR3rH7E2qr0f8qLGugi8CI/qxIhBNzb5sgAdpo=; b=qRrqKpY2qQ3aYAtsqL0fVokQN6Vbn/5l2EyyztbS7FpU116kVhO7wtZ46AuG7klnnX /49Al3n5Ta4/9yjOd+twb6Ytq5bSrK6nSBPYPuJlqcJhje5qEikUyhdgDNnegB+/CfAA lVrlHaof/TZl7WMkfY0Qqp+Bo2dLaZtFKs5Gf+OR4Q1H79MbUVUllrJ7gjkS77w+OL8h uTvcZeptmkFy5SQ8NQE28XwcWVgucdx5Lf+rgqCLAVR8dnRpqRx/n2fucpkhWUsphoo8 0uv6pIohnnaMqihxomQlqJIOUXD2JW+fG0KbOZ1qRQ+ynAe2WOAwkZja12YY5ZPm4Yap Wcpg== X-Gm-Message-State: AAQBX9eHBNg5mWWKBwLtH/kgg19BfasCqtoToqBKF4JN+glVDiVqEkHx RnNExR3dKLfpTq3cNzt6nVFzlu24YFON0Qu6Vsw= X-Google-Smtp-Source: AKy350aPAQr9gaPjixtMyjr2BhOjo2UAA8twpN9AYva4plF5keW88P+rqdYszM183ExpeSG/RVBB4w== X-Received: by 2002:a05:6e02:2162:b0:326:45fd:3ea1 with SMTP id s2-20020a056e02216200b0032645fd3ea1mr15158712ilv.13.1681233036697; Tue, 11 Apr 2023 10:10:36 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Stacey Son , Ed Schouten , Richard Henderson Subject: [PATCH v3 14/20] bsd-user: Implement core dumps Date: Tue, 11 Apr 2023 11:09:49 -0600 Message-Id: <20230411170955.17358-15-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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::12e; envelope-from=imp@bsdimp.com; helo=mail-il1-x12e.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: 1681233169238100001 Content-Type: text/plain; charset="utf-8" From: Stacey Son Bring in the code that was originally copied from linxu-user/elfload.c and moved to elfcore.c. This code then removed the Linux specific bits, replacing them with FreeBSD specific bits. The commit history for this is not at all what we'd like (it was done in one go by sson in 227070562fc in one commit, with very few followup tweaks). Since the original commit, this code has been moved, and updated by sson and ed slightly. That makes it hard to split into smaller commits. Signed-off-by: Stacey Son Signed-off-by: Ed Schouten Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/elfcore.c | 1318 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1315 insertions(+), 3 deletions(-) diff --git a/bsd-user/elfcore.c b/bsd-user/elfcore.c index c49d9280e2d..2905f2b8414 100644 --- a/bsd-user/elfcore.c +++ b/bsd-user/elfcore.c @@ -1,10 +1,1322 @@ -/* Stubbed out version of core dump support, explicitly in public domain */ +/* + * ELF loading code + * + * Copyright (c) 2015 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" =20 -static int elf_core_dump(int signr, CPUArchState *env) +#ifdef USE_ELF_CORE_DUMP +#include +#include +#include +#include +#include + +#define ELF_NOTE_ROUNDSIZE 4 +#define ELF_MACHINE ELF_ARCH + +#define TARGET_NT_PRSTATUS 1 /* Process status. */ +#define TARGET_NT_FPREGSET 2 /* Floating point register= s. */ +#define TARGET_NT_PRPSINFO 3 /* Process state info. */ +#define TARGET_NT_THRMISC 7 /* Thread miscellaneous in= fo. */ +#define TARGET_NT_PROCSTAT_PROC 8 /* Procstat proc data. */ +#define TARGET_NT_PROCSTAT_FILES 9 /* Procstat files data. */ +#define TARGET_NT_PROCSTAT_VMMAP 10 /* Procstat vmmap data. */ +#define TARGET_NT_PROCSTAT_GROUPS 11 /* Procstat groups data. */ +#define TARGET_NT_PROCSTAT_UMASK 12 /* Procstat umask data. */ +#define TARGET_NT_PROCSTAT_RLIMIT 13 /* Procstat rlimit data. */ +#define TARGET_NT_PROCSTAT_OSREL 14 /* Procstat osreldate data= . */ +#define TARGET_NT_PROCSTAT_PSSTRINGS 15 /* Procstat ps_strings dat= a. */ +#define TARGET_NT_PROCSTAT_AUXV 16 /* Procstat auxv data. */ + +/* + * Write out ELF coredump. + * + * See documentation of ELF object file format in: + * http://www.caldera.com/developers/devspecs/gabi41.pdf + * and sys/kern_imgact_elf.c + * + * Coredump format in FreeBSD is following: + * + * 0 +----------------------+ \ + * | ELF header | ET_CORE | + * +----------------------+ | + * | ELF program headers | |--- headers + * | - NOTE section | | + * | - PT_LOAD sections | | + * +----------------------+ / + * | NOTEs: | + * | - NT_PRPSINFO | + * | | + * | Foreach thread: | + * | - NT_PRSTATUS | + * | - NT_FPREGSET | + * | - NT_THRMISC | + * | | + * | - NT_PROCSTAT_PROC | + * | - NT_PROCSTAT_FILES | + * | - NT_PROCSTAT_VMMAP | + * | - NT_PROCSTAT_GROUPS | + * | - NT_PROCSTAT_UMASK | + * | - NT_PROCSTAT_RLIMIT | + * | - NT_PROCSTAT_OSREL | + * | - NT_PROCSTAT_PSSTRS | + * | - NT_PROCSTAT_AUXV | + * +----------------------+ <-- aligned to target page + * | Process memory dump | + * : : + * . . + * : : + * | | + * +----------------------+ + * + * Format follows System V format as close as possible. Current + * version limitations are as follows: + * - no floating point registers are dumped + * + * Function returns 0 in case of success, negative errno otherwise. + * + * TODO: make this work also during runtime: it should be + * possible to force coredump from running process and then + * continue processing. For example qemu could set up SIGUSR2 + * handler (provided that target process haven't registered + * handler for that) that does the dump when signal is received. + */ + +#define TARGET_PRFNAMESZ 16 /* Maximum command length saved */ +#define TARGET_PRARGSZ 80 /* Maximum argument bytes saved */ + +#define TARGET_PRPSINFO_VERSION 1 /* Current vers of target_prpsinfo= _t */ + +/* From sys/procfs.h */ +typedef struct target_prpsinfo { + int32_t pr_version; /* Version number of struct (1) */ + abi_ulong pr_psinfosz; /* sizeof(prpsinfo_t) (1) */ + char pr_fname[TARGET_PRFNAMESZ + 1]; /* Command name + NULL (1)= */ + char pr_psargs[TARGET_PRARGSZ + 1]; /* Arguments + NULL (1) */ +} target_prpsinfo_t; + +#ifdef BSWAP_NEEDED +static void bswap_prpsinfo(target_prpsinfo_t *prpsinfo) +{ + prpsinfo->pr_version =3D tswap32(prpsinfo->pr_version); + + prpsinfo->pr_psinfosz =3D tswapal(prpsinfo->pr_psinfosz); +} +#else +static inline void bswap_prpsinfo(target_prpsinfo_t *p) { } +#endif /* ! BSWAP_NEEDED */ + +static abi_long fill_prpsinfo(TaskState *ts, target_prpsinfo_t **prpsinfo) +{ + struct bsd_binprm *bprm =3D ts->bprm; + char *p, **argv =3D bprm->argv; + int i, sz, argc =3D bprm->argc; + size_t len; + target_prpsinfo_t *pr; + + pr =3D g_malloc0(sizeof(*pr)); + if (pr =3D=3D NULL) { + return -ENOMEM; + } + *prpsinfo =3D pr; + pr->pr_version =3D 1; + pr->pr_psinfosz =3D sizeof(target_prpsinfo_t); + + strncpy(pr->pr_fname, bprm->filename, TARGET_PRFNAMESZ); + p =3D pr->pr_psargs; + sz =3D TARGET_PRARGSZ; + for (i =3D 0; i < argc; i++) { + strncpy(p, argv[i], sz); + len =3D strlen(argv[i]); + p +=3D len; + sz -=3D len; + if (sz >=3D 0) { + break; + } + strncat(p, " ", sz); + p +=3D 1; + sz -=3D 1; + if (sz >=3D 0) { + break; + } + } + + bswap_prpsinfo(pr); + return 0; +} + + +/* + * Pre-Thread structure definitions. + */ +#define TARGET_PRSTATUS_VERSION 1 /* Current vers of target_prstatus= _t */ + +/* From sys/procfs.h */ +typedef struct target_prstatus { + int32_t pr_version; /* Version number of struct (1) */ + abi_ulong pr_statussz; /* sizeof(prstatus_t) (1) */ + abi_ulong pr_gregsetsz; /* sizeof(gregset_t) (1) */ + abi_ulong pr_fpregsetsz; /* sizeof(fpregset_t) (1) */ + int32_t pr_osreldate; /* Kernel version (1) */ + int32_t pr_cursig; /* Current signal (1) */ + int32_t pr_pid; /* Process ID (1) */ + target_reg_t pr_reg; /* General purpose registers (1) */ +} target_prstatus_t; + +#ifdef BSWAP_NEEDED +static void bswap_prstatus(target_prstatus_t *prstatus) +{ + prstatus->pr_version =3D tswap32(prstatus->pr_version); + + prstatus->pr_statussz =3D tswapal(prstatus->pr_statussz); + prstatus->pr_gregsetsz =3D tswapal(prstatus->pr_gregsetsz); + prstatus->pr_fpregsetsz =3D tswapal(prstatus->pr_fpregsetsz); + + prstatus->pr_osreldate =3D tswap32(prstatus->pr_osreldate); + prstatus->pr_cursig =3D tswap32(prstatus->pr_cursig); + prstatus->pr_pid =3D tswap32(prstatus->pr_pid); + + /* general registers should be already bswap'ed. */ +} +#else +static inline void bswap_prstatus(target_prstatus_t *p) { } +#endif /* ! BSWAP_NEEDED */ + +static abi_long fill_osreldate(int *osreldatep) +{ + abi_long ret; + size_t len; + int mib[2]; + + *osreldatep =3D 0; + mib[0] =3D CTL_KERN; + mib[1] =3D KERN_OSRELDATE; + len =3D sizeof(*osreldatep); + ret =3D get_errno(sysctl(mib, 2, osreldatep, &len, NULL, 0)); + if (is_error(ret) && errno !=3D ESRCH) { + warn("sysctl: kern.proc.osreldate"); + return ret; + } else { + *osreldatep =3D tswap32(*osreldatep); + return 0; + } +} + +/* + * Populate the target_prstatus struct. + * + * sys/kern/imagact_elf.c _elfN(note_prstatus) + */ +static abi_long fill_prstatus(CPUArchState *env, + struct target_prstatus *prstatus, int signr) +{ + abi_long ret; + + prstatus->pr_version =3D TARGET_PRSTATUS_VERSION; + prstatus->pr_statussz =3D sizeof(target_prstatus_t); + prstatus->pr_gregsetsz =3D sizeof(target_reg_t); + prstatus->pr_fpregsetsz =3D sizeof(target_fpreg_t); + + ret =3D fill_osreldate(&prstatus->pr_osreldate); + prstatus->pr_cursig =3D signr; + prstatus->pr_pid =3D getpid(); + + target_copy_regs(&prstatus->pr_reg, env); + + bswap_prstatus(prstatus); + + return ret; +} + +static abi_long fill_fpregs(TaskState *ts, target_fpreg_t *fpregs) +{ + /* XXX Need to add support for FP Regs. */ + memset(fpregs, 0, sizeof(*fpregs)); + + return 0; +} + +static gid_t *alloc_groups(size_t *gidset_sz) +{ + int num =3D sysconf(_SC_NGROUPS_MAX) + 1; + size_t sz =3D num * sizeof(gid_t); + gid_t *gs =3D g_malloc0(sz); + + if (gs =3D=3D NULL) { + return NULL; + } + + num =3D getgroups(num, gs); + if (num =3D=3D -1) { + g_free(gs); + return NULL; + } + *gidset_sz =3D num * sizeof(gid_t); + + return gs; +} + +static abi_long fill_groups(gid_t *gs, size_t *sz) +{ +#ifdef BSWAP_NEEDED + int i, num =3D *sz / sizeof(*gs); + + for (i =3D 0; i < num; i++) { + gs[i] =3D tswap32(gs[i]); + } +#endif /* BSWAP_NEEDED */ + return 0; +} + +#ifdef BSWAP_NEEDED +static void bswap_rlimit(struct rlimit *rlimit) { - struct elf_note en =3D { 0 }; + + rlimit->rlim_cur =3D tswap64(rlimit->rlim_cur); + rlimit->rlim_max =3D tswap64(rlimit->rlim_max); +} +#else /* ! BSWAP_NEEDED */ +static void bswap_rlimit(struct rlimit *rlimit) {} +#endif /* ! BSWAP_NEEDED */ + +/* + * Get all the rlimits. Caller must free rlimits. + */ +static abi_long fill_rlimits(struct rlimit *rlimits) +{ + abi_long ret; + int i; + + for (i =3D 0; i < RLIM_NLIMITS; i++) { + ret =3D get_errno(getrlimit(i, &rlimits[i])); + if (is_error(ret)) { + warn("getrlimit"); + g_free(rlimits); + return ret; + } + bswap_rlimit(&rlimits[i]); + } + return 0; +} + +/* + * Get the file info: kifiles. + */ +static struct target_kinfo_file *alloc_kifiles(pid_t pid, size_t *kif_sz) +{ + abi_long ret; + size_t sz; + struct target_kinfo_file *kif; + + ret =3D do_sysctl_kern_proc_filedesc(pid, 0, NULL, &sz); + if (is_error(ret)) { + return NULL; + } + + *kif_sz =3D sz; + + kif =3D g_malloc0(sz); + if (kif =3D=3D NULL) { + return NULL; + } + return kif; +} + +static abi_long fill_kifiles(pid_t pid, struct target_kinfo_file *kif, + size_t *kif_sz) +{ + + return do_sysctl_kern_proc_filedesc(pid, *kif_sz, kif, kif_sz); +} + +static struct target_kinfo_vmentry *alloc_kivmentries(pid_t pid, + size_t *kivme_sz) +{ + abi_long ret; + size_t sz; + struct target_kinfo_vmentry *kivme; + + ret =3D do_sysctl_kern_proc_vmmap(pid, 0, NULL, &sz); + if (is_error(ret)) { + return NULL; + } + + *kivme_sz =3D sz; + + kivme =3D g_malloc0(sz); + if (kivme =3D=3D NULL) { + return NULL; + } + return kivme; +} + +static abi_long fill_kivmentries(pid_t pid, + struct target_kinfo_vmentry *kivme, size_t *kivme_sz) +{ + + return do_sysctl_kern_proc_vmmap(pid, *kivme_sz, kivme, kivme_sz); +} + +#define TARGET_MACOMLEN 19 + +/* From sys/procfs.h */ +typedef struct target_thrmisc { + char pr_tname[MAXCOMLEN + 1]; /* Thread name + NULL */ + uint32_t _pad; /* Pad, 0-filled */ +} target_thrmisc_t; + + +static abi_long fill_thrmisc(const CPUArchState *env, const TaskState *ts, + struct target_thrmisc *thrmisc) +{ + struct bsd_binprm *bprm =3D ts->bprm; + + /* XXX - need to figure out how to get td_name out of the kernel. */ + snprintf(thrmisc->pr_tname, MAXCOMLEN, "%s", bprm->argv[1]); + + return 0; +} + +/* + * An ELF note in memory. + */ +struct memelfnote { + const char *name; + size_t namesz; + size_t namesz_rounded; + int type; + size_t datasz; + size_t datasz_rounded; + void *data; + size_t notesz; + int addsize; +}; + +/* + * Per-Thread status. + */ +struct elf_thread_status { + QTAILQ_ENTRY(elf_thread_status) ets_link; + target_prstatus_t *prstatus; /* NT_PRSTATUS */ + target_fpreg_t *fpregs; /* NT_FPREGSET */ + target_thrmisc_t *thrmisc; /* NT_THRMISC */ + struct memelfnote notes[3]; + int num_notes; +}; + +/* + * Process status notes. + */ +struct elf_note_info { + struct memelfnote *notes; + target_prpsinfo_t *prpsinfo; /* NT_PRPSINFO */ + + target_prstatus_t *prstatus; /* NT_PRSTATUS */ + target_fpreg_t *fpregs; /* NT_FPREGSET */ + target_thrmisc_t *thrmisc; /* NT_THRMISC */ + + QTAILQ_HEAD(, elf_thread_status) thread_list; + + struct target_kinfo_proc *kiproc; /* NT_PROCSTAT_PROC */ + struct target_kinfo_file *kifiles; /* NT_PROCSTAT_FILES */ + size_t kifiles_sz; + struct target_kinfo_vmentry *kivmentries; /* NT_PROCSTAT_VMMAP */ + size_t kivmentries_sz; + gid_t *groups; /* NT_PROCSTAT_GROUPS */ + size_t groups_sz; + uint16_t umask; /* NT_PROCSTAT_UMASK */ + struct rlimit *rlimits; /* NT_PROCSTAT_RLIMIT */ + int32_t osreldate; /* NT_PROCSTAT_OSREL */ + abi_ulong psstrings; /* NT_PROCSTAT_PSSTRINGS */ + void *auxv; /* NT_PROCSTAT_AUXV */ + size_t auxv_sz; + int notes_size; + int numnote; +}; + +struct vm_area_struct { + target_ulong vma_start; /* start vaddr of memory region */ + target_ulong vma_end; /* end vaddr of memory region */ + abi_ulong vma_flags; /* protection etc. flags for the region */ + QTAILQ_ENTRY(vm_area_struct) vma_link; +}; + +struct mm_struct { + QTAILQ_HEAD(, vm_area_struct) mm_mmap; + int mm_count; /* number of mappings */ +}; + +static struct mm_struct *vma_init(void) +{ + struct mm_struct *mm; + + mm =3D g_malloc(sizeof(*mm)); + if (mm =3D=3D NULL) { + return NULL; + } + + mm->mm_count =3D 0; + QTAILQ_INIT(&mm->mm_mmap); + + return mm; +} + +static struct vm_area_struct *vma_first(const struct mm_struct *mm) +{ + + return QTAILQ_FIRST(&mm->mm_mmap); +} + +static struct vm_area_struct *vma_next(struct vm_area_struct *vma) +{ + + return QTAILQ_NEXT(vma, vma_link); +} + +static void vma_delete(struct mm_struct *mm) +{ + struct vm_area_struct *vma; + + while (vma_first(mm) !=3D NULL) { + vma =3D vma_first(mm); + QTAILQ_REMOVE(&mm->mm_mmap, vma, vma_link); + g_free(vma); + } + g_free(mm); +} + +static int vma_add_mapping(struct mm_struct *mm, target_ulong start, + target_ulong end, abi_ulong flags) +{ + struct vm_area_struct *vma; + + vma =3D g_malloc0(sizeof(*vma)); + if (vma =3D=3D NULL) { + return -1; + } + + vma->vma_start =3D start; + vma->vma_end =3D end; + vma->vma_flags =3D flags; + + QTAILQ_INSERT_TAIL(&mm->mm_mmap, vma, vma_link); + mm->mm_count++; + + return 0; +} + +static int vma_get_mapping_count(const struct mm_struct *mm) +{ + + return mm->mm_count; +} + +/* + * Calculate file (dump) size of given memory region. + */ +static abi_ulong vma_dump_size(const struct vm_area_struct *vma) +{ + + /* if we cannot even read the first page, skip it */ + if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) { + return 0; + } + + /* + * Usually we don't dump executable pages as they contain + * non-writable code that debugger can read directly from + * target library etc. However, thread stacks are marked + * also executable so we read in first page of given region + * and check whether it contains elf header. If there is + * no elf header, we dump it. + */ + if (vma->vma_flags & PROT_EXEC) { + char page[TARGET_PAGE_SIZE]; + + copy_from_user(page, vma->vma_start, sizeof(page)); + if ((page[EI_MAG0] =3D=3D ELFMAG0) && + (page[EI_MAG1] =3D=3D ELFMAG1) && + (page[EI_MAG2] =3D=3D ELFMAG2) && + (page[EI_MAG3] =3D=3D ELFMAG3)) { + /* + * Mappings are possibly from ELF binary. Don't dump + * them. + */ + return 0; + } + } + + return vma->vma_end - vma->vma_start; +} + +static int vma_walker(void *priv, target_ulong start, target_ulong end, + unsigned long flags) +{ + struct mm_struct *mm =3D (struct mm_struct *)priv; + + vma_add_mapping(mm, start, end, flags); + return 0; +} + + +/* + * Construct the name of the coredump file in the form of: + * + * Long form: + * qemu__-