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

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: 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* rem) {
Mark Seaborn 2014/01/15 19:49:28 Should be "res", not "rem"
hidehiko 2014/01/16 05:30:12 Oops, done.
38 clockid_t host_clk_id;
39 if (!NaClAbiClockIdToClockId(clk_id, &host_clk_id))
40 return EINVAL;
41
42 struct timespec host_rem;
43 if (clock_getres(host_clk_id, &host_rem))
44 return errno;
45
46 if (rem)
Mark Seaborn 2014/01/15 19:49:28 Hmm, interesting that clock_getres() checks for NU
hidehiko 2014/01/16 05:30:12 Done to add the comment. What I found are: https:
47 TimeSpecToNaClAbiTimeSpec(host_rem, rem);
48 return 0;
49 }
50
51 int IrtClockGetTime(int clk_id, struct nacl_abi_timespec* tp) {
52 clockid_t host_clk_id;
53 if (!NaClAbiClockIdToClockId(clk_id, &host_clk_id))
54 return EINVAL;
55
56 struct timespec host_tp;
57 if (clock_gettime(host_clk_id, &host_tp))
58 return errno;
59
60 TimeSpecToNaClAbiTimeSpec(host_tp, tp);
61 return 0;
62 }
63
64 } // namespace
65
66 // Both clock_getres and clock_gettime should use nacl's ABI, nacl_clockid_t
Mark Seaborn 2014/01/15 19:49:28 You probably don't need to comment about the casti
hidehiko 2014/01/16 05:30:12 Done. I'll send a follow up CL for other files, wh
Mark Seaborn 2014/01/16 19:14:13 You don't have to change the existing ones unless
67 // and struct nacl_abi_timespec. However, the definition of nacl_irt_clock
68 // uses host type, clockid_t and timespec, so here we need to cast them.
69 const nacl_irt_clock kIrtClock = {
70 reinterpret_cast<int(*)(clockid_t, struct timespec*)>(IrtClockGetRes),
71 reinterpret_cast<int(*)(clockid_t, struct timespec*)>(IrtClockGetTime),
72 };
73
74 } // namespace nonsfi
75 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698