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