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