]> xenbits.xensource.com Git - xen.git/commitdiff
tools: hvmloader: attempt to SHUTDOWN_crash on BUG
authorKeir Fraser <keir@xen.org>
Mon, 18 Apr 2011 17:34:45 +0000 (18:34 +0100)
committerKeir Fraser <keir@xen.org>
Mon, 18 Apr 2011 17:34:45 +0000 (18:34 +0100)
Executing UD2 (invalid opcode) triggers a triple fault which signals
reboot to the toolstack, rather than crash.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Keir Fraser <keir@xen.org>
tools/firmware/hvmloader/hvmloader.c
tools/firmware/hvmloader/util.c

index bbbc964f9c518078ece5cadac9aa683fa6ab2255..855087499d20c1757fa69a72be26fb0d7c5586f8 100644 (file)
@@ -370,6 +370,9 @@ int main(void)
     int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0, smbios_sz = 0;
     uint32_t etherboot_phys_addr, option_rom_phys_addr;
 
+    /* Initialise hypercall stubs with RET, rendering them no-ops. */
+    memset((void *)HYPERCALL_PHYSICAL_ADDRESS, 0xc3 /* RET */, PAGE_SIZE);
+
     printf("HVM Loader\n");
 
     init_hypercalls();
index 25c5f7a0407658ca2711b7e79ed676fe467459b2..d16b4b2fd9cff4307b6add10ff109216e20e5453 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <xen/xen.h>
 #include <xen/memory.h>
+#include <xen/sched.h>
 
 void wrmsr(uint32_t idx, uint64_t v)
 {
@@ -537,19 +538,27 @@ int vprintf(const char *fmt, va_list ap)
     return 0;
 }
 
+static void __attribute__((noreturn)) crash(void)
+{
+    struct sched_shutdown shutdown = { .reason = SHUTDOWN_crash };
+    printf("*** HVMLoader crashed.\n");
+    hypercall_sched_op(SCHEDOP_shutdown, &shutdown);
+    printf("*** Failed to crash. Halting.\n");
+    for ( ; ; )
+        asm volatile ( "hlt" );
+}
+
 void __assert_failed(char *assertion, char *file, int line)
 {
-    printf("HVMLoader assertion '%s' failed at %s:%d\n",
+    printf("*** HVMLoader assertion '%s' failed at %s:%d\n",
            assertion, file, line);
-    for ( ; ; )
-        asm volatile ( "ud2" );
+    crash();
 }
 
 void __bug(char *file, int line)
 {
-    printf("HVMLoader bug at %s:%d\n", file, line);
-    for ( ; ; )
-        asm volatile ( "ud2" );
+    printf("*** HVMLoader bug at %s:%d\n", file, line);
+    crash();
 }
 
 static void validate_hvm_info(struct hvm_info_table *t)