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

Unified Diff: src/untrusted/irt/irt_random.c

Issue 537543003: Add a get_random_bytes() syscall to replace the SRPC-based implementation (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Fix glibc tests Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/trusted/service_runtime/sys_random.c ('k') | src/untrusted/nacl/syscall_bindings_trampoline.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/untrusted/irt/irt_random.c
diff --git a/src/untrusted/irt/irt_random.c b/src/untrusted/irt/irt_random.c
index 6f16dcf63a032678336089ef3fd6f92f30d03771..d1525afbcb1339c0d720a9694bd2babcd91125cd 100644
--- a/src/untrusted/irt/irt_random.c
+++ b/src/untrusted/irt/irt_random.c
@@ -7,46 +7,21 @@
#include <errno.h>
#include <fcntl.h>
-#include "native_client/src/public/name_service.h"
#include "native_client/src/untrusted/nacl/nacl_random.h"
#include "native_client/src/untrusted/irt/irt.h"
#include "native_client/src/untrusted/irt/irt_private.h"
#include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
-static int secure_random_fd = -1;
-
-static int prepare_secure_random(void) {
- if (secure_random_fd == -1) {
- int fd;
- int status = irt_nameservice_lookup("SecureRandom", O_RDONLY, &fd);
- if (status != NACL_NAME_SERVICE_SUCCESS) {
- return EIO;
- }
- if (!__sync_bool_compare_and_swap(&secure_random_fd, -1, fd)) {
- /*
- * We raced with another thread. It already installed an fd.
- */
- NACL_SYSCALL(close)(fd);
- }
- }
- return 0;
-}
-
int nacl_secure_random_init(void) {
return 0;
}
int nacl_secure_random(void *buf, size_t count, size_t *nread) {
- int error = prepare_secure_random();
- if (error == 0) {
- int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(read)(secure_random_fd,
- buf, count));
- if (rv < 0)
- error = -rv;
- else
- *nread = rv;
- }
- return error;
+ int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(get_random_bytes)(buf, count));
+ if (rv != 0)
+ return -rv;
+ *nread = count;
+ return 0;
}
const struct nacl_irt_random nacl_irt_random = {
« no previous file with comments | « src/trusted/service_runtime/sys_random.c ('k') | src/untrusted/nacl/syscall_bindings_trampoline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698