From: Richard Henderson Date: Tue, 16 Sep 2025 14:22:26 +0000 (-0700) Subject: target/arm: Split out alloc_cpreg X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9044ba55426437de89e05ef9c192a0a1b529b968;p=thirdparty%2Fqemu.git target/arm: Split out alloc_cpreg Include provision for a name suffix. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Peter Maydell --- diff --git a/target/arm/helper.c b/target/arm/helper.c index 8a8fa8c40e9..e36598e273b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7362,6 +7362,28 @@ void register_cp_regs_for_features(ARMCPU *cpu) #endif } +/* + * Copy a ARMCPRegInfo structure, allocating it along with the name + * and an optional suffix to the name. + */ +static ARMCPRegInfo *alloc_cpreg(const ARMCPRegInfo *in, + const char *name, const char *suffix) +{ + size_t name_len = strlen(name); + size_t suff_len = suffix ? strlen(suffix) : 0; + ARMCPRegInfo *out = g_malloc(sizeof(*in) + name_len + suff_len + 1); + char *p = (char *)(out + 1); + + *out = *in; + out->name = p; + + memcpy(p, name, name_len + 1); + if (suffix) { + memcpy(p + name_len, suffix, suff_len + 1); + } + return out; +} + /* * Private utility function for define_one_arm_cp_reg(): * add a single reginfo struct to the hash table. @@ -7374,7 +7396,6 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, CPUARMState *env = &cpu->env; ARMCPRegInfo *r2; bool ns = secstate & ARM_CP_SECSTATE_NS; - size_t name_len; /* Overriding of an existing definition must be explicitly requested. */ if (!(r->type & ARM_CP_OVERRIDE)) { @@ -7384,11 +7405,7 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, } } - /* Combine cpreg and name into one allocation. */ - name_len = strlen(name) + 1; - r2 = g_malloc(sizeof(*r2) + name_len); - *r2 = *r; - r2->name = memcpy(r2 + 1, name, name_len); + r2 = alloc_cpreg(r, name, NULL); /* * Update fields to match the instantiation, overwiting wildcards