]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common: Add a notice regarding trap handling
authorFlorian Schmidt <florian.schmidt@neclab.eu>
Wed, 16 Jan 2019 09:35:15 +0000 (10:35 +0100)
committerFlorian Schmidt <florian.schmidt@neclab.eu>
Wed, 23 Jan 2019 14:21:51 +0000 (23:21 +0900)
While traps.c itself is compiled with NO_X86_EXTREGS_FLAGS, it still
doesn't hurt to remind potential editors of the file that calling any
other function from your trap handler is potentially dangerous.

Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu>
Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
plat/common/x86/traps.c

index c4c520b46c18b2132af7fe498c0fe9444a555178..cfb120f6db44698ff5f6c181b05db01cffc627be 100644 (file)
 #include <uk/print.h>
 #include <uk/assert.h>
 
+/* A general word of caution when writing trap handlers. The platform trap
+ * entry code is set up to properly save general-purpose registers (e.g., rsi,
+ * rdi, rax, r8, ...), but it does NOT save any floating-point or SSE/AVX
+ * registers. (This would require figuring out in the trap handler code whether
+ * these are available to not risk a #UD trap inside the trap handler itself.)
+ * Hence, you need to be extra careful not to do anything that clobbers these
+ * registers if you intend to return from the handler. This includes calling
+ * other functions, which may clobber those registers.
+ * Of course, if you end your trap handler with a UK_CRASH, knock yourself out,
+ * it's not like the function you came from will ever have the chance to notice.
+ */
+
 /* Traps handled on both Xen and KVM */
 
 DECLARE_TRAP_EC(divide_error,      "divide error")