+extern vm_size_t zone_element_size(
+ void *addr,
+ zone_t *z);
+
+/*
+ * MAX_ZTRACE_DEPTH configures how deep of a stack trace is taken on each zalloc in the zone of interest. 15
+ * levels is usually enough to get past all the layers of code in kalloc and IOKit and see who the actual
+ * caller is up above these lower levels.
+ *
+ * This is used both for the zone leak detector and the zone corruption log.
+ */
+
+#define MAX_ZTRACE_DEPTH 15
+
+/*
+ * Structure for keeping track of a backtrace, used for leak detection.
+ * This is in the .h file because it is used during panic, see kern/debug.c
+ * A non-zero size indicates that the trace is in use.
+ */
+struct ztrace {
+ vm_size_t zt_size; /* How much memory are all the allocations referring to this trace taking up? */
+ uint32_t zt_depth; /* depth of stack (0 to MAX_ZTRACE_DEPTH) */
+ void* zt_stack[MAX_ZTRACE_DEPTH]; /* series of return addresses from OSBacktrace */
+ uint32_t zt_collisions; /* How many times did a different stack land here while it was occupied? */
+ uint32_t zt_hit_count; /* for determining effectiveness of hash function */
+};
+
+#if CONFIG_ZLEAKS
+
+/* support for the kern.zleak.* sysctls */
+
+extern kern_return_t zleak_activate(void);
+extern vm_size_t zleak_max_zonemap_size;
+extern vm_size_t zleak_global_tracking_threshold;
+extern vm_size_t zleak_per_zone_tracking_threshold;
+
+extern int get_zleak_state(void);
+
+#endif /* CONFIG_ZLEAKS */
+
+#ifndef VM_MAX_TAG_ZONES
+#error MAX_TAG_ZONES
+#endif
+
+#if VM_MAX_TAG_ZONES
+
+extern boolean_t zone_tagging_on;
+extern uint32_t zone_index_from_tag_index(uint32_t tag_zone_index, vm_size_t * elem_size);
+
+#endif /* VM_MAX_TAG_ZONES */
+
+/* These functions used for leak detection both in zalloc.c and mbuf.c */
+extern uintptr_t hash_mix(uintptr_t);
+extern uint32_t hashbacktrace(uintptr_t *, uint32_t, uint32_t);
+extern uint32_t hashaddr(uintptr_t, uint32_t);
+
+#define lock_zone(zone) \
+MACRO_BEGIN \
+ lck_mtx_lock_spin_always(&(zone)->lock); \
+MACRO_END
+
+#define unlock_zone(zone) \
+MACRO_BEGIN \
+ lck_mtx_unlock(&(zone)->lock); \
+MACRO_END
+
+#if CONFIG_GZALLOC
+void gzalloc_init(vm_size_t);
+void gzalloc_zone_init(zone_t);
+void gzalloc_configure(void);
+void gzalloc_reconfigure(zone_t);
+void gzalloc_empty_free_cache(zone_t);
+boolean_t gzalloc_enabled(void);
+
+vm_offset_t gzalloc_alloc(zone_t, boolean_t);
+boolean_t gzalloc_free(zone_t, void *);
+boolean_t gzalloc_element_size(void *, zone_t *, vm_size_t *);
+#endif /* CONFIG_GZALLOC */
+
+/* Callbacks for btlog lock/unlock */
+void zlog_btlog_lock(__unused void *);
+void zlog_btlog_unlock(__unused void *);
+
+#ifdef MACH_KERNEL_PRIVATE
+#define MAX_ZONE_NAME 32 /* max length of a zone name we can take from the boot-args */
+int track_this_zone(const char *zonename, const char *logname);
+#endif
+
+#if DEBUG || DEVELOPMENT
+extern boolean_t run_zone_test(void);
+extern vm_size_t zone_element_info(void *addr, vm_tag_t * ptag);
+#endif /* DEBUG || DEVELOPMENT */
+