diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 05:37:08 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 05:37:08 +0000 |
commit | face3686c641e6d055c424a55a29d0f562a4110a (patch) | |
tree | 29f9eae2bc0c9c65a16924e3d5a330f6257579be /base/memory | |
parent | 523e42f663d1b5f8766103c567287f3b33fb7508 (diff) | |
download | chromium_src-face3686c641e6d055c424a55a29d0f562a4110a.zip chromium_src-face3686c641e6d055c424a55a29d0f562a4110a.tar.gz chromium_src-face3686c641e6d055c424a55a29d0f562a4110a.tar.bz2 |
Revert of Implement ScopedFD in terms of ScopedGeneric. (https://codereview.chromium.org/191673003/)
Reason for revert:
Doesn't build on android:
FAILED: /mnt/data/b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/base/memory/base.discardable_memory_allocator_android.o.d -DV8_DEPRECATION_WARNINGS -DBLINK_SCALE_FILTERS_AT_RECORD_TIME -D_FILE_OFFSET_BITS=64 -DNO_TCMALLOC -DDISABLE_NACL -DCHROMIUM_BUILD -DCOMPONENT_BUILD -DUSE_LIBJPEG_TURBO=1 -DENABLE_WEBRTC=1 -DUSE_PROPRIETARY_CODECS -DENABLE_CONFIGURATION_POLICY -DENABLE_NEW_GAMEPAD_API=1 -DDISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY -DSYSTEM_NATIVELY_SIGNALS_MEMORY_PRESSURE -DENABLE_EGLIMAGE=1 -DENABLE_AUTOFILL_DIALOG=1 -DCLD_VERSION=1 -DENABLE_PRINTING=1 -DENABLE_MANAGED_USERS=1 -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DBASE_IMPLEMENTATION -DANDROID -D__GNU_SOURCE=1 -DUSE_STLPORT=1 -D_STLP_USE_PTR_SPECIALIZATIONS=1 '-DCHROME_BUILD_ID=""' -DHAVE_SYS_UIO_H -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -Igen/base -I../../third_party/android_tools/ndk/sources/android/cpufeatures -I../.. -fstack-protector --param=ssp-buffer-size=4 -Werror -fno-exceptions -fno-strict-aliasing -Wall -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-reserved-user-defined-literal -Wno-deprecated-register -Xclang -load -Xclang /mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/tools/clang/scripts/../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-url-directory -fcolor-diagnostics -Wexit-time-destructors -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -no-integrated-as -B/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin -ffunction-sections -funwind-tables -g -fstack-protector -fno-short-enums -Wa,--noexecstack -D__compiler_offsetof=__builtin_offsetof -Dnan=__builtin_nan -target arm-linux-androideabi -mllvm -arm-enable-ehabi --sysroot=/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//platforms/android-14/arch-arm -I/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//sources/cxx-stl/stlport/stlport -Os -g -fomit-frame-pointer -fdata-sections -ffunction-sections -funwind-tables -g0 -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -Wsign-compare -std=gnu++11 -Wno-implicit-exception-spec-mismatch -Wno-abi -c ../../base/memory/discardable_memory_allocator_android.cc -o obj/base/memory/base.discardable_memory_allocator_android.o
../../base/memory/discardable_memory_allocator_android.cc:84:25:error: no matching function for call to 'mmap'
void* const address = mmap(
^~~~
/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//platforms/android-14/arch-arm/usr/include/sys/mman.h:47:15: note: candidate function not viable: no known conversion from 'base::ScopedFD' (aka 'ScopedGeneric<int, internal::ScopedFDCloseTraits>') to 'int' for 5th argument
extern void* mmap(void *, size_t, int, int, int, off_t);
^
1 error generated.
Original issue's description:
> 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).
>
> BUG=
> R=agl@chromium.org, viettrungluu@chromium.org
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=257001
TBR=viettrungluu@chromium.org,agl@chromium.org,brettw@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=
Review URL: https://codereview.chromium.org/197873014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory')
-rw-r--r-- | base/memory/discardable_memory_allocator_android.cc | 11 | ||||
-rw-r--r-- | base/memory/shared_memory.h | 3 | ||||
-rw-r--r-- | base/memory/shared_memory_posix.cc | 24 |
3 files changed, 21 insertions, 17 deletions
diff --git a/base/memory/discardable_memory_allocator_android.cc b/base/memory/discardable_memory_allocator_android.cc index b1c936a..97e9abd 100644 --- a/base/memory/discardable_memory_allocator_android.cc +++ b/base/memory/discardable_memory_allocator_android.cc @@ -16,7 +16,6 @@ #include "base/basictypes.h" #include "base/containers/hash_tables.h" #include "base/file_util.h" -#include "base/files/scoped_file.h" #include "base/logging.h" #include "base/memory/discardable_memory.h" #include "base/memory/scoped_vector.h" @@ -66,13 +65,14 @@ bool CreateAshmemRegion(const char* name, size_t size, int* out_fd, void** out_address) { - base::ScopedFD fd(ashmem_create_region(name, size)); - if (!fd.is_valid()) { + int fd = ashmem_create_region(name, size); + if (fd < 0) { DLOG(ERROR) << "ashmem_create_region() failed"; return false; } + file_util::ScopedFD fd_closer(&fd); - const int err = ashmem_set_prot_region(fd.get(), PROT_READ | PROT_WRITE); + const int err = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); if (err < 0) { DLOG(ERROR) << "Error " << err << " when setting protection of ashmem"; return false; @@ -88,7 +88,8 @@ bool CreateAshmemRegion(const char* name, return false; } - *out_fd = fd.release(); + ignore_result(fd_closer.release()); + *out_fd = fd; *out_address = address; return true; } diff --git a/base/memory/shared_memory.h b/base/memory/shared_memory.h index 8e32e72..50b61c4 100644 --- a/base/memory/shared_memory.h +++ b/base/memory/shared_memory.h @@ -22,7 +22,6 @@ #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" #include "base/file_util.h" -#include "base/files/scoped_file.h" #endif namespace base { @@ -260,7 +259,7 @@ class BASE_EXPORT SharedMemory { private: #if defined(OS_POSIX) && !defined(OS_NACL) - bool PrepareMapFile(file_util::ScopedFILE fp, base::ScopedFD readonly); + bool PrepareMapFile(file_util::ScopedFILE fp, file_util::ScopedFD readonly); bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); void LockOrUnlockCommon(int function); #endif diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc index 1a90847..8780c04 100644 --- a/base/memory/shared_memory_posix.cc +++ b/base/memory/shared_memory_posix.cc @@ -30,6 +30,7 @@ #include "third_party/ashmem/ashmem.h" #endif +using file_util::ScopedFD; using file_util::ScopedFILE; namespace base { @@ -131,7 +132,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { ScopedFILE fp; bool fix_size = true; - ScopedFD readonly_fd; + int readonly_fd_storage = -1; + ScopedFD readonly_fd(&readonly_fd_storage); FilePath path; if (options.name_deprecated == NULL || options.name_deprecated->empty()) { @@ -143,8 +145,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { if (fp) { // Also open as readonly so that we can ShareReadOnlyToProcess. - readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY))); - if (!readonly_fd.is_valid()) { + *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)); + if (*readonly_fd < 0) { DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed"; fp.reset(); } @@ -196,8 +198,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { } // Also open as readonly so that we can ShareReadOnlyToProcess. - readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY))); - if (!readonly_fd.is_valid()) { + *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)); + if (*readonly_fd < 0) { DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed"; close(fd); fd = -1; @@ -263,8 +265,10 @@ bool SharedMemory::Open(const std::string& name, bool read_only) { const char *mode = read_only ? "r" : "r+"; ScopedFILE fp(base::OpenFile(path, mode)); - ScopedFD readonly_fd(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY))); - if (!readonly_fd.is_valid()) { + 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) { DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed"; } return PrepareMapFile(fp.Pass(), readonly_fd.Pass()); @@ -349,7 +353,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.is_valid()) return false; + if (fp == NULL || *readonly_fd < 0) return false; // This function theoretically can block on the disk, but realistically // the temporary files we create will just go into the buffer cache @@ -360,7 +364,7 @@ bool SharedMemory::PrepareMapFile(ScopedFILE fp, ScopedFD readonly_fd) { struct stat readonly_st = {}; if (fstat(fileno(fp.get()), &st)) NOTREACHED(); - if (fstat(readonly_fd.get(), &readonly_st)) + if (fstat(*readonly_fd, &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"; @@ -377,7 +381,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; } |