]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Replace uses of x86_decode_exinfo() with %pe
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 10 Jul 2017 10:35:04 +0000 (11:35 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 10 Aug 2017 18:43:38 +0000 (19:43 +0100)
x86_exc_decode_ec() and x86_decode_exinfo() are awkward to use, as they
require a local buffer of (unknown) sufficient size.

Make the functions local to decode.c and refactor the callsites to use %pe
instead.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/decode.c
arch/x86/include/arch/decode.h
arch/x86/traps.c
tests/fpu-exception-emulation/main.c
tests/invlpg/main.c
tests/vvmx/util.c
tests/xsa-191/main.c
tests/xsa-212/main.c

index 925eba25ca056ee2771730a848b2f88f7fe582b9..d9257867589c998dac9dfbafa99e485301833eb8 100644 (file)
@@ -37,7 +37,8 @@ const char *x86_exc_short_name(unsigned int exc)
     return (exc < ARRAY_SIZE(names) && names[exc]) ? names[exc] : "??";
 }
 
-int x86_exc_decode_ec(char *buf, size_t bufsz, unsigned int ev, unsigned int ec)
+static int x86_exc_decode_ec(char *buf, size_t bufsz,
+                             unsigned int ev, unsigned int ec)
 {
     switch ( ev )
     {
@@ -68,7 +69,7 @@ int x86_exc_decode_ec(char *buf, size_t bufsz, unsigned int ev, unsigned int ec)
     }
 }
 
-int x86_decode_exinfo(char *buf, size_t bufsz, exinfo_t info)
+static int x86_decode_exinfo(char *buf, size_t bufsz, exinfo_t info)
 {
     if ( !info )
         return snprintf(buf, bufsz, "nothing");
index 873b0b4b4738f2cbc1a45e509dba59bb1131d5d4..d65823fafe75ecd033a4a9a39056361875397084 100644 (file)
@@ -27,28 +27,6 @@ const char *x86_vendor_name(enum x86_vendor v);
  */
 const char *x86_exc_short_name(unsigned int ev);
 
-/**
- * Decodes an x86 error code into a readable form.
- *
- * @param buf Buffer to fill.
- * @param bufsz Size of @p buf.
- * @param ev Entry Vector.
- * @param ec Error Code.
- * @return snprintf(buf, bufsz, ...)
- */
-int x86_exc_decode_ec(char *buf, size_t bufsz,
-                      unsigned int ev, unsigned int ec);
-
-/**
- * Decodes an exinfo_t into a readable form.
- *
- * @param buf Buffer to fill.
- * @param bufsz Size of @p buf.
- * @param info exinfo_t value.
- * @return snprintf(buf, bufsz, ...)
- */
-int x86_decode_exinfo(char *buf, size_t bufsz, exinfo_t info);
-
 #endif /* XTF_X86_DECODE_H */
 
 /*
index 5804e0866ea2a4880f5834d7ed6a10223f87bf6d..a09c8e2873f2183fd606fd0c077344a2e1a29b8f 100644 (file)
@@ -41,25 +41,20 @@ void do_exception(struct cpu_regs *regs)
     /* Still unresolved? Give up and panic() with some relevent information. */
     if ( !safe )
     {
-        char buf[16];
-
-        x86_exc_decode_ec(buf, ARRAY_SIZE(buf),
-                          regs->entry_vector, regs->error_code);
+        exinfo_t ex = EXINFO(regs->entry_vector, regs->error_code);
 
         if ( regs->entry_vector == X86_EXC_PF )
         {
             unsigned long cr2 = read_cr2();
 
             panic("Unhandled exception at %04x:%p\n"
-                  "Vec %u %s[%s] %%cr2 %p\n",
-                  regs->cs, _p(regs->ip), regs->entry_vector,
-                  x86_exc_short_name(regs->entry_vector), buf, _p(cr2));
+                  "Vec %u %pe %%cr2 %p\n",
+                  regs->cs, _p(regs->ip), regs->entry_vector, _p(ex), _p(cr2));
         }
         else
             panic("Unhandled exception at %04x:%p\n"
-                  "Vec %u %s[%s]\n",
-                  regs->cs, _p(regs->ip), regs->entry_vector,
-                  x86_exc_short_name(regs->entry_vector), buf);
+                  "Vec %u %pe\n",
+                  regs->cs, _p(regs->ip), regs->entry_vector, _p(ex));
     }
 }
 
index c8eeb9eeb9016611ef7fcb3127627de7470e3d99..2e89f6148cc722c5bd144f0e8cbe3f193d07e0d2 100644 (file)
@@ -213,18 +213,15 @@ void run_sequence(const struct test_cfg *seq, unsigned int nr,
 
         if ( res != exp )
         {
-            char expstr[12], gotstr[12], cr0str[12];
-
-            x86_decode_exinfo(expstr, ARRAY_SIZE(expstr), exp);
-            x86_decode_exinfo(gotstr, ARRAY_SIZE(gotstr), res);
+            char cr0str[12];
 
             snprintf(cr0str, sizeof(cr0str), "%s%s%s",
                      t->cr0 & X86_CR0_EM ? " EM" : "",
                      t->cr0 & X86_CR0_MP ? " MP" : "",
                      t->cr0 & X86_CR0_TS ? " TS" : "");
 
-            xtf_failure("  Expected %s, got %s (cr0:%s)\n",
-                        expstr, gotstr, cr0str[0] ? cr0str : " - ");
+            xtf_failure("  Expected %pe, got %pe (cr0:%s)\n",
+                        _p(exp), _p(res), cr0str[0] ? cr0str : " - ");
         }
     }
 }
index 67429be14a4d31fab23d8db6cdfec84687daf359..c62c92ee23d3586be1c1b9b450be5da26063efe1 100644 (file)
@@ -102,13 +102,9 @@ const char test_title[] = "Invlpg tests";
  */
 static bool ex_fail(struct cpu_regs *regs, const struct extable_entry *ex)
 {
-    char buf[16];
+    exinfo_t info = EXINFO(regs->entry_vector, regs->error_code);
 
-    x86_exc_decode_ec(buf, ARRAY_SIZE(buf),
-                      regs->entry_vector, regs->error_code);
-
-    xtf_failure("    Fail: Unexpected %s[%s]\n",
-                x86_exc_short_name(regs->entry_vector), buf);
+    xtf_failure("    Fail: Unexpected fault %#x, %pe\n", info, _p(info));
 
     regs->ip = ex->fixup;
     return true;
index 6f9a0db9f676515d47d0eecc620eae962cc07ab7..5cf16c3bfc68ba6459b85f45e4f02d68e1825c4c 100644 (file)
@@ -29,7 +29,7 @@ static void decode_test_exinfo(char *str, size_t n, exinfo_t ex)
 
     if ( high == EXINFO_EXPECTED )
     {
-        x86_decode_exinfo(str, n, ex);
+        snprintf(str, n, "%pe", _p(ex));
         return;
     }
 
index ab312611f5b2e6193a1aea3eadf4d4589c7f776a..275868e65d3b7e0deeb893e14944c742e2d5e757 100644 (file)
@@ -61,14 +61,9 @@ void test_main(void)
         break;
 
     default:
-    {
-        char str[20];
-
-        x86_decode_exinfo(str, ARRAY_SIZE(str), fault);
-        xtf_error("  Error: Unexpected fault %#x (%s)\n", fault, str);
+        xtf_error("  Error: Unexpected fault %#x, %pe\n", fault, _p(fault));
         break;
     }
-    }
 
     printk("Testing stale LDT:\n");
 
@@ -99,14 +94,9 @@ void test_main(void)
         break;
 
     default:
-    {
-        char str[20];
-
-        x86_decode_exinfo(str, ARRAY_SIZE(str), fault);
-        xtf_error("  Error: Unexpected fault %#x (%s)\n", fault, str);
+        xtf_error("  Error: Unexpected fault %#x, %pe\n", fault, _p(fault));
         break;
     }
-    }
 
     xtf_success(NULL);
 }
index 5c7fac3fbe8b8069e97bab08a8a16a4841f28c88..a9233a4a0aab93d1b8f18e9ca9008e35dbda4488 100644 (file)
@@ -100,13 +100,7 @@ void test_main(void)
             xtf_success("Success: Got #DE as expected\n");
         }
         else
-        {
-            char gotstr[16];
-
-            x86_decode_exinfo(gotstr, ARRAY_SIZE(gotstr), fault);
-
-            xtf_error("Error: Got unexpected fault %s\n", gotstr);
-        }
+            xtf_error("  Error: Unexpected fault %#x, %pe\n", fault, _p(fault));
 
         break;
     }