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