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

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: size_t? 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 <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
8 12
9 #include "native_client/src/untrusted/irt/irt.h" 13 #include "native_client/src/untrusted/irt/irt.h"
10 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" 14 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
11 15
16 /*
17 * An open_resource implementation used for testing PNaCl's sandboxed
18 * translator (the linker), outside of Chromium.
19 *
20 * This code will prepend the |base_dir| to |pathname|. That is useful if,
21 * say, |pathname| is the basename of a library, and |base_dir| is a directory.
22 * holding library files. The |base_dir| is assumed to already have a
23 * separator char at the end.
24 *
25 * PNaCl's sandboxed linker also has hardcoded the name of a shim library.
26 * That will open the Chromium PPAPI shim when used with Chromium, but when
27 * testing outside of Chromium we want to open a dummy shim library instead.
28 * |file_remap| is used to redirect the hardcoded shim library name to the
29 * dummy shim. This is specified as an environment variable, e.g.:
30 * "NACL_IRT_OPEN_RESOURCE_REMAPPED=lib_orig.a:lib_dummy.a"
31 */
32 static int nacl_irt_open_resource_remapped(const char *pathname,
33 const char *base_dir,
34 const char *file_remap) {
35 if (file_remap != NULL) {
36 const char *delim_ptr = strchr(file_remap, ':');
37 size_t remap_from_len = delim_ptr - file_remap;
38 if (delim_ptr != NULL) {
39 if (strncmp(pathname, file_remap, remap_from_len) == 0 &&
jvoung (off chromium) 2014/12/02 16:24:08 Had to revert this little bit to what I had in an
40 strlen(pathname) == remap_from_len) {
41 pathname = delim_ptr + 1;
42 }
43 } else {
44 fprintf(
45 stderr,
46 "NACL_IRT_OPEN_RESOURCE_REMAP expects <from>:<to> instead of %s\n",
47 file_remap);
48 abort();
49 }
50 }
51 size_t base_len = strlen(base_dir);
52 size_t pathname_len = strlen(pathname);
53 char *merged_path = (char *) malloc(
54 sizeof(char) * (base_len + pathname_len + 1));
55 if (merged_path == NULL) {
56 errno = ENOMEM;
57 return -1;
58 }
59 strcpy(merged_path, base_dir);
60 strcat(merged_path, pathname);
61 int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(merged_path, O_RDONLY, 0));
62 free(merged_path);
63 return rv;
64 }
65
12 static int nacl_irt_open_resource(const char *pathname, int *newfd) { 66 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)); 67 char *base_dir = getenv("NACL_IRT_OPEN_RESOURCE_BASE");
68 char *file_remap = getenv("NACL_IRT_OPEN_RESOURCE_REMAP");
69 int rv;
70 if (base_dir == NULL) {
71 rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0));
72 } else {
73 rv = nacl_irt_open_resource_remapped(pathname, base_dir, file_remap);
74 }
14 if (rv < 0) 75 if (rv < 0)
15 return -rv; 76 return -rv;
16 *newfd = rv; 77 *newfd = rv;
17 return 0; 78 return 0;
18 } 79 }
19 80
20 const struct nacl_irt_resource_open nacl_irt_resource_open = { 81 const struct nacl_irt_resource_open nacl_irt_resource_open = {
21 nacl_irt_open_resource, 82 nacl_irt_open_resource,
22 }; 83 };
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