Commit 2b720d21 authored by hidehiko's avatar hidehiko Committed by Commit bot

Non-SFI Mode: Build base/ library by PNaCL toolchain for nacl_helper_nonsfi.

This CL is to build base/ for nacl_helper_nonsfi.
The library is similar to base_nacl, but slightly different:
- For rand_util, rand_util_posix should be used, instead of
  rand_util_nacl, because nacl_helper_nonsfi will be running under
  Linux directly.
- MessageLoopForIO should be based on MessagePumpLibevent rather than
  MessagePumpDefault, to support IPC.
- GetKnownDeadTerminationStatus, GetTerminationStatus,
  UnixDomainSocket::SendMsg and RecvMsg are included, as these are used
  to implement nacl_helper_nonsfi binary.
- GLIB is not supported. It is unnecessary for nacl_helper_nonsfi.
Note that this library is not used yet from any binary, because this CL
is just a preparation, but the library is built actually.

BUG=358465
TEST=Ran trybot. Implement nacl_helper_nonsfi on top of this CL, and made sure
it is working.

Review URL: https://codereview.chromium.org/659513004

Cr-Commit-Position: refs/heads/master@{#300075}
parent 3e04b7b0
......@@ -67,5 +67,60 @@
},
],
}],
['disable_nacl==0', {
'targets': [
{
'target_name': 'base_nacl_nonsfi',
'type': 'none',
'include_dirs': [
'<(DEPTH)/native_client/src/public/linux_syscalls',
],
'variables': {
'base_target': 1,
'nacl_untrusted_build': 1,
'nlib_target': 'libbase_nacl_nonsfi.a',
'build_glibc': 0,
'build_newlib': 0,
'build_irt': 0,
'build_pnacl_newlib': 0,
'build_nonsfi_helper': 1,
'sources': [
'base_switches.cc',
'base_switches.h',
# For PathExists and ReadFromFD.
'files/file_util_posix.cc',
# For MessageLoopForIO based on libevent.
'message_loop/message_pump_libevent.cc',
'message_loop/message_pump_libevent.h',
# For UnixDomainSocket::SendMsg and RecvMsg.
'posix/unix_domain_socket_linux.cc',
# For GetKnownDeadTerminationStatus and GetTerminationStatus.
'process/kill_posix.cc',
# Unlike libbase_nacl, for Non-SFI build, we need to use
# rand_util_posix for random implementation, instead of
# rand_util_nacl.cc, which is based on IRT. rand_util_nacl.cc is
# excluded below.
'rand_util_posix.cc',
# For CancelableSyncSocket.
'sync_socket_nacl.cc',
],
},
'sources!': [
'rand_util_nacl.cc',
],
'dependencies': [
'<(DEPTH)/native_client/tools.gyp:prep_toolchain',
'<(DEPTH)/third_party/libevent/libevent_nacl_nonsfi.gyp:event_nacl_nonsfi',
],
},
],
}],
],
}
......@@ -59,6 +59,7 @@
namespace base {
#if !defined(__native_client_nonsfi__)
namespace {
#if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)
......@@ -345,6 +346,7 @@ bool CopyDirectory(const FilePath& from_path,
return success;
}
#endif // !defined(__native_client_nonsfi__)
bool PathExists(const FilePath& path) {
ThreadRestrictions::AssertIOAllowed();
......@@ -356,6 +358,7 @@ bool PathExists(const FilePath& path) {
return access(path.value().c_str(), F_OK) == 0;
}
#if !defined(__native_client_nonsfi__)
bool PathIsWritable(const FilePath& path) {
ThreadRestrictions::AssertIOAllowed();
return access(path.value().c_str(), W_OK) == 0;
......@@ -368,6 +371,7 @@ bool DirectoryExists(const FilePath& path) {
return S_ISDIR(file_info.st_mode);
return false;
}
#endif // !defined(__native_client_nonsfi__)
bool ReadFromFD(int fd, char* buffer, size_t bytes) {
size_t total_read = 0;
......@@ -381,6 +385,7 @@ bool ReadFromFD(int fd, char* buffer, size_t bytes) {
return total_read == bytes;
}
#if !defined(__native_client_nonsfi__)
bool CreateSymbolicLink(const FilePath& target_path,
const FilePath& symlink_path) {
DCHECK(!symlink_path.empty());
......@@ -920,4 +925,6 @@ bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) {
#endif // !defined(OS_MACOSX)
} // namespace internal
#endif // !defined(__native_client_nonsfi__)
} // namespace base
......@@ -100,7 +100,7 @@ bool AlwaysNotifyPump(MessageLoop::Type type) {
#if defined(OS_IOS)
typedef MessagePumpIOSForIO MessagePumpForIO;
#elif defined(OS_NACL)
#elif defined(OS_NACL) && !defined(__native_client_nonsfi__)
typedef MessagePumpDefault MessagePumpForIO;
#elif defined(OS_POSIX)
typedef MessagePumpLibevent MessagePumpForIO;
......@@ -676,7 +676,7 @@ bool MessageLoopForUI::WatchFileDescriptor(
//------------------------------------------------------------------------------
// MessageLoopForIO
#if !defined(OS_NACL)
#if !defined(OS_NACL) || defined(__native_client_nonsfi__)
void MessageLoopForIO::AddIOObserver(
MessageLoopForIO::IOObserver* io_observer) {
ToPumpIO(pump_.get())->AddIOObserver(io_observer);
......@@ -714,6 +714,6 @@ bool MessageLoopForIO::WatchFileDescriptor(int fd,
}
#endif
#endif // !defined(OS_NACL)
#endif // !defined(OS_NACL) || defined(__native_client_nonsfi__)
} // namespace base
......@@ -596,7 +596,7 @@ class BASE_EXPORT MessageLoopForIO : public MessageLoop {
return loop && loop->type() == MessageLoop::TYPE_IO;
}
#if !defined(OS_NACL)
#if !defined(OS_NACL) || defined(__native_client_nonsfi__)
#if defined(OS_WIN)
typedef MessagePumpForIO::IOHandler IOHandler;
......@@ -642,7 +642,7 @@ class BASE_EXPORT MessageLoopForIO : public MessageLoop {
FileDescriptorWatcher *controller,
Watcher *delegate);
#endif // defined(OS_IOS) || defined(OS_POSIX)
#endif // !defined(OS_NACL)
#endif // !defined(OS_NACL) || defined(__native_client_nonsfi__)
};
// Do not add any member variables to MessageLoopForIO! This is important b/c
......
......@@ -6,7 +6,6 @@
#include <errno.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <unistd.h>
#include <vector>
......@@ -18,8 +17,13 @@
#include "base/posix/eintr_wrapper.h"
#include "base/stl_util.h"
#if !defined(__native_client_nonsfi__)
#include <sys/uio.h>
#endif
const size_t UnixDomainSocket::kMaxFileDescriptors = 16;
#if !defined(__native_client_nonsfi__)
// Creates a connected pair of UNIX-domain SOCK_SEQPACKET sockets, and passes
// ownership of the newly allocated file descriptors to |one| and |two|.
// Returns true on success.
......@@ -37,6 +41,7 @@ bool UnixDomainSocket::EnableReceiveProcessId(int fd) {
const int enable = 1;
return setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable)) == 0;
}
#endif // !defined(__native_client_nonsfi__)
// static
bool UnixDomainSocket::SendMsg(int fd,
......@@ -106,8 +111,14 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd,
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
char control_buffer[CMSG_SPACE(sizeof(int) * kMaxFileDescriptors) +
CMSG_SPACE(sizeof(struct ucred))];
const size_t kControlBufferSize =
CMSG_SPACE(sizeof(int) * kMaxFileDescriptors)
#if !defined(__native_client_nonsfi__)
// The PNaCl toolchain for Non-SFI binary build does not support ucred.
+ CMSG_SPACE(sizeof(struct ucred))
#endif
;
char control_buffer[kControlBufferSize];
msg.msg_control = control_buffer;
msg.msg_controllen = sizeof(control_buffer);
......@@ -130,21 +141,29 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd,
wire_fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
wire_fds_len = payload_len / sizeof(int);
}
#if !defined(__native_client_nonsfi__)
// The PNaCl toolchain for Non-SFI binary build does not support
// SCM_CREDENTIALS.
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS) {
DCHECK(payload_len == sizeof(struct ucred));
DCHECK(pid == -1);
pid = reinterpret_cast<struct ucred*>(CMSG_DATA(cmsg))->pid;
}
#endif
}
}
#if !defined(__native_client_nonsfi__)
// The PNaCl toolchain for Non-SFI binary build does not support
// MSG_TRUNC or MSG_CTRUNC.
if (msg.msg_flags & MSG_TRUNC || msg.msg_flags & MSG_CTRUNC) {
for (unsigned i = 0; i < wire_fds_len; ++i)
close(wire_fds[i]);
errno = EMSGSIZE;
return -1;
}
#endif
if (wire_fds) {
for (unsigned i = 0; i < wire_fds_len; ++i)
......@@ -165,6 +184,7 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd,
return r;
}
#if !defined(__native_client_nonsfi__)
// static
ssize_t UnixDomainSocket::SendRecvMsg(int fd,
uint8_t* reply,
......@@ -222,3 +242,4 @@ ssize_t UnixDomainSocket::SendRecvMsgWithFlags(int fd,
return reply_len;
}
#endif // !defined(__native_client_nonsfi__)
......@@ -21,10 +21,12 @@ class BASE_EXPORT UnixDomainSocket {
// Maximum number of file descriptors that can be read by RecvMsg().
static const size_t kMaxFileDescriptors;
#if !defined(__native_client_nonsfi__)
// Use to enable receiving process IDs in RecvMsgWithPid. Should be called on
// the receiving socket (i.e., the socket passed to RecvMsgWithPid). Returns
// true if successful.
static bool EnableReceiveProcessId(int fd);
#endif // !defined(__native_client_nonsfi__)
// Use sendmsg to write the given msg and include a vector of file
// descriptors. Returns true if successful.
......@@ -50,6 +52,7 @@ class BASE_EXPORT UnixDomainSocket {
ScopedVector<base::ScopedFD>* fds,
base::ProcessId* pid);
#if !defined(__native_client_nonsfi__)
// Perform a sendmsg/recvmsg pair.
// 1. This process creates a UNIX SEQPACKET socketpair. Using
// connection-oriented sockets (SEQPACKET or STREAM) is critical here,
......@@ -82,6 +85,7 @@ class BASE_EXPORT UnixDomainSocket {
int recvmsg_flags,
int* result_fd,
const Pickle& request);
#endif // !defined(__native_client_nonsfi__)
private:
// Similar to RecvMsg, but allows to specify |flags| for recvmsg(2).
static ssize_t RecvMsgWithFlags(int fd,
......
......@@ -22,6 +22,7 @@ namespace base {
namespace {
#if !defined(__native_client_nonsfi__)
bool WaitpidWithTimeout(ProcessHandle handle,
int* status,
base::TimeDelta wait) {
......@@ -83,6 +84,7 @@ bool WaitpidWithTimeout(ProcessHandle handle,
return ret_pid > 0;
}
#endif // !defined(__native_client_nonsfi__)
TerminationStatus GetTerminationStatusImpl(ProcessHandle handle,
bool can_block,
......@@ -130,6 +132,7 @@ TerminationStatus GetTerminationStatusImpl(ProcessHandle handle,
} // namespace
#if !defined(__native_client_nonsfi__)
// Attempts to kill the process identified by the given process
// entry structure. Ignores specified exit_code; posix can't force that.
// Returns true if this is successful, false otherwise.
......@@ -191,6 +194,7 @@ bool KillProcessGroup(ProcessHandle process_group_id) {
DPLOG(ERROR) << "Unable to terminate process group " << process_group_id;
return result;
}
#endif // !defined(__native_client_nonsfi__)
TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) {
return GetTerminationStatusImpl(handle, false /* can_block */, exit_code);
......@@ -206,6 +210,7 @@ TerminationStatus GetKnownDeadTerminationStatus(ProcessHandle handle,
return GetTerminationStatusImpl(handle, true /* can_block */, exit_code);
}
#if !defined(__native_client_nonsfi__)
bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
int status;
if (HANDLE_EINTR(waitpid(handle, &status, 0)) == -1) {
......@@ -478,5 +483,6 @@ void EnsureProcessGetsReaped(ProcessHandle process) {
}
#endif // !defined(OS_MACOSX)
#endif // !defined(__native_client_nonsfi__)
} // namespace base
......@@ -2562,9 +2562,6 @@
['use_cras==1', {
'defines': ['USE_CRAS=1'],
}],
['use_glib==1', {
'defines': ['USE_GLIB=1'],
}],
['use_ozone==1', {
'defines': ['USE_OZONE=1'],
}],
......@@ -2923,6 +2920,9 @@
'USE_OPENSSL_CERTS=1',
],
}],
['<(use_glib)==1 and >(nacl_untrusted_build)==0', {
'defines': ['USE_GLIB=1'],
}],
['<(use_nss)==1 and >(nacl_untrusted_build)==0', {
'defines': ['USE_NSS=1'],
}],
......
......@@ -40,20 +40,17 @@
'conditions': [
['target_arch=="ia32" or target_arch=="x64"', {
'extra_deps_newlib32_nonsfi': [
'>(tc_lib_dir_nonsfi_helper32)/libbase_nacl_nonsfi.a',
'>(tc_lib_dir_nonsfi_helper32)/libevent_nacl_nonsfi.a',
],
}],
],
},
'dependencies': [
'<(DEPTH)/base/base_nacl.gyp:base_nacl_nonsfi',
'<(DEPTH)/native_client/src/nonsfi/irt/irt.gyp:nacl_sys_private',
'<(DEPTH)/native_client/src/untrusted/nacl/nacl.gyp:nacl_lib_newlib',
'<(DEPTH)/native_client/tools.gyp:prep_toolchain',
# TODO(hidehiko): Remove this when we introduce base/.
# This dependency is introduced to make sure the library is
# actually built successfully.
'<(DEPTH)/third_party/libevent/libevent_nacl_nonsfi.gyp:event_nacl_nonsfi',
],
},
# TODO(hidehiko): Add Non-SFI version of nacl_loader_unittests.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment