ProcessLauncherPlayStation.cpp [plain text]
#include "config.h"
#include "ProcessLauncher.h"
#include <process-launcher.h>
#include <stdint.h>
#include <sys/socket.h>
namespace WebKit {
#define MAKE_PROCESS_PATH(x) "/app0/" #x "Process.self"
static const char* defaultProcessPath(ProcessLauncher::ProcessType processType)
{
switch (processType) {
case ProcessLauncher::ProcessType::Network:
return MAKE_PROCESS_PATH(Network);
#if ENABLE(GPU_PROCESS)
case ProcessLauncher::ProcessType::GPU:
return MAKE_PROCESS_PATH(GPU);
#endif
case ProcessLauncher::ProcessType::Web:
default:
return MAKE_PROCESS_PATH(Web);
}
}
void ProcessLauncher::launchProcess()
{
IPC::Connection::Identifier serverIdentifier;
IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection(IPC::Connection::ConnectionOptions::SetCloexecOnServer);
int sendBufSize = 32 * 1024;
setsockopt(socketPair.server, SOL_SOCKET, SO_SNDBUF, &sendBufSize, 4);
setsockopt(socketPair.client, SOL_SOCKET, SO_SNDBUF, &sendBufSize, 4);
int recvBufSize = 32 * 1024;
setsockopt(socketPair.server, SOL_SOCKET, SO_RCVBUF, &recvBufSize, 4);
setsockopt(socketPair.client, SOL_SOCKET, SO_RCVBUF, &recvBufSize, 4);
char coreProcessIdentifierString[16];
snprintf(coreProcessIdentifierString, sizeof coreProcessIdentifierString, "%ld", m_launchOptions.processIdentifier.toUInt64());
char* argv[] = {
coreProcessIdentifierString,
nullptr
};
PlayStation::LaunchParam param { socketPair.client, m_launchOptions.userId };
int32_t appLocalPid = PlayStation::launchProcess(
!m_launchOptions.processPath.isEmpty() ? m_launchOptions.processPath.utf8().data() : defaultProcessPath(m_launchOptions.processType),
argv, param);
if (appLocalPid < 0) {
#ifndef NDEBUG
fprintf(stderr, "Failed to launch process. err=0x%08x path=%s\n", appLocalPid, m_launchOptions.processPath.utf8().data());
#endif
return;
}
close(socketPair.client);
serverIdentifier = socketPair.server;
RefPtr<ProcessLauncher> protectedThis(this);
RunLoop::main().dispatch([=] {
protectedThis->didFinishLaunchingProcess(appLocalPid, serverIdentifier);
});
}
void ProcessLauncher::terminateProcess()
{
if (!m_processIdentifier)
return;
PlayStation::terminateProcess(m_processIdentifier);
}
void ProcessLauncher::platformInvalidate()
{
m_processIdentifier = 0;
}
}