From patchwork Mon Apr 10 18:20:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767260 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=gETlza9N; 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 4PwHQr1lwnz1yZP for ; Tue, 11 Apr 2023 04:23:16 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8w-0002k3-GS; Mon, 10 Apr 2023 14:21:30 -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 1plw8f-0002eH-36 for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -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 1plw8a-0000ei-DC for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:12 -0400 Received: by mail-il1-x129.google.com with SMTP id s4so2662980ilv.11 for ; Mon, 10 Apr 2023 11:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150866; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZT5fLQSNvwvtBf2Szoe2FViWNomI0FmkPHfn6pZOtis=; b=gETlza9NjXIn40l15kDfOHL8ahJPjhzFZPB59ZedY37d3pOvIC85j26xsAPSRJimgy sH4ibl8yWEOFvmW+fH2DATeLqZYzRarE3NGh2k4p3dpPm5jPQA+R9+rpqTVb5RKcVeSk hVz9A73wsaT5mQR+laBZ40buv2nPwGH16qRHvF6ipSxQvbLOtMFyXGGKVbpqzWj2MRH0 b4Zfc1XOGZ6FgSkdRr3B2hSs7YWGi2ZQVJ4ibm1QR18Z560/dc4ykXAsC8fHNLGphOD5 QbgWTvlWxCvo0dUyqvTepwzGbaY1h/zQzfhw1fsP5VQSu34igeIc+Jduyh6YIGNVthrE lBQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150866; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZT5fLQSNvwvtBf2Szoe2FViWNomI0FmkPHfn6pZOtis=; b=CSUIXPwobCZyBc8UFqilgnerNFgrPrfP776e1bLvhCkYuTpV6FEJLrJr+kRngj9KJm WJ68XSYiN60AJeaTrMKjUOBAHlXoWRXBu/fTY5m/bmG371mno8eYwrZjfMNF56/pdpa4 E90lS22XVvaty2vQP+Pg6MmOfz4ssUANzx+EwSfZ/ntv3v4ggMbciEQ2MnkJE1jsL01R OPxdptVYN4Ks1QkO/MmSwNj52tanRqF+53GnsPSSFpvY+TcZIx2fpE+MeSGO5ND3HhWc qBlf9nrrF1NZNTPk6xJ8f1ssXi4dEqfyPupf3rKM6Vw6gDvuG9/2f9SgCe1lASQbwOGn oP8A== X-Gm-Message-State: AAQBX9dWWx2kBv0IDNVzxBbmz96ZQTC6AmY2/+PICzUR3mXVk1/WRPGD IE1GGxFh17UWwIjAUEzQ46Wds/yGJx1v9YAXMuo= X-Google-Smtp-Source: AKy350bpgBwdap36kMgiExxDPOqcwwxtOB5w0ZR3ArOUqGoIvKPZNsd2Gnbxli/wWxlfH1cijsGtAg== X-Received: by 2002:a92:c985:0:b0:326:3001:1f85 with SMTP id y5-20020a92c985000000b0032630011f85mr246513iln.9.1681150866237; Mon, 10 Apr 2023 11:21:06 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:05 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 01/19] bsd-user: Make print_* public Date: Mon, 10 Apr 2023 12:20:38 -0600 Message-Id: <20230410182056.320-2-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767254 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=1gBf4Cgb; 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 4PwHQV5ySsz1yZP for ; Tue, 11 Apr 2023 04:22:58 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8x-0002kr-Nj; Mon, 10 Apr 2023 14:21:31 -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 1plw8d-0002e0-P3 for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -0400 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1plw8a-0000eq-DX for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:11 -0400 Received: by mail-il1-x12a.google.com with SMTP id s4so2662993ilv.11 for ; Mon, 10 Apr 2023 11:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150867; 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=vxR1gdsQAsuHf2IN6tJm6YdCj/AcvFHJBZVDZiQZkYs=; b=1gBf4Cgb59rbB3qOtNU01kiosgLcIyXYrzbWd5Be8vZIBM+4Vp0QjaNgBQW3ovsb/D FdZuu7nPTcK6Sd2zRM2UYHqNiKc1imXuHc0zDU7jI7RzH6LVJdR7QBIeAY3LGm/xZZoU CFyBUNUjNPXqTThDGRiaOSD3F7x+q0z30livbZ9SJ/wX36/yHI4SITw7IKCGKOZDt/vT BXUKOLdBopzfSqN3MhgFVbhS029+0EPYEacedUE3KU5Kv0mhVINgbT2vxi72vY1nhpt1 Asg9fZ1HxxGiSzU/zKvE7gAGGo3fogzDJ0K2gDZjevJmK0t9z3Yxt04omeRbbzghWtV/ SL1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150867; 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=vxR1gdsQAsuHf2IN6tJm6YdCj/AcvFHJBZVDZiQZkYs=; b=fC2KqeL/F9XlzQGHlazDPH5G3iG9JM/TDZJeIrBwMLyZxLBtFyupgR96j6xgtzE//Z SOOIWqyndgadwMdWJfjQ+g3tl2zabOtBqTPJgy/11wzia6WFu1YXt7PGG7YhaqSFwogJ 2oLL87fsQndgSTMjhd+Ld+5OzT9fvxNVC6STXc9uvZ0H+pdV1+FNWl12KvnxBusQTJIi laTAWRlCvDcgH9hLcldrgqwwVMqNF49kXCxKqc2qoMJe6ppwaCRlMk4Jzk3Gq3ykhIQ2 sqNVkg8wUjNpValutfxsvyBoZj4UoOehCiPaXL+/wFfNlHDxh75tzgbgkwi4ORkZRosC nCjw== X-Gm-Message-State: AAQBX9ecW+vSbCSsYDjo1+4HGxsc6s2Bys50iN2PTytbne/FzSxWacM+ 9utRQMrwT9oe6g1yuzWnwR/B1B+FH2C/tC8eGfs= X-Google-Smtp-Source: AKy350ZlJsreSzRIETfN2KhEk0PN/2OIKCPxt/bValKfcd/z83lG8b6XrV3phcXAaANIgAfl45hv3A== X-Received: by 2002:a92:c811:0:b0:328:8245:38a2 with SMTP id v17-20020a92c811000000b00328824538a2mr4454585iln.8.1681150866964; Mon, 10 Apr 2023 11:21:06 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:06 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org Subject: [PATCH v2 02/19] bsd-user: Ifdef a few MAP_ constants for NetBSD / OpenBSD. Date: Mon, 10 Apr 2023 12:20:39 -0600 Message-Id: <20230410182056.320-3-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12a; envelope-from=imp@bsdimp.com; helo=mail-il1-x12a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org MAP_GUARD, MAP_EXCL, and MAP_NOCORE are FreeBSD only. Define them to be 0 if they aren't defined, and rely on the compiler to optimize away sections not relevant. Added only to the top of mmap.c since that's the only place we need this. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index d6c5a344c9b..2d91e8e8826 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -20,6 +20,20 @@ #include "qemu.h" +/* + * Not all the BSDs have all the MAP flags, so define some of them to 0 here and + * rely on the compiler optimizing always false conditions away. + */ +#ifndef MAP_GUARD +#define MAP_GUARD 0 +#endif +#ifndef MAP_EXCL +#define MAP_EXCL 0 +#endif +#ifndef MAP_NOCORE +#define MAP_NOCORE 0 +#endif + static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; From patchwork Mon Apr 10 18:20:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767252 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=PM0cIKdh; 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 4PwHQN6VkJz1yZP for ; Tue, 11 Apr 2023 04:22:52 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8o-0002gk-29; Mon, 10 Apr 2023 14:21:22 -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 1plw8d-0002e3-Vx for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -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 1plw8b-0000ey-Ij for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:11 -0400 Received: by mail-il1-x129.google.com with SMTP id j12so3358280ilf.2 for ; Mon, 10 Apr 2023 11:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150868; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=PM0cIKdh2il8tHA5hoyYhhpr+HlVpYXWsqaK0ocdqtO7VyuVsct6ViB3MbmKVT6Zhf UYDyEBUFKl+TfL7dk1FhcZdhWB4uMBFwQIFgmlcdF9bFKZB+/znIaPN/2EmoBZKVdh5V TO0RLUiBYLINc9yRiZOGutYlGe+zx8eMn2KuoeSiPl6lqIZ/om6u3KaAgqJJd+eHmvgc YZZJd2AhWoQd+sxCemM+67SvrROQw0QVBB0sH1f6Q3ePSRquGUfRvZK80nZfSaOHgdPm HrPK3alBjATiy0JQrFCxoj656w7+bwZG8f2qtU3hJ7cToKG6zhIkMg05WKjC+QApF5iN Eg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150868; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=iEFyYhczuCTBttwCZy8wJRpWdynrTwG3pkraTEZtA6mxK7tW0DFX6bAgkerc+9ahWo P+3aLsJ0DvvQnjIvIoplSEhgIsdMoflcyyq7xM35G/t4hcrVOXF1nRhT7PVCsleZ8kRi Mkmr6ch5ADMUwij20drl9neUHT/A/6h2+iU/EPNsNLMY1zLtZUQkCBEMHuht3HYuBUn2 WM1zPl8aJaawKxZNigl3eAhl/UPpbhwgyRIpE5CZvIqIcn7qH/kqDfRB7GL8Fv4prlja SEzSSBuumDG4K966AG+IY18K6dNsv1NkD1Wt+9d0FCcyhZhDIj1dEovYL5mHZoCCJ4fm fEFg== X-Gm-Message-State: AAQBX9fk0fjm8n/Hh10jNLqZcZOZmGwA2XzDhrhwCIODS8GgyQsNMmJr z4sophrunAyZpl1omqHP7UJr1113bmLWmdhBx7c= X-Google-Smtp-Source: AKy350bdzEFQwpjeFTt9BY+4nFoCwLFzjiZw+Z5fGj5TyBxP9Oo5m0MZyy4SCBCBx0qOT98Gy+9Vmg== X-Received: by 2002:a92:c981:0:b0:326:752e:7f8a with SMTP id y1-20020a92c981000000b00326752e7f8amr6045268iln.2.1681150867906; Mon, 10 Apr 2023 11:21:07 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:07 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 03/19] bsd-user: Cleanup style. Date: Mon, 10 Apr 2023 12:20:40 -0600 Message-Id: <20230410182056.320-4-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 2d91e8e8826..d0ade1b52f3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -59,17 +59,19 @@ bool have_mmap_lock(void) /* Grab lock to make sure things are in a consistent state after fork(). */ void mmap_fork_start(void) { - if (mmap_lock_count) + if (mmap_lock_count) { abort(); + } pthread_mutex_lock(&mmap_mutex); } 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. */ @@ -83,15 +85,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); - if ((start & ~TARGET_PAGE_MASK) != 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; @@ -110,8 +115,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) { @@ -121,16 +127,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(); @@ -175,31 +183,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) { @@ -207,8 +221,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); @@ -560,8 +575,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) { @@ -610,8 +626,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; } @@ -634,14 +651,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 */ @@ -650,8 +669,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; } @@ -659,14 +679,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (real_start < real_end) { void *p; unsigned long offset1; - if (flags & MAP_ANON) + if (flags & MAP_ANON) { offset1 = 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: @@ -736,11 +758,13 @@ int target_munmap(abi_ulong start, abi_ulong len) TARGET_ABI_FMT_lx "\n", start, len); #endif - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len = TARGET_PAGE_ALIGN(len); - if (len == 0) + if (len == 0) { return -EINVAL; + } mmap_lock(); end = start + len; real_start = start & qemu_host_page_mask; @@ -758,16 +782,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; @@ -791,14 +817,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 Mon Apr 10 18:20:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767259 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=jUM2dqPf; 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 4PwHQm4Pmsz1yZP for ; Tue, 11 Apr 2023 04:23:12 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8v-0002it-S0; Mon, 10 Apr 2023 14:21:29 -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 1plw8d-0002dz-OC for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -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 1plw8c-0000f5-4o for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:11 -0400 Received: by mail-il1-x130.google.com with SMTP id k7so13378539ils.3 for ; Mon, 10 Apr 2023 11:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YqE0cOIeNp+kyq+c5+Esj5WEVDxO+dIWwYCwGSiBV/o=; b=jUM2dqPfr1ReKxXEs8izTyl6Idsz+U0dzA9GmgE/28YWpKS4ZJYk3S6Dixe/8QIXHv dHkFarcozqCPK2hU6pbvGc9BumlIF9B2idR0rrGWcE2/y6vGfi14/foSXJW8ft9MDiHB n8XZPAJwx++zcTnkmhZdiZH67cHAQQOf9vRaUCvChQcCM/n79kDaBXa8vuNuSsl7aeXd 3OxXASfIcSGbeB1BSynIkv/xU5xgSEgd3Gd36lZYFOi0P/zrMOnHXE/anqdhnmwc9Drr gxYgAh20ilhk1d7m1J89gT7QQaWzPTqJiDwvlyWrYcymBSEmYy4Rm66ZwHkHGS6dedAi f52g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YqE0cOIeNp+kyq+c5+Esj5WEVDxO+dIWwYCwGSiBV/o=; b=O0D1gGL2Lo7+zGF4CNGVsw2R4stQa55F4XiZKL+0EQApwoPp7jwOG+eR2Q7of5H/qC 2GBjS5mLP0Ir/OlY7ChAkYS02npw0VDAe02p0sGMRfHOCueiuO3bBJp3Z99NuNCf3lyT QX6gM73dKun4ayzpkG2it4VLfgZarxSz1WqiiH4q6PRljrykDrKs6ons8JI2rlb0Cgof xt2CXP9FBq9J/Nwv39Mt4rrgNwwesAC+SYCejHVYQEKXRPzDQnW7e90Wb1pDbrrQrO7A KpmWaO94l0oFSWZWa/yx1tw4UFlo+LdZB9CZu06z54K9/UeYWozbVF6E6xZrASbvQMGG 4EPA== X-Gm-Message-State: AAQBX9drPxoZuUq+LVvOYng0LvJncu+T/hmvAqeFJhGoLuSRu68DerEG TnBel5pK4GKDQ6Mp6LQ8juFAJO4DwuDNf/JCMmI= X-Google-Smtp-Source: AKy350YUXl+H7KdYL85KAd3iRQm8ItSVPhnxhfoJuSmHVPSpnKoAyE/nv22Vj0izVjWHPbxpJKtgAQ== X-Received: by 2002:a92:50b:0:b0:328:6172:a739 with SMTP id q11-20020a92050b000000b003286172a739mr188367ile.23.1681150868727; Mon, 10 Apr 2023 11:21:08 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:08 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 04/19] bsd-user: Move system FreeBSD call table to freebsd/os-syscall.c Date: Mon, 10 Apr 2023 12:20:41 -0600 Message-Id: <20230410182056.320-5-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767248 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=5XTRISPc; 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 4PwHPG4QCjz1yZP for ; Tue, 11 Apr 2023 04:21:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8k-0002fW-3b; Mon, 10 Apr 2023 14:21:18 -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 1plw8f-0002eG-1W for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -0400 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1plw8d-0000fH-Fc for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:12 -0400 Received: by mail-il1-x12e.google.com with SMTP id s4so2663041ilv.11 for ; Mon, 10 Apr 2023 11:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tWf8Mdc3sABcKlVmtCGZhLXeGei83PoA0g+BtXKSJpY=; b=5XTRISPcSoSGfO/oEmaBiOUI61Y2I1QHq1uF2KJgqoqTYuKFPl96JhnZnAsZrdXz1l zkzJPxi0ANWhr+BbMWgXoLb1pQSY5rMsNYzwRnYPzFWuTeGnnOD9iJleILsypWo64PDN v97gsZ8xPB2lRWgEbD7kAOPQO456EXMR5EjmfWYyCO3Fzzbe/gUjx+/FNO2wDnZh2+No ZCOuwFsA0s8g3jw2+9BXpV7yygKEKJxsVHBfNU+jOXAwp6TKIhfpJo9JHirK5ScQfLZq +WwKeADG+1XEd739N1leBs/rOyH64ebZ4YnaIOeXXFZfLg/8hQdmya3Igp3wc+795dm2 23fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tWf8Mdc3sABcKlVmtCGZhLXeGei83PoA0g+BtXKSJpY=; b=RSpq69T0aZivneSE7QA8DzGx/0MdgMVvq5LsMXGy5jE9GS7Q2pOCxZA8qfY0BLfiRg 19vau5m4q1fDRSHhsPWo10GlqJ4KqEPt+vVhnyzaiZyMVevKziNdqXZ9ye1yc35udNWB QliaUWIicV+S59hSMtPtzbWs50nzCtwZvevv4xAAJUm3jCKNTGIKk32pBtQxtUPv3cDJ haMzBLfEdykx4LELYsbhOii3R6hQYvsbFVa2v7wkpL1LgIgfYHOJKJNSHeVeAynnWkdv hYRKj9gDwUn9fpkRxP9RwqZ31mgcxjvjKpPe4XuLIPxMwmM4XOneQxRtY2ZEmyENt4Ik 2kNA== X-Gm-Message-State: AAQBX9dyA/Fv9XtHT9pd6Ud/WR7Yn8tqhvEUOJ/3JuTGoVvKjkGppsvb fMayx9w2lZoh5cAF8ZyMsvS36X/W7wvNoomPY2s= X-Google-Smtp-Source: AKy350bbByKRijsvXsWuwobCd5yDYQiWvZsMqnUjMl4SVxCEZ5zbYtPDWnzVzYOYz8mcJrUZS4rCiw== X-Received: by 2002:a92:290a:0:b0:326:4dd6:e3f9 with SMTP id l10-20020a92290a000000b003264dd6e3f9mr201073ilg.22.1681150869504; Mon, 10 Apr 2023 11:21:09 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:09 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 05/19] bsd-user: Remove NetBSD specific syscall printing Date: Mon, 10 Apr 2023 12:20:42 -0600 Message-Id: <20230410182056.320-6-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12e; envelope-from=imp@bsdimp.com; helo=mail-il1-x12e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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 Mon Apr 10 18:20:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767251 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=mg1oRBkt; 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 4PwHQ64GdVz1yZP for ; Tue, 11 Apr 2023 04:22:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8n-0002gj-RH; Mon, 10 Apr 2023 14:21:21 -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 1plw8f-0002eI-CC for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -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 1plw8d-0000gk-Pd for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:13 -0400 Received: by mail-il1-x129.google.com with SMTP id o12so21100314ilh.13 for ; Mon, 10 Apr 2023 11:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CrJ6hQ7Rt3y9iXgYz6Hn19qcli8MJnG4NqFH7qfo5u0=; b=mg1oRBktPEshq+TeLIrLJXGRV8A6jiHsKX0+jDWORuSas9N+aphOMug/FboYRHdwZr RPF5BL+MEExveFHlxnfRaNRc3AOYqe1cQ64C9COvlZwS0Bl0cL6kqms/sNdhjiAfbFE9 fOi1dTaEdMZCHRrMAYs+54qA2nZ589cI1RjBOBe0JiEyE4MWJaG5OFmgPSZrRlHZA3ML t/uC+rqjzoVWp663keeFrNsE65qhOrzOVNzDQnUm1Epq3kH5Aoc6X9WQvggz6OkJAEmB 9AImXnnD9zaPTdM/oFp7IricF8t39EjHvAUzyxvZ2g0n04iiNtrzUtx0L7p1e990zcmP /gdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CrJ6hQ7Rt3y9iXgYz6Hn19qcli8MJnG4NqFH7qfo5u0=; b=DcOcBTJP1ag8btbCmFtd1wkTTmD1ZyyjwIfg4VsroUBftW8GUJIm2ltd1/c3oRiEDz PC9BH4dU6VIy7eFMmVWfF6IOyL3KVQyX5PVHPrNFmV6AZPma7dPPk8Yx3NP4aINN2+fz iVyQwMQZ2a6XCz1iinD4bTkK7NSJFomcrtOGxiDIDYG9uiADJ1N239RfaeVTMdD7nXPl tNgIh0MM/eICZRvIHdhFjT9BAWe/cZ5czBXmpy9NwylxCgCneyUbEND4Q9F3Dg16J//6 EiZOqO6qQoJs0dtRX3nnJZqnFSK8xENuJ3fRu8CBZCjt7MKluD1/rD7jIU6YTmJEzc+D TvCA== X-Gm-Message-State: AAQBX9dVmmISm5vqQSnDnF36SWD3c3stqWrLZvrZPSwaxgigTybWNwJQ 8BEYGylq/vSoCAdoEPeWozLDY5NfkJfGDLzwZ3o= X-Google-Smtp-Source: AKy350YnAcLe3f6J5PFE8SXmZfs4VfYfskYQFkZOkGfHCV10afaLxm/pZSls8GoKO/djwmGK+2faHQ== X-Received: by 2002:a92:d386:0:b0:326:2d3a:c76d with SMTP id o6-20020a92d386000000b003262d3ac76dmr4805396ilo.15.1681150870439; Mon, 10 Apr 2023 11:21:10 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:10 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 06/19] bsd-user: Remove OpenBSD specific syscall printing Date: Mon, 10 Apr 2023 12:20:43 -0600 Message-Id: <20230410182056.320-7-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 Mon Apr 10 18:20:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767257 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=fvbhl8vX; 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 4PwHQg4yp8z1yZP for ; Tue, 11 Apr 2023 04:23:07 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8x-0002km-3h; Mon, 10 Apr 2023 14:21:31 -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 1plw8g-0002fI-I6 for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:16 -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 1plw8e-0000h3-VW for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:14 -0400 Received: by mail-il1-x129.google.com with SMTP id b7so1324346ilm.4 for ; Mon, 10 Apr 2023 11:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jwIHVc41F1vGdAlrXUv6Uz16Se8rtJQuutqsrYhY8XA=; b=fvbhl8vXqM6FIhTEfPcJfhKFBzZR3ayJJjO8MudSQPRKuu5FFIL3JI6F9rBUThjuVE 7wBYV44HeoQI+NQX+ozUu5tv+kv0K3ghXvBNiZM/T4lgioNvwVDA0HAjrWGRtAqGoSj5 NWDr6iaPF/i9IUgDvoDUz5/tgcszKjqEVMsJwKPuykGf0tXaTO+jJqRVqBbDqCOPD+wi fRUxEpurH3CuFIVvgZMnnK6EuZqeKGLvDh5JfldgunDIRu79QQn3W2HR6LHbwxn0+Dn/ tLiQJ3jnnyqAW/WHLcLjqF+70CBnhu3t+Pznmj8SLHAMIFu0+pmLZcRpp7PNUkMF/3qU CkKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jwIHVc41F1vGdAlrXUv6Uz16Se8rtJQuutqsrYhY8XA=; b=sOnjXtth0myJeFpKbAqxlAtpa7gjMKcYg8J3GOoClUjkBw/EkS0JvZaJwVVIyC1CxL ZhesEAKH7X8mfoKT/S5vuWOhFNjdOkmzDU7b+PmiuxhrHuVR0zMvCbWTRIU8e6hVtRTN BjoWdO6KCkAXhMLYrEQZwWpWKXC9UAjJ1cTYGIBKLfA0ZM3BKNNkhgk4wACsEpsH6vuh TyGnJKvEghDsTIRsEfx5iNF/IQJILrnoz5UowyQe2WDd5K9nCbLkJ1iAiPc4y9sNTOCr 2fiM/EdZZZsnHM6cLUwA4JpI3Mp63RL4TsUePpyqUYbzHfSi/6I3jHpHOSTe+9VI2gvw BOCg== X-Gm-Message-State: AAQBX9dNtRbQ3CZJIZTZfVxZeYOa6ywEfj0tmfyQajbhruHgQgYXAjM4 ukf9nSrAcXfzy2O7Yx5HGNMq+Y7zdoAZ3F/gKMU= X-Google-Smtp-Source: AKy350a7+aKeBoLhvzGushb7NonfJOF5ESOAh30XWgRY8mocwkavzGZj5kRw5OmN2dw6p0kI0AEIkQ== X-Received: by 2002:a92:c501:0:b0:325:b96e:6709 with SMTP id r1-20020a92c501000000b00325b96e6709mr7475087ilg.11.1681150871392; Mon, 10 Apr 2023 11:21:11 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:11 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 07/19] bsd-user: Move system call include to os-syscall.h Date: Mon, 10 Apr 2023 12:20:44 -0600 Message-Id: <20230410182056.320-8-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767256 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=jP28ot3l; 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 4PwHQd6V55z1yZP for ; Tue, 11 Apr 2023 04:23:05 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8o-0002gl-Nf; Mon, 10 Apr 2023 14:21:22 -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 1plw8h-0002fJ-8I for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:16 -0400 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1plw8f-0000hM-Oo for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:15 -0400 Received: by mail-il1-x12b.google.com with SMTP id r11so2066689ilb.9 for ; Mon, 10 Apr 2023 11:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p/770m3m0UuWja7n7zJRMdkcuTqSX6pSDmKn7o3gni8=; b=jP28ot3lOoWTfCEYsoXSNyqLume40JINZCkOT9k6UaZxuLSQWM86TY7kqlnc4XOlYj l6YSk2f0dGv1xeAJj59qU/WXKhyW0bHHX1xM3/OJe10vctwiWpqq8AKTt7QugODDSKCc wzC/J0si6OdXhXN7XI5BE2ZstRpun1lojN+jHPGORJ/ZZPiUQ+hi6qk+ax/8CABSuzOL hlDYCWADf/BUu2ElPrljnmFeLKh8dKadWLkynOgZ2LHfMFP+Z4aQWYa06ChtV++4dd9e AYlaU+UONFncBoB8yt96b3QKqI3Redob5TzFynKZR8kx0aLJwjioiGA8AYiwBuQiLiCX YEJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p/770m3m0UuWja7n7zJRMdkcuTqSX6pSDmKn7o3gni8=; b=TGrewesVwPdtb1MuerkE4jEBIqiMQMHFwA9dG/wO6lm8S4smCbLE5lbuSI8Dxx4LBW vlItYALGIeEggfyPHkK/957OIpemjm5euTiyRwLGdIeR+efo6dyfBcJ0FZZTCY03a2Fz /RElOViUZjDerNeDmriBRyy9AOSwbY4mkwytOcmL14Q1uttwTHqQ0xAbcNQ7OOaEllXq t9eNctNb9WqltTVGbAw/d8Bu3rxAgfktKHF7M0LcHVemKU7CG7i7VEtEaPYBa7GR4qXh o87wslhizFf5FxXg+ruJ1ugqR7lwiA6OxneCGojYiolp3o4ownmM7A7a9vGfpXjCeA0A 8xag== X-Gm-Message-State: AAQBX9eRIhk70KLGNvgziMzRFATK/diGdv67Cdu0aTtb2bHUy+HqgLnj DEBed3SchdbezWqFO6YVK9eWdIN4f3LMeC4gPdM= X-Google-Smtp-Source: AKy350aXi/xRkI5BxO3ySTHiPg3Bc3FvC6Bpk3O9eS1TeP2gFOXuApCNQMZEyO9wxw08v+t6ytauSg== X-Received: by 2002:a92:d9cf:0:b0:317:93dc:1122 with SMTP id n15-20020a92d9cf000000b0031793dc1122mr4678565ilq.14.1681150872393; Mon, 10 Apr 2023 11:21:12 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:12 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Richard Henderson Subject: [PATCH v2 08/19] bsd-user: Remove useless mmap definitions Date: Mon, 10 Apr 2023 12:20:45 -0600 Message-Id: <20230410182056.320-9-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Mon Apr 10 18:20:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767265 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=7BBX4x/I; 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 4PwHRn0Jyzz1yZP for ; Tue, 11 Apr 2023 04:24:05 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8y-0002kt-EC; Mon, 10 Apr 2023 14:21:32 -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 1plw8i-0002fX-NM for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:18 -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 1plw8g-0000hc-UG for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:16 -0400 Received: by mail-il1-x132.google.com with SMTP id q5so20737780ilg.12 for ; Mon, 10 Apr 2023 11:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yuaGwqi8yehJHqn9QWm7paJs7txwchU6M9DMK57E1Ps=; b=7BBX4x/IqbBRPJ4LdT2ciWK+1eP8rtvXz4CJo4WSdM3QBpH0Yg5VQFNeR22rQXd9u4 eHLHVEKVkJce2XI8byFujTBk6HpA7GRItvsnT4YsuhhGj8QQ45j2YnzbKbNvClJEXIBi XIH3PMWobWFVNp+U3euNjQ0HHZeQIIdGFLbn4Vlt1vITj3fG5lcfrmgODAry4bKogMKk Sz6b1LqXdwLRzCF3uRuWxbXDeGDqHPSPmmcU1onhcLn11er6AOsRJb3RM+SuF8G0QZVz dr6rvC/JjZc5gK3GHfF5JY7YqgAmIIKLpWoHOxAPp/1JAkKJqaTHrc5ZroRQCsJ0mzEA yumw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yuaGwqi8yehJHqn9QWm7paJs7txwchU6M9DMK57E1Ps=; b=5e9zXAyVa5yeeqItXWD2uvLYWpt+9vnbyHCaKEhwW3yrxYzOMvZmI6EWxMQXtvnhRr vARQF3DApFcOSo200e2pZ8XaILAB87QJDgM6Ose5hwyzx1hduLyRcvHxJrW+LGxGJBVe So3I37pzDq0ExPPIrhmFtZJvHO9V7Dk0gmZdvPDVM0sU81nzW9nvr4PRrdyZAGNMQHa6 LD2LZa7nvJrCtTQFQivsaQjYx3cg2avX6aQZYogJ3i+bFXSOd5f/axTqtlEIWUK3EfBQ vL0OdxwffF038NdI8HA5TbLf6euBSFc3SfIdJZcQMldVa0tsUm660XXwcUxcnrWI9WvU wVwg== X-Gm-Message-State: AAQBX9cHwi+IDMZ/XYwEARNe23k0HwFQyPUjB9cX0yViT6zSt1Gy7NqD ZkA/1aqbmOJu+oYdx1ciEew9LJ1rKCLCnd12gek= X-Google-Smtp-Source: AKy350ZhXy/LAhKvWzQgmVMWZG3Cc6ulJEmw8qjeY7W798m/saPos3QqFWQim+g3liSzNrFr+/37AA== X-Received: by 2002:a92:c692:0:b0:326:6d28:94be with SMTP id o18-20020a92c692000000b003266d2894bemr3908670ilg.12.1681150873359; Mon, 10 Apr 2023 11:21:13 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:13 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Stacey Son , Richard Henderson Subject: [PATCH v2 09/19] bsd-user: h2g_rusage Date: Mon, 10 Apr 2023 12:20:46 -0600 Message-Id: <20230410182056.320-10-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767250 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=HuVHD2Vm; 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 4PwHPw3NcCz1yZP for ; Tue, 11 Apr 2023 04:22:28 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8v-0002iu-SP; Mon, 10 Apr 2023 14:21:29 -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 1plw8j-0002fZ-3i for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:18 -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 1plw8h-0000f5-BR for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:16 -0400 Received: by mail-il1-x130.google.com with SMTP id k7so13378661ils.3 for ; Mon, 10 Apr 2023 11:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150874; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dLPGsKZ9qU3wG8gg3c0pvYiD+HZ1kzhXINDhxubxQNw=; b=HuVHD2VmF9LrGijNnNQOw1FT8pd6IU1zojiA3I0QkFcgoTubn79TeBYjoiy57KLV3x OthUg8QJK9w/oNT/8yYOchpka1kbu3f3ag79Cf8WF6sMjDYKI5F/POiATYNTIfWkJzI6 c7Am+rnFfS6/ItJ1Ho7U/Z9KX0Tww34rmOfP84HNH2Jm3U8T9ixiPfCxJOPbZiPxfSM9 NpKaGOBTy4vi/Bez7el1RjLrgAR8kSv1zjmHYsZ0paNI9vb7gYKYgzDk+2kXxu+ZCao+ /T8KjMLVirTfWP9TIlquHhBPGNBkHtgWxPYl3n5VtTK7My5O9TNTOqfoueOE5TEOQsa1 2AVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150874; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dLPGsKZ9qU3wG8gg3c0pvYiD+HZ1kzhXINDhxubxQNw=; b=am4QgUFLz16GPg5fs6WOGPqgZTkrCZfDbPOPwOb1ufr9RwCizo5fjHIW/tyDDRSv3p cQOLeTGXcJd+yoAQ6gMo7GSVH9V/IeGIr6K8BV6OLhwxv+D1JWwRZFk2r95cIbolvMEX 5huKft9jVykfOZauqnC6ciitzPlYPvVWh29GKdvu/uZMCsuOnZU2F4OTWS4OFMo3YKJk WMuDfJZ7tP6CqoCUWdDCJnzHyVSOqMpBQ8VEE63mgOLeLpUOuF/+ZHnB95t2aB6c3OxZ DRjmHK5C/pxZSM7Jmors3uD1MZbKS7HqNkAoA/L3hS6+7zfftotWaAc/c6Pgw6mrToJc mr+w== X-Gm-Message-State: AAQBX9dp4qch9wqz/16CnzVxQUYyMaZgi0xM4RXfiq3TgEpXRAK2r2zC s87cTfyqTQsRuq3Z2KreQgnxz8/0Vd40f0A7e54= X-Google-Smtp-Source: AKy350aWL/Kv5SZ+685IckIA598+X9IlwPx4WSck5QK5jjwFWdY/1xHc23jbcdBGwoFmIWl0WDwI+Q== X-Received: by 2002:a92:d201:0:b0:328:bfbd:1e87 with SMTP id y1-20020a92d201000000b00328bfbd1e87mr2340055ily.27.1681150874373; Mon, 10 Apr 2023 11:21:14 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:14 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Stacey Son , Richard Henderson Subject: [PATCH v2 10/19] bsd-user: Implement do_sysctl_kern_getprocs Date: Mon, 10 Apr 2023 12:20:47 -0600 Message-Id: <20230410182056.320-11-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767255 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=A6fe84+m; 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 4PwHQW1GFnz1yb3 for ; Tue, 11 Apr 2023 04:22:59 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8v-0002hk-On; Mon, 10 Apr 2023 14:21:29 -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 1plw8k-0002fp-Mr for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:20 -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 1plw8i-0000hy-TS for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:18 -0400 Received: by mail-il1-x132.google.com with SMTP id j28so2309576ila.0 for ; Mon, 10 Apr 2023 11:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mO99b13qRlgHCWdPhSoOiqyC95aMtsRkFEpbNDXSAnY=; b=A6fe84+mKSYK4ZTxtfTuVOnOE81+7l1d2ZbOEDcaXWfLWFmIJMCdRXG9c2xBh2WSHH xY0JbAlO4k6w7YPMFW/9xdqEiAGblN/Gg2D+abSOkD/vBpTGUCvgocyb8XZNz6YIM628 WknG26PIO7YLxDwDEDuZ0XGjW9gnHA2I3AluIbbKGG0lPPLrewLThPvtDeTzHIHO2FWo QywtdP0muD75Rr1bHNmns1ugQzRAGI2iR/3SbM4zgl0ZETeuBqbQkIqJh9rbj910wLzJ W/WhO+NNHRPY/zpoVWH+ul/MHRxrN7Y2Qa4TZKHD+/b+74GyrisMlgKgxlw6l4fM9h+A qpag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mO99b13qRlgHCWdPhSoOiqyC95aMtsRkFEpbNDXSAnY=; b=bKsmlh5f88anxRkka1JEQpOUhD2rIWBKxsoCrDB/ZIgCfj6vy0fegoXaM9UBwFmrP6 K9v2kLNhD7ctuB8ifFheYZkFP/NQpPLbJL6FKTe5LAeV7KwuiQvp9kYm7UUf15Lk+8L5 FtgHbm0EnxpH0W7PoP+DKEdM4FIld5NFWUuRT46alGCIIhYOe6VMxbnlHAm4w9ccfhHP 4iGTQJSHeqMphKMugCtylgXCSmWHQDrfU0scB0V8nR1nTO/I8HHddnCLnaxQKV5C45J2 Cgh5xJVNuAMYAv8mCuyLGGUGcbkn/Av5ao0U/Hw/RwfOCp5BasZq1Kgl7VgohxJJcg5a OLLw== X-Gm-Message-State: AAQBX9dB6wjjjeW/wAzTxhiqHR+aY3KGBpDn930JVL9kr2F3dSSVT8Xe WsJj86iRpVj6D0xArwjo8wl3PCu2XcChvLxUg70= X-Google-Smtp-Source: AKy350Z6Yg9CMOgHDJbZgPD75Z44oMKbTGWeZdO0asEBMarGCbicUP5cQyLZaGRECeFA0Gs0FJY9ZA== X-Received: by 2002:a92:d3c9:0:b0:325:b211:4355 with SMTP id c9-20020a92d3c9000000b00325b2114355mr4236822ilh.16.1681150875459; Mon, 10 Apr 2023 11:21:15 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:15 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Stacey Son , Richard Henderson Subject: [PATCH v2 11/19] bsd-user: Implement do_sysctl_kern_proc_filedesc Date: Mon, 10 Apr 2023 12:20:48 -0600 Message-Id: <20230410182056.320-12-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 Mon Apr 10 18:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767262 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=ecAPfMBz; 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 4PwHRD15wHz1yZP for ; Tue, 11 Apr 2023 04:23:36 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8y-0002ku-JT; Mon, 10 Apr 2023 14:21:32 -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 1plw8l-0002fx-9s for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:20 -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 1plw8j-0000iD-KI for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:19 -0400 Received: by mail-il1-x134.google.com with SMTP id a4so2738587ilj.10 for ; Mon, 10 Apr 2023 11:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7NzCz/sF8P038tTGJ2ITOmZzOTs2PdrJIGIXZvdsTJ8=; b=ecAPfMBzq417wv/NZczxAcrMdjbGFD3io1X0BxUrqs0RI5QdVQ74Xy95FnMxjDNX7q mhV7K7vpzA4S1dxx4lmJhNJe8alIBCqAkSK+kcmwRARK568f8DRf0ur4IsZBog6sFTKf tFK0oYcsQgTUDAVn0GQ2vdxqooGKtE3sMUlvmxZUOl9IcAokrnJulumlvSjacYI3aZn8 W9vGzhcDI8SW6+l6PpWby/VZoWmYqljdlLaN6/ASLP84aLNOTnMAGZMJtcOwP5ZbbLMK JKXUpCJ/M8nXX5ACeSZ11rwyIcPexWGpgeBSI2z9HIi1P54o2fz9FZw03hQ0M/9d6gBz jNeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7NzCz/sF8P038tTGJ2ITOmZzOTs2PdrJIGIXZvdsTJ8=; b=g0dfXaxYy+Sq/qqLE6burTmzFL4nZw9RpZO6QDeiJMp34droBz/u1g0vOpmsUoy5v+ +yrOwe3l/5cahHxnQO02+/gI0IfFsx4fjaZCC+veYDUmxBeWT6jnoEfm+sj125BBkxMk CCukIBDcxG5ip669OZyVJAWgwvLgucRQxpxfQd5y/2nZ+SwTF8gOVJsF79iHC/R2dWM/ M+JJDcP6+Ui5BgZPU+wkm+F4aKGNMN1jQDeIH25L0zZ7fZBg3cETV2MA5O3wJJKArPo+ nyGQ7IOvIK9nQA0MmjZZ1t4GGtnpkyix3SfFzJevND3F7qMXc1gbVvRRboAQ0cXz8Vfl MJiw== X-Gm-Message-State: AAQBX9f1DlRKjgjrIz7XA17Ki7uve6CYDXEFrdTSI/L0o0ZrjesQJBXH O09VSbteCJbsJxsnRE4Rg5opyVKVd/hd0o60ewE= X-Google-Smtp-Source: AKy350bfaVZkOBdfBxxRuTm7ncic+uK3tIU23MpJTORJoRgz8LLeh9vt6INQYboijhA6Hp5YSTe06Q== X-Received: by 2002:a92:c642:0:b0:31f:9b6e:2f4d with SMTP id 2-20020a92c642000000b0031f9b6e2f4dmr6665159ill.0.1681150876262; Mon, 10 Apr 2023 11:21:16 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:15 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Stacey Son , Richard Henderson Subject: [PATCH v2 12/19] bsd-user: Implement do_sysctl_kern_proc_vmmap Date: Mon, 10 Apr 2023 12:20:49 -0600 Message-Id: <20230410182056.320-13-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767258 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=Tjoxy6Vu; 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 4PwHQh4d96z1yb3 for ; Tue, 11 Apr 2023 04:23:08 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw8z-0002l3-2f; Mon, 10 Apr 2023 14:21:33 -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 1plw8l-0002gB-Pl for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:20 -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 1plw8k-0000gk-2Q for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:19 -0400 Received: by mail-il1-x129.google.com with SMTP id o12so21100451ilh.13 for ; Mon, 10 Apr 2023 11:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hvg0H+jAXckcuN28KMVfXkb7fwvWyCcCCQgrLkQjtV8=; b=Tjoxy6VuxnMkEwLnB6Z6ybsqqQ6KUW4LcJja6iRu0NtoSZqeXPv4eKzzhIi7mfi+J/ Mxxc2FkQ0hSJ8TG504R+Q2Lc2hUsaMkU+b5uYeh6TgawAmB+jGsGbiLv4omWgl8dfeyn WFTmf6P6S3e6FO3tHDy/wXyQT8O3WU2jQouGrzdtXOFG/6UTyvZba/PxIjr3sGwS1B05 059nGJE+5SqYiVirASjAr+iZSIEAhqe8rP+j5APiLtyafzcF32HTJ715miQk0jDFPlgK CAMjFaOIHD1hkuce5AB+a8pMLdO9o1cQ2pbbeiIFr0tVZn8/fVS6G4Sfr29sfR44PtXo 4eNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hvg0H+jAXckcuN28KMVfXkb7fwvWyCcCCQgrLkQjtV8=; b=hjYGk4eMQ9UCG1YlogswS/lUvS9ZWYVbTZi+lJHE6wIvSi2wHYF9bvfbcT0VICQMM4 ZOIQeMgFcswAJKx2cpfsCkeRzfH8cru/91Cl8y7nbr5eAt49Pu2vw09PJhEQASrOH+t6 lwRx1hl5AnCrrA/PENNkzQfIoI7m8PQbHxAuKbDuuCDUd8nWVvKkdT7vbBgoUJGoPWl/ qbsvLpPuXvuBEiHmPP33ohFAQGVpSbOmthoWwIkRE6bfG0Nzbq3swsLFWUdm2Ok+2C9V 7Z5eBJDQ7f7cwdqDHnS7o5F1v9eT3afEZ2ledfL7psHXJLlXTrVXrBmIo3qSfriopTrT HH9g== X-Gm-Message-State: AAQBX9eITbTxFST94WO1RqhnHk+5rCGDFgqLHOgfcMBAhbJNyxK7cGPS WYkgoAafdP8Txxhm1fkVefr8d68g8Vrj4VtOvJk= X-Google-Smtp-Source: AKy350ZiuLG6M6Qh9RPr812ixEAieuKXDnf3dSdrYG8e+ZrARK/yeIT5Vjj8evLylxxc8oT+UlYHgA== X-Received: by 2002:a92:608:0:b0:322:fe79:8141 with SMTP id x8-20020a920608000000b00322fe798141mr270238ilg.1.1681150877098; Mon, 10 Apr 2023 11:21:17 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:16 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Stacey Son , Richard Henderson Subject: [PATCH v2 13/19] bsd-user: Implement sysctl kern.proc, except kern.proc.full_path Date: Mon, 10 Apr 2023 12:20:50 -0600 Message-Id: <20230410182056.320-14-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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 Mon Apr 10 18:20:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1767264 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=1dBeHSwQ; 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 4PwHRl3yN2z1yZP for ; Tue, 11 Apr 2023 04:24:03 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plw91-0002mf-Vd; Mon, 10 Apr 2023 14:21:36 -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 1plw8p-0002hG-Bm for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:23 -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 1plw8l-0000hc-Ht for qemu-devel@nongnu.org; Mon, 10 Apr 2023 14:21:23 -0400 Received: by mail-il1-x132.google.com with SMTP id q5so20737879ilg.12 for ; Mon, 10 Apr 2023 11:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681150878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w8D+nLR3rH7E2qr0f8qLGugi8CI/qxIhBNzb5sgAdpo=; b=1dBeHSwQM0o/o/o6sVPg+D85fs7hFmPSmIT8l/mZtYI2/lHTldYoTvbAaygWPa19by 25s0JjqBtZUh/pGkjgdYdpPWtw2HUe3gqhhVq0Toss6VBzcPbQUQNC3GsnNEhQPGLjkE /FOUK6i/ZdK8k7b4b6/HuvjX7AGy4d38rbFVfBIWr1FiaSBvUOtg7XhzLoWMZDbGzbCR t2tc1F2bHAVrlo5B4MFbn6/UQHEIb+wp7gHJSU38+ILag6XuXpd9UKEMTkmsna4K0VqP c1lxpORPwGgZwJl0I2M1EMuzoaP7UIDTzsJQhhstF8UbGi2g5d5Phl6n3K8TxZqaX7kx g7TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681150878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w8D+nLR3rH7E2qr0f8qLGugi8CI/qxIhBNzb5sgAdpo=; b=FyZwvnuu4a4tjo6ofRTRzLY0LPt30L5Uiez6rJCzoaqGXewbQbO3vQKd4bdi959fBf mipkHrbtzyWMGaXEGIc5KZcWUujzgDTQTwgYEeh31fqZZW9RpKHt2CCOFL7gDIS1DitW Jr2IFuxSXYrw9aTlJLc3zF9zv7ZxtbbC/1sWQ7/TNrusS/YTlOp/mKNUsZ6eK3/tp03t On1BUtSOGtCPRoxSQiTWF0SdR26zM+OfUtFyp+AnJuKefDwkwktVNN8FJ10eZsecsok5 ZEN1qEz3FfMC/+QsjNRph3i7KGzdlq6V1SrlsBJw2AvQedzvwXSf7l3PvuNJxq6p2XNL ZW2g== X-Gm-Message-State: AAQBX9cJA91DmfvP87kZbevnHdf6sa7ggU31PKrWuHGqt6sdBL4/RqFw 6MEYR2jLNoyUSI298IjBjqqtUfUSbAT3BHvGp1I= X-Google-Smtp-Source: AKy350Z166anN2QE468pm03YjPolM7+gmMUccKUoiFZTfIsSz3hGR8fN7VNjVz1a7Pvv72cpJytWoQ== X-Received: by 2002:a92:c505:0:b0:326:68bc:b423 with SMTP id r5-20020a92c505000000b0032668bcb423mr4299757ilg.20.1681150878144; Mon, 10 Apr 2023 11:21:18 -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 a15-20020a056e02120f00b00313b281ecd2sm3104314ilq.70.2023.04.10.11.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 11:21:17 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: jrtc27@jrtc27.com, riastradh@netbsd.org, Kyle Evans , Ryo ONODERA , Brad Smith , Warner Losh , reinoud@netbsd.org, Stacey Son , Ed Schouten , Richard Henderson Subject: [PATCH v2 14/19] bsd-user: Implement core dumps Date: Mon, 10 Apr 2023 12:20:51 -0600 Message-Id: <20230410182056.320-15-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230410182056.320-1-imp@bsdimp.com> References: <20230410182056.320-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 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__-