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

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: 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 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 int fd = AllocateFD(handle, path);
binji 2014/01/07 21:40:29 return AllocateFD(handle, path); is fine. Here an
176 return fd;
176 } 177 }
177 178
178 int KernelProxy::open(const char* path, int open_flags) { 179 int KernelProxy::open(const char* path, int open_flags) {
179 ScopedFilesystem fs; 180 ScopedFilesystem fs;
180 ScopedNode node; 181 ScopedNode node;
181 182
182 Error error = AcquireFsAndNode(path, open_flags, &fs, &node); 183 Error error = AcquireFsAndNode(path, open_flags, &fs, &node);
183 if (error) { 184 if (error) {
184 errno = error; 185 errno = error;
185 return -1; 186 return -1;
186 } 187 }
187 188
188 ScopedKernelHandle handle(new KernelHandle(fs, node)); 189 ScopedKernelHandle handle(new KernelHandle(fs, node));
189 error = handle->Init(open_flags); 190 error = handle->Init(open_flags);
190 if (error) { 191 if (error) {
191 errno = error; 192 errno = error;
192 return -1; 193 return -1;
193 } 194 }
194 195
195 return AllocateFD(handle); 196 int fd = AllocateFD(handle, path);
197 return fd;
196 } 198 }
197 199
198 int KernelProxy::pipe(int pipefds[2]) { 200 int KernelProxy::pipe(int pipefds[2]) {
199 PipeNode* pipe = new PipeNode(stream_mount_.get()); 201 PipeNode* pipe = new PipeNode(stream_mount_.get());
200 ScopedNode node(pipe); 202 ScopedNode node(pipe);
201 203
202 if (pipe->Init(O_RDWR) == 0) { 204 if (pipe->Init(O_RDWR) == 0) {
203 ScopedKernelHandle handle0(new KernelHandle(stream_mount_, node)); 205 ScopedKernelHandle handle0(new KernelHandle(stream_mount_, node));
204 ScopedKernelHandle handle1(new KernelHandle(stream_mount_, node)); 206 ScopedKernelHandle handle1(new KernelHandle(stream_mount_, node));
205 207
206 // Should never fail, but... 208 // Should never fail, but...
207 if (handle0->Init(O_RDONLY) || handle1->Init(O_WRONLY)) { 209 if (handle0->Init(O_RDONLY) || handle1->Init(O_WRONLY)) {
208 errno = EACCES; 210 errno = EACCES;
209 return -1; 211 return -1;
210 } 212 }
211 213
212 pipefds[0] = AllocateFD(handle0); 214 pipefds[0] = AllocateFD(handle0, "");
binji 2014/01/07 21:40:29 I think I'd prefer having the second parameter def
213 pipefds[1] = AllocateFD(handle1); 215 pipefds[1] = AllocateFD(handle1, "");
214 return 0; 216 return 0;
215 } 217 }
216 218
217 errno = ENOSYS; 219 errno = ENOSYS;
218 return -1; 220 return -1;
219 } 221 }
220 222
221 int KernelProxy::close(int fd) { 223 int KernelProxy::close(int fd) {
222 ScopedKernelHandle handle; 224 ScopedKernelHandle handle;
223 Error error = AcquireHandle(fd, &handle); 225 Error error = AcquireHandle(fd, &handle);
224 if (error) { 226 if (error) {
225 errno = error; 227 errno = error;
226 return -1; 228 return -1;
227 } 229 }
228 230
229 // Remove the FD from the process open file descriptor map 231 // Remove the FD from the process open file descriptor map
230 FreeFD(fd); 232 FreeFD(fd);
231 return 0; 233 return 0;
232 } 234 }
233 235
234 int KernelProxy::dup(int oldfd) { 236 int KernelProxy::dup(int oldfd) {
235 ScopedKernelHandle handle; 237 ScopedKernelHandle handle;
236 Error error = AcquireHandle(oldfd, &handle); 238 Error error = AcquireHandle(oldfd, &handle);
237 if (error) { 239 if (error) {
238 errno = error; 240 errno = error;
239 return -1; 241 return -1;
240 } 242 }
241 243 // Return value will be NULL if fd is not a path, which matches with the
242 return AllocateFD(handle); 244 // appropriate argument to AllocateFD. Note that this will be a normalized
245 // Path.
246 std::string path = GetFDPath(oldfd);
binji 2014/01/07 21:40:29 hm, I think there's a race here. The oldfd mapping
247 int fd = AllocateFD(handle, path);
248 return fd;
243 } 249 }
244 250
245 int KernelProxy::dup2(int oldfd, int newfd) { 251 int KernelProxy::dup2(int oldfd, int newfd) {
246 // If it's the same file handle, just return 252 // If it's the same file handle, just return
247 if (oldfd == newfd) 253 if (oldfd == newfd)
248 return newfd; 254 return newfd;
249 255
250 ScopedKernelHandle old_handle; 256 ScopedKernelHandle old_handle;
251 Error error = AcquireHandle(oldfd, &old_handle); 257 Error error = AcquireHandle(oldfd, &old_handle);
252 if (error) { 258 if (error) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 513
508 int cnt = 0; 514 int cnt = 0;
509 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt); 515 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt);
510 if (error) 516 if (error)
511 errno = error; 517 errno = error;
512 518
513 return cnt; 519 return cnt;
514 } 520 }
515 521
516 int KernelProxy::fchdir(int fd) { 522 int KernelProxy::fchdir(int fd) {
517 errno = ENOSYS; 523 ScopedKernelHandle handle;
518 return -1; 524 Error error = AcquireHandle(fd, &handle);
525 if (error) {
526 errno = error;
527 return -1;
528 }
529
530 if (!handle->node()->IsaDir()) {
531 errno = ENOTDIR;
532 return -1;
533 }
534
535 std::string path = GetFDPath(fd);
536 if (path.empty()) {
537 errno = EBADF;
538 return -1;
539 }
540
541 error = SetCWD(path);
542 if (error) {
543 // errno is return value from SetCWD
544 errno = error;
545 return -1;
546 }
547 return 0;
519 } 548 }
520 549
521 int KernelProxy::ftruncate(int fd, off_t length) { 550 int KernelProxy::ftruncate(int fd, off_t length) {
522 ScopedKernelHandle handle; 551 ScopedKernelHandle handle;
523 Error error = AcquireHandle(fd, &handle); 552 Error error = AcquireHandle(fd, &handle);
524 if (error) { 553 if (error) {
525 errno = error; 554 errno = error;
526 return -1; 555 return -1;
527 } 556 }
528 557
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 } 1224 }
1196 1225
1197 ScopedNode node(sock); 1226 ScopedNode node(sock);
1198 ScopedKernelHandle new_handle(new KernelHandle(stream_mount_, node)); 1227 ScopedKernelHandle new_handle(new KernelHandle(stream_mount_, node));
1199 error = new_handle->Init(O_RDWR); 1228 error = new_handle->Init(O_RDWR);
1200 if (error != 0) { 1229 if (error != 0) {
1201 errno = error; 1230 errno = error;
1202 return -1; 1231 return -1;
1203 } 1232 }
1204 1233
1205 return AllocateFD(new_handle); 1234 return AllocateFD(new_handle, "");
1206 } 1235 }
1207 1236
1208 int KernelProxy::bind(int fd, const struct sockaddr* addr, socklen_t len) { 1237 int KernelProxy::bind(int fd, const struct sockaddr* addr, socklen_t len) {
1209 if (NULL == addr) { 1238 if (NULL == addr) {
1210 errno = EFAULT; 1239 errno = EFAULT;
1211 return -1; 1240 return -1;
1212 } 1241 }
1213 1242
1214 ScopedKernelHandle handle; 1243 ScopedKernelHandle handle;
1215 if (AcquireSocketHandle(fd, &handle) == -1) 1244 if (AcquireSocketHandle(fd, &handle) == -1)
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 return -1; 1585 return -1;
1557 } 1586 }
1558 1587
1559 ScopedKernelHandle handle(new KernelHandle(stream_mount_, node)); 1588 ScopedKernelHandle handle(new KernelHandle(stream_mount_, node));
1560 rtn = handle->Init(open_flags); 1589 rtn = handle->Init(open_flags);
1561 if (rtn != 0) { 1590 if (rtn != 0) {
1562 errno = rtn; 1591 errno = rtn;
1563 return -1; 1592 return -1;
1564 } 1593 }
1565 1594
1566 return AllocateFD(handle); 1595 return AllocateFD(handle, "");
1567 } 1596 }
1568 1597
1569 int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) { 1598 int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) {
1570 if (NULL == sv) { 1599 if (NULL == sv) {
1571 errno = EFAULT; 1600 errno = EFAULT;
1572 return -1; 1601 return -1;
1573 } 1602 }
1574 1603
1575 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support 1604 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support
1576 // socket pairs. Thus, this function always fails. 1605 // socket pairs. Thus, this function always fails.
(...skipping 24 matching lines...) Expand all
1601 errno = ENOTSOCK; 1630 errno = ENOTSOCK;
1602 return -1; 1631 return -1;
1603 } 1632 }
1604 1633
1605 return 0; 1634 return 0;
1606 } 1635 }
1607 1636
1608 #endif // PROVIDES_SOCKET_API 1637 #endif // PROVIDES_SOCKET_API
1609 1638
1610 } // namespace_nacl_io 1639 } // namespace_nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698