| 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 |
| 11 #include "nacl_io/host_resolver.h" | 11 #include "nacl_io/host_resolver.h" |
| 12 #include "nacl_io/kernel_object.h" | 12 #include "nacl_io/kernel_object.h" |
| 13 #include "nacl_io/mount_factory.h" | 13 #include "nacl_io/mount_factory.h" |
| 14 #include "nacl_io/mount_socket.h" | 14 #include "nacl_io/mount_socket.h" |
| 15 #include "nacl_io/ossignal.h" |
| 15 #include "nacl_io/ossocket.h" | 16 #include "nacl_io/ossocket.h" |
| 16 #include "nacl_io/ostypes.h" | 17 #include "nacl_io/ostypes.h" |
| 17 #include "nacl_io/osutime.h" | 18 #include "nacl_io/osutime.h" |
| 18 | 19 |
| 19 struct timeval; | 20 struct timeval; |
| 20 | 21 |
| 21 namespace nacl_io { | 22 namespace nacl_io { |
| 22 | 23 |
| 23 class PepperInterface; | 24 class PepperInterface; |
| 24 | 25 |
| 25 // KernelProxy provide one-to-one mapping for libc kernel calls. Calls to the | 26 // KernelProxy provide one-to-one mapping for libc kernel calls. Calls to the |
| 26 // proxy will result in IO access to the provided Mount and MountNode objects. | 27 // proxy will result in IO access to the provided Mount and MountNode objects. |
| 27 // | 28 // |
| 28 // NOTE: The KernelProxy does not directly take any kernel locks, all locking | 29 // NOTE: The KernelProxy does not directly take any kernel locks, all locking |
| 29 // is done by the parent class KernelObject. Instead, KernelProxy is | 30 // is done by the parent class KernelObject. Instead, KernelProxy is |
| 30 // responsible for taking the locks of the KernelHandle, and MountNode objects. | 31 // responsible for taking the locks of the KernelHandle, and MountNode objects. |
| 31 // For this reason, a KernelObject call should not be done while holding | 32 // For this reason, a KernelObject call should not be done while holding |
| 32 // a handle or node lock. In addition, to ensure locking order, | 33 // a handle or node lock. In addition, to ensure locking order, |
| 33 // a KernelHandle lock must never be taken after taking the associated | 34 // a KernelHandle lock must never be taken after taking the associated |
| 34 // MountNode's lock. | 35 // MountNode's lock. |
| 35 // | 36 // |
| 36 // NOTE: The KernelProxy is the only class that should be setting errno. All | 37 // NOTE: The KernelProxy is the only class that should be setting errno. All |
| 37 // other classes should return Error (as defined by nacl_io/error.h). | 38 // other classes should return Error (as defined by nacl_io/error.h). |
| 38 class KernelProxy : protected KernelObject { | 39 class KernelProxy : public KernelObject { |
| 39 public: | 40 public: |
| 40 typedef std::map<std::string, MountFactory*> MountFactoryMap_t; | 41 typedef std::map<std::string, MountFactory*> MountFactoryMap_t; |
| 41 | 42 |
| 42 KernelProxy(); | 43 KernelProxy(); |
| 43 virtual ~KernelProxy(); | 44 virtual ~KernelProxy(); |
| 44 | 45 |
| 45 // Takes ownership of |ppapi|. | 46 // Takes ownership of |ppapi|. |
| 46 // |ppapi| may be NULL. If so, no mount that uses pepper calls can be mounted. | 47 // |ppapi| may be NULL. If so, no mount that uses pepper calls can be mounted. |
| 47 virtual void Init(PepperInterface* ppapi); | 48 virtual void Init(PepperInterface* ppapi); |
| 48 | 49 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 int prot, | 119 int prot, |
| 119 int flags, | 120 int flags, |
| 120 int fd, | 121 int fd, |
| 121 size_t offset); | 122 size_t offset); |
| 122 virtual int munmap(void* addr, size_t length); | 123 virtual int munmap(void* addr, size_t length); |
| 123 virtual int tcflush(int fd, int queue_selector); | 124 virtual int tcflush(int fd, int queue_selector); |
| 124 virtual int tcgetattr(int fd, struct termios* termios_p); | 125 virtual int tcgetattr(int fd, struct termios* termios_p); |
| 125 virtual int tcsetattr(int fd, int optional_actions, | 126 virtual int tcsetattr(int fd, int optional_actions, |
| 126 const struct termios *termios_p); | 127 const struct termios *termios_p); |
| 127 | 128 |
| 129 virtual int kill(pid_t pid, int sig); |
| 130 virtual sighandler_t sigset(int signum, sighandler_t handler); |
| 131 |
| 128 #ifdef PROVIDES_SOCKET_API | 132 #ifdef PROVIDES_SOCKET_API |
| 129 virtual int select(int nfds, fd_set* readfds, fd_set* writefds, | 133 virtual int select(int nfds, fd_set* readfds, fd_set* writefds, |
| 130 fd_set* exceptfds, struct timeval* timeout); | 134 fd_set* exceptfds, struct timeval* timeout); |
| 131 | 135 |
| 132 virtual int poll(struct pollfd *fds, nfds_t nfds, int timeout); | 136 virtual int poll(struct pollfd *fds, nfds_t nfds, int timeout); |
| 133 | 137 |
| 134 // Socket support functions | 138 // Socket support functions |
| 135 virtual int accept(int fd, struct sockaddr* addr, socklen_t* len); | 139 virtual int accept(int fd, struct sockaddr* addr, socklen_t* len); |
| 136 virtual int bind(int fd, const struct sockaddr* addr, socklen_t len); | 140 virtual int bind(int fd, const struct sockaddr* addr, socklen_t len); |
| 137 virtual int connect(int fd, const struct sockaddr* addr, socklen_t len); | 141 virtual int connect(int fd, const struct sockaddr* addr, socklen_t len); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 virtual int socket(int domain, int type, int protocol); | 176 virtual int socket(int domain, int type, int protocol); |
| 173 virtual int socketpair(int domain, int type, int protocol, int* sv); | 177 virtual int socketpair(int domain, int type, int protocol, int* sv); |
| 174 #endif // PROVIDES_SOCKET_API | 178 #endif // PROVIDES_SOCKET_API |
| 175 | 179 |
| 176 protected: | 180 protected: |
| 177 MountFactoryMap_t factories_; | 181 MountFactoryMap_t factories_; |
| 178 sdk_util::ScopedRef<MountSocket> socket_mount_; | 182 sdk_util::ScopedRef<MountSocket> socket_mount_; |
| 179 int dev_; | 183 int dev_; |
| 180 PepperInterface* ppapi_; | 184 PepperInterface* ppapi_; |
| 181 static KernelProxy *s_instance_; | 185 static KernelProxy *s_instance_; |
| 186 sighandler_t sigwinch_handler_; |
| 182 #ifdef PROVIDES_SOCKET_API | 187 #ifdef PROVIDES_SOCKET_API |
| 183 HostResolver host_resolver_; | 188 HostResolver host_resolver_; |
| 184 #endif | 189 #endif |
| 185 | 190 |
| 186 #ifdef PROVIDES_SOCKET_API | 191 #ifdef PROVIDES_SOCKET_API |
| 187 virtual int AcquireSocketHandle(int fd, ScopedKernelHandle* handle); | 192 virtual int AcquireSocketHandle(int fd, ScopedKernelHandle* handle); |
| 188 #endif | 193 #endif |
| 189 | 194 |
| 190 DISALLOW_COPY_AND_ASSIGN(KernelProxy); | 195 DISALLOW_COPY_AND_ASSIGN(KernelProxy); |
| 191 }; | 196 }; |
| 192 | 197 |
| 198 typedef sdk_util::ScopedRef<KernelProxy> ScopedKernelProxy; |
| 199 |
| 193 } // namespace nacl_io | 200 } // namespace nacl_io |
| 194 | 201 |
| 195 #endif // LIBRARIES_NACL_IO_KERNEL_PROXY_H_ | 202 #endif // LIBRARIES_NACL_IO_KERNEL_PROXY_H_ |
| OLD | NEW |