-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PA: Migrate //base/mac/mach_loggin.* into partition_alloc_base/
Migrates //base/mac/mach_logging.* into PA's base, and also removes the deps to //base/mac/mach_logging.* in allocator shims. PS1 contains pure copies of //base/mac/mach_logging.* into .../partition_alloc_base/mac/. Bug: 1337681 Change-Id: I5e2489ca354bc6b1872d06cc1b111112d51c89bb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4587482 Reviewed-by: Takashi Sakamoto <tasak@google.com> Commit-Queue: Yuki Shiino <yukishiino@chromium.org> Reviewed-by: Bartek Nowierski <bartekn@chromium.org> Cr-Commit-Position: refs/heads/main@{#1153694}
- Loading branch information
Showing
7 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
base/allocator/partition_allocator/partition_alloc_base/mac/mach_logging.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/allocator/partition_allocator/partition_alloc_base/mac/mach_logging.h" | ||
|
||
#include <iomanip> | ||
#include <string> | ||
|
||
#include "base/allocator/partition_allocator/partition_alloc_base/strings/stringprintf.h" | ||
#include "build/build_config.h" | ||
|
||
namespace { | ||
|
||
std::string FormatMachErrorNumber(mach_error_t mach_err) { | ||
// For the os/kern subsystem, give the error number in decimal as in | ||
// <mach/kern_return.h>. Otherwise, give it in hexadecimal to make it easier | ||
// to visualize the various bits. See <mach/error.h>. | ||
if (mach_err >= 0 && mach_err < KERN_RETURN_MAX) { | ||
return partition_alloc::internal::base::TruncatingStringPrintf(" (%d)", | ||
mach_err); | ||
} | ||
return partition_alloc::internal::base::TruncatingStringPrintf(" (0x%08x)", | ||
mach_err); | ||
} | ||
|
||
} // namespace | ||
|
||
namespace partition_alloc::internal::logging { | ||
|
||
MachLogMessage::MachLogMessage(const char* file_path, | ||
int line, | ||
LogSeverity severity, | ||
mach_error_t mach_err) | ||
: LogMessage(file_path, line, severity), mach_err_(mach_err) {} | ||
|
||
MachLogMessage::~MachLogMessage() { | ||
stream() << ": " << mach_error_string(mach_err_) | ||
<< FormatMachErrorNumber(mach_err_); | ||
} | ||
|
||
} // namespace partition_alloc::internal::logging |
99 changes: 99 additions & 0 deletions
99
base/allocator/partition_allocator/partition_alloc_base/mac/mach_logging.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2014 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_MAC_MACH_LOGGING_H_ | ||
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_MAC_MACH_LOGGING_H_ | ||
|
||
#include <mach/mach.h> | ||
|
||
#include "base/allocator/partition_allocator/partition_alloc_base/component_export.h" | ||
#include "base/allocator/partition_allocator/partition_alloc_base/debug/debugging_buildflags.h" | ||
#include "base/allocator/partition_allocator/partition_alloc_base/logging.h" | ||
#include "build/build_config.h" | ||
|
||
// Use the PA_MACH_LOG family of macros along with a mach_error_t | ||
// (kern_return_t) containing a Mach error. The error value will be decoded so | ||
// that logged messages explain the error. | ||
// | ||
// Examples: | ||
// | ||
// kern_return_t kr = mach_timebase_info(&info); | ||
// if (kr != KERN_SUCCESS) { | ||
// PA_MACH_LOG(ERROR, kr) << "mach_timebase_info"; | ||
// } | ||
// | ||
// kr = vm_deallocate(task, address, size); | ||
// PA_MACH_DCHECK(kr == KERN_SUCCESS, kr) << "vm_deallocate"; | ||
|
||
namespace partition_alloc::internal::logging { | ||
|
||
class PA_COMPONENT_EXPORT(PARTITION_ALLOC) MachLogMessage | ||
: public partition_alloc::internal::logging::LogMessage { | ||
public: | ||
MachLogMessage(const char* file_path, | ||
int line, | ||
LogSeverity severity, | ||
mach_error_t mach_err); | ||
|
||
MachLogMessage(const MachLogMessage&) = delete; | ||
MachLogMessage& operator=(const MachLogMessage&) = delete; | ||
|
||
~MachLogMessage() override; | ||
|
||
private: | ||
mach_error_t mach_err_; | ||
}; | ||
|
||
} // namespace partition_alloc::internal::logging | ||
|
||
#if BUILDFLAG(PA_DCHECK_IS_ON) | ||
#define PA_MACH_DVLOG_IS_ON(verbose_level) PA_VLOG_IS_ON(verbose_level) | ||
#else | ||
#define PA_MACH_DVLOG_IS_ON(verbose_level) 0 | ||
#endif | ||
|
||
#define PA_MACH_LOG_STREAM(severity, mach_err) \ | ||
PA_COMPACT_GOOGLE_LOG_EX_##severity(MachLogMessage, mach_err).stream() | ||
#define PA_MACH_VLOG_STREAM(verbose_level, mach_err) \ | ||
::partition_alloc::internal::logging::MachLogMessage( \ | ||
__FILE__, __LINE__, -verbose_level, mach_err) \ | ||
.stream() | ||
|
||
#define PA_MACH_LOG(severity, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_LOG_STREAM(severity, mach_err), PA_LOG_IS_ON(severity)) | ||
#define PA_MACH_LOG_IF(severity, condition, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_LOG_STREAM(severity, mach_err), \ | ||
PA_LOG_IS_ON(severity) && (condition)) | ||
|
||
#define PA_MACH_VLOG(verbose_level, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_VLOG_STREAM(verbose_level, mach_err), \ | ||
PA_VLOG_IS_ON(verbose_level)) | ||
#define PA_MACH_VLOG_IF(verbose_level, condition, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_VLOG_STREAM(verbose_level, mach_err), \ | ||
PA_VLOG_IS_ON(verbose_level) && (condition)) | ||
|
||
#define PA_MACH_CHECK(condition, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_LOG_STREAM(FATAL, mach_err), !(condition)) \ | ||
<< "Check failed: " #condition << ". " | ||
|
||
#define PA_MACH_DLOG(severity, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_LOG_STREAM(severity, mach_err), \ | ||
PA_DLOG_IS_ON(severity)) | ||
#define PA_MACH_DLOG_IF(severity, condition, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_LOG_STREAM(severity, mach_err), \ | ||
PA_DLOG_IS_ON(severity) && (condition)) | ||
|
||
#define PA_MACH_DVLOG(verbose_level, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_VLOG_STREAM(verbose_level, mach_err), \ | ||
PA_MACH_DVLOG_IS_ON(verbose_level)) | ||
#define PA_MACH_DVLOG_IF(verbose_level, condition, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_VLOG_STREAM(verbose_level, mach_err), \ | ||
PA_MACH_DVLOG_IS_ON(verbose_level) && (condition)) | ||
|
||
#define PA_MACH_DCHECK(condition, mach_err) \ | ||
PA_LAZY_STREAM(PA_MACH_LOG_STREAM(FATAL, mach_err), \ | ||
BUILDFLAG(PA_DCHECK_IS_ON) && !(condition)) \ | ||
<< "Check failed: " #condition << ". " | ||
|
||
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_MAC_MACH_LOGGING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters