This commit was generated by cvs2svn to compensate for changes in r52,
[reactos.git] / reactos / ntoskrnl / mm / pool.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/mm/pool.c
5 * PURPOSE: Implements the kernel memory pool
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 */
8
9 /* INCLUDES ****************************************************************/
10
11 #include <internal/ntoskrnl.h>
12 #include <ddk/ntddk.h>
13 #include <internal/pool.h>
14
15 //#define NDEBUG
16 #include <internal/debug.h>
17
18 /* GLOBALS *****************************************************************/
19
20 #define TAG_NONE (ULONG)(('N'<<0) + ('o'<<8) + ('n'<<16) + ('e'<<24))
21
22 /* FUNCTIONS ***************************************************************/
23
24 PVOID ExAllocatePool(POOL_TYPE PoolType, ULONG NumberOfBytes)
25 /*
26 * FUNCTION: Allocates pool memory of a specified type and returns a pointer
27 * to the allocated block. This routine is used for general purpose allocation
28 * of memory
29 * ARGUMENTS:
30 * PoolType
31 * Specifies the type of memory to allocate which can be one
32 * of the following:
33 *
34 * NonPagedPool
35 * NonPagedPoolMustSucceed
36 * NonPagedPoolCacheAligned
37 * NonPagedPoolCacheAlignedMustS
38 * PagedPool
39 * PagedPoolCacheAligned
40 *
41 * NumberOfBytes
42 * Specifies the number of bytes to allocate
43 * RETURNS: The allocated block on success
44 * NULL on failure
45 */
46 {
47 return(ExAllocatePoolWithTag(PoolType,NumberOfBytes,TAG_NONE));
48 }
49
50 PVOID ExAllocatePoolWithTag(ULONG type, ULONG size, ULONG Tag)
51 {
52 PVOID Block;
53
54 if (type == NonPagedPoolCacheAligned ||
55 type == NonPagedPoolCacheAlignedMustS)
56 {
57 UNIMPLEMENTED;
58 }
59
60 switch(type)
61 {
62 case NonPagedPool:
63 case NonPagedPoolMustSucceed:
64 case NonPagedPoolCacheAligned:
65 case NonPagedPoolCacheAlignedMustS:
66 Block = ExAllocateNonPagedPoolWithTag(type,size,Tag);
67 break;
68
69 case PagedPool:
70 case PagedPoolCacheAligned:
71 Block = ExAllocatePagedPoolWithTag(type,size,Tag);
72 break;
73
74 default:
75 return(NULL);
76 };
77
78 if ((type==NonPagedPoolMustSucceed || type==NonPagedPoolCacheAlignedMustS)
79 && Block==NULL)
80 {
81 KeBugCheck(MUST_SUCCEED_POOL_EMPTY);
82 }
83 return(Block);
84 }
85
86 PVOID ExAllocatePoolWithQuotaTag(POOL_TYPE PoolType, ULONG NumberOfBytes,
87 ULONG Tag)
88 {
89 PVOID Block;
90 PKTHREAD current = KeGetCurrentThread();
91
92 Block = ExAllocatePoolWithTag(PoolType,NumberOfBytes,Tag);
93 switch(PoolType)
94 {
95 case NonPagedPool:
96 case NonPagedPoolMustSucceed:
97 case NonPagedPoolCacheAligned:
98 case NonPagedPoolCacheAlignedMustS:
99 // current->NPagedPoolQuota = current->NPagedPoolQuota - NumberOfBytes;
100 break;
101
102 case PagedPool:
103 case PagedPoolCacheAligned:
104 // current->PagedPoolQuota = current->PagedPoolQuota - NumberOfBytes;
105 break;
106 };
107 return(Block);
108 }
109
110 PVOID ExAllocatePoolWithQuota(POOL_TYPE PoolType, ULONG NumberOfBytes)
111 {
112 return(ExAllocatePoolWithQuotaTag(PoolType,NumberOfBytes,TAG_NONE));
113 }
114