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

Side by Side Diff: mojo/edk/embedder/platform_shared_buffer.cc

Issue 2039713004: [mojo-edk] Make the Mojo EDK compile under NaCl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows build. Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/embedder/platform_shared_buffer.h" 5 #include "mojo/edk/embedder/platform_shared_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #if defined(OS_NACL)
9 // For getpagesize() on NaCl.
10 #include <unistd.h>
11 #endif
8 12
9 #include <utility> 13 #include <utility>
10 14
11 #include "base/logging.h" 15 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
13 #include "base/memory/shared_memory.h" 17 #include "base/memory/shared_memory.h"
14 #include "base/process/process_handle.h" 18 #include "base/process/process_handle.h"
15 #include "base/sys_info.h" 19 #include "base/sys_info.h"
16 #include "mojo/edk/embedder/platform_handle_utils.h" 20 #include "mojo/edk/embedder/platform_handle_utils.h"
17 21
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 285 }
282 286
283 size_t PlatformSharedBufferMapping::GetLength() const { 287 size_t PlatformSharedBufferMapping::GetLength() const {
284 return length_; 288 return length_;
285 } 289 }
286 290
287 bool PlatformSharedBufferMapping::Map() { 291 bool PlatformSharedBufferMapping::Map() {
288 // Mojo shared buffers can be mapped at any offset. However, 292 // Mojo shared buffers can be mapped at any offset. However,
289 // base::SharedMemory must be mapped at a page boundary. So calculate what the 293 // base::SharedMemory must be mapped at a page boundary. So calculate what the
290 // nearest whole page offset is, and build a mapping that's offset from that. 294 // nearest whole page offset is, and build a mapping that's offset from that.
291 size_t offset_rounding = offset_ % base::SysInfo::VMAllocationGranularity(); 295 #if defined(OS_NACL)
296 // base::SysInfo isn't available under NaCl.
297 size_t page_size = getpagesize();
298 #else
299 size_t page_size = base::SysInfo::VMAllocationGranularity();
300 #endif
301 size_t offset_rounding = offset_ % page_size;
292 size_t real_offset = offset_ - offset_rounding; 302 size_t real_offset = offset_ - offset_rounding;
293 size_t real_length = length_ + offset_rounding; 303 size_t real_length = length_ + offset_rounding;
294 304
295 if (!shared_memory_.MapAt(static_cast<off_t>(real_offset), real_length)) 305 if (!shared_memory_.MapAt(static_cast<off_t>(real_offset), real_length))
296 return false; 306 return false;
297 307
298 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding; 308 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding;
299 return true; 309 return true;
300 } 310 }
301 311
302 void PlatformSharedBufferMapping::Unmap() { 312 void PlatformSharedBufferMapping::Unmap() {
303 shared_memory_.Unmap(); 313 shared_memory_.Unmap();
304 } 314 }
305 315
306 } // namespace edk 316 } // namespace edk
307 } // namespace mojo 317 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698