public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>, Alan Modra <amodra@gmail.com>
Subject: [PATCH 3/8] x86: change fetch error handling in ckprefix()
Date: Tue, 4 Apr 2023 08:59:17 +0200	[thread overview]
Message-ID: <838292bd-8855-00af-59c8-fcf0acb34d5c@suse.com> (raw)
In-Reply-To: <5dac45a8-cd5f-ee4d-52fc-7d283fc29ec4@suse.com>

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".

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -8921,7 +8921,11 @@ static const struct dis386 rm_table[][8]
 #define BND_PREFIX	0x04
 #define NOTRACK_PREFIX	0x05
 
-static int
+static enum {
+  ckp_okay,
+  ckp_bogus,
+  ckp_fetch_error,
+}
 ckprefix (instr_info *ins)
 {
   int newrex, i, length;
@@ -8931,7 +8935,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 = 0;
       switch (*ins->codep)
 	{
@@ -8955,7 +8960,7 @@ ckprefix (instr_info *ins)
 	  if (ins->address_mode == mode_64bit)
 	    newrex = *ins->codep;
 	  else
-	    return 1;
+	    return ckp_okay;
 	  ins->last_rex_prefix = i;
 	  break;
 	case 0xf3:
@@ -9023,27 +9028,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 = ins->rex;
-	      return 1;
+	      return ins->rex ? ckp_bogus : ckp_okay;
 	    }
 	  ins->prefixes = PREFIX_FWAIT;
 	  break;
 	default:
-	  return 1;
+	  return ckp_okay;
 	}
       /* Rex is ignored when followed by another prefix.  */
       if (ins->rex)
-	{
-	  ins->rex_used = ins->rex;
-	  return 1;
-	}
+	return ckp_bogus;
       if (*ins->codep != FWAIT_OPCODE)
 	ins->all_prefixes[i++] = *ins->codep;
       ins->rex = newrex;
       ins->codep++;
       length++;
     }
-  return 0;
+  return ckp_bogus;
 }
 
 /* Return the name of the prefix byte PREF, or NULL if PREF is not a
@@ -9886,8 +9887,12 @@ print_insn (bfd_vma pc, disassemble_info
 
   sizeflag = priv.orig_sizeflag;
 
-  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 = 0;
 	   i < (int) ARRAY_SIZE (ins.all_prefixes) && ins.all_prefixes[i];
@@ -9896,6 +9901,9 @@ print_insn (bfd_vma pc, disassemble_info
 			 (i == 0 ? "" : " "),
 			 prefix_name (&ins, ins.all_prefixes[i], sizeflag));
       return i;
+
+    case ckp_fetch_error:
+      return fetch_error (&ins);
     }
 
   ins.insn_codep = ins.codep;


  parent reply	other threads:[~2023-04-04  6:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04  6:56 [PATCH 0/8] x86: do away with (ab)using setjmp/longjmp for error handling Jan Beulich
2023-04-04  6:58 ` [PATCH 1/8] x86: move fetch error handling into a helper function Jan Beulich
2023-04-04  6:58 ` [PATCH 2/8] x86: change fetch error handling in top-level function Jan Beulich
2023-04-04  6:59 ` Jan Beulich [this message]
2023-04-04  6:59 ` [PATCH 4/8] x86: change fetch error handling in get_valid_dis386() Jan Beulich
2023-04-04  7:00 ` [PATCH 5/8] x86: change fetch error handling when processing operands Jan Beulich
2023-04-04  7:00 ` [PATCH 6/8] x86: change fetch error handling for get<N>() Jan Beulich
2023-04-04  7:01 ` [PATCH 7/8] x86: drop use of setjmp() from disassembler Jan Beulich
2023-04-04  7:01 ` [PATCH 8/8] x86: drop (explicit) BFD64 dependency " Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=838292bd-8855-00af-59c8-fcf0acb34d5c@suse.com \
    --to=jbeulich@suse.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).