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

Side by Side Diff: base/memory/shared_memory_nacl.cc

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/memory/shared_memory_mac.cc ('k') | base/memory/shared_memory_posix.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 #include "base/memory/shared_memory.h" 5 #include "base/memory/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>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include <limits> 13 #include <limits>
14 14
15 #include "base/logging.h" 15 #include "base/logging.h"
16 16
17 namespace base { 17 namespace base {
18 18
19 SharedMemory::SharedMemory() 19 SharedMemory::SharedMemory()
20 : mapped_file_(-1), 20 : mapped_file_(-1),
21 mapped_size_(0), 21 mapped_size_(0),
22 memory_(NULL), 22 memory_(NULL),
23 read_only_(false), 23 read_only_(false),
24 requested_size_(0) { 24 requested_size_(0) {
25 } 25 }
26 26
27 SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only) 27 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only)
28 : mapped_file_(handle.fd), 28 : mapped_file_(handle.fd),
29 mapped_size_(0), 29 mapped_size_(0),
30 memory_(NULL), 30 memory_(NULL),
31 read_only_(read_only), 31 read_only_(read_only),
32 requested_size_(0) { 32 requested_size_(0) {}
33 }
34 33
35 SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only, 34 SharedMemory::SharedMemory(const SharedMemoryHandle& handle,
35 bool read_only,
36 ProcessHandle process) 36 ProcessHandle process)
37 : mapped_file_(handle.fd), 37 : mapped_file_(handle.fd),
38 mapped_size_(0), 38 mapped_size_(0),
39 memory_(NULL), 39 memory_(NULL),
40 read_only_(read_only), 40 read_only_(read_only),
41 requested_size_(0) { 41 requested_size_(0) {
42 NOTREACHED(); 42 NOTREACHED();
43 } 43 }
44 44
45 SharedMemory::~SharedMemory() { 45 SharedMemory::~SharedMemory() {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 void SharedMemory::Close() { 134 void SharedMemory::Close() {
135 if (mapped_file_ > 0) { 135 if (mapped_file_ > 0) {
136 if (close(mapped_file_) < 0) 136 if (close(mapped_file_) < 0)
137 DPLOG(ERROR) << "close"; 137 DPLOG(ERROR) << "close";
138 mapped_file_ = -1; 138 mapped_file_ = -1;
139 } 139 }
140 } 140 }
141 141
142 void SharedMemory::LockDeprecated() {
143 NOTIMPLEMENTED();
144 }
145
146 void SharedMemory::UnlockDeprecated() {
147 NOTIMPLEMENTED();
148 }
149
150 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, 142 bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
151 SharedMemoryHandle *new_handle, 143 SharedMemoryHandle *new_handle,
152 bool close_self, 144 bool close_self,
153 ShareMode share_mode) { 145 ShareMode share_mode) {
154 if (share_mode == SHARE_READONLY) { 146 if (share_mode == SHARE_READONLY) {
155 // Untrusted code can't create descriptors or handles, which is needed to 147 // Untrusted code can't create descriptors or handles, which is needed to
156 // drop permissions. 148 // drop permissions.
157 return false; 149 return false;
158 } 150 }
159 const int new_fd = dup(mapped_file_); 151 const int new_fd = dup(mapped_file_);
160 if (new_fd < 0) { 152 if (new_fd < 0) {
161 DPLOG(ERROR) << "dup() failed."; 153 DPLOG(ERROR) << "dup() failed.";
162 return false; 154 return false;
163 } 155 }
164 156
165 new_handle->fd = new_fd; 157 new_handle->fd = new_fd;
166 new_handle->auto_close = true; 158 new_handle->auto_close = true;
167 159
168 if (close_self) { 160 if (close_self) {
169 Unmap(); 161 Unmap();
170 Close(); 162 Close();
171 } 163 }
172 return true; 164 return true;
173 } 165 }
174 166
175 } // namespace base 167 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_mac.cc ('k') | base/memory/shared_memory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698