From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7897) id 4E2663853D7C; Mon, 21 Nov 2022 14:37:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E2663853D7C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669041429; bh=0N+Mj/96UoCVAkg0yKBcVC9HGBZzpxJVUMNaOYb8/GM=; h=From:To:Subject:Date:From; b=XvQsaw+wtp2gRzP/Wc2ygziA42lYIxTGqnRICOz9dXoEOGWP3TQUQrdi8Nk9cUBhu RYUz1CMHUSVBn0Yv5wkk9ysA7Go/0nEc3YXpQ2+MI4JCCrv/+LJwwW+wW20wxdrbF0 KayDlXndduCoFxM9UWgwqsuMlSP03d5vCavBWsg0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Torbjorn Svensson To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/arm: Ensure that stack pointers are in sync X-Act-Checkin: binutils-gdb X-Git-Author: =?utf-8?q?Torbj=C3=B6rn_SVENSSON?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 4d9fd8683fd48f081cb205afed07ba69f9aed134 X-Git-Newrev: b0b23e06c3a2e3b92d6f12d99650c7d1cc5d939c Message-Id: <20221121143709.4E2663853D7C@sourceware.org> Date: Mon, 21 Nov 2022 14:37:09 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db0b23e06c3a2= e3b92d6f12d99650c7d1cc5d939c commit b0b23e06c3a2e3b92d6f12d99650c7d1cc5d939c Author: Torbj=C3=B6rn SVENSSON Date: Fri Nov 4 13:58:31 2022 +0100 gdb/arm: Ensure that stack pointers are in sync =20 For targets with secext, msp and psp can be seen as an alias for one of msp_s, msp_ns, psp_s or psp_ns. Without this patch, sp might be secure, but msp or psp is non-secure (this state can not happen in the hardware). =20 Signed-off-by: Torbj=C3=B6rn SVENSSON Diff: --- gdb/arm-tdep.c | 90 ++++++++++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 124a94dc87d..f748df83e56 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -324,20 +324,6 @@ reconstruct_t_bit(struct gdbarch *gdbarch, CORE_ADDR l= r, ULONGEST psr) return psr; } =20 -/* Initialize stack pointers, and flag the active one. */ - -static inline void -arm_cache_init_sp (int regnum, CORE_ADDR* member, - struct arm_prologue_cache *cache, - frame_info_ptr frame) -{ - CORE_ADDR val =3D get_frame_register_unsigned (frame, regnum); - if (val =3D=3D cache->sp) - cache->active_sp_regnum =3D regnum; - - *member =3D val; -} - /* Initialize CACHE fields for which zero is not adequate (CACHE is expected to have been ZALLOC'ed before calling this function). */ =20 @@ -362,34 +348,82 @@ arm_cache_init (struct arm_prologue_cache *cache, fra= me_info_ptr frame) =20 if (tdep->have_sec_ext) { - CORE_ADDR msp_val =3D get_frame_register_unsigned (frame, tdep->m_pr= ofile_msp_regnum); - CORE_ADDR psp_val =3D get_frame_register_unsigned (frame, tdep->m_pr= ofile_psp_regnum); - - arm_cache_init_sp (tdep->m_profile_msp_s_regnum, &cache->msp_s, cach= e, frame); - arm_cache_init_sp (tdep->m_profile_psp_s_regnum, &cache->psp_s, cach= e, frame); - arm_cache_init_sp (tdep->m_profile_msp_ns_regnum, &cache->msp_ns, ca= che, frame); - arm_cache_init_sp (tdep->m_profile_psp_ns_regnum, &cache->psp_ns, ca= che, frame); - + const CORE_ADDR msp_val + =3D get_frame_register_unsigned (frame, tdep->m_profile_msp_regnum); + const CORE_ADDR psp_val + =3D get_frame_register_unsigned (frame, tdep->m_profile_psp_regnum); + + cache->msp_s + =3D get_frame_register_unsigned (frame, tdep->m_profile_msp_s_regnum); + cache->msp_ns + =3D get_frame_register_unsigned (frame, tdep->m_profile_msp_ns_regnum); + cache->psp_s + =3D get_frame_register_unsigned (frame, tdep->m_profile_psp_s_regnum); + cache->psp_ns + =3D get_frame_register_unsigned (frame, tdep->m_profile_psp_ns_regnum); + + /* Identify what msp is alias for (msp_s or msp_ns). */ if (msp_val =3D=3D cache->msp_s) cache->active_msp_regnum =3D tdep->m_profile_msp_s_regnum; else if (msp_val =3D=3D cache->msp_ns) cache->active_msp_regnum =3D tdep->m_profile_msp_ns_regnum; + else + { + warning (_("Invalid state, unable to determine msp alias, assuming " + "msp_s.")); + cache->active_msp_regnum =3D tdep->m_profile_msp_s_regnum; + } + + /* Identify what psp is alias for (psp_s or psp_ns). */ if (psp_val =3D=3D cache->psp_s) cache->active_psp_regnum =3D tdep->m_profile_psp_s_regnum; else if (psp_val =3D=3D cache->psp_ns) cache->active_psp_regnum =3D tdep->m_profile_psp_ns_regnum; + else + { + warning (_("Invalid state, unable to determine psp alias, assuming " + "psp_s.")); + cache->active_psp_regnum =3D tdep->m_profile_psp_s_regnum; + } =20 - /* Use MSP_S as default stack pointer. */ - if (cache->active_sp_regnum =3D=3D ARM_SP_REGNUM) - cache->active_sp_regnum =3D tdep->m_profile_msp_s_regnum; + /* Identify what sp is alias for (msp_s, msp_ns, psp_s or psp_ns). = */ + if (msp_val =3D=3D cache->sp) + cache->active_sp_regnum =3D cache->active_msp_regnum; + else if (psp_val =3D=3D cache->sp) + cache->active_sp_regnum =3D cache->active_psp_regnum; + else + { + warning (_("Invalid state, unable to determine sp alias, assuming " + "msp.")); + cache->active_sp_regnum =3D cache->active_msp_regnum; + } } else if (tdep->is_m) { - arm_cache_init_sp (tdep->m_profile_msp_regnum, &cache->msp_s, cache,= frame); - arm_cache_init_sp (tdep->m_profile_psp_regnum, &cache->psp_s, cache,= frame); + cache->msp_s + =3D get_frame_register_unsigned (frame, tdep->m_profile_msp_s_regnum); + cache->psp_s + =3D get_frame_register_unsigned (frame, tdep->m_profile_psp_s_regnum); + + /* Identify what sp is alias for (msp or psp). */ + if (cache->msp_s =3D=3D cache->sp) + cache->active_sp_regnum =3D tdep->m_profile_msp_regnum; + else if (cache->psp_s =3D=3D cache->sp) + cache->active_sp_regnum =3D tdep->m_profile_psp_regnum; + else + { + warning (_("Invalid state, unable to determine sp alias, assuming " + "msp.")); + cache->active_sp_regnum =3D tdep->m_profile_msp_regnum; + } } else - arm_cache_init_sp (ARM_SP_REGNUM, &cache->msp_s, cache, frame); + { + cache->msp_s + =3D get_frame_register_unsigned (frame, ARM_SP_REGNUM); + + cache->active_sp_regnum =3D ARM_SP_REGNUM; + } } =20 /* Return the requested stack pointer value (in REGNUM), taking into