Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_object.h

Issue 99203014: [NaCl SDK] Map active fds to absolute paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add absolute path to Descriptor_t Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/kernel_object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 12 matching lines...) Expand all
23 namespace nacl_io { 23 namespace nacl_io {
24 24
25 // KernelObject provides basic functionality for threadsafe access to kernel 25 // KernelObject provides basic functionality for threadsafe access to kernel
26 // objects such as the CWD, mount points, file descriptors and file handles. 26 // objects such as the CWD, mount points, file descriptors and file handles.
27 // All Kernel locks are private to ensure the lock order. 27 // All Kernel locks are private to ensure the lock order.
28 // 28 //
29 // All calls are assumed to be a relative path. 29 // All calls are assumed to be a relative path.
30 class KernelObject { 30 class KernelObject {
31 public: 31 public:
32 struct Descriptor_t { 32 struct Descriptor_t {
33 Descriptor_t() : flags(0) {} 33 Descriptor_t() : flags(0), path() {}
binji 2014/01/08 17:25:43 nit: path() is unnecessary, the default constructo
34 explicit Descriptor_t(const ScopedKernelHandle& h) : handle(h), flags(0) {} 34 explicit Descriptor_t(const ScopedKernelHandle& h, const std::string& path_)
35 : handle(h), flags(0), path(path_) {}
Sam Clegg 2014/01/08 18:23:24 The _ suffix is used for member variables in the s
35 36
36 ScopedKernelHandle handle; 37 ScopedKernelHandle handle;
37 int flags; 38 int flags;
39 std::string path;
38 }; 40 };
39 typedef std::vector<Descriptor_t> HandleMap_t; 41 typedef std::vector<Descriptor_t> HandleMap_t;
40 typedef std::map<std::string, ScopedFilesystem> FsMap_t; 42 typedef std::map<std::string, ScopedFilesystem> FsMap_t;
41 43
42 KernelObject(); 44 KernelObject();
43 virtual ~KernelObject(); 45 virtual ~KernelObject();
44 46
45 // Attach the given Filesystem object at the specified path. 47 // Attach the given Filesystem object at the specified path.
46 Error AttachFsAtPath(const ScopedFilesystem& fs, const std::string& path); 48 Error AttachFsAtPath(const ScopedFilesystem& fs, const std::string& path);
47 49
(...skipping 10 matching lines...) Expand all
58 // Find the filesystem and node for the given path, acquiring/creating it as 60 // Find the filesystem and node for the given path, acquiring/creating it as
59 // specified by the |oflags|. 61 // specified by the |oflags|.
60 // Assumes |out_fs| and |out_node| are non-NULL. 62 // Assumes |out_fs| and |out_node| are non-NULL.
61 Error AcquireFsAndNode(const std::string& path, 63 Error AcquireFsAndNode(const std::string& path,
62 int oflags, 64 int oflags,
63 ScopedFilesystem* out_fs, 65 ScopedFilesystem* out_fs,
64 ScopedNode* out_node); 66 ScopedNode* out_node);
65 67
66 // Get FD-specific flags (currently only FD_CLOEXEC is supported). 68 // Get FD-specific flags (currently only FD_CLOEXEC is supported).
67 Error GetFDFlags(int fd, int* out_flags); 69 Error GetFDFlags(int fd, int* out_flags);
70 // Get path at which FD was opened, if available.
71 std::string GetFDPath(int fd);
binji 2014/01/08 17:25:43 remove GetFDPath
68 // Set FD-specific flags (currently only FD_CLOEXEC is supported). 72 // Set FD-specific flags (currently only FD_CLOEXEC is supported).
69 Error SetFDFlags(int fd, int flags); 73 Error SetFDFlags(int fd, int flags);
70 74
71 // Convert from FD to KernelHandle, and acquire the handle. 75 // Convert from FD to KernelHandle, and acquire the handle.
72 // Assumes |out_handle| is non-NULL. 76 // Assumes |out_handle| is non-NULL.
73 Error AcquireHandle(int fd, ScopedKernelHandle* out_handle); 77 Error AcquireHandle(int fd, ScopedKernelHandle* out_handle);
78 Error AcquireHandleAndPath(int fd, ScopedKernelHandle *out_handle,
79 std::string& path);
binji 2014/01/08 17:25:43 Our style guide says that out parameters must be p
74 80
75 // Allocate a new fd and assign the handle to it, while 81 // Allocate a new fd and assign the handle to it, while
76 // ref counting the handle and associated filesystem. 82 // ref counting the handle and associated filesystem.
77 // Assumes |handle| is non-NULL; 83 // Assumes |handle| is non-NULL;
78 int AllocateFD(const ScopedKernelHandle& handle); 84 int AllocateFD(const ScopedKernelHandle& handle,
85 const std::string& path = std::string());
Sam Clegg 2014/01/08 18:23:24 No spaces around the "=" sign for default params.
79 86
80 // Assumes |handle| is non-NULL; 87 // Assumes |handle| is non-NULL;
81 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle); 88 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle,
89 const std::string& path);
82 void FreeFD(int fd); 90 void FreeFD(int fd);
83 91
84 // Returns or sets CWD 92 // Returns or sets CWD
85 std::string GetCWD(); 93 std::string GetCWD();
86 Error SetCWD(const std::string& path); 94 Error SetCWD(const std::string& path);
87 95
88 // Returns parts of the absolute path for the given relative path 96 // Returns parts of the absolute path for the given relative path
89 Path GetAbsParts(const std::string& path); 97 Path GetAbsParts(const std::string& path);
90 98
91 private: 99 private:
(...skipping 10 matching lines...) Expand all
102 110
103 // Lock to protect cwd_. 111 // Lock to protect cwd_.
104 sdk_util::SimpleLock cwd_lock_; 112 sdk_util::SimpleLock cwd_lock_;
105 113
106 DISALLOW_COPY_AND_ASSIGN(KernelObject); 114 DISALLOW_COPY_AND_ASSIGN(KernelObject);
107 }; 115 };
108 116
109 } // namespace nacl_io 117 } // namespace nacl_io
110 118
111 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ 119 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/kernel_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698