| 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 #ifndef LIBRARIES_NACL_IO_KERNEL_PROXY_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_PROXY_H_ |
| 6 #define LIBRARIES_NACL_IO_KERNEL_PROXY_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_PROXY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual int close(int fd); | 69 virtual int close(int fd); |
| 70 virtual int dup(int fd); | 70 virtual int dup(int fd); |
| 71 virtual int dup2(int fd, int newfd); | 71 virtual int dup2(int fd, int newfd); |
| 72 | 72 |
| 73 virtual void exit(int status); | 73 virtual void exit(int status); |
| 74 | 74 |
| 75 // Path related System calls handled by KernelProxy (not filesystem-specific) | 75 // Path related System calls handled by KernelProxy (not filesystem-specific) |
| 76 virtual int chdir(const char* path); | 76 virtual int chdir(const char* path); |
| 77 virtual char* getcwd(char* buf, size_t size); | 77 virtual char* getcwd(char* buf, size_t size); |
| 78 virtual char* getwd(char* buf); | 78 virtual char* getwd(char* buf); |
| 79 virtual int mount(const char *source, | 79 virtual int mount(const char* source, |
| 80 const char *target, | 80 const char* target, |
| 81 const char *filesystemtype, | 81 const char* filesystemtype, |
| 82 unsigned long mountflags, | 82 unsigned long mountflags, |
| 83 const void *data); | 83 const void* data); |
| 84 virtual int umount(const char *path); | 84 virtual int umount(const char* path); |
| 85 | 85 |
| 86 // Stub system calls that don't do anything (yet), handled by KernelProxy. | 86 // Stub system calls that don't do anything (yet), handled by KernelProxy. |
| 87 virtual int chown(const char* path, uid_t owner, gid_t group); | 87 virtual int chown(const char* path, uid_t owner, gid_t group); |
| 88 virtual int fchown(int fd, uid_t owner, gid_t group); | 88 virtual int fchown(int fd, uid_t owner, gid_t group); |
| 89 virtual int lchown(const char* path, uid_t owner, gid_t group); | 89 virtual int lchown(const char* path, uid_t owner, gid_t group); |
| 90 virtual int utime(const char* filename, const struct utimbuf* times); | 90 virtual int utime(const char* filename, const struct utimbuf* times); |
| 91 | 91 |
| 92 // System calls that take a path as an argument: The kernel proxy will look | 92 // System calls that take a path as an argument: The kernel proxy will look |
| 93 // for the Node associated to the path. To find the node, the kernel proxy | 93 // for the Node associated to the path. To find the node, the kernel proxy |
| 94 // calls the corresponding filesystem's GetNode() method. The corresponding | 94 // calls the corresponding filesystem's GetNode() method. The corresponding |
| 95 // method will be called. If the node cannot be found, errno is set and -1 is | 95 // method will be called. If the node cannot be found, errno is set and -1 is |
| 96 // returned. | 96 // returned. |
| 97 virtual int chmod(const char *path, mode_t mode); | 97 virtual int chmod(const char* path, mode_t mode); |
| 98 virtual int mkdir(const char *path, mode_t mode); | 98 virtual int mkdir(const char* path, mode_t mode); |
| 99 virtual int rmdir(const char *path); | 99 virtual int rmdir(const char* path); |
| 100 virtual int stat(const char *path, struct stat *buf); | 100 virtual int stat(const char* path, struct stat* buf); |
| 101 | 101 |
| 102 // System calls that take a file descriptor as an argument: | 102 // System calls that take a file descriptor as an argument: |
| 103 // The kernel proxy will determine to which filesystem the file | 103 // The kernel proxy will determine to which filesystem the file |
| 104 // descriptor's corresponding file handle belongs. The | 104 // descriptor's corresponding file handle belongs. The |
| 105 // associated filesystem's function will be called. | 105 // associated filesystem's function will be called. |
| 106 virtual ssize_t read(int fd, void *buf, size_t nbyte); | 106 virtual ssize_t read(int fd, void* buf, size_t nbyte); |
| 107 virtual ssize_t write(int fd, const void *buf, size_t nbyte); | 107 virtual ssize_t write(int fd, const void* buf, size_t nbyte); |
| 108 | 108 |
| 109 virtual int fchmod(int fd, int prot); | 109 virtual int fchmod(int fd, int prot); |
| 110 virtual int fcntl(int fd, int request, va_list args); | 110 virtual int fcntl(int fd, int request, va_list args); |
| 111 virtual int fstat(int fd, struct stat *buf); | 111 virtual int fstat(int fd, struct stat* buf); |
| 112 virtual int getdents(int fd, void *buf, unsigned int count); | 112 virtual int getdents(int fd, void* buf, unsigned int count); |
| 113 virtual int fchdir(int fd); | 113 virtual int fchdir(int fd); |
| 114 virtual int ftruncate(int fd, off_t length); | 114 virtual int ftruncate(int fd, off_t length); |
| 115 virtual int fsync(int fd); | 115 virtual int fsync(int fd); |
| 116 virtual int fdatasync(int fd); | 116 virtual int fdatasync(int fd); |
| 117 virtual int isatty(int fd); | 117 virtual int isatty(int fd); |
| 118 virtual int ioctl(int fd, int request, va_list args); | 118 virtual int ioctl(int fd, int request, va_list args); |
| 119 | 119 |
| 120 // lseek() relies on the filesystem's Stat() to determine whether or not the | 120 // lseek() relies on the filesystem's Stat() to determine whether or not the |
| 121 // file handle corresponding to fd is a directory | 121 // file handle corresponding to fd is a directory |
| 122 virtual off_t lseek(int fd, off_t offset, int whence); | 122 virtual off_t lseek(int fd, off_t offset, int whence); |
| 123 | 123 |
| 124 // remove() uses the filesystem's GetNode() and Stat() to determine whether | 124 // remove() uses the filesystem's GetNode() and Stat() to determine whether |
| 125 // or not the path corresponds to a directory or a file. The filesystem's | 125 // or not the path corresponds to a directory or a file. The filesystem's |
| 126 // Rmdir() or Unlink() is called accordingly. | 126 // Rmdir() or Unlink() is called accordingly. |
| 127 virtual int remove(const char* path); | 127 virtual int remove(const char* path); |
| 128 // unlink() is a simple wrapper around the filesystem's Unlink function. | 128 // unlink() is a simple wrapper around the filesystem's Unlink function. |
| 129 virtual int unlink(const char* path); | 129 virtual int unlink(const char* path); |
| 130 virtual int truncate(const char* path, off_t len); | 130 virtual int truncate(const char* path, off_t len); |
| 131 virtual int lstat(const char* path, struct stat* buf); | 131 virtual int lstat(const char* path, struct stat* buf); |
| 132 virtual int rename(const char* path, const char* newpath); | 132 virtual int rename(const char* path, const char* newpath); |
| 133 // access() uses the Filesystem's Stat(). | 133 // access() uses the Filesystem's Stat(). |
| 134 virtual int access(const char* path, int amode); | 134 virtual int access(const char* path, int amode); |
| 135 virtual int readlink(const char *path, char *buf, size_t count); | 135 virtual int readlink(const char* path, char* buf, size_t count); |
| 136 virtual int utimes(const char *filename, const struct timeval times[2]); | 136 virtual int utimes(const char* filename, const struct timeval times[2]); |
| 137 | 137 |
| 138 virtual int link(const char* oldpath, const char* newpath); | 138 virtual int link(const char* oldpath, const char* newpath); |
| 139 virtual int symlink(const char* oldpath, const char* newpath); | 139 virtual int symlink(const char* oldpath, const char* newpath); |
| 140 | 140 |
| 141 virtual void* mmap(void* addr, | 141 virtual void* mmap(void* addr, |
| 142 size_t length, | 142 size_t length, |
| 143 int prot, | 143 int prot, |
| 144 int flags, | 144 int flags, |
| 145 int fd, | 145 int fd, |
| 146 size_t offset); | 146 size_t offset); |
| 147 virtual int munmap(void* addr, size_t length); | 147 virtual int munmap(void* addr, size_t length); |
| 148 virtual int tcflush(int fd, int queue_selector); | 148 virtual int tcflush(int fd, int queue_selector); |
| 149 virtual int tcgetattr(int fd, struct termios* termios_p); | 149 virtual int tcgetattr(int fd, struct termios* termios_p); |
| 150 virtual int tcsetattr(int fd, int optional_actions, | 150 virtual int tcsetattr(int fd, |
| 151 const struct termios *termios_p); | 151 int optional_actions, |
| 152 const struct termios* termios_p); |
| 152 | 153 |
| 153 virtual int kill(pid_t pid, int sig); | 154 virtual int kill(pid_t pid, int sig); |
| 154 virtual int sigaction(int signum, const struct sigaction* action, | 155 virtual int sigaction(int signum, |
| 156 const struct sigaction* action, |
| 155 struct sigaction* oaction); | 157 struct sigaction* oaction); |
| 156 | 158 |
| 157 #ifdef PROVIDES_SOCKET_API | 159 #ifdef PROVIDES_SOCKET_API |
| 158 virtual int select(int nfds, fd_set* readfds, fd_set* writefds, | 160 virtual int select(int nfds, |
| 159 fd_set* exceptfds, struct timeval* timeout); | 161 fd_set* readfds, |
| 162 fd_set* writefds, |
| 163 fd_set* exceptfds, |
| 164 struct timeval* timeout); |
| 160 | 165 |
| 161 virtual int poll(struct pollfd *fds, nfds_t nfds, int timeout); | 166 virtual int poll(struct pollfd* fds, nfds_t nfds, int timeout); |
| 162 | 167 |
| 163 // Socket support functions | 168 // Socket support functions |
| 164 virtual int accept(int fd, struct sockaddr* addr, socklen_t* len); | 169 virtual int accept(int fd, struct sockaddr* addr, socklen_t* len); |
| 165 virtual int bind(int fd, const struct sockaddr* addr, socklen_t len); | 170 virtual int bind(int fd, const struct sockaddr* addr, socklen_t len); |
| 166 virtual int connect(int fd, const struct sockaddr* addr, socklen_t len); | 171 virtual int connect(int fd, const struct sockaddr* addr, socklen_t len); |
| 167 virtual struct hostent* gethostbyname(const char* name); | 172 virtual struct hostent* gethostbyname(const char* name); |
| 168 virtual void freeaddrinfo(struct addrinfo *res); | 173 virtual void freeaddrinfo(struct addrinfo* res); |
| 169 virtual int getaddrinfo(const char* node, const char* service, | 174 virtual int getaddrinfo(const char* node, |
| 175 const char* service, |
| 170 const struct addrinfo* hints, | 176 const struct addrinfo* hints, |
| 171 struct addrinfo** res); | 177 struct addrinfo** res); |
| 172 virtual int getpeername(int fd, struct sockaddr* addr, socklen_t* len); | 178 virtual int getpeername(int fd, struct sockaddr* addr, socklen_t* len); |
| 173 virtual int getsockname(int fd, struct sockaddr* addr, socklen_t* len); | 179 virtual int getsockname(int fd, struct sockaddr* addr, socklen_t* len); |
| 174 virtual int getsockopt(int fd, | 180 virtual int getsockopt(int fd, |
| 175 int lvl, | 181 int lvl, |
| 176 int optname, | 182 int optname, |
| 177 void* optval, | 183 void* optval, |
| 178 socklen_t* len); | 184 socklen_t* len); |
| 179 virtual int listen(int fd, int backlog); | 185 virtual int listen(int fd, int backlog); |
| 180 virtual ssize_t recv(int fd, | 186 virtual ssize_t recv(int fd, void* buf, size_t len, int flags); |
| 181 void* buf, | |
| 182 size_t len, | |
| 183 int flags); | |
| 184 virtual ssize_t recvfrom(int fd, | 187 virtual ssize_t recvfrom(int fd, |
| 185 void* buf, | 188 void* buf, |
| 186 size_t len, | 189 size_t len, |
| 187 int flags, | 190 int flags, |
| 188 struct sockaddr* addr, | 191 struct sockaddr* addr, |
| 189 socklen_t* addrlen); | 192 socklen_t* addrlen); |
| 190 virtual ssize_t recvmsg(int fd, struct msghdr* msg, int flags); | 193 virtual ssize_t recvmsg(int fd, struct msghdr* msg, int flags); |
| 191 virtual ssize_t send(int fd, const void* buf, size_t len, int flags); | 194 virtual ssize_t send(int fd, const void* buf, size_t len, int flags); |
| 192 virtual ssize_t sendto(int fd, | 195 virtual ssize_t sendto(int fd, |
| 193 const void* buf, | 196 const void* buf, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 216 ScopedFilesystem* out_filesystem); | 219 ScopedFilesystem* out_filesystem); |
| 217 | 220 |
| 218 Error CreateFsNode(const ScopedFilesystem& fs); | 221 Error CreateFsNode(const ScopedFilesystem& fs); |
| 219 | 222 |
| 220 protected: | 223 protected: |
| 221 FsFactoryMap_t factories_; | 224 FsFactoryMap_t factories_; |
| 222 sdk_util::ScopedRef<StreamFs> stream_fs_; | 225 sdk_util::ScopedRef<StreamFs> stream_fs_; |
| 223 sdk_util::ScopedRef<DevFs> dev_fs_; | 226 sdk_util::ScopedRef<DevFs> dev_fs_; |
| 224 int dev_; | 227 int dev_; |
| 225 PepperInterface* ppapi_; | 228 PepperInterface* ppapi_; |
| 226 static KernelProxy *s_instance_; | 229 static KernelProxy* s_instance_; |
| 227 struct sigaction sigwinch_handler_; | 230 struct sigaction sigwinch_handler_; |
| 228 nacl_io_exit_handler_t exit_handler_; | 231 nacl_io_exit_handler_t exit_handler_; |
| 229 void* exit_handler_user_data_; | 232 void* exit_handler_user_data_; |
| 230 #ifdef PROVIDES_SOCKET_API | 233 #ifdef PROVIDES_SOCKET_API |
| 231 HostResolver host_resolver_; | 234 HostResolver host_resolver_; |
| 232 #endif | 235 #endif |
| 233 | 236 |
| 234 #ifdef PROVIDES_SOCKET_API | 237 #ifdef PROVIDES_SOCKET_API |
| 235 virtual int AcquireSocketHandle(int fd, ScopedKernelHandle* handle); | 238 virtual int AcquireSocketHandle(int fd, ScopedKernelHandle* handle); |
| 236 #endif | 239 #endif |
| 237 | 240 |
| 238 ScopedEventEmitter signal_emitter_; | 241 ScopedEventEmitter signal_emitter_; |
| 239 DISALLOW_COPY_AND_ASSIGN(KernelProxy); | 242 DISALLOW_COPY_AND_ASSIGN(KernelProxy); |
| 240 }; | 243 }; |
| 241 | 244 |
| 242 } // namespace nacl_io | 245 } // namespace nacl_io |
| 243 | 246 |
| 244 #endif // LIBRARIES_NACL_IO_KERNEL_PROXY_H_ | 247 #endif // LIBRARIES_NACL_IO_KERNEL_PROXY_H_ |
| OLD | NEW |