Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 1 | /* |
| 2 | * copyright 2010, 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 BCC_CONTEXTMANAGER_H |
| 18 | #define BCC_CONTEXTMANAGER_H |
| 19 | |
Logan | 1dc6314 | 2011-02-25 17:14:51 +0800 | [diff] [blame^] | 20 | #include <Config.h> |
| 21 | |
| 22 | #include <llvm/System/Mutex.h> |
| 23 | |
Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 24 | #include <stddef.h> |
| 25 | |
Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 26 | |
| 27 | namespace bcc { |
| 28 | |
Logan | 1dc6314 | 2011-02-25 17:14:51 +0800 | [diff] [blame^] | 29 | class ContextManager { |
| 30 | public: |
| 31 | // Starting address of context slot address space |
| 32 | static char * const ContextFixedAddr; |
Logan | 4259805 | 2011-01-26 22:41:13 +0800 | [diff] [blame] | 33 | |
Logan | 1dc6314 | 2011-02-25 17:14:51 +0800 | [diff] [blame^] | 34 | // Number of the context slots |
| 35 | static size_t const ContextSlotCount = BCC_CONTEXT_SLOT_COUNT_; |
Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 36 | |
Logan | 1dc6314 | 2011-02-25 17:14:51 +0800 | [diff] [blame^] | 37 | // Context size |
| 38 | static size_t const ContextCodeSize = BCC_CONTEXT_CODE_SIZE_; |
| 39 | static size_t const ContextDataSize = BCC_CONTEXT_DATA_SIZE_; |
| 40 | static size_t const ContextSize = ContextCodeSize + ContextDataSize; |
Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 41 | |
Logan | 1dc6314 | 2011-02-25 17:14:51 +0800 | [diff] [blame^] | 42 | private: |
| 43 | // Context manager singleton |
| 44 | static ContextManager TheContextManager; |
| 45 | |
| 46 | private: |
| 47 | // Mutex lock for context slot occupation table |
| 48 | llvm::sys::Mutex mContextSlotOccupiedLock; |
| 49 | |
| 50 | // Context slot occupation table |
| 51 | bool mContextSlotOccupied[ContextSlotCount]; |
| 52 | |
| 53 | ContextManager(); |
| 54 | |
| 55 | public: |
| 56 | static ContextManager &get() { |
| 57 | return TheContextManager; |
| 58 | } |
| 59 | |
| 60 | char *allocateContext(); |
| 61 | char *allocateContext(char *addr, int imageFd, off_t imageOffset); |
| 62 | void deallocateContext(char *addr); |
| 63 | |
| 64 | bool isManagingContext(char *addr); |
| 65 | |
| 66 | private: |
| 67 | static ssize_t getSlotIndexFromAddress(char *addr); |
| 68 | |
| 69 | }; |
Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 70 | |
| 71 | } // namespace bcc |
| 72 | |
Logan | eb3d12b | 2010-12-16 06:20:18 +0800 | [diff] [blame] | 73 | #endif // BCC_CONTEXTMANAGER_H |