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

Side by Side 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: Conform to style guide 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "nacl_io/kernel_proxy.h" 5 #include "nacl_io/kernel_proxy.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <limits.h> 10 #include <limits.h>
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 } 166 }
167 167
168 ScopedKernelHandle handle(new KernelHandle(fs, node)); 168 ScopedKernelHandle handle(new KernelHandle(fs, node));
169 error = handle->Init(O_RDONLY); 169 error = handle->Init(O_RDONLY);
170 if (error) { 170 if (error) {
171 errno = error; 171 errno = error;
172 return -1; 172 return -1;
173 } 173 }
174 174
175 return AllocateFD(handle); 175 return AllocateFD(handle, path);
176 } 176 }
177 177
178 int KernelProxy::open(const char* path, int open_flags) { 178 int KernelProxy::open(const char* path, int open_flags) {
179 ScopedFilesystem fs; 179 ScopedFilesystem fs;
180 ScopedNode node; 180 ScopedNode node;
181 181
182 Error error = AcquireFsAndNode(path, open_flags, &fs, &node); 182 Error error = AcquireFsAndNode(path, open_flags, &fs, &node);
183 if (error) { 183 if (error) {
184 errno = error; 184 errno = error;
185 return -1; 185 return -1;
186 } 186 }
187 187
188 ScopedKernelHandle handle(new KernelHandle(fs, node)); 188 ScopedKernelHandle handle(new KernelHandle(fs, node));
189 error = handle->Init(open_flags); 189 error = handle->Init(open_flags);
190 if (error) { 190 if (error) {
191 errno = error; 191 errno = error;
192 return -1; 192 return -1;
193 } 193 }
194 194
195 return AllocateFD(handle); 195 return AllocateFD(handle, path);
196 } 196 }
197 197
198 int KernelProxy::pipe(int pipefds[2]) { 198 int KernelProxy::pipe(int pipefds[2]) {
199 PipeNode* pipe = new PipeNode(stream_mount_.get()); 199 PipeNode* pipe = new PipeNode(stream_mount_.get());
200 ScopedNode node(pipe); 200 ScopedNode node(pipe);
201 201
202 if (pipe->Init(O_RDWR) == 0) { 202 if (pipe->Init(O_RDWR) == 0) {
203 ScopedKernelHandle handle0(new KernelHandle(stream_mount_, node)); 203 ScopedKernelHandle handle0(new KernelHandle(stream_mount_, node));
204 ScopedKernelHandle handle1(new KernelHandle(stream_mount_, node)); 204 ScopedKernelHandle handle1(new KernelHandle(stream_mount_, node));
205 205
(...skipping 20 matching lines...) Expand all
226 return -1; 226 return -1;
227 } 227 }
228 228
229 // Remove the FD from the process open file descriptor map 229 // Remove the FD from the process open file descriptor map
230 FreeFD(fd); 230 FreeFD(fd);
231 return 0; 231 return 0;
232 } 232 }
233 233
234 int KernelProxy::dup(int oldfd) { 234 int KernelProxy::dup(int oldfd) {
235 ScopedKernelHandle handle; 235 ScopedKernelHandle handle;
236 Error error = AcquireHandle(oldfd, &handle); 236 std::string path;
237 Error error = AcquireHandleAndPath(oldfd, &handle, &path);
237 if (error) { 238 if (error) {
238 errno = error; 239 errno = error;
239 return -1; 240 return -1;
240 } 241 }
241 242 return AllocateFD(handle, path);
242 return AllocateFD(handle);
243 } 243 }
244 244
245 int KernelProxy::dup2(int oldfd, int newfd) { 245 int KernelProxy::dup2(int oldfd, int newfd) {
246 // If it's the same file handle, just return 246 // If it's the same file handle, just return
247 if (oldfd == newfd) 247 if (oldfd == newfd)
248 return newfd; 248 return newfd;
249 249
250 ScopedKernelHandle old_handle; 250 ScopedKernelHandle old_handle;
251 Error error = AcquireHandle(oldfd, &old_handle); 251 std::string old_path;
252 Error error = AcquireHandleAndPath(oldfd, &old_handle, &old_path);
252 if (error) { 253 if (error) {
253 errno = error; 254 errno = error;
254 return -1; 255 return -1;
255 } 256 }
256 257
257 FreeAndReassignFD(newfd, old_handle); 258 FreeAndReassignFD(newfd, old_handle, old_path);
258 return newfd; 259 return newfd;
259 } 260 }
260 261
261 int KernelProxy::chdir(const char* path) { 262 int KernelProxy::chdir(const char* path) {
262 Error error = SetCWD(path); 263 Error error = SetCWD(path);
263 if (error) { 264 if (error) {
264 errno = error; 265 errno = error;
265 return -1; 266 return -1;
266 } 267 }
267 return 0; 268 return 0;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 508
508 int cnt = 0; 509 int cnt = 0;
509 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt); 510 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt);
510 if (error) 511 if (error)
511 errno = error; 512 errno = error;
512 513
513 return cnt; 514 return cnt;
514 } 515 }
515 516
516 int KernelProxy::fchdir(int fd) { 517 int KernelProxy::fchdir(int fd) {
517 errno = ENOSYS; 518 ScopedKernelHandle handle;
518 return -1; 519 std::string path;
520 Error error = AcquireHandleAndPath(fd, &handle, &path);
521 if (error) {
522 errno = error;
523 return -1;
524 }
525
526 if (!handle->node()->IsaDir()) {
527 errno = ENOTDIR;
528 return -1;
529 }
530
531 if (path.empty()) {
532 errno = EBADF;
533 return -1;
534 }
535
536 error = SetCWD(path);
537 if (error) {
538 // errno is return value from SetCWD
539 errno = error;
540 return -1;
541 }
542 return 0;
519 } 543 }
520 544
521 int KernelProxy::ftruncate(int fd, off_t length) { 545 int KernelProxy::ftruncate(int fd, off_t length) {
522 ScopedKernelHandle handle; 546 ScopedKernelHandle handle;
523 Error error = AcquireHandle(fd, &handle); 547 Error error = AcquireHandle(fd, &handle);
524 if (error) { 548 if (error) {
525 errno = error; 549 errno = error;
526 return -1; 550 return -1;
527 } 551 }
528 552
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 errno = ENOTSOCK; 1625 errno = ENOTSOCK;
1602 return -1; 1626 return -1;
1603 } 1627 }
1604 1628
1605 return 0; 1629 return 0;
1606 } 1630 }
1607 1631
1608 #endif // PROVIDES_SOCKET_API 1632 #endif // PROVIDES_SOCKET_API
1609 1633
1610 } // namespace_nacl_io 1634 } // namespace_nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698