From aa740f50b9a56eae7ab0e2b82b0277fb39f6202b Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Wed, 16 Jan 2019 10:35:15 +0100 Subject: [PATCH] plat/common: Add a notice regarding trap handling 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 Reviewed-by: Yuri Volchkov --- plat/common/x86/traps.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plat/common/x86/traps.c b/plat/common/x86/traps.c index c4c520b46..cfb120f6d 100644 --- a/plat/common/x86/traps.c +++ b/plat/common/x86/traps.c @@ -40,6 +40,18 @@ #include #include +/* 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") -- 2.39.5