diff options
author | Zeno Albisser <zeno.albisser@theqtcompany.com> | 2014-12-05 15:04:29 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@theqtcompany.com> | 2014-12-09 10:49:28 +0100 |
commit | af6588f8d723931a298c995fa97259bb7f7deb55 (patch) | |
tree | 060ca707847ba1735f01af2372e0d5e494dc0366 /chromium/base/files/file.h | |
parent | 2fff84d821cc7b1c785f6404e0f8091333283e74 (diff) |
BASELINE: Update chromium to 40.0.2214.28 and ninja to 1.5.3.
Change-Id: I759465284fd64d59ad120219cbe257f7402c4181
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/base/files/file.h')
-rw-r--r-- | chromium/base/files/file.h | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/chromium/base/files/file.h b/chromium/base/files/file.h index 1913bc7f6c4..7b6366c1c2e 100644 --- a/chromium/base/files/file.h +++ b/chromium/base/files/file.h @@ -19,6 +19,7 @@ #include "base/base_export.h" #include "base/basictypes.h" #include "base/files/scoped_file.h" +#include "base/gtest_prod_util.h" #include "base/move.h" #include "base/time/time.h" @@ -26,6 +27,8 @@ #include "base/win/scoped_handle.h" #endif +FORWARD_DECLARE_TEST(FileTest, MemoryCorruption); + namespace base { class FilePath; @@ -249,7 +252,8 @@ class BASE_EXPORT File { // doesn't exist, |false| is returned. bool SetLength(int64 length); - // Flushes the buffers. + // Instructs the filesystem to flush the file to disk. (POSIX: fsync, Windows: + // FlushFileBuffers). bool Flush(); // Updates the file times. @@ -295,12 +299,59 @@ class BASE_EXPORT File { static std::string ErrorToString(Error error); private: + FRIEND_TEST_ALL_PREFIXES(::FileTest, MemoryCorruption); + +#if defined(OS_POSIX) + // Encloses a single ScopedFD, saving a cheap tamper resistent memory checksum + // alongside it. This checksum is validated at every access, allowing early + // detection of memory corruption. + + // TODO(gavinp): This is in place temporarily to help us debug + // https://crbug.com/424562 , which can't be reproduced in valgrind. Remove + // this code after we have fixed this issue. + class MemoryCheckingScopedFD { + public: + MemoryCheckingScopedFD(); + MemoryCheckingScopedFD(int fd); + ~MemoryCheckingScopedFD(); + + bool is_valid() const { Check(); return file_.is_valid(); } + int get() const { Check(); return file_.get(); } + + void reset() { Check(); file_.reset(); UpdateChecksum(); } + void reset(int fd) { Check(); file_.reset(fd); UpdateChecksum(); } + int release() { + Check(); + int fd = file_.release(); + UpdateChecksum(); + return fd; + } + + private: + FRIEND_TEST_ALL_PREFIXES(::FileTest, MemoryCorruption); + + // Computes the checksum for the current value of |file_|. Returns via an + // out parameter to guard against implicit conversions of unsigned integral + // types. + void ComputeMemoryChecksum(unsigned int* out_checksum) const; + + // Confirms that the current |file_| and |file_memory_checksum_| agree, + // failing a CHECK if they do not. + void Check() const; + + void UpdateChecksum(); + + ScopedFD file_; + unsigned int file_memory_checksum_; + }; +#endif + void SetPlatformFile(PlatformFile file); #if defined(OS_WIN) win::ScopedHandle file_; #elif defined(OS_POSIX) - ScopedFD file_; + MemoryCheckingScopedFD file_; #endif Error error_details_; |