diff options
Diffstat (limited to 'src/common/mac')
-rw-r--r-- | src/common/mac/dump_syms.mm | 2 | ||||
-rw-r--r-- | src/common/mac/macho_id.cc | 15 | ||||
-rw-r--r-- | src/common/mac/macho_utilities.cc | 89 | ||||
-rw-r--r-- | src/common/mac/macho_utilities.h | 85 | ||||
-rw-r--r-- | src/common/mac/macho_walker.cc | 3 |
5 files changed, 187 insertions, 7 deletions
diff --git a/src/common/mac/dump_syms.mm b/src/common/mac/dump_syms.mm index b122b54b..427e15b3 100644 --- a/src/common/mac/dump_syms.mm +++ b/src/common/mac/dump_syms.mm @@ -38,11 +38,13 @@ #include <mach-o/loader.h> #include <mach-o/nlist.h> #include <mach-o/stab.h> +#include <fcntl.h> #import <Foundation/Foundation.h> #import "dump_syms.h" #import "common/mac/file_id.h" +#import "common/mac/macho_utilities.h" using google_breakpad::FileID; diff --git a/src/common/mac/macho_id.cc b/src/common/mac/macho_id.cc index e3f90e0c..c45329ed 100644 --- a/src/common/mac/macho_id.cc +++ b/src/common/mac/macho_id.cc @@ -47,6 +47,7 @@ #include "common/mac/macho_id.h" #include "common/mac/macho_walker.h" +#include "common/mac/macho_utilities.h" namespace MacFileUtilities { @@ -142,7 +143,7 @@ void MachoID::Update(MachoWalker *walker, unsigned long offset, size_t size) { } bool MachoID::UUIDCommand(int cpu_type, unsigned char bytes[16]) { - struct uuid_command uuid_cmd; + struct breakpad_uuid_command uuid_cmd; MachoWalker walker(path_, UUIDWalkerCB, &uuid_cmd); uuid_cmd.cmd = 0; @@ -284,7 +285,7 @@ bool MachoID::WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset, return false; if (swap) - swap_segment_command_64(&seg64, NXHostByteOrder()); + breakpad_swap_segment_command_64(&seg64, NXHostByteOrder()); struct mach_header_64 header; off_t header_offset; @@ -301,7 +302,7 @@ bool MachoID::WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset, return false; if (swap) - swap_section_64(&sec64, 1, NXHostByteOrder()); + breakpad_swap_section_64(&sec64, 1, NXHostByteOrder()); macho_id->Update(walker, header_offset + sec64.offset, sec64.size); offset += sizeof(struct section_64); @@ -316,13 +317,15 @@ bool MachoID::WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset, bool MachoID::UUIDWalkerCB(MachoWalker *walker, load_command *cmd, off_t offset, bool swap, void *context) { if (cmd->cmd == LC_UUID) { - struct uuid_command *uuid_cmd = (struct uuid_command *)context; + struct breakpad_uuid_command *uuid_cmd = + (struct breakpad_uuid_command *)context; - if (!walker->ReadBytes(uuid_cmd, sizeof(struct uuid_command), offset)) + if (!walker->ReadBytes(uuid_cmd, sizeof(struct breakpad_uuid_command), + offset)) return false; if (swap) - swap_uuid_command(uuid_cmd, NXHostByteOrder()); + breakpad_swap_uuid_command(uuid_cmd, NXHostByteOrder()); return false; } diff --git a/src/common/mac/macho_utilities.cc b/src/common/mac/macho_utilities.cc new file mode 100644 index 00000000..d25de5c8 --- /dev/null +++ b/src/common/mac/macho_utilities.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// macho_utilties.cc: Utilities for dealing with mach-o files +// +// Author: Dave Camp + +#include "common/mac/macho_utilities.h" + +void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc, + enum NXByteOrder target_byte_order) +{ + uc->cmd = NXSwapLong(uc->cmd); + uc->cmdsize = NXSwapLong(uc->cmdsize); +} + +void breakpad_swap_segment_command_64(struct segment_command_64 *sg, + enum NXByteOrder target_byte_order) +{ + sg->cmd = NXSwapLong(sg->cmd); + sg->cmdsize = NXSwapLong(sg->cmdsize); + + sg->vmaddr = NXSwapLongLong(sg->vmaddr); + sg->vmsize = NXSwapLongLong(sg->vmsize); + sg->fileoff = NXSwapLongLong(sg->fileoff); + sg->filesize = NXSwapLongLong(sg->filesize); + + sg->maxprot = NXSwapLong(sg->maxprot); + sg->initprot = NXSwapLong(sg->initprot); + sg->nsects = NXSwapLong(sg->nsects); + sg->flags = NXSwapLong(sg->flags); +} + +void breakpad_swap_mach_header_64(struct mach_header_64 *mh, + enum NXByteOrder target_byte_order) +{ + mh->magic = NXSwapLong(mh->magic); + mh->cputype = NXSwapLong(mh->cputype); + mh->cpusubtype = NXSwapLong(mh->cpusubtype); + mh->filetype = NXSwapLong(mh->filetype); + mh->ncmds = NXSwapLong(mh->ncmds); + mh->sizeofcmds = NXSwapLong(mh->sizeofcmds); + mh->flags = NXSwapLong(mh->flags); + mh->reserved = NXSwapLong(mh->reserved); +} + +void breakpad_swap_section_64(struct section_64 *s, + uint32_t nsects, + enum NXByteOrder target_byte_order) +{ + for (uint32_t i = 0; i < nsects; i++) { + s[i].addr = NXSwapLongLong(s[i].addr); + s[i].size = NXSwapLongLong(s[i].size); + + s[i].offset = NXSwapLong(s[i].offset); + s[i].align = NXSwapLong(s[i].align); + s[i].reloff = NXSwapLong(s[i].reloff); + s[i].nreloc = NXSwapLong(s[i].nreloc); + s[i].flags = NXSwapLong(s[i].flags); + s[i].reserved1 = NXSwapLong(s[i].reserved1); + s[i].reserved2 = NXSwapLong(s[i].reserved2); + } +} diff --git a/src/common/mac/macho_utilities.h b/src/common/mac/macho_utilities.h new file mode 100644 index 00000000..aa7d2fb6 --- /dev/null +++ b/src/common/mac/macho_utilities.h @@ -0,0 +1,85 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// macho_utilities.h: Utilities for dealing with mach-o files +// +// Author: Dave Camp + +#ifndef COMMON_MAC_MACHO_UTILITIES_H__ +#define COMMON_MAC_MACHO_UTILITIES_H__ + +#include <mach-o/loader.h> +#include <mach/thread_status.h> + +/* Some #defines and structs that aren't defined in older SDKs */ +#ifndef CPU_ARCH_ABI64 +# define CPU_ARCH_ABI64 0x01000000 +#endif + +#ifndef CPU_TYPE_X86 +# define CPU_TYPE_X86 CPU_TYPE_I386 +#endif + +#ifndef CPU_TYPE_POWERPC64 +# define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64) +#endif + +#ifndef LC_UUID +# define LC_UUID 0x1b /* the uuid */ +#endif + + +// The uuid_command struct/swap routines were added during the 10.4 series. +// Their presence isn't guaranteed. +struct breakpad_uuid_command { + uint32_t cmd; /* LC_UUID */ + uint32_t cmdsize; /* sizeof(struct uuid_command) */ + uint8_t uuid[16]; /* the 128-bit uuid */ +}; + +void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc, + enum NXByteOrder target_byte_order); + +// Older SDKs defines thread_state_data_t as an int[] instead +// of the natural_t[] it should be. +typedef natural_t breakpad_thread_state_data_t[THREAD_STATE_MAX]; + +// The 64-bit swap routines were added during the 10.4 series, their +// presence isn't guaranteed. +void breakpad_swap_segment_command_64(struct segment_command_64 *sg, + enum NXByteOrder target_byte_order); + +void breakpad_swap_mach_header_64(struct mach_header_64 *mh, + enum NXByteOrder target_byte_order); + +void breakpad_swap_section_64(struct section_64 *s, + uint32_t nsects, + enum NXByteOrder target_byte_order); + +#endif
\ No newline at end of file diff --git a/src/common/mac/macho_walker.cc b/src/common/mac/macho_walker.cc index cd66529d..9f56701b 100644 --- a/src/common/mac/macho_walker.cc +++ b/src/common/mac/macho_walker.cc @@ -42,6 +42,7 @@ #include <unistd.h> #include "common/mac/macho_walker.h" +#include "common/mac/macho_utilities.h" namespace MacFileUtilities { @@ -204,7 +205,7 @@ bool MachoWalker::WalkHeader64AtOffset(off_t offset) { bool swap = (header.magic == MH_CIGAM_64); if (swap) - swap_mach_header_64(&header, NXHostByteOrder()); + breakpad_swap_mach_header_64(&header, NXHostByteOrder()); current_header_ = &header; current_header_size_ = sizeof(header); |