]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/dtrace_glue.h
xnu-4570.31.3.tar.gz
[apple/xnu.git] / bsd / sys / dtrace_glue.h
CommitLineData
2d21ac55
A
1/*
2 * Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _DTRACE_GLUE_H
30#define _DTRACE_GLUE_H
31
32#ifdef KERNEL_BUILD
33
34#include <libkern/libkern.h>
2d21ac55 35#include <kern/locks.h>
5ba3f43e 36#include <kern/debug.h>
2d21ac55 37#include <kern/thread_call.h>
4a3eedf9 38#include <kern/thread.h>
2d21ac55
A
39#include <machine/machine_routines.h>
40#include <sys/syslog.h>
41#include <sys/ucred.h>
42#include <stdarg.h>
43#include <mach/kmod.h>
44#include <libkern/OSAtomic.h>
45
6d2010ae
A
46#if defined(__i386__) || defined(__x86_64__)
47#include <i386/mp.h>
48#endif
49
2d21ac55
A
50/*
51 * cmn_err
52 */
53#define CE_CONT 0 /* continuation */
54#define CE_NOTE 1 /* notice */
55#define CE_WARN 2 /* warning */
56#define CE_PANIC 3 /* panic */
57#define CE_IGNORE 4 /* print nothing */
58
59extern void cmn_err( int, const char *, ... );
60
61/*
62 * pid/proc
63 */
64
b0d623f7
A
65/* Solaris proc_t is the struct. Darwin's proc_t is a pointer to it. */
66#define proc_t struct proc /* Steer clear of the Darwin typedef for proc_t */
2d21ac55
A
67#define curproc ((struct proc *)current_proc()) /* Called from probe context, must blacklist */
68
69proc_t* sprlock(pid_t pid);
70void sprunlock(proc_t *p);
71
72/*
73 * uread/uwrite
74 */
75
76int uread(proc_t *p, void *buf, user_size_t len, user_addr_t a);
77int uwrite(proc_t *p, void *buf, user_size_t len, user_addr_t a);
78
79/*
80 * fuword / suword
81 */
82
83int fuword8(user_addr_t, uint8_t *);
84int fuword16(user_addr_t, uint16_t *);
85int fuword32(user_addr_t, uint32_t *);
86int fuword64(user_addr_t, uint64_t *);
87
88void fuword8_noerr(user_addr_t, uint8_t *);
89void fuword16_noerr(user_addr_t, uint16_t *);
90void fuword32_noerr(user_addr_t, uint32_t *);
91void fuword64_noerr(user_addr_t, uint64_t *);
92
93int suword64(user_addr_t, uint64_t value);
94int suword32(user_addr_t, uint32_t value);
95int suword16(user_addr_t, uint16_t value);
96int suword8(user_addr_t, uint8_t value);
97
98/*
99 * cpuvar
100 */
101extern lck_mtx_t cpu_lock;
fe8ab488 102extern lck_mtx_t cyc_lock;
2d21ac55
A
103extern lck_mtx_t mod_lock;
104
fe8ab488
A
105/*
106 * wrap_timer_call: wrapper of timer_call for cyclic timers.
107 */
108struct wrap_timer_call;
109
2d21ac55
A
110/*
111 * Per-CPU data.
112 */
6d2010ae 113typedef struct dtrace_cpu {
2d21ac55 114 processorid_t cpu_id; /* CPU number */
6d2010ae 115 struct dtrace_cpu *cpu_next; /* next existing CPU */
2d21ac55
A
116 lck_rw_t cpu_ft_lock; /* DTrace: fasttrap lock */
117 uintptr_t cpu_dtrace_caller; /* DTrace: caller, if any */
118 hrtime_t cpu_dtrace_chillmark; /* DTrace: chill mark time */
119 hrtime_t cpu_dtrace_chilled; /* DTrace: total chill time */
120 boolean_t cpu_dtrace_invop_underway; /* DTrace gaurds against invalid op re-entrancy */
fe8ab488
A
121
122 /* Local cyclic timers on this CPU */
123 LIST_HEAD(cyc_list_head, wrap_timer_call) cpu_cyc_list;
6d2010ae 124} dtrace_cpu_t;
2d21ac55 125
6d2010ae 126extern dtrace_cpu_t *cpu_list;
2d21ac55
A
127
128/*
129 * The cpu_core structure consists of per-CPU state available in any context.
130 * On some architectures, this may mean that the page(s) containing the
131 * NCPU-sized array of cpu_core structures must be locked in the TLB -- it
132 * is up to the platform to assure that this is performed properly. Note that
133 * the structure is sized to avoid false sharing.
134 */
135#define CPU_CACHE_COHERENCE_SIZE 64
2d21ac55
A
136
137typedef struct cpu_core {
2d21ac55
A
138 uint64_t cpuc_dtrace_illval; /* DTrace illegal value */
139 lck_mtx_t cpuc_pid_lock; /* DTrace pid provider lock */
b0d623f7
A
140 uint16_t cpuc_dtrace_flags; /* DTrace flags */
141 uint64_t cpuc_missing_tos; /* Addr. of top most stack frame if missing */
142 uint8_t cpuc_pad[CPU_CACHE_COHERENCE_SIZE - sizeof(uint64_t) - sizeof(lck_mtx_t) - sizeof(uint16_t) - sizeof(uint64_t) ]; /* padding */
2d21ac55
A
143} cpu_core_t;
144
b0d623f7 145extern cpu_core_t *cpu_core;
6d2010ae 146
39236c6e
A
147extern unsigned int dtrace_max_cpus; /* max number of enabled cpus */
148#define NCPU dtrace_max_cpus
6d2010ae 149
b0d623f7 150extern int cpu_number(void); /* From #include <kern/cpu_number.h>. Called from probe context, must blacklist. */
2d21ac55
A
151
152#define CPU (&(cpu_list[cpu_number()])) /* Pointer to current CPU */
153#define CPU_ON_INTR(cpup) ml_at_interrupt_context() /* always invoked on current cpu */
2d21ac55
A
154
155/*
156 * Routines used to register interest in cpu's being added to or removed
157 * from the system.
158 */
159typedef enum {
160 CPU_INIT,
161 CPU_CONFIG,
162 CPU_UNCONFIG,
163 CPU_ON,
164 CPU_OFF,
165 CPU_CPUPART_IN,
166 CPU_CPUPART_OUT
167} cpu_setup_t;
168
169typedef int cpu_setup_func_t(cpu_setup_t, int, void *);
170
171extern void register_cpu_setup_func(cpu_setup_func_t *, void *);
172extern void unregister_cpu_setup_func(cpu_setup_func_t *, void *);
173
174/*
175 * CPU_DTRACE
176 */
177
178/*
179 * DTrace flags.
180 */
181#define CPU_DTRACE_NOFAULT 0x0001 /* Don't fault */
182#define CPU_DTRACE_DROP 0x0002 /* Drop this ECB */
183#define CPU_DTRACE_BADADDR 0x0004 /* DTrace fault: bad address */
184#define CPU_DTRACE_BADALIGN 0x0008 /* DTrace fault: bad alignment */
185#define CPU_DTRACE_DIVZERO 0x0010 /* DTrace fault: divide by zero */
186#define CPU_DTRACE_ILLOP 0x0020 /* DTrace fault: illegal operation */
187#define CPU_DTRACE_NOSCRATCH 0x0040 /* DTrace fault: out of scratch */
188#define CPU_DTRACE_KPRIV 0x0080 /* DTrace fault: bad kernel access */
189#define CPU_DTRACE_UPRIV 0x0100 /* DTrace fault: bad user access */
190#define CPU_DTRACE_TUPOFLOW 0x0200 /* DTrace fault: tuple stack overflow */
2d21ac55
A
191#define CPU_DTRACE_USTACK_FP 0x0400 /* pid provider hint to ustack() */
192#define CPU_DTRACE_ENTRY 0x0800 /* pid provider hint to ustack() */
b0d623f7 193#define CPU_DTRACE_BADSTACK 0x1000 /* DTrace fault: bad stack */
2d21ac55
A
194
195#define CPU_DTRACE_FAULT (CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \
196 CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \
197 CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \
b0d623f7
A
198 CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \
199 CPU_DTRACE_BADSTACK)
2d21ac55
A
200#define CPU_DTRACE_ERROR (CPU_DTRACE_FAULT | CPU_DTRACE_DROP)
201
6d2010ae
A
202/*
203 * Loadable Modules
204 */
205
206/* Keep the compiler happy */
207struct dtrace_module_symbols;
208
209/* Solaris' modctl structure, greatly simplified, shadowing parts of xnu kmod structure. */
210typedef struct modctl {
211 struct modctl *mod_next;
212 struct modctl *mod_stale; // stale module chain
213 uint32_t mod_id; // the kext unique identifier
214 char mod_modname[KMOD_MAX_NAME];
215 int mod_loadcnt;
216 char mod_loaded;
fe8ab488 217 uint16_t mod_flags; // See flags below
6d2010ae
A
218 int mod_nenabled; // # of enabled DTrace probes in module
219 vm_address_t mod_address; // starting address (of Mach-o header blob)
220 vm_size_t mod_size; // total size (of blob)
221 UUID mod_uuid;
222 struct dtrace_module_symbols* mod_user_symbols;
223} modctl_t;
224
225/* Definitions for mod_flags */
fe8ab488
A
226#define MODCTL_IS_MACH_KERNEL 0x01 // This module represents /mach_kernel
227#define MODCTL_HAS_KERNEL_SYMBOLS 0x02 // Kernel symbols (nlist) are available
228#define MODCTL_FBT_PROBES_PROVIDED 0x04 // fbt probes have been provided
229#define MODCTL_FBT_INVALID 0x08 // Module is invalid for fbt probes
230#define MODCTL_SDT_PROBES_PROVIDED 0x10 // sdt probes have been provided
231#define MODCTL_SDT_INVALID 0x20 // Module is invalid for sdt probes
232#define MODCTL_HAS_UUID 0x40 // Module has UUID
233#define MODCTL_FBT_PRIVATE_PROBES_PROVIDED 0x80 // fbt private probes have been provided
234#define MODCTL_FBT_PROVIDE_PRIVATE_PROBES 0x100 // fbt provider must provide private probes
5ba3f43e
A
235#define MODCTL_FBT_PROVIDE_BLACKLISTED_PROBES 0x200 // fbt provider must provide blacklisted probes
236#define MODCTL_FBT_BLACKLISTED_PROBES_PROVIDED 0x400 // fbt blacklisted probes have been provided
6d2010ae
A
237
238/* Simple/singular mod_flags accessors */
239#define MOD_IS_MACH_KERNEL(mod) (mod->mod_flags & MODCTL_IS_MACH_KERNEL)
240#define MOD_HAS_KERNEL_SYMBOLS(mod) (mod->mod_flags & MODCTL_HAS_KERNEL_SYMBOLS)
241#define MOD_HAS_USERSPACE_SYMBOLS(mod) (mod->mod_user_symbols) /* No point in duplicating state in the flags bits */
242#define MOD_FBT_PROBES_PROVIDED(mod) (mod->mod_flags & MODCTL_FBT_PROBES_PROVIDED)
243#define MOD_FBT_INVALID(mod) (mod->mod_flags & MODCTL_FBT_INVALID)
244#define MOD_SDT_PROBES_PROVIDED(mod) (mod->mod_flags & MODCTL_SDT_PROBES_PROVIDED)
245#define MOD_SDT_INVALID(mod) (mod->mod_flags & MODCTL_SDT_INVALID)
246#define MOD_HAS_UUID(mod) (mod->mod_flags & MODCTL_HAS_UUID)
fe8ab488
A
247#define MOD_FBT_PRIVATE_PROBES_PROVIDED(mod) (mod->mod_flags & MODCTL_FBT_PRIVATE_PROBES_PROVIDED)
248#define MOD_FBT_PROVIDE_PRIVATE_PROBES(mod) (mod->mod_flags & MODCTL_FBT_PROVIDE_PRIVATE_PROBES)
5ba3f43e
A
249#define MOD_FBT_BLACKLISTED_PROBES_PROVIDED(mod) (mod->mod_flags & MODCTL_FBT_BLACKLISTED_PROBES_PROVIDED)
250#define MOD_FBT_PROVIDE_BLACKLISTED_PROBES(mod) (mod->mod_flags & MODCTL_FBT_PROVIDE_BLACKLISTED_PROBES)
6d2010ae
A
251
252/* Compound accessors */
fe8ab488 253#define MOD_FBT_PRIVATE_PROBES_DONE(mod) (MOD_FBT_PRIVATE_PROBES_PROVIDED(mod) || !MOD_FBT_PROVIDE_PRIVATE_PROBES(mod))
5ba3f43e
A
254#define MOD_FBT_BLACKLISTED_PROBES_DONE(mod) (MOD_FBT_BLACKLISTED_PROBES_PROVIDED(mod) || !MOD_FBT_PROVIDE_BLACKLISTED_PROBES(mod))
255#define MOD_FBT_DONE(mod) ((MOD_FBT_PROBES_PROVIDED(mod) && MOD_FBT_PRIVATE_PROBES_DONE(mod) && MOD_FBT_BLACKLISTED_PROBES_DONE(mod)) || MOD_FBT_INVALID(mod))
6d2010ae
A
256#define MOD_SDT_DONE(mod) (MOD_SDT_PROBES_PROVIDED(mod) || MOD_SDT_INVALID(mod))
257#define MOD_SYMBOLS_DONE(mod) (MOD_FBT_DONE(mod) && MOD_SDT_DONE(mod))
258
259extern modctl_t *dtrace_modctl_list;
260
2d21ac55
A
261/*
262 * cred_t
263 */
264/* Privileges */
265#define PRIV_DTRACE_KERNEL 3
266#define PRIV_DTRACE_PROC 4
267#define PRIV_DTRACE_USER 5
268#define PRIV_PROC_OWNER 30
269#define PRIV_PROC_ZONE 35
270#define PRIV_ALL (-1) /* All privileges required */
271
272/* Privilege sets */
273#define PRIV_EFFECTIVE 0
274
275typedef struct ucred cred_t;
276#define cr_suid cr_svuid
277#define cr_sgid cr_svgid
278
279extern cred_t *dtrace_CRED(void); /* Safe to call from probe context. */
280#define CRED() kauth_cred_get() /* Can't be called from probe context! */
281extern int PRIV_POLICY_CHOICE(void *, int, int);
282extern int PRIV_POLICY_ONLY(void *, int, int);
283extern gid_t crgetgid(const cred_t *);
284extern uid_t crgetuid(const cred_t *);
285#define crgetzoneid(x) ((zoneid_t)0)
286
287#define crhold(a) {}
288#define crfree(a) {}
289
290/*
291 * "cyclic"
292 */
293#define CY_LOW_LEVEL 0
294#define CY_LOCK_LEVEL 1
295#define CY_HIGH_LEVEL 2
296#define CY_SOFT_LEVELS 2
297#define CY_LEVELS 3
298
299typedef uintptr_t cyclic_id_t;
300typedef cyclic_id_t *cyclic_id_list_t;
301typedef uint16_t cyc_level_t;
302typedef void (*cyc_func_t)(void *);
303
304#define CYCLIC_NONE ((cyclic_id_t)0)
305
306typedef struct cyc_time {
307 hrtime_t cyt_when;
308 hrtime_t cyt_interval;
309} cyc_time_t;
310
311typedef struct cyc_handler {
312 cyc_func_t cyh_func;
313 void *cyh_arg;
314 cyc_level_t cyh_level;
315} cyc_handler_t;
316
317typedef struct cyc_omni_handler {
6d2010ae
A
318 void (*cyo_online)(void *, dtrace_cpu_t *, cyc_handler_t *, cyc_time_t *);
319 void (*cyo_offline)(void *, dtrace_cpu_t *, void *);
2d21ac55
A
320 void *cyo_arg;
321} cyc_omni_handler_t;
322
fe8ab488
A
323extern void dtrace_install_cpu_hooks(void);
324
2d21ac55
A
325extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
326extern void cyclic_remove(cyclic_id_t);
327
328extern cyclic_id_list_t cyclic_add_omni(cyc_omni_handler_t *);
329extern void cyclic_remove_omni(cyclic_id_list_t);
330
331extern cyclic_id_t cyclic_timer_add(cyc_handler_t *, cyc_time_t *);
332extern void cyclic_timer_remove(cyclic_id_t);
333
2d21ac55
A
334/*
335 * ddi
336 */
337
338#define DDI_SUCCESS 0
339#define DDI_FAILURE -1
340
341#define DDI_DEV_T_NONE ((dev_t)-1)
342#define DDI_DEV_T_ANY ((dev_t)-2)
343#define DDI_MAJOR_T_UNKNOWN ((major_t)0)
344
345#define DDI_PSEUDO "ddi_pseudo"
346
347typedef enum {
348 DDI_ATTACH = 0,
349 DDI_RESUME = 1,
350 DDI_PM_RESUME = 2
351} ddi_attach_cmd_t;
352
353typedef enum {
354 DDI_DETACH = 0,
355 DDI_SUSPEND = 1,
356 DDI_PM_SUSPEND = 2,
357 DDI_HOTPLUG_DETACH = 3 /* detach, don't try to auto-unconfig */
358} ddi_detach_cmd_t;
359
360#define DDI_PROP_SUCCESS 0
361
362#define DDI_PROP_DONTPASS 1
363typedef uint_t major_t;
364typedef uint_t minor_t;
365
366typedef struct __dev_info *dev_info_t;
367
368extern void ddi_report_dev(dev_info_t *);
2d21ac55
A
369
370int ddi_getprop(dev_t dev, dev_info_t *dip, int flags, const char *name, int defvalue);
371
372extern int ddi_prop_free(void *);
b0d623f7 373extern int ddi_prop_lookup_int_array(dev_t, dev_info_t *, uint_t, const char *, int **, uint_t *);
2d21ac55
A
374
375extern int ddi_driver_major(dev_info_t *);
376
377extern int ddi_create_minor_node(dev_info_t *, const char *, int, minor_t, const char *, int);
378extern void ddi_remove_minor_node(dev_info_t *, char *);
379
380extern major_t getemajor(dev_t);
381extern minor_t getminor(dev_t);
382
2d21ac55
A
383extern dev_t makedevice(major_t, minor_t);
384
385/*
386 * Kernel Debug Interface
387 */
388
389typedef enum kdi_dtrace_set {
390 KDI_DTSET_DTRACE_ACTIVATE,
391 KDI_DTSET_DTRACE_DEACTIVATE,
392 KDI_DTSET_KMDB_BPT_ACTIVATE,
393 KDI_DTSET_KMDB_BPT_DEACTIVATE
394} kdi_dtrace_set_t;
395
396extern int kdi_dtrace_set(kdi_dtrace_set_t);
397extern void debug_enter(char *);
398
399/*
400 * DTrace specific zone allocation
401 */
402
403/*
404 * To break dtrace memory usage out in a trackable
405 * fashion, uncomment the #define below. This will
406 * enable emulation of the general kalloc.XXX zones
407 * for most dtrace allocations. (kalloc.large is not
408 * emulated)
409 *
410 * #define DTRACE_MEMORY_ZONES 1
411 *
412 */
413
414#if defined(DTRACE_MEMORY_ZONES)
415void dtrace_alloc_init(void);
416void *dtrace_alloc(vm_size_t);
417void dtrace_free(void *, vm_size_t);
418#endif
419
420/*
421 * kmem
422 */
423
424#define KM_SLEEP 0x00000000
425#define KM_NOSLEEP 0x00000001
426
427typedef struct vmem vmem_t;
428typedef struct kmem_cache kmem_cache_t;
429
430#define kmem_alloc dt_kmem_alloc /* Avoid clash with Darwin's kmem_alloc */
431#define kmem_free dt_kmem_free /* Avoid clash with Darwin's kmem_free */
432#define kmem_zalloc dt_kmem_zalloc /* Avoid clash with Darwin's kmem_zalloc */
433extern void *dt_kmem_alloc(size_t, int);
434extern void dt_kmem_free(void *, size_t);
435extern void *dt_kmem_zalloc(size_t, int);
436
437extern void *dt_kmem_alloc_aligned(size_t, size_t, int);
438extern void *dt_kmem_zalloc_aligned(size_t, size_t, int);
439extern void dt_kmem_free_aligned(void*, size_t);
440
441extern kmem_cache_t *
b0d623f7 442kmem_cache_create(const char *, size_t, size_t, int (*)(void *, void *, int),
2d21ac55
A
443 void (*)(void *, void *), void (*)(void *), void *, vmem_t *, int);
444extern void *kmem_cache_alloc(kmem_cache_t *, int);
445extern void kmem_cache_free(kmem_cache_t *, void *);
446extern void kmem_cache_destroy(kmem_cache_t *);
447
448/*
449 * kthread
450 */
451
452typedef struct _kthread kthread_t; /* For dtrace_vtime_switch(), dtrace_panicked and dtrace_errthread */
453
2d21ac55
A
454/*
455 * proc
456 */
457
458#define DATAMODEL_MASK 0x0FF00000
459
460#define DATAMODEL_ILP32 0x00100000
461#define DATAMODEL_LP64 0x00200000
462
463#define DATAMODEL_NONE 0
464
465#if defined(__LP64__)
466#define DATAMODEL_NATIVE DATAMODEL_LP64
467#else
468#define DATAMODEL_NATIVE DATAMODEL_ILP32
469#endif /* __LP64__ */
470
471typedef unsigned int model_t; /* For dtrace_instr_size_isa() prototype in <sys/dtrace.h> */
472
473/*
474 * taskq
475 */
476
477#define TQ_SLEEP 0x00 /* Can block for memory */
478
479typedef uint_t pri_t;
480typedef struct taskq taskq_t;
481typedef void (task_func_t)(void *);
482typedef uintptr_t taskqid_t;
483
484extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
485extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
486extern void taskq_destroy(taskq_t *);
487
488extern pri_t maxclsyspri;
489
490/*
491 * vmem
492 */
493
494#define VMC_IDENTIFIER 0x00040000 /* not backed by memory */
495#define VM_SLEEP 0x00000000 /* same as KM_SLEEP */
496#define VM_BESTFIT 0x00000100
497
498extern void *vmem_alloc(vmem_t *, size_t, int);
499extern vmem_t *vmem_create(const char *, void *, size_t, size_t, void *,
500 void *, vmem_t *, size_t, int);
501extern void vmem_destroy(vmem_t *);
502extern void vmem_free(vmem_t *vmp, void *vaddr, size_t size);
503
504/*
505 * Atomic
506 */
507
5ba3f43e
A
508static inline uint8_t atomic_or_8(uint8_t *addr, uint8_t mask)
509{
510 return OSBitOrAtomic8(mask, addr);
511}
512
513static inline uint32_t atomic_and_32( uint32_t *addr, int32_t mask)
514{
515 return OSBitAndAtomic(mask, addr);
516}
517
39037602 518static inline uint32_t atomic_add_32( uint32_t *theAddress, int32_t theAmount )
2d21ac55 519{
39037602 520 return OSAddAtomic( theAmount, theAddress );
2d21ac55
A
521}
522
b0d623f7 523#if defined(__i386__) || defined(__x86_64__)
39236c6e 524static inline void atomic_add_64( uint64_t *theAddress, int64_t theAmount )
b0d623f7 525{
39236c6e 526 (void)OSAddAtomic64( theAmount, (SInt64 *)theAddress );
b0d623f7 527}
5ba3f43e
A
528#elif defined(__arm__)
529static inline void atomic_add_64( uint64_t *theAddress, int64_t theAmount )
39037602 530{
5ba3f43e
A
531 // FIXME
532 // atomic_add_64() is at present only called from fasttrap.c to increment
533 // or decrement a 64bit counter. Narrow to 32bits since arm has
534 // no convenient 64bit atomic op.
535
536 (void)OSAddAtomic( (int32_t)theAmount, &(((SInt32 *)theAddress)[0]));
39037602 537}
5ba3f43e
A
538#elif defined (__arm64__)
539static inline void atomic_add_64( uint64_t *theAddress, int64_t theAmount )
540{
541 (void)OSAddAtomic64( theAmount, (SInt64 *)theAddress );
542}
543#endif
39037602
A
544
545static inline uint32_t atomic_or_32(uint32_t *addr, uint32_t mask)
546{
547 return OSBitOrAtomic(mask, addr);
548}
549
550
2d21ac55
A
551/*
552 * Miscellaneous
553 */
554
555typedef uintptr_t pc_t;
556typedef uintptr_t greg_t; /* For dtrace_impl.h prototype of dtrace_getfp() */
5ba3f43e
A
557#if defined(__arm__) || defined(__arm64__)
558#define regs arm_saved_state
559#endif
2d21ac55
A
560extern struct regs *find_user_regs( thread_t thread);
561extern vm_offset_t dtrace_get_cpu_int_stack_top(void);
562extern vm_offset_t max_valid_stack_address(void); /* kern/thread.h */
2d21ac55 563
5ba3f43e 564#define panic_quiesce (panic_active())
2d21ac55
A
565
566#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
567
2d21ac55
A
568extern int vuprintf(const char *, va_list);
569
2d21ac55
A
570extern hrtime_t dtrace_abs_to_nano(uint64_t);
571
b0d623f7 572__private_extern__ const char * strstr(const char *, const char *);
5ba3f43e
A
573const void* bsearch(const void*, const void*, size_t, size_t, int (*compar)(const void *, const void *));
574
575int dtrace_buffer_copyout(const void*, user_addr_t, vm_size_t);
576
2d21ac55 577
39037602
A
578#define DTRACE_NCLIENTS 32
579
2d21ac55
A
580#undef proc_t
581
b0d623f7
A
582/*
583 * Safe counted string compare against a literal string. The sizeof() intentionally
584 * counts the trailing NUL, and so ensures that all the characters in the literal
585 * can participate in the comparison.
586 */
587#define LIT_STRNEQL(s1, lit_s2) (0 == strncmp( (s1), (lit_s2), sizeof((lit_s2)) ))
588
589/*
590 * Safe counted string compare of a literal against the beginning of a string. Here
591 * the sizeof() is reduced by 1 so that the trailing null of the literal does not
592 * participate in the comparison.
593 */
594#define LIT_STRNSTART(s1, lit_s2) (0 == strncmp( (s1), (lit_s2), sizeof((lit_s2)) - 1 ))
595
596#define KERNELBASE VM_MIN_KERNEL_ADDRESS
2d21ac55
A
597#endif /* KERNEL_BUILD */
598#endif /* _DTRACE_GLUE_H */
599