~laumann/hadb

99ebf7e4e186e338c34b66f34d2e023bcd06fba6 — Thomas Bracht Laumann Jespersen 1 year, 3 months ago bf89f69
trace: add {read,write}mem for ptrace
1 files changed, 14 insertions(+), 0 deletions(-)

M trace/lib+linux.ha
M trace/lib+linux.ha => trace/lib+linux.ha +14 -0
@@ 34,3 34,17 @@ export fn waitpid(pid: pid_t) void = {
	// preferred waitpid(2), but only have wait4()
	rt::wait4(pid, &waitstatus, 0, &rusage)!;
};

export fn readmem(pid: pid_t, addr: u64) u64 = {
	match (rt::ptrace(rt::PTRACE_PEEKDATA, pid, addr : uintptr, 0)) {
	case let err: rt::errno => abort("ptrace(PTRACE_PEEKDATA, ...) failed");
	case let data: u64 => return data;
	};
};

export fn writemem(pid: pid_t, addr: u64, val: u64) void = {
	match (rt::ptrace(rt::PTRACE_POKEDATA, pid, addr : uintptr, val : uintptr)) {
	case let err: rt::errno => abort("ptrace(PTRACE_POKEDATA, ...) failed");
	case => void;
	};
};