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

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