| 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> |
| 11 | 11 |
| 12 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <sys/types.h> | 14 #include <sys/types.h> |
| 15 #include <semaphore.h> | 15 #include <semaphore.h> |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 #include "base/base_export.h" | 18 #include "base/base_export.h" |
| 19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/memory/shared_memory_handle.h" |
| 20 #include "base/process/process_handle.h" | 21 #include "base/process/process_handle.h" |
| 21 | 22 |
| 22 #if defined(OS_POSIX) | 23 #if defined(OS_POSIX) |
| 23 #include "base/file_descriptor_posix.h" | 24 #include "base/file_descriptor_posix.h" |
| 24 #include "base/files/file_util.h" | 25 #include "base/files/file_util.h" |
| 25 #include "base/files/scoped_file.h" | 26 #include "base/files/scoped_file.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 namespace base { | 29 namespace base { |
| 29 | 30 |
| 30 class FilePath; | 31 class FilePath; |
| 31 | 32 |
| 32 // SharedMemoryHandle is a platform specific type which represents | |
| 33 // the underlying OS handle to a shared memory segment. | |
| 34 #if defined(OS_WIN) | |
| 35 typedef HANDLE SharedMemoryHandle; | |
| 36 #elif defined(OS_POSIX) | |
| 37 typedef FileDescriptor SharedMemoryHandle; | |
| 38 #endif | |
| 39 | |
| 40 // Options for creating a shared memory object. | 33 // Options for creating a shared memory object. |
| 41 struct SharedMemoryCreateOptions { | 34 struct SharedMemoryCreateOptions { |
| 42 SharedMemoryCreateOptions() | 35 SharedMemoryCreateOptions() |
| 43 : name_deprecated(NULL), | 36 : name_deprecated(NULL), |
| 44 size(0), | 37 size(0), |
| 45 open_existing_deprecated(false), | 38 open_existing_deprecated(false), |
| 46 executable(false), | 39 executable(false), |
| 47 share_read_only(false) {} | 40 share_read_only(false) {} |
| 48 | 41 |
| 49 // DEPRECATED (crbug.com/345734): | 42 // DEPRECATED (crbug.com/345734): |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 explicit SharedMemory(const std::wstring& name); | 75 explicit SharedMemory(const std::wstring& name); |
| 83 #endif | 76 #endif |
| 84 | 77 |
| 85 // Create a new SharedMemory object from an existing, open | 78 // Create a new SharedMemory object from an existing, open |
| 86 // shared memory file. | 79 // shared memory file. |
| 87 // | 80 // |
| 88 // WARNING: This does not reduce the OS-level permissions on the handle; it | 81 // WARNING: This does not reduce the OS-level permissions on the handle; it |
| 89 // only affects how the SharedMemory will be mmapped. Use | 82 // only affects how the SharedMemory will be mmapped. Use |
| 90 // ShareReadOnlyToProcess to drop permissions. TODO(jln,jyasskin): DCHECK | 83 // ShareReadOnlyToProcess to drop permissions. TODO(jln,jyasskin): DCHECK |
| 91 // that |read_only| matches the permissions of the handle. | 84 // that |read_only| matches the permissions of the handle. |
| 92 SharedMemory(SharedMemoryHandle handle, bool read_only); | 85 SharedMemory(const SharedMemoryHandle& handle, bool read_only); |
| 93 | 86 |
| 94 // Create a new SharedMemory object from an existing, open | 87 // Create a new SharedMemory object from an existing, open |
| 95 // shared memory file that was created by a remote process and not shared | 88 // shared memory file that was created by a remote process and not shared |
| 96 // to the current process. | 89 // to the current process. |
| 97 SharedMemory(SharedMemoryHandle handle, bool read_only, | 90 SharedMemory(const SharedMemoryHandle& handle, |
| 91 bool read_only, |
| 98 ProcessHandle process); | 92 ProcessHandle process); |
| 99 | 93 |
| 100 // Closes any open files. | 94 // Closes any open files. |
| 101 ~SharedMemory(); | 95 ~SharedMemory(); |
| 102 | 96 |
| 103 // Return true iff the given handle is valid (i.e. not the distingished | 97 // Return true iff the given handle is valid (i.e. not the distingished |
| 104 // invalid value; NULL for a HANDLE and -1 for a file descriptor) | 98 // invalid value; NULL for a HANDLE and -1 for a file descriptor) |
| 105 static bool IsHandleValid(const SharedMemoryHandle& handle); | 99 static bool IsHandleValid(const SharedMemoryHandle& handle); |
| 106 | 100 |
| 107 // Returns invalid handle (see comment above for exact definition). | 101 // Returns invalid handle (see comment above for exact definition). |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 size_t mapped_size_; | 275 size_t mapped_size_; |
| 282 void* memory_; | 276 void* memory_; |
| 283 bool read_only_; | 277 bool read_only_; |
| 284 size_t requested_size_; | 278 size_t requested_size_; |
| 285 | 279 |
| 286 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 280 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
| 287 }; | 281 }; |
| 288 } // namespace base | 282 } // namespace base |
| 289 | 283 |
| 290 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 284 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
| OLD | NEW |