Commit a0f463c2 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

Move seize related functions into seize.[ch]

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent c2bd1773
......@@ -66,6 +66,7 @@ OBJS += cr-show.o
OBJS += util.o
OBJS += rbtree.o
OBJS += elf.o
OBJS += seize.o
DEPS := $(patsubst %.o,%.d,$(OBJS))
......
#ifndef SEIZE_H_
#define SEIZE_H_
#include <sys/ptrace.h>
int seize_task(pid_t pid);
int unseize_task(pid_t pid);
#endif /* SEIZE_H_ */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/vfs.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include <sys/wait.h>
#include "compiler.h"
#include "types.h"
#include "list.h"
#include "util.h"
#include "seize.h"
#include "crtools.h"
int unseize_task(pid_t pid)
{
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
/*
* This routine seizes task putting it into a special
* state where we can manipulate the task via ptrace
* inteface, and finally we can detach ptrace out of
* of it so the task would not know if it was saddled
* up with someone else.
*/
int seize_task(pid_t pid)
{
siginfo_t si;
int status;
int ret = 0;
jerr_rc(ptrace(PTRACE_SEIZE, pid, NULL,
(void *)(unsigned long)PTRACE_SEIZE_DEVEL), ret, err);
jerr_rc(ptrace(PTRACE_INTERRUPT, pid, NULL, NULL), ret, err);
ret = -10;
if (wait4(pid, &status, __WALL, NULL) != pid)
goto err;
ret = -20;
if (!WIFSTOPPED(status))
goto err;
jerr_rc(ptrace(PTRACE_GETSIGINFO, pid, NULL, &si), ret, err_cont);
ret = -30;
if ((si.si_code >> 8) != PTRACE_EVENT_STOP)
goto err_cont;
jerr_rc(ptrace(PTRACE_SETOPTIONS, pid, NULL,
(void *)(unsigned long)PTRACE_O_TRACEEXIT), ret, err_cont);
err:
return ret;
err_cont:
continue_task(pid);
goto err;
}
......@@ -187,53 +187,6 @@ void printk_vma(struct vma_area *vma_area)
((vma_area->vma.status & VMA_AREA_VDSO) ? "vdso" : "n")))));
}
int unseize_task(pid_t pid)
{
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
/*
* This routine seizes task putting it into a special
* state where we can manipulate the task via ptrace
* inteface, and finally we can detach ptrace out of
* of it so the task would not know if it was saddled
* up with someone else.
*/
int seize_task(pid_t pid)
{
siginfo_t si;
int status;
int ret = 0;
jerr_rc(ptrace(PTRACE_SEIZE, pid, NULL,
(void *)(unsigned long)PTRACE_SEIZE_DEVEL), ret, err);
jerr_rc(ptrace(PTRACE_INTERRUPT, pid, NULL, NULL), ret, err);
ret = -10;
if (wait4(pid, &status, __WALL, NULL) != pid)
goto err;
ret = -20;
if (!WIFSTOPPED(status))
goto err;
jerr_rc(ptrace(PTRACE_GETSIGINFO, pid, NULL, &si), ret, err_cont);
ret = -30;
if ((si.si_code >> 8) != PTRACE_EVENT_STOP)
goto err_cont;
jerr_rc(ptrace(PTRACE_SETOPTIONS, pid, NULL,
(void *)(unsigned long)PTRACE_O_TRACEEXIT), ret, err_cont);
err:
return ret;
err_cont:
continue_task(pid);
goto err;
}
int close_safe(int *fd)
{
int ret = 0;
......
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