Chromium Code Reviews| Index: base/files/file_posix.cc |
| diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc |
| index 43684b5dabfe3df9b2a6907cd5dfbecb8e3582c3..95cfbfb8c07ddbedb7dc90941c5f6775b0af172d 100644 |
| --- a/base/files/file_posix.cc |
| +++ b/base/files/file_posix.cc |
| @@ -166,6 +166,27 @@ void File::Info::FromStat(const stat_wrapper_t& stat_info) { |
| Time::kNanosecondsPerMicrosecond); |
| } |
| +// Define empty hooks for blacklisting file descriptors used in base::File. |
| +// These functions should be declared 'weak', i.e. the functions declared in |
| +// a default way would have precedence over the weak ones at link time. This |
| +// works for both static and dynamic linking. |
| +// |
| +// With compilers other than GCC define strong no-op symbols for simplicity. |
|
Fabrice (no longer in Chrome)
2014/11/04 15:37:21
Nit: other than GCC and Clang (so msvc, essentiall
pasko
2014/11/04 17:48:05
Thanks, I did not realize COMPILER_GCC is defined
|
| +#if defined(COMPILER_GCC) |
| +#define ATTRIBUTE_WEAK __attribute__ ((weak)) |
| +#else |
| +#define ATTRIBUTE_WEAK |
| +#endif |
| +BASE_EXPORT void ProtectFileDescriptor(int fd) ATTRIBUTE_WEAK; |
| +BASE_EXPORT void UnprotectFileDescriptor(int fd) ATTRIBUTE_WEAK; |
| +#undef ATTRIBUTE_WEAK |
| + |
| +void ProtectFileDescriptor(int fd) { |
| +} |
| + |
| +void UnprotectFileDescriptor(int fd) { |
| +} |
| + |
| // NaCl doesn't implement system calls to open files directly. |
| #if !defined(OS_NACL) |
| // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? |
| @@ -252,6 +273,7 @@ void File::InitializeUnsafe(const FilePath& name, uint32 flags) { |
| async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
| error_details_ = FILE_OK; |
| file_.reset(descriptor); |
| + ProtectFileDescriptor(descriptor); |
| } |
| #endif // !defined(OS_NACL) |
| @@ -264,6 +286,7 @@ PlatformFile File::GetPlatformFile() const { |
| } |
| PlatformFile File::TakePlatformFile() { |
| + UnprotectFileDescriptor(GetPlatformFile()); |
| return file_.release(); |
| } |
| @@ -272,6 +295,7 @@ void File::Close() { |
| return; |
| base::ThreadRestrictions::AssertIOAllowed(); |
| + UnprotectFileDescriptor(GetPlatformFile()); |
| file_.reset(); |
| } |
| @@ -484,8 +508,10 @@ File::Error File::OSErrorToFileError(int saved_errno) { |
| } |
| void File::SetPlatformFile(PlatformFile file) { |
| - DCHECK(!file_.is_valid()); |
| + CHECK(!file_.is_valid()); |
| file_.reset(file); |
| + if (file_.is_valid()) |
| + ProtectFileDescriptor(GetPlatformFile()); |
| } |
| } // namespace base |