Commit 8a8850d1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

dump: Dump TLS via sys_arch_prctl

As such -- no need for kernel patch.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 3725fd32
...@@ -543,7 +543,6 @@ err: ...@@ -543,7 +543,6 @@ err:
static int dump_task_tls(pid_t pid, struct desc_struct *tls_array, int size) static int dump_task_tls(pid_t pid, struct desc_struct *tls_array, int size)
{ {
FILE *file = NULL;
int ret = -1; int ret = -1;
if (size != GDT_ENTRY_TLS_ENTRIES) { if (size != GDT_ENTRY_TLS_ENTRIES) {
...@@ -551,43 +550,14 @@ static int dump_task_tls(pid_t pid, struct desc_struct *tls_array, int size) ...@@ -551,43 +550,14 @@ static int dump_task_tls(pid_t pid, struct desc_struct *tls_array, int size)
goto err; goto err;
} }
file = fopen_proc("%d/tls", "r", pid); memzero(tls_array, sizeof(*tls_array) * size);
if (!file) {
pr_perror("Can't open %d tls", pid);
goto err;
}
ret = 0;
while (fgets(loc_buf, sizeof(loc_buf), file)) {
u32 a, b;
if (sscanf(loc_buf, "%x %x", &a, &b) != 2) {
pr_err("Can't parse tls entry: %s\n");
ret = -1;
goto err;
}
if (ret >= GDT_ENTRY_TLS_ENTRIES) {
pr_err("Too many entries in tls\n");
ret = -1;
goto err;
}
tls_array[ret].a = a;
tls_array[ret].b = b;
ret++;
}
if (ret != GDT_ENTRY_TLS_ENTRIES) {
pr_err("tls returened %i entries instead of %i\n",
ret, GDT_ENTRY_TLS_ENTRIES);
ret = -1;
goto err;
}
ret = 0; /* pure x86-64 has a base address only */
ret = sys_arch_prctl(ARCH_GET_FS, &tls_array[0].base_addr);
if (ret)
pr_err("Failed to obtain TLS entry: %d\n", ret);
err: err:
if (file)
fclose(file);
return ret; return ret;
} }
......
...@@ -98,7 +98,7 @@ static void show_core_regs(struct cr_fdset *cr_fdset) ...@@ -98,7 +98,7 @@ static void show_core_regs(struct cr_fdset *cr_fdset)
for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++) { for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++) {
read_ptr_safe(fd_core, &tls, err); read_ptr_safe(fd_core, &tls, err);
pr_info("tls[%2i] = %x %x\n", i, tls.a, tls.b); pr_info("tls[%2i] = %x\n", i, tls.base_addr);
} }
err: err:
......
...@@ -140,8 +140,13 @@ struct user_regs_entry { ...@@ -140,8 +140,13 @@ struct user_regs_entry {
} __packed; } __packed;
struct desc_struct { struct desc_struct {
u32 a; union {
u32 b; struct {
u32 a;
u32 b;
} x86_32;
u64 base_addr;
};
} __packed; } __packed;
struct user_fpregs_entry { struct user_fpregs_entry {
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#include "bitops.h" #include "bitops.h"
/* prctl */
#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004
/* some constants for ptrace */ /* some constants for ptrace */
#define PTRACE_SEIZE 0x4206 #define PTRACE_SEIZE 0x4206
#define PTRACE_INTERRUPT 0x4207 #define PTRACE_INTERRUPT 0x4207
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment