Commit 0c5a5e62 authored by mark@chromium.org's avatar mark@chromium.org

Back out r269483 and the line of fixes that followed it.

This backs out r296483, r269492, r269501, and r269511. The iOS bots hated it.
They don't like mach_vm_* and must use vm_* instead, and they can't #include
<mach/mach_vm.h> at all. The above patches dealt with that, but then when it
turned out that the iOS bots also weren't even building ScopedMachVM or
MACH_LOG at all, I decided to call it quits.

http://build.chromium.org/p/chromium.mac/builders/iOS%20Device%20%28ninja%29/builds/919/steps/compile/logs/stdio
http://build.chromium.org/p/chromium.mac/builders/iOS%20Device%20%28ninja%29/builds/921/steps/compile/logs/stdio
http://build.chromium.org/p/chromium.mac/builders/iOS%20Simulator%20%28dbg%29/builds/16185/steps/compile/logs/stdio

TBR=rsesek

Review URL: https://codereview.chromium.org/274193007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269516 0039d316-1c4b-4281-b951-d872f2087c98
parent be266584
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef BASE_MAC_MAC_LOGGING_H_ #ifndef BASE_MAC_MAC_LOGGING_H_
#define BASE_MAC_MAC_LOGGING_H_ #define BASE_MAC_MAC_LOGGING_H_
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -45,12 +43,6 @@ class BASE_EXPORT OSStatusLogMessage : public logging::LogMessage { ...@@ -45,12 +43,6 @@ class BASE_EXPORT OSStatusLogMessage : public logging::LogMessage {
} // namespace logging } // namespace logging
#if defined(NDEBUG)
#define MAC_DVLOG_IS_ON(verbose_level) 0
#else
#define MAC_DVLOG_IS_ON(verbose_level) VLOG_IS_ON(verbose_level)
#endif
#define OSSTATUS_LOG_STREAM(severity, status) \ #define OSSTATUS_LOG_STREAM(severity, status) \
COMPACT_GOOGLE_LOG_EX_ ## severity(OSStatusLogMessage, status).stream() COMPACT_GOOGLE_LOG_EX_ ## severity(OSStatusLogMessage, status).stream()
#define OSSTATUS_VLOG_STREAM(verbose_level, status) \ #define OSSTATUS_VLOG_STREAM(verbose_level, status) \
...@@ -82,10 +74,10 @@ class BASE_EXPORT OSStatusLogMessage : public logging::LogMessage { ...@@ -82,10 +74,10 @@ class BASE_EXPORT OSStatusLogMessage : public logging::LogMessage {
#define OSSTATUS_DVLOG(verbose_level, status) \ #define OSSTATUS_DVLOG(verbose_level, status) \
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \ LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
MAC_DVLOG_IS_ON(verbose_level)) DVLOG_IS_ON(verbose_level))
#define OSSTATUS_DVLOG_IF(verbose_level, condition, status) \ #define OSSTATUS_DVLOG_IF(verbose_level, condition, status) \
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \ LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status) \
MAC_DVLOG_IS_ON(verbose_level) && (condition)) DVLOG_IS_ON(verbose_level) && (condition))
#define OSSTATUS_DCHECK(condition, status) \ #define OSSTATUS_DCHECK(condition, status) \
LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), \ LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), \
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <mach/mach.h> #include <mach/mach.h>
#include "base/base_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -32,7 +31,7 @@ ...@@ -32,7 +31,7 @@
namespace logging { namespace logging {
class BASE_EXPORT MachLogMessage : public logging::LogMessage { class MachLogMessage : public logging::LogMessage {
public: public:
MachLogMessage(const char* file_path, MachLogMessage(const char* file_path,
int line, int line,
...@@ -46,7 +45,7 @@ class BASE_EXPORT MachLogMessage : public logging::LogMessage { ...@@ -46,7 +45,7 @@ class BASE_EXPORT MachLogMessage : public logging::LogMessage {
DISALLOW_COPY_AND_ASSIGN(MachLogMessage); DISALLOW_COPY_AND_ASSIGN(MachLogMessage);
}; };
class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage { class BootstrapLogMessage : public logging::LogMessage {
public: public:
BootstrapLogMessage(const char* file_path, BootstrapLogMessage(const char* file_path,
int line, int line,
...@@ -62,12 +61,6 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage { ...@@ -62,12 +61,6 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage {
} // namespace logging } // namespace logging
#if defined(NDEBUG)
#define MACH_DVLOG_IS_ON(verbose_level) 0
#else
#define MACH_DVLOG_IS_ON(verbose_level) VLOG_IS_ON(verbose_level)
#endif
#define MACH_LOG_STREAM(severity, mach_err) \ #define MACH_LOG_STREAM(severity, mach_err) \
COMPACT_GOOGLE_LOG_EX_ ## severity(MachLogMessage, mach_err).stream() COMPACT_GOOGLE_LOG_EX_ ## severity(MachLogMessage, mach_err).stream()
#define MACH_VLOG_STREAM(verbose_level, mach_err) \ #define MACH_VLOG_STREAM(verbose_level, mach_err) \
...@@ -99,18 +92,16 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage { ...@@ -99,18 +92,16 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage {
#define MACH_DVLOG(verbose_level, mach_err) \ #define MACH_DVLOG(verbose_level, mach_err) \
LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \ LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \
MACH_DVLOG_IS_ON(verbose_level)) DVLOG_IS_ON(verbose_level))
#define MACH_DVLOG_IF(verbose_level, condition, mach_err) \ #define MACH_DVLOG_IF(verbose_level, condition, mach_err) \
LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \ LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err) \
MACH_DVLOG_IS_ON(verbose_level) && (condition)) DVLOG_IS_ON(verbose_level) && (condition))
#define MACH_DCHECK(condition, mach_err) \ #define MACH_DCHECK(condition, mach_err) \
LAZY_STREAM(MACH_LOG_STREAM(FATAL, mach_err), \ LAZY_STREAM(MACH_LOG_STREAM(FATAL, mach_err), \
DCHECK_IS_ON && !(condition)) \ DCHECK_IS_ON && !(condition)) \
<< "Check failed: " # condition << ". " << "Check failed: " # condition << ". "
#define BOOTSTRAP_DVLOG_IS_ON MACH_DVLOG_IS_ON
#define BOOTSTRAP_LOG_STREAM(severity, bootstrap_err) \ #define BOOTSTRAP_LOG_STREAM(severity, bootstrap_err) \
COMPACT_GOOGLE_LOG_EX_ ## severity(BootstrapLogMessage, \ COMPACT_GOOGLE_LOG_EX_ ## severity(BootstrapLogMessage, \
bootstrap_err).stream() bootstrap_err).stream()
...@@ -145,10 +136,10 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage { ...@@ -145,10 +136,10 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage {
#define BOOTSTRAP_DVLOG(verbose_level, bootstrap_err) \ #define BOOTSTRAP_DVLOG(verbose_level, bootstrap_err) \
LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \ LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \
BOOTSTRAP_DVLOG_IS_ON(verbose_level)) DVLOG_IS_ON(verbose_level))
#define BOOTSTRAP_DVLOG_IF(verbose_level, condition, bootstrap_err) \ #define BOOTSTRAP_DVLOG_IF(verbose_level, condition, bootstrap_err) \
LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \ LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err) \
BOOTSTRAP_DVLOG_IS_ON(verbose_level) && (condition)) DVLOG_IS_ON(verbose_level) && (condition))
#define BOOTSTRAP_DCHECK(condition, bootstrap_err) \ #define BOOTSTRAP_DCHECK(condition, bootstrap_err) \
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(FATAL, bootstrap_err), \ LAZY_STREAM(BOOTSTRAP_LOG_STREAM(FATAL, bootstrap_err), \
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <mach/mach.h> #include <mach/mach.h>
#include "base/base_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/base_export.h"
namespace base { namespace base {
namespace mac { namespace mac {
......
...@@ -4,12 +4,6 @@ ...@@ -4,12 +4,6 @@
#include "base/mac/scoped_mach_vm.h" #include "base/mac/scoped_mach_vm.h"
#if defined(OS_IOS)
#define mach_vm_address_t vm_address_t
#define mach_vm_size_t vm_size_t
#define mach_vm_deallocate vm_deallocate
#endif // OS_IOS
namespace base { namespace base {
namespace mac { namespace mac {
......
...@@ -6,24 +6,12 @@ ...@@ -6,24 +6,12 @@
#define BASE_MAC_SCOPED_MACH_VM_H_ #define BASE_MAC_SCOPED_MACH_VM_H_
#include <mach/mach.h> #include <mach/mach.h>
#include <mach/mach_vm.h>
#include <algorithm> #include <algorithm>
#include "base/base_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h"
#if !defined(OS_IOS)
#include <mach/mach_vm.h>
#else // OS_IOS
// mach_vm.h is forbidden on iOS, but the routines in vm_map.h are a suitable
// substitute.
#include <mach/vm_map.h>
#define mach_vm_address_t vm_address_t
#define mach_vm_size_t vm_size_t
#define mach_vm_deallocate vm_deallocate
#endif // OS_IOS
// Use ScopedMachVM to supervise ownership of pages in the current process // Use ScopedMachVM to supervise ownership of pages in the current process
// through the Mach VM subsystem. Pages allocated with mach_vm_allocate can be // through the Mach VM subsystem. Pages allocated with mach_vm_allocate can be
...@@ -57,7 +45,7 @@ ...@@ -57,7 +45,7 @@
namespace base { namespace base {
namespace mac { namespace mac {
class BASE_EXPORT ScopedMachVM { class ScopedMachVM {
public: public:
explicit ScopedMachVM(mach_vm_address_t address = 0, mach_vm_size_t size = 0) explicit ScopedMachVM(mach_vm_address_t address = 0, mach_vm_size_t size = 0)
: address_(address), : address_(address),
...@@ -102,10 +90,4 @@ class BASE_EXPORT ScopedMachVM { ...@@ -102,10 +90,4 @@ class BASE_EXPORT ScopedMachVM {
} // namespace mac } // namespace mac
} // namespace base } // namespace base
#if defined(OS_IOS)
#undef mach_vm_address_t
#undef mach_vm_size_t
#undef mach_vm_deallocate
#endif // OS_IOS
#endif // BASE_MAC_SCOPED_MACH_VM_H_ #endif // BASE_MAC_SCOPED_MACH_VM_H_
...@@ -5,12 +5,11 @@ ...@@ -5,12 +5,11 @@
#include "base/memory/discardable_memory.h" #include "base/memory/discardable_memory.h"
#include <mach/mach.h> #include <mach/mach.h>
#include <sys/mman.h>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_vm.h"
#include "base/memory/discardable_memory_emulated.h" #include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_malloc.h" #include "base/memory/discardable_memory_malloc.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -26,44 +25,39 @@ const int kDiscardableMemoryTag = VM_MAKE_TAG(252); ...@@ -26,44 +25,39 @@ const int kDiscardableMemoryTag = VM_MAKE_TAG(252);
class DiscardableMemoryMac : public DiscardableMemory { class DiscardableMemoryMac : public DiscardableMemory {
public: public:
explicit DiscardableMemoryMac(size_t size) explicit DiscardableMemoryMac(size_t size)
: memory_(0, 0), : buffer_(0),
size_(mach_vm_round_page(size)) { size_(size) {
} }
bool Initialize() { bool Initialize() {
DCHECK_EQ(memory_.size(), 0u);
vm_address_t address = 0;
kern_return_t ret = vm_allocate(mach_task_self(), kern_return_t ret = vm_allocate(mach_task_self(),
&address, &buffer_,
size_, size_,
VM_FLAGS_PURGABLE | VM_FLAGS_PURGABLE |
VM_FLAGS_ANYWHERE | VM_FLAGS_ANYWHERE |
kDiscardableMemoryTag); kDiscardableMemoryTag);
if (ret != KERN_SUCCESS) { if (ret != KERN_SUCCESS) {
MACH_DLOG(ERROR, ret) << "vm_allocate"; DLOG(ERROR) << "vm_allocate() failed";
return false; return false;
} }
memory_.reset(address, size_);
return true; return true;
} }
virtual ~DiscardableMemoryMac() { virtual ~DiscardableMemoryMac() {
if (buffer_)
vm_deallocate(mach_task_self(), buffer_, size_);
} }
virtual DiscardableMemoryLockStatus Lock() OVERRIDE { virtual DiscardableMemoryLockStatus Lock() OVERRIDE {
kern_return_t ret; DCHECK_EQ(0, mprotect(reinterpret_cast<void*>(buffer_),
MACH_DCHECK((ret = vm_protect(mach_task_self(), size_,
memory_.address(), PROT_READ | PROT_WRITE));
memory_.size(),
FALSE,
VM_PROT_DEFAULT)) == KERN_SUCCESS, ret);
int state = VM_PURGABLE_NONVOLATILE; int state = VM_PURGABLE_NONVOLATILE;
ret = vm_purgable_control(mach_task_self(), kern_return_t ret = vm_purgable_control(mach_task_self(),
memory_.address(), buffer_,
VM_PURGABLE_SET_STATE, VM_PURGABLE_SET_STATE,
&state); &state);
if (ret != KERN_SUCCESS) if (ret != KERN_SUCCESS)
return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
...@@ -74,24 +68,21 @@ class DiscardableMemoryMac : public DiscardableMemory { ...@@ -74,24 +68,21 @@ class DiscardableMemoryMac : public DiscardableMemory {
virtual void Unlock() OVERRIDE { virtual void Unlock() OVERRIDE {
int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT; int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT;
kern_return_t ret = vm_purgable_control(mach_task_self(), kern_return_t ret = vm_purgable_control(mach_task_self(),
memory_.address(), buffer_,
VM_PURGABLE_SET_STATE, VM_PURGABLE_SET_STATE,
&state); &state);
MACH_DLOG_IF(ERROR, ret != KERN_SUCCESS, ret) << "vm_purgable_control"; DCHECK_EQ(0, mprotect(reinterpret_cast<void*>(buffer_), size_, PROT_NONE));
MACH_DCHECK((ret = vm_protect(mach_task_self(), if (ret != KERN_SUCCESS)
memory_.address(), DLOG(ERROR) << "Failed to unlock memory.";
memory_.size(),
FALSE,
VM_PROT_NONE)) == KERN_SUCCESS, ret);
} }
virtual void* Memory() const OVERRIDE { virtual void* Memory() const OVERRIDE {
return reinterpret_cast<void*>(memory_.address()); return reinterpret_cast<void*>(buffer_);
} }
private: private:
mac::ScopedMachVM memory_; vm_address_t buffer_;
size_t size_; const size_t size_;
DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMac); DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMac);
}; };
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/mach_logging.h"
#include "base/scoped_clear_errno.h" #include "base/scoped_clear_errno.h"
#include "third_party/apple_apsl/CFBase.h" #include "third_party/apple_apsl/CFBase.h"
#include "third_party/apple_apsl/malloc.h" #include "third_party/apple_apsl/malloc.h"
...@@ -223,12 +222,10 @@ void DeprotectMallocZone(ChromeMallocZone* default_zone, ...@@ -223,12 +222,10 @@ void DeprotectMallocZone(ChromeMallocZone* default_zone,
reinterpret_cast<vm_region_info_t>(&info), reinterpret_cast<vm_region_info_t>(&info),
&count, &count,
&unused); &unused);
MACH_CHECK(result == KERN_SUCCESS, result) << "mach_vm_region"; CHECK(result == KERN_SUCCESS);
// The kernel always returns a null object for VM_REGION_BASIC_INFO_64, but result = mach_port_deallocate(mach_task_self(), unused);
// balance it with a deallocate in case this ever changes. See 10.9.2 CHECK(result == KERN_SUCCESS);
// xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region.
mach_port_deallocate(mach_task_self(), unused);
// Does the region fully enclose the zone pointers? Possibly unwarranted // Does the region fully enclose the zone pointers? Possibly unwarranted
// simplification used: using the size of a full version 8 malloc zone rather // simplification used: using the size of a full version 8 malloc zone rather
...@@ -251,7 +248,7 @@ void DeprotectMallocZone(ChromeMallocZone* default_zone, ...@@ -251,7 +248,7 @@ void DeprotectMallocZone(ChromeMallocZone* default_zone,
*reprotection_length, *reprotection_length,
false, false,
info.protection | VM_PROT_WRITE); info.protection | VM_PROT_WRITE);
MACH_CHECK(result == KERN_SUCCESS, result) << "mach_vm_protect"; CHECK(result == KERN_SUCCESS);
} }
} }
...@@ -649,7 +646,7 @@ void EnableTerminationOnOutOfMemory() { ...@@ -649,7 +646,7 @@ void EnableTerminationOnOutOfMemory() {
default_reprotection_length, default_reprotection_length,
false, false,
default_reprotection_value); default_reprotection_value);
MACH_CHECK(result == KERN_SUCCESS, result) << "mach_vm_protect"; CHECK(result == KERN_SUCCESS);
} }
if (purgeable_reprotection_start) { if (purgeable_reprotection_start) {
...@@ -658,7 +655,7 @@ void EnableTerminationOnOutOfMemory() { ...@@ -658,7 +655,7 @@ void EnableTerminationOnOutOfMemory() {
purgeable_reprotection_length, purgeable_reprotection_length,
false, false,
purgeable_reprotection_value); purgeable_reprotection_value);
MACH_CHECK(result == KERN_SUCCESS, result) << "mach_vm_protect"; CHECK(result == KERN_SUCCESS);
} }
#endif #endif
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/containers/hash_tables.h" #include "base/containers/hash_tables.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
#include "base/sys_info.h" #include "base/sys_info.h"
...@@ -117,6 +116,7 @@ size_t ProcessMetrics::GetPeakWorkingSetSize() const { ...@@ -117,6 +116,7 @@ size_t ProcessMetrics::GetPeakWorkingSetSize() const {
// shared_bytes is the size of shared resident memory. // shared_bytes is the size of shared resident memory.
bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
size_t* shared_bytes) { size_t* shared_bytes) {
kern_return_t kr;
size_t private_pages_count = 0; size_t private_pages_count = 0;
size_t shared_pages_count = 0; size_t shared_pages_count = 0;
...@@ -153,26 +153,22 @@ bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, ...@@ -153,26 +153,22 @@ bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
vm_region_top_info_data_t info; vm_region_top_info_data_t info;
mach_msg_type_number_t info_count = VM_REGION_TOP_INFO_COUNT; mach_msg_type_number_t info_count = VM_REGION_TOP_INFO_COUNT;
mach_port_t object_name; mach_port_t object_name;
kern_return_t kr = mach_vm_region(task, kr = mach_vm_region(task,
&address, &address,
&size, &size,
VM_REGION_TOP_INFO, VM_REGION_TOP_INFO,
reinterpret_cast<vm_region_info_t>(&info), (vm_region_info_t)&info,
&info_count, &info_count,
&object_name); &object_name);
if (kr == KERN_INVALID_ADDRESS) { if (kr == KERN_INVALID_ADDRESS) {
// We're at the end of the address space. // We're at the end of the address space.
break; break;
} else if (kr != KERN_SUCCESS) { } else if (kr != KERN_SUCCESS) {
MACH_DLOG(ERROR, kr) << "mach_vm_region"; DLOG(ERROR) << "Calling mach_vm_region failed with error: "
<< mach_error_string(kr);
return false; return false;
} }
// The kernel always returns a null object for VM_REGION_TOP_INFO, but
// balance it with a deallocate in case this ever changes. See 10.9.2
// xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region.
mach_port_deallocate(mach_task_self(), object_name);
if (IsAddressInSharedRegion(address, cpu_type) && if (IsAddressInSharedRegion(address, cpu_type) &&
info.share_mode != SM_PRIVATE) info.share_mode != SM_PRIVATE)
continue; continue;
...@@ -200,10 +196,18 @@ bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, ...@@ -200,10 +196,18 @@ bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
} }
} }
vm_size_t page_size;
kr = host_page_size(task, &page_size);
if (kr != KERN_SUCCESS) {
DLOG(ERROR) << "Failed to fetch host page size, error: "
<< mach_error_string(kr);
return false;
}
if (private_bytes) if (private_bytes)
*private_bytes = private_pages_count * PAGE_SIZE; *private_bytes = private_pages_count * page_size;
if (shared_bytes) if (shared_bytes)
*shared_bytes = shared_pages_count * PAGE_SIZE; *shared_bytes = shared_pages_count * page_size;
return true; return true;
} }
...@@ -231,14 +235,16 @@ double ProcessMetrics::GetCPUUsage() { ...@@ -231,14 +235,16 @@ double ProcessMetrics::GetCPUUsage() {
if (task == MACH_PORT_NULL) if (task == MACH_PORT_NULL)
return 0; return 0;
kern_return_t kr;
// Libtop explicitly loops over the threads (libtop_pinfo_update_cpu_usage() // Libtop explicitly loops over the threads (libtop_pinfo_update_cpu_usage()
// in libtop.c), but this is more concise and gives the same results: // in libtop.c), but this is more concise and gives the same results:
task_thread_times_info thread_info_data; task_thread_times_info thread_info_data;
mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT; mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
kern_return_t kr = task_info(task, kr = task_info(task,
TASK_THREAD_TIMES_INFO, TASK_THREAD_TIMES_INFO,
reinterpret_cast<task_info_t>(&thread_info_data), reinterpret_cast<task_info_t>(&thread_info_data),
&thread_info_count); &thread_info_count);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
// Most likely cause: |task| is a zombie. // Most likely cause: |task| is a zombie.
return 0; return 0;
...@@ -288,12 +294,14 @@ int ProcessMetrics::GetIdleWakeupsPerSecond() { ...@@ -288,12 +294,14 @@ int ProcessMetrics::GetIdleWakeupsPerSecond() {
if (task == MACH_PORT_NULL) if (task == MACH_PORT_NULL)
return 0; return 0;
kern_return_t kr;
task_power_info power_info_data; task_power_info power_info_data;
mach_msg_type_number_t power_info_count = TASK_POWER_INFO_COUNT; mach_msg_type_number_t power_info_count = TASK_POWER_INFO_COUNT;
kern_return_t kr = task_info(task, kr = task_info(task,
TASK_POWER_INFO, TASK_POWER_INFO,
reinterpret_cast<task_info_t>(&power_info_data), reinterpret_cast<task_info_t>(&power_info_data),
&power_info_count); &power_info_count);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
// Most likely cause: |task| is a zombie, or this is on a pre-10.8.4 system // Most likely cause: |task| is a zombie, or this is on a pre-10.8.4 system
// where TASK_POWER_INFO isn't supported yet. // where TASK_POWER_INFO isn't supported yet.
...@@ -354,12 +362,19 @@ size_t GetSystemCommitCharge() { ...@@ -354,12 +362,19 @@ size_t GetSystemCommitCharge() {
kern_return_t kr = host_statistics(host, HOST_VM_INFO, kern_return_t kr = host_statistics(host, HOST_VM_INFO,
reinterpret_cast<host_info_t>(&data), reinterpret_cast<host_info_t>(&data),
&count); &count);
if (kr != KERN_SUCCESS) { if (kr) {
MACH_DLOG(WARNING, kr) << "host_statistics"; DLOG(WARNING) << "Failed to fetch host statistics.";
return 0;
}
vm_size_t page_size;
kr = host_page_size(host, &page_size);
if (kr) {
DLOG(ERROR) << "Failed to fetch host page size.";
return 0; return 0;
} }
return (data.active_count * PAGE_SIZE) / 1024; return (data.active_count * page_size) / 1024;
} }
} // namespace base } // namespace base
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h"
#include "base/threading/thread_id_name_manager.h" #include "base/threading/thread_id_name_manager.h"
#include "base/tracked_objects.h" #include "base/tracked_objects.h"
...@@ -62,19 +61,20 @@ void SetPriorityNormal(mach_port_t mach_thread_id) { ...@@ -62,19 +61,20 @@ void SetPriorityNormal(mach_port_t mach_thread_id) {
// Please note that this call could fail in rare cases depending // Please note that this call could fail in rare cases depending
// on runtime conditions. // on runtime conditions.
thread_standard_policy policy; thread_standard_policy policy;
kern_return_t result = kern_return_t result = thread_policy_set(mach_thread_id,
thread_policy_set(mach_thread_id, THREAD_STANDARD_POLICY,
THREAD_STANDARD_POLICY, (thread_policy_t)&policy,
reinterpret_cast<thread_policy_t>(&policy), THREAD_STANDARD_POLICY_COUNT);
THREAD_STANDARD_POLICY_COUNT);
if (result != KERN_SUCCESS) if (result != KERN_SUCCESS)
MACH_DVLOG(1, result) << "thread_policy_set"; DVLOG(1) << "thread_policy_set() failure: " << result;
} }
// Enables time-contraint policy and priority suitable for low-latency, // Enables time-contraint policy and priority suitable for low-latency,
// glitch-resistant audio. // glitch-resistant audio.
void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
kern_return_t result;
// Increase thread priority to real-time. // Increase thread priority to real-time.
// Please note that the thread_policy_set() calls may fail in // Please note that the thread_policy_set() calls may fail in
...@@ -85,13 +85,12 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { ...@@ -85,13 +85,12 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
// Make thread fixed priority. // Make thread fixed priority.
thread_extended_policy_data_t policy; thread_extended_policy_data_t policy;
policy.timeshare = 0; // Set to 1 for a non-fixed thread. policy.timeshare = 0; // Set to 1 for a non-fixed thread.
kern_return_t result = result = thread_policy_set(mach_thread_id,
thread_policy_set(mach_thread_id, THREAD_EXTENDED_POLICY,
THREAD_EXTENDED_POLICY, (thread_policy_t)&policy,
reinterpret_cast<thread_policy_t>(&policy), THREAD_EXTENDED_POLICY_COUNT);
THREAD_EXTENDED_POLICY_COUNT);
if (result != KERN_SUCCESS) { if (result != KERN_SUCCESS) {
MACH_DVLOG(1, result) << "thread_policy_set"; DVLOG(1) << "thread_policy_set() failure: " << result;
return; return;
} }
...@@ -100,10 +99,10 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { ...@@ -100,10 +99,10 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
precedence.importance = 63; precedence.importance = 63;
result = thread_policy_set(mach_thread_id, result = thread_policy_set(mach_thread_id,
THREAD_PRECEDENCE_POLICY, THREAD_PRECEDENCE_POLICY,
reinterpret_cast<thread_policy_t>(&precedence), (thread_policy_t)&precedence,
THREAD_PRECEDENCE_POLICY_COUNT); THREAD_PRECEDENCE_POLICY_COUNT);
if (result != KERN_SUCCESS) { if (result != KERN_SUCCESS) {
MACH_DVLOG(1, result) << "thread_policy_set"; DVLOG(1) << "thread_policy_set() failure: " << result;
return; return;
} }
...@@ -134,7 +133,7 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { ...@@ -134,7 +133,7 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
mach_timebase_info_data_t tb_info; mach_timebase_info_data_t tb_info;
mach_timebase_info(&tb_info); mach_timebase_info(&tb_info);
double ms_to_abs_time = double ms_to_abs_time =
(static_cast<double>(tb_info.denom) / tb_info.numer) * 1000000; ((double)tb_info.denom / (double)tb_info.numer) * 1000000;
thread_time_constraint_policy_data_t time_constraints; thread_time_constraint_policy_data_t time_constraints;
time_constraints.period = kTimeQuantum * ms_to_abs_time; time_constraints.period = kTimeQuantum * ms_to_abs_time;
...@@ -142,12 +141,12 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { ...@@ -142,12 +141,12 @@ void SetPriorityRealtimeAudio(mach_port_t mach_thread_id) {
time_constraints.constraint = kMaxTimeAllowed * ms_to_abs_time; time_constraints.constraint = kMaxTimeAllowed * ms_to_abs_time;
time_constraints.preemptible = 0; time_constraints.preemptible = 0;
result = result = thread_policy_set(mach_thread_id,
thread_policy_set(mach_thread_id, THREAD_TIME_CONSTRAINT_POLICY,
THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&time_constraints,
reinterpret_cast<thread_policy_t>(&time_constraints), THREAD_TIME_CONSTRAINT_POLICY_COUNT);
THREAD_TIME_CONSTRAINT_POLICY_COUNT); if (result != KERN_SUCCESS)
MACH_DVLOG_IF(1, result != KERN_SUCCESS, result) << "thread_policy_set"; DVLOG(1) << "thread_policy_set() failure: " << result;
return; return;
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
...@@ -47,7 +46,7 @@ uint64_t ComputeCurrentTicks() { ...@@ -47,7 +46,7 @@ uint64_t ComputeCurrentTicks() {
// whether mach_timebase_info has already been called. This is // whether mach_timebase_info has already been called. This is
// recommended by Apple's QA1398. // recommended by Apple's QA1398.
kern_return_t kr = mach_timebase_info(&timebase_info); kern_return_t kr = mach_timebase_info(&timebase_info);
MACH_DCHECK(kr == KERN_SUCCESS, kr) << "mach_timebase_info"; DCHECK_EQ(KERN_SUCCESS, kr);
} }
// mach_absolute_time is it when it comes to ticks on the Mac. Other calls // mach_absolute_time is it when it comes to ticks on the Mac. Other calls
...@@ -86,7 +85,7 @@ uint64_t ComputeThreadTicks() { ...@@ -86,7 +85,7 @@ uint64_t ComputeThreadTicks() {
THREAD_BASIC_INFO, THREAD_BASIC_INFO,
reinterpret_cast<thread_info_t>(&thread_info_data), reinterpret_cast<thread_info_t>(&thread_info_data),
&thread_info_count); &thread_info_count);
MACH_DCHECK(kr == KERN_SUCCESS, kr) << "thread_info"; DCHECK_EQ(KERN_SUCCESS, kr);
return (thread_info_data.user_time.seconds * return (thread_info_data.user_time.seconds *
base::Time::kMicrosecondsPerSecond) + base::Time::kMicrosecondsPerSecond) +
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "base/mac/authorization_util.h" #include "base/mac/authorization_util.h"
#include "base/mac/bundle_locations.h" #include "base/mac/bundle_locations.h"
#include "base/mac/mac_logging.h" #include "base/mac/mac_logging.h"
#include "base/mac/mach_logging.h"
#import "base/mac/mac_util.h" #import "base/mac/mac_util.h"
#include "base/mac/scoped_authorizationref.h" #include "base/mac/scoped_authorizationref.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
...@@ -82,7 +81,7 @@ io_service_t CopyHDIXDriveServiceForMedia(io_service_t media) { ...@@ -82,7 +81,7 @@ io_service_t CopyHDIXDriveServiceForMedia(io_service_t media) {
kIORegistryIterateParents, kIORegistryIterateParents,
&iterator_ref); &iterator_ref);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "IORegistryEntryCreateIterator"; LOG(ERROR) << "IORegistryEntryCreateIterator: " << kr;
return IO_OBJECT_NULL; return IO_OBJECT_NULL;
} }
base::mac::ScopedIOObject<io_iterator_t> iterator(iterator_ref); base::mac::ScopedIOObject<io_iterator_t> iterator(iterator_ref);
...@@ -208,7 +207,7 @@ bool IsPathOnReadOnlyDiskImage(const char path[], ...@@ -208,7 +207,7 @@ bool IsPathOnReadOnlyDiskImage(const char path[],
match_dict, match_dict,
&iterator_ref); &iterator_ref);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "IOServiceGetMatchingServices"; LOG(ERROR) << "IOServiceGetMatchingServices: " << kr;
return false; return false;
} }
base::mac::ScopedIOObject<io_iterator_t> iterator(iterator_ref); base::mac::ScopedIOObject<io_iterator_t> iterator(iterator_ref);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h" #include "base/mac/scoped_mach_port.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -29,6 +28,11 @@ namespace content { ...@@ -29,6 +28,11 @@ namespace content {
namespace { namespace {
// Prints a string representation of a Mach error code.
std::string MachErrorCode(kern_return_t err) {
return base::StringPrintf("0x%x %s", err, mach_error_string(err));
}
// Mach message structure used in the child as a sending message. // Mach message structure used in the child as a sending message.
struct MachBroker_ChildSendMsg { struct MachBroker_ChildSendMsg {
mach_msg_header_t header; mach_msg_header_t header;
...@@ -60,7 +64,8 @@ class MachListenerThreadDelegate : public base::PlatformThread::Delegate { ...@@ -60,7 +64,8 @@ class MachListenerThreadDelegate : public base::PlatformThread::Delegate {
MACH_PORT_RIGHT_RECEIVE, MACH_PORT_RIGHT_RECEIVE,
&port); &port);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "mach_port_allocate"; LOG(ERROR) << "Failed to allocate MachBroker server port: "
<< MachErrorCode(kr);
return false; return false;
} }
...@@ -68,7 +73,8 @@ class MachListenerThreadDelegate : public base::PlatformThread::Delegate { ...@@ -68,7 +73,8 @@ class MachListenerThreadDelegate : public base::PlatformThread::Delegate {
kr = mach_port_insert_right( kr = mach_port_insert_right(
mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND); mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "mach_port_insert_right"; LOG(ERROR) << "Failed to insert send right for MachBroker server port: "
<< MachErrorCode(kr);
return false; return false;
} }
...@@ -90,35 +96,33 @@ class MachListenerThreadDelegate : public base::PlatformThread::Delegate { ...@@ -90,35 +96,33 @@ class MachListenerThreadDelegate : public base::PlatformThread::Delegate {
msg.header.msgh_size = sizeof(msg); msg.header.msgh_size = sizeof(msg);
msg.header.msgh_local_port = server_port_.get(); msg.header.msgh_local_port = server_port_.get();
const mach_msg_option_t options = MACH_RCV_MSG |
MACH_RCV_TRAILER_TYPE(MACH_RCV_TRAILER_AUDIT) |
MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT);
kern_return_t kr; kern_return_t kr;
while ((kr = mach_msg(&msg.header, do {
options,
0,
sizeof(msg),
server_port_,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL)) == KERN_SUCCESS) {
// Use the kernel audit information to make sure this message is from // Use the kernel audit information to make sure this message is from
// a task that this process spawned. The kernel audit token contains the // a task that this process spawned. The kernel audit token contains the
// unspoofable pid of the task that sent the message. // unspoofable pid of the task that sent the message.
// mach_msg_option_t options = MACH_RCV_MSG |
// TODO(rsesek): In the 10.7 SDK, there's audit_token_to_pid(). MACH_RCV_TRAILER_TYPE(MACH_RCV_TRAILER_AUDIT) |
pid_t child_pid; MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT);
audit_token_to_au32(msg.trailer.msgh_audit,
NULL, NULL, NULL, NULL, NULL, &child_pid, NULL, NULL); kr = mach_msg(&msg.header, options, 0, sizeof(msg), server_port_,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
mach_port_t child_task_port = msg.child_task_port.name; if (kr == KERN_SUCCESS) {
// TODO(rsesek): In the 10.7 SDK, there's audit_token_to_pid().
// Take the lock and update the broker information. pid_t child_pid;
base::AutoLock lock(broker_->GetLock()); audit_token_to_au32(msg.trailer.msgh_audit,
broker_->FinalizePid(child_pid, child_task_port); NULL, NULL, NULL, NULL, NULL, &child_pid, NULL, NULL);
}
mach_port_t child_task_port = msg.child_task_port.name;
MACH_LOG(ERROR, kr) << "mach_msg";
// Take the lock and update the broker information.
base::AutoLock lock(broker_->GetLock());
broker_->FinalizePid(child_pid, child_task_port);
}
} while (kr == KERN_SUCCESS);
LOG(ERROR) << "MachBroker thread exiting; mach_msg() likely failed: "
<< MachErrorCode(kr);
} }
private: private:
...@@ -137,7 +141,7 @@ bool MachBroker::ChildSendTaskPortToParent() { ...@@ -137,7 +141,7 @@ bool MachBroker::ChildSendTaskPortToParent() {
mach_port_t bootstrap_port; mach_port_t bootstrap_port;
kern_return_t kr = task_get_bootstrap_port(mach_task_self(), &bootstrap_port); kern_return_t kr = task_get_bootstrap_port(mach_task_self(), &bootstrap_port);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "task_get_bootstrap_port"; LOG(ERROR) << "Failed to look up bootstrap port: " << MachErrorCode(kr);
return false; return false;
} }
...@@ -145,7 +149,7 @@ bool MachBroker::ChildSendTaskPortToParent() { ...@@ -145,7 +149,7 @@ bool MachBroker::ChildSendTaskPortToParent() {
kr = bootstrap_look_up(bootstrap_port, kr = bootstrap_look_up(bootstrap_port,
const_cast<char*>(GetMachPortName().c_str()), &parent_port); const_cast<char*>(GetMachPortName().c_str()), &parent_port);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
BOOTSTRAP_LOG(ERROR, kr) << "bootstrap_look_up"; LOG(ERROR) << "Failed to look up named parent port: " << MachErrorCode(kr);
return false; return false;
} }
...@@ -165,7 +169,7 @@ bool MachBroker::ChildSendTaskPortToParent() { ...@@ -165,7 +169,7 @@ bool MachBroker::ChildSendTaskPortToParent() {
kr = mach_msg(&msg.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, sizeof(msg), kr = mach_msg(&msg.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, sizeof(msg),
0, MACH_PORT_NULL, 100 /*milliseconds*/, MACH_PORT_NULL); 0, MACH_PORT_NULL, 100 /*milliseconds*/, MACH_PORT_NULL);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "mach_msg"; LOG(ERROR) << "Failed to send task port to parent: " << MachErrorCode(kr);
return false; return false;
} }
...@@ -275,7 +279,9 @@ void MachBroker::InvalidatePid(base::ProcessHandle pid) { ...@@ -275,7 +279,9 @@ void MachBroker::InvalidatePid(base::ProcessHandle pid) {
kern_return_t kr = mach_port_deallocate(mach_task_self(), kern_return_t kr = mach_port_deallocate(mach_task_self(),
it->second); it->second);
MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; LOG_IF(WARNING, kr != KERN_SUCCESS)
<< "Failed to mach_port_deallocate mach task " << it->second
<< ", error " << MachErrorCode(kr);
mach_map_.erase(it); mach_map_.erase(it);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment