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

Unified Diff: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc

Issue 99203014: [NaCl SDK] Map active fds to absolute paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Map active fds to absolute paths. Created 6 years, 11 months 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
Index: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
index 672f51c30825aa1c9a8b4febf07f1047128e7b0c..298820026dcc3817d4a6f879d298c9923748f802 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
@@ -172,7 +172,8 @@ int KernelProxy::open_resource(const char* path) {
return -1;
}
- return AllocateFD(handle);
+ int fd = AllocateFD(handle, path);
binji 2014/01/07 21:40:29 return AllocateFD(handle, path); is fine. Here an
+ return fd;
}
int KernelProxy::open(const char* path, int open_flags) {
@@ -192,7 +193,8 @@ int KernelProxy::open(const char* path, int open_flags) {
return -1;
}
- return AllocateFD(handle);
+ int fd = AllocateFD(handle, path);
+ return fd;
}
int KernelProxy::pipe(int pipefds[2]) {
@@ -209,8 +211,8 @@ int KernelProxy::pipe(int pipefds[2]) {
return -1;
}
- pipefds[0] = AllocateFD(handle0);
- pipefds[1] = AllocateFD(handle1);
+ pipefds[0] = AllocateFD(handle0, "");
binji 2014/01/07 21:40:29 I think I'd prefer having the second parameter def
+ pipefds[1] = AllocateFD(handle1, "");
return 0;
}
@@ -238,8 +240,12 @@ int KernelProxy::dup(int oldfd) {
errno = error;
return -1;
}
-
- return AllocateFD(handle);
+ // Return value will be NULL if fd is not a path, which matches with the
+ // appropriate argument to AllocateFD. Note that this will be a normalized
+ // Path.
+ std::string path = GetFDPath(oldfd);
binji 2014/01/07 21:40:29 hm, I think there's a race here. The oldfd mapping
+ int fd = AllocateFD(handle, path);
+ return fd;
}
int KernelProxy::dup2(int oldfd, int newfd) {
@@ -514,8 +520,31 @@ int KernelProxy::getdents(int fd, void* buf, unsigned int count) {
}
int KernelProxy::fchdir(int fd) {
- errno = ENOSYS;
- return -1;
+ ScopedKernelHandle handle;
+ Error error = AcquireHandle(fd, &handle);
+ if (error) {
+ errno = error;
+ return -1;
+ }
+
+ if (!handle->node()->IsaDir()) {
+ errno = ENOTDIR;
+ return -1;
+ }
+
+ std::string path = GetFDPath(fd);
+ if (path.empty()) {
+ errno = EBADF;
+ return -1;
+ }
+
+ error = SetCWD(path);
+ if (error) {
+ // errno is return value from SetCWD
+ errno = error;
+ return -1;
+ }
+ return 0;
}
int KernelProxy::ftruncate(int fd, off_t length) {
@@ -1202,7 +1231,7 @@ int KernelProxy::accept(int fd, struct sockaddr* addr, socklen_t* len) {
return -1;
}
- return AllocateFD(new_handle);
+ return AllocateFD(new_handle, "");
}
int KernelProxy::bind(int fd, const struct sockaddr* addr, socklen_t len) {
@@ -1563,7 +1592,7 @@ int KernelProxy::socket(int domain, int type, int protocol) {
return -1;
}
- return AllocateFD(handle);
+ return AllocateFD(handle, "");
}
int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) {

Powered by Google App Engine
This is Rietveld 408576698