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