The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_MEMORY_HEAP_PMEM_H |
| 18 | #define ANDROID_MEMORY_HEAP_PMEM_H |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <stdint.h> |
| 22 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/MemoryHeapBase.h> |
| 24 | #include <binder/IMemory.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/SortedVector.h> |
Mathias Agopian | 6faf789 | 2010-01-25 19:00:00 -0800 | [diff] [blame] | 26 | #include <utils/threads.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class MemoryHeapBase; |
| 31 | |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
Mathias Agopian | 6faf789 | 2010-01-25 19:00:00 -0800 | [diff] [blame] | 34 | class MemoryHeapPmem : public MemoryHeapBase |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | class MemoryPmem : public BnMemory { |
| 38 | public: |
| 39 | MemoryPmem(const sp<MemoryHeapPmem>& heap); |
| 40 | ~MemoryPmem(); |
| 41 | protected: |
| 42 | const sp<MemoryHeapPmem>& getHeap() const { return mClientHeap; } |
| 43 | private: |
| 44 | friend class MemoryHeapPmem; |
| 45 | virtual void revoke() = 0; |
| 46 | sp<MemoryHeapPmem> mClientHeap; |
| 47 | }; |
| 48 | |
Mathias Agopian | 92c3b39 | 2010-04-19 19:09:03 -0700 | [diff] [blame] | 49 | MemoryHeapPmem(const sp<MemoryHeapBase>& pmemHeap, uint32_t flags = 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | ~MemoryHeapPmem(); |
| 51 | |
| 52 | /* HeapInterface additions */ |
| 53 | virtual sp<IMemory> mapMemory(size_t offset, size_t size); |
| 54 | |
| 55 | /* make the whole heap visible (you know who you are) */ |
| 56 | virtual status_t slap(); |
| 57 | |
| 58 | /* hide (revoke) the whole heap (the client will see the garbage page) */ |
| 59 | virtual status_t unslap(); |
| 60 | |
| 61 | /* revoke all allocations made by this heap */ |
| 62 | virtual void revoke(); |
| 63 | |
| 64 | private: |
| 65 | /* use this to create your own IMemory for mapMemory */ |
| 66 | virtual sp<MemoryPmem> createMemory(size_t offset, size_t size); |
| 67 | void remove(const wp<MemoryPmem>& memory); |
| 68 | |
| 69 | private: |
| 70 | sp<MemoryHeapBase> mParentHeap; |
| 71 | mutable Mutex mLock; |
| 72 | SortedVector< wp<MemoryPmem> > mAllocations; |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | // --------------------------------------------------------------------------- |
| 77 | }; // namespace android |
| 78 | |
| 79 | #endif // ANDROID_MEMORY_HEAP_PMEM_H |