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_OBJECT_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
6 #define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
7 | 7 |
8 #include <pthread.h> | 8 #include <pthread.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "nacl_io/error.h" |
14 #include "nacl_io/path.h" | 15 #include "nacl_io/path.h" |
15 | 16 |
16 class KernelHandle; | 17 class KernelHandle; |
17 class Mount; | 18 class Mount; |
18 | 19 |
19 // KernelObject provides basic functionality for threadsafe | 20 // KernelObject provides basic functionality for threadsafe |
20 // access to kernel objects such as file descriptors and | 21 // access to kernel objects such as file descriptors and |
21 // file handles. It also provides access to the CWD for | 22 // file handles. It also provides access to the CWD for |
22 // path resolution. | 23 // path resolution. |
23 class KernelObject { | 24 class KernelObject { |
24 public: | 25 public: |
25 typedef std::vector<KernelHandle*> HandleMap_t; | 26 typedef std::vector<KernelHandle*> HandleMap_t; |
26 typedef std::map<std::string, Mount*> MountMap_t; | 27 typedef std::map<std::string, Mount*> MountMap_t; |
27 | 28 |
28 KernelObject(); | 29 KernelObject(); |
29 virtual ~KernelObject(); | 30 virtual ~KernelObject(); |
30 | 31 |
31 // Find the mount for the given path, and acquires it | 32 // Find the mount for the given path, and acquires it. |
32 Mount* AcquireMountAndPath(const std::string& relpath, Path *pobj); | 33 // Assumes |out_mount| and |out_path| are non-NULL. |
| 34 Error AcquireMountAndPath(const std::string& relpath, |
| 35 Mount** out_mount, |
| 36 Path* out_path); |
| 37 // Assumes |mnt| is non-NULL. |
33 void ReleaseMount(Mount* mnt); | 38 void ReleaseMount(Mount* mnt); |
34 | 39 |
35 // Convert from FD to KernelHandle, and acquire the handle. | 40 // Convert from FD to KernelHandle, and acquire the handle. |
36 KernelHandle* AcquireHandle(int fd); | 41 // Assumes |out_handle| is non-NULL. |
| 42 Error AcquireHandle(int fd, KernelHandle** out_handle); |
| 43 // Assumes |handle| is non-NULL. |
37 void ReleaseHandle(KernelHandle* handle); | 44 void ReleaseHandle(KernelHandle* handle); |
38 | 45 |
39 // Allocate a new fd and assign the handle to it, while | 46 // Allocate a new fd and assign the handle to it, while |
40 // ref counting the handle and associated mount. | 47 // ref counting the handle and associated mount. |
| 48 // Assumes |handle| is non-NULL; |
41 int AllocateFD(KernelHandle* handle); | 49 int AllocateFD(KernelHandle* handle); |
| 50 // Assumes |handle| is non-NULL; |
42 void FreeAndReassignFD(int fd, KernelHandle* handle); | 51 void FreeAndReassignFD(int fd, KernelHandle* handle); |
43 void FreeFD(int fd); | 52 void FreeFD(int fd); |
44 | 53 |
45 protected: | 54 protected: |
46 Path GetAbsPathLocked(const std::string& path); | 55 Path GetAbsPathLocked(const std::string& path); |
47 | 56 |
48 std::vector<int> free_fds_; | 57 std::vector<int> free_fds_; |
49 std::string cwd_; | 58 std::string cwd_; |
50 | 59 |
51 HandleMap_t handle_map_; | 60 HandleMap_t handle_map_; |
52 MountMap_t mounts_; | 61 MountMap_t mounts_; |
53 | 62 |
54 // Kernel lock protects kernel wide resources such as the mount table... | 63 // Kernel lock protects kernel wide resources such as the mount table... |
55 pthread_mutex_t kernel_lock_; | 64 pthread_mutex_t kernel_lock_; |
56 | 65 |
57 // Process lock protects process wide resources such as CWD, file handles... | 66 // Process lock protects process wide resources such as CWD, file handles... |
58 pthread_mutex_t process_lock_; | 67 pthread_mutex_t process_lock_; |
59 | 68 |
60 DISALLOW_COPY_AND_ASSIGN(KernelObject); | 69 DISALLOW_COPY_AND_ASSIGN(KernelObject); |
61 }; | 70 }; |
62 | 71 |
63 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 72 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
OLD | NEW |