Make WinCVS look a little cleaner.
[reactos.git] / reactos / ntoskrnl / ex / zone.c
1 /* $Id: zone.c,v 1.4 2002/09/08 10:23:20 chorns Exp $
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 <ddk/ntddk.h>
13
14 /* FUNCTIONS ***************************************************************/
15
16 NTSTATUS
17 STDCALL
18 ExExtendZone (
19 PZONE_HEADER Zone,
20 PVOID Segment,
21 ULONG SegmentSize
22 )
23 {
24 PZONE_ENTRY entry;
25 PZONE_SEGMENT seg;
26 unsigned int i;
27
28 seg = (PZONE_SEGMENT)Segment;
29 seg->size = SegmentSize;
30
31 PushEntryList(&Zone->SegmentList,&seg->Entry);
32
33 entry = (PZONE_ENTRY)( ((PVOID)seg) + sizeof(ZONE_SEGMENT) );
34
35 for (i=0;i<(SegmentSize / Zone->BlockSize);i++)
36 {
37 PushEntryList(&Zone->FreeList,&entry->Entry);
38 entry = (PZONE_ENTRY)(((PVOID)entry) + sizeof(ZONE_ENTRY) +
39 Zone->BlockSize);
40 }
41 return(STATUS_SUCCESS);
42 }
43
44
45 NTSTATUS
46 STDCALL
47 ExInterlockedExtendZone (
48 PZONE_HEADER Zone,
49 PVOID Segment,
50 ULONG SegmentSize,
51 PKSPIN_LOCK Lock
52 )
53 {
54 NTSTATUS ret;
55 KIRQL oldlvl;
56
57 KeAcquireSpinLock(Lock,&oldlvl);
58 ret = ExExtendZone(Zone,Segment,SegmentSize);
59 KeReleaseSpinLock(Lock,oldlvl);
60 return(ret);
61 }
62
63
64 NTSTATUS
65 STDCALL
66 ExInitializeZone (
67 PZONE_HEADER Zone,
68 ULONG BlockSize,
69 PVOID InitialSegment,
70 ULONG InitialSegmentSize
71 )
72 /*
73 * FUNCTION: Initalizes a zone header
74 * ARGUMENTS:
75 * Zone = zone header to be initialized
76 * BlockSize = Size (in bytes) of the allocation size of the zone
77 * InitialSegment = Initial segment of storage allocated by the
78 * caller
79 * InitialSegmentSize = Initial size of the segment
80 */
81 {
82 unsigned int i;
83 PZONE_SEGMENT seg;
84 PZONE_ENTRY entry;
85
86 Zone->FreeList.Next=NULL;
87 Zone->SegmentList.Next=NULL;
88 Zone->BlockSize=BlockSize;
89 Zone->TotalSegmentSize = InitialSegmentSize;
90
91 seg = (PZONE_SEGMENT)InitialSegment;
92 seg->size = InitialSegmentSize;
93
94 PushEntryList(&Zone->SegmentList,&seg->Entry);
95
96 entry = (PZONE_ENTRY)( ((PVOID)seg) + sizeof(ZONE_SEGMENT) );
97
98 for (i=0;i<(InitialSegmentSize / BlockSize);i++)
99 {
100 PushEntryList(&Zone->FreeList,&entry->Entry);
101 entry = (PZONE_ENTRY)(((PVOID)entry) + sizeof(ZONE_ENTRY) + BlockSize);
102 }
103
104 return(STATUS_SUCCESS);
105 }
106
107 /* EOF */