Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: mojo/system/raw_shared_buffer_posix.cc

Issue 304233005: Mojo: Implement passing of shared buffers across processes on POSIX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/raw_shared_buffer.cc ('k') | mojo/system/raw_shared_buffer_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5c98737efdc786ad31abe42f149f2febafb2f75c 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>
@@ -32,7 +33,7 @@ namespace system {
// RawSharedBuffer -------------------------------------------------------------
-bool RawSharedBuffer::InitNoLock() {
+bool RawSharedBuffer::Init() {
DCHECK(!handle_.is_valid());
base::ThreadRestrictions::ScopedAllowIO allow_io;
@@ -82,11 +83,40 @@ bool RawSharedBuffer::InitNoLock() {
return true;
}
-scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::MapImplNoLock(
- size_t offset,
- size_t length) {
- lock_.AssertAcquired();
+bool RawSharedBuffer::InitFromPlatformHandle(
+ 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";
+ 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::MapImpl(size_t offset,
+ size_t length) {
size_t offset_rounding = offset % base::SysInfo::VMAllocationGranularity();
size_t real_offset = offset - offset_rounding;
size_t real_length = length + offset_rounding;
« no previous file with comments | « mojo/system/raw_shared_buffer.cc ('k') | mojo/system/raw_shared_buffer_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698