Commit 2e3c4e36 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

Move everything related to ptrace into ptrace.[ch]

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 83fd63d3
......@@ -64,7 +64,7 @@ OBJS += cr-dump.o
OBJS += cr-restore.o
OBJS += cr-show.o
OBJS += util.o
OBJS += seize.o
OBJS += ptrace.o
OBJS += restorer.o
OBJS += log.o
......
......@@ -29,7 +29,7 @@
#include "compiler.h"
#include "crtools.h"
#include "syscall.h"
#include "seize.h"
#include "ptrace.h"
#include "util.h"
#include "image.h"
......
......@@ -5,5 +5,9 @@
extern int seize_task(pid_t pid);
extern int unseize_task(pid_t pid);
extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
extern int ptrace_show_area(pid_t pid, void *addr, long bytes);
extern int ptrace_show_area_r(pid_t pid, void *addr, long bytes);
#endif /* SEIZE_H_ */
......@@ -123,11 +123,6 @@ extern void printk(const char *format, ...);
#define memzero_p(p) memset(p, 0, sizeof(*p))
#define memzero(p, size) memset(p, 0, size)
extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
extern int ptrace_show_area(pid_t pid, void *addr, long bytes);
extern int ptrace_show_area_r(pid_t pid, void *addr, long bytes);
extern void printk_registers(user_regs_struct_t *regs);
extern void printk_siginfo(siginfo_t *siginfo);
......
......@@ -17,6 +17,7 @@
#include "compiler.h"
#include "syscall.h"
#include "types.h"
#include "ptrace.h"
#include "util.h"
#include "parasite-syscall.h"
......
......@@ -27,9 +27,8 @@
#include "compiler.h"
#include "types.h"
#include "list.h"
#include "util.h"
#include "seize.h"
#include "ptrace.h"
#include "crtools.h"
......@@ -79,3 +78,84 @@ err_cont:
continue_task(pid);
goto err;
}
int ptrace_show_area_r(pid_t pid, void *addr, long bytes)
{
unsigned long w, i;
if (bytes & (sizeof(long) - 1))
return -1;
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *a = addr;
unsigned long v;
v = ptrace(PTRACE_PEEKDATA, pid, a + w, NULL);
if (v == -1U && errno)
goto err;
else {
unsigned char *c = (unsigned char *)&v;
for (i = sizeof(v)/sizeof(*c); i > 0; i--)
printk("%02x ", c[i - 1]);
printk(" ");
}
}
printk("\n");
return 0;
err:
return -2;
}
int ptrace_show_area(pid_t pid, void *addr, long bytes)
{
unsigned long w, i;
if (bytes & (sizeof(long) - 1))
return -1;
printk("%016lx: ", (unsigned long)addr);
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *a = addr;
unsigned long v;
v = ptrace(PTRACE_PEEKDATA, pid, a + w, NULL);
if (v == -1U && errno)
goto err;
else {
unsigned char *c = (unsigned char *)&v;
for (i = 0; i < sizeof(v)/sizeof(*c); i++)
printk("%02x ", c[i]);
printk(" ");
}
}
printk("\n");
return 0;
err:
return -2;
}
int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes)
{
unsigned long w;
if (bytes & (sizeof(long) - 1))
return -1;
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *d = dst, *a = addr;
d[w] = ptrace(PTRACE_PEEKDATA, pid, a + w, NULL);
if (d[w] == -1U && errno)
goto err;
}
return 0;
err:
return -2;
}
int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes)
{
unsigned long w;
if (bytes & (sizeof(long) - 1))
return -1;
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *s = src, *a = addr;
if (ptrace(PTRACE_POKEDATA, pid, a + w, s[w]))
goto err;
}
return 0;
err:
return -2;
}
......@@ -47,86 +47,6 @@ void printk(const char *format, ...)
va_end(params);
}
int ptrace_show_area_r(pid_t pid, void *addr, long bytes)
{
unsigned long w, i;
if (bytes & (sizeof(long) - 1))
return -1;
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *a = addr;
unsigned long v;
v = ptrace(PTRACE_PEEKDATA, pid, a + w, NULL);
if (v == -1U && errno)
goto err;
else {
unsigned char *c = (unsigned char *)&v;
for (i = sizeof(v)/sizeof(*c); i > 0; i--)
printk("%02x ", c[i - 1]);
printk(" ");
}
}
printk("\n");
return 0;
err:
return -2;
}
int ptrace_show_area(pid_t pid, void *addr, long bytes)
{
unsigned long w, i;
if (bytes & (sizeof(long) - 1))
return -1;
printk("%016lx: ", (unsigned long)addr);
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *a = addr;
unsigned long v;
v = ptrace(PTRACE_PEEKDATA, pid, a + w, NULL);
if (v == -1U && errno)
goto err;
else {
unsigned char *c = (unsigned char *)&v;
for (i = 0; i < sizeof(v)/sizeof(*c); i++)
printk("%02x ", c[i]);
printk(" ");
}
}
printk("\n");
return 0;
err:
return -2;
}
int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes)
{
unsigned long w;
if (bytes & (sizeof(long) - 1))
return -1;
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *d = dst, *a = addr;
d[w] = ptrace(PTRACE_PEEKDATA, pid, a + w, NULL);
if (d[w] == -1U && errno)
goto err;
}
return 0;
err:
return -2;
}
int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes)
{
unsigned long w;
if (bytes & (sizeof(long) - 1))
return -1;
for (w = 0; w < bytes / sizeof(long); w++) {
unsigned long *s = src, *a = addr;
if (ptrace(PTRACE_POKEDATA, pid, a + w, s[w]))
goto err;
}
return 0;
err:
return -2;
}
void hex_dump(void *addr, unsigned long len)
{
unsigned char *p = addr;
......
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