From patchwork Mon Mar 11 19:12:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 779434 Delivered-To: patch@linaro.org Received: by 2002:a5d:604e:0:b0:33e:7753:30bd with SMTP id j14csp1690310wrt; Mon, 11 Mar 2024 12:22:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXqBy8UW+Gr+I/RJFQdh3oKYMMZXMOdCQaS60FuTpevbkrHRG4ENgULfqITD1IPvo0AfiOsvRLUx3ieGV8ah9KJ X-Google-Smtp-Source: AGHT+IEfOTD2W6k0Ulk2F7Gv7pEUQGTQirZSuWl/J9fgpOD6pijOKOrSpbGryShbF1s2JXYoZpqx X-Received: by 2002:ac8:5a91:0:b0:42e:ae64:396d with SMTP id c17-20020ac85a91000000b0042eae64396dmr9221773qtc.53.1710184937985; Mon, 11 Mar 2024 12:22:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710184937; cv=none; d=google.com; s=arc-20160816; b=rdc64gHgjshcpfbS/YksweEOGNDzhHhIVQRiVPBfuJK02XZJjFy406j99CBe4X1JWE E+teKe1KqOt15qPnLykEXPZgQ07+s3NzABdYZP8vyc33tsgQUAbsUoPHPw1TxoS/BEAs IIabxxn1m8kxv2wOrWZzsOLDbwHRXiJZtg8klSu4SCAMSdXbP3WC06uCnSmz7DkcoY1n 5QLci+hauathITD9Ly/0wRSSo6I1n1zFW7dokU0+iXDYFCJPur9YNYytkg7iqEKYQ4mK iwbuETel70wXYy1gQx3J9mmuSq+nN0ESRRbWlJADZPZIWDHz5h63VTECuKjEwntknFQu IJgg== 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:to:from :dkim-signature; bh=SGZNrXP3eEMFAkYdDHaYkmUoBTYEXbgmFV3euRom/N8=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=q7d2/c7hlW88HDtxRWXWDIkXd+yXUdmJlqNgV5mVeHGIhBzTHBW4yh+i/uWl3kvFJC BrgeQpwNVWgPHiORBpuq8hLTeUSd09rO1qMZfAbRuelJPVOkTzsFhQOkY7eUfqhBYlnv rfTF4yo7rW5VeHkFVFV5RuO7Ty73A/YTIY8t0BrkRMG3nqwgGHFd8WAWRU2eFsjtfh4k cMXcdx2f3aMPX6xkiftzriE9ut4pa+L9a364IETfpohcZARb+AqM1Sefn+IHSOkyC6Q8 7hOKwlcR8A8CQUMZ6MH1enpGIU7gzJWqx8a76RmaK7LtRQd9llk4Ip4cko/6w2J8YKWE tN9g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVfqPziU; 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 i2-20020ac85c02000000b0042ef2dcf970si6190201qti.298.2024.03.11.12.22.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2024 12:22:17 -0700 (PDT) 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=hVfqPziU; 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 1rjl9u-0007Hu-G9; Mon, 11 Mar 2024 15:18:02 -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 1rjl4x-0003OQ-HW for qemu-devel@nongnu.org; Mon, 11 Mar 2024 15:13:02 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450: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 1rjl4u-0000Ni-JF for qemu-devel@nongnu.org; Mon, 11 Mar 2024 15:12:55 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-513b1c69cb8so888985e87.1 for ; Mon, 11 Mar 2024 12:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710184371; x=1710789171; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SGZNrXP3eEMFAkYdDHaYkmUoBTYEXbgmFV3euRom/N8=; b=hVfqPziUAcHozo5wQjpWEcWYwT++u4PW7yHk8pqx4Lf/wtPSWYjkePAhC1tCm1NBkU lHXk4yeFDuc6hGKcMtXG59kROP7y80dCE9lL2njUfnAXNIAJ9vcy4PAH8LAKnaHVbYKH CpKafzs68YhRg15jfXzc8yloUFlo7MEzXGKWYaSML7WGxIdAjhHa8BxtHe8+vNKh03MM Ox+2pJtw8NHUMCyar1/d7lOZKgq4NzirdOA06+cuowxlt8ymQsabwIG2fGiKLAGqeuzZ jmQPTykgzuBC0q6E5ZfDMuVBFwJ2pEWzDejPKkL86U9qwK7YHwrEd0j1Sb9POZ344zZb us8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710184371; x=1710789171; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SGZNrXP3eEMFAkYdDHaYkmUoBTYEXbgmFV3euRom/N8=; b=d9NYcVgkSpMIhX8prm3XYnMfQLv58T2w29STQVkhsVpCBB1RxuhCBi0T0IyEF4/KpP XlBa5QWH42lEntSF51y+oihepFmcTUXWFrVRxB7/EXhQjci/e3BmR/9AoiGzoPO+mxkr Ws6ysSdQlW59PMoQRt5wxBM4CL7O2YAqgB+8Qz4DU5F0WNxslLAl/7E9JbHR9u7I9akq /3PuPS5QKORbwlDpUyttiZ95xL/16oTIweNlHWXww1Af4m+MAyyvL6tYLTpTuimZ52gi MvH4RgY/vDYNalvFgVre0xrAzrJhUIrWmt0C5Hw/bez5SG+OctBLcHqmK98gaP2Unybn ichQ== X-Gm-Message-State: AOJu0YxI4eagGO6Fi8q6ravFd2GfGLf4U1R+25gkYoymnVVVZVS3fGKf OmpmaxJW2Bl1upzS36CS1stLt+PqX56O7lEVQxqGR9Kmyph7ZnRB6Dd9YqdJydzYBM1gPLxY9cI y X-Received: by 2002:ac2:5a09:0:b0:513:45b7:91c2 with SMTP id q9-20020ac25a09000000b0051345b791c2mr4405200lfn.36.1710184370636; Mon, 11 Mar 2024 12:12:50 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t10-20020a05600c450a00b004131388d948sm14425266wmo.0.2024.03.11.12.12.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 12:12:50 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 17/20] contrib/elf2dmp: Use GPtrArray Date: Mon, 11 Mar 2024 19:12:38 +0000 Message-Id: <20240311191241.4177990-18-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240311191241.4177990-1-peter.maydell@linaro.org> References: <20240311191241.4177990-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12b; envelope-from=peter.maydell@linaro.org; helo=mail-lf1-x12b.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 From: Akihiko Odaki This removes the need to enumarate QEMUCPUState twice and saves code. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Tested-by: Viktor Prutyanov Message-id: 20240307-elf2dmp-v4-17-4f324ad4d99d@daynix.com Signed-off-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index a22c057d3ec..7d896cac5b1 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -66,7 +66,7 @@ static bool init_states(QEMU_Elf *qe) Elf64_Nhdr *start = (void *)((uint8_t *)qe->map + phdr[0].p_offset); Elf64_Nhdr *end = (void *)((uint8_t *)start + phdr[0].p_memsz); Elf64_Nhdr *nhdr; - size_t cpu_nr = 0; + GPtrArray *states; if (phdr[0].p_type != PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); @@ -74,38 +74,29 @@ static bool init_states(QEMU_Elf *qe) } qe->has_kernel_gs_base = 1; + states = g_ptr_array_new(); for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) { if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { QEMUCPUState *state = nhdr_get_desc(nhdr); if (state->size < sizeof(*state)) { - eprintf("CPU #%zu: QEMU CPU state size %u doesn't match\n", - cpu_nr, state->size); + eprintf("CPU #%u: QEMU CPU state size %u doesn't match\n", + states->len, state->size); /* * We assume either every QEMU CPU state has KERNEL_GS_BASE or * no one has. */ qe->has_kernel_gs_base = 0; } - cpu_nr++; + g_ptr_array_add(states, state); } } - printf("%zu CPU states has been found\n", cpu_nr); + printf("%u CPU states has been found\n", states->len); - qe->state = g_new(QEMUCPUState*, cpu_nr); - - cpu_nr = 0; - - for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) { - if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { - qe->state[cpu_nr] = nhdr_get_desc(nhdr); - cpu_nr++; - } - } - - qe->state_nr = cpu_nr; + qe->state_nr = states->len; + qe->state = (void *)g_ptr_array_free(states, FALSE); return true; }