[PATCH 9/9] x86: Save FS/GS base in core dump

From: Andi Kleen
Date: Mon Mar 21 2016 - 12:18:18 EST


From: Andi Kleen <ak@xxxxxxxxxxxxxxx>

Add FS/GS base dumping to the standard ELF_CORE_COPY_REGS macro

I think this is only used in some special cases, the majority
of core dumps seem to go through the getregs interface also
used by ptrace.

Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
---
arch/x86/include/asm/elf.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index 0df9c95..f57cc17 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -9,6 +9,8 @@
#include <asm/ptrace.h>
#include <asm/user.h>
#include <asm/auxvec.h>
+#include <asm/proto.h>
+#include <asm/fsgs.h>

typedef unsigned long elf_greg_t;

@@ -226,8 +228,13 @@ do { \
(pr_reg)[18] = (regs)->flags; \
(pr_reg)[19] = (regs)->sp; \
(pr_reg)[20] = (regs)->ss; \
- (pr_reg)[21] = current->thread.fs; \
- (pr_reg)[22] = current->thread.gs; \
+ if (boot_cpu_has(X86_FEATURE_FSGSBASE)) { \
+ (pr_reg)[21] = rdfsbase(); \
+ (pr_reg)[22] = read_user_gsbase(); \
+ } else { \
+ (pr_reg)[21] = current->thread.fs; \
+ (pr_reg)[22] = current->thread.gs; \
+ } \
asm("movl %%ds,%0" : "=r" (v)); (pr_reg)[23] = v; \
asm("movl %%es,%0" : "=r" (v)); (pr_reg)[24] = v; \
asm("movl %%fs,%0" : "=r" (v)); (pr_reg)[25] = v; \
--
2.5.5