OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/shared_memory.h" | 5 #include "base/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 // static | 90 // static |
91 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { | 91 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { |
92 DCHECK_GE(handle.fd, 0); | 92 DCHECK_GE(handle.fd, 0); |
93 if (HANDLE_EINTR(close(handle.fd)) < 0) | 93 if (HANDLE_EINTR(close(handle.fd)) < 0) |
94 DPLOG(ERROR) << "close"; | 94 DPLOG(ERROR) << "close"; |
95 } | 95 } |
96 | 96 |
97 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { | 97 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { |
98 return CreateAnonymous(size) && Map(size); | 98 return CreateAnonymous(size, false) && Map(size); |
99 } | 99 } |
100 | 100 |
101 bool SharedMemory::CreateAnonymous(uint32 size) { | 101 bool SharedMemory::CreateAnonymous(uint32 size, bool executable) { |
102 return CreateNamed("", false, size); | 102 return CreateNamed("", false, size, executable); |
103 } | 103 } |
104 | 104 |
105 #if !defined(OS_ANDROID) | 105 #if !defined(OS_ANDROID) |
106 // Chromium mostly only uses the unique/private shmem as specified by | 106 // Chromium mostly only uses the unique/private shmem as specified by |
107 // "name == L"". The exception is in the StatsTable. | 107 // "name == L"". The exception is in the StatsTable. |
108 // TODO(jrg): there is no way to "clean up" all unused named shmem if | 108 // TODO(jrg): there is no way to "clean up" all unused named shmem if |
109 // we restart from a crash. (That isn't a new problem, but it is a problem.) | 109 // we restart from a crash. (That isn't a new problem, but it is a problem.) |
110 // In case we want to delete it later, it may be useful to save the value | 110 // In case we want to delete it later, it may be useful to save the value |
111 // of mem_filename after FilePathForMemoryName(). | 111 // of mem_filename after FilePathForMemoryName(). |
112 bool SharedMemory::CreateNamed(const std::string& name, | 112 bool SharedMemory::CreateNamed(const std::string& name, bool open_existing, |
113 bool open_existing, uint32 size) { | 113 uint32 size, bool executable) { |
114 DCHECK_EQ(-1, mapped_file_); | 114 DCHECK_EQ(-1, mapped_file_); |
115 if (size == 0) return false; | 115 if (size == 0) return false; |
116 | 116 |
117 // This function theoretically can block on the disk, but realistically | 117 // This function theoretically can block on the disk, but realistically |
118 // the temporary files we create will just go into the buffer cache | 118 // the temporary files we create will just go into the buffer cache |
119 // and be deleted before they ever make it out to disk. | 119 // and be deleted before they ever make it out to disk. |
120 base::ThreadRestrictions::ScopedAllowIO allow_io; | 120 base::ThreadRestrictions::ScopedAllowIO allow_io; |
121 | 121 |
122 FILE *fp; | 122 FILE *fp; |
123 bool fix_size = true; | 123 bool fix_size = true; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 new_handle->fd = new_fd; | 365 new_handle->fd = new_fd; |
366 new_handle->auto_close = true; | 366 new_handle->auto_close = true; |
367 | 367 |
368 if (close_self) | 368 if (close_self) |
369 Close(); | 369 Close(); |
370 | 370 |
371 return true; | 371 return true; |
372 } | 372 } |
373 | 373 |
374 } // namespace base | 374 } // namespace base |
OLD | NEW |