source: git/omalloc/omPage.h @ 8ae02b9

spielwiese
Last change on this file since 8ae02b9 was 13fe1b, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: DecAlpha-ccc-port git-svn-id: file:///usr/local/Singular/svn/trunk@5409 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*******************************************************************
2 *  File:    omPage.h
3 *  Purpose: declaration of routines for primitve page managment
4 *  Author:  obachman (Olaf Bachmann)
5 *  Created: 11/99
6 *  Version: $Id: omPage.h,v 1.8 2001-04-30 09:02:10 Singular Exp $
7 *******************************************************************/
8#ifndef OM_PAGE_H
9#define OM_PAGE_H
10
11/***********************************************************************
12 *
13 * Identifying whether an address is a BinAddr or LargeAddr:
14 * For this to work, omRegisterBinAddr or omRegisterLargeAddr must be called
15 * with every address gotten from an external malloc  routine
16 */
17
18/* Here is how it works (assume SIZEOF_LONG == 4, SIZEOF_SYSTEM_PAGE = 2^12):
19   Let
20   Addr: |    15               |  5       |    12        |
21          PAGE_INDEX            PAGE_SHIFT PAGE_OFFSET
22
23                                      PAGE_BASE
24
25   omPageIndicies is an array of bit-fields which is indexed by
26                  PAGE_INDEX - omMinPageIndex. Its maximal length
27                  is 2^15. PAGE_SHIFT is used as index into the bit-field.
28                  If it's value is 1, then addr is from omPage, else
29                  not.
30
31   omMinPageIndex is minimal page index of registered addr
32
33   In other words: omIsPageAddr iff
34   omPageIndicies[PAGE_INDEX - omMinPageIndex] & (1 << PAGE_SHIFT) */
35
36
37#define OM_SIZEOF_INDEX_PAGE (SIZEOF_SYSTEM_PAGE << LOG_BIT_SIZEOF_LONG)
38
39#define omGetPageShiftOfAddr(addr) \
40  ((((unsigned long) addr) & (OM_SIZEOF_INDEX_PAGE -1)) >> LOG_BIT_SIZEOF_SYSTEM_PAGE)
41
42#define omGetPageIndexOfAddr(addr) \
43  (((unsigned long) addr) >> (LOG_BIT_SIZEOF_LONG + LOG_BIT_SIZEOF_SYSTEM_PAGE))
44
45#define omIsPageAddr(addr) \
46   ((omPageIndicies[omGetPageIndexOfAddr(addr) - omMinPageIndex] & \
47    (((unsigned long)1) << omGetPageShiftOfAddr(addr))) != 0)
48
49extern void omPageIndexFault(unsigned long page_index);
50extern unsigned long omMaxPageIndex;
51extern unsigned long omMinPageIndex;
52extern unsigned long *omPageIndicies;
53
54#define omRegisterPageIndex(index)                      \
55do                                                      \
56{                                                       \
57  if (index < omMinPageIndex || index > omMaxPageIndex) \
58  {                                                     \
59    omPageIndexFault(index);                            \
60  }                                                     \
61}                                                       \
62while (0)
63
64#define omRegisterExternalAddr(addr)                        \
65do                                                          \
66{                                                           \
67  unsigned long _omPageIndex = omGetPageIndexOfAddr(addr);  \
68  omRegisterPageIndex(_omPageIndex);                        \
69  omPageIndicies[_omPageIndex - omMinPageIndex] &=          \
70    ~ (((unsigned long) 1) << omGetPageShiftOfAddr(addr));  \
71}                                                           \
72while (0)
73
74#define omRegisterPageAddr(addr)                            \
75do                                                          \
76{                                                           \
77  unsigned long _omPageIndex = omGetPageIndexOfAddr(addr);  \
78  omRegisterPageIndex(_omPageIndex);                        \
79  omPageIndicies[_omPageIndex - omMinPageIndex] |=          \
80      (((unsigned long) 1) << omGetPageShiftOfAddr(addr));  \
81}                                                           \
82while (0)
83
84/***********************************************************************
85 *
86 * declarations of procedures
87 */
88
89void* omGetPage();
90
91void omFreePage(void* page);
92
93void omReleaseFreePages();
94
95int omGetNumberOfFreePages();
96int omGetNumberOfUsedPages();
97int omGetNumberOfAllocatedPages();
98
99/***********************************************************************
100 *
101 * Macros for page manipulations
102 */
103
104#define omIsAddrPageAligned(addr) \
105  (((long) (addr) & (SIZEOF_SYSTEM_PAGE -1)) == 0)
106
107#define omGetPageOfAddr(addr) \
108  ((void*) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1)))
109
110#define omGetBinPageOfAddr(addr) \
111  ((omBinPage) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1)))
112
113#define omIsAddrOnPage(addr, page) (omGetPageOfAddr(addr) == (void*) (page))
114
115#define omAreAddrOnSamePage(a1, a2) \
116  (omGetPageOfAddr(a1) == omGetPageOfAddr(a2))
117
118int omIsAddrOnFreePage(void* addr);
119int omIsAddrOnRegisteredPage(void* addr);
120
121#define omIsNotAddrOnFreePage(addr) (!omIsAddrOnFreePage(addr))
122
123#endif /* OM_PAGE_H */
Note: See TracBrowser for help on using the repository browser.