summaryrefslogtreecommitdiffstats
path: root/components/nacl
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 07:09:27 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 07:09:27 +0000
commitf5d6d24a4df936ed5489d8f200500210ec84def2 (patch)
tree508f28ad355fcf589fa1f8f424c22132dcc63552 /components/nacl
parent6f14aa8920c92e40799665af64776eead5053bfc (diff)
downloadchromium_src-f5d6d24a4df936ed5489d8f200500210ec84def2.zip
chromium_src-f5d6d24a4df936ed5489d8f200500210ec84def2.tar.gz
chromium_src-f5d6d24a4df936ed5489d8f200500210ec84def2.tar.bz2
Implement nacl_irt_clock for non-sfi mode.
This CL implements nacl_irt_clock on non-sfi mode, which is simply proxying to the glibc implementation. 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/139303003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245459 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/nacl')
-rw-r--r--components/nacl/loader/nonsfi/abi_conversion.cc13
-rw-r--r--components/nacl/loader/nonsfi/abi_conversion.h11
-rw-r--r--components/nacl/loader/nonsfi/irt_basic.cc10
-rw-r--r--components/nacl/loader/nonsfi/irt_clock.cc74
-rw-r--r--components/nacl/loader/nonsfi/irt_interfaces.cc1
-rw-r--r--components/nacl/loader/nonsfi/irt_interfaces.h1
6 files changed, 104 insertions, 6 deletions
diff --git a/components/nacl/loader/nonsfi/abi_conversion.cc b/components/nacl/loader/nonsfi/abi_conversion.cc
index 5977106..ae746f4 100644
--- a/components/nacl/loader/nonsfi/abi_conversion.cc
+++ b/components/nacl/loader/nonsfi/abi_conversion.cc
@@ -9,10 +9,23 @@
#include "base/logging.h"
#include "native_client/src/trusted/service_runtime/include/sys/stat.h"
+#include "native_client/src/trusted/service_runtime/include/sys/time.h"
namespace nacl {
namespace nonsfi {
+void NaClAbiTimeSpecToTimeSpec(const struct nacl_abi_timespec& nacl_timespec,
+ struct timespec* host_timespec) {
+ host_timespec->tv_sec = nacl_timespec.tv_sec;
+ host_timespec->tv_nsec = nacl_timespec.tv_nsec;
+}
+
+void TimeSpecToNaClAbiTimeSpec(const struct timespec& host_timespec,
+ struct nacl_abi_timespec* nacl_timespec) {
+ nacl_timespec->tv_sec = host_timespec.tv_sec;
+ nacl_timespec->tv_nsec = host_timespec.tv_nsec;
+}
+
void StatToNaClAbiStat(
const struct stat& host_stat, struct nacl_abi_stat* nacl_stat) {
// Some fields in host_stat, such as st_dev, group/other bits of mode and
diff --git a/components/nacl/loader/nonsfi/abi_conversion.h b/components/nacl/loader/nonsfi/abi_conversion.h
index 13479e2..771f2dc 100644
--- a/components/nacl/loader/nonsfi/abi_conversion.h
+++ b/components/nacl/loader/nonsfi/abi_conversion.h
@@ -6,11 +6,22 @@
#define COMPONENTS_NACL_LOADER_NONSFI_ABI_CONVERSION_H_
struct stat;
+struct timespec;
struct nacl_abi_stat;
+struct nacl_abi_timespec;
namespace nacl {
namespace nonsfi {
+// Converts the timespec struct from NaCl's to host's ABI.
+void NaClAbiTimeSpecToTimeSpec(const struct nacl_abi_timespec& nacl_timespec,
+ struct timespec* host_timespec);
+
+// Converts the timespec struct from host's to NaCl's ABI.
+void TimeSpecToNaClAbiTimeSpec(const struct timespec& host_timespec,
+ struct nacl_abi_timespec* nacl_timespec);
+
+
// Converts the stat struct from host's to NaCl's ABI.
void StatToNaClAbiStat(
const struct stat& host_stat, struct nacl_abi_stat* nacl_stat);
diff --git a/components/nacl/loader/nonsfi/irt_basic.cc b/components/nacl/loader/nonsfi/irt_basic.cc
index f65ee53..49fbfe4 100644
--- a/components/nacl/loader/nonsfi/irt_basic.cc
+++ b/components/nacl/loader/nonsfi/irt_basic.cc
@@ -9,6 +9,7 @@
#include <time.h>
#include <unistd.h>
+#include "components/nacl/loader/nonsfi/abi_conversion.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"
@@ -40,16 +41,13 @@ int IrtClock(nacl_abi_clock_t* ticks) {
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;
+ NaClAbiTimeSpecToTimeSpec(*req, &host_req);
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;
- }
+ if (rem)
+ TimeSpecToNaClAbiTimeSpec(host_rem, rem);
return 0;
}
diff --git a/components/nacl/loader/nonsfi/irt_clock.cc b/components/nacl/loader/nonsfi/irt_clock.cc
new file mode 100644
index 0000000..2ad0ae1
--- /dev/null
+++ b/components/nacl/loader/nonsfi/irt_clock.cc
@@ -0,0 +1,74 @@
+// 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 <time.h>
+
+#include "components/nacl/loader/nonsfi/abi_conversion.h"
+#include "components/nacl/loader/nonsfi/irt_interfaces.h"
+#include "native_client/src/trusted/service_runtime/include/sys/time.h"
+
+namespace nacl {
+namespace nonsfi {
+namespace {
+
+bool NaClAbiClockIdToClockId(int nacl_clk_id, clockid_t* host_clk_id) {
+ switch (nacl_clk_id) {
+ case NACL_ABI_CLOCK_REALTIME:
+ *host_clk_id = CLOCK_REALTIME;
+ break;
+ case NACL_ABI_CLOCK_MONOTONIC:
+ *host_clk_id = CLOCK_MONOTONIC;
+ break;
+ case NACL_ABI_CLOCK_PROCESS_CPUTIME_ID:
+ *host_clk_id = CLOCK_PROCESS_CPUTIME_ID;
+ break;
+ case NACL_ABI_CLOCK_THREAD_CPUTIME_ID:
+ *host_clk_id = CLOCK_THREAD_CPUTIME_ID;
+ break;
+ default:
+ // Unknown clock id.
+ return false;
+ }
+ return true;
+}
+
+int IrtClockGetRes(int clk_id, struct nacl_abi_timespec* res) {
+ clockid_t host_clk_id;
+ if (!NaClAbiClockIdToClockId(clk_id, &host_clk_id))
+ return EINVAL;
+
+ struct timespec host_res;
+ if (clock_getres(host_clk_id, &host_res))
+ return errno;
+
+ // clock_getres() requires a NULL check but clock_gettime() doesn't.
+ if (res)
+ TimeSpecToNaClAbiTimeSpec(host_res, res);
+ return 0;
+}
+
+int IrtClockGetTime(int clk_id, struct nacl_abi_timespec* tp) {
+ clockid_t host_clk_id;
+ if (!NaClAbiClockIdToClockId(clk_id, &host_clk_id))
+ return EINVAL;
+
+ struct timespec host_tp;
+ if (clock_gettime(host_clk_id, &host_tp))
+ return errno;
+
+ TimeSpecToNaClAbiTimeSpec(host_tp, tp);
+ return 0;
+}
+
+} // namespace
+
+// Cast away the distinction between host types and NaCl ABI types.
+const nacl_irt_clock kIrtClock = {
+ reinterpret_cast<int(*)(clockid_t, struct timespec*)>(IrtClockGetRes),
+ reinterpret_cast<int(*)(clockid_t, struct timespec*)>(IrtClockGetTime),
+};
+
+} // namespace nonsfi
+} // namespace nacl
diff --git a/components/nacl/loader/nonsfi/irt_interfaces.cc b/components/nacl/loader/nonsfi/irt_interfaces.cc
index 3ec29ff..89ff4f5 100644
--- a/components/nacl/loader/nonsfi/irt_interfaces.cc
+++ b/components/nacl/loader/nonsfi/irt_interfaces.cc
@@ -27,6 +27,7 @@ const NaClInterfaceTable kIrtInterfaces[] = {
NACL_INTERFACE_TABLE(NACL_IRT_THREAD_v0_1, kIrtThread),
NACL_INTERFACE_TABLE(NACL_IRT_FUTEX_v0_1, kIrtFutex),
NACL_INTERFACE_TABLE(NACL_IRT_TLS_v0_1, kIrtTls),
+ NACL_INTERFACE_TABLE(NACL_IRT_CLOCK_v0_1, kIrtClock),
};
#undef NACL_INTERFACE_TABLE
diff --git a/components/nacl/loader/nonsfi/irt_interfaces.h b/components/nacl/loader/nonsfi/irt_interfaces.h
index 33e13a6..463fc44 100644
--- a/components/nacl/loader/nonsfi/irt_interfaces.h
+++ b/components/nacl/loader/nonsfi/irt_interfaces.h
@@ -19,6 +19,7 @@ extern const struct nacl_irt_fdio kIrtFdIO;
extern const struct nacl_irt_thread kIrtThread;
extern const struct nacl_irt_futex kIrtFutex;
extern const struct nacl_irt_tls kIrtTls;
+extern const struct nacl_irt_clock kIrtClock;
} // namespace nonsfi
} // namespace nacl