Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "chrome/common/transport_dib.h" |
michael@0 | 6 | |
michael@0 | 7 | #include <unistd.h> |
michael@0 | 8 | #include <sys/stat.h> |
michael@0 | 9 | |
michael@0 | 10 | #include "base/eintr_wrapper.h" |
michael@0 | 11 | #include "base/shared_memory.h" |
michael@0 | 12 | |
michael@0 | 13 | TransportDIB::TransportDIB() |
michael@0 | 14 | : size_(0) { |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | TransportDIB::TransportDIB(TransportDIB::Handle dib) |
michael@0 | 18 | : shared_memory_(dib, false /* read write */), |
michael@0 | 19 | size_(0) { |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | TransportDIB::~TransportDIB() { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | // static |
michael@0 | 26 | TransportDIB* TransportDIB::Create(size_t size, uint32_t sequence_num) { |
michael@0 | 27 | TransportDIB* dib = new TransportDIB; |
michael@0 | 28 | if (!dib->shared_memory_.Create("", false /* read write */, |
michael@0 | 29 | false /* do not open existing */, size)) { |
michael@0 | 30 | delete dib; |
michael@0 | 31 | return NULL; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | dib->size_ = size; |
michael@0 | 35 | return dib; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | // static |
michael@0 | 39 | TransportDIB* TransportDIB::Map(TransportDIB::Handle handle) { |
michael@0 | 40 | TransportDIB* dib = new TransportDIB(handle); |
michael@0 | 41 | struct stat st; |
michael@0 | 42 | fstat(handle.fd, &st); |
michael@0 | 43 | |
michael@0 | 44 | if (!dib->shared_memory_.Map(st.st_size)) { |
michael@0 | 45 | delete dib; |
michael@0 | 46 | HANDLE_EINTR(close(handle.fd)); |
michael@0 | 47 | return nullptr; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | dib->size_ = st.st_size; |
michael@0 | 51 | |
michael@0 | 52 | return dib; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void* TransportDIB::memory() const { |
michael@0 | 56 | return shared_memory_.memory(); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | TransportDIB::Id TransportDIB::id() const { |
michael@0 | 60 | return shared_memory_.id(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | TransportDIB::Handle TransportDIB::handle() const { |
michael@0 | 64 | return shared_memory_.handle(); |
michael@0 | 65 | } |