Planeshift

macho_utilities.h

Go to the documentation of this file.
00001 // Copyright (c) 2006, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 // macho_utilities.h: Utilities for dealing with mach-o files
00031 //
00032 // Author: Dave Camp
00033 
00034 #ifndef COMMON_MAC_MACHO_UTILITIES_H__
00035 #define COMMON_MAC_MACHO_UTILITIES_H__
00036 
00037 #include <mach-o/loader.h>
00038 #include <mach/thread_status.h>
00039 
00040 /* Some #defines and structs that aren't defined in older SDKs */
00041 #ifndef CPU_ARCH_ABI64
00042 # define CPU_ARCH_ABI64    0x01000000
00043 #endif
00044 
00045 #ifndef CPU_TYPE_X86
00046 # define CPU_TYPE_X86 CPU_TYPE_I386
00047 #endif
00048 
00049 #ifndef CPU_TYPE_POWERPC64
00050 # define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
00051 #endif
00052 
00053 #ifndef LC_UUID
00054 # define LC_UUID         0x1b    /* the uuid */
00055 #endif
00056 
00057 // The uuid_command struct/swap routines were added during the 10.4 series.
00058 // Their presence isn't guaranteed.
00059 struct breakpad_uuid_command {
00060   uint32_t    cmd;            /* LC_UUID */
00061   uint32_t    cmdsize;        /* sizeof(struct uuid_command) */
00062   uint8_t     uuid[16];       /* the 128-bit uuid */
00063 };
00064 
00065 void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc,
00066                                 enum NXByteOrder target_byte_order);
00067 
00068 // Older SDKs defines thread_state_data_t as an int[] instead
00069 // of the natural_t[] it should be.
00070 typedef natural_t breakpad_thread_state_data_t[THREAD_STATE_MAX];
00071 
00072 // The 64-bit swap routines were added during the 10.4 series, their
00073 // presence isn't guaranteed.
00074 void breakpad_swap_segment_command_64(struct segment_command_64 *sg,
00075                                       enum NXByteOrder target_byte_order);
00076 
00077 void breakpad_swap_mach_header_64(struct mach_header_64 *mh,
00078                                   enum NXByteOrder target_byte_order);
00079 
00080 void breakpad_swap_section_64(struct section_64 *s,
00081                               uint32_t nsects,
00082                               enum NXByteOrder target_byte_order);
00083 
00084 #endif