OLD | NEW |
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 const char* target, | 411 const char* target, |
412 const char* filesystemtype, | 412 const char* filesystemtype, |
413 unsigned long mountflags, | 413 unsigned long mountflags, |
414 const void* data, | 414 const void* data, |
415 bool create_fs_node, | 415 bool create_fs_node, |
416 ScopedFilesystem* out_filesystem) { | 416 ScopedFilesystem* out_filesystem) { |
417 std::string abs_path = GetAbsParts(target).Join(); | 417 std::string abs_path = GetAbsParts(target).Join(); |
418 | 418 |
419 // Find a factory of that type | 419 // Find a factory of that type |
420 FsFactoryMap_t::iterator factory = factories_.find(filesystemtype); | 420 FsFactoryMap_t::iterator factory = factories_.find(filesystemtype); |
421 if (factory == factories_.end()) | 421 if (factory == factories_.end()) { |
| 422 LOG_ERROR("Unknown filesystem type: %s", filesystemtype); |
422 return ENODEV; | 423 return ENODEV; |
| 424 } |
423 | 425 |
424 // Create a map of settings | 426 // Create a map of settings |
425 StringMap_t smap; | 427 StringMap_t smap; |
426 smap["SOURCE"] = source; | 428 smap["SOURCE"] = source; |
427 | 429 |
428 if (data) { | 430 if (data) { |
429 std::vector<std::string> elements; | 431 std::vector<std::string> elements; |
430 sdk_util::SplitString(static_cast<const char*>(data), ',', &elements); | 432 sdk_util::SplitString(static_cast<const char*>(data), ',', &elements); |
431 | 433 |
432 for (std::vector<std::string>::const_iterator it = elements.begin(); | 434 for (std::vector<std::string>::const_iterator it = elements.begin(); |
(...skipping 19 matching lines...) Expand all Loading... |
452 Error error = factory->second->CreateFilesystem(args, &fs); | 454 Error error = factory->second->CreateFilesystem(args, &fs); |
453 if (error) | 455 if (error) |
454 return error; | 456 return error; |
455 | 457 |
456 error = AttachFsAtPath(fs, abs_path); | 458 error = AttachFsAtPath(fs, abs_path); |
457 if (error) | 459 if (error) |
458 return error; | 460 return error; |
459 | 461 |
460 if (create_fs_node) { | 462 if (create_fs_node) { |
461 error = CreateFsNode(fs); | 463 error = CreateFsNode(fs); |
462 if (error) | 464 if (error) { |
| 465 DetachFsAtPath(abs_path, &fs); |
463 return error; | 466 return error; |
| 467 } |
464 } | 468 } |
465 | 469 |
466 *out_filesystem = fs; | 470 *out_filesystem = fs; |
467 return 0; | 471 return 0; |
468 } | 472 } |
469 | 473 |
470 Error KernelProxy::CreateFsNode(const ScopedFilesystem& fs) { | 474 Error KernelProxy::CreateFsNode(const ScopedFilesystem& fs) { |
471 assert(dev_fs_); | 475 assert(dev_fs_); |
472 | 476 |
473 return dev_fs_->CreateFsNode(fs.get()); | 477 return dev_fs_->CreateFsNode(fs.get()); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 837 |
834 error = fs->Access(rel, amode); | 838 error = fs->Access(rel, amode); |
835 if (error) { | 839 if (error) { |
836 errno = error; | 840 errno = error; |
837 return -1; | 841 return -1; |
838 } | 842 } |
839 return 0; | 843 return 0; |
840 } | 844 } |
841 | 845 |
842 int KernelProxy::readlink(const char* path, char* buf, size_t count) { | 846 int KernelProxy::readlink(const char* path, char* buf, size_t count) { |
| 847 LOG_TRACE("readlink is not implemented."); |
843 errno = EINVAL; | 848 errno = EINVAL; |
844 return -1; | 849 return -1; |
845 } | 850 } |
846 | 851 |
847 int KernelProxy::utimes(const char* filename, const struct timeval times[2]) { | 852 int KernelProxy::utimes(const char* filename, const struct timeval times[2]) { |
| 853 LOG_TRACE("utimes is not implemented."); |
848 errno = EINVAL; | 854 errno = EINVAL; |
849 return -1; | 855 return -1; |
850 } | 856 } |
851 | 857 |
852 // TODO(noelallen): Needs implementation. | 858 // TODO(noelallen): Needs implementation. |
853 int KernelProxy::link(const char* oldpath, const char* newpath) { | 859 int KernelProxy::link(const char* oldpath, const char* newpath) { |
| 860 LOG_TRACE("link is not implemented."); |
854 errno = EINVAL; | 861 errno = EINVAL; |
855 return -1; | 862 return -1; |
856 } | 863 } |
857 | 864 |
858 int KernelProxy::symlink(const char* oldpath, const char* newpath) { | 865 int KernelProxy::symlink(const char* oldpath, const char* newpath) { |
| 866 LOG_TRACE("symlink is not implemented."); |
859 errno = EINVAL; | 867 errno = EINVAL; |
860 return -1; | 868 return -1; |
861 } | 869 } |
862 | 870 |
863 void* KernelProxy::mmap(void* addr, | 871 void* KernelProxy::mmap(void* addr, |
864 size_t length, | 872 size_t length, |
865 int prot, | 873 int prot, |
866 int flags, | 874 int flags, |
867 int fd, | 875 int fd, |
868 size_t offset) { | 876 size_t offset) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 sigwinch_handler_.sa_handler != SIG_DFL) { | 1002 sigwinch_handler_.sa_handler != SIG_DFL) { |
995 sigwinch_handler_.sa_handler(SIGWINCH); | 1003 sigwinch_handler_.sa_handler(SIGWINCH); |
996 } | 1004 } |
997 break; | 1005 break; |
998 | 1006 |
999 case SIGUSR1: | 1007 case SIGUSR1: |
1000 case SIGUSR2: | 1008 case SIGUSR2: |
1001 break; | 1009 break; |
1002 | 1010 |
1003 default: | 1011 default: |
| 1012 LOG_TRACE("Unsupported signal: %d", sig); |
1004 errno = EINVAL; | 1013 errno = EINVAL; |
1005 return -1; | 1014 return -1; |
1006 } | 1015 } |
1007 return 0; | 1016 return 0; |
1008 } | 1017 } |
1009 | 1018 |
1010 int KernelProxy::sigaction(int signum, | 1019 int KernelProxy::sigaction(int signum, |
1011 const struct sigaction* action, | 1020 const struct sigaction* action, |
1012 struct sigaction* oaction) { | 1021 struct sigaction* oaction) { |
1013 if (action && action->sa_flags & SA_SIGINFO) { | 1022 if (action && action->sa_flags & SA_SIGINFO) { |
(...skipping 23 matching lines...) Expand all Loading... |
1037 case SIGCHLD: | 1046 case SIGCHLD: |
1038 case SIGURG: | 1047 case SIGURG: |
1039 case SIGFPE: | 1048 case SIGFPE: |
1040 case SIGILL: | 1049 case SIGILL: |
1041 case SIGQUIT: | 1050 case SIGQUIT: |
1042 case SIGSEGV: | 1051 case SIGSEGV: |
1043 case SIGTRAP: | 1052 case SIGTRAP: |
1044 if (action && action->sa_handler != SIG_DFL) { | 1053 if (action && action->sa_handler != SIG_DFL) { |
1045 // Trying to set this action to anything other than SIG_DFL | 1054 // Trying to set this action to anything other than SIG_DFL |
1046 // is not yet supported. | 1055 // is not yet supported. |
| 1056 LOG_TRACE("sigaction on signal %d != SIG_DFL not supported.", sig); |
1047 errno = EINVAL; | 1057 errno = EINVAL; |
1048 return -1; | 1058 return -1; |
1049 } | 1059 } |
1050 | 1060 |
1051 if (oaction) { | 1061 if (oaction) { |
1052 memset(oaction, 0, sizeof(*oaction)); | 1062 memset(oaction, 0, sizeof(*oaction)); |
1053 oaction->sa_handler = SIG_DFL; | 1063 oaction->sa_handler = SIG_DFL; |
1054 } | 1064 } |
1055 return 0; | 1065 return 0; |
1056 | 1066 |
1057 // KILL and STOP cannot be handled | 1067 // KILL and STOP cannot be handled |
1058 case SIGKILL: | 1068 case SIGKILL: |
1059 case SIGSTOP: | 1069 case SIGSTOP: |
| 1070 LOG_TRACE("sigaction on SIGKILL/SIGSTOP not supported."); |
1060 errno = EINVAL; | 1071 errno = EINVAL; |
1061 return -1; | 1072 return -1; |
1062 } | 1073 } |
1063 | 1074 |
1064 // Unknown signum | 1075 // Unknown signum |
1065 errno = EINVAL; | 1076 errno = EINVAL; |
1066 return -1; | 1077 return -1; |
1067 } | 1078 } |
1068 | 1079 |
1069 #ifdef PROVIDES_SOCKET_API | 1080 #ifdef PROVIDES_SOCKET_API |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 | 1113 |
1103 // NULL timeout signals wait forever. | 1114 // NULL timeout signals wait forever. |
1104 int ms_timeout = -1; | 1115 int ms_timeout = -1; |
1105 if (timeout != NULL) { | 1116 if (timeout != NULL) { |
1106 int64_t ms = timeout->tv_sec * 1000 + ((timeout->tv_usec + 500) / 1000); | 1117 int64_t ms = timeout->tv_sec * 1000 + ((timeout->tv_usec + 500) / 1000); |
1107 | 1118 |
1108 // If the timeout is invalid or too long (larger than signed 32 bit). | 1119 // If the timeout is invalid or too long (larger than signed 32 bit). |
1109 if ((timeout->tv_sec < 0) || (timeout->tv_sec >= (INT_MAX / 1000)) || | 1120 if ((timeout->tv_sec < 0) || (timeout->tv_sec >= (INT_MAX / 1000)) || |
1110 (timeout->tv_usec < 0) || (timeout->tv_usec >= 1000000) || (ms < 0) || | 1121 (timeout->tv_usec < 0) || (timeout->tv_usec >= 1000000) || (ms < 0) || |
1111 (ms >= INT_MAX)) { | 1122 (ms >= INT_MAX)) { |
| 1123 LOG_TRACE("Invalid timeout: tv_sec=%d tv_usec=%d.", |
| 1124 timeout->tv_sec, |
| 1125 timeout->tv_usec); |
1112 errno = EINVAL; | 1126 errno = EINVAL; |
1113 return -1; | 1127 return -1; |
1114 } | 1128 } |
1115 | 1129 |
1116 ms_timeout = static_cast<int>(ms); | 1130 ms_timeout = static_cast<int>(ms); |
1117 } | 1131 } |
1118 | 1132 |
1119 int result = poll(&pollfds[0], pollfds.size(), ms_timeout); | 1133 int result = poll(&pollfds[0], pollfds.size(), ms_timeout); |
1120 if (result == -1) | 1134 if (result == -1) |
1121 return -1; | 1135 return -1; |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 errno = ENOTSOCK; | 1691 errno = ENOTSOCK; |
1678 return -1; | 1692 return -1; |
1679 } | 1693 } |
1680 | 1694 |
1681 return 0; | 1695 return 0; |
1682 } | 1696 } |
1683 | 1697 |
1684 #endif // PROVIDES_SOCKET_API | 1698 #endif // PROVIDES_SOCKET_API |
1685 | 1699 |
1686 } // namespace_nacl_io | 1700 } // namespace_nacl_io |
OLD | NEW |