X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/89b3af67bb32e691275bf6fa803d1834b2284115..21362eb3e66fd2c787aee132bce100a44d71a99c:/bsd/kern/mach_process.c diff --git a/bsd/kern/mach_process.c b/bsd/kern/mach_process.c index 6ecd242b1..a79d9de65 100644 --- a/bsd/kern/mach_process.c +++ b/bsd/kern/mach_process.c @@ -87,6 +87,7 @@ #include #include +#include /* Macros to clear/set/test flags. */ @@ -95,8 +96,12 @@ #define ISSET(t, f) ((t) & (f)) extern thread_t port_name_to_thread(mach_port_name_t port_name); +extern kern_return_t thread_getstatus(thread_t thread, int flavor, thread_state_t tstate, mach_msg_type_number_t *count); extern thread_t get_firstthread(task_t); +#if defined (ppc) +extern kern_return_t thread_setstatus(thread_t thread, int flavor, thread_state_t tstate, mach_msg_type_number_t count); +#endif /* * sys-trace system call. @@ -112,6 +117,15 @@ ptrace(p, uap, retval) task_t task; thread_t th_act; struct uthread *ut; + int *locr0; +#if defined(ppc) + struct ppc_thread_state64 statep; +#elif defined(i386) + struct i386_saved_state statep; +#else +#error architecture not supported +#endif + unsigned long state_count; int tr_sigexc = 0; AUDIT_ARG(cmd, uap->req); @@ -259,16 +273,39 @@ ptrace(p, uap, retval) th_act = (thread_t)get_firstthread(task); if (th_act == THREAD_NULL) goto errorLabel; - + ut = (uthread_t)get_bsdthread_info(th_act); + locr0 = ut->uu_ar0; +#if defined(i386) + state_count = i386_NEW_THREAD_STATE_COUNT; + if (thread_getstatus(th_act, i386_NEW_THREAD_STATE, &statep, &state_count) != KERN_SUCCESS) { + goto errorLabel; + } +#elif defined(ppc) + state_count = PPC_THREAD_STATE64_COUNT; + if (thread_getstatus(th_act, PPC_THREAD_STATE64, (thread_state_t)&statep, (mach_msg_type_number_t *)&state_count) != KERN_SUCCESS) { + goto errorLabel; + } +#else +#error architecture not supported +#endif if (uap->addr != (user_addr_t)1) { -#if defined(ppc) +#if defined(i386) + locr0[PC] = (int)uap->addr; +#elif defined(ppc) #define ALIGNED(addr,size) (((unsigned)(addr)&((size)-1))==0) - if (!ALIGNED((int)uap->addr, sizeof(int))) - return (ERESTART); + if (!ALIGNED((int)uap->addr, sizeof(int))) + return (ERESTART); + + statep.srr0 = uap->addr; + state_count = PPC_THREAD_STATE64_COUNT; + if (thread_setstatus(th_act, PPC_THREAD_STATE64, (thread_state_t)&statep, state_count) != KERN_SUCCESS) { + goto errorLabel; + } #undef ALIGNED +#else +#error architecture not implemented! #endif - thread_setentrypoint(th_act, uap->addr); - } + } /* uap->addr != (user_addr_t)1 */ if ((unsigned)uap->data >= NSIG) goto errorLabel; @@ -276,18 +313,37 @@ ptrace(p, uap, retval) if (uap->data != 0) { psignal_lock(t, uap->data, 0); } +#if defined(ppc) + state_count = PPC_THREAD_STATE64_COUNT; + if (thread_getstatus(th_act, PPC_THREAD_STATE64, (thread_state_t)&statep, (mach_msg_type_number_t *)&state_count) != KERN_SUCCESS) { + goto errorLabel; + } +#endif + +#define MSR_SE_BIT 21 if (uap->req == PT_STEP) { - /* - * set trace bit - */ - thread_setsinglestep(th_act, 1); - } else { - /* - * clear trace bit if on - */ - thread_setsinglestep(th_act, 0); +#if defined(i386) + locr0[PS] |= PSL_T; +#elif defined(ppc) + statep.srr1 |= MASK(MSR_SE); +#else +#error architecture not implemented! +#endif + } /* uap->req == PT_STEP */ + else { /* PT_CONTINUE - clear trace bit if set */ +#if defined(i386) + locr0[PS] &= ~PSL_T; +#elif defined(ppc) + statep.srr1 &= ~MASK(MSR_SE); +#endif } +#if defined (ppc) + state_count = PPC_THREAD_STATE64_COUNT; + if (thread_setstatus(th_act, PPC_THREAD_STATE64, (thread_state_t)&statep, state_count) != KERN_SUCCESS) { + goto errorLabel; + } +#endif resume: t->p_xstat = uap->data; t->p_stat = SRUN;