#include <kern/task.h>
#include <kern/thread.h>
+#include <mach/machine/thread_status.h>
/* Macros to clear/set/test flags. */
#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.
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);
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;
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;