0

Move call_with_eh_frame to base/apple

Bug: 1444927
Change-Id: Ia7bc55cc6bde98c902efa38833453154a0d72d19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4779215
Commit-Queue: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1183642}
This commit is contained in:
Avi Drissman
2023-08-15 15:50:52 +00:00
committed by Chromium LUCI CQ
parent 834680492b
commit b94ce740b6
8 changed files with 41 additions and 43 deletions

@@ -1948,14 +1948,14 @@ component("base") {
"apple/bridging.h", "apple/bridging.h",
"apple/bundle_locations.h", "apple/bundle_locations.h",
"apple/bundle_locations.mm", "apple/bundle_locations.mm",
"apple/call_with_eh_frame.cc",
"apple/call_with_eh_frame.h",
"apple/call_with_eh_frame_asm.S",
"apple/owned_objc.h", "apple/owned_objc.h",
"apple/owned_objc.mm", "apple/owned_objc.mm",
"file_version_info_apple.h", "file_version_info_apple.h",
"file_version_info_apple.mm", "file_version_info_apple.mm",
"files/file_util_mac.mm", "files/file_util_mac.mm",
"mac/call_with_eh_frame.cc",
"mac/call_with_eh_frame.h",
"mac/call_with_eh_frame_asm.S",
"mac/dispatch_source_mach.cc", "mac/dispatch_source_mach.cc",
"mac/dispatch_source_mach.h", "mac/dispatch_source_mach.h",
"mac/foundation_util.h", "mac/foundation_util.h",
@@ -3727,8 +3727,8 @@ test("base_unittests") {
sources += [ sources += [
"allocator/partition_allocator/shim/allocator_interception_mac_unittest.mm", "allocator/partition_allocator/shim/allocator_interception_mac_unittest.mm",
"allocator/partition_allocator/shim/malloc_zone_functions_mac_unittest.cc", "allocator/partition_allocator/shim/malloc_zone_functions_mac_unittest.cc",
"apple/call_with_eh_frame_unittest.mm",
"enterprise_util_mac_unittest.mm", "enterprise_util_mac_unittest.mm",
"mac/call_with_eh_frame_unittest.mm",
"mac/dispatch_source_mach_unittest.cc", "mac/dispatch_source_mach_unittest.cc",
"mac/launch_application_unittest.mm", "mac/launch_application_unittest.mm",
"mac/mac_util_unittest.mm", "mac/mac_util_unittest.mm",

@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/mac/call_with_eh_frame.h" #include "base/apple/call_with_eh_frame.h"
#include <stdint.h> #include <stdint.h>
#include <unwind.h> #include <unwind.h>
#include "build/build_config.h" namespace base::apple {
namespace base::mac {
#if defined(__x86_64__) || defined(__aarch64__) #if defined(__x86_64__) || defined(__aarch64__)
extern "C" _Unwind_Reason_Code __gxx_personality_v0(int, extern "C" _Unwind_Reason_Code __gxx_personality_v0(int,
@@ -42,10 +40,10 @@ _Unwind_Reason_Code CxxPersonalityRoutine(
return __gxx_personality_v0(version, actions, exception_class, return __gxx_personality_v0(version, actions, exception_class,
exception_object, context); exception_object, context);
} }
#else // !defined(__x86_64__) && !defined(__aarch64__) #else // !defined(__x86_64__) && !defined(__aarch64__)
// No implementation exists, so just call the block directly. // No implementation exists, so just call the block directly.
void CallWithEHFrame(void (^block)(void)) { void CallWithEHFrame(void (^block)(void)) {
block(); block();
} }
#endif // defined(__x86_64__) || defined(__aarch64__) #endif // defined(__x86_64__) || defined(__aarch64__)
} // namespace base::mac } // namespace base::apple

@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef BASE_MAC_CALL_WITH_EH_FRAME_H_ #ifndef BASE_APPLE_CALL_WITH_EH_FRAME_H_
#define BASE_MAC_CALL_WITH_EH_FRAME_H_ #define BASE_APPLE_CALL_WITH_EH_FRAME_H_
#include "base/base_export.h" #include "base/base_export.h"
namespace base::mac { namespace base::apple {
// Invokes the specified block in a stack frame with a special exception // Invokes the specified block in a stack frame with a special exception
// handler. This function creates an exception handling stack frame that // handler. This function creates an exception handling stack frame that
@@ -19,6 +19,6 @@ namespace base::mac {
// in such a way that disrupts the generation of useful stack traces. // in such a way that disrupts the generation of useful stack traces.
void BASE_EXPORT CallWithEHFrame(void (^block)(void)); void BASE_EXPORT CallWithEHFrame(void (^block)(void));
} // namespace base::mac } // namespace base::apple
#endif // BASE_MAC_CALL_WITH_EH_FRAME_H_ #endif // BASE_APPLE_CALL_WITH_EH_FRAME_H_

@@ -4,8 +4,8 @@
#if defined(__x86_64__) || defined(__aarch64__) #if defined(__x86_64__) || defined(__aarch64__)
// base::mac::CallWithEHFrame(void () block_pointer) // base::apple::CallWithEHFrame(void () block_pointer)
#define CALL_WITH_EH_FRAME __ZN4base3mac15CallWithEHFrameEU13block_pointerFvvE #define CALL_WITH_EH_FRAME __ZN4base5apple15CallWithEHFrameEU13block_pointerFvvE
.section __TEXT,__text,regular,pure_instructions .section __TEXT,__text,regular,pure_instructions
#if !defined(COMPONENT_BUILD) #if !defined(COMPONENT_BUILD)
@@ -20,7 +20,7 @@ CALL_WITH_EH_FRAME:
// Configure the C++ exception handler personality routine. Normally the // Configure the C++ exception handler personality routine. Normally the
// compiler would emit ___gxx_personality_v0 here. The purpose of this // compiler would emit ___gxx_personality_v0 here. The purpose of this
// function is to use a custom personality routine. // function is to use a custom personality routine.
.cfi_personality 155, __ZN4base3mac21CxxPersonalityRoutineEi14_Unwind_ActionyP17_Unwind_ExceptionP15_Unwind_Context .cfi_personality 155, __ZN4base5apple21CxxPersonalityRoutineEi14_Unwind_ActionyP17_Unwind_ExceptionP15_Unwind_Context
.cfi_lsda 16, CallWithEHFrame_exception_table .cfi_lsda 16, CallWithEHFrame_exception_table
#if defined(__x86_64__) #if defined(__x86_64__)

@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/mac/call_with_eh_frame.h" #include "base/apple/call_with_eh_frame.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace base::mac { namespace base::apple {
namespace { namespace {
class CallWithEHFrameTest : public testing::Test { class CallWithEHFrameTest : public testing::Test {
@@ -23,7 +23,7 @@ class CallWithEHFrameTest : public testing::Test {
// Catching from within the EHFrame is allowed. // Catching from within the EHFrame is allowed.
TEST_F(CallWithEHFrameTest, CatchExceptionHigher) { TEST_F(CallWithEHFrameTest, CatchExceptionHigher) {
bool __block saw_exception = false; bool __block saw_exception = false;
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
@try { @try {
ThrowException(); ThrowException();
} @catch (NSException* exception) { } @catch (NSException* exception) {
@@ -38,7 +38,7 @@ TEST_F(CallWithEHFrameTest, CatchExceptionLower) {
auto catch_exception_lower = ^{ auto catch_exception_lower = ^{
bool saw_exception = false; bool saw_exception = false;
@try { @try {
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
ThrowException(); ThrowException();
}); });
} @catch (NSException* exception) { } @catch (NSException* exception) {
@@ -50,4 +50,4 @@ TEST_F(CallWithEHFrameTest, CatchExceptionLower) {
} }
} // namespace } // namespace
} // namespace base::mac } // namespace base::apple

@@ -10,10 +10,10 @@
#include <limits> #include <limits>
#include <memory> #include <memory>
#include "base/apple/call_with_eh_frame.h"
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/mac/call_with_eh_frame.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
@@ -391,7 +391,7 @@ void MessagePumpCFRunLoopBase::RunDelayedWorkTimer(CFRunLoopTimerRef timer,
MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
// The timer fired, assume we have work and let RunWork() figure out what to // The timer fired, assume we have work and let RunWork() figure out what to
// do and what to schedule after. // do and what to schedule after.
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
// It would be incorrect to expect that `self->delayed_work_scheduled_at_` // It would be incorrect to expect that `self->delayed_work_scheduled_at_`
// is smaller than or equal to `TimeTicks::Now()` because the fire date of a // is smaller than or equal to `TimeTicks::Now()` because the fire date of a
// CFRunLoopTimer can be adjusted slightly. // CFRunLoopTimer can be adjusted slightly.
@@ -407,7 +407,7 @@ void MessagePumpCFRunLoopBase::RunDelayedWorkTimer(CFRunLoopTimerRef timer,
// static // static
void MessagePumpCFRunLoopBase::RunWorkSource(void* info) { void MessagePumpCFRunLoopBase::RunWorkSource(void* info) {
MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
self->RunWork(); self->RunWork();
}); });
} }
@@ -474,7 +474,7 @@ void MessagePumpCFRunLoopBase::RunIdleWork() {
// static // static
void MessagePumpCFRunLoopBase::RunNestingDeferredWorkSource(void* info) { void MessagePumpCFRunLoopBase::RunNestingDeferredWorkSource(void* info) {
MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
self->RunNestingDeferredWork(); self->RunNestingDeferredWork();
}); });
} }
@@ -524,7 +524,7 @@ void MessagePumpCFRunLoopBase::PreWaitObserver(CFRunLoopObserverRef observer,
CFRunLoopActivity activity, CFRunLoopActivity activity,
void* info) { void* info) {
MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
// Current work item tracking needs to go away since execution will stop. // Current work item tracking needs to go away since execution will stop.
// Matches the PushWorkItemScope() in AfterWaitObserver() (with an arbitrary // Matches the PushWorkItemScope() in AfterWaitObserver() (with an arbitrary
// amount of matching Pop/Push in between when running work items). // amount of matching Pop/Push in between when running work items).
@@ -550,7 +550,7 @@ void MessagePumpCFRunLoopBase::AfterWaitObserver(CFRunLoopObserverRef observer,
CFRunLoopActivity activity, CFRunLoopActivity activity,
void* info) { void* info) {
MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
// Emerging from sleep, any work happening after this (outside of a // Emerging from sleep, any work happening after this (outside of a
// RunWork()) should be considered native work. Matching PopWorkItemScope() // RunWork()) should be considered native work. Matching PopWorkItemScope()
// is in BeforeWait(). // is in BeforeWait().
@@ -570,7 +570,7 @@ void MessagePumpCFRunLoopBase::PreSourceObserver(CFRunLoopObserverRef observer,
// level did not sleep or exit, nesting-deferred work may have accumulated // level did not sleep or exit, nesting-deferred work may have accumulated
// if a nested loop ran. Schedule nesting-deferred work for processing if // if a nested loop ran. Schedule nesting-deferred work for processing if
// appropriate. // appropriate.
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
self->MaybeScheduleNestingDeferredWork(); self->MaybeScheduleNestingDeferredWork();
}); });
} }
@@ -611,7 +611,7 @@ void MessagePumpCFRunLoopBase::EnterExitObserver(CFRunLoopObserverRef observer,
// to sleep or exiting. It must be called before decrementing the // to sleep or exiting. It must be called before decrementing the
// value so that the value still corresponds to the level of the exiting // value so that the value still corresponds to the level of the exiting
// loop. // loop.
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
self->MaybeScheduleNestingDeferredWork(); self->MaybeScheduleNestingDeferredWork();
}); });
@@ -625,7 +625,7 @@ void MessagePumpCFRunLoopBase::EnterExitObserver(CFRunLoopObserverRef observer,
break; break;
} }
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
self->EnterExitRunLoop(activity); self->EnterExitRunLoop(activity);
}); });
} }

@@ -6,9 +6,9 @@
#include <Carbon/Carbon.h> // for <HIToolbox/Events.h> #include <Carbon/Carbon.h> // for <HIToolbox/Events.h>
#include "base/apple/call_with_eh_frame.h"
#include "base/check.h" #include "base/check.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/mac/call_with_eh_frame.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
@@ -240,11 +240,11 @@ std::string DescriptionForNSEvent(NSEvent* event) {
inMode:(NSString*)mode inMode:(NSString*)mode
dequeue:(BOOL)dequeue { dequeue:(BOOL)dequeue {
__block NSEvent* event = nil; __block NSEvent* event = nil;
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
event = [super nextEventMatchingMask:mask event = [super nextEventMatchingMask:mask
untilDate:expiration untilDate:expiration
inMode:mode inMode:mode
dequeue:dequeue]; dequeue:dequeue];
}); });
return event; return event;
} }
@@ -298,7 +298,7 @@ std::string DescriptionForNSEvent(NSEvent* event) {
crash_reporter::ScopedCrashKeyString scopedKey(&sendActionKey, value); crash_reporter::ScopedCrashKeyString scopedKey(&sendActionKey, value);
__block BOOL rv; __block BOOL rv;
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
rv = [super sendAction:anAction to:aTarget from:sender]; rv = [super sendAction:anAction to:aTarget from:sender];
}); });
return rv; return rv;
@@ -323,7 +323,7 @@ std::string DescriptionForNSEvent(NSEvent* event) {
crash_reporter::ScopedCrashKeyString scopedKey(&nseventKey, crash_reporter::ScopedCrashKeyString scopedKey(&nseventKey,
DescriptionForNSEvent(event)); DescriptionForNSEvent(event));
base::mac::CallWithEHFrame(^{ base::apple::CallWithEHFrame(^{
static const bool kKioskMode = static const bool kKioskMode =
base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode);
if (kKioskMode) { if (kKioskMode) {

@@ -49,7 +49,7 @@ base::debug::TaskAnnotator::RunTask(char const*, base::PendingTask*)
base::MessageLoop::RunTask(base::PendingTask*) base::MessageLoop::RunTask(base::PendingTask*)
base::MessageLoop::DoWork() base::MessageLoop::DoWork()
base::MessagePumpCFRunLoopBase::RunWork() base::MessagePumpCFRunLoopBase::RunWork()
base::mac::CallWithEHFrame(void () block_pointer) base::apple::CallWithEHFrame(void () block_pointer)
base::MessagePumpCFRunLoopBase::RunWorkSource(void*) base::MessagePumpCFRunLoopBase::RunWorkSource(void*)
<???> <???>
<???> <???>
@@ -61,7 +61,7 @@ base::MessagePumpCFRunLoopBase::RunWorkSource(void*)
<???> <???>
<???> <???>
__71-[BrowserCrApplication nextEventMatchingMask:untilDate:inMode:dequeue:]_block_invoke __71-[BrowserCrApplication nextEventMatchingMask:untilDate:inMode:dequeue:]_block_invoke
base::mac::CallWithEHFrame(void () block_pointer) base::apple::CallWithEHFrame(void () block_pointer)
-[BrowserCrApplication nextEventMatchingMask:untilDate:inMode:dequeue:] -[BrowserCrApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
<???> <???>
base::MessagePumpNSApplication::DoRun(base::MessagePump::Delegate*) base::MessagePumpNSApplication::DoRun(base::MessagePump::Delegate*)
@@ -151,7 +151,7 @@ base::debug::TaskAnnotator::RunTask(char const*, base::PendingTask*)
base::MessageLoop::RunTask(base::PendingTask*) base::MessageLoop::RunTask(base::PendingTask*)
base::MessageLoop::DoWork() base::MessageLoop::DoWork()
base::MessagePumpCFRunLoopBase::RunWork() base::MessagePumpCFRunLoopBase::RunWork()
base::mac::CallWithEHFrame(void () block_pointer) base::apple::CallWithEHFrame(void () block_pointer)
base::MessagePumpCFRunLoopBase::RunWorkSource(void*) base::MessagePumpCFRunLoopBase::RunWorkSource(void*)
``` ```