Loading...
gen/stack_logging.c Libc-262 Libc-391.2.7
--- Libc/Libc-262/gen/stack_logging.c
+++ Libc/Libc-391.2.7/gen/stack_logging.c
@@ -3,19 +3,20 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * 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
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -28,22 +29,28 @@
 #import <pthread.h>
 #import <mach/mach.h>
 #include <mach/vm_statistics.h>
+#import <malloc/malloc.h>
+#import <stdlib.h>
 
 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, 
                     VM_MAKE_TAG(VM_MEMORY_ANALYSIS_TOOL)| TRUE)) {
-	address = 0;
+	malloc_printf("*** out of memory while stack logging\n");
+	abort();
     } 
     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);
 }
@@ -51,9 +58,9 @@
 /***************	Recording stack		***********/
 
 static void *first_frame_address(void) {
-#if 0
+#if defined(__i386__)
     return __builtin_frame_address(1);
-#elif defined(__ppc__)
+#elif defined(__ppc__) || defined(__ppc64__)
     void *addr;
 #warning __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421
     __asm__ volatile("mr %0, r1" : "=r" (addr));
@@ -68,7 +75,7 @@
     void *ret;
 #if defined(__MACH__) && defined(__i386__)
     __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr));
-#elif defined(__MACH__) && defined(__ppc__)
+#elif defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__))
     __asm__ volatile("lwz %0,0x0(%1)" : "=r" (ret) : "b" (addr));
 #elif defined(__hpux__)
     __asm__ volatile("ldw 0x0(%1),%0" : "=r" (ret) : "r" (addr));
@@ -83,7 +90,7 @@
 
 #if defined(__i386__) || defined (__m68k__)
 #define FP_LINK_OFFSET 1
-#elif defined(__ppc__)
+#elif defined(__ppc__) || defined(__ppc64__)
 #define FP_LINK_OFFSET 2
 #elif defined(__hppa__)
 #define FP_LINK_OFFSET -5
@@ -103,7 +110,7 @@
         buffer[*nb] = *((vm_address_t *)fp_link);
         (*nb)++;
         addr2 = next_frame_address(addr);
-#if defined(__ppc__)
+#if defined(__ppc__) || defined(__ppc64__)
         if ((unsigned)addr2 <= (unsigned)addr) break; // catch bozo frames
 #endif
         addr = addr2;