summaryrefslogtreecommitdiffstats
path: root/private/ntos/inc/region.h
blob: 0d8c0aefb6dbad8945277e6556d06301afe98c19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// Region Allocation.
//
// Regions can be used to replace zones where it is not essential that the
// specified spinlock be acquired.
//

typedef struct _REGION_SEGMENT_HEADER {
    struct _REGION_SEGMENT_HEADER *NextSegment;
    PVOID Reserved;
} REGION_SEGMENT_HEADER, *PREGION_SEGMENT_HEADER;

typedef struct _REGION_HEADER {
    SLIST_HEADER ListHead;
    PREGION_SEGMENT_HEADER FirstSegment;
    ULONG BlockSize;
    ULONG TotalSize;
} REGION_HEADER, *PREGION_HEADER;

NTKERNELAPI
VOID
ExInitializeRegion(
    IN PREGION_HEADER Region,
    IN ULONG BlockSize,
    IN PVOID Segment,
    IN ULONG SegmentSize
    );

NTKERNELAPI
VOID
ExInterlockedExtendRegion(
    IN PREGION_HEADER Region,
    IN PVOID Segment,
    IN ULONG SegmentSize,
    IN PKSPIN_LOCK Lock
    );

//++
//
// PVOID
// ExInterlockedAllocateFromRegion(
//     IN PREGION_HEADER Region,
//     IN PKSPIN_LOCK Lock
//     )
//
// Routine Description:
//
//     This routine removes a free entry from the specified region and returns
//     the address of the entry.
//
// Arguments:
//
//     Region - Supplies a pointer to the region header.
//
//     Lock - Supplies a pointer to a spinlock.
//
// Return Value:
//
//     The address of the removed entry is returned as the function value.
//
//--

#if defined(_ALPHA_) || defined(_MIPS_) || defined(_X86_)

#define ExInterlockedAllocateFromRegion(Region, Lock) \
    (PVOID)ExInterlockedPopEntrySList(&(Region)->ListHead, Lock)

#else

#define ExInterlockedAllocateFromRegion(Region, Lock) \
    (PVOID)ExInterlockedPopEntryList((PSINGLE_LIST_ENTRY)&(Region)->ListHead.Next, Lock)

#endif

//++
//
// PVOID
// ExInterlockedFreeToRegion(
//     IN PREGION_HEADER Region,
//     IN PVOID Block,
//     IN PKSPIN_LOCK Lock
//     )
//
// Routine Description:
//
//     This routine inserts an entry at the front of the free list for the
//     specified region.
//
// Arguments:
//
//     Region - Supplies a pointer to the region header.
//
//     Block - Supplies a pointer to the entry that is inserted at the front
//        of the region free list.
//
//     Lock - Supplies a pointer to a spinlock.
//
// Return Value:
//
//     The previous firt entry in the region free list is returned as the
//     function value. a value of NULL implies the region went from empty
//     to at least one free block.
//
//--

#if defined(_ALPHA_) || defined(_MIPS_) || defined(_X86_)

#define ExInterlockedFreeToRegion(Region, Block, Lock) \
    ExInterlockedPushEntrySList(&(Region)->ListHead, ((PSINGLE_LIST_ENTRY)(Block)), Lock)

#else

#define ExInterlockedFreeToRegion(Region, Block, Lock) \
    ExInterlockedPushEntryList((PSINGLE_LIST_ENTRY)&(Region)->ListHead.Next, ((PSINGLE_LIST_ENTRY)(Block)), Lock)

#endif

//++
//
// BOOLEAN
// ExIsFullRegion(
//     IN PREGION_HEADER Region
//     )
//
// Routine Description:
//
//     This routine determines if the specified region is full. A region is
//     considered full if the free list is empty.
//
// Arguments:
//
//     Region - Supplies a pointer the region header.
//
// Return Value:
//
//     TRUE if the region is full and FALSE otherwise.
//
//--

#define ExIsFullRegion(Region) \
    ((Region)->ListHead.Next == (PSINGLE_LIST_ENTRY)NULL)

//++
//
// BOOLEAN
// ExIsObjectInFirstRegionSegment(
//     IN PREGION_HEADER Region,
//     IN PVOID Object
//     )
//
// Routine Description:
//
//     This routine determines if the specified object is contained in the
//     first region segement.
//
// Arguments:
//
//     Region - Supplies a pointer to the region header.
//
//     Object - Supplies a pointer to an object.
//
// Return Value:
//
//     TRUE if the Object came from the first segment of region.
//
//--

#define ExIsObjectInFirstRegionSegment(Region, Object) ((BOOLEAN)   \
    (((PUCHAR)(Object) >= ((PUCHAR)((Region)->FirstSegment) + sizeof(REGION_SEGMENT_HEADER))) &&        \
     ((PUCHAR)(Object) < ((PUCHAR)((Region)->FirstSegment) + (Region)->TotalSize + sizeof(REGION_SEGMENT_HEADER)))))