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

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: 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 side-by-side diff with in-line comments
Download patch
« pnacl/driver/pnacl-translate.py ('K') | « 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..1442b6551bc44f890064e0a3ac58fb4aa48a02c3 100644
--- a/src/untrusted/irt/irt_core_resource.c
+++ b/src/untrusted/irt/irt_core_resource.c
@@ -4,13 +4,59 @@
* found in the LICENSE file.
*/
+#include <errno.h>
#include <fcntl.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"
+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.
+ const char *base_dir,
+ const char *file_remap) {
+ const size_t max_path_len = 2047;
+ 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.
+ size_t base_len;
+ size_t pathname_len;
+ /*
+ * Map the file name if there is a request to do so. This is for mapping
+ * the PNaCl libpnacl_irt_shim.a -> libpnacl_irt_shim_dummy.a.
+ */
+ if (file_remap) {
Mark Seaborn 2014/12/01 20:54:17 Add "!= NULL"
jvoung (off chromium) 2014/12/01 22:00:09 Done.
+ const char *delim_ptr = strchr(file_remap, ':');
+ if (delim_ptr) {
Mark Seaborn 2014/12/01 20:54:17 Add "!= NULL"
jvoung (off chromium) 2014/12/01 22:00:09 Done.
+ ptrdiff_t remap_from_len = delim_ptr - file_remap;
+ if (remap_from_len > max_path_len) {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ if (strncmp(pathname, file_remap, remap_from_len) == 0 &&
+ strlen(pathname) == remap_from_len) {
+ pathname = delim_ptr + 1;
+ }
+ }
+ }
+ base_len = strnlen(base_dir, max_path_len);
+ pathname_len = strnlen(pathname, max_path_len);
+ if (pathname_len + base_len > max_path_len) {
+ 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. :-)
+ return -1;
+ }
+ strncat(merged_path, base_dir, max_path_len);
+ strncat(merged_path, pathname, max_path_len - base_len);
+ return NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(merged_path, O_RDONLY, 0));
+}
+
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) {
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.
+ rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, O_RDONLY, 0));
+ } else {
+ rv = nacl_irt_open_resource_remapped(pathname, newfd, base_dir, file_remap);
+ }
if (rv < 0)
return -rv;
*newfd = rv;
« 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