aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorjimblandy <jimblandy@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-05-05 17:36:16 +0000
committerjimblandy <jimblandy@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-05-05 17:36:16 +0000
commit52a508dfe205d2c9c21171a33d630c4e314e1255 (patch)
treee91f903ee424428223ed537899827f11ff158d77 /src/common
parentBreakpad symbol dumper: Promise that Module::SetLoadAddress can be called at ... (diff)
downloadbreakpad-52a508dfe205d2c9c21171a33d630c4e314e1255.tar.xz
Breakpad Mac Dumper: Fix compilation warnings on OS X 10.6
Breakpad's Macintosh symbol dumper uses deprecated functions for dealing with mixed-endianness code. This patch provides an overloaded function, ByteSwap, that automatically chooses the OSSwap* functions from <libkern/OSByteOrder.h> appropriate for its argument's size. This patch does *not* address warnings in src/common/mac/dump_syms.mm, because that code is about to be replaced entirely; there's no reason to bother reviewing a big, detailed patch against it. a=jimblandy, r=mark git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@589 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common')
-rw-r--r--src/common/mac/byteswap.h48
-rw-r--r--src/common/mac/macho_utilities.cc59
-rw-r--r--src/common/mac/macho_walker.cc3
3 files changed, 80 insertions, 30 deletions
diff --git a/src/common/mac/byteswap.h b/src/common/mac/byteswap.h
new file mode 100644
index 00000000..a5d745b3
--- /dev/null
+++ b/src/common/mac/byteswap.h
@@ -0,0 +1,48 @@
+// -*- mode: c++ -*-
+
+// Copyright (c) 2010, 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.
+
+// Original author: Jim Blandy <jim@mozilla.com> <jimb@red-bean.com>
+
+// byteswap.h: Overloaded functions for conveniently byteswapping values.
+
+#ifndef COMMON_MAC_BYTESWAP_H_
+#define COMMON_MAC_BYTESWAP_H_
+
+#include <libkern/OSByteOrder.h>
+
+static inline uint16_t ByteSwap(uint16_t v) { return OSSwapInt16(v); }
+static inline uint32_t ByteSwap(uint32_t v) { return OSSwapInt32(v); }
+static inline uint64_t ByteSwap(uint64_t v) { return OSSwapInt64(v); }
+static inline int16_t ByteSwap(int16_t v) { return OSSwapInt16(v); }
+static inline int32_t ByteSwap(int32_t v) { return OSSwapInt32(v); }
+static inline int64_t ByteSwap(int64_t v) { return OSSwapInt64(v); }
+
+#endif // COMMON_MAC_BYTESWAP_H_
diff --git a/src/common/mac/macho_utilities.cc b/src/common/mac/macho_utilities.cc
index d25de5c8..89f9e775 100644
--- a/src/common/mac/macho_utilities.cc
+++ b/src/common/mac/macho_utilities.cc
@@ -31,43 +31,44 @@
//
// Author: Dave Camp
+#include "common/mac/byteswap.h"
#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);
+ uc->cmd = ByteSwap(uc->cmd);
+ uc->cmdsize = ByteSwap(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->cmd = ByteSwap(sg->cmd);
+ sg->cmdsize = ByteSwap(sg->cmdsize);
- sg->vmaddr = NXSwapLongLong(sg->vmaddr);
- sg->vmsize = NXSwapLongLong(sg->vmsize);
- sg->fileoff = NXSwapLongLong(sg->fileoff);
- sg->filesize = NXSwapLongLong(sg->filesize);
+ sg->vmaddr = ByteSwap(sg->vmaddr);
+ sg->vmsize = ByteSwap(sg->vmsize);
+ sg->fileoff = ByteSwap(sg->fileoff);
+ sg->filesize = ByteSwap(sg->filesize);
- sg->maxprot = NXSwapLong(sg->maxprot);
- sg->initprot = NXSwapLong(sg->initprot);
- sg->nsects = NXSwapLong(sg->nsects);
- sg->flags = NXSwapLong(sg->flags);
+ sg->maxprot = ByteSwap(sg->maxprot);
+ sg->initprot = ByteSwap(sg->initprot);
+ sg->nsects = ByteSwap(sg->nsects);
+ sg->flags = ByteSwap(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);
+ mh->magic = ByteSwap(mh->magic);
+ mh->cputype = ByteSwap(mh->cputype);
+ mh->cpusubtype = ByteSwap(mh->cpusubtype);
+ mh->filetype = ByteSwap(mh->filetype);
+ mh->ncmds = ByteSwap(mh->ncmds);
+ mh->sizeofcmds = ByteSwap(mh->sizeofcmds);
+ mh->flags = ByteSwap(mh->flags);
+ mh->reserved = ByteSwap(mh->reserved);
}
void breakpad_swap_section_64(struct section_64 *s,
@@ -75,15 +76,15 @@ void breakpad_swap_section_64(struct section_64 *s,
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].addr = ByteSwap(s[i].addr);
+ s[i].size = ByteSwap(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);
+ s[i].offset = ByteSwap(s[i].offset);
+ s[i].align = ByteSwap(s[i].align);
+ s[i].reloff = ByteSwap(s[i].reloff);
+ s[i].nreloc = ByteSwap(s[i].nreloc);
+ s[i].flags = ByteSwap(s[i].flags);
+ s[i].reserved1 = ByteSwap(s[i].reserved1);
+ s[i].reserved2 = ByteSwap(s[i].reserved2);
}
}
diff --git a/src/common/mac/macho_walker.cc b/src/common/mac/macho_walker.cc
index 4bc2ebba..4e1d9f16 100644
--- a/src/common/mac/macho_walker.cc
+++ b/src/common/mac/macho_walker.cc
@@ -43,6 +43,7 @@ extern "C" { // necessary for Leopard
#include <unistd.h>
}
+#include "common/mac/byteswap.h"
#include "common/mac/macho_walker.h"
#include "common/mac/macho_utilities.h"
@@ -136,7 +137,7 @@ bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
return false;
if (magic == MH_CIGAM || magic == MH_CIGAM_64)
- header_cpu_type = NXSwapInt(header_cpu_type);
+ header_cpu_type = ByteSwap(header_cpu_type);
if (valid_cpu_type != header_cpu_type)
return false;