#import <stdbool.h>
#import <malloc/malloc.h>
#import <mach/vm_statistics.h>
#import <sys/cdefs.h>
#import <os/availability.h>
#define STACK_LOGGING_MAX_STACK_SIZE 512
#define stack_logging_type_free 0
#define stack_logging_type_generic 1
#define stack_logging_type_alloc 2
#define stack_logging_type_dealloc 4
#define stack_logging_type_vm_allocate 16
#define stack_logging_type_vm_deallocate 32
#define stack_logging_type_mapped_file_or_shared_mem 128
#define stack_logging_valid_type_flags ( \
stack_logging_type_generic | \
stack_logging_type_alloc | \
stack_logging_type_dealloc | \
stack_logging_type_vm_allocate | \
stack_logging_type_vm_deallocate | \
stack_logging_type_mapped_file_or_shared_mem | \
VM_FLAGS_ALIAS_MASK);
#define stack_logging_flag_zone 8
#define stack_logging_flag_cleared 64
#define STACK_LOGGING_VM_USER_TAG(flags) (((flags) & VM_FLAGS_ALIAS_MASK) >> 24)
#define STACK_LOGGING_DISGUISE(address) ((address) ^ 0x00005555)
typedef enum {
stack_logging_mode_none = 0,
stack_logging_mode_all,
stack_logging_mode_malloc,
stack_logging_mode_vm,
stack_logging_mode_lite
} stack_logging_mode_type;
extern boolean_t turn_on_stack_logging(stack_logging_mode_type mode);
extern void turn_off_stack_logging();
#define MEMORYSTATUS_ENABLE_MSL_MALLOC 0x10000000
#define MEMORYSTATUS_ENABLE_MSL_VM 0x20000000
#define MEMORYSTATUS_ENABLE_MSL_LITE 0x40000000
#define MEMORYSTATUS_DISABLE_MSL 0x80000000
extern void __disk_stack_logging_log_stack(uint32_t type_flags, uintptr_t zone_ptr, uintptr_t size, uintptr_t ptr_arg, uintptr_t return_val, uint32_t num_hot_to_skip);
typedef struct mach_stack_logging_record {
uint32_t type_flags;
uint64_t stack_identifier;
uint64_t argument;
mach_vm_address_t address;
} mach_stack_logging_record_t;
extern kern_return_t __mach_stack_logging_start_reading(task_t task, vm_address_t shared_memory_address, boolean_t *uses_lite_mode);
extern kern_return_t __mach_stack_logging_stop_reading(task_t task);
extern kern_return_t __mach_stack_logging_set_file_path(task_t task, char* file_path);
extern kern_return_t __mach_stack_logging_get_frames(task_t task, mach_vm_address_t address, mach_vm_address_t *stack_frames_buffer, uint32_t max_stack_frames, uint32_t *count);
extern kern_return_t __mach_stack_logging_enumerate_records(task_t task, mach_vm_address_t address, void enumerator(mach_stack_logging_record_t, void *), void *context);
extern kern_return_t __mach_stack_logging_frames_for_uniqued_stack(task_t task, uint64_t stack_identifier, mach_vm_address_t *stack_frames_buffer, uint32_t max_stack_frames, uint32_t *count)
API_DEPRECATED("use __mach_stack_logging_get_frames_for_stackid instead", macos(10.9, 10.13), ios(7.0, 11.0), watchos(1.0, 4.0), tvos(9.0, 11.0));
extern kern_return_t __mach_stack_logging_get_frames_for_stackid(task_t task, uint64_t stack_identifier, mach_vm_address_t *stack_frames_buffer, uint32_t max_stack_frames, uint32_t *count,
bool *last_frame_is_threadid)
API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0));
extern uint64_t __mach_stack_logging_stackid_for_vm_region(task_t task, mach_vm_address_t address);
struct backtrace_uniquing_table;
extern kern_return_t
__mach_stack_logging_uniquing_table_read_stack(struct backtrace_uniquing_table *uniquing_table,
uint64_t stackid,
mach_vm_address_t *out_frames_buffer,
uint32_t *out_frames_count,
uint32_t max_frames);
extern
struct backtrace_uniquing_table *
__mach_stack_logging_copy_uniquing_table(task_t task);
extern
void
__mach_stack_logging_uniquing_table_release(struct backtrace_uniquing_table *);
extern
void
__mach_stack_logging_uniquing_table_retain(struct backtrace_uniquing_table *);
extern
size_t
__mach_stack_logging_uniquing_table_sizeof(struct backtrace_uniquing_table *);
extern
void *
__mach_stack_logging_uniquing_table_serialize(struct backtrace_uniquing_table *table, mach_vm_size_t *size);
extern
struct backtrace_uniquing_table *
__mach_stack_logging_uniquing_table_copy_from_serialized(void *buffer, size_t size);
extern void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *num);