Chromium Code Reviews| Index: src/nonsfi/irt/irt_interfaces.c |
| diff --git a/src/nonsfi/irt/irt_interfaces.c b/src/nonsfi/irt/irt_interfaces.c |
| index 562d204b71a58f26605fb3d5cbdf71cf0bf45646..e364d27c9e0b49dd7aab794b15a66b28ecc0d196 100644 |
| --- a/src/nonsfi/irt/irt_interfaces.c |
| +++ b/src/nonsfi/irt/irt_interfaces.c |
| @@ -38,6 +38,10 @@ |
| #include "native_client/src/untrusted/irt/irt_dev.h" |
| #include "native_client/src/untrusted/irt/irt_interfaces.h" |
| +#if defined(__native_client__) |
| +#include "native_client/src/nonsfi/irt/irt_random.h" |
| +#endif |
| + |
| /* |
| * This is an implementation of NaCl's IRT interfaces that runs |
| * outside of the NaCl sandbox. |
| @@ -431,6 +435,22 @@ static int futex_wake(volatile int *addr, int nwake, int *count) { |
| } |
| #endif |
| +#if defined(__native_client__) |
| +static int urandom_fd = -1; |
|
Mark Seaborn
2014/10/30 18:58:30
Style nit: Add "g_" prefix to the name
hidehiko
2014/10/31 14:03:52
Done (in irt_random.c).
|
| + |
| +void nonsfi_set_urandom_fd(int fd) { |
| + urandom_fd = fd; |
| +} |
| + |
| +static int irt_get_random_bytes(void *buf, size_t count, size_t *nread) { |
|
Mark Seaborn
2014/10/30 18:58:30
It's rather unfortunate that this isn't tested on
hidehiko
2014/10/31 14:03:52
Done.
|
| + int result = read(urandom_fd, buf, count); |
| + if (result < 0) |
| + return errno; |
| + *nread = result; |
| + return 0; |
| +} |
| +#endif |
| + |
| #if defined(__linux__) || defined(__native_client__) |
| static int irt_clock_getres(nacl_irt_clockid_t clk_id, |
| struct timespec *time_nacl) { |
| @@ -599,6 +619,12 @@ const struct nacl_irt_futex nacl_irt_futex = { |
| }; |
| #endif |
| +#if defined(__native_client__) |
| +const struct nacl_irt_random nacl_irt_random = { |
| + irt_get_random_bytes, |
| +}; |
| +#endif |
| + |
| #if defined(__linux__) || defined(__native_client__) |
| const struct nacl_irt_clock nacl_irt_clock = { |
| irt_clock_getres, |
| @@ -650,6 +676,9 @@ static const struct nacl_irt_interface irt_interfaces[] = { |
| { NACL_IRT_TLS_v0_1, &nacl_irt_tls, sizeof(nacl_irt_tls), NULL }, |
| { NACL_IRT_THREAD_v0_1, &nacl_irt_thread, sizeof(nacl_irt_thread), NULL }, |
| { NACL_IRT_FUTEX_v0_1, &nacl_irt_futex, sizeof(nacl_irt_futex), NULL }, |
| +#if defined(__native_client__) |
| + { NACL_IRT_RANDOM_v0_1, &nacl_irt_random, sizeof(nacl_irt_random), NULL }, |
| +#endif |
| #if defined(__linux__) || defined(__native_client__) |
| { NACL_IRT_CLOCK_v0_1, &nacl_irt_clock, sizeof(nacl_irt_clock), NULL }, |
| #endif |