Skip to content

Commit

Permalink
Cherry-pick 99fd778. rdar://123385397
Browse files Browse the repository at this point in the history
    Notify options should be set as early as possible
    https://bugs.webkit.org/show_bug.cgi?id=269850
    rdar://123385397

    Reviewed by Brent Fulgham.

    Notify options should be set as early as possible before any notifications are subscribed to.

    * Source/WebKit/Shared/AuxiliaryProcess.h:
    * Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm:
    (WebKit::AuxiliaryProcess::setNotifyOptions): Deleted.
    * Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
    (WebKit::setNotifyOptions):
    (WebKit::XPCServiceEventHandler):
    (WebKit::XPCServiceMain):
    * Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm:
    (WebKit::tryApplyCachedSandbox):
    (WebKit::compileAndApplySandboxSlowCase):
    (WebKit::applySandbox):
    * Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
    (WebKit::WebProcess::platformInitializeProcess):

    Canonical link: https://commits.webkit.org/275186@main
  • Loading branch information
pvollan authored and Mohsin Qureshi committed Mar 7, 2024
1 parent 460ff24 commit d0d9055
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
2 changes: 0 additions & 2 deletions Source/WebKit/Shared/AuxiliaryProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class AuxiliaryProcess : public IPC::Connection::Client, public IPC::MessageSend
bool parentProcessHasEntitlement(ASCIILiteral entitlement);
#endif

static void setNotifyOptions();

protected:
explicit AuxiliaryProcess();
virtual ~AuxiliaryProcess();
Expand Down
20 changes: 0 additions & 20 deletions Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#import <mach/task.h>
#import <pal/spi/cg/CoreGraphicsSPI.h>
#import <pal/spi/cocoa/NSKeyedUnarchiverSPI.h>
#import <pal/spi/cocoa/NotifySPI.h>
#import <wtf/cocoa/Entitlements.h>
#import <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
#import <wtf/cocoa/SoftLinking.h>
Expand All @@ -59,9 +58,6 @@
SOFT_LINK_OPTIONAL(libAccessibility, _AXSUpdateWebAccessibilitySettings, void, (), ());
#endif

SOFT_LINK_SYSTEM_LIBRARY(libsystem_notify)
SOFT_LINK_OPTIONAL(libsystem_notify, notify_set_options, void, __cdecl, (uint32_t));

namespace WebKit {

#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
Expand Down Expand Up @@ -293,20 +289,4 @@ static void initializeTimerCoalescingPolicy()
}
#endif

void AuxiliaryProcess::setNotifyOptions()
{
uint32_t opts = 0;
#if ENABLE(NOTIFY_FILTERING)
opts |= NOTIFY_OPT_DISPATCH | NOTIFY_OPT_REGEN | NOTIFY_OPT_FILTERED;
#endif
#if ENABLE(NOTIFY_BLOCKING)
opts |= NOTIFY_OPT_LOOPBACK;
#endif
if (!opts)
return;
if (!notify_set_optionsPtr())
return
notify_set_optionsPtr()(opts);
}

} // namespace WebKit
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import <mach/mach.h>
#import <pal/spi/cf/CFUtilitiesSPI.h>
#import <pal/spi/cocoa/LaunchServicesSPI.h>
#import <pal/spi/cocoa/NotifySPI.h>
#import <sys/sysctl.h>
#import <wtf/BlockPtr.h>
#import <wtf/Language.h>
Expand Down Expand Up @@ -103,6 +104,25 @@ static void initializeLogd(bool disableLogging)
RELEASE_LOG(Process, "Initialized logd %s", stringWithSpaces);
}

static void setNotifyOptions()
{
static bool hasSetOptions = false;
if (hasSetOptions)
return;
hasSetOptions = true;

uint32_t opts = 0;
#if ENABLE(NOTIFY_FILTERING)
opts |= NOTIFY_OPT_DISPATCH | NOTIFY_OPT_REGEN | NOTIFY_OPT_FILTERED;
#endif
#if ENABLE(NOTIFY_BLOCKING)
opts |= NOTIFY_OPT_LOOPBACK;
#endif
if (!opts)
return;
notify_set_options(opts);
}

#if PLATFORM(MAC) || PLATFORM(MACCATALYST)

NEVER_INLINE NO_RETURN_DUE_TO_CRASH static void crashDueWebKitFrameworkVersionMismatch()
Expand Down Expand Up @@ -148,6 +168,8 @@ void XPCServiceEventHandler(xpc_connection_t peer)
return;
}
if (!strcmp(messageName, "bootstrap")) {
setNotifyOptions();

bool disableLogging = xpc_dictionary_get_bool(event, "disable-logging");
initializeLogd(disableLogging);

Expand Down Expand Up @@ -228,6 +250,8 @@ void XPCServiceEventHandler(xpc_connection_t peer)

int XPCServiceMain(int, const char**)
{
setNotifyOptions();

auto bootstrap = adoptOSObject(xpc_copy_bootstrap());

if (bootstrap) {
Expand Down
6 changes: 0 additions & 6 deletions Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ static bool tryApplyCachedSandbox(const SandboxInfo& info)
ASSERT(static_cast<void *>(sandboxDataPtr + profile.size) <= static_cast<void *>(cachedSandboxContents.data() + cachedSandboxContents.size()));
profile.data = sandboxDataPtr;

AuxiliaryProcess::setNotifyOptions();

if (sandbox_apply(&profile)) {
WTFLogAlways("%s: Could not apply cached sandbox: %s\n", getprogname(), safeStrerror(errno).data());
return false;
Expand Down Expand Up @@ -541,8 +539,6 @@ static bool compileAndApplySandboxSlowCase(const String& profileOrProfilePath, b
CString temp = isProfilePath ? FileSystem::fileSystemRepresentation(profileOrProfilePath) : profileOrProfilePath.utf8();
uint64_t flags = isProfilePath ? SANDBOX_NAMED_EXTERNAL : 0;

AuxiliaryProcess::setNotifyOptions();

ALLOW_DEPRECATED_DECLARATIONS_BEGIN
if (sandbox_init_with_parameters(temp.data(), flags, parameters.namedParameterArray(), &errorBuf)) {
ALLOW_DEPRECATED_DECLARATIONS_END
Expand Down Expand Up @@ -604,8 +600,6 @@ static bool applySandbox(const AuxiliaryProcessInitializationParameters& paramet
if (!sandboxProfile)
return compileAndApplySandboxSlowCase(profileOrProfilePath, isProfilePath, sandboxInitializationParameters);

AuxiliaryProcess::setNotifyOptions();

if (sandbox_apply(sandboxProfile.get())) {
WTFLogAlways("%s: Could not apply compiled sandbox: %s\n", getprogname(), safeStrerror(errno).data());
CRASH();
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ static void registerLogHook()

void WebProcess::platformInitializeProcess(const AuxiliaryProcessInitializationParameters& parameters)
{
setNotifyOptions();
#if ENABLE(LOGD_BLOCKING_IN_WEBCONTENT)
prewarmLogs();
registerLogHook();
Expand Down

0 comments on commit d0d9055

Please sign in to comment.