• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
67 void breakpad_swap_load_command(struct load_command *lc);
68 
69 void breakpad_swap_dylib_command(struct dylib_command *dc);
70 
71 // Older SDKs defines thread_state_data_t as an int[] instead
72 // of the natural_t[] it should be.
73 typedef natural_t breakpad_thread_state_data_t[THREAD_STATE_MAX];
74 
75 void breakpad_swap_segment_command(struct segment_command *sc);
76 
77 // The 64-bit swap routines were added during the 10.4 series, their
78 // presence isn't guaranteed.
79 void breakpad_swap_segment_command_64(struct segment_command_64 *sg);
80 
81 void breakpad_swap_fat_header(struct fat_header *fh);
82 
83 void breakpad_swap_fat_arch(struct fat_arch *fa, uint32_t narchs);
84 
85 void breakpad_swap_mach_header(struct mach_header *mh);
86 
87 void breakpad_swap_mach_header_64(struct mach_header_64 *mh);
88 
89 void breakpad_swap_section(struct section *s,
90                            uint32_t nsects);
91 
92 void breakpad_swap_section_64(struct section_64 *s,
93                               uint32_t nsects);
94 
95 #endif
96