From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id EFD473858D37; Fri, 21 Apr 2023 10:10:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFD473858D37 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] x86: change fetch error handling in ckprefix() X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: 06173b5d0926a76c9d1af832d76636f80fc04413 X-Git-Newrev: bf4d07d5394c370b5d52e99e5adf0e53fa342928 Message-Id: <20230421101045.EFD473858D37@sourceware.org> Date: Fri, 21 Apr 2023 10:10:45 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Apr 2023 10:10:46 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dbf4d07d5394c= 370b5d52e99e5adf0e53fa342928 commit bf4d07d5394c370b5d52e99e5adf0e53fa342928 Author: Jan Beulich Date: Fri Apr 21 12:08:15 2023 +0200 x86: change fetch error handling in ckprefix() =20 Use a tristate (enum) return value type to be able to express all three cases which are of interest to the (sole) caller. This also allows doing away with the abuse of "rex_used". Diff: --- opcodes/i386-dis.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 393522f37ac..60bfa41a5ad 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -8953,7 +8953,11 @@ static const struct dis386 rm_table[][8] =3D { #define BND_PREFIX 0x04 #define NOTRACK_PREFIX 0x05 =20 -static int +static enum { + ckp_okay, + ckp_bogus, + ckp_fetch_error, +} ckprefix (instr_info *ins) { int newrex, i, length; @@ -8963,7 +8967,8 @@ ckprefix (instr_info *ins) /* The maximum instruction length is 15bytes. */ while (length < MAX_CODE_LENGTH - 1) { - FETCH_DATA (ins->info, ins->codep + 1); + if (!fetch_code (ins->info, ins->codep + 1)) + return ckp_fetch_error; newrex =3D 0; switch (*ins->codep) { @@ -8987,7 +8992,7 @@ ckprefix (instr_info *ins) if (ins->address_mode =3D=3D mode_64bit) newrex =3D *ins->codep; else - return 1; + return ckp_okay; ins->last_rex_prefix =3D i; break; case 0xf3: @@ -9055,27 +9060,23 @@ ckprefix (instr_info *ins) ins->codep++; /* This ensures that the previous REX prefixes are noticed as unused prefixes, as in the return case below. */ - ins->rex_used =3D ins->rex; - return 1; + return ins->rex ? ckp_bogus : ckp_okay; } ins->prefixes =3D PREFIX_FWAIT; break; default: - return 1; + return ckp_okay; } /* Rex is ignored when followed by another prefix. */ if (ins->rex) - { - ins->rex_used =3D ins->rex; - return 1; - } + return ckp_bogus; if (*ins->codep !=3D FWAIT_OPCODE) ins->all_prefixes[i++] =3D *ins->codep; ins->rex =3D newrex; ins->codep++; length++; } - return 0; + return ckp_bogus; } =20 /* Return the name of the prefix byte PREF, or NULL if PREF is not a @@ -9918,8 +9919,12 @@ print_insn (bfd_vma pc, disassemble_info *info, int = intel_syntax) =20 sizeflag =3D priv.orig_sizeflag; =20 - if (!ckprefix (&ins) || ins.rex_used) + switch (ckprefix (&ins)) { + case ckp_okay: + break; + + case ckp_bogus: /* Too many prefixes or unused REX prefixes. */ for (i =3D 0; i < (int) ARRAY_SIZE (ins.all_prefixes) && ins.all_prefixes[i]; @@ -9928,6 +9933,9 @@ print_insn (bfd_vma pc, disassemble_info *info, int i= ntel_syntax) (i =3D=3D 0 ? "" : " "), prefix_name (&ins, ins.all_prefixes[i], sizeflag)); return i; + + case ckp_fetch_error: + return fetch_error (&ins); } =20 ins.insn_codep =3D ins.codep;