From patchwork Wed Apr 5 21:35:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=pPjsESZj; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHz74Vt6z1yZm for ; Thu, 6 Apr 2023 07:37:22 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAnz-0005IW-JE; Wed, 05 Apr 2023 17:36: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 1pkAnw-0005HY-IL for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:32 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnt-0005a5-GS for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:32 -0400 Received: by mail-il1-x130.google.com with SMTP id t5so8184573ilu.5 for ; Wed, 05 Apr 2023 14:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730587; 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=2DM3wKZtPkr/t8eKmexvlOqylubu6rNGh4+x7s6epeI=; b=pPjsESZjn62wv+C4Rz188U1i9yFRYYpzEtX9xlIfYy7tBi44HU8yO83UxTXs6B5dnS CH4HkSaDx0vm6Opo2lZEfhS3qEC5VttA/fEhcgnKrRTVcwqudXTM2DBy7fAmyBaVIe0R ou3PySby6jaVP42O464j8JVSCfLE0XTH6f3qEpLYXcufdCpuhBeW8zlldcQhV4ApXEew ur5pTbwVLwUynBxgAjspQve1ElnkE6mV1Cti2jAq5z1j+mCxZn1pfgzR0L6IzOiRAyru zqdpoU9x8FhFBKKnbCqaXjkxkUsgwBEed41GXYFD1lsFPuFR4TZkJ3zPZnio0WLEF6Rl XxiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730587; 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=2DM3wKZtPkr/t8eKmexvlOqylubu6rNGh4+x7s6epeI=; b=CPYQI0knAx9GsFIALeEFJl41x3KmzP8tJKqQ5JYSWVPDqdSZxNf6umXmBPz8M8UsSA vBM0EWu1FJ0+dNLw7BwmMJwWEwit0K/J046od0pE/01s6WUslqTTwYPNK23kbUOwerOc H2TltoWHGrBxS0g8XAjY1yaKPfyYn2SiFwFnNetuC+w6YKoPxc9stsC1fzJYREgrUmOe EpWwyK8AJjCaderEa+dL8UNzEMUoBJz7/FtCl0Om73dzLvD1Y4RKTa6I0tZTK+FOkitg 90we15ktThK/f51KgdyWuHH/+0fqtfjLO5Uq30Q0/32nm5f61IABFQXbK9co76YEIs8k d5SA== X-Gm-Message-State: AAQBX9eUSZfbmObn65UbOxFc/F+qlrOUmAulFgNzqBoc8v0yUfAmB3x9 ATd8ypcQ/7qr+rjUF0b6cYuBexHLljtsb8dA22I= X-Google-Smtp-Source: AKy350ZF1HWvHI82e9O5d2l+PwKKtFua+xLrUwdQ0M0dy2CjlvTfbFZ/WAE8vJIno4cuqkRbvXxZ4w== X-Received: by 2002:a92:cc82:0:b0:31f:ba63:382 with SMTP id x2-20020a92cc82000000b0031fba630382mr4671292ilo.30.1680730587398; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:27 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 01/16] bsd-user: Make print_* public Date: Wed, 5 Apr 2023 15:35:57 -0600 Message-Id: <20230405213612.15942-2-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); } -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); } -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 arg6) { 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})"); } -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 arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) { /* 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); } -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 arg6) { /* 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 *name, abi_long arg1, * Variants for the return value output function */ -static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret) +void print_syscall_ret_addr(const struct syscallname *name, abi_long ret) { if (ret == -1) { gemu_log(" = -1 errno=%d (%s)\n", errno, strerror(errno)); @@ -159,9 +156,9 @@ static const struct syscallname openbsd_scnames[] = { #include "openbsd/strace.list" }; -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 arg6) { unsigned int i; const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," @@ -190,8 +187,8 @@ static void print_syscall(int num, const struct syscallname *scnames, gemu_log("Unknown syscall %d\n", num); } -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 *scnames, + unsigned int nscnames) { unsigned int i; From patchwork Wed Apr 5 21:35:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=jecIIYpi; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHzM4W0Kz1yYs for ; Thu, 6 Apr 2023 07:37:35 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAny-0005Hl-6L; Wed, 05 Apr 2023 17:36: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 1pkAnv-0005HI-6C for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:31 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnt-0005aC-Jb for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:30 -0400 Received: by mail-il1-x135.google.com with SMTP id r19so8262708ilj.6 for ; Wed, 05 Apr 2023 14:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730588; 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=VTc0CkhboZdbdLS1nawm6MDD/m9xKS8bqWOZ/27lhR4=; b=jecIIYpiDVCco47YeSYCyhHB4oAgWQJiJliOoxBeizLCn1mFvtIFnk477nrn/gF1gy 6+kB/+4XoShVvF1aZgo37AvsS8axg9RWIilBw6NrnjvpERkdw+vZVDkL6d1ASp9V/yiZ mMxSRAW+vbx/UcSxFOZkm+lFXMyeUbP9mSk/Q/K0QU4yu5iaBoBzJ81R9mrJAkAgU4BY hALovkndEDhUTtBnr0XW7ixFhTxY79GwhTVHdXO4JD6ZF+dJyH082QC2CrbzMeFNdzvP /DSz3PPSK0IBqib6AEif3+zFiZtGF0tYVQrQwWJ2CNtd91+GaXe8wGFhsajDCd7pWkvh RYzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730588; 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=VTc0CkhboZdbdLS1nawm6MDD/m9xKS8bqWOZ/27lhR4=; b=sbZMVp7SvPwJijY2nNFMVEb/sUR051eITCAvyBVPFkY3+1WaCyhvcb5Kx6MArXBwdp ANYAKIT8hqQD12IS3082RvUXWD6tIr/8u/NWa0qebM8SoPnCNBu4Hd3vJYgJwhJjt2x+ cYajyaKnS0c90dKtNA59ILC50KOZa69XLADEo/QKDDJWp35W3WApI/ZnuNfwGLK9/tSJ G+8hzMCut8o1bNaKWQ6USaFL1dYEul/ThUXduAHqId+mUzUAoh2P6u+umNNYfLRXuS7l SBfcP3pwYYjLgp5Jew9/hlus0vS75L+XqcLB2IafdwuDw3Hbeyd5HfDmxNxISKduLZX8 JQSQ== X-Gm-Message-State: AAQBX9e5nh2QltdymuZJAEpqvTV/H4ihpD8iBrQgYTmoNrTqIEIbIgmS KpA9LaPHbKIhA/twF9cKZMeXx1twU8AImUQqgeQ= X-Google-Smtp-Source: AKy350ar8vgsWVXwTZH+tPsynguOOvjNWulAFgRE2qXedLTMVp4jLEn8rAT+tYzUKBf+IKlVt8ux7Q== X-Received: by 2002:a92:dc90:0:b0:325:e0f6:a5a4 with SMTP id c16-20020a92dc90000000b00325e0f6a5a4mr5793266iln.13.1680730588257; Wed, 05 Apr 2023 14:36:28 -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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:27 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 02/16] bsd-user: Ifdef a few MAP_ constants for NetBSD Date: Wed, 5 Apr 2023 15:35:58 -0600 Message-Id: <20230405213612.15942-3-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::135; envelope-from=imp@bsdimp.com; helo=mail-il1-x135.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Add back the ifdefs that I removed in 36d5d891559f (but only these ifdefs, the rest of the commit is not reverted). Signed-off-by: Warner Losh --- bsd-user/mmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index d6c5a344c9b..f732a6f6f2b 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -416,27 +416,33 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, qemu_log("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); } +#ifdef MAP_GUARD if (flags & MAP_GUARD) { qemu_log("MAP_GUARD "); } +#endif if (flags & MAP_FIXED) { qemu_log("MAP_FIXED "); } if (flags & MAP_ANON) { qemu_log("MAP_ANON "); } +#ifdef MAP_EXCL if (flags & MAP_EXCL) { qemu_log("MAP_EXCL "); } +#endif if (flags & MAP_PRIVATE) { qemu_log("MAP_PRIVATE "); } if (flags & MAP_SHARED) { qemu_log("MAP_SHARED "); } +#ifdef MAP_NOCORE if (flags & MAP_NOCORE) { qemu_log("MAP_NOCORE "); } +#endif if (flags & MAP_STACK) { qemu_log("MAP_STACK "); } @@ -454,6 +460,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, goto fail; } } +#ifdef MAP_GUARD if ((flags & MAP_GUARD) && (prot != PROT_NONE || fd != -1 || offset != 0 || (flags & (MAP_SHARED | MAP_PRIVATE | /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */ @@ -461,6 +468,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, errno = EINVAL; goto fail; } +#endif if (offset & ~TARGET_PAGE_MASK) { errno = EINVAL; @@ -608,11 +616,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, goto the_end; } +#ifdef MAP_EXCL /* Reject the mapping if any page within the range is mapped */ if ((flags & MAP_EXCL) && page_check_range(start, len, 0) < 0) { errno = EINVAL; goto fail; } +#endif /* handle the start of the mapping */ if (start > real_start) { From patchwork Wed Apr 5 21:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=JW9gyOIT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHzB6rlbz1yYs for ; Thu, 6 Apr 2023 07:37:26 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoF-0005OH-T3; Wed, 05 Apr 2023 17:36: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 1pkAnw-0005Hn-WD for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:34 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnu-0005aG-GD for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:32 -0400 Received: by mail-il1-x129.google.com with SMTP id n1so18792364ili.10 for ; Wed, 05 Apr 2023 14:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730589; 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=fdI4FOHX2F3suDBHi4XUkEMxaX1KjSb9ZI97Vo0+ATM=; b=JW9gyOITO/oP91IUVq7Cebd9akgIO7eyLFUDb8doRmA7OOczMD2qyGtF+L/45JqDBt I7+1YyMrHEoVt3MU29k4rX5OKMa6gTCBAsGXdbmRMgVIE+55BbN/yT75WrZP63FK/yZg zYkk6heAh3UgrkPM2yUePg8I/RFcOjE5XprwhUMS8rAq0A9KWGuCb8pMgVi49FZvYTwZ jz0cuRbibwlsjSa2ml3oT6oIsYjxwXmRsx32zLB61ZED/r45tR6P5p+08ZG9gSJofBLF bWYPSQcxcmlIrqCaBVSflKH0ivpD7xjBF9x/v1sb1TaLkJWwzfelGUu0RQBrj5DWMZyF 84hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730589; 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=fdI4FOHX2F3suDBHi4XUkEMxaX1KjSb9ZI97Vo0+ATM=; b=g3gKpRJAd/vIS16+40CZtTWXMiEULwCoSzyCP0E5zbAmrPvrXJwjLfURaQjsX8xJhd 2K4etUnGQDwmCKkXVZfTZI6/iyt+rpOLpv6mYieYf46wmH19OKBQjxoKX28E9G3HEcCU eGS4u+1t8OEEz62yDuLnJOctKZkIjHyBewBzFr1Vntz77O/xAYt9bsVCkj0lwp6yoStS AVRdpzoetSsBKLq2dVv1HTi3WS2XZ0HzT+eodQvzckwSq0PiC5gRfvXki4A4Uig+T5uH 4C6goRIlLd2tY2MS4JkuIHsaaAy6YYTmGjVtksuZ0taZHVa0jSYasyJPOv62Kqo8QRef Ypiw== X-Gm-Message-State: AAQBX9cn+Y10i/NAwrVPmW2iPReyrNnqK1qNO2EkK+zwbDas1FLLVPY7 ZVzYYFHQFAPZGPj4Xspq/EB/D2Qo2eOSuQBOjXM= X-Google-Smtp-Source: AKy350aXJVuRa3FLtDpjs+2+8Tbo4gW/XduyGpoG/PMv2J7Q1Ety9z7srrOREH1uM2M1IPLAqqLKJA== X-Received: by 2002:a05:6e02:2162:b0:326:45fd:3ea1 with SMTP id s2-20020a056e02216200b0032645fd3ea1mr3035715ilv.13.1680730589036; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:28 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 03/16] bsd-user: Cleanup style. Date: Wed, 5 Apr 2023 15:35:59 -0600 Message-Id: <20230405213612.15942-4-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 f732a6f6f2b..5f60efb3c5d 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -45,17 +45,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); } void mmap_fork_end(int child) { - if (child) + if (child) { pthread_mutex_init(&mmap_mutex, NULL); - else + } else { pthread_mutex_unlock(&mmap_mutex); + } } /* NOTE: all the constants are the HOST ones, but addresses are target. */ @@ -69,15 +71,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) != 0) + if ((start & ~TARGET_PAGE_MASK) != 0) { return -EINVAL; + } len = TARGET_PAGE_ALIGN(len); end = start + len; - if (end < start) + if (end < start) { return -EINVAL; + } prot &= PROT_READ | PROT_WRITE | PROT_EXEC; - if (len == 0) + if (len == 0) { return 0; + } mmap_lock(); host_start = start & qemu_host_page_mask; @@ -96,8 +101,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) } ret = mprotect(g2h_untagged(host_start), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret != 0) + if (ret != 0) { goto error; + } host_start += qemu_host_page_size; } if (end < host_end) { @@ -107,16 +113,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) } ret = mprotect(g2h_untagged(host_end - qemu_host_page_size), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret != 0) + if (ret != 0) { goto error; + } host_end -= qemu_host_page_size; } /* handle the pages in the middle */ if (host_start < host_end) { ret = mprotect(g2h_untagged(host_start), host_end - host_start, prot); - if (ret != 0) + if (ret != 0) { goto error; + } } page_set_flags(start, start + len, prot | PAGE_VALID); mmap_unlock(); @@ -161,31 +169,37 @@ static int mmap_frag(abi_ulong real_start, /* get the protection of the target pages outside the mapping */ prot1 = 0; for (addr = real_start; addr < real_end; addr++) { - if (addr < start || addr >= end) + if (addr < start || addr >= end) { prot1 |= page_get_flags(addr); + } } if (prot1 == 0) { /* no page was there, so we allocate one. See also above. */ void *p = mmap(host_start, qemu_host_page_size, prot, flags | ((fd != -1) ? MAP_ANON : 0), -1, 0); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { return -1; + } prot1 = prot; } prot1 &= PAGE_BITS; prot_new = prot | prot1; if (fd != -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) == MAP_SHARED && - (prot & PROT_WRITE)) + (prot & PROT_WRITE)) { return -1; + } /* 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); + } /* read the corresponding file data */ if (pread(fd, g2h_untagged(start), end - start, offset) == -1) { @@ -193,8 +207,9 @@ static int mmap_frag(abi_ulong real_start, } /* put final protection */ - if (prot_new != (prot1 | PROT_WRITE)) + if (prot_new != (prot1 | PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot_new); + } } else { if (prot_new != prot1) { mprotect(host_start, qemu_host_page_size, prot_new); @@ -554,8 +569,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, */ p = mmap(g2h_untagged(start), host_len, prot, flags | MAP_FIXED | ((fd != -1) ? MAP_ANON : 0), -1, 0); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { goto fail; + } /* update start so that it points to the file position at 'offset' */ host_start = (unsigned long)p; if (fd != -1) { @@ -604,8 +620,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, retaddr = target_mmap(start, len, prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); - if (retaddr == -1) + if (retaddr == -1) { goto fail; + } if (pread(fd, g2h_untagged(start), len, offset) == -1) { goto fail; } @@ -630,14 +647,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, /* one single host page */ ret = mmap_frag(real_start, start, end, prot, flags, fd, offset); - if (ret == -1) + if (ret == -1) { goto fail; + } goto the_end1; } ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, prot, flags, fd, offset); - if (ret == -1) + if (ret == -1) { goto fail; + } real_start += qemu_host_page_size; } /* handle the end of the mapping */ @@ -646,8 +665,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, real_end - qemu_host_page_size, end, prot, flags, fd, offset + real_end - qemu_host_page_size - start); - if (ret == -1) + if (ret == -1) { goto fail; + } real_end -= qemu_host_page_size; } @@ -655,14 +675,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 = 0; - else + } else { offset1 = offset + real_start - start; + } p = mmap(g2h_untagged(real_start), real_end - real_start, prot, flags, fd, offset1); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { goto fail; + } } } the_end1: @@ -732,11 +754,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 = TARGET_PAGE_ALIGN(len); - if (len == 0) + if (len == 0) { return -EINVAL; + } mmap_lock(); end = start + len; real_start = start & qemu_host_page_mask; @@ -754,16 +778,18 @@ int target_munmap(abi_ulong start, abi_ulong len) } end = real_end; } - if (prot != 0) + if (prot != 0) { real_start += qemu_host_page_size; + } } if (end < real_end) { prot = 0; for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } - if (prot != 0) + if (prot != 0) { real_end -= qemu_host_page_size; + } } ret = 0; @@ -787,14 +813,17 @@ int target_msync(abi_ulong start, abi_ulong len, int flags) { abi_ulong end; - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len = TARGET_PAGE_ALIGN(len); end = start + len; - if (end < start) + if (end < start) { return -EINVAL; - if (end == start) + } + if (end == start) { return 0; + } start &= qemu_host_page_mask; return msync(g2h_untagged(start), end - start, flags); From patchwork Wed Apr 5 21:36:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=Hu3iTcR0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHz74Qk8z1yYs for ; Thu, 6 Apr 2023 07:37:22 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAnz-0005IV-Gx; Wed, 05 Apr 2023 17:36: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 1pkAnx-0005Ho-30 for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:34 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnv-0005aP-Ev for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:32 -0400 Received: by mail-il1-x135.google.com with SMTP id h14so18153701ilj.0 for ; Wed, 05 Apr 2023 14:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730590; 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=AhXur0mol2eJRCuT8H9O7gNE5+OMCeuHhvCsZFIq5AU=; b=Hu3iTcR0bmj5FTe+D3yBkxQHhjT6G0r33E3HzDRpgvXSl7QAYQPsJIySwcyjATIKWZ zD1dsnxRGfCgxwXweBpmGObiSItcFVHxZTS6tBtvuQD2QjZyzgvYYc+j5fuhhlkVuGA9 75v76qiHEqF9tVozIhH1GsfDKKopCAYpGSXJfBHcIU+GIcVKlf1ZSudjF8Czjo5JzCyx mvO+fQV0V6u4kOfnr0L9vRXjEma1MbOPk/yZlwLStV1yDVVfeovUaqSR20vIy17ZNqo8 gNY1kmMY052nxrhntI4NavsREugm7sbIoBXD+xG7vw0CO9hXacjGTpBbjS5ci+y0tL8y keng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730590; 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=AhXur0mol2eJRCuT8H9O7gNE5+OMCeuHhvCsZFIq5AU=; b=BvX4xd9TMPKcLWaPElTfj7DL5OU8igtsYFMHhoPutCWYciS3nkcYeUzfBFUtSnOWpP /6KDG8xyrE7zvEIYf1UtdF60htdQe5fnIMBGKuLLYiUywwOZq5lRo/pjjm6kyWZmJS9t FE9VteQjKL9AMBO/sdLVQcbt3gedS88wOGZ7tHz0QiuKj0VUPp/jC3gCNZOPMu8di3z9 E8r6Zgf7MXhvrVw5VC2lg9DWAQigA+baSwjSZ1rYqZFW9G4udo+ZBj1JINRtDkn7PD1T Ukqk1kJMqD0yX5QQMFo9/H2+JxWMQ01Rm5BMYr2eIx2QddhB84jg63N4Ggk6M86mt3oZ phqw== X-Gm-Message-State: AAQBX9dnCPUzGctBgkvRKlQgfYbhs9MjA4ASDNARrENvJq5OlhI7X2Fm m2/SqhtHpU45Ifp52syGudTpikc+svuRRRDlVoc= X-Google-Smtp-Source: AKy350ZUFAXgFwqZbkFWPXtZMovi1xYv9yaAP0EJQow5fpCn9n2QgZ8i0brSvnyV1eZuOrOQUTXiDA== X-Received: by 2002:a92:d38f:0:b0:315:420e:a77b with SMTP id o15-20020a92d38f000000b00315420ea77bmr2658964ilo.10.1680730589887; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:29 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 04/16] bsd-user: Move system FreeBSD call table to freebsd/os-syscall.c Date: Wed, 5 Apr 2023 15:36:00 -0600 Message-Id: <20230405213612.15942-5-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::135; envelope-from=imp@bsdimp.com; helo=mail-il1-x135.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; } +static const struct syscallname freebsd_scnames[] = { +#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 arg5, + 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_scnames)); +} + /* * 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); }; -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 *name, abi_long ret) * An array of all of the syscalls we know about */ -static const struct syscallname freebsd_scnames[] = { -#include "freebsd/strace.list" -}; static const struct syscallname netbsd_scnames[] = { #include "netbsd/strace.list" }; @@ -212,20 +209,6 @@ void print_syscall_ret(int num, abi_long ret, const struct 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_scnames)); -} - void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) { From patchwork Wed Apr 5 21:36:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=nRGU74Kq; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHzs2C41z1yYs for ; Thu, 6 Apr 2023 07:38:01 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAo7-0005JR-SD; Wed, 05 Apr 2023 17:36:44 -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 1pkAnx-0005Hs-Gt for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:34 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnv-0005af-V8 for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:33 -0400 Received: by mail-il1-x12d.google.com with SMTP id n1so18792419ili.10 for ; Wed, 05 Apr 2023 14:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730591; 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=1BJY2q4N9OTbwCSs0lpKm2HeXuDh951JsDQY9hlEtgM=; b=nRGU74Kq2K72WplUgDfkKvK6qcCcdu0fcCpvRASMGoNz7ANU/WbY+wluJIQ705l1Aa S6Dq4NVioyKBA+6Bg8pv2OkRqPw8GBWE6z+ZHq3CiX0m2OtlsGKh+H8WTZShz5EDM10t 4+1QLN+3T1XQ5tPhqL76xbsmf4oVJXKZIKzG21orAezJnT2An61GFw6k+KBBw3p9zScx mD18ZkmsV9yoQ0ypxTNYiEZbkFB0XulmvD6qe3bEc3JsxV1Le01PpVPAr/nLqF4SThdC dfwXoWIPSjdPDReuTZCa/IB38ktfM34eOUJGYHpiQAFDwKGTy3ifHT044q4wenpc/6N+ BjGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730591; 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=1BJY2q4N9OTbwCSs0lpKm2HeXuDh951JsDQY9hlEtgM=; b=mmbQdbXJIcllULWdA87214ToVwgcFF0csFfR8/+KHqCa517bKH75wxw4G5sIIr+j0u wL5QRTvCkbIYZWdhQa1TIAhLqancHCzUgjS9d2D0cKyp3Q+bmadUHqXa1MaFkZPwhQrG ajWbru9G7talNS0WqsBxRYmH9bEvZpl/h6JP2ahiJnE3D1kjbshdyCrUrp+yAKWq1E4+ UgmdOPu5HVJrrjC2wWQU5WCQ1rao29fvutUtH2sxpBneAAeyl+bPbw5P1CFiFPzU1/0y t6UDLrVYL2hf8jRDJQ8y6FmzLWe8xbJJD8n4E4cDMUOiShS11WetZkTgqY/2iJX5dgL/ Sy5Q== X-Gm-Message-State: AAQBX9dxS9zc7f191tBoqa7BAuZerq53TEaZgkETj4QgYxzQZ+TO963S qp7qcyTjNICZlHKgKuz8HHWs26NYAbV+eN2O/+Q= X-Google-Smtp-Source: AKy350ZdnEvDGSzOs7CiJ1Z1UxYrXp/W9H+v2b9OZcFXtzaTK63plkfBF47xDqEoWlou8qHJL3axOg== X-Received: by 2002:a92:cc02:0:b0:326:54d0:38b3 with SMTP id s2-20020a92cc02000000b0032654d038b3mr4672471ilp.16.1680730590726; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:30 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 05/16] bsd-user: Remove NetBSD specific syscall printing Date: Wed, 5 Apr 2023 15:36:01 -0600 Message-Id: <20230405213612.15942-6-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); }; -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 *name, abi_long ret) * An array of all of the syscalls we know about */ -static const struct syscallname netbsd_scnames[] = { -#include "netbsd/strace.list" -}; static const struct syscallname openbsd_scnames[] = { #include "openbsd/strace.list" }; @@ -209,20 +206,6 @@ void print_syscall_ret(int num, abi_long ret, const struct 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) { From patchwork Wed Apr 5 21:36:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=5HkGm7HF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ086mZjz1yZm for ; Thu, 6 Apr 2023 07:38:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAo7-0005JL-NS; Wed, 05 Apr 2023 17:36:43 -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 1pkAnz-0005IT-CS for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:35 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnx-0005ao-Ak for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:34 -0400 Received: by mail-il1-x129.google.com with SMTP id h14so18153742ilj.0 for ; Wed, 05 Apr 2023 14:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730592; 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+1pyA/IVH1HKwHyEkUgzX0roAnFA4GI59mdl6vS7Qs=; b=5HkGm7HFce6bnqwIvZSyNrcVVEycKyXqg53FvIFQsOk43ZOWIuizOGAS23aSdq6Zb6 sTryFsS4c2h1YO5S7acU3WibB2IsqCF98HM+9qUncNUxCi05xk2vopoiY3qF41PCRt0x rL6thIKub290LOVAtVaLPbnGk2MUoOo7vyv1+1HLkTkAVO1y3zNz5tV5NwaUYrrtJ4PH Np0JL+ShUXKPyU4vxgbHbvAFzLQadxYAUjWqwGw/iuK3cYJ3/3XzvBcA4EvYeA3rICiK az5KUIZtlu2UhblPvFFmHYyXsbGBwuWHmvgWIQxOWW6dSNOvIGelkKKJ5Ql0XIgyMMu/ 8m2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730592; 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+1pyA/IVH1HKwHyEkUgzX0roAnFA4GI59mdl6vS7Qs=; b=mRJldW2bms4cwJDWCWmqzY1IhXFOKb47Danj9nidPYI4zUhw41mJLSSVm2PTbyaKGa gT0FSRCQJ0N9bKL7oF0ucPzCAoVaAPIe2H5BxZaifnS7O0UHGg5ciU1ef4+2jhlI2d1A gVUxd2q+vdqQwC+MxAN5aZC2WApFwIhYum9N9Rskwv/lEyypTncUVhPGmK6GQYJLTu6n 44BXqgvozM7hvXzy0E66t+nlC8s5WsfQ+3X7RNqp1S0R3Kjiu9L58EEWvnWL1RN1fQIq 8xg9i0KCbvyFeitV+wzmldmYd7f6TPkKzNB6BSHCxiN8Kbvt759Jq21PBzAld+Iwq8+t l7pQ== X-Gm-Message-State: AAQBX9cAPgZIhDY8uvHufmFAhTV5Oe7w9gDBagFOkatK7bvjJepJBuD2 uBw0zRg7m3lgviX/36FSR/eOS/UuAj8jeRmSM8g= X-Google-Smtp-Source: AKy350YJszeHRxALi/gCzKK1FXd4QlY/GuTO+4uQQrmU+tKj9tu8hB/MFqVKX/4hhhrppQ5E2fag5g== X-Received: by 2002:a92:c84e:0:b0:311:137e:83c6 with SMTP id b14-20020a92c84e000000b00311137e83c6mr5243904ilq.22.1680730591692; Wed, 05 Apr 2023 14:36:31 -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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:31 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 06/16] bsd-user: Remove OpenBSD specific syscall printing Date: Wed, 5 Apr 2023 15:36:02 -0600 Message-Id: <20230405213612.15942-7-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); }; -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) } } -/* - * An array of all of the syscalls we know about - */ - -static const struct syscallname openbsd_scnames[] = { -#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 arg6) @@ -203,23 +195,6 @@ void print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames, } } -/* - * 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_scnames)); -} - static void print_signal(abi_ulong arg, int last) { From patchwork Wed Apr 5 21:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=8AbaC8/F; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ0v17ynz1yYs for ; Thu, 6 Apr 2023 07:38:55 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoI-0005QL-N2; Wed, 05 Apr 2023 17:36:54 -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 1pkAnz-0005Ie-Py for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:36 -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 1pkAny-0005b5-2J for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:35 -0400 Received: by mail-il1-x133.google.com with SMTP id v5so16952228ilj.4 for ; Wed, 05 Apr 2023 14:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730592; 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=YADKy9wq15UL6Z5a2q0MBYrk4ZKu0ScqB+QGx/cMSLI=; b=8AbaC8/FojNZ8e98gcQbZ4t35sDnzOa3U/1oFsHGXweV7VumnlnvR++4LXyCpG0bQu phA8FvCDWveOVyy7KsbKMQXZJ9n1zE5AWa6Y58vmRXmRu3PQJ/C7C//G3iNUi8Fz+/Yf cYIfzPJc/elzS4NcoUfHrLlSgZq1u9j5ZL0+fnO/LhVl6EXo5XWafPEHYqVJI4HrRVu3 BuohtpMqgoQsSKLRmoSS2M0foNW24SBfwMyAPwPKmPHHqccLU35wVPxPMCvTyBa2zBXT b+cyotejBOyYs/9UQiUDE2w2WJ1QiIemhMUaWK0QeQxmKhH3DEA52gqc1yOIYObSZTg/ GVfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730592; 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=YADKy9wq15UL6Z5a2q0MBYrk4ZKu0ScqB+QGx/cMSLI=; b=L65zPBxWdwYJ3pIB3zZobdUHrknpRGQ9iyuao5yiNk3Xp7xp022WlZ6VH5RPzFrgdY TIn6GiKDrtB0Yon8WNEPLUBCs3NbpxlwKRD+krgcNJvvH9Jz2Q/emV0n57cTn4hikau2 x1mVrSPOwen41GMbWFA3JRnDKOqGTD4SpI8FK6wiTIYM4tqpiJSvm0gPNxVfe2PNSRO8 cg9lk2rJNE4EZR90zHFxFpe5xUmD5oTjXaISHhBDaoxaXQocHl6aTO8ebKL/iC5ds7Hq dm6NrEABLEhqMeSaUpBYn/uOPlntW+q1vgU4sHaNoQUPJfT8nveDTqBbXoaFTpcqXs9s 4RAA== X-Gm-Message-State: AAQBX9eKVzalBKCR+wvInGuUrRLhFyMJgmSo9v6/iXJ7foF7lAgj9geK ZZDXafd7gpKWC9rkEbxbu3DZwL/sr0AMt8rHJKg= X-Google-Smtp-Source: AKy350aRE+9ZHrGzmw5uOGD9gSstaa3NX+8MAnfyBhFxy2voYoRNIWraPw5V3ecE0avwNl+tX0A/AA== X-Received: by 2002:a92:db10:0:b0:315:3d99:bbd3 with SMTP id b16-20020a92db10000000b003153d99bbd3mr5084008iln.8.1680730592478; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:32 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 07/16] bsd-user: Move system call include to os-syscall.h Date: Wed, 5 Apr 2023 15:36:03 -0600 Message-Id: <20230405213612.15942-8-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 @@ #include "errno_defs.h" -#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" struct target_iovec { abi_long iov_base; /* Starting address */ @@ -98,11 +75,9 @@ struct target_iovec { * sys/timex.h */ -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 == 32 abi_long _pad; @@ -120,8 +95,8 @@ struct target_freebsd__umtx_time { }; 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 == 32 abi_long _pad; #endif From patchwork Wed Apr 5 21:36:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=gD9OWsTO; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHzK0lhwz1yZm for ; Thu, 6 Apr 2023 07:37:33 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoF-0005OE-RT; Wed, 05 Apr 2023 17:36: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 1pkAo0-0005If-Q6 for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:38 -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 1pkAnz-0005bD-3P for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:36 -0400 Received: by mail-il1-x12c.google.com with SMTP id j6so19497857ilr.7 for ; Wed, 05 Apr 2023 14:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730593; 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=6KgNQN5pzVZc5GjTmUd6jps4RQccUnKb+ZsxjaSjC8s=; b=gD9OWsTOC1nd5QXZtD0kLF0DSdgKERYA8F/I318xIhg6HsD0Q54YsM1RbMd5hJAozK SHyzRdFOATzsI32USBJ60N8cxB3Zp3Bhe/cW0ISSSdK36nzPI5yVj4pGqAjcILJ048hr U9tOtDyrOOAy9NTTEXtQctOns9x4LkK1vl4brjjq5s/BDI5i2RePgnkxd1YviYQ67NnC DwTbdkBkVXuUAPa1jlv397ugR1PvBD6qa5u68IWOUAPlRtOzE2GKZe8toOUWITZOVtnY 5J3HDPMYX9gu7DArOhpJO55EAH+KyGJMhqGqYrQz5mQHxRN43Mahz2EylilM2bs0O5UC 85nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730593; 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=6KgNQN5pzVZc5GjTmUd6jps4RQccUnKb+ZsxjaSjC8s=; b=kNncCXYPduhTbn9WgX/mfuO1QvAH6UbnXLVmRzQ8Qdl5zU96ngYPqsrlXxqLukfDZX L31VIArX7MvF6DrUR+anKzaQlsklgvUGFsWbSRzoim752zmKkJwri6/J3tb6BETYuRPM BLA88viRcj95CxG2P2C1oe+DjaF5vvkX/Z9XaSPNN5FVPIrTAzAeEWreStjaG0mhSfA2 CWEpETgeu1R35pjx7+ohJLQM2eynARibTSU28lIEM+/d87xhAir/uoUQisrbWhx/GYy6 OwqynaVepVUN9AR7sG7bhiIop7YbD9L5I3r7yMsA23D5Im1hEOYfh7ibKFhTWxDVq+CO k++Q== X-Gm-Message-State: AAQBX9e5msVanw0qvyi0YJ1EfO3JdsEmbQWG+Msg4Sli0aScOkn05/05 eUXrmyQHS9SUeO4q47kPvc4mxuH3gCdh0NwlFB8= X-Google-Smtp-Source: AKy350ZbM1bpsnUO7CEwEsnxBncPt2jX8jViLXO6KTmll9MYKuMq7lulsfv+CRN0DPJ3f7gLBDFkGA== X-Received: by 2002:a92:605:0:b0:325:cf1a:34c6 with SMTP id x5-20020a920605000000b00325cf1a34c6mr5910473ilg.19.1680730593309; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:32 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 08/16] bsd-user: Remove useless mmap definitions Date: Wed, 5 Apr 2023 15:36:04 -0600 Message-Id: <20230405213612.15942-9-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 */ }; -/* - * sys/mman.h - */ -#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */ - /* MAP_INHERIT */ -#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */ - /* 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 after */ - /* exec */ -#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */ - /* 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 after */ - /* exec */ -#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */ - /* 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 /* From patchwork Wed Apr 5 21:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=2jxhZy66; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ0H0b5Bz1yYs for ; Thu, 6 Apr 2023 07:38:23 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoG-0005P0-IF; Wed, 05 Apr 2023 17:36:52 -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 1pkAo1-0005Ih-DF for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:38 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnz-0005a5-BR for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:37 -0400 Received: by mail-il1-x130.google.com with SMTP id t5so8184793ilu.5 for ; Wed, 05 Apr 2023 14:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730594; 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=atGMiRwy9B/r1Cd+3QThXqU+xpU78gHAAUbSFzOWBxo=; b=2jxhZy66m+SND2ruguUtl3VlCjkDCEnewbRmwRmEDSwW9WXU4UVf3cTKXP5tci9//u e3E0GDK9n3xDmDwR7CP7Hbpcm0RHj6x4ietfAPkvVUbNq1EMBViQveWAyiYzQJaR/jKV TNdf38zbBYoSXQ44XauNtVBOsnuSpuk91cFUZyfHv2Ql45bT832EvugGyBH8FTGTvCx0 G6Mso72jbGDkB3jeXSq/ftYWH22oyw1DOxDkdYG2F0y15a3bSWy7dTAOxmhex0Bxvjne r1qAq2COHKnAXESlm0fN5ZL4GJzQ3Mc62MjXll4O53tWXovPObmZKtWYV6IdvTtq6fFa KStQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730594; 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=atGMiRwy9B/r1Cd+3QThXqU+xpU78gHAAUbSFzOWBxo=; b=IXqW7X9IVp9w/CCMarJMH+2aBym0Q4zvbEdTIfe38LInN2Y4K5MANIO7+7OkBDl8hz r+jcAnLVUmbAv4a+QTe0uuwfSAdz8gezOMGtH6jGzmxfDr9JbwAmkTRabkiQCA6qNfOn WtXVQHFbqLRJSGy2X8ZuVCKaSb9lrzviYrwwhJCIou18ETfyGZbodAU8oEWIrBQoSLzO RMgPcFMipVjpgVOQdPd8RQoG0Tk9Y323zkVSu56L393053wO9FelQO7/CR0pyQVz6//v zt9i5Sp2Kgk6gklB7NDPkn8gPsC0N936Ay+P+dOUg8H8Xz2dqR0CwAE6PsM6ZDo0E4ie wzDA== X-Gm-Message-State: AAQBX9ccCpLlvTaqDuG3GTtJolqOo6/YG+XZzW9I99MezT/HRJ6xkjc1 R0N5QZ8wWlQo439ZYPAVFmLJ/gWLLAX8ClVC7+w= X-Google-Smtp-Source: AKy350YpogAAxEPW6x29pNKZlzqZt0otmZk7D2BOkTJVY35PELwgv0CBIMw6cL144o+MbtekvTYxdQ== X-Received: by 2002:a92:d3c7:0:b0:323:29d:6724 with SMTP id c7-20020a92d3c7000000b00323029d6724mr5161843ilh.31.1680730594281; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:34 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith , Stacey Son Subject: [PATCH 09/16] bsd-user: h2g_rusage Date: Wed, 5 Apr 2023 15:36:05 -0600 Message-Id: <20230405213612.15942-10-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 += include_directories('include') 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 */ From patchwork Wed Apr 5 21:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=ArFRag9q; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ0317f6z1yYs for ; Thu, 6 Apr 2023 07:38:11 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoJ-0005QM-0M; Wed, 05 Apr 2023 17:36:55 -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 1pkAo2-0005J6-H7 for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:39 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAo0-0005Zx-Dh for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:38 -0400 Received: by mail-il1-x12d.google.com with SMTP id q8so4884409ilo.1 for ; Wed, 05 Apr 2023 14:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730595; 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=fyNQ7RJFtKzseu4TIr7i9vzRUyiAoH1sZuqVRNZHuzI=; b=ArFRag9q72JX78twUgQ2vIXmyGLhH6SdxiratkYYb3lXHkS8et1EtRT+wObbT/cDL8 BkmtMel2W0scc4n3pdhXnTn1Eguix6dOB9OLtB7X+04VFvQV/iEVLnaiZIdPhMeK4D7h 5xr4+SwwcGn6HtRpp3pCfyJgYJqhs6RcmI3fp3geb+u8GWr9bUleIAfjs71SNDLTBdtA L0SZLaG10WMtSmxgRcsJ1J0tvXwSYlk2WJ9A1hrP91twgtbdZ6Gsp9WGXP7L3/BiMQsq i1wysAbBFO/JrWEK0D14X8cGiyRZnrRTq77EqJzcEOWvriv4EeiM+5FUuhDP6YckQ+sQ cJwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730595; 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=fyNQ7RJFtKzseu4TIr7i9vzRUyiAoH1sZuqVRNZHuzI=; b=NYNPa9vq9bAuuiB329q6CPHit1fFrx/VX1mFdPwbFojSy4KbsbXCGY3WTLKYGjr0nF uuhQYl62q+0Y7nqsLI7Kx3BB50rg7B8iwJ84DVvECJpCHZi7+eN0Y7KCXB1rcFINvO4i 7lhb6mSeoMZnLoiET3wz9yy6xfc8rtQ4WuXpH12ykCWIGjvJwOquxBI+4OLhLNubhO+J GZmn0GIXJCklUFn+CUxYcF4cHXBSn0oD7kyJP8WqELNc77SlmzUgB7dHSs7UHWIJQOms icG/QwIhf0rfz69THZn9vQOhj9GmacH25GOea9FXl0UTHB9Wefb88DvJOe4AEM8Yw80m Rtvw== X-Gm-Message-State: AAQBX9dJVaFvky43UXVYhx3tjASlPRpQCzDoLTB+UZAcJPxzkKBCqe7A kLGTBEOQy5dnjUXVKZ2L6+cKzBPWKEUJip+51f4= X-Google-Smtp-Source: AKy350aSSbTwlvDjdPoNM/ewgtU7lXLAp5jTFDE/rOfp3g9JSmD8+0/VwHzD9OcKRznYybaISRO9zQ== X-Received: by 2002:a92:dc48:0:b0:325:a6a3:6693 with SMTP id x8-20020a92dc48000000b00325a6a36693mr5028599ilq.28.1680730595257; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:34 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith , Stacey Son Subject: [PATCH 10/16] bsd-user: Implmenet do_sysctl_kern_getprocs Date: Wed, 5 Apr 2023 15:36:06 -0600 Message-Id: <20230405213612.15942-11-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 @@ #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" /* * Length for the fixed length types. @@ -107,6 +112,164 @@ static abi_ulong h2g_ulong_sat(u_long ul) */ #define bsd_get_ncpu() 1 +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 == NULL in procstat). */ + tki->ki_args = tswapal((abi_ulong)(uintptr_t)hki->ki_args); + tki->ki_paddr = tswapal((abi_ulong)(uintptr_t)hki->ki_paddr); + tki->ki_addr = tswapal((abi_ulong)(uintptr_t)hki->ki_addr); + tki->ki_tracep = tswapal((abi_ulong)(uintptr_t)hki->ki_tracep); + tki->ki_textvp = tswapal((abi_ulong)(uintptr_t)hki->ki_textvp); + tki->ki_fd = tswapal((abi_ulong)(uintptr_t)hki->ki_fd); + tki->ki_vmspace = tswapal((abi_ulong)(uintptr_t)hki->ki_vmspace); + tki->ki_wchan = 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=0; 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 == NULL) + return -TARGET_EINVAL; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = op; + mib[3] = arg; + + miblen = (op == KERN_PROC_ALL || op == KERN_PROC_PROC) ? 3 : 4; + + len = 0; + ret = get_errno(sysctl(mib, miblen, NULL, &len, NULL, 0)); + if (is_error(ret)) + return ret; + + num = len / sizeof(*kipp); + *tlen = num * sizeof(struct target_kinfo_proc); + if (tki == NULL) + return ret; + + if (olen < *tlen) + return -TARGET_EINVAL; + + kipp = g_malloc(len); + if (kipp == NULL) + return -TARGET_ENOMEM; + ret = get_errno(sysctl(mib, miblen, kipp, &len, NULL, 0)); + num = len / sizeof(*kipp); + *tlen = num * sizeof(struct target_kinfo_proc); + if (len % sizeof(*kipp) != 0 || kipp->ki_structsize != sizeof(*kipp)) { + ret = -TARGET_EINVAL; /* XXX */ + } else if (!is_error(ret)) { + for(i=0; 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 requested * 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); /* 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 namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, From patchwork Wed Apr 5 21:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=clDytpwB; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ0z0JGrz1yYs for ; Thu, 6 Apr 2023 07:38:59 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoI-0005Q0-1Z; Wed, 05 Apr 2023 17:36:54 -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 1pkAo4-0005JC-4t for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:41 -0400 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAo2-0005c3-4w for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:39 -0400 Received: by mail-il1-x132.google.com with SMTP id j2so12494889ila.8 for ; Wed, 05 Apr 2023 14:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730596; 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=xqUvsNtt8LU1jK0PKJqgb4Y1fta0i6VhS1aSO5xc5ho=; b=clDytpwB84ZPBsuzb0HIvYi+hCeLRXX/vOMcYAHOL1dd4GOapBdXVFfKRZUE8dxPnO 7GZLPNGuc5zkThqU/Cr9kZrSHjdUJnFX0By+v4KcAvn5nm9AtK1BZgG7446VcWYFgbNH FTgvQ2C7NGTYEKfgzc12FBWEJ0BOk/BS3PVmReuy6F6nPYyyALB50EO5UEUapZ9LTsie 3dCvMOSFhl6OB97WPBoK+Zepa2fI6TEhUgNWYL7nqoo5ral/GlYCSL0IUVE52jRyIISU G6XKqEbPJEhLsMxGdsZPCjDGTaNDP0y04xQzI26GedvC6ymkadl6J/q/Dq0DXY7k3tsO ppfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730596; 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=xqUvsNtt8LU1jK0PKJqgb4Y1fta0i6VhS1aSO5xc5ho=; b=zDr6P/zcH9tRP5y2PaUuHjnnk8rgCYaFyPep0fAbRHSs/9NFlzCXinPEFnzOeor7l3 41d4jHCQuzPR8+NfpfZtZKb0+xHJAYP5z1aT9IcIo4bVsZvtLQ0nI6En/QvOr7Rnl6OW 9SFQM23CCn2nMi+D4xeWgJIULeo850gBP9DqvsAcSqNlFccEt6fy95qnaWlPoiAlfCLb QoHQB2fzFuoEH1QbSVG5oHPw0iZ9EgEDk0xd3EW3zmOTgP3cumjwBIDM9/jiL2e3EDK4 JKP0KUJdY4bNIZW4yrwI4OA4nQO3DmZ/RgB3fSwV2qTCBNInnFQa81WZcJNC7xti7ZZz M9Gg== X-Gm-Message-State: AAQBX9d+GJ2Sog+JnG8jiZpeo80PBwDNqsgfJGoqOKKA64wfJ6nD1q89 C/Mw4EG5ojaiOI9VPr7HEWQMoRzBXKU4HyPP220= X-Google-Smtp-Source: AKy350Z84qMxCgKlj+3/PcZCCSvnvcmNvF/GyuZ08rYxTTyqkYXDVt8YU01eWSghhO74QCM/o1vShg== X-Received: by 2002:a92:d249:0:b0:326:5469:119a with SMTP id v9-20020a92d249000000b003265469119amr5422565ilg.28.1680730596167; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:35 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith , Stacey Son Subject: [PATCH 11/16] bsd-user: Implement do_sysctl_kern_proc_filedesc Date: Wed, 5 Apr 2023 15:36:07 -0600 Message-Id: <20230405213612.15942-12-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: 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; } +static void +host_to_target_kinfo_file(struct target_kinfo_file *tkif, + struct kinfo_file *hkif) +{ + int type = 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 = 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 == NULL) { + return -TARGET_EINVAL; + } + + len = 0; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_FILEDESC; + mib[3] = pid; + + ret = get_errno(sysctl(mib, 4, NULL, &len, NULL, 0)); + if (is_error(ret)) { + return ret; + } + if (tkif == NULL) { + *tlen = len; + return ret; + } + len = len * 4 / 3; + buf = g_malloc(len); + if (buf == 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 = get_errno(sysctl(mib, 4, buf, &len, NULL, 0)); + if (is_error(ret)) { + g_free(buf); + return ret; + } + *tlen = len; + bp = buf; + eb = buf + len; + while (bp < eb) { + kf = (struct kinfo_file *)(uintptr_t)bp; + bp += 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 = buf; + eb = buf + len; + tp = (char *)tkif; + while (bp < eb) { + kf = (struct kinfo_file *)(uintptr_t)bp; + sz = 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 += sz; + /* Advance to next packed, target record. */ + tp += sz; + } + + g_free(buf); + return ret; +} + /* * This uses the undocumented oidfmt interface to find the kind of a requested * sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to 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); /* 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 namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, From patchwork Wed Apr 5 21:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=uUO6WxH2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ081rDfz1yYs for ; Thu, 6 Apr 2023 07:38:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoG-0005P2-Rd; Wed, 05 Apr 2023 17:36:52 -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 1pkAo4-0005JE-4g for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:41 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAo2-0005aC-9Y for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:39 -0400 Received: by mail-il1-x135.google.com with SMTP id r19so8262985ilj.6 for ; Wed, 05 Apr 2023 14:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730597; 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=qJNLRgyd/jIgyJneOYfM0Kr8qQRycbIc/fkXEn+sSrU=; b=uUO6WxH2kbAWThoR0jrwvaZTmse66nZ4/+t5s4yfRY+BNvIdoK6lv5ojMJbpKm6VlN 3lTdWPchKqAMf3k+KSPcW9T68uFqtmqp0Nw5twfswNRBT0v+bxOXsAcoZrakgJM0E2Nv ckrNtUYOJF44We3CHb/4/xViuSk/WUukqfe1DqlGgtKqVQsHcdK1ZNSxlrAHwf5pw+WH 7Q1x+p+8C6YTe3GTmqXdVeC0L1jfwNQ3ogzslsUIHIDxnI2+PJoHz+tuqBCRdn391i0J 74z37vaF1oLbtMlWkkFGwHycmOcLKxb43ncoDuRI05Oukhaiw6B3URPRARrvMYKx0OWS V6wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730597; 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=qJNLRgyd/jIgyJneOYfM0Kr8qQRycbIc/fkXEn+sSrU=; b=nb50pg8lDIGYFzujC7/mglu7gXH3RK7odtkL/xLV9TJvN8rhuHvrN2UmjnThq/6UpX RlOhYmhg1TQ2MKaxIOjtOB7f1NUGrWjkbUBMqVZDKhvEU9xG85Z1yre685dM05UD+S2L qGgZd3kn843Eyz5LUL7E/tJGEYQGjc1a7A0/lk/3MKrOAEi7JNxyToedWL8Z2KUxAWgQ Kdd+xUWfk9gU0nObeMOi5hWKPl9oxHJ/oWqX9b6Zcu0LpCkHEp4dkKAkBoMgGIoc2yEJ jVTS3u4Ovfo1kTD0K4tRiq6EG4DQ1EmjbIfg6nMrkVetDfkIVqw/6fB7iNm67kcCl0zV 0i3w== X-Gm-Message-State: AAQBX9c5w9jhV4WxJYQumPcgd9YYcOOxEk20WKKIpfPPpfhYdhjTkby0 xm8pqTA/XQzkGIronLfjR9nELiSeW3wYGuBKuTc= X-Google-Smtp-Source: AKy350a2qyPhBWvjotUXd7YP52Fb2hWThMhIhOJDIXukyTPkklaobnNFZyTJPRTgZf2f7aTm00vtBg== X-Received: by 2002:a92:c8c7:0:b0:326:198b:a8eb with SMTP id c7-20020a92c8c7000000b00326198ba8ebmr5061924ilq.9.1680730597223; Wed, 05 Apr 2023 14:36: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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:36 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith , Stacey Son Subject: [PATCH 12/16] bsd-user: Implement do_sysctl_kern_proc_vmmap Date: Wed, 5 Apr 2023 15:36:08 -0600 Message-Id: <20230405213612.15942-13-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::135; envelope-from=imp@bsdimp.com; helo=mail-il1-x135.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son 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; } +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 == NULL) { + return -TARGET_EINVAL; + } + + len = 0; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_VMMAP; + mib[3] = pid; + + ret = get_errno(sysctl(mib, 4, NULL, &len, NULL, 0)); + if (is_error(ret)) { + return ret; + } + if (tkve == NULL) { + *tlen = len; + return ret; + } + len = len * 4 / 3; + buf = g_malloc(len); + if (buf == 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 = get_errno(sysctl(mib, 4, buf, &len, NULL, 0)); + if (is_error(ret)) { + g_free(buf); + return ret; + } + *tlen = len; + bp = buf; + eb = buf + len; + while (bp < eb) { + kve = (struct kinfo_vmentry *)(uintptr_t)bp; + bp += 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 = buf; + eb = buf + len; + tp = (char *)tkve; + while (bp < eb) { + kve = (struct kinfo_vmentry *)(uintptr_t)bp; + sz = 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 += sz; + /* Advance to next packed, target record. */ + tp += sz; + } + + g_free(buf); + return ret; +} + /* * This uses the undocumented oidfmt interface to find the kind of a requested * sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() (compare to 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 namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen); abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep, From patchwork Wed Apr 5 21:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=iYX4D0VU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsJ0x2f3pz1yZm for ; Thu, 6 Apr 2023 07:38:57 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoH-0005P7-By; Wed, 05 Apr 2023 17:36:53 -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 1pkAo5-0005JM-Dj for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:41 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAo3-0005cO-Oj for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:41 -0400 Received: by mail-il1-x134.google.com with SMTP id q5so14135212ilg.12 for ; Wed, 05 Apr 2023 14:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730598; 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=AeIvXzgL0oZucwVnf8p6ob7Tf8wGgiHdAxgwBN2F8Dc=; b=iYX4D0VUvWTGhzDwh2Vf0kXp45+zqdUShNQEhxrk5RBNuKQH21V3p/VbYM4DoEYdla mKwXA7GIPrrAf9w1+P4dQ3/gugB5IjhSB5Ix+A9OQGV5eEyEU8LOqofBK5yZccJu2HmW ofdtguBVQ/nVGMEzPwlA2qafvbCRaTCBcZnWIYkzMk/nuYBkoQz/3LG52e9MtZjnJoz3 Z8FbpsZAN1yKEq8wVSVfCEl4EdNVT1bF1WxH52aMCHOWEmR8fwFLh0yrJJ2gmKFewe21 05RdNEa31i3A6VR9KkGrXG7/4/eKcPmy9aShOAff7+a39NHPY7k+Blh+eJ/4VZxZ4nEP DI1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730598; 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=AeIvXzgL0oZucwVnf8p6ob7Tf8wGgiHdAxgwBN2F8Dc=; b=gv12asGS6d7tuCXGiFju8JfScxjs3A6yCJ9OwLyx3BDFuybSSutvQIkpKY/yuUR+7O BoceaDprS/mf8BcrjurapyyQLwtryG566qcAEx4XUj6NmuM5DNXzplQQg+NIPKwqyW2B rhG2CepxBmxUF1ysdHSg2d6HqKB1eJLzL9Kc+X+HED4cAuJ7rOaUDDHN9Svx5Ae5CIgY TGrmkIqxTwHw2E5+B6nOec+EwADIOqgexoOA+tkGdtbszs/3uWqWBPa83z9wZsk2o23R C5b0ZcNTs1Ky+fNxyTXN5wWDysl+yYXtAElFWvLav0r5XakQ8jRlpZ+mSNk+bPc5KtlI 4rRA== X-Gm-Message-State: AAQBX9ev/X+BhxDOeIaxYVpRhMuv5S1N9ChC31MFb62L6gl7upY6n63P woYaCSSIIaLYIDOhKPThq2ISCAz/tpHh/leZtgc= X-Google-Smtp-Source: AKy350YwlVD5n8BVNMELRgWfp/1PMZyv45BgzGzE3sLbsSc5fgJURQMJM3p9ukVj1OaCu/+Hxvf8YQ== X-Received: by 2002:a92:6c06:0:b0:326:c31b:81d1 with SMTP id h6-20020a926c06000000b00326c31b81d1mr3568188ilc.14.1680730598019; Wed, 05 Apr 2023 14:36:38 -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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:37 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith , Stacey Son Subject: [PATCH 13/16] bsd-user: Implement sysctl kern.proc, except kern.proc.full_path Date: Wed, 5 Apr 2023 15:36:09 -0600 Message-Id: <20230405213612.15942-14-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::134; envelope-from=imp@bsdimp.com; helo=mail-il1-x134.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son 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 *env, int32_t *snamep, ret = 0; goto out; + 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 = do_sysctl_kern_getprocs(snamep[2], snamep[3], oldlen, + holdp, &holdlen); + goto out; + + case KERN_PROC_FILEDESC: + ret = do_sysctl_kern_proc_filedesc(snamep[3], oldlen, holdp, + &holdlen); + goto out; + + case KERN_PROC_VMMAP: + ret = do_sysctl_kern_proc_vmmap(snamep[3], oldlen, holdp, + &holdlen); + goto out; + + default: + break; + } + break; + default: break; } From patchwork Wed Apr 5 21:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1765769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=ytn/ufKb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsHzH3F3Yz1yYs for ; Thu, 6 Apr 2023 07:37:31 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoJ-0005QR-JI; Wed, 05 Apr 2023 17:36:55 -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 1pkAo8-0005Km-PQ for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:46 -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 1pkAo4-0005b5-IP for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:44 -0400 Received: by mail-il1-x133.google.com with SMTP id v5so16952429ilj.4 for ; Wed, 05 Apr 2023 14:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730599; 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=l6tsqUBY1YtWrUEbkmsbW91Yfgsm/h8FYRBQmpt6L4U=; b=ytn/ufKbgQZ5dzQoUInrocB3xfXwKDiQVNwW7DdrXrMSV0azJHvjip9qOQ40Z+R52R /kIDtxPxo69YpQ/ueEnUgjgubvJ0dwvOQdlZb80fu1sbnVTrVYnVJUYVUFpn+1kk77vS grXRkoT4u/Y4gxzjC5a8pbhf6jA3i2TIF+WAN3/nH0ik1+BZBeRDcSe60tf7djlZKeI2 AHKBhUMC+5bSruItSVvmWSY1OSjYBI+MLBJS+7B8Eo1cCRqp4/PL4wepEa4jf9SPqc15 nYuAU4o5MvwfuI7FCuuqddZiqLA74J+XTDMVe2eJnjKnVSfwUugc44wV8Sn4ouK8xrjt qnnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730599; 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=l6tsqUBY1YtWrUEbkmsbW91Yfgsm/h8FYRBQmpt6L4U=; b=U7a4rOpZsy359p09sD6JzDw237xwWoCu9PLO40gXiulhYG/R5oF1Du6MBCSap8XBI8 LizqK7naBP9ySUQ/2W/5vu4xsfGHRFmSFvtXlq8RBFaTu5xj1OQ1Z30IDPYy1qa+HsIb jKze72t39X4SkPafs7v9UOhSTAlo3F7Ob/7+9Ky+emdr9yhgw8w2iNg5Lw/0Dh87kyMG ryV5kU1RprqdYLLj3EwI0BkwQALUnA/F79KM8uZWm6XzLo9P2OTm44QD3amOvA87iEOu JYg37qwz0KpzY0j+k5ZPUtcI6BcZHN8t4KlJeXdA/hcSK05k788xPFOHKs1bXCzXYIMo QctQ== X-Gm-Message-State: AAQBX9c1qFrI9WLKTCNUUguIrvhuPSy8ZlcjJeOJ4Mc0j8s4/rgm5epe Oy9SJvQuFayUWyzpR3s829hMHSjZU9EbFVPU3dU= X-Google-Smtp-Source: AKy350bh/HMYykx4fsaL08AqAQP+rZo7ScXxAuKQPx1ZUWmF8pSbyHFTOAXjYD9JPGXvLTaUXlZFBQ== X-Received: by 2002:a05:6e02:4c5:b0:315:4b70:8376 with SMTP id f5-20020a056e0204c500b003154b708376mr5150295ils.29.1680730599116; Wed, 05 Apr 2023 14:36:39 -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 i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:38 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith , Stacey Son , Ed Schouten Subject: [PATCH 14/16] bsd-user: Implment core dumps Date: Wed, 5 Apr 2023 15:36:10 -0600 Message-Id: <20230405213612.15942-15-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stacey Son 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" -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 registers. */ +#define TARGET_NT_PRPSINFO 3 /* Process state info. */ +#define TARGET_NT_THRMISC 7 /* Thread miscellaneous info. */ +#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 data. */ +#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 = tswap32(prpsinfo->pr_version); + + prpsinfo->pr_psinfosz = 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 = ts->bprm; + char *p, **argv = bprm->argv; + int i, sz, argc = bprm->argc; + size_t len; + target_prpsinfo_t *pr; + + pr = g_malloc0(sizeof(*pr)); + if (pr == NULL) { + return -ENOMEM; + } + *prpsinfo = pr; + pr->pr_version = 1; + pr->pr_psinfosz = sizeof(target_prpsinfo_t); + + strncpy(pr->pr_fname, bprm->filename, TARGET_PRFNAMESZ); + p = pr->pr_psargs; + sz = TARGET_PRARGSZ; + for (i = 0; i < argc; i++) { + strncpy(p, argv[i], sz); + len = strlen(argv[i]); + p += len; + sz -= len; + if (sz >= 0) { + break; + } + strncat(p, " ", sz); + p += 1; + sz -= 1; + if (sz >= 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 = tswap32(prstatus->pr_version); + + prstatus->pr_statussz = tswapal(prstatus->pr_statussz); + prstatus->pr_gregsetsz = tswapal(prstatus->pr_gregsetsz); + prstatus->pr_fpregsetsz = tswapal(prstatus->pr_fpregsetsz); + + prstatus->pr_osreldate = tswap32(prstatus->pr_osreldate); + prstatus->pr_cursig = tswap32(prstatus->pr_cursig); + prstatus->pr_pid = 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 = 0; + mib[0] = CTL_KERN; + mib[1] = KERN_OSRELDATE; + len = sizeof(*osreldatep); + ret = get_errno(sysctl(mib, 2, osreldatep, &len, NULL, 0)); + if (is_error(ret) && errno != ESRCH) { + warn("sysctl: kern.proc.osreldate"); + return ret; + } else { + *osreldatep = 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 = TARGET_PRSTATUS_VERSION; + prstatus->pr_statussz = sizeof(target_prstatus_t); + prstatus->pr_gregsetsz = sizeof(target_reg_t); + prstatus->pr_fpregsetsz = sizeof(target_fpreg_t); + + ret = fill_osreldate(&prstatus->pr_osreldate); + prstatus->pr_cursig = signr; + prstatus->pr_pid = 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 = sysconf(_SC_NGROUPS_MAX) + 1; + size_t sz = num * sizeof(gid_t); + gid_t *gs = g_malloc0(sz); + + if (gs == NULL) { + return NULL; + } + + num = getgroups(num, gs); + if (num == -1) { + g_free(gs); + return NULL; + } + *gidset_sz = num * sizeof(gid_t); + + return gs; +} + +static abi_long fill_groups(gid_t *gs, size_t *sz) +{ +#ifdef BSWAP_NEEDED + int i, num = *sz / sizeof(*gs); + + for (i = 0; i < num; i++) { + gs[i] = tswap32(gs[i]); + } +#endif /* BSWAP_NEEDED */ + return 0; +} + +#ifdef BSWAP_NEEDED +static void bswap_rlimit(struct rlimit *rlimit) { - struct elf_note en = { 0 }; + + rlimit->rlim_cur = tswap64(rlimit->rlim_cur); + rlimit->rlim_max = 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 = 0; i < RLIM_NLIMITS; i++) { + ret = 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 = do_sysctl_kern_proc_filedesc(pid, 0, NULL, &sz); + if (is_error(ret)) { + return NULL; + } + + *kif_sz = sz; + + kif = g_malloc0(sz); + if (kif == 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 = do_sysctl_kern_proc_vmmap(pid, 0, NULL, &sz); + if (is_error(ret)) { + return NULL; + } + + *kivme_sz = sz; + + kivme = g_malloc0(sz); + if (kivme == 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 = 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 = g_malloc(sizeof(*mm)); + if (mm == NULL) { + return NULL; + } + + mm->mm_count = 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) != NULL) { + vma = 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 = g_malloc0(sizeof(*vma)); + if (vma == NULL) { + return -1; + } + + vma->vma_start = start; + vma->vma_end = end; + vma->vma_flags = 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] == ELFMAG0) && + (page[EI_MAG1] == ELFMAG1) && + (page[EI_MAG2] == ELFMAG2) && + (page[EI_MAG3] == 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 = (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__-