mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-30 17:20:26 +02:00
* Updated breakpad to latest version.
This commit is contained in:
@@ -29,8 +29,6 @@
|
||||
|
||||
ARCHS = $(ARCHS_STANDARD_32_64_BIT)
|
||||
SDKROOT = macosx10.5
|
||||
SDKROOT[arch=i386] = macosx10.4
|
||||
SDKROOT[arch=ppc] = macosx10.4
|
||||
|
||||
GCC_VERSION = 4.2
|
||||
GCC_VERSION[sdk=macosx10.4][arch=*] = 4.0
|
||||
|
@@ -32,7 +32,7 @@
|
||||
// Each file is sent with a name field in addition to the filename and data
|
||||
// The data will be sent synchronously.
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface HTTPMultipartUpload : NSObject {
|
||||
@protected
|
||||
|
@@ -32,6 +32,8 @@
|
||||
|
||||
@interface HTTPMultipartUpload(PrivateMethods)
|
||||
- (NSString *)multipartBoundary;
|
||||
// Each of the following methods will append the starting multipart boundary,
|
||||
// but not the ending one.
|
||||
- (NSData *)formDataForKey:(NSString *)key value:(NSString *)value;
|
||||
- (NSData *)formDataForFileContents:(NSData *)contents name:(NSString *)name;
|
||||
- (NSData *)formDataForFile:(NSString *)file name:(NSString *)name;
|
||||
@@ -67,11 +69,9 @@
|
||||
NSString *fmt = @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; "
|
||||
"filename=\"minidump.dmp\"\r\nContent-Type: application/octet-stream\r\n\r\n";
|
||||
NSString *pre = [NSString stringWithFormat:fmt, boundary_, escaped];
|
||||
NSString *post = [NSString stringWithFormat:@"\r\n--%@--\r\n", boundary_];
|
||||
|
||||
[data appendData:[pre dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
[data appendData:contents];
|
||||
[data appendData:[post dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -182,6 +182,9 @@
|
||||
[postBody appendData:fileData];
|
||||
}
|
||||
|
||||
NSString *epilogue = [NSString stringWithFormat:@"\r\n--%@--\r\n", boundary_];
|
||||
[postBody appendData:[epilogue dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
|
||||
[req setHTTPBody:postBody];
|
||||
[req setHTTPMethod:@"POST"];
|
||||
|
||||
@@ -193,7 +196,8 @@
|
||||
error:error];
|
||||
|
||||
[response_ retain];
|
||||
|
||||
[req release];
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
8
thirdparty/breakpad/common/mac/MachIPC.mm
vendored
8
thirdparty/breakpad/common/mac/MachIPC.mm
vendored
@@ -32,6 +32,7 @@
|
||||
|
||||
#import <stdio.h>
|
||||
#import "MachIPC.h"
|
||||
#include "common/mac/bootstrap_compat.h"
|
||||
|
||||
namespace google_breakpad {
|
||||
//==============================================================================
|
||||
@@ -187,9 +188,10 @@ ReceivePort::ReceivePort(const char *receive_port_name) {
|
||||
if (init_result_ != KERN_SUCCESS)
|
||||
return;
|
||||
|
||||
init_result_ = bootstrap_register(bootstrap_port,
|
||||
const_cast<char*>(receive_port_name),
|
||||
port_);
|
||||
init_result_ = breakpad::BootstrapRegister(
|
||||
bootstrap_port,
|
||||
const_cast<char*>(receive_port_name),
|
||||
port_);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
@@ -134,7 +134,7 @@ class SimpleStringDictionary {
|
||||
// Given |key|, returns its corresponding |value|.
|
||||
// If |key| is NULL, an assert will fire or NULL will be returned. If |key|
|
||||
// is not found or is an empty string, NULL is returned.
|
||||
const char *GetValueForKey(const char *key);
|
||||
const char *GetValueForKey(const char *key) const;
|
||||
|
||||
// Stores a string |value| represented by |key|. If |key| is NULL or an empty
|
||||
// string, this will assert (or do nothing). If |value| is NULL then
|
||||
|
@@ -55,13 +55,13 @@ int SimpleStringDictionary::GetCount() const {
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
const char *SimpleStringDictionary::GetValueForKey(const char *key) {
|
||||
const char *SimpleStringDictionary::GetValueForKey(const char *key) const {
|
||||
assert(key);
|
||||
if (!key)
|
||||
return NULL;
|
||||
|
||||
for (int i = 0; i < MAX_NUM_ENTRIES; ++i) {
|
||||
KeyValueEntry &entry = entries_[i];
|
||||
const KeyValueEntry &entry = entries_[i];
|
||||
if (entry.IsActive() && !strcmp(entry.GetKey(), key)) {
|
||||
return entry.GetValue();
|
||||
}
|
||||
|
42
thirdparty/breakpad/common/mac/bootstrap_compat.cc
vendored
Normal file
42
thirdparty/breakpad/common/mac/bootstrap_compat.cc
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2012, 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.
|
||||
|
||||
#include "common/mac/bootstrap_compat.h"
|
||||
|
||||
namespace breakpad {
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
kern_return_t BootstrapRegister(mach_port_t bp,
|
||||
name_t service_name,
|
||||
mach_port_t sp) {
|
||||
return bootstrap_register(bp, service_name, sp);
|
||||
}
|
||||
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
||||
|
||||
} // namesapce breakpad
|
54
thirdparty/breakpad/common/mac/bootstrap_compat.h
vendored
Normal file
54
thirdparty/breakpad/common/mac/bootstrap_compat.h
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2012, 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.
|
||||
|
||||
#ifndef COMMON_MAC_BOOTSTRAP_COMPAT_H_
|
||||
#define COMMON_MAC_BOOTSTRAP_COMPAT_H_
|
||||
|
||||
#include <servers/bootstrap.h>
|
||||
|
||||
namespace breakpad {
|
||||
|
||||
// Wrapper for bootstrap_register to avoid deprecation warnings.
|
||||
//
|
||||
// In 10.6, it's possible to call bootstrap_check_in as the one-stop-shop for
|
||||
// handling what bootstrap_register is used for. In 10.5, bootstrap_check_in
|
||||
// can't check in a service whose name has not yet been registered, despite
|
||||
// bootstrap_register being marked as deprecated in that OS release. Breakpad
|
||||
// needs to register new service names, and in 10.5, calling
|
||||
// bootstrap_register is the only way to achieve that. Attempts to call
|
||||
// bootstrap_check_in for a new service name on 10.5 will result in
|
||||
// BOOTSTRAP_UNKNOWN_SERVICE being returned rather than registration of the
|
||||
// new service name.
|
||||
kern_return_t BootstrapRegister(mach_port_t bp,
|
||||
name_t service_name,
|
||||
mach_port_t sp);
|
||||
|
||||
} // namespace breakpad
|
||||
|
||||
#endif // COMMON_MAC_BOOTSTRAP_COMPAT_H_
|
24
thirdparty/breakpad/common/mac/dump_syms.h
vendored
24
thirdparty/breakpad/common/mac/dump_syms.h
vendored
@@ -1,6 +1,6 @@
|
||||
// -*- mode: c++ -*-
|
||||
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -52,9 +52,9 @@ namespace google_breakpad {
|
||||
|
||||
class DumpSymbols {
|
||||
public:
|
||||
DumpSymbols()
|
||||
DumpSymbols()
|
||||
: input_pathname_(),
|
||||
object_filename_(),
|
||||
object_filename_(),
|
||||
contents_(),
|
||||
selected_object_file_(),
|
||||
selected_object_name_() { }
|
||||
@@ -84,9 +84,9 @@ class DumpSymbols {
|
||||
// object file, then the dumper will dump the object file whose
|
||||
// architecture matches that of this dumper program.
|
||||
bool SetArchitecture(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype);
|
||||
|
||||
// If this dumper's file includes an object file for |arch_name|, then select
|
||||
// that object file for dumping, and return true. Otherwise, return false,
|
||||
|
||||
// If this dumper's file includes an object file for |arch_name|, then select
|
||||
// that object file for dumping, and return true. Otherwise, return false,
|
||||
// and leave this dumper's selected architecture unchanged.
|
||||
//
|
||||
// By default, if this dumper's file contains only one object file, then
|
||||
@@ -94,7 +94,7 @@ class DumpSymbols {
|
||||
// object file, then the dumper will dump the object file whose
|
||||
// architecture matches that of this dumper program.
|
||||
bool SetArchitecture(const std::string &arch_name);
|
||||
|
||||
|
||||
// Return a pointer to an array of 'struct fat_arch' structures,
|
||||
// describing the object files contained in this dumper's file. Set
|
||||
// *|count| to the number of elements in the array. The returned array is
|
||||
@@ -109,10 +109,10 @@ class DumpSymbols {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Read the selected object file's debugging information, and write it
|
||||
// out to |stream|. Return true on success; if an error occurs, report it
|
||||
// and return false.
|
||||
bool WriteSymbolFile(std::ostream &stream);
|
||||
// Read the selected object file's debugging information, and write it out to
|
||||
// |stream|. Write the CFI section if |cfi| is true. Return true on success;
|
||||
// if an error occurs, report it and return false.
|
||||
bool WriteSymbolFile(std::ostream &stream, bool cfi);
|
||||
|
||||
private:
|
||||
// Used internally.
|
||||
@@ -158,7 +158,7 @@ class DumpSymbols {
|
||||
// has exactly one element.
|
||||
vector<struct fat_arch> object_files_;
|
||||
|
||||
// The object file in object_files_ selected to dump, or NULL if
|
||||
// The object file in object_files_ selected to dump, or NULL if
|
||||
// SetArchitecture hasn't been called yet.
|
||||
const struct fat_arch *selected_object_file_;
|
||||
|
||||
|
48
thirdparty/breakpad/common/mac/dump_syms.mm
vendored
48
thirdparty/breakpad/common/mac/dump_syms.mm
vendored
@@ -1,6 +1,6 @@
|
||||
// -*- mode: c++ -*-
|
||||
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -79,7 +79,7 @@ namespace google_breakpad {
|
||||
bool DumpSymbols::Read(NSString *filename) {
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:filename]) {
|
||||
fprintf(stderr, "Object file does not exist: %s\n",
|
||||
[filename fileSystemRepresentation]);
|
||||
[filename fileSystemRepresentation]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -101,15 +101,15 @@ bool DumpSymbols::Read(NSString *filename) {
|
||||
// pathForResource:ofType:inDirectory likes.
|
||||
NSString *base_name = [input_pathname_ lastPathComponent];
|
||||
NSString *dwarf_resource;
|
||||
|
||||
|
||||
do {
|
||||
NSString *new_base_name = [base_name stringByDeletingPathExtension];
|
||||
|
||||
// If stringByDeletingPathExtension returned the name unchanged, then
|
||||
// there's nothing more for us to strip off --- lose.
|
||||
if ([new_base_name isEqualToString:base_name]) {
|
||||
fprintf(stderr, "Unable to find DWARF-bearing file in bundle: %s\n",
|
||||
[input_pathname_ fileSystemRepresentation]);
|
||||
fprintf(stderr, "Unable to find DWARF-bearing file in bundle: %s\n",
|
||||
[input_pathname_ fileSystemRepresentation]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -141,12 +141,12 @@ bool DumpSymbols::Read(NSString *filename) {
|
||||
// file don't affect memory and vice versa).
|
||||
NSError *error;
|
||||
contents_ = [NSData dataWithContentsOfFile:object_filename_
|
||||
options:0
|
||||
error:&error];
|
||||
options:0
|
||||
error:&error];
|
||||
if (!contents_) {
|
||||
fprintf(stderr, "Error reading object file: %s: %s\n",
|
||||
[object_filename_ fileSystemRepresentation],
|
||||
[[error localizedDescription] UTF8String]);
|
||||
[object_filename_ fileSystemRepresentation],
|
||||
[[error localizedDescription] UTF8String]);
|
||||
return false;
|
||||
}
|
||||
[contents_ retain];
|
||||
@@ -166,7 +166,7 @@ bool DumpSymbols::Read(NSString *filename) {
|
||||
fat_reader.object_files(&object_files_count);
|
||||
if (object_files_count == 0) {
|
||||
fprintf(stderr, "Fat binary file contains *no* architectures: %s\n",
|
||||
[object_filename_ fileSystemRepresentation]);
|
||||
[object_filename_ fileSystemRepresentation]);
|
||||
return false;
|
||||
}
|
||||
object_files_.resize(object_files_count);
|
||||
@@ -197,14 +197,14 @@ bool DumpSymbols::SetArchitecture(const std::string &arch_name) {
|
||||
}
|
||||
return arch_set;
|
||||
}
|
||||
|
||||
|
||||
string DumpSymbols::Identifier() {
|
||||
FileID file_id([object_filename_ fileSystemRepresentation]);
|
||||
unsigned char identifier_bytes[16];
|
||||
cpu_type_t cpu_type = selected_object_file_->cputype;
|
||||
if (!file_id.MachoIdentifier(cpu_type, identifier_bytes)) {
|
||||
fprintf(stderr, "Unable to calculate UUID of mach-o binary %s!\n",
|
||||
[object_filename_ fileSystemRepresentation]);
|
||||
[object_filename_ fileSystemRepresentation]);
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ bool DumpSymbols::ReadDwarf(google_breakpad::Module *module,
|
||||
const mach_o::Reader &macho_reader,
|
||||
const mach_o::SectionMap &dwarf_sections) const {
|
||||
// Build a byte reader of the appropriate endianness.
|
||||
ByteReader byte_reader(macho_reader.big_endian()
|
||||
ByteReader byte_reader(macho_reader.big_endian()
|
||||
? dwarf2reader::ENDIANNESS_BIG
|
||||
: dwarf2reader::ENDIANNESS_LITTLE);
|
||||
|
||||
@@ -265,10 +265,10 @@ bool DumpSymbols::ReadDwarf(google_breakpad::Module *module,
|
||||
// There had better be a __debug_info section!
|
||||
if (!debug_info_section.first) {
|
||||
fprintf(stderr, "%s: __DWARF segment of file has no __debug_info section\n",
|
||||
selected_object_name_.c_str());
|
||||
selected_object_name_.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Build a line-to-module loader for the root handler to use.
|
||||
DumperLineToModule line_to_module(&byte_reader);
|
||||
|
||||
@@ -343,7 +343,7 @@ bool DumpSymbols::ReadCFI(google_breakpad::Module *module,
|
||||
// investigation, Mac OS X only uses DW_EH_PE_pcrel-based pointers, so
|
||||
// this is the only base address the CFI parser will need.
|
||||
byte_reader.SetCFIDataBase(section.address, cfi);
|
||||
|
||||
|
||||
dwarf2reader::CallFrameInfo::Reporter dwarf_reporter(selected_object_name_,
|
||||
section.section_name);
|
||||
dwarf2reader::CallFrameInfo parser(cfi, cfi_size,
|
||||
@@ -421,7 +421,7 @@ bool DumpSymbols::LoadCommandDumper::SymtabCommand(const ByteBuffer &entries,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DumpSymbols::WriteSymbolFile(std::ostream &stream) {
|
||||
bool DumpSymbols::WriteSymbolFile(std::ostream &stream, bool cfi) {
|
||||
// Select an object file, if SetArchitecture hasn't been called to set one
|
||||
// explicitly.
|
||||
if (!selected_object_file_) {
|
||||
@@ -433,10 +433,10 @@ bool DumpSymbols::WriteSymbolFile(std::ostream &stream) {
|
||||
const NXArchInfo *local_arch = NXGetLocalArchInfo();
|
||||
if (!SetArchitecture(local_arch->cputype, local_arch->cpusubtype)) {
|
||||
fprintf(stderr, "%s: object file contains more than one"
|
||||
" architecture, none of which match the current"
|
||||
" architecture, none of which match the current"
|
||||
" architecture; specify an architecture explicitly"
|
||||
" with '-a ARCH' to resolve the ambiguity\n",
|
||||
[object_filename_ fileSystemRepresentation]);
|
||||
" with '-a ARCH' to resolve the ambiguity\n",
|
||||
[object_filename_ fileSystemRepresentation]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -472,7 +472,7 @@ bool DumpSymbols::WriteSymbolFile(std::ostream &stream) {
|
||||
identifier += "0";
|
||||
|
||||
// Create a module to hold the debugging information.
|
||||
Module module([module_name UTF8String], "mac", selected_arch_name,
|
||||
Module module([module_name UTF8String], "mac", selected_arch_name,
|
||||
identifier);
|
||||
|
||||
// Parse the selected object file.
|
||||
@@ -481,8 +481,8 @@ bool DumpSymbols::WriteSymbolFile(std::ostream &stream) {
|
||||
if (!reader.Read(reinterpret_cast<const uint8_t *>([contents_ bytes])
|
||||
+ selected_object_file_->offset,
|
||||
selected_object_file_->size,
|
||||
selected_object_file_->cputype,
|
||||
selected_object_file_->cpusubtype))
|
||||
selected_object_file_->cputype,
|
||||
selected_object_file_->cpusubtype))
|
||||
return false;
|
||||
|
||||
// Walk its load commands, and deal with whatever is there.
|
||||
@@ -490,7 +490,7 @@ bool DumpSymbols::WriteSymbolFile(std::ostream &stream) {
|
||||
if (!reader.WalkLoadCommands(&load_command_dumper))
|
||||
return false;
|
||||
|
||||
return module.Write(stream);
|
||||
return module.Write(stream, cfi);
|
||||
}
|
||||
|
||||
} // namespace google_breakpad
|
||||
|
45
thirdparty/breakpad/common/mac/macho_id.cc
vendored
45
thirdparty/breakpad/common/mac/macho_id.cc
vendored
@@ -51,18 +51,29 @@ extern "C" { // necessary for Leopard
|
||||
|
||||
namespace MacFileUtilities {
|
||||
|
||||
using google_breakpad::MD5Init;
|
||||
using google_breakpad::MD5Update;
|
||||
using google_breakpad::MD5Final;
|
||||
|
||||
MachoID::MachoID(const char *path)
|
||||
: file_(0),
|
||||
: memory_(0),
|
||||
memory_size_(0),
|
||||
crc_(0),
|
||||
md5_context_(),
|
||||
update_function_(NULL) {
|
||||
strlcpy(path_, path, sizeof(path_));
|
||||
}
|
||||
|
||||
MachoID::MachoID(const char *path, void *memory, size_t size)
|
||||
: memory_(memory),
|
||||
memory_size_(size),
|
||||
crc_(0),
|
||||
md5_context_(),
|
||||
update_function_(NULL) {
|
||||
strlcpy(path_, path, sizeof(path_));
|
||||
file_ = open(path, O_RDONLY);
|
||||
}
|
||||
|
||||
MachoID::~MachoID() {
|
||||
if (file_ != -1)
|
||||
close(file_);
|
||||
}
|
||||
|
||||
// The CRC info is from http://en.wikipedia.org/wiki/Adler-32
|
||||
@@ -144,10 +155,8 @@ void MachoID::Update(MachoWalker *walker, off_t offset, size_t size) {
|
||||
|
||||
bool MachoID::UUIDCommand(int cpu_type, unsigned char bytes[16]) {
|
||||
struct breakpad_uuid_command uuid_cmd;
|
||||
MachoWalker walker(path_, UUIDWalkerCB, &uuid_cmd);
|
||||
|
||||
uuid_cmd.cmd = 0;
|
||||
if (!walker.WalkHeader(cpu_type))
|
||||
if (!WalkHeader(cpu_type, UUIDWalkerCB, &uuid_cmd))
|
||||
return false;
|
||||
|
||||
// If we found the command, we'll have initialized the uuid_command
|
||||
@@ -162,10 +171,8 @@ bool MachoID::UUIDCommand(int cpu_type, unsigned char bytes[16]) {
|
||||
|
||||
bool MachoID::IDCommand(int cpu_type, unsigned char identifier[16]) {
|
||||
struct dylib_command dylib_cmd;
|
||||
MachoWalker walker(path_, IDWalkerCB, &dylib_cmd);
|
||||
|
||||
dylib_cmd.cmd = 0;
|
||||
if (!walker.WalkHeader(cpu_type))
|
||||
if (!WalkHeader(cpu_type, IDWalkerCB, &dylib_cmd))
|
||||
return false;
|
||||
|
||||
// If we found the command, we'll have initialized the dylib_command
|
||||
@@ -204,29 +211,39 @@ bool MachoID::IDCommand(int cpu_type, unsigned char identifier[16]) {
|
||||
}
|
||||
|
||||
uint32_t MachoID::Adler32(int cpu_type) {
|
||||
MachoWalker walker(path_, WalkerCB, this);
|
||||
update_function_ = &MachoID::UpdateCRC;
|
||||
crc_ = 0;
|
||||
|
||||
if (!walker.WalkHeader(cpu_type))
|
||||
if (!WalkHeader(cpu_type, WalkerCB, this))
|
||||
return 0;
|
||||
|
||||
return crc_;
|
||||
}
|
||||
|
||||
bool MachoID::MD5(int cpu_type, unsigned char identifier[16]) {
|
||||
MachoWalker walker(path_, WalkerCB, this);
|
||||
update_function_ = &MachoID::UpdateMD5;
|
||||
|
||||
MD5Init(&md5_context_);
|
||||
|
||||
if (!walker.WalkHeader(cpu_type))
|
||||
if (!WalkHeader(cpu_type, WalkerCB, this))
|
||||
return false;
|
||||
|
||||
MD5Final(identifier, &md5_context_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MachoID::WalkHeader(int cpu_type,
|
||||
MachoWalker::LoadCommandCallback callback,
|
||||
void *context) {
|
||||
if (memory_) {
|
||||
MachoWalker walker(memory_, memory_size_, callback, context);
|
||||
return walker.WalkHeader(cpu_type);
|
||||
} else {
|
||||
MachoWalker walker(path_, callback, context);
|
||||
return walker.WalkHeader(cpu_type);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
bool MachoID::WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
|
||||
bool swap, void *context) {
|
||||
|
17
thirdparty/breakpad/common/mac/macho_id.h
vendored
17
thirdparty/breakpad/common/mac/macho_id.h
vendored
@@ -37,15 +37,15 @@
|
||||
#include <limits.h>
|
||||
#include <mach-o/loader.h>
|
||||
|
||||
#include "common/mac/macho_walker.h"
|
||||
#include "common/md5.h"
|
||||
|
||||
namespace MacFileUtilities {
|
||||
|
||||
class MachoWalker;
|
||||
|
||||
class MachoID {
|
||||
public:
|
||||
MachoID(const char *path);
|
||||
MachoID(const char *path, void *memory, size_t size);
|
||||
~MachoID();
|
||||
|
||||
// For the given |cpu_type|, return a UUID from the LC_UUID command.
|
||||
@@ -80,6 +80,10 @@ class MachoID {
|
||||
// Bottleneck for update routines
|
||||
void Update(MachoWalker *walker, off_t offset, size_t size);
|
||||
|
||||
// Factory for the MachoWalker
|
||||
bool WalkHeader(int cpu_type, MachoWalker::LoadCommandCallback callback,
|
||||
void *context);
|
||||
|
||||
// The callback from the MachoWalker for CRC and MD5
|
||||
static bool WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
|
||||
bool swap, void *context);
|
||||
@@ -95,14 +99,17 @@ class MachoID {
|
||||
// File path
|
||||
char path_[PATH_MAX];
|
||||
|
||||
// File descriptor
|
||||
int file_;
|
||||
// Memory region to read from
|
||||
void *memory_;
|
||||
|
||||
// Size of the memory region
|
||||
size_t memory_size_;
|
||||
|
||||
// The current crc value
|
||||
uint32_t crc_;
|
||||
|
||||
// The MD5 context
|
||||
MD5Context md5_context_;
|
||||
google_breakpad::MD5Context md5_context_;
|
||||
|
||||
// The current update to call from the Update callback
|
||||
UpdateFunction update_function_;
|
||||
|
@@ -38,6 +38,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Unfortunately, CPU_TYPE_ARM is not define for 10.4.
|
||||
#if !defined(CPU_TYPE_ARM)
|
||||
#define CPU_TYPE_ARM 12
|
||||
#endif
|
||||
|
||||
namespace google_breakpad {
|
||||
namespace mach_o {
|
||||
|
||||
@@ -230,6 +235,7 @@ bool Reader::Read(const uint8_t *buffer,
|
||||
uint32_t expected_magic;
|
||||
// validate that magic matches the expected cpu type
|
||||
switch (expected_cpu_type) {
|
||||
case CPU_TYPE_ARM:
|
||||
case CPU_TYPE_I386:
|
||||
expected_magic = MH_CIGAM;
|
||||
break;
|
||||
|
30
thirdparty/breakpad/common/mac/macho_walker.cc
vendored
30
thirdparty/breakpad/common/mac/macho_walker.cc
vendored
@@ -52,6 +52,8 @@ namespace MacFileUtilities {
|
||||
MachoWalker::MachoWalker(const char *path, LoadCommandCallback callback,
|
||||
void *context)
|
||||
: file_(0),
|
||||
memory_(NULL),
|
||||
memory_size_(0),
|
||||
callback_(callback),
|
||||
callback_context_(context),
|
||||
current_header_(NULL),
|
||||
@@ -60,6 +62,18 @@ MachoWalker::MachoWalker(const char *path, LoadCommandCallback callback,
|
||||
file_ = open(path, O_RDONLY);
|
||||
}
|
||||
|
||||
MachoWalker::MachoWalker(void *memory, size_t size,
|
||||
LoadCommandCallback callback, void *context)
|
||||
: file_(0),
|
||||
memory_(memory),
|
||||
memory_size_(size),
|
||||
callback_(callback),
|
||||
callback_context_(context),
|
||||
current_header_(NULL),
|
||||
current_header_size_(0),
|
||||
current_header_offset_(0) {
|
||||
}
|
||||
|
||||
MachoWalker::~MachoWalker() {
|
||||
if (file_ != -1)
|
||||
close(file_);
|
||||
@@ -90,7 +104,21 @@ bool MachoWalker::WalkHeader(int cpu_type) {
|
||||
}
|
||||
|
||||
bool MachoWalker::ReadBytes(void *buffer, size_t size, off_t offset) {
|
||||
return pread(file_, buffer, size, offset) == (ssize_t)size;
|
||||
if (memory_) {
|
||||
if (offset < 0)
|
||||
return false;
|
||||
bool result = true;
|
||||
if (offset + size > memory_size_) {
|
||||
if (static_cast<size_t>(offset) >= memory_size_)
|
||||
return false;
|
||||
size = memory_size_ - offset;
|
||||
result = false;
|
||||
}
|
||||
memcpy(buffer, static_cast<char *>(memory_) + offset, size);
|
||||
return result;
|
||||
} else {
|
||||
return pread(file_, buffer, size, offset) == (ssize_t)size;
|
||||
}
|
||||
}
|
||||
|
||||
bool MachoWalker::CurrentHeader(struct mach_header_64 *header, off_t *offset) {
|
||||
|
17
thirdparty/breakpad/common/mac/macho_walker.h
vendored
17
thirdparty/breakpad/common/mac/macho_walker.h
vendored
@@ -52,7 +52,8 @@ class MachoWalker {
|
||||
off_t offset, bool swap, void *context);
|
||||
|
||||
MachoWalker(const char *path, LoadCommandCallback callback, void *context);
|
||||
MachoWalker(int file_descriptor, LoadCommandCallback callback, void *context);
|
||||
MachoWalker(void *memory, size_t size, LoadCommandCallback callback,
|
||||
void *context);
|
||||
~MachoWalker();
|
||||
|
||||
// Begin walking the header for |cpu_type|. If |cpu_type| is 0, then the
|
||||
@@ -68,7 +69,7 @@ class MachoWalker {
|
||||
|
||||
// Read |size| bytes from the opened file at |offset| into |buffer|
|
||||
bool ReadBytes(void *buffer, size_t size, off_t offset);
|
||||
|
||||
|
||||
// Return the current header and header offset
|
||||
bool CurrentHeader(struct mach_header_64 *header, off_t *offset);
|
||||
|
||||
@@ -87,19 +88,25 @@ class MachoWalker {
|
||||
// File descriptor to the opened file
|
||||
int file_;
|
||||
|
||||
// Memory location to read from.
|
||||
void *memory_;
|
||||
|
||||
// Size of the memory segment we can read from.
|
||||
size_t memory_size_;
|
||||
|
||||
// User specified callback & context
|
||||
LoadCommandCallback callback_;
|
||||
void *callback_context_;
|
||||
|
||||
|
||||
// Current header, size, and offset. The mach_header_64 is used for both
|
||||
// 32-bit and 64-bit headers because they only differ in their last field
|
||||
// (reserved). By adding the |current_header_size_| and the
|
||||
// (reserved). By adding the |current_header_size_| and the
|
||||
// |current_header_offset_|, you can determine the offset in the file just
|
||||
// after the header.
|
||||
struct mach_header_64 *current_header_;
|
||||
unsigned long current_header_size_;
|
||||
off_t current_header_offset_;
|
||||
|
||||
|
||||
private:
|
||||
MachoWalker(const MachoWalker &);
|
||||
MachoWalker &operator=(const MachoWalker &);
|
||||
|
Reference in New Issue
Block a user