| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } else if (current_size > size) { | 218 } else if (current_size > size) { |
| 219 // possibly shrink. | 219 // possibly shrink. |
| 220 if ((ftruncate(fileno(fp), size) != 0) || | 220 if ((ftruncate(fileno(fp), size) != 0) || |
| 221 (fflush(fp) != 0)) { | 221 (fflush(fp) != 0)) { |
| 222 return false; | 222 return false; |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 mapped_file_ = dup(fileno(fp)); | 227 mapped_file_ = dup(fileno(fp)); |
| 228 DCHECK(mapped_file_ >= 0); | 228 if (mapped_file_ == -1) { |
| 229 if (errno == EMFILE) { |
| 230 LOG(WARNING) << "Shared memory creation failed; out of file descriptors"; |
| 231 return false; |
| 232 } else { |
| 233 NOTREACHED() << "Call to dup failed, errno=" << errno; |
| 234 } |
| 235 } |
| 229 | 236 |
| 230 struct stat st; | 237 struct stat st; |
| 231 if (fstat(mapped_file_, &st)) | 238 if (fstat(mapped_file_, &st)) |
| 232 NOTREACHED(); | 239 NOTREACHED(); |
| 233 inode_ = st.st_ino; | 240 inode_ = st.st_ino; |
| 234 | 241 |
| 235 return true; | 242 return true; |
| 236 } | 243 } |
| 237 | 244 |
| 238 bool SharedMemory::Map(size_t bytes) { | 245 bool SharedMemory::Map(size_t bytes) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 316 |
| 310 void SharedMemory::Unlock() { | 317 void SharedMemory::Unlock() { |
| 311 LockOrUnlockCommon(F_ULOCK); | 318 LockOrUnlockCommon(F_ULOCK); |
| 312 } | 319 } |
| 313 | 320 |
| 314 SharedMemoryHandle SharedMemory::handle() const { | 321 SharedMemoryHandle SharedMemory::handle() const { |
| 315 return FileDescriptor(mapped_file_, false); | 322 return FileDescriptor(mapped_file_, false); |
| 316 } | 323 } |
| 317 | 324 |
| 318 } // namespace base | 325 } // namespace base |
| OLD | NEW |