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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pnacl/driver/pnacl-translate.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/untrusted/irt/irt_core_resource.c
diff --git a/src/untrusted/irt/irt_core_resource.c b/src/untrusted/irt/irt_core_resource.c
index eb0ceebaafadd5647363e236bf8863059182f9b9..b591a1ecef41facd771aa2f3ec65a36d27007568 100644
--- a/src/untrusted/irt/irt_core_resource.c
+++ b/src/untrusted/irt/irt_core_resource.c
@@ -4,13 +4,73 @@
* found in the LICENSE file.
*/
+#include <errno.h>
#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "native_client/src/untrusted/irt/irt.h"
#include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
+/*
+ * 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.
+ * 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.
+ *
+ * This code will prepend the |base_dir| to |pathname|. That is useful if,
+ * say, |pathname| is the basename of a library, and |base_dir| is a directory.
+ * holding library files. The |base_dir| is assumed to already have a
+ * separator char at the end.
+ *
+ * PNaCl's sandboxed linker also has hardcoded the name of a shim library.
+ * That will open the chromium PPAPI shim when used with chromium, but when
+ * testing outside of chromium we want to open a dummy shim library instead.
+ * |file_remap| is used to redirect the hardcoded shim library name to the
+ * dummy shim. This is specified as an environment variable, e.g.:
+ * "NACL_IRT_OPEN_RESOURCE_REMAPPED=lib_orig.a:lib_dummy.a"
+ */
+static int nacl_irt_open_resource_remapped(const char *pathname,
+ const char *base_dir,
+ const char *file_remap) {
+ if (file_remap != NULL) {
+ const char *delim_ptr = strchr(file_remap, ':');
+ if (delim_ptr != NULL) {
+ if (strcmp(pathname, file_remap) == 0) {
+ pathname = delim_ptr + 1;
+ }
+ } else {
+ fprintf(
+ stderr,
+ "NACL_IRT_OPEN_RESOURCE_REMAP expects <from>:<to> instead of %s\n",
+ file_remap);
+ abort();
+ }
+ }
+ size_t base_len = strlen(base_dir);
+ size_t pathname_len = strlen(pathname);
+ 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.
+ sizeof(char) * (base_len + pathname_len + 1));
+ if (merged_path == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ 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.
+ strcat(merged_path, base_dir);
+ strcat(merged_path, pathname);
+ int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(merged_path, O_RDONLY, 0));
+ free(merged_path);
+ return rv;
+}
+
static int nacl_irt_open_resource(const char *pathname, int *newfd) {
- int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0));
+ char *base_dir = getenv("NACL_IRT_OPEN_RESOURCE_BASE");
+ char *file_remap = getenv("NACL_IRT_OPEN_RESOURCE_REMAP");
+ int rv;
+ if (base_dir == NULL) {
+ rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0));
+ } else {
+ rv = nacl_irt_open_resource_remapped(pathname, base_dir, file_remap);
+ }
if (rv < 0)
return -rv;
*newfd = rv;
« 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