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

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

Issue 1997153002: libchrome: Several upstreamable fixes from libchrome Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Addressed feedback Created 4 years, 7 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
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 <stddef.h> 9 #include <stddef.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 struct stat stat; 279 struct stat stat;
280 if (fstat(fileno(fp.get()), &stat) != 0) 280 if (fstat(fileno(fp.get()), &stat) != 0)
281 return false; 281 return false;
282 const size_t current_size = stat.st_size; 282 const size_t current_size = stat.st_size;
283 if (current_size != options.size) { 283 if (current_size != options.size) {
284 if (HANDLE_EINTR(ftruncate(fileno(fp.get()), options.size)) != 0) 284 if (HANDLE_EINTR(ftruncate(fileno(fp.get()), options.size)) != 0)
285 return false; 285 return false;
286 } 286 }
287 requested_size_ = options.size; 287 requested_size_ = options.size;
288 } 288 }
289 if (fp == NULL) { 289 if (fp == nullptr) {
290 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; 290 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed";
291 FilePath dir = path.DirName(); 291 FilePath dir = path.DirName();
292 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { 292 if (access(dir.value().c_str(), W_OK | X_OK) < 0) {
293 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); 293 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value();
294 if (dir.value() == "/dev/shm") { 294 if (dir.value() == "/dev/shm") {
295 LOG(FATAL) << "This is frequently caused by incorrect permissions on " 295 LOG(FATAL) << "This is frequently caused by incorrect permissions on "
296 << "/dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix."; 296 << "/dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix.";
297 } 297 }
298 } 298 }
299 return false; 299 return false;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 if (IGNORE_EINTR(close(readonly_mapped_file_)) < 0) 396 if (IGNORE_EINTR(close(readonly_mapped_file_)) < 0)
397 PLOG(ERROR) << "close"; 397 PLOG(ERROR) << "close";
398 readonly_mapped_file_ = -1; 398 readonly_mapped_file_ = -1;
399 } 399 }
400 } 400 }
401 401
402 #if !defined(OS_ANDROID) 402 #if !defined(OS_ANDROID)
403 bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) { 403 bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) {
404 DCHECK_EQ(-1, mapped_file_); 404 DCHECK_EQ(-1, mapped_file_);
405 DCHECK_EQ(-1, readonly_mapped_file_); 405 DCHECK_EQ(-1, readonly_mapped_file_);
406 if (fp == NULL) 406 if (fp == nullptr)
407 return false; 407 return false;
408 408
409 // This function theoretically can block on the disk, but realistically 409 // This function theoretically can block on the disk, but realistically
410 // the temporary files we create will just go into the buffer cache 410 // the temporary files we create will just go into the buffer cache
411 // and be deleted before they ever make it out to disk. 411 // and be deleted before they ever make it out to disk.
412 base::ThreadRestrictions::ScopedAllowIO allow_io; 412 base::ThreadRestrictions::ScopedAllowIO allow_io;
413 413
414 struct stat st = {}; 414 struct stat st = {};
415 if (fstat(fileno(fp.get()), &st)) 415 if (fstat(fileno(fp.get()), &st))
416 NOTREACHED(); 416 NOTREACHED();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 #if defined(GOOGLE_CHROME_BUILD) 455 #if defined(GOOGLE_CHROME_BUILD)
456 std::string name_base = std::string("com.google.Chrome"); 456 std::string name_base = std::string("com.google.Chrome");
457 #else 457 #else
458 std::string name_base = std::string("org.chromium.Chromium"); 458 std::string name_base = std::string("org.chromium.Chromium");
459 #endif 459 #endif
460 *path = temp_dir.AppendASCII(name_base + ".shmem." + mem_name); 460 *path = temp_dir.AppendASCII(name_base + ".shmem." + mem_name);
461 return true; 461 return true;
462 } 462 }
463 #endif // !defined(OS_ANDROID) 463 #endif // !defined(OS_ANDROID)
464 464
465 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, 465 bool SharedMemory::ShareToProcessCommon(ProcessHandle,
466 SharedMemoryHandle* new_handle, 466 SharedMemoryHandle* new_handle,
467 bool close_self, 467 bool close_self,
468 ShareMode share_mode) { 468 ShareMode share_mode) {
469 int handle_to_dup = -1; 469 int handle_to_dup = -1;
470 switch(share_mode) { 470 switch(share_mode) {
471 case SHARE_CURRENT_MODE: 471 case SHARE_CURRENT_MODE:
472 handle_to_dup = mapped_file_; 472 handle_to_dup = mapped_file_;
473 break; 473 break;
474 case SHARE_READONLY: 474 case SHARE_READONLY:
475 // We could imagine re-opening the file from /dev/fd, but that can't make 475 // We could imagine re-opening the file from /dev/fd, but that can't make
(...skipping 18 matching lines...) Expand all
494 494
495 if (close_self) { 495 if (close_self) {
496 Unmap(); 496 Unmap();
497 Close(); 497 Close();
498 } 498 }
499 499
500 return true; 500 return true;
501 } 501 }
502 502
503 } // namespace base 503 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698