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

Side by Side Diff: src/nonsfi/irt/irt_interfaces.c

Issue 686723003: Non-SFI mode: Implement nacl_irt_random only for nacl_helper_nonsfi. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | src/nonsfi/irt/irt_random.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "native_client/src/nonsfi/irt/irt_interfaces.h" 7 #include "native_client/src/nonsfi/irt/irt_interfaces.h"
8 8
9 #include <assert.h> 9 #include <assert.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 20 matching lines...) Expand all
31 #include "native_client/src/public/irt_core.h" 31 #include "native_client/src/public/irt_core.h"
32 #include "native_client/src/trusted/service_runtime/include/machine/_types.h" 32 #include "native_client/src/trusted/service_runtime/include/machine/_types.h"
33 #include "native_client/src/trusted/service_runtime/include/sys/mman.h" 33 #include "native_client/src/trusted/service_runtime/include/sys/mman.h"
34 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" 34 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
35 #include "native_client/src/trusted/service_runtime/include/sys/time.h" 35 #include "native_client/src/trusted/service_runtime/include/sys/time.h"
36 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" 36 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
37 #include "native_client/src/untrusted/irt/irt.h" 37 #include "native_client/src/untrusted/irt/irt.h"
38 #include "native_client/src/untrusted/irt/irt_dev.h" 38 #include "native_client/src/untrusted/irt/irt_dev.h"
39 #include "native_client/src/untrusted/irt/irt_interfaces.h" 39 #include "native_client/src/untrusted/irt/irt_interfaces.h"
40 40
41 #if defined(__native_client__)
42 #include "native_client/src/nonsfi/irt/irt_random.h"
43 #endif
44
41 /* 45 /*
42 * This is an implementation of NaCl's IRT interfaces that runs 46 * This is an implementation of NaCl's IRT interfaces that runs
43 * outside of the NaCl sandbox. 47 * outside of the NaCl sandbox.
44 * 48 *
45 * This allows PNaCl to be used as a portability layer without the 49 * This allows PNaCl to be used as a portability layer without the
46 * SFI-based sandboxing. PNaCl pexes can be translated to 50 * SFI-based sandboxing. PNaCl pexes can be translated to
47 * non-SFI-sandboxed native code and linked against this IRT 51 * non-SFI-sandboxed native code and linked against this IRT
48 * implementation. 52 * implementation.
49 */ 53 */
50 54
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 static int futex_wake(volatile int *addr, int nwake, int *count) { 428 static int futex_wake(volatile int *addr, int nwake, int *count) {
425 int result = syscall(__NR_futex, addr, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 429 int result = syscall(__NR_futex, addr, FUTEX_WAKE | FUTEX_PRIVATE_FLAG,
426 nwake, 0, 0, 0); 430 nwake, 0, 0, 0);
427 if (result < 0) 431 if (result < 0)
428 return errno; 432 return errno;
429 *count = result; 433 *count = result;
430 return 0; 434 return 0;
431 } 435 }
432 #endif 436 #endif
433 437
438 #if defined(__native_client__)
439 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).
440
441 void nonsfi_set_urandom_fd(int fd) {
442 urandom_fd = fd;
443 }
444
445 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.
446 int result = read(urandom_fd, buf, count);
447 if (result < 0)
448 return errno;
449 *nread = result;
450 return 0;
451 }
452 #endif
453
434 #if defined(__linux__) || defined(__native_client__) 454 #if defined(__linux__) || defined(__native_client__)
435 static int irt_clock_getres(nacl_irt_clockid_t clk_id, 455 static int irt_clock_getres(nacl_irt_clockid_t clk_id,
436 struct timespec *time_nacl) { 456 struct timespec *time_nacl) {
437 struct timespec time; 457 struct timespec time;
438 int result = check_error(clock_getres(clk_id, &time)); 458 int result = check_error(clock_getres(clk_id, &time));
439 /* 459 /*
440 * The timespec pointer is allowed to be NULL for clock_getres() though 460 * The timespec pointer is allowed to be NULL for clock_getres() though
441 * not for clock_gettime(). 461 * not for clock_gettime().
442 */ 462 */
443 if (time_nacl != NULL) 463 if (time_nacl != NULL)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 }; 612 };
593 #elif !defined(__native_client__) 613 #elif !defined(__native_client__)
594 DEFINE_STUB(futex_wait_abs) 614 DEFINE_STUB(futex_wait_abs)
595 DEFINE_STUB(futex_wake) 615 DEFINE_STUB(futex_wake)
596 const struct nacl_irt_futex nacl_irt_futex = { 616 const struct nacl_irt_futex nacl_irt_futex = {
597 USE_STUB(nacl_irt_futex, futex_wait_abs), 617 USE_STUB(nacl_irt_futex, futex_wait_abs),
598 USE_STUB(nacl_irt_futex, futex_wake), 618 USE_STUB(nacl_irt_futex, futex_wake),
599 }; 619 };
600 #endif 620 #endif
601 621
622 #if defined(__native_client__)
623 const struct nacl_irt_random nacl_irt_random = {
624 irt_get_random_bytes,
625 };
626 #endif
627
602 #if defined(__linux__) || defined(__native_client__) 628 #if defined(__linux__) || defined(__native_client__)
603 const struct nacl_irt_clock nacl_irt_clock = { 629 const struct nacl_irt_clock nacl_irt_clock = {
604 irt_clock_getres, 630 irt_clock_getres,
605 irt_clock_gettime, 631 irt_clock_gettime,
606 }; 632 };
607 #endif 633 #endif
608 634
609 DEFINE_STUB(utimes) 635 DEFINE_STUB(utimes)
610 const struct nacl_irt_dev_filename nacl_irt_dev_filename = { 636 const struct nacl_irt_dev_filename nacl_irt_dev_filename = {
611 irt_open, 637 irt_open,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 }; 669 };
644 #endif 670 #endif
645 671
646 static const struct nacl_irt_interface irt_interfaces[] = { 672 static const struct nacl_irt_interface irt_interfaces[] = {
647 { NACL_IRT_BASIC_v0_1, &nacl_irt_basic, sizeof(nacl_irt_basic), NULL }, 673 { NACL_IRT_BASIC_v0_1, &nacl_irt_basic, sizeof(nacl_irt_basic), NULL },
648 { NACL_IRT_FDIO_v0_1, &nacl_irt_fdio, sizeof(nacl_irt_fdio), NULL }, 674 { NACL_IRT_FDIO_v0_1, &nacl_irt_fdio, sizeof(nacl_irt_fdio), NULL },
649 { NACL_IRT_MEMORY_v0_3, &nacl_irt_memory, sizeof(nacl_irt_memory), NULL }, 675 { NACL_IRT_MEMORY_v0_3, &nacl_irt_memory, sizeof(nacl_irt_memory), NULL },
650 { NACL_IRT_TLS_v0_1, &nacl_irt_tls, sizeof(nacl_irt_tls), NULL }, 676 { NACL_IRT_TLS_v0_1, &nacl_irt_tls, sizeof(nacl_irt_tls), NULL },
651 { NACL_IRT_THREAD_v0_1, &nacl_irt_thread, sizeof(nacl_irt_thread), NULL }, 677 { NACL_IRT_THREAD_v0_1, &nacl_irt_thread, sizeof(nacl_irt_thread), NULL },
652 { NACL_IRT_FUTEX_v0_1, &nacl_irt_futex, sizeof(nacl_irt_futex), NULL }, 678 { NACL_IRT_FUTEX_v0_1, &nacl_irt_futex, sizeof(nacl_irt_futex), NULL },
679 #if defined(__native_client__)
680 { NACL_IRT_RANDOM_v0_1, &nacl_irt_random, sizeof(nacl_irt_random), NULL },
681 #endif
653 #if defined(__linux__) || defined(__native_client__) 682 #if defined(__linux__) || defined(__native_client__)
654 { NACL_IRT_CLOCK_v0_1, &nacl_irt_clock, sizeof(nacl_irt_clock), NULL }, 683 { NACL_IRT_CLOCK_v0_1, &nacl_irt_clock, sizeof(nacl_irt_clock), NULL },
655 #endif 684 #endif
656 { NACL_IRT_DEV_FILENAME_v0_3, &nacl_irt_dev_filename, 685 { NACL_IRT_DEV_FILENAME_v0_3, &nacl_irt_dev_filename,
657 sizeof(nacl_irt_dev_filename), NULL }, 686 sizeof(nacl_irt_dev_filename), NULL },
658 { NACL_IRT_DEV_GETPID_v0_1, &nacl_irt_dev_getpid, 687 { NACL_IRT_DEV_GETPID_v0_1, &nacl_irt_dev_getpid,
659 sizeof(nacl_irt_dev_getpid), NULL }, 688 sizeof(nacl_irt_dev_getpid), NULL },
660 #if defined(__native_client__) 689 #if defined(__native_client__)
661 { NACL_IRT_EXCEPTION_HANDLING_v0_1, &nacl_irt_exception_handling, 690 { NACL_IRT_EXCEPTION_HANDLING_v0_1, &nacl_irt_exception_handling,
662 sizeof(nacl_irt_exception_handling), NULL}, 691 sizeof(nacl_irt_exception_handling), NULL},
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 nacl_entry_func_t entry_func = 752 nacl_entry_func_t entry_func =
724 #if defined(__APPLE__) 753 #if defined(__APPLE__)
725 _start; 754 _start;
726 #else 755 #else
727 _user_start; 756 _user_start;
728 #endif 757 #endif
729 758
730 return nacl_irt_nonsfi_entry(argc, argv, environ, entry_func); 759 return nacl_irt_nonsfi_entry(argc, argv, environ, entry_func);
731 } 760 }
732 #endif 761 #endif
OLDNEW
« no previous file with comments | « no previous file | src/nonsfi/irt/irt_random.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698