From: Keir Fraser Date: Mon, 18 Apr 2011 17:34:45 +0000 (+0100) Subject: tools: hvmloader: attempt to SHUTDOWN_crash on BUG X-Git-Tag: 4.2.0-rc1~2338 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=576d39339e6f89c6cf33b54e09b2f73791262e79;p=xen.git tools: hvmloader: attempt to SHUTDOWN_crash on BUG Executing UD2 (invalid opcode) triggers a triple fault which signals reboot to the toolstack, rather than crash. Signed-off-by: Ian Campbell Signed-off-by: Keir Fraser --- diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c index bbbc964f9c..855087499d 100644 --- a/tools/firmware/hvmloader/hvmloader.c +++ b/tools/firmware/hvmloader/hvmloader.c @@ -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(); diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index 25c5f7a040..d16b4b2fd9 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -24,6 +24,7 @@ #include #include #include +#include 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)