]> xenbits.xensource.com Git - rumpuser-xen.git/commitdiff
rumpuser_exit(), _exit(): Cleanly halt Mini-OS.
authorMartin Lucina <martin@lucina.net>
Tue, 11 Nov 2014 15:11:46 +0000 (16:11 +0100)
committerMartin Lucina <martin@lucina.net>
Tue, 11 Nov 2014 15:28:46 +0000 (16:28 +0100)
rumpuser_exit() and _exit() were calling minios_do_exit() which is
intended to be called from an exception context and/or other "panic"
situation.  This was causing the stack trace code in minios_do_exit() to
walk off into never never land when the rumprun-xen application called
exit() or returned from main().

This commit adds a new minios_do_halt(reason) function, with the reason
code intended to mirror SHUTDOWN_* in xen/sched.h. Of those, currently
only poweroff and crash are implemented.

We then modify the rumpuser_exit() and _exit() functions to correctly
shut down the domain by calling minios_stop_kernel() followed by
minios_do_halt(MINIOS_HALT_POWEROFF).

Signed-off-by: Martin Lucina <martin@lucina.net>
include/mini-os/kernel.h
lib/emul.c
rumphyper_base.c
xen/kernel.c

index e9ff923fe09c958eb8bd79c4b7d6e5539e43e48c..2fce9067711c2ac23e67cfb6e40b2c0a5372d3e6 100644 (file)
@@ -4,6 +4,11 @@
 extern int app_main(start_info_t *);
 
 extern void minios_do_exit(void) __attribute__((noreturn));
-extern void stop_kernel(void);
+extern void minios_stop_kernel(void);
+
+/* Values should mirror SHUTDOWN_* in xen/sched.h */
+#define MINIOS_HALT_POWEROFF 0
+#define MINIOS_HALT_CRASH 3
+extern void minios_do_halt(int reason) __attribute__((noreturn));
 
 #endif /* _MINIOS_KERNEL_H_ */
index d61b7d15483de2817a2ddce79175d8951f7ad425..8852004da8a279cb4ac73b4b968add8c6f073509 100644 (file)
@@ -77,6 +77,6 @@ munmap(void *addr, size_t len)
 void __dead
 _exit(int eval)
 {
-
-       minios_do_exit();
+       minios_stop_kernel();
+       minios_do_halt(MINIOS_HALT_POWEROFF);
 }
index c9e52b620f0219463773cec6415c4d6d35c3f0af..0f8e05d21def04913b0fc67704f2c93f094a694a 100644 (file)
@@ -216,8 +216,8 @@ rumpuser_getrandom(void *buf, size_t buflen, int flags, size_t *retp)
 void
 rumpuser_exit(int value)
 {
-
-       minios_do_exit();
+       minios_stop_kernel();
+       minios_do_halt(MINIOS_HALT_POWEROFF);
 }
 
 #define NBLKDEV 10
index f3151a96a66e175857b8ebdc569d09fcb8827b7f..f7f763f5a77e78eb0eb117af2b67f6c684a505b3 100644 (file)
@@ -137,7 +137,7 @@ void _minios_start_kernel(start_info_t *si)
     run_idle_thread();
 }
 
-void stop_kernel(void)
+void minios_stop_kernel(void)
 {
     /* TODO: fs import */
 
@@ -165,6 +165,22 @@ void stop_kernel(void)
     arch_fini();
 }
 
+/*
+ * minios_do_halt: Called by "application" code to halt the Xen domain.
+ */
+
+void minios_do_halt(int reason)
+{
+    minios_printk("minios: halting, reason=%d\n", reason);
+    for( ;; )
+    {
+        struct sched_shutdown sched_shutdown = {
+            .reason = (reason == MINIOS_HALT_POWEROFF) ?
+                SHUTDOWN_poweroff : SHUTDOWN_crash };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+    }
+}
+
 /*
  * do_exit: This is called whenever an IRET fails in entry.S.
  * This will generally be because an application has got itself into