]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/dtrace/dtrace_glue.c
xnu-4570.61.1.tar.gz
[apple/xnu.git] / bsd / dev / dtrace / dtrace_glue.c
index 7bd5500b097a5de86cc8b1dadfdb7a8954d60f98..d47102fe604c78e195e39917aadc47d8612f39b6 100644 (file)
@@ -301,7 +301,11 @@ typedef struct wrap_timer_call {
 typedef struct cyc_list {
        cyc_omni_handler_t cyl_omni;
        wrap_timer_call_t cyl_wrap_by_cpus[];
+#if __arm__ && (__BIGGEST_ALIGNMENT__ > 4)
+} __attribute__ ((aligned (8))) cyc_list_t;
+#else
 } cyc_list_t;
+#endif
 
 /* CPU going online/offline notifications */
 void (*dtrace_cpu_state_changed_hook)(int, boolean_t) = NULL;
@@ -573,29 +577,6 @@ cyclic_remove(cyclic_id_t cyclic)
        }
 }
 
-/*
- * timeout / untimeout (converted to dtrace_timeout / dtrace_untimeout due to name collision)
- */ 
-
-thread_call_t
-dtrace_timeout(void (*func)(void *, void *), void* arg, uint64_t nanos)
-{
-#pragma unused(arg)
-       thread_call_t call = thread_call_allocate(func, NULL);
-
-       nanoseconds_to_absolutetime(nanos, &nanos);
-
-       /*
-        * This method does not use clock_deadline_for_periodic_event() because it is a one-shot,
-        * and clock drift on later invocations is not a worry.
-        */
-       uint64_t deadline = mach_absolute_time() + nanos;
-       /* DRK: consider using a lower priority callout here */
-       thread_call_enter_delayed(call, deadline);
-
-       return call;
-}
-
 /*
  * ddi
  */
@@ -605,63 +586,13 @@ ddi_report_dev(dev_info_t *devi)
 #pragma unused(devi)
 }
 
-
-static unsigned int gRegisteredProps = 0;
-static struct {
-       char name[32];          /* enough for "dof-data-" + digits */
-       int *data;
-       uint_t nelements;
-} gPropTable[16];
-
 kern_return_t _dtrace_register_anon_DOF(char *, uchar_t *, uint_t);
 
 kern_return_t
 _dtrace_register_anon_DOF(char *name, uchar_t *data, uint_t nelements)
 {
-       if (gRegisteredProps < sizeof(gPropTable)/sizeof(gPropTable[0])) {
-               int *p = (int *)_MALLOC(nelements*sizeof(int), M_TEMP, M_WAITOK);
-               
-               if (NULL == p)
-                       return KERN_FAILURE;
-                       
-               strlcpy(gPropTable[gRegisteredProps].name, name, sizeof(gPropTable[0].name));
-               gPropTable[gRegisteredProps].nelements = nelements;
-               gPropTable[gRegisteredProps].data = p;
-                       
-               while (nelements-- > 0) {
-                       *p++ = (int)(*data++);
-               }
-               
-               gRegisteredProps++;
-               return KERN_SUCCESS;
-       }
-       else
-               return KERN_FAILURE;
-}
-
-int
-ddi_prop_lookup_int_array(dev_t match_dev, dev_info_t *dip, uint_t flags,
-    const char *name, int **data, uint_t *nelements)
-{
-#pragma unused(match_dev,dip,flags)
-       unsigned int i;
-       for (i = 0; i < gRegisteredProps; ++i)
-       {
-               if (0 == strncmp(name, gPropTable[i].name,
-                                       sizeof(gPropTable[i].name))) {
-                       *data = gPropTable[i].data;
-                       *nelements = gPropTable[i].nelements;
-                       return DDI_SUCCESS;
-               }
-       }
-       return DDI_FAILURE;
-}
-       
-int
-ddi_prop_free(void *buf)
-{
-       _FREE(buf, M_TEMP);
-       return DDI_SUCCESS;
+#pragma unused(name, data, nelements)
+       return KERN_FAILURE;
 }
 
 int
@@ -1249,6 +1180,30 @@ dtrace_copyoutstr(uintptr_t src, user_addr_t dst, size_t len, volatile uint16_t
        }
 }
 
+extern const int copysize_limit_panic;
+
+int
+dtrace_buffer_copyout(const void *kaddr, user_addr_t uaddr, vm_size_t nbytes)
+{
+       /*
+        * Partition the copyout in copysize_limit_panic-sized chunks
+        */
+       while (nbytes >= (vm_size_t)copysize_limit_panic) {
+               if (copyout(kaddr, uaddr, copysize_limit_panic) != 0)
+                       return (EFAULT);
+
+               nbytes -= copysize_limit_panic;
+               uaddr += copysize_limit_panic;
+               kaddr += copysize_limit_panic;
+       }
+       if (nbytes > 0) {
+               if (copyout(kaddr, uaddr, nbytes) != 0)
+                       return (EFAULT);
+       }
+
+       return (0);
+}
+
 uint8_t
 dtrace_fuword8(user_addr_t uaddr)
 {
@@ -1483,6 +1438,8 @@ strstr(const char *in, const char *str)
 {
     char c;
     size_t len;
+    if (!in || !str)
+        return in;
 
     c = *str++;
     if (!c)
@@ -1502,6 +1459,26 @@ strstr(const char *in, const char *str)
     return (const char *) (in - 1);
 }
 
+const void*
+bsearch(const void *key, const void *base0, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
+{
+       const char *base = base0;
+       size_t lim;
+       int cmp;
+       const void *p;
+       for (lim = nmemb; lim != 0; lim >>= 1) {
+               p = base + (lim >> 1) * size;
+               cmp = (*compar)(key, p);
+               if (cmp == 0)
+                       return p;
+               if (cmp > 0) {  /* key > p: move right */
+                       base = (const char *)p + size;
+                       lim--;
+               }               /* else move left */
+       }
+       return (NULL);
+}
+
 /*
  * Runtime and ABI
  */