From patchwork Tue Feb 27 18:48:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 776284 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp309107wro; Tue, 27 Feb 2024 10:51:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUoa8hO0Is+yf6pqg80F7oV6vCBcdXRzK8jP+1cFrswLE80iscU+43CIhhnt5Po3oen8GqP7I+1fYQeMel51cm2 X-Google-Smtp-Source: AGHT+IEd7tW7hfENBS5elUb5ALzzhgWX55ajHR9bRW7Qji3kW9HqKcBVEA9XNvK/VmQaLbOknQfm X-Received: by 2002:a05:622a:1755:b0:42e:80bb:f25b with SMTP id l21-20020a05622a175500b0042e80bbf25bmr8659320qtk.60.1709059882268; Tue, 27 Feb 2024 10:51:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709059882; cv=none; d=google.com; s=arc-20160816; b=wsWST/E3bcZ7Oa/QdDEnlvfPKG5eFV6YC/bilHm9EwGYt8GT3fV64v24kSINeXtaNX NHB4U8DhUm+kq5s4LBs85z1HmSFL+U0XFQhmZPcBDkmzhiP+hwalugMapVaW7USgT7EI /uRsaKsQ+XFqf/SY0QCO/0rhda4lhtvg5oN3pQi0i68seuZyJvg2k3yaeKG8tmDqiMzN 97WsoIJdyFV6TLNFfJbs4wylY9o703X8fypO60FdJI7+PU3ICGLFeNHINoZUAvkMAUs3 /eS4rjVDQgupvF+WFJgLlHYlBKvvOax98S/WGgy6ItSUyufTrHCZ9rpJ8OZC8L73ryVw XMSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; fh=Vvliz9ENSk/yCY42nG87aL5dW+Zo0lduSx74U3lH2V8=; b=UiB3Ag9nhDJe7kYob81vWT1R7gt65nWOMR1MvCnuDAGIvf3NIQ/wGG0/8jNRggfief W/2dAQMwHBAHDnOloDo89g9ewxEWMTN9oE+vJelK1EJHCWqAeh9saQZ02LM2//kB4wUt sTXJ52m9DM2tYNoWCkK00A/Jt1JzhKmBjCYbzPc0HOEJU43krUygwtZoSMpl3qFIeXDQ OJqQUepfniTd3x4S9sVlH24TDU/jIQFzISBT5hEaFj1JooPJRvRBWVaRo41jQ4MmZFba 5fyADni1rN2NjDa+ODe8opbnlghW8Hu4Z5MsvNPhlBXf9kESfYWsoPyDqR4wjOnldClN 6+PA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OxK0o86D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k18-20020ac85fd2000000b0042e816dce4asi6174150qta.506.2024.02.27.10.51.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 10:51:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OxK0o86D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VT-0006WZ-8N; Tue, 27 Feb 2024 13:48:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rf2VR-0006Vy-83 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:45 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VP-0001TM-LJ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:44 -0500 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6da202aa138so3146822b3a.2 for ; Tue, 27 Feb 2024 10:48:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059722; x=1709664522; darn=nongnu.org; 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=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=OxK0o86DootcJA/PGAIEqljBMZ2pcp5uozj74eTAIIF7l8CDGiujiSMd7d0rKtfGGW 8hLBmHrFV8r+wqEcV8LamQm/8isQ3IjYM/lzhfYZ05oEoenj6IQvCufH+HcFRKgjYY0F K6l9rPw9kjj3nDVj9NcfHIYzRq6wLezNaXVO33NG5jxgA6A2NcirkOsYJEAsoy3BfQSv hF7OJ2/EGRx4mFEFS6HRUwl3sH5iPdu14oimDHcyIYC/UVXcpmokFTAHkScktD/hVDlF FXbhLdcLlNvzuuqjZfy8fstYm/KsyEGy81g22kZgoPD451NEi3N7LMA68tnZcpD4rfv+ 384A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059722; x=1709664522; 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=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=bLBybGEm0OF3BSCZUfz5/fBIPPktopZoh0hiyTqmId5lGtYeLKCc2lFR/uezBos2Q8 tT3n3rO5yBNwk7S/lsp6liB2l7gtbveRH8ouH1uFAofyYL7k6CNQ5B/A+mH/ltFWILCa fAaft0bbXi4aKPVcZ5QX6+LoW9clqJDCKggtIYoRmDiFLs/wTZae15LndobPd1yN3EcP /Qb+fZ+LAC9DdUfIP8FV+jQuRGAG4mVCS4quLt0ZbUJaHTSr2pbHkDlHDDXTJivyVtfC 857PXcCvrvMz+SlFJSXPGmzi/fYwCxP4k7x0TXDPjilWZH4tnoCabW15nAwt3aDOWyNN 1aKA== X-Gm-Message-State: AOJu0Yx5EPQBNz8oqiI+5qpZR3Dlmuh2uvHfyP+QAv3sLSrfRTA+RXy6 PtBk2YjVQzIoBr05GcFQkS9i2n3nRUMWpaGb0Ursn97Pj/4Uwc2MkfauTycAaJzkl4TgLopN0cK B X-Received: by 2002:a05:6a00:987:b0:6e5:8d9:d59a with SMTP id u7-20020a056a00098700b006e508d9d59amr11052223pfg.16.1709059722234; Tue, 27 Feb 2024 10:48:42 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:41 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 04/14] linux-user/elfload: Stack allocate struct mm_struct Date: Tue, 27 Feb 2024 08:48:23 -1000 Message-Id: <20240227184833.193836-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Ignoring the fact that g_malloc cannot fail, the structure is quite small and might as well be allocated locally. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index cc43487a37..98b82b1a49 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4099,7 +4099,7 @@ struct mm_struct { int mm_count; /* number of mappings */ }; -static struct mm_struct *vma_init(void); +static void vma_init(struct mm_struct *); static void vma_delete(struct mm_struct *); static int vma_add_mapping(struct mm_struct *, target_ulong, target_ulong, abi_ulong); @@ -4174,17 +4174,10 @@ static inline void bswap_note(struct elf_note *en) { } * thread that received the signal is stopped. */ -static struct mm_struct *vma_init(void) +static void vma_init(struct mm_struct *mm) { - struct mm_struct *mm; - - if ((mm = g_malloc(sizeof (*mm))) == NULL) - return (NULL); - mm->mm_count = 0; QTAILQ_INIT(&mm->mm_mmap); - - return (mm); } static void vma_delete(struct mm_struct *mm) @@ -4195,7 +4188,6 @@ static void vma_delete(struct mm_struct *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, @@ -4638,7 +4630,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) struct elfhdr elf; struct elf_phdr phdr; struct rlimit dumpsize; - struct mm_struct *mm = NULL; + struct mm_struct mm; off_t offset = 0, data_offset = 0; int segs = 0; int fd = -1; @@ -4664,11 +4656,10 @@ static int elf_core_dump(int signr, const CPUArchState *env) * set up structure containing this information. After * this point vma_xxx functions can be used. */ - if ((mm = vma_init()) == NULL) - goto out; + vma_init(&mm); - walk_memory_regions(mm, vma_walker); - segs = vma_get_mapping_count(mm); + walk_memory_regions(&mm, vma_walker); + segs = vma_get_mapping_count(&mm); /* * Construct valid coredump ELF header. We also @@ -4701,7 +4692,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) * Write program headers for memory regions mapped in * the target process. */ - for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) { + for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { (void) memset(&phdr, 0, sizeof (phdr)); phdr.p_type = PT_LOAD; @@ -4738,7 +4729,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) /* * Finally we can dump process memory into corefile as well. */ - for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) { + for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { abi_ulong addr; abi_ulong end; @@ -4767,8 +4758,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) out: free_note_info(&info); - if (mm != NULL) - vma_delete(mm); + vma_delete(&mm); (void) close(fd); if (errno != 0)