branch update for HEAD-2003021201
[reactos.git] / ntoskrnl / mm / pool.c
1 /* $Id$
2  * 
3  * COPYRIGHT:    See COPYING in the top level directory
4  * PROJECT:      ReactOS kernel
5  * FILE:         ntoskrnl/mm/pool.c
6  * PURPOSE:      Implements the kernel memory pool
7  * PROGRAMMER:   David Welch (welch@mcmail.com)
8  */
9
10 /* INCLUDES ****************************************************************/
11
12 #include <ddk/ntddk.h>
13 #include <reactos/bugcodes.h>
14 #include <internal/ntoskrnl.h>
15 #include <internal/pool.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20 /* GLOBALS *****************************************************************/
21
22 #define TAG_NONE (ULONG)(('N'<<0) + ('o'<<8) + ('n'<<16) + ('e'<<24))
23
24 /* FUNCTIONS ***************************************************************/
25
26 PVOID STDCALL STATIC
27 EiAllocatePool(POOL_TYPE PoolType,
28                ULONG NumberOfBytes,
29                ULONG Tag,
30                PVOID Caller)
31 {
32    PVOID Block;
33    
34    if (PoolType == NonPagedPoolCacheAligned || 
35        PoolType == NonPagedPoolCacheAlignedMustS)
36      {
37         UNIMPLEMENTED;
38      }
39    
40    switch(PoolType)
41      {
42       case NonPagedPool:
43       case NonPagedPoolMustSucceed:
44       case NonPagedPoolCacheAligned:
45       case NonPagedPoolCacheAlignedMustS:
46         Block = 
47           ExAllocateNonPagedPoolWithTag(PoolType,
48                                         NumberOfBytes,
49                                         Tag,
50                                         Caller);
51         break;
52         
53       case PagedPool:
54       case PagedPoolCacheAligned:
55         Block = ExAllocatePagedPoolWithTag(PoolType,NumberOfBytes,Tag);
56         break;
57         
58       default:
59         return(NULL);
60      };
61    
62    if ((PoolType==NonPagedPoolMustSucceed || 
63         PoolType==NonPagedPoolCacheAlignedMustS) && Block==NULL)     
64      {
65         KeBugCheck(MUST_SUCCEED_POOL_EMPTY);
66      }
67    return(Block);
68 }
69
70 PVOID STDCALL
71 ExAllocatePool (POOL_TYPE PoolType, ULONG NumberOfBytes)
72 /*
73  * FUNCTION: Allocates pool memory of a specified type and returns a pointer
74  * to the allocated block. This routine is used for general purpose allocation
75  * of memory
76  * ARGUMENTS:
77  *        PoolType
78  *               Specifies the type of memory to allocate which can be one
79  *               of the following:
80  *  
81  *               NonPagedPool
82  *               NonPagedPoolMustSucceed
83  *               NonPagedPoolCacheAligned
84  *               NonPagedPoolCacheAlignedMustS
85  *               PagedPool
86  *               PagedPoolCacheAligned
87  *        
88  *        NumberOfBytes
89  *               Specifies the number of bytes to allocate
90  * RETURNS: The allocated block on success
91  *          NULL on failure
92  */
93 {
94    PVOID Block;
95    Block = EiAllocatePool(PoolType,
96                           NumberOfBytes,
97                           TAG_NONE,
98                           (PVOID)__builtin_return_address(0));
99    return(Block);
100 }
101
102
103 PVOID STDCALL
104 ExAllocatePoolWithTag (ULONG PoolType, ULONG NumberOfBytes, ULONG Tag)
105 {
106    PVOID Block;
107    Block = EiAllocatePool(PoolType,
108                           NumberOfBytes,
109                           Tag,
110                           (PVOID)__builtin_return_address(0));
111    return(Block);
112 }
113
114
115 PVOID STDCALL
116 ExAllocatePoolWithQuota (POOL_TYPE PoolType, ULONG NumberOfBytes)
117 {
118   return(ExAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, TAG_NONE));
119 }
120
121
122 PVOID STDCALL
123 ExAllocatePoolWithQuotaTag (IN  POOL_TYPE       PoolType,
124                             IN  ULONG           NumberOfBytes,
125                             IN  ULONG           Tag)
126 {
127 #if 0
128   PVOID Block;
129   Block = EiAllocatePool(PoolType,
130                          NumberOfBytes,
131                          Tag,
132                          (PVOID)__builtin_return_address(0));
133   return(Block);
134 #endif
135   UNIMPLEMENTED;
136 }
137
138 VOID STDCALL
139 ExFreePool(IN PVOID Block)
140 {
141   if (Block >= MmPagedPoolBase && Block < (MmPagedPoolBase + MmPagedPoolSize))
142     {
143       ExFreePagedPool(Block);
144     }
145   else
146     {
147       ExFreeNonPagedPool(Block);
148     }
149 }
150
151 /* EOF */
152
153
154
155