Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: components/nacl/loader/nonsfi/irt_basic.cc

Issue 125533004: Initial implementation of IRT for non-SFI mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/nacl.gyp ('k') | components/nacl/loader/nonsfi/irt_interfaces.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <errno.h>
6 #include <sched.h>
7 #include <stdlib.h>
8 #include <sys/time.h>
9 #include <time.h>
10 #include <unistd.h>
11
12 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
13 #include "native_client/src/trusted/service_runtime/include/sys/time.h"
14 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
15
16 namespace nacl {
17 namespace nonsfi {
18 namespace {
19
20 void IrtExit(int status) {
21 _exit(status);
22 }
23
24 int IrtGetToD(struct nacl_abi_timeval* tv) {
25 struct timeval host_tv;
26 if (gettimeofday(&host_tv, NULL))
27 return errno;
28 tv->nacl_abi_tv_sec = host_tv.tv_sec;
29 tv->nacl_abi_tv_usec = host_tv.tv_usec;
30 return 0;
31 }
32
33 int IrtClock(nacl_abi_clock_t* ticks) {
34 // There is no definition of errno when clock is failed.
35 // So we assume it always succeeds.
36 *ticks = clock();
37 return 0;
38 }
39
40 int IrtNanoSleep(const struct nacl_abi_timespec* req,
41 struct nacl_abi_timespec* rem) {
42 struct timespec host_req;
43 host_req.tv_sec = req->tv_sec;
44 host_req.tv_nsec = req->tv_nsec;
45 struct timespec host_rem;
46 if (nanosleep(&host_req, &host_rem))
47 return errno;
48
49 if (rem) {
50 rem->tv_sec = host_rem.tv_sec;
51 rem->tv_nsec = host_rem.tv_nsec;
52 }
53 return 0;
54 }
55
56 int IrtSchedYield() {
57 if (sched_yield())
58 return errno;
59
60 return 0;
61 }
62
63 int IrtSysconf(int name, int* value) {
64 int result;
65 switch (name) {
66 case NACL_ABI__SC_NPROCESSORS_ONLN:
67 errno = 0;
68 result = sysconf(_SC_NPROCESSORS_ONLN);
69 break;
70 case NACL_ABI__SC_PAGESIZE:
71 errno = 0;
72 result = sysconf(_SC_PAGESIZE);
73 break;
74 default:
75 return EINVAL;
76 }
77
78 if (result == -1 && errno == EINVAL)
79 return EINVAL;
80
81 *value = result;
82 return 0;
83 }
84
85 } // namespace
86
87 // For gettod, clock and nanosleep, their argument types should be nacl_abi_X,
88 // rather than host type, such as timeval or clock_t etc. However, the
89 // definition of nacl_irt_basic uses host types, so here we need to cast them.
90 const nacl_irt_basic kIrtBasic = {
91 IrtExit,
92 reinterpret_cast<int(*)(struct timeval*)>(IrtGetToD),
93 reinterpret_cast<int(*)(clock_t*)>(IrtClock),
94 reinterpret_cast<int(*)(const struct timespec*, struct timespec*)>(
95 IrtNanoSleep),
96 IrtSchedYield,
97 IrtSysconf,
98 };
99
100 } // namespace nonsfi
101 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl.gyp ('k') | components/nacl/loader/nonsfi/irt_interfaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698