From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id 4CE6A395C05E; Fri, 26 May 2023 07:54:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CE6A395C05E 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: convert two pointers to (indexing) integers X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: d8acf3769314463ba7ed8262bf105a64f1f2e838 X-Git-Newrev: 1a3b4f90bc5fa5e71df1db8e663f76e262f3134d Message-Id: <20230526075408.4CE6A395C05E@sourceware.org> Date: Fri, 26 May 2023 07:54:08 +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, 26 May 2023 07:54:08 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1a3b4f90bc5f= a5e71df1db8e663f76e262f3134d commit 1a3b4f90bc5fa5e71df1db8e663f76e262f3134d Author: Jan Beulich Date: Fri May 26 09:53:51 2023 +0200 x86: convert two pointers to (indexing) integers =20 This in particular reduces the number of pointers to non-const that we have (and that could potentially be used for undue modification of state). As a result, fetch_code()'s 2nd parameter can then also become pointer-to-const. Diff: --- opcodes/i386-dis.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 55c70b6dd51..6f75abf57f3 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -161,9 +161,9 @@ struct instr_info char *obufp; char *mnemonicendp; const uint8_t *start_codep; - uint8_t *insn_codep; uint8_t *codep; const uint8_t *end_codep; + unsigned char nr_prefixes; signed char last_lock_prefix; signed char last_repz_prefix; signed char last_repnz_prefix; @@ -247,8 +247,8 @@ struct dis_private { bfd_vma insn_start; int orig_sizeflag; =20 - /* Points to first byte not fetched. */ - uint8_t *max_fetched; + /* Indexes first byte not fetched. */ + unsigned int fetched; uint8_t the_buffer[2 * MAX_CODE_LENGTH - 1]; }; =20 @@ -289,32 +289,31 @@ struct dis_private { to ADDR (exclusive) are valid. Returns true for success, false on error. */ static bool -fetch_code (struct disassemble_info *info, uint8_t *until) +fetch_code (struct disassemble_info *info, const uint8_t *until) { int status =3D -1; struct dis_private *priv =3D info->private_data; - bfd_vma start =3D priv->insn_start + (priv->max_fetched - priv->the_buff= er); + bfd_vma start =3D priv->insn_start + priv->fetched; + uint8_t *fetch_end =3D priv->the_buffer + priv->fetched; + ptrdiff_t needed =3D until - fetch_end; =20 - if (until <=3D priv->max_fetched) + if (needed <=3D 0) return true; =20 - if (until <=3D priv->the_buffer + ARRAY_SIZE (priv->the_buffer)) - status =3D (*info->read_memory_func) (start, - priv->max_fetched, - until - priv->max_fetched, - info); + if (priv->fetched + needed <=3D ARRAY_SIZE (priv->the_buffer)) + status =3D (*info->read_memory_func) (start, fetch_end, needed, info); if (status !=3D 0) { /* If we did manage to read at least one byte, then print_insn_i386 will do something sensible. Otherwise, print an error. We do that here because this is where we know STATUS. */ - if (priv->max_fetched =3D=3D priv->the_buffer) + if (!priv->fetched) (*info->memory_error_func) (status, start, info); return false; } =20 - priv->max_fetched =3D until; + priv->fetched +=3D needed; return true; } =20 @@ -9782,7 +9781,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int i= ntel_syntax) info->bytes_per_line =3D 7; =20 info->private_data =3D &priv; - priv.max_fetched =3D priv.the_buffer; + priv.fetched =3D 0; priv.insn_start =3D pc; =20 for (i =3D 0; i < MAX_OPERANDS; ++i) @@ -9814,7 +9813,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int i= ntel_syntax) goto fetch_error_out; } =20 - ins.insn_codep =3D ins.codep; + ins.nr_prefixes =3D ins.codep - ins.start_codep; =20 if (!fetch_code (info, ins.codep + 1)) { @@ -11829,7 +11828,9 @@ static bool BadOp (instr_info *ins) { /* Throw away prefixes and 1st. opcode byte. */ - ins->codep =3D ins->insn_codep + 1; + struct dis_private *priv =3D ins->info->private_data; + + ins->codep =3D priv->the_buffer + ins->nr_prefixes + 1; ins->obufp =3D stpcpy (ins->obufp, "(bad)"); return true; }