X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/224c70764cab4e0e39a26aaf3ad3016552f62f55..065eae9f38780a3602538caa52399f41f061a88e:/gen/stack_logging.c?ds=inline diff --git a/gen/stack_logging.c b/gen/stack_logging.c index 6c66890..6fcc0b5 100644 --- a/gen/stack_logging.c +++ b/gen/stack_logging.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2000, 2002-2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -32,6 +32,7 @@ #include #import #import +#import extern void spin_lock(int *); extern void spin_unlock(int *); @@ -43,6 +44,7 @@ static inline void *allocate_pages(unsigned bytes) { if (vm_allocate(mach_task_self(), (vm_address_t *)&address, bytes, VM_MAKE_TAG(VM_MEMORY_ANALYSIS_TOOL)| TRUE)) { malloc_printf("*** out of memory while stack logging\n"); + CRSetCrashLogMessage("*** out of memory while stack logging\n"); abort(); } return (void *)address; @@ -116,8 +118,9 @@ unsigned stack_logging_get_unique_stack(unsigned **table, unsigned *table_num_pa stack_logging_record_list_t *stack_logging_the_record_list = NULL; int stack_logging_enable_logging = 0; - int stack_logging_dontcompact = 0; +int stack_logging_finished_init = 0; +int stack_logging_postponed = 0; static int stack_logging_spin_lock = 0; @@ -156,7 +159,7 @@ void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsign arg1 *= arg2; arg2 = arg3; arg3 = 0; type &= ~stack_logging_flag_calloc; } if (type & stack_logging_flag_object) { - unsigned *class = (unsigned *)arg1; + unsigned *class = (unsigned *)(uintptr_t)arg1; arg1 = arg2 + class[5]; // corresponds to the instance_size field arg2 = 0; arg3 = 0; type = stack_logging_type_alloc; } @@ -167,12 +170,12 @@ void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsign if (stack_logging_type_alloc) { if (!result) return; stack_logging_log_stack(stack_logging_type_alloc, 0, 0, 0, result, num_hot_to_skip+1); - stack_logging_log_stack(stack_logging_type_alloc, arg1, 0, 0, *((int *)result), num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_alloc, arg1, 0, 0, *((int *)(uintptr_t)result), num_hot_to_skip+1); return; } if (stack_logging_type_dealloc) { if (!arg1) return; - stack_logging_log_stack(stack_logging_type_dealloc, *((int *)arg1), 0, 0, 0, num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_dealloc, *((int *)(uintptr_t)arg1), 0, 0, 0, num_hot_to_skip+1); stack_logging_log_stack(stack_logging_type_dealloc, arg1, 0, 0, 0, num_hot_to_skip+1); return; } @@ -181,9 +184,9 @@ void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsign if (type == stack_logging_flag_set_handle_size) { if (!arg1) return; // Thanks to a horrible hack, arg3 contains the prvious handle value - if (arg3 == *((int *)arg1)) return; + if (arg3 == *((int *)(uintptr_t)arg1)) return; stack_logging_log_stack(stack_logging_type_dealloc, arg3, 0, 0, 0, num_hot_to_skip+1); - stack_logging_log_stack(stack_logging_type_alloc, arg2, 0, 0, *((int *)arg1), num_hot_to_skip+1); + stack_logging_log_stack(stack_logging_type_alloc, arg2, 0, 0, *((int *)(uintptr_t)arg1), num_hot_to_skip+1); return; } if (type == (stack_logging_type_dealloc|stack_logging_type_alloc)) { @@ -225,9 +228,9 @@ void stack_logging_log_stack(unsigned type, unsigned arg1, unsigned arg2, unsign rec->address = STACK_LOGGING_DISGUISE(arg1); // we disguise the address } // printf("Before getting samples 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); - thread_stack_pcs(stack_entries, MAX_NUM_PC - 1, &count); + thread_stack_pcs((vm_address_t *)stack_entries, MAX_NUM_PC - 1, &count); // We put at the bottom of the stack a marker that denotes the thread (+1 for good measure...) - stack_entries[count++] = (int)pthread_self() + 1; + stack_entries[count++] = (int)(uintptr_t)pthread_self() + 1; /* now let's unique the sample */ // printf("Uniquing 0x%x 0x%x 0x%x 0x%x -> 0x%x\n", type, arg1, arg2, arg3, result); rec->uniqued_stack = stack_logging_get_unique_stack(&stack_logging_the_record_list->uniquing_table, &stack_logging_the_record_list->uniquing_table_num_pages, stack_entries, count, num_hot_to_skip+2); // we additionally skip the warmest 2 entries that are an artefact of the code @@ -278,7 +281,7 @@ kern_return_t stack_logging_get_frames(task_t task, memory_reader_t reader, vm_a } index++; } - fprintf(stderr, "*** stack_logging: no record found for 0x%x\n", address); + fprintf(stderr, "*** stack_logging: no record found for %p\n", address); return 0; }