OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 /* | 9 /* |
10 * NaCl Simple/secure ELF loader (NaCl SEL). | 10 * NaCl Simple/secure ELF loader (NaCl SEL). |
11 */ | 11 */ |
12 #include "native_client/src/include/portability.h" | 12 #include "native_client/src/include/portability.h" |
13 #include "native_client/src/include/portability_io.h" | 13 #include "native_client/src/include/portability_io.h" |
14 #include "native_client/src/include/portability_string.h" | 14 #include "native_client/src/include/portability_string.h" |
15 #include "native_client/src/include/nacl_macros.h" | 15 #include "native_client/src/include/nacl_macros.h" |
16 | 16 |
17 #include "native_client/src/public/desc_metadata_types.h" | 17 #include "native_client/src/public/desc_metadata_types.h" |
| 18 #include "native_client/src/public/nacl_app.h" |
18 #include "native_client/src/public/secure_service.h" | 19 #include "native_client/src/public/secure_service.h" |
19 | 20 |
20 #include "native_client/src/shared/gio/gio.h" | 21 #include "native_client/src/shared/gio/gio.h" |
21 #include "native_client/src/shared/platform/nacl_check.h" | 22 #include "native_client/src/shared/platform/nacl_check.h" |
22 #include "native_client/src/shared/platform/nacl_exit.h" | 23 #include "native_client/src/shared/platform/nacl_exit.h" |
23 #include "native_client/src/shared/platform/nacl_log.h" | 24 #include "native_client/src/shared/platform/nacl_log.h" |
24 #include "native_client/src/shared/platform/nacl_sync.h" | 25 #include "native_client/src/shared/platform/nacl_sync.h" |
25 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 26 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
26 #include "native_client/src/shared/platform/nacl_time.h" | 27 #include "native_client/src/shared/platform/nacl_time.h" |
27 #include "native_client/src/shared/srpc/nacl_srpc.h" | 28 #include "native_client/src/shared/srpc/nacl_srpc.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 72 } |
72 | 73 |
73 static int ShouldEnableDynamicLoading(void) { | 74 static int ShouldEnableDynamicLoading(void) { |
74 return !IsEnvironmentVariableSet("NACL_DISABLE_DYNAMIC_LOADING"); | 75 return !IsEnvironmentVariableSet("NACL_DISABLE_DYNAMIC_LOADING"); |
75 } | 76 } |
76 | 77 |
77 int NaClAppWithSyscallTableCtor(struct NaClApp *nap, | 78 int NaClAppWithSyscallTableCtor(struct NaClApp *nap, |
78 struct NaClSyscallTableEntry *table) { | 79 struct NaClSyscallTableEntry *table) { |
79 struct NaClDescEffectorLdr *effp; | 80 struct NaClDescEffectorLdr *effp; |
80 | 81 |
| 82 /* Zero-initialize in case we miss any fields below. */ |
| 83 memset(nap, 0, sizeof(*nap)); |
| 84 |
81 /* The validation cache will be injected later, if it exists. */ | 85 /* The validation cache will be injected later, if it exists. */ |
82 nap->validation_cache = NULL; | 86 nap->validation_cache = NULL; |
83 | 87 |
84 nap->validator = NaClCreateValidator(); | 88 nap->validator = NaClCreateValidator(); |
85 | 89 |
86 /* Get the set of features that the CPU we're running on supports. */ | 90 /* Get the set of features that the CPU we're running on supports. */ |
87 /* These may be adjusted later in sel_main.c for fixed-feature CPU mode. */ | 91 /* These may be adjusted later in sel_main.c for fixed-feature CPU mode. */ |
88 nap->cpu_features = (NaClCPUFeatures *) malloc( | 92 nap->cpu_features = (NaClCPUFeatures *) malloc( |
89 nap->validator->CPUFeatureSize); | 93 nap->validator->CPUFeatureSize); |
90 if (NULL == nap->cpu_features) { | 94 if (NULL == nap->cpu_features) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 cleanup_cpu_features: | 330 cleanup_cpu_features: |
327 free(nap->cpu_features); | 331 free(nap->cpu_features); |
328 cleanup_none: | 332 cleanup_none: |
329 return 0; | 333 return 0; |
330 } | 334 } |
331 | 335 |
332 int NaClAppCtor(struct NaClApp *nap) { | 336 int NaClAppCtor(struct NaClApp *nap) { |
333 return NaClAppWithSyscallTableCtor(nap, nacl_syscall); | 337 return NaClAppWithSyscallTableCtor(nap, nacl_syscall); |
334 } | 338 } |
335 | 339 |
| 340 struct NaClApp *NaClAppCreate(void) { |
| 341 struct NaClApp *nap = malloc(sizeof(struct NaClApp)); |
| 342 if (nap == NULL) |
| 343 NaClLog(LOG_FATAL, "Failed to allocate NaClApp\n"); |
| 344 if (!NaClAppCtor(nap)) |
| 345 NaClLog(LOG_FATAL, "NaClAppCtor() failed\n"); |
| 346 return nap; |
| 347 } |
| 348 |
336 /* | 349 /* |
337 * unaligned little-endian load. precondition: nbytes should never be | 350 * unaligned little-endian load. precondition: nbytes should never be |
338 * more than 8. | 351 * more than 8. |
339 */ | 352 */ |
340 static uint64_t NaClLoadMem(uintptr_t addr, | 353 static uint64_t NaClLoadMem(uintptr_t addr, |
341 size_t user_nbytes) { | 354 size_t user_nbytes) { |
342 uint64_t value = 0; | 355 uint64_t value = 0; |
343 | 356 |
344 CHECK(0 != user_nbytes && user_nbytes <= 8); | 357 CHECK(0 != user_nbytes && user_nbytes <= 8); |
345 | 358 |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 nacl_global_xlate_base = mem_start; | 1337 nacl_global_xlate_base = mem_start; |
1325 | 1338 |
1326 NaClSandboxMemoryStartForValgrind(mem_start); | 1339 NaClSandboxMemoryStartForValgrind(mem_start); |
1327 | 1340 |
1328 _ovly_debug_event(); | 1341 _ovly_debug_event(); |
1329 } | 1342 } |
1330 | 1343 |
1331 void NaClGdbHook(struct NaClApp const *nap) { | 1344 void NaClGdbHook(struct NaClApp const *nap) { |
1332 StopForDebuggerInit(nap->mem_start); | 1345 StopForDebuggerInit(nap->mem_start); |
1333 } | 1346 } |
OLD | NEW |