X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/0a7de7458d150b5d4dffc935ba399be265ef0a1a..a991bd8d3e7fe02dbca0644054bab73c5b75324a:/bsd/dev/dtrace/dtrace_glue.c diff --git a/bsd/dev/dtrace/dtrace_glue.c b/bsd/dev/dtrace/dtrace_glue.c index d33a8f030..ffbd0bb15 100644 --- a/bsd/dev/dtrace/dtrace_glue.c +++ b/bsd/dev/dtrace/dtrace_glue.c @@ -26,45 +26,28 @@ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ - -/* - * APPLE NOTE: This file is compiled even if dtrace is unconfig'd. A symbol - * from this file (_dtrace_register_anon_DOF) always needs to be exported for - * an external kext to link against. - */ - -#if CONFIG_DTRACE - -#define MACH__POSIX_C_SOURCE_PRIVATE 1 /* pulls in suitable savearea from mach/ppc/thread_status.h */ #include -#include -#include -#include -#include #include #include -#include #include #include #include #include #include -#include +#include #include #include #include #include #include #include -#include #include #include #include #include #include -#include #include /* All the bits we care about are guarded by MACH_KERNEL_PRIVATE :-( */ /* @@ -73,10 +56,11 @@ /* 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 */ +KALLOC_HEAP_DEFINE(KHEAP_DTRACE, "dtrace", KHEAP_ID_DEFAULT); + void dtrace_sprlock(proc_t *p) { - lck_mtx_assert(&p->p_mlock, LCK_MTX_ASSERT_NOTOWNED); lck_mtx_lock(&p->p_dtrace_sprlock); } @@ -100,8 +84,6 @@ sprlock(pid_t pid) dtrace_sprlock(p); - proc_lock(p); - return p; } @@ -110,8 +92,6 @@ void sprunlock(proc_t *p) { if (p != PROC_NULL) { - proc_unlock(p); - dtrace_sprunlock(p); task_resume_internal(p->task); @@ -273,11 +253,6 @@ dtrace_CRED(void) } } -#define HAS_ALLPRIVS(cr) priv_isfullset(&CR_OEPRIV(cr)) -#define HAS_PRIVILEGE(cr, pr) ((pr) == PRIV_ALL ? \ - HAS_ALLPRIVS(cr) : \ - PRIV_ISASSERT(&CR_OEPRIV(cr), pr)) - int PRIV_POLICY_CHOICE(void* cred, int priv, int all) { @@ -605,15 +580,6 @@ cyclic_remove(cyclic_id_t cyclic) } } -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) -{ -#pragma unused(name, data, nelements) - return KERN_FAILURE; -} - int ddi_driver_major(dev_info_t *devi) { @@ -672,10 +638,9 @@ dt_kmem_alloc_site(size_t size, int kmflag, vm_allocation_site_t *site) /* * We ignore the M_NOWAIT bit in kmflag (all of kmflag, in fact). - * Requests larger than 8K with M_NOWAIT fail in kalloc_canblock. + * Requests larger than 8K with M_NOWAIT fail in kalloc_ext. */ - vm_size_t vsize = size; - return kalloc_canblock(&vsize, TRUE, site); + return kalloc_ext(KHEAP_DTRACE, size, Z_WAITOK, site).addr; } void * @@ -685,35 +650,15 @@ dt_kmem_zalloc_site(size_t size, int kmflag, vm_allocation_site_t *site) /* * We ignore the M_NOWAIT bit in kmflag (all of kmflag, in fact). - * Requests larger than 8K with M_NOWAIT fail in kalloc_canblock. + * Requests larger than 8K with M_NOWAIT fail in kalloc_ext. */ - vm_size_t vsize = size; - void* buf = kalloc_canblock(&vsize, TRUE, site); - - if (!buf) { - return NULL; - } - - bzero(buf, size); - - return buf; + return kalloc_ext(KHEAP_DTRACE, size, Z_WAITOK | Z_ZERO, site).addr; } void dt_kmem_free(void *buf, size_t size) { -#pragma unused(size) - /* - * DTrace relies on this, its doing a lot of NULL frees. - * A null free causes the debug builds to panic. - */ - if (buf == NULL) { - return; - } - - ASSERT(size > 0); - - kfree(buf, size); + kheap_free(KHEAP_DTRACE, buf, size); } @@ -855,12 +800,13 @@ vmem_create(const char *name, void *base, size_t size, size_t quantum, void *ign ASSERT(NULL == ignore6); ASSERT(NULL == source); ASSERT(0 == qcache_max); + ASSERT(size <= INT32_MAX); ASSERT(vmflag & VMC_IDENTIFIER); size = MIN(128, size); /* Clamp to 128 initially, since the underlying data structure is pre-allocated */ - p->blist = bl = blist_create( size ); - blist_free(bl, 0, size); + p->blist = bl = blist_create((daddr_t)size); + blist_free(bl, 0, (daddr_t)size); if (base) { blist_alloc( bl, (daddr_t)(uintptr_t)base ); /* Chomp off initial ID(s) */ } @@ -877,11 +823,11 @@ vmem_alloc(vmem_t *vmp, size_t size, int vmflag) p = blist_alloc(bl, (daddr_t)size); - if ((daddr_t)-1 == p) { + if (p == SWAPBLK_NONE) { blist_resize(&bl, (bl->bl_blocks) << 1, 1); q->blist = bl; p = blist_alloc(bl, (daddr_t)size); - if ((daddr_t)-1 == p) { + if (p == SWAPBLK_NONE) { panic("vmem_alloc: failure after blist_resize!"); } } @@ -1371,39 +1317,6 @@ cmn_err( int level, const char *format, ... ) uprintf("\n"); } -/* - * History: - * 2002-01-24 gvdl Initial implementation of strstr - */ - -__private_extern__ const char * -strstr(const char *in, const char *str) -{ - char c; - size_t len; - if (!in || !str) { - return in; - } - - c = *str++; - if (!c) { - return (const char *) in; // Trivial empty string case - } - len = strlen(str); - do { - char sc; - - do { - sc = *in++; - if (!sc) { - return (char *) 0; - } - } while (sc != c); - } while (strncmp(in, str, len) != 0); - - 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 *)) { @@ -1503,25 +1416,3 @@ void dtrace_vtime_disable(void) { } - -#else /* else ! CONFIG_DTRACE */ - -#include -#include -#include - -/* - * This exists to prevent build errors when dtrace is unconfigured. - */ - -kern_return_t _dtrace_register_anon_DOF(char *, unsigned char *, uint32_t); - -kern_return_t -_dtrace_register_anon_DOF(char *arg1, unsigned char *arg2, uint32_t arg3) -{ -#pragma unused(arg1, arg2, arg3) - - return KERN_FAILURE; -} - -#endif /* CONFIG_DTRACE */