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

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: rebase 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
« no previous file with comments | « pnacl/driver/pnacl-translate.py ('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) 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
Mark Seaborn 2014/12/02 00:42:07 Nit: "open resource" -> "open_resource()"
jvoung (off chromium) 2014/12/02 16:24:08 Done.
18 * translator (the linker), outside of chromium.
Mark Seaborn 2014/12/02 00:42:07 Nit: capitalise as "Chromium"
jvoung (off chromium) 2014/12/02 16:24:08 Done.
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 if (delim_ptr != NULL) {
38 if (strcmp(pathname, file_remap) == 0) {
39 pathname = delim_ptr + 1;
40 }
41 } else {
42 fprintf(
43 stderr,
44 "NACL_IRT_OPEN_RESOURCE_REMAP expects <from>:<to> instead of %s\n",
45 file_remap);
46 abort();
47 }
48 }
49 size_t base_len = strlen(base_dir);
50 size_t pathname_len = strlen(pathname);
51 char *merged_path = (char *)malloc(
Mark Seaborn 2014/12/02 00:42:07 Nit: add space after "(char *)"
jvoung (off chromium) 2014/12/02 16:24:08 Done.
52 sizeof(char) * (base_len + pathname_len + 1));
53 if (merged_path == NULL) {
54 errno = ENOMEM;
55 return -1;
56 }
57 merged_path[0] = '\0';
Mark Seaborn 2014/12/02 00:42:07 Use strcpy() instead of this + strcat()?
jvoung (off chromium) 2014/12/02 16:24:08 Done.
58 strcat(merged_path, base_dir);
59 strcat(merged_path, pathname);
60 int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(merged_path, O_RDONLY, 0));
61 free(merged_path);
62 return rv;
63 }
64
12 static int nacl_irt_open_resource(const char *pathname, int *newfd) { 65 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)); 66 char *base_dir = getenv("NACL_IRT_OPEN_RESOURCE_BASE");
67 char *file_remap = getenv("NACL_IRT_OPEN_RESOURCE_REMAP");
68 int rv;
69 if (base_dir == NULL) {
70 rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0));
71 } else {
72 rv = nacl_irt_open_resource_remapped(pathname, base_dir, file_remap);
73 }
14 if (rv < 0) 74 if (rv < 0)
15 return -rv; 75 return -rv;
16 *newfd = rv; 76 *newfd = rv;
17 return 0; 77 return 0;
18 } 78 }
19 79
20 const struct nacl_irt_resource_open nacl_irt_resource_open = { 80 const struct nacl_irt_resource_open nacl_irt_resource_open = {
21 nacl_irt_open_resource, 81 nacl_irt_open_resource,
22 }; 82 };
OLDNEW
« no previous file with comments | « pnacl/driver/pnacl-translate.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698