From c56574b411de65c6ae45262542e57ea2d016db10 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sun, 12 Feb 2012 00:30:24 +0400 Subject: [PATCH] dump: Obtain task brk via misc dump command Right now we do syscall_seized for this, but we have the misc dumping command and the core is (after patch #3) dump after parasite, so we can get brk from the misc dump, thus avoiding one more switch to parasite. Signed-off-by: Pavel Emelyanov Signed-off-by: Cyrill Gorcunov --- cr-dump.c | 13 ++++--------- include/parasite-syscall.h | 1 - include/parasite.h | 1 + include/syscall.h | 5 +++++ parasite-syscall.c | 25 ------------------------- parasite.c | 1 + 6 files changed, 11 insertions(+), 35 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index f31331d75..88ca821a3 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -665,7 +665,7 @@ static int dump_task_core(struct core_entry *core, struct cr_fdset *fdset) } static int dump_task_core_all(pid_t pid, int pid_dir, struct proc_pid_stat *stat, - struct cr_fdset *cr_fdset) + struct parasite_dump_misc *misc, struct cr_fdset *cr_fdset) { struct core_entry *core = xzalloc(sizeof(*core)); int ret = -1; @@ -704,6 +704,8 @@ static int dump_task_core_all(pid_t pid, int pid_dir, struct proc_pid_stat *stat core->tc.mm_env_start = stat->env_start; core->tc.mm_env_end = stat->env_end; + core->tc.mm_brk = misc->brk; + pr_info("Obtainting sigmask ... "); ret = get_task_sigmask(pid, pid_dir, &core->tc.blk_sigset); if (ret) @@ -716,13 +718,6 @@ static int dump_task_core_all(pid_t pid, int pid_dir, struct proc_pid_stat *stat goto err_free; pr_info("OK\n"); - pr_info("Obtainting task brk ... "); - brk = brk_seized(pid, 0); - if ((long)brk < 0) - goto err_free; - core->tc.mm_brk = brk; - pr_info("OK\n"); - core->tc.task_state = TASK_ALIVE; core->tc.exit_code = 0; @@ -1254,7 +1249,7 @@ static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset) goto err; } - ret = dump_task_core_all(pid, pid_dir, &pps_buf, cr_fdset); + ret = dump_task_core_all(pid, pid_dir, &pps_buf, &misc, cr_fdset); if (ret) { pr_err("Dump core (pid: %d) failed with %d\n", pid, ret); goto err; diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h index cd7228495..4da341221 100644 --- a/include/parasite-syscall.h +++ b/include/parasite-syscall.h @@ -28,7 +28,6 @@ extern void *mmap_seized(pid_t pid, user_regs_struct_t *regs, extern int munmap_seized(pid_t pid, user_regs_struct_t *regs, void *addr, size_t length); -extern unsigned long brk_seized(pid_t pid, unsigned long addr); extern int syscall_seized(pid_t pid, user_regs_struct_t *where, diff --git a/include/parasite.h b/include/parasite.h index 12ae5b60d..cbe500222 100644 --- a/include/parasite.h +++ b/include/parasite.h @@ -89,6 +89,7 @@ struct parasite_dump_pages_args { struct parasite_dump_misc { parasite_status_t status; unsigned int secbits; + unsigned long brk; }; /* diff --git a/include/syscall.h b/include/syscall.h index 966cb75c1..e42e94aa4 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -258,6 +258,11 @@ static always_inline long sys_prctl(int code, unsigned long arg2, unsigned long return syscall5(__NR_prctl, code, arg2, arg3, arg4, arg5); } +static always_inline long sys_brk(unsigned long arg) +{ + return syscall1(__NR_brk, arg); +} + static always_inline long sys_clone(unsigned long flags, void *child_stack, void *parent_tid, void *child_tid) { diff --git a/parasite-syscall.c b/parasite-syscall.c index cb9b8db51..a1918f165 100644 --- a/parasite-syscall.c +++ b/parasite-syscall.c @@ -92,31 +92,6 @@ int munmap_seized(pid_t pid, user_regs_struct_t *regs, return ret; } -unsigned long brk_seized(pid_t pid, unsigned long addr) -{ - user_regs_struct_t params, regs_orig; - unsigned long ret = -1UL; - - jerr(ptrace(PTRACE_GETREGS, pid, NULL, ®s_orig), err); - params = regs_orig; - - params.ax = (unsigned long)__NR_brk; /* brk */ - params.di = (unsigned long)addr; /* @addr */ - - ret = syscall_seized(pid, ®s_orig, ¶ms, ¶ms); - if (!ret) - ret = (unsigned long)params.ax; - else - ret = -1UL; - - if (ptrace(PTRACE_SETREGS, pid, NULL, ®s_orig)) { - pr_panic("Can't restore registers (pid: %d)\n", pid); - ret = -1UL; - } -err: - return ret; -} - int syscall_seized(pid_t pid, user_regs_struct_t *where, user_regs_struct_t *params, diff --git a/parasite.c b/parasite.c index 191e8fc1f..ff4960549 100644 --- a/parasite.c +++ b/parasite.c @@ -363,6 +363,7 @@ static int dump_misc(struct parasite_dump_misc *args) parasite_status_t *st = &args->status; args->secbits = sys_prctl(PR_GET_SECUREBITS, 0, 0, 0, 0); + args->brk = sys_brk(0); SET_PARASITE_STATUS(st, 0, 0); return 0;