Handle set_pc errors

This commit is contained in:
Derek Parker
2015-02-28 10:41:05 -06:00
parent 636719a4c6
commit b065674fe3
3 changed files with 8 additions and 6 deletions

View File

@ -17,7 +17,10 @@ func (r *Regs) SP() uint64 {
}
func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error {
C.set_pc(thread.os.thread_act, C.uint64_t(pc))
kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc))
if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not set pc")
}
return nil
}

View File

@ -47,19 +47,18 @@ get_registers(mach_port_name_t task, x86_thread_state64_t *state) {
}
// TODO(dp) this should return kret instead of void
void
kern_return_t
set_pc(thread_act_t task, uint64_t pc) {
kern_return_t kret;
x86_thread_state64_t state;
mach_msg_type_number_t stateCount = x86_THREAD_STATE64_COUNT;
kret = thread_get_state(task, x86_THREAD_STATE64, (thread_state_t)&state, &stateCount);
if (kret != KERN_SUCCESS) puts(mach_error_string(kret));
if (kret != KERN_SUCCESS) return kret;
state.__rip = pc;
kret = thread_set_state(task, x86_THREAD_STATE64, (thread_state_t)&state, stateCount);
if (kret != KERN_SUCCESS) puts(mach_error_string(kret));
// TODO(dp) - possible memory leak - vm_deallocate state
return thread_set_state(task, x86_THREAD_STATE64, (thread_state_t)&state, stateCount);
}
// TODO(dp) this should return kret instead of void

View File

@ -13,7 +13,7 @@ read_memory(mach_port_name_t, mach_vm_address_t, void *, mach_msg_type_number_t)
kern_return_t
get_registers(mach_port_name_t, x86_thread_state64_t*);
void
kern_return_t
set_pc(thread_act_t, uint64_t);
void