From patchwork Thu Sep 2 23:47:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12473463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CCEBC433FE for ; Fri, 3 Sep 2021 00:14:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 111246108B for ; Fri, 3 Sep 2021 00:14:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 111246108B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:55302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLwrB-0006Ca-8M for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 20:14:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLwRS-0007Ez-DM for qemu-devel@nongnu.org; Thu, 02 Sep 2021 19:48:22 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]:40484) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mLwRQ-0003EJ-Pb for qemu-devel@nongnu.org; Thu, 02 Sep 2021 19:48:22 -0400 Received: by mail-il1-x129.google.com with SMTP id u7so3563767ilk.7 for ; Thu, 02 Sep 2021 16:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vUuIjHdOsQ3caYYxK0NPr5NDtTA7+bJ4PGL6XLNxUdI=; b=1D20P7x91D6EbIdMFmyM8i11F37UtC3BzRAyuW4zbMOYABImmkSuBDlbikG5wAYq7F 2ytJahbCc67ulDsmq/sOA1rgEwn5gmAxuO64klqr/W5YdR/uOopegVZFcQ33YvQ3Agod rj9q1bovVLpzVOEmFF1KsOWi7MCiOckIU+ZitRjtyXXQph3le/wECqPVC2GHIHb6pm1p Vo32lp+ODO4tyZbiGjfecMFa683XDHM147rjEgs0hbNwp9XsN9ZS3jyxbNhQQsma810G wKxMfk4R2RrML4mqgwVfSJQ8teg5ao6OveSynglqQB+xwZE6nKdnpHC9Ji1N6S6ESL7F s7yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vUuIjHdOsQ3caYYxK0NPr5NDtTA7+bJ4PGL6XLNxUdI=; b=VhA57cnvOjTSo5eT+77ezwYTVquIj9rWdq9fdBGl7KgNYo8XZLMsLRRxDcEWSmku7G 3crcItDCAjabkPJjXRmNCaETmJSoscl1OAVnYgZtoaoKgW6OJFWO7JSBKw4k1Yf+l291 k/cdr0gml3aLqN7HmbCZ7k3X5s6tYfsDVMRs5PqfoD9uTUVLaAV1FH6/2OIQ/fIWUtrm ZgRAh10p5hG5xcyWCus+q3R+UVJCsNUL2ifjLFC+JOWVUEcHIOaDqZHt6FYx67RhxhiF Xo99XQBlC1ipR+njZ1UCQ2FHQmUaj6YDeMf2UAeF4VVqkquBWBkzANklrtJHsjmqkjal Vf1g== X-Gm-Message-State: AOAM531ebcKMCcyr31s3cNJdcr3w9DthLDdQfkqGAq5l+zaeRrHFvY5h 6Xv9WCiccGhwoyANYpmxCOfsCx2g6tXfIA== X-Google-Smtp-Source: ABdhPJz73S7jDEY27W8lIqdMDgXfzA08e+i8LbD0eAmBHSyEvANNEziaH0vnRuI0SE7/lZUu7BrDGQ== X-Received: by 2002:a92:d112:: with SMTP id a18mr525627ilb.34.1630626499309; Thu, 02 Sep 2021 16:48:19 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id u10sm1740502ilg.15.2021.09.02.16.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 16:48:18 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PATCH v3 37/43] bsd-user: add stubbed out core dump support Date: Thu, 2 Sep 2021 17:47:23 -0600 Message-Id: <20210902234729.76141-38-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210902234729.76141-1-imp@bsdimp.com> References: <20210902234729.76141-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Add a stubbed-out version of the bsd-user fork's core dump support. This allows elfload.c to be almost the same between what's upstream and what's in qemu-project upstream w/o the burden of reviewing the core dump support. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfcore.c | 10 ++++++++++ bsd-user/elfload.c | 22 ++++++++++++++++++++-- bsd-user/qemu.h | 6 ++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 bsd-user/elfcore.c diff --git a/bsd-user/elfcore.c b/bsd-user/elfcore.c new file mode 100644 index 0000000000..c49d9280e2 --- /dev/null +++ b/bsd-user/elfcore.c @@ -0,0 +1,10 @@ +/* Stubbed out version of core dump support, explicitly in public domain */ + +static int elf_core_dump(int signr, CPUArchState *env) +{ + struct elf_note en = { 0 }; + + bswap_note(&en); + + return 0; +} diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 11ca813c7a..05751f3ce7 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -26,15 +26,17 @@ static abi_ulong target_auxents; /* Where the AUX entries are in target */ static size_t target_auxents_sz; /* Size of AUX entries including AT_NULL */ +#include "target_arch_reg.h" #include "target_os_elf.h" #include "target_os_stack.h" #include "target_os_thread.h" - -#include "elf.h" +#include "target_os_user.h" abi_ulong target_stksiz; abi_ulong target_stkbas; +static int elf_core_dump(int signr, CPUArchState *env); + static inline void memcpy_fromfs(void *to, const void *from, unsigned long n) { memcpy(to, from, n); @@ -100,15 +102,25 @@ static void bswap_sym(struct elf_sym *sym) bswap16s(&sym->st_shndx); } +static void bswap_note(struct elf_note *en) +{ + bswap32s(&en->n_namesz); + bswap32s(&en->n_descsz); + bswap32s(&en->n_type); +} + #else /* ! BSWAP_NEEDED */ static void bswap_ehdr(struct elfhdr *ehdr) { } static void bswap_phdr(struct elf_phdr *phdr, int phnum) { } static void bswap_shdr(struct elf_shdr *shdr, int shnum) { } static void bswap_sym(struct elf_sym *sym) { } +static void bswap_note(struct elf_note *en) { } #endif /* ! BSWAP_NEEDED */ +#include "elfcore.c" + /* * 'copy_elf_strings()' copies argument/envelope strings from user * memory to free pages in kernel mem. These are in a format ready @@ -834,6 +846,12 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, info->entry = elf_entry; +#ifdef USE_ELF_CORE_DUMP + bprm->core_dump = &elf_core_dump; +#else + bprm->core_dump = NULL; +#endif + return 0; } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 3685156123..8d20554688 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -51,6 +51,7 @@ extern enum BSDType bsd_type; * kernel */ struct image_info { + abi_ulong load_bias; abi_ulong load_addr; abi_ulong start_code; abi_ulong end_code; @@ -65,6 +66,9 @@ struct image_info { abi_ulong entry; abi_ulong code_offset; abi_ulong data_offset; + abi_ulong arg_start; + abi_ulong arg_end; + uint32_t elf_flags; }; #define MAX_SIGQUEUE_SIZE 1024 @@ -132,6 +136,7 @@ struct bsd_binprm { char **envp; char *filename; /* (Given) Name of binary */ char *fullpath; /* Full path of binary */ + int (*core_dump)(int, CPUArchState *); }; void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); @@ -145,6 +150,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info); int load_flt_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info); +int is_target_elf_binary(int fd); abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len);