summaryrefslogtreecommitdiffstats
path: root/base/memory/shared_memory_posix.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 19:02:35 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 19:02:35 +0000
commit42f558fdef03f1ec2261f554151d8a4d168919e4 (patch)
treea2f2403061c945c8983524036bc73550098de6b7 /base/memory/shared_memory_posix.cc
parentcb8d22b096bf5698bcf58725d6e4d7534e235a0a (diff)
downloadchromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.zip
chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.tar.gz
chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.tar.bz2
Implement ScopedFD in terms of ScopedGeneric.
Move to a new file base/files/scoped_file.h. I will also add ScopedFILE to here (currently in file_util.h) later. I think there is a crash in the old code in content/browser/zygote_host/zygote_host_impl_linux.cc that this patch should fix. The old ScopedFD took the address of something in a vector that is being modified. I removed SafeScopedFD from content/common/sandbox_linux/sandbox_linux.cc since base's ScopedFD not CHECKs on close failure (this is a more recent addition). Reland of https://codereview.chromium.org/191673003/ R=agl, viettrungluu Review URL: https://codereview.chromium.org/202113004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory/shared_memory_posix.cc')
-rw-r--r--base/memory/shared_memory_posix.cc24
1 files changed, 10 insertions, 14 deletions
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc
index 8780c04..1a90847 100644
--- a/base/memory/shared_memory_posix.cc
+++ b/base/memory/shared_memory_posix.cc
@@ -30,7 +30,6 @@
#include "third_party/ashmem/ashmem.h"
#endif
-using file_util::ScopedFD;
using file_util::ScopedFILE;
namespace base {
@@ -132,8 +131,7 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
ScopedFILE fp;
bool fix_size = true;
- int readonly_fd_storage = -1;
- ScopedFD readonly_fd(&readonly_fd_storage);
+ ScopedFD readonly_fd;
FilePath path;
if (options.name_deprecated == NULL || options.name_deprecated->empty()) {
@@ -145,8 +143,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
if (fp) {
// Also open as readonly so that we can ShareReadOnlyToProcess.
- *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
- if (*readonly_fd < 0) {
+ readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
+ if (!readonly_fd.is_valid()) {
DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed";
fp.reset();
}
@@ -198,8 +196,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
}
// Also open as readonly so that we can ShareReadOnlyToProcess.
- *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
- if (*readonly_fd < 0) {
+ readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
+ if (!readonly_fd.is_valid()) {
DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed";
close(fd);
fd = -1;
@@ -265,10 +263,8 @@ bool SharedMemory::Open(const std::string& name, bool read_only) {
const char *mode = read_only ? "r" : "r+";
ScopedFILE fp(base::OpenFile(path, mode));
- int readonly_fd_storage = -1;
- ScopedFD readonly_fd(&readonly_fd_storage);
- *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY));
- if (*readonly_fd < 0) {
+ ScopedFD readonly_fd(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
+ if (!readonly_fd.is_valid()) {
DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed";
}
return PrepareMapFile(fp.Pass(), readonly_fd.Pass());
@@ -353,7 +349,7 @@ void SharedMemory::UnlockDeprecated() {
bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) {
DCHECK_EQ(-1, mapped_file_);
DCHECK_EQ(-1, readonly_mapped_file_);
- if (fp == NULL || *readonly_fd < 0) return false;
+ if (fp == NULL || !readonly_fd.is_valid()) return false;
// This function theoretically can block on the disk, but realistically
// the temporary files we create will just go into the buffer cache
@@ -364,7 +360,7 @@ bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) {
struct stat readonly_st = {};
if (fstat(fileno(fp.get()), &st))
NOTREACHED();
- if (fstat(*readonly_fd, &readonly_st))
+ if (fstat(readonly_fd.get(), &readonly_st))
NOTREACHED();
if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) {
LOG(ERROR) << "writable and read-only inodes don't match; bailing";
@@ -381,7 +377,7 @@ bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) {
}
}
inode_ = st.st_ino;
- readonly_mapped_file_ = *readonly_fd.release();
+ readonly_mapped_file_ = readonly_fd.release();
return true;
}