]> git.saurik.com Git - apple/libc.git/blame - gen/stack_logging.h
Libc-262.tar.gz
[apple/libc.git] / gen / stack_logging.h
CommitLineData
e9ce8d39
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#import <malloc.h>
24
25#define stack_logging_type_free 0
26#define stack_logging_type_generic 1 /* anything that is not allocation/deallocation */
27#define stack_logging_type_alloc 2 /* malloc, realloc, etc... */
28#define stack_logging_type_dealloc 4 /* free, realloc, etc... */
29
30// Following flags are absorbed by stack_logging_log_stack()
31#define stack_logging_flag_zone 8 /* NSZoneMalloc, etc... */
32#define stack_logging_flag_calloc 16 /* multiply arguments to get the size */
33#define stack_logging_flag_object 32 /* NSAllocateObject(Class, extraBytes, zone) */
34#define stack_logging_flag_cleared 64 /* for NewEmptyHandle */
35#define stack_logging_flag_handle 128 /* for Handle (de-)allocation routines */
36#define stack_logging_flag_set_handle_size 256 /* (Handle, newSize) treated specially */
37
38/* Macro used to disguise addresses so that leak finding can work */
39#define STACK_LOGGING_DISGUISE(address) (((unsigned)address) ^ 0x00005555) /* nicely idempotent */
40
41typedef struct {
42 unsigned type;
43 unsigned uniqued_stack;
44 unsigned argument;
45 unsigned address; /* disguised, to avoid confusing leaks */
46} stack_logging_record_t;
47
48typedef struct {
49 unsigned overall_num_bytes;
50 unsigned num_records;
51 unsigned lock; /* 0 means OK to lock; used for inter-process locking */
52 unsigned *uniquing_table; /* allocated using vm_allocate() */
53 /* hashtable organized as (PC, uniqued parent)
54 Only the second half of the table is active
55 To enable us to grow dynamically */
56 unsigned uniquing_table_num_pages; /* number of pages of the table */
57 unsigned extra_retain_count; /* not used by stack_logging_log_stack */
58 unsigned filler[2]; /* align to cache lines for better performance */
59 stack_logging_record_t records[0]; /* records follow here */
60} stack_logging_record_list_t;
61
62extern unsigned stack_logging_get_unique_stack(unsigned **table, unsigned *table_num_pages, unsigned *stack_entries, unsigned count, unsigned num_hot_to_skip);
63 /* stack_entries are from hot to cold */
64
65extern stack_logging_record_list_t *stack_logging_the_record_list;
66 /* This is the global variable containing all logs */
67
68extern int stack_logging_enable_logging;
69 /* when clear, no logging takes place */
70
71extern int stack_logging_dontcompact;
72 /* default is to compact; when set does not compact alloc/free logs; useful for tracing history */
73
74extern void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsigned arg3, unsigned result, unsigned num_hot_to_skip);
75
76extern kern_return_t stack_logging_get_frames(task_t task, memory_reader_t reader, vm_address_t address, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames);
77 /* Gets the last record in stack_logging_the_record_list about address */
78
79#define STACK_LOGGING_ENUMERATION_PROVIDED 1 // temporary to avoid dependencies between projects
80
81extern kern_return_t stack_logging_enumerate_records(task_t task, memory_reader_t reader, vm_address_t address, void enumerator(stack_logging_record_t, void *), void *context);
82 /* Gets all the records about address;
83 If !address, gets all records */
84
85extern kern_return_t stack_logging_frames_for_uniqued_stack(task_t task, memory_reader_t reader, unsigned uniqued_stack, vm_address_t *stack_frames_buffer, unsigned max_stack_frames, unsigned *num_frames);
86 /* Given a uniqued_stack fills stack_frames_buffer */
87
88extern void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *num);
89 /* Convenience to fill buffer with the PCs of the frames, starting with the hot frames;
90 num: returned number of frames
91 */
92