Changeset 241197 in webkit


Ignore:
Timestamp:
Feb 8, 2019 9:18:08 AM (5 years ago)
Author:
achristensen@apple.com
Message:

Add SPI to use networking daemon instead of XPC service
https://bugs.webkit.org/show_bug.cgi?id=194427

Reviewed by Geoffrey Garen.

Source/WebKit:

There is still work to be done, but with the proper plist it starts and loads webpages!

  • NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm:

(WebKit::DaemonMain):

  • Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h:
  • Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:

(WebKit::XPCEventHandler):
(WebKit::XPCInitializationHandler):
(WebKit::XPCServiceMain):
(WebKit::XPCServiceEventHandler): Deleted.

  • UIProcess/API/APIProcessPoolConfiguration.h:
  • UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
  • UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:

(-[_WKProcessPoolConfiguration usesNetworkingDaemon]):
(-[_WKProcessPoolConfiguration setUsesNetworkingDaemon:]):

  • UIProcess/AuxiliaryProcessProxy.cpp:

(WebKit::AuxiliaryProcessProxy::getLaunchOptions):

  • UIProcess/Launcher/ProcessLauncher.h:
  • UIProcess/Launcher/mac/ProcessLauncherMac.mm:

(WebKit::serviceName):
(WebKit::ProcessLauncher::launchProcess):

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::getLaunchOptions):

  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::usesNetworkingDaemon const):

  • UIProcess/WebProcessPool.h:

Source/WTF:

  • wtf/spi/darwin/XPCSPI.h:

Instead of using XPC bootstrap SPI, we just send a separate message.
xpc_copy_bootstrap does not seem to work in daemons.

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r241192 r241197  
     12019-02-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to use networking daemon instead of XPC service
     4        https://bugs.webkit.org/show_bug.cgi?id=194427
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * wtf/spi/darwin/XPCSPI.h:
     9        Instead of using XPC bootstrap SPI, we just send a separate message.
     10        xpc_copy_bootstrap does not seem to work in  daemons.
     11
    1122019-02-08  Benjamin Poulain  <benjamin@webkit.org>
    213
  • trunk/Source/WTF/wtf/spi/darwin/XPCSPI.h

    r237266 r241197  
    153153void xpc_dictionary_set_mach_send(xpc_object_t, const char*, mach_port_t);
    154154
    155 void xpc_connection_set_bootstrap(xpc_connection_t, xpc_object_t bootstrap);
    156 xpc_object_t xpc_copy_bootstrap(void);
    157155void xpc_connection_set_oneshot_instance(xpc_connection_t, uuid_t instance);
    158156
     
    182180
    183181WTF_EXTERN_C_END
     182
     183#define XPC_CONNECTION_MACH_SERVICE_LISTENER (1 << 0)
  • trunk/Source/WebKit/ChangeLog

    r241191 r241197  
     12019-02-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to use networking daemon instead of XPC service
     4        https://bugs.webkit.org/show_bug.cgi?id=194427
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        There is still work to be done, but with the proper plist it starts and loads webpages!
     9
     10        * NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm:
     11        (WebKit::DaemonMain):
     12        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h:
     13        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
     14        (WebKit::XPCEventHandler):
     15        (WebKit::XPCInitializationHandler):
     16        (WebKit::XPCServiceMain):
     17        (WebKit::XPCServiceEventHandler): Deleted.
     18        * UIProcess/API/APIProcessPoolConfiguration.h:
     19        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
     20        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
     21        (-[_WKProcessPoolConfiguration usesNetworkingDaemon]):
     22        (-[_WKProcessPoolConfiguration setUsesNetworkingDaemon:]):
     23        * UIProcess/AuxiliaryProcessProxy.cpp:
     24        (WebKit::AuxiliaryProcessProxy::getLaunchOptions):
     25        * UIProcess/Launcher/ProcessLauncher.h:
     26        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     27        (WebKit::serviceName):
     28        (WebKit::ProcessLauncher::launchProcess):
     29        * UIProcess/Network/NetworkProcessProxy.cpp:
     30        (WebKit::NetworkProcessProxy::getLaunchOptions):
     31        * UIProcess/WebProcessPool.cpp:
     32        (WebKit::WebProcessPool::usesNetworkingDaemon const):
     33        * UIProcess/WebProcessPool.h:
     34
    1352019-02-08  Keith Rollin  <krollin@apple.com>
    236
  • trunk/Source/WebKit/NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm

    r240973 r241197  
    2727#import "DaemonEntryPoint.h"
    2828
     29#import "XPCServiceEntryPoint.h"
     30#import <wtf/spi/darwin/XPCSPI.h>
     31
    2932namespace WebKit {
     33   
     34int DaemonMain(int argc, const char** argv)
     35{
     36    if (argc < 2 || strcmp(argv[1], "WebKitNetworkingDaemon")) {
     37        WTFLogAlways("Unexpected daemon parameters");
     38        return EXIT_FAILURE;
     39    }
    3040
    31 int DaemonMain(int, const char**)
    32 {
    33     return 0;
     41    xpc_connection_t listener = xpc_connection_create_mach_service("com.apple.WebKit.NetworkingDaemon", dispatch_get_main_queue(), XPC_CONNECTION_MACH_SERVICE_LISTENER);
     42   
     43    xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) {
     44        if (!peer || xpc_get_type(peer) != XPC_TYPE_CONNECTION) {
     45            WTFLogAlways("Unexpected XPC object");
     46            return;
     47        }
     48
     49        XPCEventHandler(peer, AuxiliaryProcessType::Daemon);
     50    });
     51
     52    xpc_connection_resume(listener);
     53    CFRunLoopRun();
     54
     55    return EXIT_SUCCESS;
    3456}
    3557
  • trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h

    r240683 r241197  
    131131int XPCServiceMain(int, const char**);
    132132
     133enum class AuxiliaryProcessType { Daemon, XPCService };
     134void XPCEventHandler(xpc_connection_t, AuxiliaryProcessType);
     135
    133136void XPCServiceExit(OSObjectPtr<xpc_object_t>&& priorityBoostMessage);
    134137
  • trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm

    r240956 r241197  
    3939namespace WebKit {
    4040
    41 static void XPCServiceEventHandler(xpc_connection_t peer)
     41void XPCInitializationHandler(xpc_object_t);
     42
     43void XPCEventHandler(xpc_connection_t peer, AuxiliaryProcessType processType)
    4244{
    4345    static xpc_object_t priorityBoostMessage = nullptr;
     
    4850        if (type == XPC_TYPE_ERROR) {
    4951            if (event == XPC_ERROR_CONNECTION_INVALID || event == XPC_ERROR_TERMINATION_IMMINENT) {
    50                 // FIXME: Handle this case more gracefully.
    51                 exit(EXIT_FAILURE);
     52                if (processType == AuxiliaryProcessType::XPCService) {
     53                    // FIXME: Handle this case more gracefully.
     54                    exit(EXIT_FAILURE);
     55                } else {
     56                    // FIXME: Deref the NetworkProcess object associated with this xpc connection
     57                    // once we have a container for such objects.
     58                }
    5259            }
    5360        } else {
     
    5562
    5663            if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "bootstrap")) {
     64                XPCInitializationHandler(xpc_dictionary_get_value(event, "initialization-message"));
     65               
    5766                CFBundleRef webKitBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"));
    5867                CFStringRef entryPointFunctionName = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR("WebKitEntryPoint"));
     
    93102}
    94103
    95 int XPCServiceMain(int, const char**)
     104void XPCInitializationHandler(xpc_object_t event)
    96105{
     106    ASSERT(event);
     107    ASSERT(xpc_get_type(event) == XPC_TYPE_DICTIONARY);
    97108#if defined(__i386__)
    98109    // FIXME: This should only be done for the 32-bit plug-in XPC service so we rely on the fact that
     
    105116#endif
    106117
    107     auto bootstrap = adoptOSObject(xpc_copy_bootstrap());
    108118#if PLATFORM(IOS_FAMILY)
    109     auto containerEnvironmentVariables = xpc_dictionary_get_value(bootstrap.get(), "ContainerEnvironmentVariables");
     119    auto containerEnvironmentVariables = xpc_dictionary_get_value(event, "ContainerEnvironmentVariables");
    110120    xpc_dictionary_apply(containerEnvironmentVariables, ^(const char *key, xpc_object_t value) {
    111121        setenv(key, xpc_string_get_string_ptr(value), 1);
     
    114124#endif
    115125
    116     if (bootstrap) {
    117126#if PLATFORM(MAC)
    118         if (const char* webKitBundleVersion = xpc_dictionary_get_string(bootstrap.get(), "WebKitBundleVersion")) {
    119             CFBundleRef webKitBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"));
    120             NSString *expectedBundleVersion = (NSString *)CFBundleGetValueForInfoDictionaryKey(webKitBundle, kCFBundleVersionKey);
     127    if (const char* webKitBundleVersion = xpc_dictionary_get_string(event, "WebKitBundleVersion")) {
     128        CFBundleRef webKitBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"));
     129        NSString *expectedBundleVersion = (NSString *)CFBundleGetValueForInfoDictionaryKey(webKitBundle, kCFBundleVersionKey);
    121130
    122             if (strcmp(webKitBundleVersion, expectedBundleVersion.UTF8String)) {
    123                 _WKSetCrashReportApplicationSpecificInformation([NSString stringWithFormat:@"WebKit framework version mismatch: '%s'", webKitBundleVersion]);
    124                 __builtin_trap();
    125             }
     131        if (strcmp(webKitBundleVersion, expectedBundleVersion.UTF8String)) {
     132            _WKSetCrashReportApplicationSpecificInformation([NSString stringWithFormat:@"WebKit framework version mismatch: '%s'", webKitBundleVersion]);
     133            __builtin_trap();
    126134        }
     135    }
    127136#endif
    128137
    129         if (xpc_object_t languages = xpc_dictionary_get_value(bootstrap.get(), "OverrideLanguages")) {
    130             @autoreleasepool {
    131                 NSDictionary *existingArguments = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain];
    132                 NSMutableDictionary *newArguments = [existingArguments mutableCopy];
    133                 RetainPtr<NSMutableArray> newLanguages = adoptNS([[NSMutableArray alloc] init]);
    134                 xpc_array_apply(languages, ^(size_t index, xpc_object_t value) {
    135                     [newLanguages addObject:[NSString stringWithCString:xpc_string_get_string_ptr(value) encoding:NSUTF8StringEncoding]];
    136                     return true;
    137                 });
    138                 [newArguments setValue:newLanguages.get() forKey:@"AppleLanguages"];
    139                 [[NSUserDefaults standardUserDefaults] setVolatileDomain:newArguments forName:NSArgumentDomain];
    140             }
     138    if (xpc_object_t languages = xpc_dictionary_get_value(event, "OverrideLanguages")) {
     139        @autoreleasepool {
     140            NSDictionary *existingArguments = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain];
     141            NSMutableDictionary *newArguments = [existingArguments mutableCopy];
     142            RetainPtr<NSMutableArray> newLanguages = adoptNS([[NSMutableArray alloc] init]);
     143            xpc_array_apply(languages, ^(size_t index, xpc_object_t value) {
     144                [newLanguages addObject:[NSString stringWithCString:xpc_string_get_string_ptr(value) encoding:NSUTF8StringEncoding]];
     145                return true;
     146            });
     147            [newArguments setValue:newLanguages.get() forKey:@"AppleLanguages"];
     148            [[NSUserDefaults standardUserDefaults] setVolatileDomain:newArguments forName:NSArgumentDomain];
    141149        }
    142150    }
     
    154162#endif
    155163#endif
     164}
    156165
    157     xpc_main(XPCServiceEventHandler);
     166int XPCServiceMain(int, const char**)
     167{
     168    xpc_main([] (xpc_connection_t peer) {
     169        XPCEventHandler(peer, AuxiliaryProcessType::XPCService);
     170    });
    158171    return 0;
    159172}
  • trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h

    r240363 r241197  
    183183    bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
    184184    void setSuppressesConnectionTerminationOnSystemChange(bool suppressesConnectionTerminationOnSystemChange) { m_suppressesConnectionTerminationOnSystemChange = suppressesConnectionTerminationOnSystemChange; }
     185
     186    bool usesNetworkingDaemon() const { return m_usesNetworkingDaemon; }
     187    void setUsesNetworkingDaemon(bool usesNetworkingDaemon) { m_usesNetworkingDaemon = usesNetworkingDaemon; }
    185188#endif
    186189
     
    236239#if PLATFORM(COCOA)
    237240    bool m_suppressesConnectionTerminationOnSystemChange { false };
     241    bool m_usesNetworkingDaemon { false };
    238242#endif
    239243};
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h

    r240363 r241197  
    7171@property (nonatomic) BOOL suppressesConnectionTerminationOnSystemChange WK_API_AVAILABLE(macosx(10.14), ios(12.0));
    7272@property (nonatomic, getter=isJITEnabled) BOOL JITEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     73@property (nonatomic) BOOL usesNetworkingDaemon WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    7374
    7475@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm

    r240363 r241197  
    317317}
    318318
     319- (BOOL)usesNetworkingDaemon
     320{
     321    return _processPoolConfiguration->usesNetworkingDaemon();
     322}
     323
     324- (void)setUsesNetworkingDaemon:(BOOL)enabled
     325{
     326    _processPoolConfiguration->setUsesNetworkingDaemon(enabled);
     327}
     328
     329
    319330- (void)setSuppressesConnectionTerminationOnSystemChange:(BOOL)suppressesConnectionTerminationOnSystemChange
    320331{
  • trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp

    r240683 r241197  
    7373        varname = "NETWORK_PROCESS_CMD_PREFIX";
    7474        break;
     75    case ProcessLauncher::ProcessType::NetworkDaemon:
     76        ASSERT_NOT_REACHED();
    7577    }
    7678    const char* processCmdPrefix = getenv(varname);
  • trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h

    r240640 r241197  
    6666#endif
    6767        Network,
     68        NetworkDaemon
    6869    };
    6970
  • trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r238388 r241197  
    5757    case ProcessLauncher::ProcessType::Network:
    5858        return "com.apple.WebKit.Networking";
     59    case ProcessLauncher::ProcessType::NetworkDaemon:
     60        ASSERT_NOT_REACHED();
     61        return nullptr;
    5962#if ENABLE(NETSCAPE_PLUGIN_API)
    6063    case ProcessLauncher::ProcessType::Plugin32:
     
    9699    ASSERT(!m_xpcConnection);
    97100
    98     const char* name;
    99     if (!m_launchOptions.customWebContentServiceBundleIdentifier.isNull())
    100         name = m_launchOptions.customWebContentServiceBundleIdentifier.data();
    101     else
    102         name = serviceName(m_launchOptions);
    103 
    104     m_xpcConnection = adoptOSObject(xpc_connection_create(name, nullptr));
    105 
    106     uuid_t uuid;
    107     uuid_generate(uuid);
    108     xpc_connection_set_oneshot_instance(m_xpcConnection.get(), uuid);
     101    if (m_launchOptions.processType == ProcessLauncher::ProcessType::NetworkDaemon)
     102        m_xpcConnection = adoptOSObject(xpc_connection_create_mach_service("com.apple.WebKit.NetworkingDaemon", dispatch_get_main_queue(), 0));
     103    else {
     104        const char* name = m_launchOptions.customWebContentServiceBundleIdentifier.isNull() ? serviceName(m_launchOptions) : m_launchOptions.customWebContentServiceBundleIdentifier.data();
     105        m_xpcConnection = adoptOSObject(xpc_connection_create(name, nullptr));
     106
     107        uuid_t uuid;
     108        uuid_generate(uuid);
     109        xpc_connection_set_oneshot_instance(m_xpcConnection.get(), uuid);
     110    }
    109111
    110112    // Inherit UI process localization. It can be different from child process default localization:
     
    137139    xpc_dictionary_set_string(initializationMessage.get(), "WebKitBundleVersion", [[NSBundle bundleWithIdentifier:@"com.apple.WebKit"].infoDictionary[(__bridge NSString *)kCFBundleVersionKey] UTF8String]);
    138140#endif
    139     xpc_connection_set_bootstrap(m_xpcConnection.get(), initializationMessage.get());
    140141
    141142    if (shouldLeakBoost(m_launchOptions)) {
     
    172173        clientIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    173174
    174     // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
    175175    auto bootstrapMessage = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
     176
     177    xpc_dictionary_set_value(bootstrapMessage.get(), "initialization-message", initializationMessage.get());
    176178   
    177179    if (m_client && !m_client->isJITEnabled())
     
    201203    auto errorHandlerImpl = [weakProcessLauncher = makeWeakPtr(*this), listeningPort] (xpc_object_t event) {
    202204        ASSERT(!event || xpc_get_type(event) == XPC_TYPE_ERROR);
     205
     206        if (event)
     207            LOG_ERROR("Error launching auxiliary process: %s", xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
    203208
    204209        auto processLauncher = weakProcessLauncher.get();
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r240687 r241197  
    103103void NetworkProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions)
    104104{
    105     launchOptions.processType = ProcessLauncher::ProcessType::Network;
     105    launchOptions.processType = m_processPool.usesNetworkingDaemon() ? ProcessLauncher::ProcessType::NetworkDaemon : ProcessLauncher::ProcessType::Network;
    106106    AuxiliaryProcessProxy::getLaunchOptions(launchOptions);
    107107
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r240725 r241197  
    15081508}
    15091509
     1510bool WebProcessPool::usesNetworkingDaemon() const
     1511{
     1512#if PLATFORM(COCOA)
     1513    return m_configuration->usesNetworkingDaemon();
     1514#else
     1515    return false;
     1516#endif
     1517}
     1518   
    15101519void WebProcessPool::setCacheModel(CacheModel cacheModel)
    15111520{
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r240725 r241197  
    256256    API::DownloadClient& downloadClient() { return *m_downloadClient; }
    257257
     258    bool usesNetworkingDaemon() const;
     259   
    258260    API::LegacyContextHistoryClient& historyClient() { return *m_historyClient; }
    259261    WebContextClient& client() { return m_client; }
Note: See TracChangeset for help on using the changeset viewer.