| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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 /* | 7 /* |
| 8 * NaCl Simple/secure ELF loader (NaCl SEL). | 8 * NaCl Simple/secure ELF loader (NaCl SEL). |
| 9 */ | 9 */ |
| 10 #include "native_client/src/include/portability.h" | 10 #include "native_client/src/include/portability.h" |
| 11 #include "native_client/src/include/portability_io.h" | 11 #include "native_client/src/include/portability_io.h" |
| 12 | 12 |
| 13 #if NACL_OSX |
| 14 #include <crt_externs.h> |
| 15 #endif |
| 16 |
| 13 #include <errno.h> | 17 #include <errno.h> |
| 14 #include <limits.h> | 18 #include <limits.h> |
| 15 #include <stdio.h> | 19 #include <stdio.h> |
| 16 #include <stdlib.h> | 20 #include <stdlib.h> |
| 17 #include <string.h> | 21 #include <string.h> |
| 18 | 22 |
| 19 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm || NACL_SANDBOX_FIXED_AT_ZERO == 1 | 23 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm || NACL_SANDBOX_FIXED_AT_ZERO == 1 |
| 20 /* Required for our use of mallopt -- see below. */ | 24 /* Required for our use of mallopt -- see below. */ |
| 21 #include <malloc.h> | 25 #include <malloc.h> |
| 22 #endif | 26 #endif |
| 23 | 27 |
| 24 #include "native_client/src/shared/gio/gio.h" | 28 #include "native_client/src/shared/gio/gio.h" |
| 25 #include "native_client/src/shared/imc/nacl_imc_c.h" | 29 #include "native_client/src/shared/imc/nacl_imc_c.h" |
| 26 #include "native_client/src/shared/platform/nacl_check.h" | 30 #include "native_client/src/shared/platform/nacl_check.h" |
| 27 #include "native_client/src/shared/platform/nacl_exit.h" | 31 #include "native_client/src/shared/platform/nacl_exit.h" |
| 28 #include "native_client/src/shared/platform/nacl_log.h" | 32 #include "native_client/src/shared/platform/nacl_log.h" |
| 29 #include "native_client/src/shared/platform/nacl_sync.h" | 33 #include "native_client/src/shared/platform/nacl_sync.h" |
| 30 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 34 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 31 #include "native_client/src/shared/srpc/nacl_srpc.h" | 35 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 32 | 36 |
| 33 #include "native_client/src/trusted/perf_counter/nacl_perf_counter.h" | 37 #include "native_client/src/trusted/perf_counter/nacl_perf_counter.h" |
| 38 #include "native_client/src/trusted/service_runtime/env_cleanser.h" |
| 34 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 39 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 35 #include "native_client/src/trusted/service_runtime/nacl_app.h" | 40 #include "native_client/src/trusted/service_runtime/nacl_app.h" |
| 36 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" | 41 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" |
| 37 #include "native_client/src/trusted/service_runtime/nacl_config_dangerous.h" | 42 #include "native_client/src/trusted/service_runtime/nacl_config_dangerous.h" |
| 38 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 43 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
| 39 #include "native_client/src/trusted/service_runtime/nacl_signal.h" | 44 #include "native_client/src/trusted/service_runtime/nacl_signal.h" |
| 40 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 45 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
| 41 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" | 46 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" |
| 42 #include "native_client/src/trusted/service_runtime/outer_sandbox.h" | 47 #include "native_client/src/trusted/service_runtime/outer_sandbox.h" |
| 43 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 48 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 int log_desc; | 190 int log_desc; |
| 186 int verbosity = 0; | 191 int verbosity = 0; |
| 187 int fuzzing_quit_after_load = 0; | 192 int fuzzing_quit_after_load = 0; |
| 188 int debug_mode_bypass_acl_checks = 0; | 193 int debug_mode_bypass_acl_checks = 0; |
| 189 int debug_mode_ignore_validator = 0; | 194 int debug_mode_ignore_validator = 0; |
| 190 int stub_out_mode = 0; | 195 int stub_out_mode = 0; |
| 191 int skip_qualification = 0; | 196 int skip_qualification = 0; |
| 192 int enable_debug_stub = 0; | 197 int enable_debug_stub = 0; |
| 193 int handle_signals = 0; | 198 int handle_signals = 0; |
| 194 struct NaClPerfCounter time_all_main; | 199 struct NaClPerfCounter time_all_main; |
| 200 const char **envp; |
| 201 struct NaClEnvCleanser env_cleanser; |
| 195 | 202 |
| 196 | 203 |
| 197 const char* sandbox_fd_string; | 204 const char* sandbox_fd_string; |
| 198 | 205 |
| 206 #if NACL_OSX |
| 207 /* Mac dynamic libraries cannot access the environ variable directly. */ |
| 208 envp = (const char **) *_NSGetEnviron(); |
| 209 #else |
| 210 /* Overzealous code style check is overzealous. */ |
| 211 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */ |
| 212 extern char **environ; |
| 213 envp = (const char **) environ; |
| 214 #endif |
| 215 |
| 199 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm || NACL_SANDBOX_FIXED_AT_ZERO == 1 | 216 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm || NACL_SANDBOX_FIXED_AT_ZERO == 1 |
| 200 /* | 217 /* |
| 201 * Set malloc not to use mmap even for large allocations. This is currently | 218 * Set malloc not to use mmap even for large allocations. This is currently |
| 202 * necessary when we must use a specific area of RAM for the sandbox. | 219 * necessary when we must use a specific area of RAM for the sandbox. |
| 203 * | 220 * |
| 204 * During startup, before the sandbox is set up, the sel_ldr allocates a chunk | 221 * During startup, before the sandbox is set up, the sel_ldr allocates a chunk |
| 205 * of memory to store the untrusted code. Normally such an allocation would | 222 * of memory to store the untrusted code. Normally such an allocation would |
| 206 * go into the sel_ldr's heap area, but the allocation is typically large -- | 223 * go into the sel_ldr's heap area, but the allocation is typically large -- |
| 207 * at least hundreds of KiB. The default malloc configuration on Linux (at | 224 * at least hundreds of KiB. The default malloc configuration on Linux (at |
| 208 * least) switches to mmap for such allocations, and mmap will select | 225 * least) switches to mmap for such allocations, and mmap will select |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 "Not running app code since errcode is %s (%d)\n", | 804 "Not running app code since errcode is %s (%d)\n", |
| 788 NaClErrorString(errcode), | 805 NaClErrorString(errcode), |
| 789 errcode); | 806 errcode); |
| 790 goto done; | 807 goto done; |
| 791 } | 808 } |
| 792 | 809 |
| 793 if (!DynArraySet(&env_vars, env_vars.num_entries, NULL)) { | 810 if (!DynArraySet(&env_vars, env_vars.num_entries, NULL)) { |
| 794 NaClLog(LOG_FATAL, "Adding env_vars NULL terminator failed\n"); | 811 NaClLog(LOG_FATAL, "Adding env_vars NULL terminator failed\n"); |
| 795 } | 812 } |
| 796 | 813 |
| 814 NaClEnvCleanserCtor(&env_cleanser, 0); |
| 815 if (!NaClEnvCleanserInit(&env_cleanser, envp, |
| 816 (char const *const *)env_vars.ptr_array)) { |
| 817 NaClLog(LOG_FATAL, "Failed to initialise env cleanser\n"); |
| 818 } |
| 819 |
| 797 /* | 820 /* |
| 798 * only nap->ehdrs.e_entry is usable, no symbol table is | 821 * only nap->ehdrs.e_entry is usable, no symbol table is |
| 799 * available. | 822 * available. |
| 800 */ | 823 */ |
| 801 if (!NaClCreateMainThread(nap, | 824 if (!NaClCreateMainThread(nap, |
| 802 argc - optind, | 825 argc - optind, |
| 803 argv + optind, | 826 argv + optind, |
| 804 (const char **) env_vars.ptr_array)) { | 827 NaClEnvCleanserEnvironment(&env_cleanser))) { |
| 805 fprintf(stderr, "creating main thread failed\n"); | 828 fprintf(stderr, "creating main thread failed\n"); |
| 806 goto done; | 829 goto done; |
| 807 } | 830 } |
| 831 |
| 832 NaClEnvCleanserDtor(&env_cleanser); |
| 833 |
| 808 NaClPerfCounterMark(&time_all_main, "CreateMainThread"); | 834 NaClPerfCounterMark(&time_all_main, "CreateMainThread"); |
| 809 NaClPerfCounterIntervalLast(&time_all_main); | 835 NaClPerfCounterIntervalLast(&time_all_main); |
| 810 DynArrayDtor(&env_vars); | 836 DynArrayDtor(&env_vars); |
| 811 | 837 |
| 812 ret_code = NaClWaitForMainThreadToExit(nap); | 838 ret_code = NaClWaitForMainThreadToExit(nap); |
| 813 NaClPerfCounterMark(&time_all_main, "WaitForMainThread"); | 839 NaClPerfCounterMark(&time_all_main, "WaitForMainThread"); |
| 814 NaClPerfCounterIntervalLast(&time_all_main); | 840 NaClPerfCounterIntervalLast(&time_all_main); |
| 815 | 841 |
| 816 NaClPerfCounterMark(&time_all_main, "SelMainEnd"); | 842 NaClPerfCounterMark(&time_all_main, "SelMainEnd"); |
| 817 NaClPerfCounterIntervalTotal(&time_all_main); | 843 NaClPerfCounterIntervalTotal(&time_all_main); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 844 if (handle_signals) NaClSignalHandlerFini(); | 870 if (handle_signals) NaClSignalHandlerFini(); |
| 845 NaClAllModulesFini(); | 871 NaClAllModulesFini(); |
| 846 | 872 |
| 847 WINDOWS_EXCEPTION_CATCH; | 873 WINDOWS_EXCEPTION_CATCH; |
| 848 | 874 |
| 849 NaClExit(ret_code); | 875 NaClExit(ret_code); |
| 850 | 876 |
| 851 /* Unreachable, but having the return prevents a compiler error. */ | 877 /* Unreachable, but having the return prevents a compiler error. */ |
| 852 return ret_code; | 878 return ret_code; |
| 853 } | 879 } |
| OLD | NEW |