summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/Breakpad/src/common/mac/macho_walker.cc')
-rw-r--r--3rdParty/Breakpad/src/common/mac/macho_walker.cc69
1 files changed, 35 insertions, 34 deletions
diff --git a/3rdParty/Breakpad/src/common/mac/macho_walker.cc b/3rdParty/Breakpad/src/common/mac/macho_walker.cc
index 92da7b1..1acd866 100644
--- a/3rdParty/Breakpad/src/common/mac/macho_walker.cc
+++ b/3rdParty/Breakpad/src/common/mac/macho_walker.cc
@@ -35,11 +35,9 @@
-extern "C" { // necessary for Leopard
- #include <assert.h>
- #include <fcntl.h>
- #include <mach-o/arch.h>
- #include <mach-o/loader.h>
- #include <mach-o/swap.h>
- #include <string.h>
- #include <unistd.h>
-}
+#include <assert.h>
+#include <fcntl.h>
+#include <mach-o/arch.h>
+#include <mach-o/fat.h>
+#include <mach-o/loader.h>
+#include <string.h>
+#include <unistd.h>
@@ -53,3 +51,3 @@ MachoWalker::MachoWalker(const char *path, LoadCommandCallback callback,
void *context)
- : file_(0),
+ : file_(-1),
memory_(NULL),
@@ -66,3 +64,3 @@ MachoWalker::MachoWalker(void *memory, size_t size,
LoadCommandCallback callback, void *context)
- : file_(0),
+ : file_(-1),
memory_(memory),
@@ -81,4 +79,6 @@ MachoWalker::~MachoWalker() {
-int MachoWalker::ValidateCPUType(int cpu_type) {
- // If the user didn't specify, use the local architecture.
+bool MachoWalker::WalkHeader(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype) {
+ cpu_type_t valid_cpu_type = cpu_type;
+ cpu_subtype_t valid_cpu_subtype = cpu_subtype;
+ // if |cpu_type| is 0, use the native cpu type.
if (cpu_type == 0) {
@@ -86,12 +86,7 @@ int MachoWalker::ValidateCPUType(int cpu_type) {
assert(arch);
- cpu_type = arch->cputype;
+ valid_cpu_type = arch->cputype;
+ valid_cpu_subtype = CPU_SUBTYPE_MULTIPLE;
}
-
- return cpu_type;
-}
-
-bool MachoWalker::WalkHeader(int cpu_type) {
- int valid_cpu_type = ValidateCPUType(cpu_type);
off_t offset;
- if (FindHeader(valid_cpu_type, offset)) {
+ if (FindHeader(valid_cpu_type, valid_cpu_subtype, offset)) {
if (cpu_type & CPU_ARCH_ABI64)
@@ -113,3 +108,3 @@ bool MachoWalker::ReadBytes(void *buffer, size_t size, off_t offset) {
return false;
- size = memory_size_ - offset;
+ size = memory_size_ - static_cast<size_t>(offset);
result = false;
@@ -133,4 +128,5 @@ bool MachoWalker::CurrentHeader(struct mach_header_64 *header, off_t *offset) {
-bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
- int valid_cpu_type = ValidateCPUType(cpu_type);
+bool MachoWalker::FindHeader(cpu_type_t cpu_type,
+ cpu_subtype_t cpu_subtype,
+ off_t &offset) {
// Read the magic bytes that's common amongst all mach-o files
@@ -155,4 +151,4 @@ bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
// header
- cpu_type_t header_cpu_type;
- if (!ReadBytes(&header_cpu_type, sizeof(header_cpu_type), offset))
+ struct mach_header header;
+ if (!ReadBytes(&header, sizeof(header), 0))
return false;
@@ -160,6 +156,9 @@ bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
if (magic == MH_CIGAM || magic == MH_CIGAM_64)
- header_cpu_type = ByteSwap(header_cpu_type);
+ breakpad_swap_mach_header(&header);
- if (valid_cpu_type != header_cpu_type)
+ if (cpu_type != header.cputype ||
+ (cpu_subtype != CPU_SUBTYPE_MULTIPLE &&
+ cpu_subtype != header.cpusubtype)) {
return false;
+ }
@@ -175,3 +174,3 @@ bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
if (NXHostByteOrder() != NX_BigEndian)
- swap_fat_header(&fat, NXHostByteOrder());
+ breakpad_swap_fat_header(&fat);
@@ -186,5 +185,7 @@ bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
if (NXHostByteOrder() != NX_BigEndian)
- swap_fat_arch(&arch, 1, NXHostByteOrder());
+ breakpad_swap_fat_arch(&arch, 1);
- if (arch.cputype == valid_cpu_type) {
+ if (arch.cputype == cpu_type &&
+ (cpu_subtype == CPU_SUBTYPE_MULTIPLE ||
+ arch.cpusubtype == cpu_subtype)) {
offset = arch.offset;
@@ -207,3 +208,3 @@ bool MachoWalker::WalkHeaderAtOffset(off_t offset) {
if (swap)
- swap_mach_header(&header, NXHostByteOrder());
+ breakpad_swap_mach_header(&header);
@@ -233,3 +234,3 @@ bool MachoWalker::WalkHeader64AtOffset(off_t offset) {
if (swap)
- breakpad_swap_mach_header_64(&header, NXHostByteOrder());
+ breakpad_swap_mach_header_64(&header);
@@ -254,3 +255,3 @@ bool MachoWalker::WalkHeaderCore(off_t offset, uint32_t number_of_commands,
if (swap)
- swap_load_command(&cmd, NXHostByteOrder());
+ breakpad_swap_load_command(&cmd);