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

Side by Side Diff: src/untrusted/irt/irt_core_resource.c

Issue 731423004: Add options for base dir and redirecting files to IRT open resource and use it. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: uncomment assert Created 6 years 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) 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 #include <errno.h>
7 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdlib.h>
10 #include <string.h>
8 11
9 #include "native_client/src/untrusted/irt/irt.h" 12 #include "native_client/src/untrusted/irt/irt.h"
10 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" 13 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
11 14
15 static int nacl_irt_open_resource_remapped(const char *pathname, int *newfd,
Mark Seaborn 2014/12/01 20:54:17 Can you add a comment explaining what this is for?
jvoung (off chromium) 2014/12/01 22:00:09 Done.
16 const char *base_dir,
17 const char *file_remap) {
18 const size_t max_path_len = 2047;
19 char merged_path[2048] = "\0";
Mark Seaborn 2014/12/01 20:54:17 You can declare this and the others closer to wher
jvoung (off chromium) 2014/12/01 22:00:09 Done.
20 size_t base_len;
21 size_t pathname_len;
22 /*
23 * Map the file name if there is a request to do so. This is for mapping
24 * the PNaCl libpnacl_irt_shim.a -> libpnacl_irt_shim_dummy.a.
25 */
26 if (file_remap) {
Mark Seaborn 2014/12/01 20:54:17 Add "!= NULL"
jvoung (off chromium) 2014/12/01 22:00:09 Done.
27 const char *delim_ptr = strchr(file_remap, ':');
28 if (delim_ptr) {
Mark Seaborn 2014/12/01 20:54:17 Add "!= NULL"
jvoung (off chromium) 2014/12/01 22:00:09 Done.
29 ptrdiff_t remap_from_len = delim_ptr - file_remap;
30 if (remap_from_len > max_path_len) {
31 errno = ENAMETOOLONG;
32 return -1;
33 }
34 if (strncmp(pathname, file_remap, remap_from_len) == 0 &&
35 strlen(pathname) == remap_from_len) {
36 pathname = delim_ptr + 1;
37 }
38 }
39 }
40 base_len = strnlen(base_dir, max_path_len);
41 pathname_len = strnlen(pathname, max_path_len);
42 if (pathname_len + base_len > max_path_len) {
43 errno = ENAMETOOLONG;
Mark Seaborn 2014/12/01 20:54:17 Suggestion: Would it be easier to use VLAs, malloc
jvoung (off chromium) 2014/12/01 22:00:10 Okay, I'll just use malloc. re: c++'s std::string
Mark Seaborn 2014/12/02 00:42:07 Using malloc() is a good compromise, I think. :-)
44 return -1;
45 }
46 strncat(merged_path, base_dir, max_path_len);
47 strncat(merged_path, pathname, max_path_len - base_len);
48 return NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(merged_path, O_RDONLY, 0));
49 }
50
12 static int nacl_irt_open_resource(const char *pathname, int *newfd) { 51 static int nacl_irt_open_resource(const char *pathname, int *newfd) {
13 int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0)); 52 char *base_dir = getenv("NACL_IRT_OPEN_RESOURCE_BASE");
53 char *file_remap = getenv("NACL_IRT_OPEN_RESOURCE_REMAP");
54 int rv;
55 if (!base_dir) {
Mark Seaborn 2014/12/01 20:54:17 NaCl style is "if (base_dir == NULL)" (no implicit
jvoung (off chromium) 2014/12/01 22:00:09 Done.
56 rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0));
57 } else {
58 rv = nacl_irt_open_resource_remapped(pathname, newfd, base_dir, file_remap);
59 }
14 if (rv < 0) 60 if (rv < 0)
15 return -rv; 61 return -rv;
16 *newfd = rv; 62 *newfd = rv;
17 return 0; 63 return 0;
18 } 64 }
19 65
20 const struct nacl_irt_resource_open nacl_irt_resource_open = { 66 const struct nacl_irt_resource_open nacl_irt_resource_open = {
21 nacl_irt_open_resource, 67 nacl_irt_open_resource,
22 }; 68 };
OLDNEW
« pnacl/driver/pnacl-translate.py ('K') | « pnacl/driver/pnacl-translate.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698