~laumann/hadb

b9b2ca2126e4d32482de99c72d56b6db19b92f20 — Thomas Bracht Laumann Jespersen 10 months ago c872f63
trace: formatting
1 files changed, 18 insertions(+), 9 deletions(-)

M trace/lib+linux.ha
M trace/lib+linux.ha => trace/lib+linux.ha +18 -9
@@ 10,21 10,26 @@ export fn fork() (pid_t | void | error) = {
		return pid : pid_t;
	case let err: rt::errno =>
		return err : error;
	case void => return void;
	case void =>
		return void;
	};
};

export fn traceme() void = {
	match (rt::ptrace(rt::PTRACE_TRACEME, 0, 0, 0)) {
	case let err: rt::errno => abort("ptrace(PTRACE_TRACEME, ...) failed");
	case => void;
	case let err: rt::errno =>
		abort("ptrace(PTRACE_TRACEME, ...) failed");
	case =>
		void;
	};
};

export fn cont(pid: pid_t) void = {
	match (rt::ptrace(rt::PTRACE_CONT, pid, 0, 0)) {
	case let err: rt::errno => abort("ptrace(PTRACE_CONT, ...) failed");
	case => void;
	case let err: rt::errno =>
		abort("ptrace(PTRACE_CONT, ...) failed");
	case =>
		void;
	};
};



@@ 37,14 42,18 @@ export fn waitpid(pid: pid_t) void = {

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;
	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;
	case let err: rt::errno =>
		abort("ptrace(PTRACE_POKEDATA, ...) failed");
	case =>
		void;
	};
};