ipc/chromium/src/chrome/common/transport_dib_win.cc

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include <limits>
michael@0 6 #include <windows.h>
michael@0 7
michael@0 8 #include "base/logging.h"
michael@0 9 #include "base/sys_info.h"
michael@0 10 #include "chrome/common/transport_dib.h"
michael@0 11
michael@0 12 TransportDIB::TransportDIB() {
michael@0 13 }
michael@0 14
michael@0 15 TransportDIB::~TransportDIB() {
michael@0 16 }
michael@0 17
michael@0 18 TransportDIB::TransportDIB(HANDLE handle)
michael@0 19 : shared_memory_(handle, false /* read write */) {
michael@0 20 }
michael@0 21
michael@0 22 // static
michael@0 23 TransportDIB* TransportDIB::Create(size_t size, uint32_t sequence_num) {
michael@0 24 size_t allocation_granularity = base::SysInfo::VMAllocationGranularity();
michael@0 25 size = size / allocation_granularity + 1;
michael@0 26 size = size * allocation_granularity;
michael@0 27
michael@0 28 TransportDIB* dib = new TransportDIB;
michael@0 29
michael@0 30 if (!dib->shared_memory_.Create("", false /* read write */,
michael@0 31 true /* open existing */, size)) {
michael@0 32 delete dib;
michael@0 33 return NULL;
michael@0 34 }
michael@0 35
michael@0 36 dib->size_ = size;
michael@0 37 dib->sequence_num_ = sequence_num;
michael@0 38
michael@0 39 return dib;
michael@0 40 }
michael@0 41
michael@0 42 // static
michael@0 43 TransportDIB* TransportDIB::Map(TransportDIB::Handle handle) {
michael@0 44 TransportDIB* dib = new TransportDIB(handle);
michael@0 45 if (!dib->shared_memory_.Map(0 /* map whole shared memory segment */)) {
michael@0 46 CHROMIUM_LOG(ERROR) << "Failed to map transport DIB"
michael@0 47 << " handle:" << handle
michael@0 48 << " error:" << GetLastError();
michael@0 49 delete dib;
michael@0 50 return NULL;
michael@0 51 }
michael@0 52
michael@0 53 // There doesn't seem to be any way to find the size of the shared memory
michael@0 54 // region! GetFileSize indicates that the handle is invalid. Thus, we
michael@0 55 // conservatively set the size to the maximum and hope that the renderer
michael@0 56 // isn't about to ask us to read off the end of the array.
michael@0 57 dib->size_ = std::numeric_limits<size_t>::max();
michael@0 58
michael@0 59 return dib;
michael@0 60 }
michael@0 61
michael@0 62 void* TransportDIB::memory() const {
michael@0 63 return shared_memory_.memory();
michael@0 64 }
michael@0 65
michael@0 66 TransportDIB::Handle TransportDIB::handle() const {
michael@0 67 return shared_memory_.handle();
michael@0 68 }
michael@0 69
michael@0 70 TransportDIB::Id TransportDIB::id() const {
michael@0 71 return Id(shared_memory_.handle(), sequence_num_);
michael@0 72 }

mercurial