My Project
Loading...
Searching...
No Matches
omPage.h
Go to the documentation of this file.
1/*******************************************************************
2 * File: omPage.h
3 * Purpose: declaration of routines for primitve page managment
4 * Author: obachman (Olaf Bachmann)
5 * Created: 11/99
6 *******************************************************************/
7#ifndef OM_PAGE_H
8#define OM_PAGE_H
9
10/***********************************************************************
11 *
12 * Identifying whether an address is a BinAddr or LargeAddr:
13 * For this to work, omRegisterBinAddr or omRegisterLargeAddr must be called
14 * with every address gotten from an external malloc routine
15 */
16
17/* Here is how it works (assume SIZEOF_LONG == 4, SIZEOF_SYSTEM_PAGE = 2^12):
18 Let
19 Addr: | 15 | 5 | 12 |
20 PAGE_INDEX PAGE_SHIFT PAGE_OFFSET
21
22 PAGE_BASE
23
24 omPageIndicies is an array of bit-fields which is indexed by
25 PAGE_INDEX - omMinPageIndex. Its maximal length
26 is 2^15. PAGE_SHIFT is used as index into the bit-field.
27 If it's value is 1, then addr is from omPage, else
28 not.
29
30 omMinPageIndex is minimal page index of registered addr
31
32 In other words: omIsPageAddr iff
33 omPageIndicies[PAGE_INDEX - omMinPageIndex] & (1 << PAGE_SHIFT) */
34
35
36#define OM_SIZEOF_INDEX_PAGE (SIZEOF_SYSTEM_PAGE << LOG_BIT_SIZEOF_LONG)
37
38#define omGetPageShiftOfAddr(addr) \
39 ((((unsigned long) addr) & (OM_SIZEOF_INDEX_PAGE -1)) >> LOG_BIT_SIZEOF_SYSTEM_PAGE)
40
41#define omGetPageIndexOfAddr(addr) \
42 (((unsigned long) addr) >> (LOG_BIT_SIZEOF_LONG + LOG_BIT_SIZEOF_SYSTEM_PAGE))
43
44#define omIsPageAddr(addr) \
45 ((omPageIndicies[omGetPageIndexOfAddr(addr) - omMinPageIndex] & \
46 (((unsigned long)1) << omGetPageShiftOfAddr(addr))) != 0)
47
48extern void omPageIndexFault(unsigned long page_index);
49extern unsigned long omMaxPageIndex;
50extern unsigned long omMinPageIndex;
51extern unsigned long *omPageIndicies;
52
53#define omRegisterPageIndex(index) \
54do \
55{ \
56 if (index < omMinPageIndex || index > omMaxPageIndex) \
57 { \
58 omPageIndexFault(index); \
59 } \
60} \
61while (0)
62
63#define omRegisterExternalAddr(addr) \
64do \
65{ \
66 unsigned long _omPageIndex = omGetPageIndexOfAddr(addr); \
67 omRegisterPageIndex(_omPageIndex); \
68 omPageIndicies[_omPageIndex - omMinPageIndex] &= \
69 ~ (((unsigned long) 1) << omGetPageShiftOfAddr(addr)); \
70} \
71while (0)
72
73#define omRegisterPageAddr(addr) \
74do \
75{ \
76 unsigned long _omPageIndex = omGetPageIndexOfAddr(addr); \
77 omRegisterPageIndex(_omPageIndex); \
78 omPageIndicies[_omPageIndex - omMinPageIndex] |= \
79 (((unsigned long) 1) << omGetPageShiftOfAddr(addr)); \
80} \
81while (0)
82
83/***********************************************************************
84 *
85 * declarations of procedures
86 */
87
88void* omGetPage();
89
90void omFreePage(void* page);
91
93
97
98/***********************************************************************
99 *
100 * Macros for page manipulations
101 */
102
103#define omIsAddrPageAligned(addr) \
104 (((long) (addr) & (SIZEOF_SYSTEM_PAGE -1)) == 0)
105
106#define omGetPageOfAddr(addr) \
107 ((void*) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1)))
108
109#define omGetBinPageOfAddr(addr) \
110 ((omBinPage) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1)))
111
112#define omIsAddrOnPage(addr, page) (omGetPageOfAddr(addr) == (void*) (page))
113
114#define omAreAddrOnSamePage(a1, a2) \
115 (omGetPageOfAddr(a1) == omGetPageOfAddr(a2))
116
117int omIsAddrOnFreePage(void* addr);
119
120#define omIsNotAddrOnFreePage(addr) (!omIsAddrOnFreePage(addr))
121
122#endif /* OM_PAGE_H */
int omGetNumberOfUsedPages()
unsigned long omMaxPageIndex
unsigned long omMinPageIndex
void omReleaseFreePages()
unsigned long * omPageIndicies
int omIsAddrOnFreePage(void *addr)
int omIsAddrOnRegisteredPage(void *addr)
void * omGetPage()
int omGetNumberOfAllocatedPages()
void omPageIndexFault(unsigned long page_index)
int omGetNumberOfFreePages()
void omFreePage(void *page)