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

Side by Side Diff: src/trusted/service_runtime/mmap_test.c

Issue 12226119: Factor out duplicated GioMemoryFileSnapshotCtor() + NaClAppLoadFile() calls (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/trusted/service_runtime/load_file.c ('k') | src/trusted/service_runtime/sel_main.c » ('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) 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 "native_client/src/include/portability.h" 7 #include "native_client/src/include/portability.h"
8 8
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <string.h> 10 #include <string.h>
11 #if NACL_LINUX 11 #if NACL_LINUX
12 # include <sys/mman.h> 12 # include <sys/mman.h>
13 #elif NACL_OSX 13 #elif NACL_OSX
14 # include <mach/mach.h> 14 # include <mach/mach.h>
15 #endif 15 #endif
16 16
17 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" 17 #include "native_client/src/trusted/service_runtime/include/bits/mman.h"
18 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 18 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
19 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" 19 #include "native_client/src/trusted/service_runtime/include/sys/errno.h"
20 20
21 #include "native_client/src/include/nacl_assert.h" 21 #include "native_client/src/include/nacl_assert.h"
22 #include "native_client/src/shared/gio/gio.h" 22 #include "native_client/src/trusted/service_runtime/load_file.h"
23 #include "native_client/src/trusted/service_runtime/mmap_test_check.h" 23 #include "native_client/src/trusted/service_runtime/mmap_test_check.h"
24 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" 24 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h"
25 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" 25 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
26 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" 26 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h"
27 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h"
28 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" 27 #include "native_client/src/trusted/service_runtime/sel_addrspace.h"
29 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 28 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
30 29
31 /* 30 /*
32 * Perform some minimal initialisation of the NaClAppThread based on 31 * Perform some minimal initialisation of the NaClAppThread based on
33 * what we need for the test. Reusing NaClAppThreadMake() here is 32 * what we need for the test. Reusing NaClAppThreadMake() here is
34 * difficult because it launches an untrusted thread. 33 * difficult because it launches an untrusted thread.
35 */ 34 */
36 static void InitThread(struct NaClApp *nap, struct NaClAppThread *natp) { 35 static void InitThread(struct NaClApp *nap, struct NaClAppThread *natp) {
37 memset(natp, 0xff, sizeof(*natp)); 36 memset(natp, 0xff, sizeof(*natp));
(...skipping 24 matching lines...) Expand all
62 #elif NACL_OSX 61 #elif NACL_OSX
63 CheckMapping(addr, expected_size, VM_PROT_NONE, SM_EMPTY); 62 CheckMapping(addr, expected_size, VM_PROT_NONE, SM_EMPTY);
64 #else 63 #else
65 # error "Unrecognized OS" 64 # error "Unrecognized OS"
66 #endif 65 #endif
67 } 66 }
68 #endif 67 #endif
69 68
70 int main(int argc, char **argv) { 69 int main(int argc, char **argv) {
71 char *nacl_file; 70 char *nacl_file;
72 struct GioMemoryFileSnapshot gf;
73 struct NaClApp state; 71 struct NaClApp state;
74 struct NaClApp *nap = &state; 72 struct NaClApp *nap = &state;
75 struct NaClAppThread nat, *natp = &nat; 73 struct NaClAppThread nat, *natp = &nat;
76 int errcode; 74 int errcode;
77 uint32_t initial_addr; 75 uint32_t initial_addr;
78 uint32_t addr; 76 uint32_t addr;
79 struct NaClVmmap *mem_map; 77 struct NaClVmmap *mem_map;
80 struct NaClVmmapEntry *ent; 78 struct NaClVmmapEntry *ent;
81 char *nacl_verbosity = getenv("NACLVERBOSITY"); 79 char *nacl_verbosity = getenv("NACLVERBOSITY");
82 80
83 NaClHandleBootstrapArgs(&argc, &argv); 81 NaClHandleBootstrapArgs(&argc, &argv);
84 82
85 if (argc < 2) { 83 if (argc < 2) {
86 printf("No nexe file!\n\nFAIL\n"); 84 printf("No nexe file!\n\nFAIL\n");
87 } 85 }
88 nacl_file = argv[1]; 86 nacl_file = argv[1];
89 87
90 NaClAllModulesInit(); 88 NaClAllModulesInit();
91 89
92 NaClLogSetVerbosity((NULL == nacl_verbosity) 90 NaClLogSetVerbosity((NULL == nacl_verbosity)
93 ? 0 91 ? 0
94 : strtol(nacl_verbosity, (char **) 0, 0)); 92 : strtol(nacl_verbosity, (char **) 0, 0));
95 93
96 NaClFileNameForValgrind(nacl_file);
97 errcode = GioMemoryFileSnapshotCtor(&gf, nacl_file);
98 ASSERT_NE(errcode, 0);
99 errcode = NaClAppCtor(&state); 94 errcode = NaClAppCtor(&state);
100 ASSERT_NE(errcode, 0); 95 ASSERT_NE(errcode, 0);
101 errcode = NaClAppLoadFile((struct Gio *) &gf, 96 errcode = NaClAppLoadFileFromFilename(nap, nacl_file);
102 &state); 97 ASSERT_EQ(errcode, LOAD_OK);
103 ASSERT_EQ(errcode, 0);
104 98
105 InitThread(&state, natp); 99 InitThread(&state, natp);
106 100
107 /* 101 /*
108 * Initial mappings: 102 * Initial mappings:
109 * 0. -- Zero page 103 * 0. -- Zero page
110 * 1. rx Static code segment 104 * 1. rx Static code segment
111 * 2. r Read-only data segment 105 * 2. r Read-only data segment
112 * 3. rw Writable data segment 106 * 3. rw Writable data segment
113 * 4. rw Stack 107 * 4. rw Stack
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64 454 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64
461 CheckForGuardRegion(nap->mem_start - ((size_t) 40 << 30), (size_t) 40 << 30); 455 CheckForGuardRegion(nap->mem_start - ((size_t) 40 << 30), (size_t) 40 << 30);
462 CheckForGuardRegion(nap->mem_start + ((size_t) 4 << 30), (size_t) 40 << 30); 456 CheckForGuardRegion(nap->mem_start + ((size_t) 4 << 30), (size_t) 40 << 30);
463 #endif 457 #endif
464 458
465 NaClAddrSpaceFree(nap); 459 NaClAddrSpaceFree(nap);
466 460
467 printf("PASS\n"); 461 printf("PASS\n");
468 return 0; 462 return 0;
469 } 463 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/load_file.c ('k') | src/trusted/service_runtime/sel_main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698