KD System Rewrite:
[reactos.git] / reactos / ntoskrnl / ex / zone.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/zone.c
6 * PURPOSE: Implements zone buffers
7 *
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
9 */
10
11 /* INCLUDES ****************************************************************/
12
13 #include <ntoskrnl.h>
14
15 /* FUNCTIONS ***************************************************************/
16
17 // undocumented? from extypes.h in here for now...
18
19 //typedef struct _ZONE_ENTRY
20 //{
21 // SINGLE_LIST_ENTRY Entry;
22 //} ZONE_ENTRY, *PZONE_ENTRY;
23
24
25
26 /*
27 * @implemented
28 */
29 NTSTATUS
30 STDCALL
31 ExExtendZone (
32 PZONE_HEADER Zone,
33 PVOID Segment,
34 ULONG SegmentSize
35 )
36 {
37 PZONE_SEGMENT_HEADER entry;
38 PZONE_SEGMENT_HEADER seg;
39 unsigned int i;
40
41 seg = (PZONE_SEGMENT_HEADER)Segment;
42 seg->Reserved = (PVOID) SegmentSize;
43
44 PushEntryList(&Zone->SegmentList,&seg->SegmentList);
45
46 entry = (PZONE_SEGMENT_HEADER)( ((char*)seg) + sizeof(ZONE_SEGMENT_HEADER) );
47
48 for (i=0;i<(SegmentSize / Zone->BlockSize);i++)
49 {
50 PushEntryList(&Zone->FreeList,&entry->SegmentList);
51 entry = (PZONE_SEGMENT_HEADER)(((char*)entry) + sizeof(PZONE_SEGMENT_HEADER) +
52 Zone->BlockSize);
53 }
54 return(STATUS_SUCCESS);
55 }
56
57
58 /*
59 * @implemented
60 */
61 NTSTATUS
62 STDCALL
63 ExInterlockedExtendZone (
64 PZONE_HEADER Zone,
65 PVOID Segment,
66 ULONG SegmentSize,
67 PKSPIN_LOCK Lock
68 )
69 {
70 NTSTATUS ret;
71 KIRQL oldlvl;
72
73 KeAcquireSpinLock(Lock,&oldlvl);
74 ret = ExExtendZone(Zone,Segment,SegmentSize);
75 KeReleaseSpinLock(Lock,oldlvl);
76 return(ret);
77 }
78
79
80 /*
81 * @implemented
82 */
83 NTSTATUS
84 STDCALL
85 ExInitializeZone (
86 PZONE_HEADER Zone,
87 ULONG BlockSize,
88 PVOID InitialSegment,
89 ULONG InitialSegmentSize
90 )
91 /*
92 * FUNCTION: Initalizes a zone header
93 * ARGUMENTS:
94 * Zone = zone header to be initialized
95 * BlockSize = Size (in bytes) of the allocation size of the zone
96 * InitialSegment = Initial segment of storage allocated by the
97 * caller
98 * InitialSegmentSize = Initial size of the segment
99 */
100 {
101 unsigned int i;
102 PZONE_SEGMENT_HEADER seg;
103 PZONE_SEGMENT_HEADER entry;
104
105 Zone->FreeList.Next=NULL;
106 Zone->SegmentList.Next=NULL;
107 Zone->BlockSize=BlockSize;
108 Zone->TotalSegmentSize = InitialSegmentSize;
109
110 seg = (PZONE_SEGMENT_HEADER)InitialSegment;
111 seg->Reserved = (PVOID*) InitialSegmentSize;
112
113 PushEntryList(&Zone->SegmentList,&seg->SegmentList);
114
115 entry = (PZONE_SEGMENT_HEADER)( ((char*)seg) + sizeof(ZONE_SEGMENT_HEADER) );
116
117 for (i=0;i<(InitialSegmentSize / BlockSize);i++)
118 {
119 PushEntryList(&Zone->FreeList,&entry->SegmentList);
120 entry = (PZONE_SEGMENT_HEADER)(((char*)entry) + sizeof(PZONE_SEGMENT_HEADER) + BlockSize);
121 }
122
123 return(STATUS_SUCCESS);
124 }
125
126 /* EOF */