]> xenbits.xensource.com Git - xen.git/commitdiff
x86emul: drop and avoid use of BUG()
authorJan Beulich <jbeulich@suse.com>
Mon, 26 Aug 2024 08:33:09 +0000 (10:33 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 26 Aug 2024 08:33:09 +0000 (10:33 +0200)
Generally it is not a good idea to use BUG() in emulator code. Even for
internal flaws we're better off returning errors to callers, rather than
crashing the system. Replace the sole remaining use and remove the
test / fuzzing harness surrogate. Put in place a declaration pleasing
the compiler when finding uses in Xen headers, while at the same time
breaking the build (at linking time) in case an active reference would
newly appear.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/tests/x86_emulator/x86-emulate.h
xen/arch/x86/x86_emulate/decode.c
xen/arch/x86/x86_emulate/private.h

index d2012ab767f39bb1744dc5dd246844a502cf604a..4fca051152703479de85de7a0e18b7eab74e04fd 100644 (file)
@@ -42,7 +42,6 @@
 
 #include <xen-tools/common-macros.h>
 
-#define BUG() abort()
 #define ASSERT assert
 #define ASSERT_UNREACHABLE() assert(!__LINE__)
 
index ee4cbdc0002cbd7a7823129096020b4e8907609e..5a880578c7c1e610e7e2f9c888d04e1cd0456bba 100644 (file)
@@ -1122,7 +1122,9 @@ int x86emul_decode(struct x86_emulate_state *s,
             switch ( def_ad_bytes )
             {
             default:
-                BUG(); /* Shouldn't be possible. */
+                ASSERT_UNREACHABLE(); /* Shouldn't be possible. */
+                return X86EMUL_UNHANDLEABLE;
+
             case 2:
                 if ( ctxt->regs->eflags & X86_EFLAGS_VM )
                     break;
index a2faa8b29b3a0c39fca402df73591d969760a3a0..f735bb6a5a65976d9e7d8edcde9640359391ccef 100644 (file)
@@ -15,6 +15,9 @@
 # include <asm/x86-vendors.h>
 # include <asm/x86_emulate.h>
 
+# undef BUG /* Make sure it's not used anywhere here. */
+void BUG(void);
+
 # ifndef CONFIG_HVM
 #  define X86EMUL_NO_FPU
 #  define X86EMUL_NO_MMX