Index: mojo/system/raw_shared_buffer_posix.cc |
diff --git a/mojo/system/raw_shared_buffer_posix.cc b/mojo/system/raw_shared_buffer_posix.cc |
index 3ce50f040b707c4d823d2dca731af36671c5a2b9..343aa6a1b3a9bd8953881e50e75170ab16bc0569 100644 |
--- a/mojo/system/raw_shared_buffer_posix.cc |
+++ b/mojo/system/raw_shared_buffer_posix.cc |
@@ -7,6 +7,7 @@ |
#include <stdint.h> |
#include <stdio.h> // For |fileno()|. |
#include <sys/mman.h> // For |mmap()|/|munmap()|. |
+#include <sys/stat.h> |
#include <sys/types.h> // For |off_t|. |
#include <unistd.h> |
@@ -82,6 +83,38 @@ bool RawSharedBuffer::InitNoLock() { |
return true; |
} |
+bool RawSharedBuffer::InitFromPlatformHandleNoLock( |
+ embedder::ScopedPlatformHandle platform_handle) { |
+ DCHECK(!handle_.is_valid()); |
+ |
+ if (static_cast<uint64_t>(num_bytes_) > |
+ static_cast<uint64_t>(std::numeric_limits<off_t>::max())) { |
+ return false; |
+ } |
+ |
+ struct stat sb = {}; |
+ // Note: |fstat()| isn't interruptible. |
+ if (fstat(platform_handle.get().fd, &sb) != 0) { |
+ PLOG(ERROR) << "fstat"; |
yzshen1
2014/05/30 00:09:35
nit: maybe also output the errno?
viettrungluu
2014/05/30 00:23:42
That's what PLOG does.
yzshen1
2014/05/30 00:27:48
Right. Didn't notice that. Thanks.
|
+ return false; |
+ } |
+ |
+ if (!S_ISREG(sb.st_mode)) { |
+ LOG(ERROR) << "Platform handle not to a regular file"; |
+ return false; |
+ } |
+ |
+ if (sb.st_size != static_cast<off_t>(num_bytes_)) { |
+ LOG(ERROR) << "Shared memory file has the wrong size"; |
+ return false; |
+ } |
+ |
+ // TODO(vtl): More checks? |
+ |
+ handle_ = platform_handle.Pass(); |
+ return true; |
+} |
+ |
scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::MapImplNoLock( |
size_t offset, |
size_t length) { |