From 09de69eca1bc82fe4851d48baf4af5e9a1b9d0fa Mon Sep 17 00:00:00 2001 From: "qsr@chromium.org" Date: Mon, 24 Oct 2011 14:58:12 +0000 Subject: [PATCH] Do not use mach_vm.h on iOS. mach_vm.h has been removed from iOS5. Use #define to use vm_ replacement of mach_vm_ functions on iOS. Do not use mach_vm_allocate -> use a stack variable instead. Review URL: http://breakpad.appspot.com/321001 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@879 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/mac/handler/dynamic_images.cc | 1 - src/client/mac/handler/dynamic_images.h | 2 + src/client/mac/handler/mach_vm_compat.h | 48 ++++++++++++++++++++ src/client/mac/handler/minidump_generator.cc | 19 ++------ src/client/mac/handler/minidump_generator.h | 1 + 5 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 src/client/mac/handler/mach_vm_compat.h diff --git a/src/client/mac/handler/dynamic_images.cc b/src/client/mac/handler/dynamic_images.cc index 11f4e95d..3b22e180 100644 --- a/src/client/mac/handler/dynamic_images.cc +++ b/src/client/mac/handler/dynamic_images.cc @@ -38,7 +38,6 @@ extern "C" { // needed to compile on Leopard #include #include #include -#include #include #include #include diff --git a/src/client/mac/handler/dynamic_images.h b/src/client/mac/handler/dynamic_images.h index d4062ea6..d039eda0 100644 --- a/src/client/mac/handler/dynamic_images.h +++ b/src/client/mac/handler/dynamic_images.h @@ -45,6 +45,8 @@ #include #include +#include "mach_vm_compat.h" + namespace google_breakpad { using std::string; diff --git a/src/client/mac/handler/mach_vm_compat.h b/src/client/mac/handler/mach_vm_compat.h new file mode 100644 index 00000000..baaf1d0c --- /dev/null +++ b/src/client/mac/handler/mach_vm_compat.h @@ -0,0 +1,48 @@ +// Copyright (c) 2011, 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 CLIENT_MAC_GENERATOR_MACH_VM_COMPAT_H_ +#define CLIENT_MAC_GENERATOR_MACH_VM_COMPAT_H_ + +#include + +// On iOS 5, mach/mach_vm.h is not supported anymore. As the architecture is 32 +// bits, we can use the simple vm_ functions instead of the mach_vm_ ones. +#if TARGET_OS_IPHONE +#include +#define mach_vm_address_t vm_address_t +#define mach_vm_read vm_read +#define mach_vm_region vm_region +#define mach_vm_region_recurse vm_region_recurse +#define mach_vm_size_t vm_size_t +#else +#include +#endif // TARGET_OS_IPHONE + +#endif // CLIENT_MAC_GENERATOR_MACH_VM_COMPAT_H_ diff --git a/src/client/mac/handler/minidump_generator.cc b/src/client/mac/handler/minidump_generator.cc index f245f66d..68d7903a 100644 --- a/src/client/mac/handler/minidump_generator.cc +++ b/src/client/mac/handler/minidump_generator.cc @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -1378,19 +1377,11 @@ bool MinidumpGenerator::WriteMiscInfoStream(MDRawDirectory *misc_info_stream) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, static_cast(info_ptr->process_id) }; u_int mibsize = static_cast(sizeof(mib) / sizeof(mib[0])); - size_t size; - if (!sysctl(mib, mibsize, NULL, &size, NULL, 0)) { - mach_vm_address_t addr; - if (mach_vm_allocate(mach_task_self(), - &addr, - size, - true) == KERN_SUCCESS) { - struct kinfo_proc *proc = (struct kinfo_proc *)addr; - if (!sysctl(mib, mibsize, proc, &size, NULL, 0)) - info_ptr->process_create_time = - static_cast(proc->kp_proc.p_starttime.tv_sec); - mach_vm_deallocate(mach_task_self(), addr, size); - } + struct kinfo_proc proc; + size_t size = sizeof(proc); + if (sysctl(mib, mibsize, &proc, &size, NULL, 0) == 0) { + info_ptr->process_create_time = + static_cast(proc.kp_proc.p_starttime.tv_sec); } // Speed diff --git a/src/client/mac/handler/minidump_generator.h b/src/client/mac/handler/minidump_generator.h index 7e932073..f5a4d44a 100644 --- a/src/client/mac/handler/minidump_generator.h +++ b/src/client/mac/handler/minidump_generator.h @@ -43,6 +43,7 @@ #include "google_breakpad/common/minidump_format.h" #include "dynamic_images.h" +#include "mach_vm_compat.h" #if !TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7) #define HAS_PPC_SUPPORT