Changeset 150595 in webkit


Ignore:
Timestamp:
May 23, 2013 11:03:02 AM (11 years ago)
Author:
barraclough@apple.com
Message:

Move posix_spawn onto a zero delay timer
https://bugs.webkit.org/show_bug.cgi?id=116682

Reviewed by Anders Carlson.

<rdar://problem/13973468>

  • Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm:

(ReexecInfo):

  • struct to hold info from the XPC message.

(WebKit::reexec):

  • moved call to posix_spawn out to this helper.

(WebKit::reexecCallBack):

  • calls reexec.

(WebKit::XPCServiceEventHandler):

  • removed call to posix_spawn; schedule a call to reexecCallBack.
Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r150583 r150595  
     12013-05-23  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Move posix_spawn onto a zero delay timer
     4        https://bugs.webkit.org/show_bug.cgi?id=116682
     5
     6        Reviewed by Anders Carlson.
     7
     8        <rdar://problem/13973468>
     9
     10        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm:
     11        (ReexecInfo):
     12            - struct to hold info from the XPC message.
     13        (WebKit::reexec):
     14            - moved call to posix_spawn out to this helper.
     15        (WebKit::reexecCallBack):
     16            - calls reexec.
     17        (WebKit::XPCServiceEventHandler):
     18            - removed call to posix_spawn; schedule a call to reexecCallBack.
     19
    1202013-05-23  Csaba Osztrogonác  <ossy@webkit.org>
    221
  • trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm

    r144409 r150595  
    3434namespace WebKit {
    3535
     36struct ReexecInfo {
     37    bool executableHeap;
     38    char** environment;
     39    cpu_type_t cpuType;
     40};
     41
     42static NO_RETURN void reexec(ReexecInfo *info)
     43{
     44    posix_spawnattr_t attr;
     45    posix_spawnattr_init(&attr);
     46
     47    short flags = 0;
     48
     49    // We just want to set the process state, not actually launch a new process,
     50    // so we are going to use the darwin extension to posix_spawn POSIX_SPAWN_SETEXEC
     51    // to act like a more full featured exec.
     52    flags |= POSIX_SPAWN_SETEXEC;
     53
     54    sigset_t signalMaskSet;
     55    sigemptyset(&signalMaskSet);
     56    posix_spawnattr_setsigmask(&attr, &signalMaskSet);
     57    flags |= POSIX_SPAWN_SETSIGMASK;
     58
     59    static const int allowExecutableHeapFlag = 0x2000;
     60    if (info->executableHeap)
     61        flags |= allowExecutableHeapFlag;
     62
     63    posix_spawnattr_setflags(&attr, flags);
     64
     65    size_t outCount = 0;
     66    posix_spawnattr_setbinpref_np(&attr, 1, &info->cpuType, &outCount);
     67
     68    char path[4 * PATH_MAX];
     69    uint32_t pathLength = sizeof(path);
     70    _NSGetExecutablePath(path, &pathLength);
     71
     72    char** argv = *_NSGetArgv();
     73    const char* programName = argv[0];
     74    const char* args[] = { programName, 0 };
     75
     76    pid_t processIdentifier = 0;
     77    posix_spawn(&processIdentifier, path, 0, &attr, const_cast<char**>(args), info->environment);
     78
     79    posix_spawnattr_destroy(&attr);
     80
     81    NSLog(@"Unable to re-exec for path: %s", path);
     82    exit(EXIT_FAILURE);
     83}
     84
     85static NO_RETURN void reexecCallBack(CFRunLoopTimerRef timer, void *info)
     86{
     87    reexec(static_cast<ReexecInfo *>(info));
     88}
     89
    3690static void XPCServiceEventHandler(xpc_connection_t peer)
    3791{
     
    48102
    49103            if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "re-exec")) {
    50                 posix_spawnattr_t attr;
    51                 posix_spawnattr_init(&attr);
     104                ReexecInfo *info = static_cast<ReexecInfo *>(malloc(sizeof(ReexecInfo)));
    52105
    53                 short flags = 0;
    54 
    55                 // We just want to set the process state, not actually launch a new process,
    56                 // so we are going to use the darwin extension to posix_spawn POSIX_SPAWN_SETEXEC
    57                 // to act like a more full featured exec.
    58                 flags |= POSIX_SPAWN_SETEXEC;
    59 
    60                 sigset_t signalMaskSet;
    61                 sigemptyset(&signalMaskSet);
    62                 posix_spawnattr_setsigmask(&attr, &signalMaskSet);
    63                 flags |= POSIX_SPAWN_SETSIGMASK;
    64 
    65                 static const int allowExecutableHeapFlag = 0x2000;
    66                 if (xpc_dictionary_get_bool(event, "executable-heap"))
    67                     flags |= allowExecutableHeapFlag;
    68 
    69                 posix_spawnattr_setflags(&attr, flags);
    70 
    71                 cpu_type_t cpuTypes[] = { (cpu_type_t)xpc_dictionary_get_uint64(event, "architecture") };
    72                 size_t outCount = 0;
    73                 posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
    74 
    75                 char path[4 * PATH_MAX];
    76                 uint32_t pathLength = sizeof(path);
    77                 _NSGetExecutablePath(path, &pathLength);
    78 
    79                 char** argv = *_NSGetArgv();
    80                 const char* programName = argv[0];
    81                 const char* args[] = { programName, 0 };
     106                info->executableHeap = xpc_dictionary_get_bool(event, "executable-heap");
     107                info->cpuType = (cpu_type_t)xpc_dictionary_get_uint64(event, "architecture");
    82108
    83109                xpc_object_t environmentArray = xpc_dictionary_get_value(event, "environment");
    84110                size_t numberOfEnvironmentVariables = xpc_array_get_count(environmentArray);
     111                char** environment = static_cast<char **>(malloc(numberOfEnvironmentVariables * sizeof(char*) + 1));
     112                for (size_t i = 0; i < numberOfEnvironmentVariables; ++i)
     113                    environment[i] = strdup(xpc_array_get_string(environmentArray, i));
     114                environment[numberOfEnvironmentVariables] = 0;
     115                info->environment = environment;
    85116
    86                 const char** environment = (const char**)malloc(numberOfEnvironmentVariables * sizeof(char*) + 1);
    87                 for (size_t i = 0; i < numberOfEnvironmentVariables; ++i)
    88                     environment[i] = xpc_array_get_string(environmentArray, i);
    89                 environment[numberOfEnvironmentVariables] = 0;
    90 
    91                 pid_t processIdentifier = 0;
    92                 posix_spawn(&processIdentifier, path, 0, &attr, const_cast<char**>(args), const_cast<char**>(environment));
    93 
    94                 posix_spawnattr_destroy(&attr);
    95 
    96                 NSLog(@"Unable to re-exec for path: %s", path);
    97                 exit(EXIT_FAILURE);
     117                CFRunLoopTimerContext context = { 0, info, NULL, NULL, NULL };
     118                CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), 0, 0, 0, reexecCallBack, &context);
     119                CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
    98120            }
    99121
Note: See TracChangeset for help on using the changeset viewer.