summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 11:12:12 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 11:12:12 +0000
commit1139c6c20257d5077aa77c77047a368ce5d3de94 (patch)
tree03180c8744513836d677ef3a49b0b1e2b62ca2d2
parentde2be4544da8057fe35a63d60126267395298dd5 (diff)
downloadchromium_src-1139c6c20257d5077aa77c77047a368ce5d3de94.zip
chromium_src-1139c6c20257d5077aa77c77047a368ce5d3de94.tar.gz
chromium_src-1139c6c20257d5077aa77c77047a368ce5d3de94.tar.bz2
Initial implementation of IRT for non-SFI mode.
This CL implements the mechanism to pass an irt querying function to the plugin process via AT_SYSINFO. Also, as the first step to implement many irt functions for non-SFI mode, this CL introduces nacl_irt_basic. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3734 TEST=Tried to call a newly added function from plugin via AT_SYSINFO. Review URL: https://codereview.chromium.org/125533004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244144 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--components/nacl.gyp3
-rw-r--r--components/nacl/loader/nonsfi/irt_basic.cc101
-rw-r--r--components/nacl/loader/nonsfi/irt_interfaces.cc47
-rw-r--r--components/nacl/loader/nonsfi/irt_interfaces.h22
-rw-r--r--components/nacl/loader/nonsfi/nonsfi_main.cc3
5 files changed, 176 insertions, 0 deletions
diff --git a/components/nacl.gyp b/components/nacl.gyp
index 9284102..a1404ed 100644
--- a/components/nacl.gyp
+++ b/components/nacl.gyp
@@ -192,6 +192,9 @@
'nacl/loader/nacl_sandbox_linux.cc',
'nacl/loader/nonsfi/elf_loader.cc',
'nacl/loader/nonsfi/elf_loader.h',
+ 'nacl/loader/nonsfi/irt_basic.cc',
+ 'nacl/loader/nonsfi/irt_interfaces.cc',
+ 'nacl/loader/nonsfi/irt_interfaces.h',
'nacl/loader/nonsfi/nonsfi_main.cc',
'nacl/loader/nonsfi/nonsfi_main.h',
'../base/posix/unix_domain_socket_linux.cc',
diff --git a/components/nacl/loader/nonsfi/irt_basic.cc b/components/nacl/loader/nonsfi/irt_basic.cc
new file mode 100644
index 0000000..f65ee53
--- /dev/null
+++ b/components/nacl/loader/nonsfi/irt_basic.cc
@@ -0,0 +1,101 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <errno.h>
+#include <sched.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "components/nacl/loader/nonsfi/irt_interfaces.h"
+#include "native_client/src/trusted/service_runtime/include/sys/time.h"
+#include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
+
+namespace nacl {
+namespace nonsfi {
+namespace {
+
+void IrtExit(int status) {
+ _exit(status);
+}
+
+int IrtGetToD(struct nacl_abi_timeval* tv) {
+ struct timeval host_tv;
+ if (gettimeofday(&host_tv, NULL))
+ return errno;
+ tv->nacl_abi_tv_sec = host_tv.tv_sec;
+ tv->nacl_abi_tv_usec = host_tv.tv_usec;
+ return 0;
+}
+
+int IrtClock(nacl_abi_clock_t* ticks) {
+ // There is no definition of errno when clock is failed.
+ // So we assume it always succeeds.
+ *ticks = clock();
+ return 0;
+}
+
+int IrtNanoSleep(const struct nacl_abi_timespec* req,
+ struct nacl_abi_timespec* rem) {
+ struct timespec host_req;
+ host_req.tv_sec = req->tv_sec;
+ host_req.tv_nsec = req->tv_nsec;
+ struct timespec host_rem;
+ if (nanosleep(&host_req, &host_rem))
+ return errno;
+
+ if (rem) {
+ rem->tv_sec = host_rem.tv_sec;
+ rem->tv_nsec = host_rem.tv_nsec;
+ }
+ return 0;
+}
+
+int IrtSchedYield() {
+ if (sched_yield())
+ return errno;
+
+ return 0;
+}
+
+int IrtSysconf(int name, int* value) {
+ int result;
+ switch (name) {
+ case NACL_ABI__SC_NPROCESSORS_ONLN:
+ errno = 0;
+ result = sysconf(_SC_NPROCESSORS_ONLN);
+ break;
+ case NACL_ABI__SC_PAGESIZE:
+ errno = 0;
+ result = sysconf(_SC_PAGESIZE);
+ break;
+ default:
+ return EINVAL;
+ }
+
+ if (result == -1 && errno == EINVAL)
+ return EINVAL;
+
+ *value = result;
+ return 0;
+}
+
+} // namespace
+
+// For gettod, clock and nanosleep, their argument types should be nacl_abi_X,
+// rather than host type, such as timeval or clock_t etc. However, the
+// definition of nacl_irt_basic uses host types, so here we need to cast them.
+const nacl_irt_basic kIrtBasic = {
+ IrtExit,
+ reinterpret_cast<int(*)(struct timeval*)>(IrtGetToD),
+ reinterpret_cast<int(*)(clock_t*)>(IrtClock),
+ reinterpret_cast<int(*)(const struct timespec*, struct timespec*)>(
+ IrtNanoSleep),
+ IrtSchedYield,
+ IrtSysconf,
+};
+
+} // namespace nonsfi
+} // namespace nacl
diff --git a/components/nacl/loader/nonsfi/irt_interfaces.cc b/components/nacl/loader/nonsfi/irt_interfaces.cc
new file mode 100644
index 0000000..151df35
--- /dev/null
+++ b/components/nacl/loader/nonsfi/irt_interfaces.cc
@@ -0,0 +1,47 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/nacl/loader/nonsfi/irt_interfaces.h"
+
+#include <cstring>
+
+namespace nacl {
+namespace nonsfi {
+
+namespace {
+
+// This table keeps a pair of IRT entry (such as nacl_irt_basic, nacl_irt_fdio
+// etc.) and its registered name with its version (such as NACL_IRT_BASIC_v0_1,
+// NACL_IRT_FDIO_v0_1, etc.).
+struct NaClInterfaceTable {
+ const char* name;
+ const void* table;
+ size_t size;
+};
+
+#define NACL_INTERFACE_TABLE(name, value) { name, &value, sizeof(value) }
+const NaClInterfaceTable kIrtInterfaces[] = {
+ NACL_INTERFACE_TABLE(NACL_IRT_BASIC_v0_1, kIrtBasic),
+};
+#undef NACL_INTERFACE_TABLE
+
+} // namespace
+
+size_t NaClIrtInterface(const char* interface_ident,
+ void* table, size_t tablesize) {
+ for (size_t i = 0; i < arraysize(kIrtInterfaces); ++i) {
+ if (std::strcmp(interface_ident, kIrtInterfaces[i].name) == 0) {
+ const size_t size = kIrtInterfaces[i].size;
+ if (size <= tablesize) {
+ std::memcpy(table, kIrtInterfaces[i].table, size);
+ return size;
+ }
+ break;
+ }
+ }
+ return 0;
+}
+
+} // namespace nonsfi
+} // namespace nacl
diff --git a/components/nacl/loader/nonsfi/irt_interfaces.h b/components/nacl/loader/nonsfi/irt_interfaces.h
new file mode 100644
index 0000000..9c0d02e
--- /dev/null
+++ b/components/nacl/loader/nonsfi/irt_interfaces.h
@@ -0,0 +1,22 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_NACL_LOADER_NONSFI_IRT_INTERFACES_H_
+#define COMPONENTS_NACL_LOADER_NONSFI_IRT_INTERFACES_H_
+
+#include "base/basictypes.h"
+#include "native_client/src/untrusted/irt/irt.h"
+
+namespace nacl {
+namespace nonsfi {
+
+size_t NaClIrtInterface(const char* interface_ident,
+ void* table, size_t tablesize);
+
+extern const struct nacl_irt_basic kIrtBasic;
+
+} // namespace nonsfi
+} // namespace nacl
+
+#endif // COMPONENTS_NACL_LOADER_NONSFI_IRT_INTERFACES_H_
diff --git a/components/nacl/loader/nonsfi/nonsfi_main.cc b/components/nacl/loader/nonsfi/nonsfi_main.cc
index d5e5d9a..d9847c52 100644
--- a/components/nacl/loader/nonsfi/nonsfi_main.cc
+++ b/components/nacl/loader/nonsfi/nonsfi_main.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "components/nacl/loader/nonsfi/elf_loader.h"
+#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "native_client/src/include/elf_auxv.h"
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/public/secure_service.h"
@@ -55,6 +56,8 @@ void LoadModuleRpc(struct NaClSrpcRpc* rpc,
0, // argc.
0, // Null terminate for argv.
0, // Null terminate for envv.
+ AT_SYSINFO,
+ reinterpret_cast<uintptr_t>(&NaClIrtInterface),
AT_NULL,
0, // Null terminate for auxv.
};