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 BASE_MEMORY_SHARED_MEMORY_H_ | 5 #ifndef BASE_MEMORY_SHARED_MEMORY_H_ |
6 #define BASE_MEMORY_SHARED_MEMORY_H_ | 6 #define BASE_MEMORY_SHARED_MEMORY_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/files/file_util.h" | 24 #include "base/files/file_util.h" |
25 #include "base/files/scoped_file.h" | 25 #include "base/files/scoped_file.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 | 29 |
30 class FilePath; | 30 class FilePath; |
31 | 31 |
32 // SharedMemoryHandle is a platform specific type which represents | 32 // SharedMemoryHandle is a platform specific type which represents |
33 // the underlying OS handle to a shared memory segment. | 33 // the underlying OS handle to a shared memory segment. |
34 #if defined(OS_WIN) | 34 #if defined(OS_POSIX) |
35 typedef HANDLE SharedMemoryHandle; | |
36 #elif defined(OS_POSIX) | |
37 typedef FileDescriptor SharedMemoryHandle; | 35 typedef FileDescriptor SharedMemoryHandle; |
38 #endif | 36 #endif |
39 | 37 |
40 // Options for creating a shared memory object. | 38 // Options for creating a shared memory object. |
41 struct SharedMemoryCreateOptions { | 39 struct SharedMemoryCreateOptions { |
42 SharedMemoryCreateOptions() | 40 SharedMemoryCreateOptions() |
43 : name_deprecated(NULL), | 41 : name_deprecated(NULL), |
44 size(0), | 42 size(0), |
45 open_existing_deprecated(false), | 43 open_existing_deprecated(false), |
46 executable(false), | 44 executable(false), |
(...skipping 21 matching lines...) Expand all Loading... |
68 // If true, the file can be shared read-only to a process. | 66 // If true, the file can be shared read-only to a process. |
69 bool share_read_only; | 67 bool share_read_only; |
70 }; | 68 }; |
71 | 69 |
72 // Platform abstraction for shared memory. Provides a C++ wrapper | 70 // Platform abstraction for shared memory. Provides a C++ wrapper |
73 // around the OS primitive for a memory mapped file. | 71 // around the OS primitive for a memory mapped file. |
74 class BASE_EXPORT SharedMemory { | 72 class BASE_EXPORT SharedMemory { |
75 public: | 73 public: |
76 SharedMemory(); | 74 SharedMemory(); |
77 | 75 |
78 #if defined(OS_WIN) | |
79 // Similar to the default constructor, except that this allows for | |
80 // calling LockDeprecated() to acquire the named mutex before either Create or | |
81 // Open are called on Windows. | |
82 explicit SharedMemory(const std::wstring& name); | |
83 #endif | |
84 | |
85 // Create a new SharedMemory object from an existing, open | 76 // Create a new SharedMemory object from an existing, open |
86 // shared memory file. | 77 // shared memory file. |
87 // | 78 // |
88 // WARNING: This does not reduce the OS-level permissions on the handle; it | 79 // WARNING: This does not reduce the OS-level permissions on the handle; it |
89 // only affects how the SharedMemory will be mmapped. Use | 80 // only affects how the SharedMemory will be mmapped. Use |
90 // ShareReadOnlyToProcess to drop permissions. TODO(jln,jyasskin): DCHECK | 81 // ShareReadOnlyToProcess to drop permissions. TODO(jln,jyasskin): DCHECK |
91 // that |read_only| matches the permissions of the handle. | 82 // that |read_only| matches the permissions of the handle. |
92 SharedMemory(SharedMemoryHandle handle, bool read_only); | 83 SharedMemory(SharedMemoryHandle handle, bool read_only); |
93 | 84 |
94 // Create a new SharedMemory object from an existing, open | 85 // Create a new SharedMemory object from an existing, open |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 271 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
281 enum ShareMode { | 272 enum ShareMode { |
282 SHARE_READONLY, | 273 SHARE_READONLY, |
283 SHARE_CURRENT_MODE, | 274 SHARE_CURRENT_MODE, |
284 }; | 275 }; |
285 bool ShareToProcessCommon(ProcessHandle process, | 276 bool ShareToProcessCommon(ProcessHandle process, |
286 SharedMemoryHandle* new_handle, | 277 SharedMemoryHandle* new_handle, |
287 bool close_self, | 278 bool close_self, |
288 ShareMode); | 279 ShareMode); |
289 | 280 |
290 #if defined(OS_WIN) | 281 #if defined(OS_POSIX) |
291 std::wstring name_; | |
292 HANDLE mapped_file_; | |
293 #elif defined(OS_POSIX) | |
294 int mapped_file_; | 282 int mapped_file_; |
295 int readonly_mapped_file_; | 283 int readonly_mapped_file_; |
296 #endif | 284 #endif |
297 size_t mapped_size_; | 285 size_t mapped_size_; |
298 void* memory_; | 286 void* memory_; |
299 bool read_only_; | 287 bool read_only_; |
300 size_t requested_size_; | 288 size_t requested_size_; |
301 #if !defined(OS_POSIX) | 289 #if !defined(OS_POSIX) |
302 HANDLE lock_; | 290 HANDLE lock_; |
303 #endif | 291 #endif |
(...skipping 16 matching lines...) Expand all Loading... |
320 } | 308 } |
321 | 309 |
322 private: | 310 private: |
323 SharedMemory* shared_memory_; | 311 SharedMemory* shared_memory_; |
324 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); | 312 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); |
325 }; | 313 }; |
326 | 314 |
327 } // namespace base | 315 } // namespace base |
328 | 316 |
329 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 317 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |