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/bundle_locations.h",
"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.mm",
"file_version_info_apple.h",
"file_version_info_apple.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.h",
"mac/foundation_util.h",
@ -3727,8 +3727,8 @@ test("base_unittests") {
sources += [
"allocator/partition_allocator/shim/allocator_interception_mac_unittest.mm",
"allocator/partition_allocator/shim/malloc_zone_functions_mac_unittest.cc",
"apple/call_with_eh_frame_unittest.mm",
"enterprise_util_mac_unittest.mm",
"mac/call_with_eh_frame_unittest.mm",
"mac/dispatch_source_mach_unittest.cc",
"mac/launch_application_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
// 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 <unwind.h>
#include "build/build_config.h"
namespace base::mac {
namespace base::apple {
#if defined(__x86_64__) || defined(__aarch64__)
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,
exception_object, context);
}
#else // !defined(__x86_64__) && !defined(__aarch64__)
#else // !defined(__x86_64__) && !defined(__aarch64__)
// No implementation exists, so just call the block directly.
void CallWithEHFrame(void (^block)(void)) {
block();
}
#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
// found in the LICENSE file.
#ifndef BASE_MAC_CALL_WITH_EH_FRAME_H_
#define BASE_MAC_CALL_WITH_EH_FRAME_H_
#ifndef BASE_APPLE_CALL_WITH_EH_FRAME_H_
#define BASE_APPLE_CALL_WITH_EH_FRAME_H_
#include "base/base_export.h"
namespace base::mac {
namespace base::apple {
// Invokes the specified block in a stack frame with a special exception
// 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.
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__)
// base::mac::CallWithEHFrame(void () block_pointer)
#define CALL_WITH_EH_FRAME __ZN4base3mac15CallWithEHFrameEU13block_pointerFvvE
// base::apple::CallWithEHFrame(void () block_pointer)
#define CALL_WITH_EH_FRAME __ZN4base5apple15CallWithEHFrameEU13block_pointerFvvE
.section __TEXT,__text,regular,pure_instructions
#if !defined(COMPONENT_BUILD)
@ -20,7 +20,7 @@ CALL_WITH_EH_FRAME:
// Configure the C++ exception handler personality routine. Normally the
// compiler would emit ___gxx_personality_v0 here. The purpose of this
// 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
#if defined(__x86_64__)

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

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

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

@ -49,7 +49,7 @@ base::debug::TaskAnnotator::RunTask(char const*, base::PendingTask*)
base::MessageLoop::RunTask(base::PendingTask*)
base::MessageLoop::DoWork()
base::MessagePumpCFRunLoopBase::RunWork()
base::mac::CallWithEHFrame(void () block_pointer)
base::apple::CallWithEHFrame(void () block_pointer)
base::MessagePumpCFRunLoopBase::RunWorkSource(void*)
<???>
<???>
@ -61,7 +61,7 @@ base::MessagePumpCFRunLoopBase::RunWorkSource(void*)
<???>
<???>
__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:]
<???>
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::DoWork()
base::MessagePumpCFRunLoopBase::RunWork()
base::mac::CallWithEHFrame(void () block_pointer)
base::apple::CallWithEHFrame(void () block_pointer)
base::MessagePumpCFRunLoopBase::RunWorkSource(void*)
```