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

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

Issue 139303003: Implement nacl_irt_clock for non-sfi mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
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 <time.h>
7
8 #include "components/nacl/loader/nonsfi/abi_conversion.h"
9 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
10 #include "native_client/src/trusted/service_runtime/include/sys/time.h"
11
12 namespace nacl {
13 namespace nonsfi {
14 namespace {
15
16 bool NaClAbiClockIdToClockId(int nacl_clk_id, clockid_t* host_clk_id) {
17 switch (nacl_clk_id) {
18 case NACL_ABI_CLOCK_REALTIME:
19 *host_clk_id = CLOCK_REALTIME;
20 break;
21 case NACL_ABI_CLOCK_MONOTONIC:
22 *host_clk_id = CLOCK_MONOTONIC;
23 break;
24 case NACL_ABI_CLOCK_PROCESS_CPUTIME_ID:
25 *host_clk_id = CLOCK_PROCESS_CPUTIME_ID;
26 break;
27 case NACL_ABI_CLOCK_THREAD_CPUTIME_ID:
28 *host_clk_id = CLOCK_THREAD_CPUTIME_ID;
29 break;
30 default:
31 // Unknown clock id.
32 return false;
33 }
34 return true;
35 }
36
37 int IrtClockGetRes(int clk_id, struct nacl_abi_timespec* res) {
38 clockid_t host_clk_id;
39 if (!NaClAbiClockIdToClockId(clk_id, &host_clk_id))
40 return EINVAL;
41
42 struct timespec host_res;
43 if (clock_getres(host_clk_id, &host_res))
44 return errno;
45
46 // clock_getres() requires a NULL check but clock_gettime() doesn't.
47 if (res)
48 TimeSpecToNaClAbiTimeSpec(host_res, res);
49 return 0;
50 }
51
52 int IrtClockGetTime(int clk_id, struct nacl_abi_timespec* tp) {
53 clockid_t host_clk_id;
54 if (!NaClAbiClockIdToClockId(clk_id, &host_clk_id))
55 return EINVAL;
56
57 struct timespec host_tp;
58 if (clock_gettime(host_clk_id, &host_tp))
59 return errno;
60
61 TimeSpecToNaClAbiTimeSpec(host_tp, tp);
62 return 0;
63 }
64
65 } // namespace
66
67 // Cast away the distinction between host types and NaCl ABI types.
68 const nacl_irt_clock kIrtClock = {
69 reinterpret_cast<int(*)(clockid_t, struct timespec*)>(IrtClockGetRes),
70 reinterpret_cast<int(*)(clockid_t, struct timespec*)>(IrtClockGetTime),
71 };
72
73 } // namespace nonsfi
74 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/loader/nonsfi/irt_basic.cc ('k') | components/nacl/loader/nonsfi/irt_interfaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698