]> git.saurik.com Git - apple/libc.git/blobdiff - gen/stack_logging.c
Libc-391.4.1.tar.gz
[apple/libc.git] / gen / stack_logging.c
index 3f9da9cf0c31f2854d1ad276a97ee01af55bf2e1..ff59ae47037899a42d49043a794fedf1443031b6 100644 (file)
@@ -3,8 +3,6 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
- * 
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
@@ -36,6 +34,7 @@
 
 extern void spin_lock(int *);
 
+static inline void *allocate_pages(unsigned) __attribute__((always_inline));
 static inline void *allocate_pages(unsigned bytes) {
     void *address;
     if (vm_allocate(mach_task_self(), (vm_address_t *)&address, bytes, 
@@ -46,19 +45,29 @@ static inline void *allocate_pages(unsigned bytes) {
     return (void *)address;
 }
 
+static inline void deallocate_pages(void *, unsigned) __attribute__((always_inline));
 static inline void deallocate_pages(void *ptr, unsigned bytes) {
     vm_deallocate(mach_task_self(), (vm_address_t)ptr, bytes);
 }
 
+static inline void copy_pages(const void *, void *, unsigned) __attribute__((always_inline));
 static inline void copy_pages(const void *source, void *dest, unsigned bytes) {
     if (vm_copy(mach_task_self(), (vm_address_t)source, bytes, (vm_address_t)dest)) memmove(dest, source, bytes);
 }
 
 /***************       Recording stack         ***********/
 
-static void *first_frame_address(void) {
+// The three functions below are marked as noinline to ensure consistent inlining across
+// all versions of GCC and all compiler flags.  The malloc stack logging code expects
+// these functions to not be inlined.
+// For details, see <rdar://problem/4199620>.
+//
+// The performance cost of not inlining these functions is negligible, and they're only
+// called when MallocStackLogging is set anyway, so they won't affect normal usage.
+
+static __attribute__((noinline)) void *first_frame_address(void) {
 #if defined(__i386__)
-    return __builtin_frame_address(1);
+    return __builtin_frame_address(0);
 #elif defined(__ppc__) || defined(__ppc64__)
     void *addr;
 #warning __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421
@@ -70,7 +79,7 @@ static void *first_frame_address(void) {
 #endif
 }
 
-static void *next_frame_address(void *addr) {
+static __attribute__((noinline)) void *next_frame_address(void *addr) {
     void *ret;
 #if defined(__MACH__) && defined(__i386__)
     __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr));
@@ -99,7 +108,7 @@ static void *next_frame_address(void *addr) {
 #error  ********** Unimplemented architecture
 #endif
 
-void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) {
+__attribute__((noinline)) void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) {
     void *addr;
     addr = first_frame_address();
     *nb = 0;