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

Side by Side Diff: tests/sel_main_chrome/sel_main_chrome_test.cc

Issue 261683002: Make a NaClDesc ctor for creating descs from NaClFileInfo. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: make it posix file descriptor Created 6 years, 7 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/validator/nacl_file_info.h ('k') | no next file » | 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 <fcntl.h> 7 #include <fcntl.h>
8 #include <cstring> 8 #include <cstring>
9 9
10 #if NACL_WINDOWS 10 #if NACL_WINDOWS
11 # include <io.h> 11 # include <io.h>
12 #endif 12 #endif
13 13
14 #include "native_client/src/public/chrome_main.h" 14 #include "native_client/src/public/chrome_main.h"
15 #include "native_client/src/public/nacl_app.h" 15 #include "native_client/src/public/nacl_app.h"
16 #include "native_client/src/public/nacl_file_info.h"
16 #include "native_client/src/shared/platform/nacl_check.h" 17 #include "native_client/src/shared/platform/nacl_check.h"
17 #include "native_client/src/shared/platform/nacl_threads.h" 18 #include "native_client/src/shared/platform/nacl_threads.h"
18 #include "native_client/src/shared/srpc/nacl_srpc.h" 19 #include "native_client/src/shared/srpc/nacl_srpc.h"
19 #include "native_client/src/trusted/desc/nacl_desc_custom.h" 20 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
20 #include "native_client/src/trusted/desc_cacheability/desc_cacheability.h" 21 #include "native_client/src/trusted/desc/nacl_desc_file_info.h"
21 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" 22 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h"
22 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 23 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
23 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" 24 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h"
24 #include "native_client/src/trusted/service_runtime/nacl_config.h" 25 #include "native_client/src/trusted/service_runtime/nacl_config.h"
25 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" 26 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h"
26 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" 27 #include "native_client/src/trusted/service_runtime/sel_addrspace.h"
27 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 28 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
28 #include "native_client/src/trusted/validator/nacl_file_info.h"
29 #include "native_client/src/trusted/validator/validation_cache.h" 29 #include "native_client/src/trusted/validator/validation_cache.h"
30 30
31 31
32 int OpenFileReadOnly(const char *filename) { 32 int OpenFileReadOnly(const char *filename) {
33 #if NACL_WINDOWS 33 #if NACL_WINDOWS
34 return _open(filename, _O_RDONLY); 34 return _open(filename, _O_RDONLY);
35 #else 35 #else
36 return open(filename, O_RDONLY); 36 return open(filename, O_RDONLY);
37 #endif 37 #endif
38 } 38 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 CHECK(h->expected_token_lo == file_token->lo); 117 CHECK(h->expected_token_lo == file_token->lo);
118 CHECK(h->expected_token_hi == file_token->hi); 118 CHECK(h->expected_token_hi == file_token->hi);
119 *fd = h->expected_file_handle; 119 *fd = h->expected_file_handle;
120 *file_path = h->expected_file_path; 120 *file_path = h->expected_file_path;
121 *file_path_length = static_cast<uint32_t>(strlen(h->expected_file_path)); 121 *file_path_length = static_cast<uint32_t>(strlen(h->expected_file_path));
122 return 1; 122 return 1;
123 } 123 }
124 124
125 struct ThreadArgs { 125 struct ThreadArgs {
126 NaClHandle channel; 126 NaClHandle channel;
127 int nexe_fd; 127 NaClFileInfo file_info;
128 NaClFileToken nexe_token;
129 }; 128 };
130 129
131 void WINAPI DummyRendererThread(void *thread_arg) { 130 void WINAPI DummyRendererThread(void *thread_arg) {
132 struct ThreadArgs *args = (struct ThreadArgs *) thread_arg; 131 struct ThreadArgs *args = (struct ThreadArgs *) thread_arg;
133 132
134 nacl::DescWrapperFactory desc_wrapper_factory; 133 nacl::DescWrapperFactory desc_wrapper_factory;
135 nacl::DescWrapper *nexe_desc = 134 struct NaClDesc *desc = NaClDescIoFromFileInfo(args->file_info,
136 desc_wrapper_factory.MakeFileDesc(args->nexe_fd, NACL_ABI_O_RDONLY); 135 NACL_ABI_O_RDONLY);
136 CHECK(desc != NULL);
137 nacl::DescWrapper *nexe_desc = desc_wrapper_factory.MakeGenericCleanup(desc);
137 CHECK(nexe_desc != NULL); 138 CHECK(nexe_desc != NULL);
138 if (args->nexe_token.lo != 0 && args->nexe_token.hi != 0) {
139 int token_res = NaClDescSetFileToken(nexe_desc->desc(), &args->nexe_token);
140 CHECK(token_res != 0);
141 }
142
143 DummyLauncher launcher(args->channel); 139 DummyLauncher launcher(args->channel);
144 NaClSrpcChannel trusted_channel; 140 NaClSrpcChannel trusted_channel;
145 NaClSrpcChannel untrusted_channel; 141 NaClSrpcChannel untrusted_channel;
146 CHECK(launcher.SetupCommandAndLoad(&trusted_channel, nexe_desc)); 142 CHECK(launcher.SetupCommandAndLoad(&trusted_channel, nexe_desc));
147 CHECK(launcher.StartModuleAndSetupAppChannel(&trusted_channel, 143 CHECK(launcher.StartModuleAndSetupAppChannel(&trusted_channel,
148 &untrusted_channel)); 144 &untrusted_channel));
149 } 145 }
150 146
151 void ExampleDescDestroy(void *handle) { 147 void ExampleDescDestroy(void *handle) {
152 UNREFERENCED_PARAMETER(handle); 148 UNREFERENCED_PARAMETER(handle);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 NaClHandleBootstrapArgs(&argc, &argv); 189 NaClHandleBootstrapArgs(&argc, &argv);
194 #if NACL_LINUX 190 #if NACL_LINUX
195 args->prereserved_sandbox_size = g_prereserved_sandbox_size; 191 args->prereserved_sandbox_size = g_prereserved_sandbox_size;
196 #endif 192 #endif
197 193
198 CHECK(argc == 3 || argc == 4); 194 CHECK(argc == 3 || argc == 4);
199 195
200 args->irt_fd = OpenFileReadOnly(argv[1]); 196 args->irt_fd = OpenFileReadOnly(argv[1]);
201 CHECK(args->irt_fd >= 0); 197 CHECK(args->irt_fd >= 0);
202 198
203 thread_args.nexe_fd = OpenFileReadOnly(argv[2]); 199 memset(&thread_args.file_info, 0, sizeof thread_args.file_info);
204 CHECK(thread_args.nexe_fd >= 0); 200 thread_args.file_info.desc = OpenFileReadOnly(argv[2]);
201 CHECK(thread_args.file_info.desc >= 0);
205 NaClFileNameForValgrind(argv[2]); 202 NaClFileNameForValgrind(argv[2]);
206 203
207 NaClHandle socketpair[2]; 204 NaClHandle socketpair[2];
208 CHECK(NaClSocketPair(socketpair) == 0); 205 CHECK(NaClSocketPair(socketpair) == 0);
209 args->imc_bootstrap_handle = socketpair[0]; 206 args->imc_bootstrap_handle = socketpair[0];
210 thread_args.channel = socketpair[1]; 207 thread_args.channel = socketpair[1];
211 208
212 // Check that NaClDescMakeCustomDesc() works when called in this context. 209 // Check that NaClDescMakeCustomDesc() works when called in this context.
213 NaClAppSetDesc(nap, NACL_CHROME_DESC_BASE, MakeExampleDesc()); 210 NaClAppSetDesc(nap, NACL_CHROME_DESC_BASE, MakeExampleDesc());
214 211
215 // Set up mock validation cache. 212 // Set up mock validation cache.
216 struct TestValidationHandle test_handle; 213 struct TestValidationHandle test_handle;
217 struct NaClValidationCache test_cache; 214 struct NaClValidationCache test_cache;
218 if (argc == 4) { 215 if (argc == 4) {
219 CHECK(strcmp(argv[3], "-vcache") == 0); 216 CHECK(strcmp(argv[3], "-vcache") == 0);
220 test_handle.expected_token_lo = 0xabcdef123456789LL; 217 test_handle.expected_token_lo = 0xabcdef123456789LL;
221 test_handle.expected_token_hi = 0x101010101010101LL; 218 test_handle.expected_token_hi = 0x101010101010101LL;
222 test_handle.expected_file_handle = OpenFileHandleReadExec(argv[2]); 219 test_handle.expected_file_handle = OpenFileHandleReadExec(argv[2]);
223 test_handle.expected_file_path = strdup(argv[2]); 220 test_handle.expected_file_path = strdup(argv[2]);
224 test_cache.handle = &test_handle; 221 test_cache.handle = &test_handle;
225 test_cache.CreateQuery = &TestCreateQuery; 222 test_cache.CreateQuery = &TestCreateQuery;
226 test_cache.AddData = &TestAddData; 223 test_cache.AddData = &TestAddData;
227 test_cache.QueryKnownToValidate = &TestQueryKnownToValidate; 224 test_cache.QueryKnownToValidate = &TestQueryKnownToValidate;
228 test_cache.SetKnownToValidate = &TestSetKnownToValidate; 225 test_cache.SetKnownToValidate = &TestSetKnownToValidate;
229 test_cache.DestroyQuery = &TestDestroyQuery; 226 test_cache.DestroyQuery = &TestDestroyQuery;
230 test_cache.CachingIsInexpensive = &TestCachingIsInexpensive; 227 test_cache.CachingIsInexpensive = &TestCachingIsInexpensive;
231 test_cache.ResolveFileToken = &TestResolveFileToken; 228 test_cache.ResolveFileToken = &TestResolveFileToken;
232 args->validation_cache = &test_cache; 229 args->validation_cache = &test_cache;
233 thread_args.nexe_token.lo = test_handle.expected_token_lo; 230 thread_args.file_info.file_token.lo = test_handle.expected_token_lo;
234 thread_args.nexe_token.hi = test_handle.expected_token_hi; 231 thread_args.file_info.file_token.hi = test_handle.expected_token_hi;
235 } else {
236 thread_args.nexe_token.lo = 0;
237 thread_args.nexe_token.hi = 0;
238 } 232 }
239 233
240 NaClThread thread; 234 NaClThread thread;
241 CHECK(NaClThreadCtor(&thread, DummyRendererThread, &thread_args, 235 CHECK(NaClThreadCtor(&thread, DummyRendererThread, &thread_args,
242 NACL_KERN_STACK_SIZE)); 236 NACL_KERN_STACK_SIZE));
243 237
244 NaClChromeMainStartApp(nap, args); 238 NaClChromeMainStartApp(nap, args);
245 NaClLog(LOG_FATAL, "NaClChromeMainStartApp() should never return\n"); 239 NaClLog(LOG_FATAL, "NaClChromeMainStartApp() should never return\n");
246 return 1; 240 return 1;
247 } 241 }
OLDNEW
« no previous file with comments | « src/trusted/validator/nacl_file_info.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698