]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/i386/fasttrap_isa.c
xnu-3248.20.55.tar.gz
[apple/xnu.git] / bsd / dev / i386 / fasttrap_isa.c
index be620b5173b10562c1918467931fdbffc4481c83..4eeb6d140f0b4060e13e28b1e52aefeb45111373 100644 (file)
@@ -45,6 +45,8 @@ extern dtrace_id_t dtrace_probeid_error;
 #include <sys/dtrace_ptss.h>
 #include <kern/debug.h>
 
+#include <machine/pal_routines.h>
+
 /* Solaris proc_t is the struct. Darwin's proc_t is a pointer to it. */
 #define proc_t struct proc /* Steer clear of the Darwin typedef for proc_t */
 
@@ -195,21 +197,19 @@ extern dtrace_id_t dtrace_probeid_error;
  *
  * REG_RAX -> EAX
  * REG_RCX -> ECX
- * ...
+ * REG_RDX -> EDX
+ * REG_RBX -> EBX
+ * REG_RSP -> UESP
+ * REG_RBP -> EBP
+ * REG_RSI -> ESI
  * REG_RDI -> EDI
  *
  * The fasttrap_getreg function knows how to make the correct transformation.
  */
-#if __sol64 || defined(__APPLE__)
 static const uint8_t regmap[16] = {
        REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI,
        REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15,
 };
-#else
-static const uint8_t regmap[8] = {
-       EAX, ECX, EDX, EBX, UESP, EBP, ESI, EDI
-};
-#endif
 
 static user_addr_t fasttrap_getreg(x86_saved_state_t *, uint_t);
 
@@ -361,13 +361,11 @@ fasttrap_tracepoint_init(proc_t *p, fasttrap_tracepoint_t *tp, user_addr_t pc,
                break;
        }
 
-#if __sol64 || defined(__APPLE__)
        /*
         * Identify the REX prefix on 64-bit processes.
         */
        if (p_model == DATAMODEL_LP64 && (instr[start] & 0xf0) == 0x40)
                rex = instr[start++];
-#endif
 
        /*
         * Now that we're pretty sure that the instruction is okay, copy the
@@ -450,11 +448,9 @@ fasttrap_tracepoint_init(proc_t *p, fasttrap_tracepoint_t *tp, user_addr_t pc,
                                 * modes, there is a 32-bit operand.
                                 */
                                if (mod == 0 && rm == 5) {
-#if __sol64 || defined(__APPLE__)
                                        if (p_model == DATAMODEL_LP64)
                                                tp->ftt_base = REG_RIP;
                                        else
-#endif
                                                tp->ftt_base = FASTTRAP_NOREG;
                                        sz = 4;
                                } else  {
@@ -552,7 +548,6 @@ fasttrap_tracepoint_init(proc_t *p, fasttrap_tracepoint_t *tp, user_addr_t pc,
                        break;
 
                case FASTTRAP_NOP:
-#if __sol64 || defined(__APPLE__)
                        ASSERT(p_model == DATAMODEL_LP64 || rex == 0);
 
                        /*
@@ -562,7 +557,6 @@ fasttrap_tracepoint_init(proc_t *p, fasttrap_tracepoint_t *tp, user_addr_t pc,
                         * (e.g. xchgl %r8d, %eax or xcghq %r8, %rax).
                         */
                        if (FASTTRAP_REX_B(rex) == 0)
-#endif
                                tp->ftt_type = FASTTRAP_T_NOP;
                        break;
 
@@ -589,7 +583,6 @@ fasttrap_tracepoint_init(proc_t *p, fasttrap_tracepoint_t *tp, user_addr_t pc,
                }
        }
 
-#if __sol64 || defined(__APPLE__)
        if (p_model == DATAMODEL_LP64 && tp->ftt_type == FASTTRAP_T_COMMON) {
                /*
                 * If the process is 64-bit and the instruction type is still
@@ -635,7 +628,6 @@ fasttrap_tracepoint_init(proc_t *p, fasttrap_tracepoint_t *tp, user_addr_t pc,
                        }
                }
        }
-#endif
 
        return (0);
 }
@@ -991,12 +983,12 @@ fasttrap_pid_probe32(x86_saved_state_t *regs)
         * parent. We know that there's only one thread of control in such a
         * process: this one.
         */
-       /*
-        * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
-        * FIXME: How do we assert this?
-        */
-       while (p->p_lflag & P_LINVFORK)
-               p = p->p_pptr;
+       if (p->p_lflag & P_LINVFORK) {
+               proc_list_lock();
+               while (p->p_lflag & P_LINVFORK)
+                       p = p->p_pptr;
+               proc_list_unlock();
+       }
 
        pid = p->p_pid;
        pid_mtx = &cpu_core[CPU->cpu_id].cpuc_pid_lock;
@@ -1550,12 +1542,12 @@ fasttrap_pid_probe64(x86_saved_state_t *regs)
         * parent. We know that there's only one thread of control in such a
         * process: this one.
         */
-       /*
-        * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
-        * FIXME: How do we assert this?
-        */
-       while (p->p_lflag & P_LINVFORK)
-               p = p->p_pptr;
+       if (p->p_lflag & P_LINVFORK) {
+               proc_list_lock();
+               while (p->p_lflag & P_LINVFORK)
+                       p = p->p_pptr;
+               proc_list_unlock();
+       }
 
        pid = p->p_pid;
        pid_mtx = &cpu_core[CPU->cpu_id].cpuc_pid_lock;
@@ -2182,13 +2174,10 @@ fasttrap_return_probe(x86_saved_state_t *regs)
         * parent. We know that there's only one thread of control in such a
         * process: this one.
         */
-       /*
-        * APPLE NOTE: Terry says: "You need to hold the process locks (currently: kernel funnel) for this traversal"
-        * How do we assert this?
-        */
-       while (p->p_lflag & P_LINVFORK) {
+       proc_list_lock();
+       while (p->p_lflag & P_LINVFORK)
                p = p->p_pptr;
-       }
+       proc_list_unlock();
 
        /*
         * We set rp->r_pc to the address of the traced instruction so
@@ -2207,11 +2196,11 @@ fasttrap_return_probe(x86_saved_state_t *regs)
        return (0);
 }
 
-
 uint64_t
 fasttrap_pid_getarg(void *arg, dtrace_id_t id, void *parg, int argno,
     int aframes)
 {
+       pal_register_cache_state(current_thread(), VALID);
 #pragma unused(arg, id, parg, aframes)
        return (fasttrap_anarg((x86_saved_state_t *)find_user_regs(current_thread()), 1, argno));
 }
@@ -2220,6 +2209,7 @@ uint64_t
 fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg, int argno,
     int aframes)
 {
+       pal_register_cache_state(current_thread(), VALID);
 #pragma unused(arg, id, parg, aframes)
        return (fasttrap_anarg((x86_saved_state_t *)find_user_regs(current_thread()), 0, argno));
 }