Created
June 27, 2013 14:28
-
-
Save 0x75/5876878 to your computer and use it in GitHub Desktop.
debug port installation routine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mach_port_t install_debug_port(void) { | |
mach_port_t *exceptionPort = (mach_port_t *) malloc(sizeof(mach_port_t)); | |
mach_port_t me; | |
exception_mask_t mask = EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC | EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT | EXC_MASK_SYSCALL; | |
// Create a port by allocating a receive right, and then create a send right | |
// accessible under the same name. | |
me = mach_task_self(); | |
mach_assert("mach_port_allocate()", mach_port_allocate(me, MACH_PORT_RIGHT_RECEIVE, exceptionPort)); | |
mach_assert("mach_port_insert_right()", mach_port_insert_right(me, *exceptionPort, *exceptionPort, MACH_MSG_TYPE_MAKE_SEND)); | |
/* get the old exception ports */ | |
mach_assert("mach_get_exception_ports()", task_get_exception_ports(targetTask, mask, old_exc_ports.masks, &old_exc_ports.count, old_exc_ports.ports, old_exc_ports.behaviors, old_exc_ports.flavors)); | |
/* set the new exception port */ | |
mach_assert("task_set_exception_ports()", task_set_exception_ports(targetTask, mask, *exceptionPort, EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE)); | |
return *exceptionPort; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment