Home | History | Annotate | Download | only in mac
      1 // Copyright (c) 2006, Google Inc.
      2 // All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 //     * Redistributions of source code must retain the above copyright
      9 // notice, this list of conditions and the following disclaimer.
     10 //     * Redistributions in binary form must reproduce the above
     11 // copyright notice, this list of conditions and the following disclaimer
     12 // in the documentation and/or other materials provided with the
     13 // distribution.
     14 //     * Neither the name of Google Inc. nor the names of its
     15 // contributors may be used to endorse or promote products derived from
     16 // this software without specific prior written permission.
     17 //
     18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 // macho_utilities.h: Utilities for dealing with mach-o files
     31 //
     32 // Author: Dave Camp
     33 
     34 #ifndef COMMON_MAC_MACHO_UTILITIES_H__
     35 #define COMMON_MAC_MACHO_UTILITIES_H__
     36 
     37 #include <mach-o/loader.h>
     38 #include <mach/thread_status.h>
     39 
     40 /* Some #defines and structs that aren't defined in older SDKs */
     41 #ifndef CPU_ARCH_ABI64
     42 # define CPU_ARCH_ABI64    0x01000000
     43 #endif
     44 
     45 #ifndef CPU_TYPE_X86
     46 # define CPU_TYPE_X86 CPU_TYPE_I386
     47 #endif
     48 
     49 #ifndef CPU_TYPE_POWERPC64
     50 # define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
     51 #endif
     52 
     53 #ifndef LC_UUID
     54 # define LC_UUID         0x1b    /* the uuid */
     55 #endif
     56 
     57 // The uuid_command struct/swap routines were added during the 10.4 series.
     58 // Their presence isn't guaranteed.
     59 struct breakpad_uuid_command {
     60   uint32_t    cmd;            /* LC_UUID */
     61   uint32_t    cmdsize;        /* sizeof(struct uuid_command) */
     62   uint8_t     uuid[16];       /* the 128-bit uuid */
     63 };
     64 
     65 void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc,
     66                                 enum NXByteOrder target_byte_order);
     67 
     68 // Older SDKs defines thread_state_data_t as an int[] instead
     69 // of the natural_t[] it should be.
     70 typedef natural_t breakpad_thread_state_data_t[THREAD_STATE_MAX];
     71 
     72 // The 64-bit swap routines were added during the 10.4 series, their
     73 // presence isn't guaranteed.
     74 void breakpad_swap_segment_command_64(struct segment_command_64 *sg,
     75                                       enum NXByteOrder target_byte_order);
     76 
     77 void breakpad_swap_mach_header_64(struct mach_header_64 *mh,
     78                                   enum NXByteOrder target_byte_order);
     79 
     80 void breakpad_swap_section_64(struct section_64 *s,
     81                               uint32_t nsects,
     82                               enum NXByteOrder target_byte_order);
     83 
     84 #endif
     85