| 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 11 matching lines...) Expand all Loading... |
| 22 #include "nacl_io/filesystem.h" | 22 #include "nacl_io/filesystem.h" |
| 23 #include "nacl_io/fusefs/fuse_fs_factory.h" | 23 #include "nacl_io/fusefs/fuse_fs_factory.h" |
| 24 #include "nacl_io/host_resolver.h" | 24 #include "nacl_io/host_resolver.h" |
| 25 #include "nacl_io/html5fs/html5_fs.h" | 25 #include "nacl_io/html5fs/html5_fs.h" |
| 26 #include "nacl_io/httpfs/http_fs.h" | 26 #include "nacl_io/httpfs/http_fs.h" |
| 27 #include "nacl_io/kernel_handle.h" | 27 #include "nacl_io/kernel_handle.h" |
| 28 #include "nacl_io/kernel_wrap_real.h" | 28 #include "nacl_io/kernel_wrap_real.h" |
| 29 #include "nacl_io/log.h" | 29 #include "nacl_io/log.h" |
| 30 #include "nacl_io/memfs/mem_fs.h" | 30 #include "nacl_io/memfs/mem_fs.h" |
| 31 #include "nacl_io/node.h" | 31 #include "nacl_io/node.h" |
| 32 #include "nacl_io/osinttypes.h" |
| 32 #include "nacl_io/osmman.h" | 33 #include "nacl_io/osmman.h" |
| 33 #include "nacl_io/ossocket.h" | 34 #include "nacl_io/ossocket.h" |
| 34 #include "nacl_io/osstat.h" | 35 #include "nacl_io/osstat.h" |
| 35 #include "nacl_io/passthroughfs/passthrough_fs.h" | 36 #include "nacl_io/passthroughfs/passthrough_fs.h" |
| 36 #include "nacl_io/path.h" | 37 #include "nacl_io/path.h" |
| 37 #include "nacl_io/pepper_interface.h" | 38 #include "nacl_io/pepper_interface.h" |
| 38 #include "nacl_io/pipe/pipe_node.h" | 39 #include "nacl_io/pipe/pipe_node.h" |
| 39 #include "nacl_io/socket/tcp_node.h" | 40 #include "nacl_io/socket/tcp_node.h" |
| 40 #include "nacl_io/socket/udp_node.h" | 41 #include "nacl_io/socket/udp_node.h" |
| 41 #include "nacl_io/stream/stream_fs.h" | 42 #include "nacl_io/stream/stream_fs.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 78 |
| 78 factories_["memfs"] = new TypedFsFactory<MemFs>; | 79 factories_["memfs"] = new TypedFsFactory<MemFs>; |
| 79 factories_["dev"] = new TypedFsFactory<DevFs>; | 80 factories_["dev"] = new TypedFsFactory<DevFs>; |
| 80 factories_["html5fs"] = new TypedFsFactory<Html5Fs>; | 81 factories_["html5fs"] = new TypedFsFactory<Html5Fs>; |
| 81 factories_["httpfs"] = new TypedFsFactory<HttpFs>; | 82 factories_["httpfs"] = new TypedFsFactory<HttpFs>; |
| 82 factories_["passthroughfs"] = new TypedFsFactory<PassthroughFs>; | 83 factories_["passthroughfs"] = new TypedFsFactory<PassthroughFs>; |
| 83 | 84 |
| 84 ScopedFilesystem root_fs; | 85 ScopedFilesystem root_fs; |
| 85 rtn = MountInternal("", "/", "passthroughfs", 0, NULL, false, &root_fs); | 86 rtn = MountInternal("", "/", "passthroughfs", 0, NULL, false, &root_fs); |
| 86 if (rtn != 0) | 87 if (rtn != 0) |
| 87 assert(false); | 88 return rtn; |
| 88 | 89 |
| 89 ScopedFilesystem fs; | 90 ScopedFilesystem fs; |
| 90 rtn = MountInternal("", "/dev", "dev", 0, NULL, false, &fs); | 91 rtn = MountInternal("", "/dev", "dev", 0, NULL, false, &fs); |
| 91 if (rtn != 0) | 92 if (rtn != 0) |
| 92 assert(false); | 93 return rtn; |
| 93 dev_fs_ = sdk_util::static_scoped_ref_cast<DevFs>(fs); | 94 dev_fs_ = sdk_util::static_scoped_ref_cast<DevFs>(fs); |
| 94 | 95 |
| 95 // Create the filesystem nodes for / and /dev afterward. They can't be | 96 // Create the filesystem nodes for / and /dev afterward. They can't be |
| 96 // created the normal way because the dev filesystem didn't exist yet. | 97 // created the normal way because the dev filesystem didn't exist yet. |
| 97 rtn = CreateFsNode(root_fs); | 98 rtn = CreateFsNode(root_fs); |
| 98 if (rtn != 0) | 99 if (rtn != 0) |
| 99 assert(false); | 100 return rtn; |
| 100 | 101 |
| 101 rtn = CreateFsNode(dev_fs_); | 102 rtn = CreateFsNode(dev_fs_); |
| 102 if (rtn != 0) | 103 if (rtn != 0) |
| 103 assert(false); | 104 return rtn; |
| 104 | 105 |
| 105 // Open the first three in order to get STDIN, STDOUT, STDERR | 106 // Open the first three in order to get STDIN, STDOUT, STDERR |
| 106 int fd; | 107 int fd; |
| 107 fd = open("/dev/stdin", O_RDONLY, 0); | 108 fd = open("/dev/stdin", O_RDONLY, 0); |
| 109 if (fd < 0) { |
| 110 LOG_ERROR("failed to open /dev/stdin: %s", strerror(errno)); |
| 111 return errno; |
| 112 } |
| 108 assert(fd == 0); | 113 assert(fd == 0); |
| 109 if (fd < 0) | |
| 110 rtn = errno; | |
| 111 | 114 |
| 112 fd = open("/dev/stdout", O_WRONLY, 0); | 115 fd = open("/dev/stdout", O_WRONLY, 0); |
| 116 if (fd < 0) { |
| 117 LOG_ERROR("failed to open /dev/stdout: %s", strerror(errno)); |
| 118 return errno; |
| 119 } |
| 113 assert(fd == 1); | 120 assert(fd == 1); |
| 114 if (fd < 0) | |
| 115 rtn = errno; | |
| 116 | 121 |
| 117 fd = open("/dev/stderr", O_WRONLY, 0); | 122 fd = open("/dev/stderr", O_WRONLY, 0); |
| 123 if (fd < 0) { |
| 124 LOG_ERROR("failed to open /dev/sterr: %s", strerror(errno)); |
| 125 return errno; |
| 126 } |
| 118 assert(fd == 2); | 127 assert(fd == 2); |
| 119 if (fd < 0) | |
| 120 rtn = errno; | |
| 121 | 128 |
| 122 #ifdef PROVIDES_SOCKET_API | 129 #ifdef PROVIDES_SOCKET_API |
| 123 host_resolver_.Init(ppapi_); | 130 host_resolver_.Init(ppapi_); |
| 124 #endif | 131 #endif |
| 125 | 132 |
| 126 FsInitArgs args; | 133 FsInitArgs args; |
| 127 args.dev = dev_++; | 134 args.dev = dev_++; |
| 128 args.ppapi = ppapi_; | 135 args.ppapi = ppapi_; |
| 129 stream_fs_.reset(new StreamFs()); | 136 stream_fs_.reset(new StreamFs()); |
| 130 int result = stream_fs_->Init(args); | 137 int result = stream_fs_->Init(args); |
| 131 if (result != 0) { | 138 if (result != 0) { |
| 132 assert(false); | 139 LOG_ERROR("initializing streamfs failed: %s", strerror(result)); |
| 133 rtn = result; | 140 return result; |
| 134 } | 141 } |
| 135 | 142 |
| 136 return rtn; | 143 return 0; |
| 137 } | 144 } |
| 138 | 145 |
| 139 bool KernelProxy::RegisterFsType(const char* fs_type, | 146 bool KernelProxy::RegisterFsType(const char* fs_type, |
| 140 fuse_operations* fuse_ops) { | 147 fuse_operations* fuse_ops) { |
| 141 FsFactoryMap_t::iterator iter = factories_.find(fs_type); | 148 FsFactoryMap_t::iterator iter = factories_.find(fs_type); |
| 142 if (iter != factories_.end()) | 149 if (iter != factories_.end()) |
| 143 return false; | 150 return false; |
| 144 | 151 |
| 145 factories_[fs_type] = new FuseFsFactory(fuse_ops); | 152 factories_[fs_type] = new FuseFsFactory(fuse_ops); |
| 146 return true; | 153 return true; |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 case SIGCHLD: | 1136 case SIGCHLD: |
| 1130 case SIGURG: | 1137 case SIGURG: |
| 1131 case SIGFPE: | 1138 case SIGFPE: |
| 1132 case SIGILL: | 1139 case SIGILL: |
| 1133 case SIGQUIT: | 1140 case SIGQUIT: |
| 1134 case SIGSEGV: | 1141 case SIGSEGV: |
| 1135 case SIGTRAP: | 1142 case SIGTRAP: |
| 1136 if (action && action->sa_handler != SIG_DFL) { | 1143 if (action && action->sa_handler != SIG_DFL) { |
| 1137 // Trying to set this action to anything other than SIG_DFL | 1144 // Trying to set this action to anything other than SIG_DFL |
| 1138 // is not yet supported. | 1145 // is not yet supported. |
| 1139 LOG_TRACE("sigaction on signal %d != SIG_DFL not supported.", sig); | 1146 LOG_TRACE("sigaction on signal %d != SIG_DFL not supported.", signum); |
| 1140 errno = EINVAL; | 1147 errno = EINVAL; |
| 1141 return -1; | 1148 return -1; |
| 1142 } | 1149 } |
| 1143 | 1150 |
| 1144 if (oaction) { | 1151 if (oaction) { |
| 1145 memset(oaction, 0, sizeof(*oaction)); | 1152 memset(oaction, 0, sizeof(*oaction)); |
| 1146 oaction->sa_handler = SIG_DFL; | 1153 oaction->sa_handler = SIG_DFL; |
| 1147 } | 1154 } |
| 1148 return 0; | 1155 return 0; |
| 1149 | 1156 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 | 1203 |
| 1197 // NULL timeout signals wait forever. | 1204 // NULL timeout signals wait forever. |
| 1198 int ms_timeout = -1; | 1205 int ms_timeout = -1; |
| 1199 if (timeout != NULL) { | 1206 if (timeout != NULL) { |
| 1200 int64_t ms = timeout->tv_sec * 1000 + ((timeout->tv_usec + 500) / 1000); | 1207 int64_t ms = timeout->tv_sec * 1000 + ((timeout->tv_usec + 500) / 1000); |
| 1201 | 1208 |
| 1202 // If the timeout is invalid or too long (larger than signed 32 bit). | 1209 // If the timeout is invalid or too long (larger than signed 32 bit). |
| 1203 if ((timeout->tv_sec < 0) || (timeout->tv_sec >= (INT_MAX / 1000)) || | 1210 if ((timeout->tv_sec < 0) || (timeout->tv_sec >= (INT_MAX / 1000)) || |
| 1204 (timeout->tv_usec < 0) || (timeout->tv_usec >= 1000000) || (ms < 0) || | 1211 (timeout->tv_usec < 0) || (timeout->tv_usec >= 1000000) || (ms < 0) || |
| 1205 (ms >= INT_MAX)) { | 1212 (ms >= INT_MAX)) { |
| 1206 LOG_TRACE("Invalid timeout: tv_sec=%d tv_usec=%d.", | 1213 LOG_TRACE("Invalid timeout: tv_sec=%" PRIi64 " tv_usec=%ld.", |
| 1207 timeout->tv_sec, | 1214 timeout->tv_sec, |
| 1208 timeout->tv_usec); | 1215 timeout->tv_usec); |
| 1209 errno = EINVAL; | 1216 errno = EINVAL; |
| 1210 return -1; | 1217 return -1; |
| 1211 } | 1218 } |
| 1212 | 1219 |
| 1213 ms_timeout = static_cast<int>(ms); | 1220 ms_timeout = static_cast<int>(ms); |
| 1214 } | 1221 } |
| 1215 | 1222 |
| 1216 int result = poll(&pollfds[0], pollfds.size(), ms_timeout); | 1223 int result = poll(&pollfds[0], pollfds.size(), ms_timeout); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 errno = ENOTSOCK; | 1792 errno = ENOTSOCK; |
| 1786 return -1; | 1793 return -1; |
| 1787 } | 1794 } |
| 1788 | 1795 |
| 1789 return 0; | 1796 return 0; |
| 1790 } | 1797 } |
| 1791 | 1798 |
| 1792 #endif // PROVIDES_SOCKET_API | 1799 #endif // PROVIDES_SOCKET_API |
| 1793 | 1800 |
| 1794 } // namespace_nacl_io | 1801 } // namespace_nacl_io |
| OLD | NEW |