From patchwork Tue Feb 27 18:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 776283 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp309063wro; Tue, 27 Feb 2024 10:51:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUkmS2ltFoQPAQ4HHEelRzumG/fE/4uR1mEs+3Hd2FO8+Ux+tQPr7i1r39Qke4lN5DAUlqQEW8mmZG0pM9xjESi X-Google-Smtp-Source: AGHT+IEX4a5nolqwfbvMlwjeaoS6tlh/tg7N92ENF5p9UKEQofo4f14h1Z/3cx2u/KHV0eyL3tBi X-Received: by 2002:ad4:5cc6:0:b0:68f:309d:986 with SMTP id iu6-20020ad45cc6000000b0068f309d0986mr3645209qvb.17.1709059873535; Tue, 27 Feb 2024 10:51:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709059873; cv=none; d=google.com; s=arc-20160816; b=W6xX8H6VQV1XRLBfClNZFH3/wgo0C3jE6zaOvYq6S+rt5M3JTIztY6bq62Dgsd6AEC TCXmNW/POFTarm1QGIOGzz9ud65cwPl8jMf3PZKvOV3tvbcP2SZ004A6MbIw6MhvjiVN nC1i8cUogR4Qis6/v7Np+VBbTllR5KfCCwCfXvO9h/6yF65aZai2AMcpodQkboY+yFnh RLeAxEfRtxGmhbk7jQJsaXVRLEpudd9w1BdXHGVElWL7hKU9flLGIW30jqGkE4WqnjaH j8O83NDPCv6Lhxfunz3g8dkyugtmPrCAoJLa0/aq142pFIb/mzHKrU7+WLER2IYMvnBH QDIQ== 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=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; fh=Vvliz9ENSk/yCY42nG87aL5dW+Zo0lduSx74U3lH2V8=; b=q/j+0+ythDMBKs+R+viPM4nLwNAXkRe0TdtNHhZALDEqER8F1IgG+rhQjOvor12WZw gOaBiK74FYctSVyMRDoWrICr/+QOFHxFOhwQ9Bly9RcQIm8rtwF5dGSfGyii2Gs9K/IL fQx42Ejz+XF68udv6BT2x1VRuwMn20SaFEocPmYh9fWp1RgM7bkNBLL5ZhlV29u9UI5X BK+xQim3DoMAn+YpzZpSF3bWQFmNUAbgKy0mKgROgqQdcULWYe03P5vPjRVm18PPg1nK +RR8hPFxCh2su9hKgi/CjzTeJnxhX7A54M6ySOdFOPhiKUEULBOU09nWYv3157FMzlBV ZVKg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H8CbB2Ob; 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 gv3-20020a056214262300b0068cb0aa2ec6si8330306qvb.518.2024.02.27.10.51.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 10:51:13 -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=H8CbB2Ob; 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 1rf2VV-0006Xi-4I; Tue, 27 Feb 2024 13:48:49 -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 1rf2VT-0006Wb-Hs for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:47 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VS-0001Tp-4p for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:47 -0500 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c1a7d51fb5so1209222b6e.1 for ; Tue, 27 Feb 2024 10:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059725; x=1709664525; 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=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=H8CbB2ObOaECqOHiTpuCP40k83kMXOXglRn98bVANnPu4CuOSbphs5JzntlE9p06XA DisI2QF3aWWfhMPD6GKsEiggz1z6iIZLWOBi+iNEU2Xnwdv9tkpEIGqpoTBg/0dxl5t4 B566IxnFyL5x3wJP4RcJYVLrfGxXPLr8y5fBRsOMYEEZv5PqRh0HdnyNNoJOnznZ1nxO jXjzfmrNSU7wlSlZYIHdti/0ylxRCaHTYnti0op0fDBnkoy/9ZXYZowEre/w3eE5YOwl QoawxWchR8tsrTQhzikZdOQXTbbVt0T/5nQ0TFkd0PXsxeUMPQR7BWCS9HV3ZKAtV8kI 0Lpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059725; x=1709664525; 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=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=JgLZunwSZi81ci/+f1ZQ5g0hnRRdzKvKChN1fOoDL/pS01Ip/ZDNPaB5ETM8VncEiT +3rMMlTJ9HwrL6j6661YeatsD8+b7wyAP4JCU9b3XWPUf+P+maubzKGpPKfJWoI1Xp5C Ik1AOrRuUlH6NW+QgHuGRJI2ob8Qa9lwmV6JMkDJe+GjRqzuM7yVYo8jmg3/O54fJ31/ Rz7hY6C/lzSdZ8sizf+kGu/SoRQknhBukHP43mVvtVuBPfSPpXVpza1WqqZeEhLUwLa/ Q2UKT/58NJS87LDzAl+1DKKmsutVQrPDh8JinUOJwnHn9a2aAWhrEHEs/kV+5ztXqIf3 wjzw== X-Gm-Message-State: AOJu0YyTkughH2cjgf8p8pG3N/taK18klJ93nU0TLYpactasJIGFrC+q XjUqtu8xBHnyFKOFcZTxDII63U49w8R+OZYpLDx1r51LGdSIQc5l07Lh6HynkhfEmjTYO80FDie a X-Received: by 2002:a05:6808:280e:b0:3bf:d775:616e with SMTP id et14-20020a056808280e00b003bfd775616emr2563878oib.53.1709059725010; Tue, 27 Feb 2024 10:48:45 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:44 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 06/14] linux-user/elfload: Open core file after vma_init Date: Tue, 27 Feb 2024 08:48:25 -1000 Message-Id: <20240227184833.193836-7-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::231; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x231.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 Swap the ordering of vma_init and open. This will be necessary for further changes, and adjusts the error cleanup path. Narrow the scope of corefile, as the variable can be freed immediately after use in open(). Signed-off-by: Richard Henderson --- linux-user/elfload.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 39d9ef9acc..877799e9c7 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4625,7 +4625,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) const CPUState *cpu = env_cpu((CPUArchState *)env); const TaskState *ts = (const TaskState *)cpu->opaque; struct vm_area_struct *vma = NULL; - g_autofree char *corefile = NULL; struct elf_note_info info; struct elfhdr elf; struct elf_phdr phdr; @@ -4644,12 +4643,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) return 0; } - corefile = core_dump_filename(ts); - - if ((fd = open(corefile, O_WRONLY | O_CREAT, - S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) - return (-errno); - /* * Walk through target process memory mappings and * set up structure containing this information. After @@ -4657,6 +4650,15 @@ static int elf_core_dump(int signr, const CPUArchState *env) */ vma_init(&mm); + { + g_autofree char *corefile = core_dump_filename(ts); + fd = open(corefile, O_WRONLY | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + } + if (fd < 0) { + goto out; + } + walk_memory_regions(&mm, vma_walker); segs = vma_get_mapping_count(&mm);