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