From nobody Mon Feb 9 07:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528895446688340.31531994846875; Wed, 13 Jun 2018 06:10:46 -0700 (PDT) Received: from localhost ([::1]:34107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT5Xt-0005YD-5M for importer@patchew.org; Wed, 13 Jun 2018 09:10:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT5SH-0001Wu-8Q for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fT5SE-0005SI-Ry for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:53 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35194) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fT5SE-0005PE-J1 for qemu-devel@nongnu.org; Wed, 13 Jun 2018 09:04:50 -0400 Received: by mail-wm0-x236.google.com with SMTP id j15-v6so5322957wme.0 for ; Wed, 13 Jun 2018 06:04:50 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id h7-v6sm1736493wmb.48.2018.06.13.06.04.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 06:04:45 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DB8EC3E12A1; Wed, 13 Jun 2018 13:56:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bp/1YbPML67ffji3kuZga7TLev+DhxX9wc1+8T4FSYo=; b=ECj7tu4fjh4/8D9TnUj4U3q9JfAeovlW40BMCtdoXVmWCtEEPbC2Ql3KTY2vvt3TQb fj1hu5UZj8TaNNmtnF0E6txsC9QC0+T1Np6YrGdBEL4ThYmrruTEN12aRG9BVg9/TKUc DhPxoadhLxFmb5hn98SL4uup3nsA0uWRuaNlw= 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=Bp/1YbPML67ffji3kuZga7TLev+DhxX9wc1+8T4FSYo=; b=FV6835pbhRaRdz7neEklvW2lEnlMopqiss0i/5RJNEx1nYZCnMgZSoG9QEQu/RybKQ 4QwbLEeE+7jAfffiz3Eq41krurQIjoQ15gFKL+ONrCXwuXvlilSZXPyNbWa5AqS3ZNan aI21Ewkj6t1KsitET9Waudu25tmLH4s7X3hHZuFkPondAum8mlvDbIIf7sHiJFVOEG8f OmdWLqJlO5/hN8Nh1JkVrZjzOe7Wdx0x3UXi2+4pSKjCUHBa1KnTfJqkEHCRbOSU+mpn dpCZaWYWb7YcCMKyAyhoongEtExUaII0YfhMIt9n1zALJvwqYDRAQTGXugWwc4qLiFVp igqQ== X-Gm-Message-State: APt69E0uUL9hrs325ys4Cxy3HQRXPIYAAeHsghMCq+hhTFbvJDPv7sex 0+YFtAzuTcyBf5ItFACj8LbCtg== X-Google-Smtp-Source: ADUXVKJjWkrJB5NEY5muC1z6dhFHcM/GDXK/6n9j0uKzxjag4aF1qqUsJUstAB5IHyPfNkKqr00GeQ== X-Received: by 2002:a1c:d650:: with SMTP id n77-v6mr3704750wmg.140.1528895089453; Wed, 13 Jun 2018 06:04:49 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 13 Jun 2018 13:55:53 +0100 Message-Id: <20180613125601.14371-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180613125601.14371-1-alex.bennee@linaro.org> References: <20180613125601.14371-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::236 Subject: [Qemu-devel] [RISU PATCH v3 14/22] risu: add process_arch_opt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Richard Henderson Allows the backend to do more that just set a flag when it comes to processing options. Signed-off-by: Richard Henderson [AJB: tweaked order, added stdlib includes] Signed-off-by: Alex Benn=C3=A9e --- risu.c | 33 +++++++++++---------------------- risu.h | 7 +++++-- risu_reginfo_aarch64.c | 10 ++++++++-- risu_reginfo_arm.c | 14 ++++++++++---- risu_reginfo_m68k.c | 10 ++++++++-- risu_reginfo_ppc64.c | 10 ++++++++-- 6 files changed, 50 insertions(+), 34 deletions(-) diff --git a/risu.c b/risu.c index 18de351..01525d2 100644 --- a/risu.c +++ b/risu.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -27,7 +26,6 @@ #include =20 #include "config.h" - #include "risu.h" =20 void *memblock; @@ -287,7 +285,7 @@ void usage(void) } } =20 -struct option * setup_options(char **short_opts) +static struct option * setup_options(char **short_opts) { static struct option default_longopts[] =3D { {"help", no_argument, 0, '?'}, @@ -303,20 +301,19 @@ struct option * setup_options(char **short_opts) =20 if (arch_long_opts) { const size_t osize =3D sizeof(struct option); - const int default_count =3D ARRAY_SIZE(default_longopts); - struct option *dptr; - int extra_count =3D 0; + const int default_count =3D ARRAY_SIZE(default_longopts) - 1; + int arch_count; =20 /* count additional opts */ - dptr =3D arch_long_opts; - do {} while (dptr[extra_count++].name); + for (arch_count =3D 0; arch_long_opts[arch_count].name; arch_count= ++) { + continue; + } =20 - lopts =3D calloc(default_count + extra_count, osize); + lopts =3D calloc(default_count + arch_count + 1, osize); =20 /* Copy default opts + extra opts */ memcpy(lopts, default_longopts, default_count * osize); - dptr =3D &lopts[default_count - 1]; - memcpy(dptr, arch_long_opts, extra_count * osize); + memcpy(lopts + default_count, arch_long_opts, arch_count * osize); } =20 return lopts; @@ -343,34 +340,26 @@ int main(int argc, char **argv) =20 switch (c) { case 0: - { /* flag set by getopt_long, do nothing */ break; - } case 't': - { trace_fn =3D optarg; trace =3D 1; break; - } case 'h': - { hostname =3D optarg; break; - } case 'p': - { /* FIXME err handling */ port =3D strtol(optarg, 0, 10); break; - } case '?': - { usage(); exit(1); - } default: - abort(); + assert(c >=3D FIRST_ARCH_OPT); + process_arch_opt(c, optarg); + break; } } =20 diff --git a/risu.h b/risu.h index 89811f4..48c50d9 100644 --- a/risu.h +++ b/risu.h @@ -16,10 +16,13 @@ #include #include #include +#include =20 /* Extra option processing for architectures */ -extern void *arch_long_opts; -extern char *arch_extra_help; +extern const struct option * const arch_long_opts; +extern const char * const arch_extra_help; +void process_arch_opt(int opt, const char *arg); +#define FIRST_ARCH_OPT 0x100 =20 /* GCC computed include to pull in the correct risu_reginfo_*.h for * the architecture. diff --git a/risu_reginfo_aarch64.c b/risu_reginfo_aarch64.c index ab12270..c270e0b 100644 --- a/risu_reginfo_aarch64.c +++ b/risu_reginfo_aarch64.c @@ -14,12 +14,18 @@ #include #include #include /* for FPSIMD_MAGIC */ +#include =20 #include "risu.h" #include "risu_reginfo_aarch64.h" =20 -void *arch_long_opts; -char *arch_extra_help; +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} =20 /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc) diff --git a/risu_reginfo_arm.c b/risu_reginfo_arm.c index 5acad02..12ad0ef 100644 --- a/risu_reginfo_arm.c +++ b/risu_reginfo_arm.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include =20 #include "risu.h" #include "risu_reginfo_arm.h" @@ -22,13 +22,19 @@ extern int insnsize(ucontext_t *uc); =20 /* Should we test for FP exception status bits? */ static int test_fp_exc; -static struct option extra_opts[] =3D { +static const struct option extra_opts[] =3D { {"test-fp-exc", no_argument, &test_fp_exc, 1}, {0, 0, 0, 0} }; =20 -void *arch_long_opts =3D &extra_opts[0]; -char *arch_extra_help =3D " --test-fp-exc Check FP exception bits whe= n comparing\n"; +const struct option * const arch_long_opts =3D &extra_opts[0]; +const char * const arch_extra_help =3D + " --test-fp-exc Check FP exception bits when comparing\n"; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} =20 static void reginfo_init_vfp(struct reginfo *ri, ucontext_t *uc) { diff --git a/risu_reginfo_m68k.c b/risu_reginfo_m68k.c index d429502..7a1c5a9 100644 --- a/risu_reginfo_m68k.c +++ b/risu_reginfo_m68k.c @@ -10,12 +10,18 @@ #include #include #include +#include =20 #include "risu.h" #include "risu_reginfo_m68k.h" =20 -void *arch_long_opts; -char *arch_extra_help; +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} =20 /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc) diff --git a/risu_reginfo_ppc64.c b/risu_reginfo_ppc64.c index 395111c..4b70460 100644 --- a/risu_reginfo_ppc64.c +++ b/risu_reginfo_ppc64.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include "risu.h" #include "risu_reginfo_ppc64.h" @@ -22,8 +23,13 @@ #define XER 37 #define CCR 38 =20 -void *arch_long_opts; -char *arch_extra_help; +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} =20 /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc) --=20 2.17.1