Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/irt_interfaces.h" | |
| 13 #include "native_client/src/trusted/service_runtime/include/sys/time.h" | |
| 14 | |
| 15 namespace nacl { | |
| 16 namespace nonsfi { | |
| 17 namespace { | |
| 18 | |
| 19 void IrtExit(int status) { | |
| 20 // Note: when we start to support threads, here we need to join them. | |
|
Mark Seaborn
2014/01/07 09:45:06
That's not the case. There's no need to join thre
hidehiko
2014/01/07 11:52:29
Oops, I misunderstood. Done.
| |
| 21 ::exit(status); | |
|
Mark Seaborn
2014/01/07 09:45:06
This should really call _exit(), because exit() do
hidehiko
2014/01/07 11:52:29
Done.
| |
| 22 while (1) *(volatile int *) 0 = 0; // Crash. | |
|
Mark Seaborn
2014/01/07 09:45:06
Not really necessary, since _exit() is generally d
hidehiko
2014/01/07 11:52:29
Ok, removed. This is extracted from native_client/
| |
| 23 } | |
| 24 | |
| 25 int IrtGetToD(struct nacl_abi_timeval* tv) { | |
| 26 struct timeval host_tv; | |
| 27 int result = ::gettimeofday(&host_tv, NULL); | |
| 28 if (result) | |
| 29 return errno; | |
| 30 tv->nacl_abi_tv_sec = host_tv.tv_sec; | |
| 31 tv->nacl_abi_tv_usec = host_tv.tv_usec; | |
| 32 return 0; | |
| 33 } | |
| 34 | |
| 35 int IrtClock(nacl_abi_clock_t* ticks) { | |
| 36 *ticks = ::clock(); // No failure. | |
|
Mark Seaborn
2014/01/07 09:45:06
The man page says this can return (clock_t)-1 on f
hidehiko
2014/01/07 11:52:29
Good catch. I just mimic'ed native_client/src/trus
Mark Seaborn
2014/01/10 05:12:20
Oh, you're right. http://pubs.opengroup.org/onlin
hidehiko
2014/01/10 07:27:47
Done.
| |
| 37 return 0; | |
| 38 } | |
| 39 | |
| 40 int IrtNanoSleep(const struct nacl_abi_timespec* req, | |
| 41 struct nacl_abi_timespec* rem) { | |
| 42 // We should be able to call nanosleep(NULL, &host_rem) for this. | |
|
Mark Seaborn
2014/01/07 09:45:06
Why do you expect req==NULL to work? This isn't p
hamaji
2014/01/07 11:32:09
Let me reply as I wrote this.
I think both linux
hidehiko
2014/01/07 11:52:29
Thank you for your comment, Shinichiro.
So, accord
Mark Seaborn
2014/01/10 05:12:20
Out of curiosity, what's the case you need the wor
hidehiko
2014/01/10 07:27:47
It turned out that it was just our test code. We'l
| |
| 43 // However, the user mode qemu-arm does not handle this case | |
| 44 // properly. It just runs nanosleep with the parameter for the | |
| 45 // previous nanosleep call. To work-around this issue, we handle | |
| 46 // this case by ourselves. | |
| 47 if (!req) | |
| 48 return EFAULT; | |
| 49 | |
| 50 struct timespec host_req; | |
| 51 host_req.tv_sec = req->tv_sec; | |
| 52 host_req.tv_nsec = req->tv_nsec; | |
| 53 struct timespec host_rem; | |
| 54 int result = ::nanosleep(&host_req, &host_rem); | |
| 55 if (result) | |
| 56 return errno; | |
| 57 | |
| 58 if (rem) { | |
| 59 rem->tv_sec = host_rem.tv_sec; | |
| 60 rem->tv_nsec = host_rem.tv_nsec; | |
| 61 } | |
| 62 return 0; | |
| 63 } | |
| 64 | |
| 65 int IrtSchedYield() { | |
| 66 int result = ::sched_yield(); | |
| 67 if (result) | |
| 68 return errno; | |
| 69 | |
| 70 return 0; | |
| 71 } | |
| 72 | |
| 73 int IrtSysconf(int name, int* value) { | |
| 74 errno = 0; | |
| 75 *value = ::sysconf(name); | |
|
Mark Seaborn
2014/01/07 09:45:06
Calling through to sysconf() isn't valid because t
hidehiko
2014/01/07 11:52:29
Great to know. Done.
| |
| 76 if (*value == -1 && errno == EINVAL) | |
| 77 return EINVAL; | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 // For gettod, clock and nanosleep, their argument types should be nacl_abi_X, | |
| 84 // rather than host type, such as timeval or clock_t etc. However, the | |
| 85 // definition of nacl_irt_basic uses host types, so here we need to cast them. | |
| 86 const nacl_irt_basic kIrtBasic = { | |
| 87 IrtExit, | |
| 88 reinterpret_cast<int(*)(struct timeval*)>(IrtGetToD), | |
| 89 reinterpret_cast<int(*)(clock_t*)>(IrtClock), | |
| 90 reinterpret_cast<int(*)(const struct timespec*, struct timespec*)>( | |
| 91 IrtNanoSleep), | |
| 92 IrtSchedYield, | |
| 93 IrtSysconf, | |
| 94 }; | |
| 95 | |
| 96 } // namespace nonsfi | |
| 97 } // namespace nacl | |
| OLD | NEW |