1cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland/* 2cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * Copyright (C) 2017 The Android Open Source Project 3cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * 4cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * Licensed under the Apache License, Version 2.0 (the "License"); 5cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * you may not use this file except in compliance with the License. 6cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * You may obtain a copy of the License at 7cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * 8cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * http://www.apache.org/licenses/LICENSE-2.0 9cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * 10cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * Unless required by applicable law or agreed to in writing, software 11cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * distributed under the License is distributed on an "AS IS" BASIS, 12cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * See the License for the specific language governing permissions and 14cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland * limitations under the License. 15cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland */ 16cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 17e843e54393319f99e0155d2cf8c6af0be1f6ce60Dan Albert#include <unistd.h> 18e843e54393319f99e0155d2cf8c6af0be1f6ce60Dan Albert 19cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland#include <hidlmemory/FrameworkUtils.h> 20cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 21cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Morelandnamespace android { 22cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 23cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Morelandnamespace hardware { 24cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 25cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Morelandsp<HidlMemory> fromHeap(const sp<IMemoryHeap>& heap) { 26cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland int fd = dup(heap->getHeapID()); 27cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 28cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland if (fd < 0) { 29cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland return HidlMemory::getInstance(hidl_memory()); 30cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland } 31cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 32cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland // Only being used because this library is paired with the IAllocator 33cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland // ashmem. Other places should not make assumptions about the contents 34cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland // of this memory. 35cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland return HidlMemory::getInstance("ashmem", fd, heap->getSize()); 36cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland} 37cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland 38cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland} // namespace hardware 39cb9e4900dc5a42241a2b5027d6eb2cf098181789Steven Moreland} // namespace android 40