* @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 <kern/thread.h>
-#include <mach/thread_status.h>
-#include <stdarg.h>
-#include <string.h>
-#include <sys/malloc.h>
#include <sys/time.h>
#include <sys/proc.h>
-#include <sys/proc_internal.h>
#include <sys/kauth.h>
#include <sys/user.h>
#include <sys/systm.h>
#include <sys/dtrace.h>
#include <sys/dtrace_impl.h>
-#include <libkern/OSAtomic.h>
+#include <machine/atomic.h>
#include <libkern/OSKextLibPrivate.h>
#include <kern/kern_types.h>
#include <kern/timer_call.h>
#include <kern/thread_call.h>
#include <kern/task.h>
#include <kern/sched_prim.h>
-#include <kern/queue.h>
#include <miscfs/devfs/devfs.h>
#include <kern/kalloc.h>
#include <mach/vm_param.h>
#include <mach/mach_vm.h>
#include <mach/task.h>
-#include <vm/pmap.h>
#include <vm/vm_map.h> /* All the bits we care about are guarded by MACH_KERNEL_PRIVATE :-( */
/*
/* 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);
}
dtrace_sprlock(p);
- proc_lock(p);
-
return p;
}
sprunlock(proc_t *p)
{
if (p != PROC_NULL) {
- proc_unlock(p);
-
dtrace_sprunlock(p);
task_resume_internal(p->task);
}
}
-#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)
{
}
}
-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)
{
/*
* 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 *
/*
* 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);
}
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) */
}
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!");
}
}
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 *))
{
dtrace_vtime_disable(void)
{
}
-
-#else /* else ! CONFIG_DTRACE */
-
-#include <sys/types.h>
-#include <mach/vm_types.h>
-#include <mach/kmod.h>
-
-/*
- * 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 */