blob: 00600120f24097de4999ba135b208f379849453b [file] [log] [blame]
Loganeb3d12b2010-12-16 06:20:18 +08001/*
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
Logan1dc63142011-02-25 17:14:51 +080020#include <Config.h>
21
22#include <llvm/System/Mutex.h>
23
Loganeb3d12b2010-12-16 06:20:18 +080024#include <stddef.h>
25
Loganeb3d12b2010-12-16 06:20:18 +080026
27namespace bcc {
28
Logan1dc63142011-02-25 17:14:51 +080029 class ContextManager {
30 public:
31 // Starting address of context slot address space
32 static char * const ContextFixedAddr;
Logan42598052011-01-26 22:41:13 +080033
Logan1dc63142011-02-25 17:14:51 +080034 // Number of the context slots
35 static size_t const ContextSlotCount = BCC_CONTEXT_SLOT_COUNT_;
Loganeb3d12b2010-12-16 06:20:18 +080036
Logan1dc63142011-02-25 17:14:51 +080037 // 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;
Loganeb3d12b2010-12-16 06:20:18 +080041
Logan1dc63142011-02-25 17:14:51 +080042 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 };
Loganeb3d12b2010-12-16 06:20:18 +080070
71} // namespace bcc
72
Loganeb3d12b2010-12-16 06:20:18 +080073#endif // BCC_CONTEXTMANAGER_H