@@ -14,95 +14,49 @@ private class MallocAllocationFunction extends AllocationFunction {
1414 int sizeArg ;
1515
1616 MallocAllocationFunction ( ) {
17- exists ( string name |
18- hasGlobalOrStdName ( name ) and
19- // malloc(size)
20- ( name = "malloc" and sizeArg = 0 )
21- or
22- hasGlobalName ( name ) and
23- (
24- // ExAllocatePool(type, size)
25- name = "ExAllocatePool" and sizeArg = 1
26- or
27- // ExAllocatePool(type, size, tag)
28- name = "ExAllocatePoolWithTag" and sizeArg = 1
29- or
30- // ExAllocatePoolWithTagPriority(type, size, tag, priority)
31- name = "ExAllocatePoolWithTagPriority" and sizeArg = 1
32- or
33- // ExAllocatePoolWithQuota(type, size)
34- name = "ExAllocatePoolWithQuota" and sizeArg = 1
35- or
36- // ExAllocatePoolWithQuotaTag(type, size, tag)
37- name = "ExAllocatePoolWithQuotaTag" and sizeArg = 1
38- or
39- // IoAllocateMdl(address, size, flag, flag, irp)
40- name = "IoAllocateMdl" and sizeArg = 1
41- or
42- // IoAllocateErrorLogEntry(object, size)
43- name = "IoAllocateErrorLogEntry" and sizeArg = 1
44- or
45- // MmAllocateContiguousMemory(size, maxaddress)
46- name = "MmAllocateContiguousMemory" and sizeArg = 0
47- or
48- // MmAllocateContiguousNodeMemory(size, minaddress, maxaddress, bound, flag, prefer)
49- name = "MmAllocateContiguousNodeMemory" and sizeArg = 0
50- or
51- // MmAllocateContiguousMemorySpecifyCache(size, minaddress, maxaddress, bound, type)
52- name = "MmAllocateContiguousMemorySpecifyCache" and sizeArg = 0
53- or
54- // MmAllocateContiguousMemorySpecifyCacheNode(size, minaddress, maxaddress, bound, type, prefer)
55- name = "MmAllocateContiguousMemorySpecifyCacheNode" and sizeArg = 0
56- or
57- // MmAllocateNonCachedMemory(size)
58- name = "MmAllocateNonCachedMemory" and sizeArg = 0
59- or
60- // MmAllocateMappingAddress(size, tag)
61- name = "MmAllocateMappingAddress" and sizeArg = 0
62- or
63- // MmAllocatePagesForMdl(minaddress, maxaddress, skip, size)
64- name = "MmAllocatePagesForMdl" and sizeArg = 3
65- or
66- // MmAllocatePagesForMdlEx(minaddress, maxaddress, skip, size, type, flags)
67- name = "MmAllocatePagesForMdlEx" and sizeArg = 3
68- or
69- // MmAllocateNodePagesForMdlEx(minaddress, maxaddress, skip, size, type, prefer, flags)
70- name = "MmAllocateNodePagesForMdlEx" and sizeArg = 3
71- or
72- // LocalAlloc(flags, size)
73- name = "LocalAlloc" and sizeArg = 1
74- or
75- // GlobalAlloc(flags, size)
76- name = "GlobalAlloc" and sizeArg = 1
77- or
78- // HeapAlloc(heap, flags, size)
79- name = "HeapAlloc" and sizeArg = 2
80- or
81- // VirtualAlloc(address, size, type, flag)
82- name = "VirtualAlloc" and sizeArg = 1
83- or
84- // CoTaskMemAlloc(size)
85- name = "CoTaskMemAlloc" and sizeArg = 0
86- or
87- // kmem_alloc(size, flags)
88- name = "kmem_alloc" and sizeArg = 0
89- or
90- // kmem_zalloc(size, flags)
91- name = "kmem_zalloc" and sizeArg = 0
92- or
93- // CRYPTO_malloc(size_t num, const char *file, int line)
94- name = "CRYPTO_malloc" and sizeArg = 0
95- or
96- // CRYPTO_zalloc(size_t num, const char *file, int line)
97- name = "CRYPTO_zalloc" and sizeArg = 0
98- or
99- // CRYPTO_secure_malloc(size_t num, const char *file, int line)
100- name = "CRYPTO_secure_malloc" and sizeArg = 0
101- or
102- // CRYPTO_secure_zalloc(size_t num, const char *file, int line)
103- name = "CRYPTO_secure_zalloc" and sizeArg = 0
104- )
105- )
17+ hasGlobalOrStdName ( "malloc" ) and // malloc(size)
18+ sizeArg = 0
19+ or
20+ hasGlobalName ( [
21+ "MmAllocateContiguousMemory" , // MmAllocateContiguousMemory(size, maxaddress)
22+ "MmAllocateContiguousNodeMemory" , // MmAllocateContiguousNodeMemory(size, minaddress, maxaddress, bound, flag, prefer)
23+ "MmAllocateContiguousMemorySpecifyCache" , // MmAllocateContiguousMemorySpecifyCache(size, minaddress, maxaddress, bound, type)
24+ "MmAllocateContiguousMemorySpecifyCacheNode" , // MmAllocateContiguousMemorySpecifyCacheNode(size, minaddress, maxaddress, bound, type, prefer)
25+ "MmAllocateNonCachedMemory" , // MmAllocateNonCachedMemory(size)
26+ "MmAllocateMappingAddress" , // MmAllocateMappingAddress(size, tag)
27+ "CoTaskMemAlloc" , // CoTaskMemAlloc(size)
28+ "kmem_alloc" , // kmem_alloc(size, flags)
29+ "kmem_zalloc" , // kmem_zalloc(size, flags)
30+ "CRYPTO_malloc" , // CRYPTO_malloc(size_t num, const char *file, int line)
31+ "CRYPTO_zalloc" , // CRYPTO_zalloc(size_t num, const char *file, int line)
32+ "CRYPTO_secure_malloc" , // CRYPTO_secure_malloc(size_t num, const char *file, int line)
33+ "CRYPTO_secure_zalloc" // CRYPTO_secure_zalloc(size_t num, const char *file, int line)
34+ ] ) and
35+ sizeArg = 0
36+ or
37+ hasGlobalName ( [
38+ "ExAllocatePool" , // ExAllocatePool(type, size)
39+ "ExAllocatePoolWithTag" , // ExAllocatePool(type, size, tag)
40+ "ExAllocatePoolWithTagPriority" , // ExAllocatePoolWithTagPriority(type, size, tag, priority)
41+ "ExAllocatePoolWithQuota" , // ExAllocatePoolWithQuota(type, size)
42+ "ExAllocatePoolWithQuotaTag" , // ExAllocatePoolWithQuotaTag(type, size, tag)
43+ "IoAllocateMdl" , // IoAllocateMdl(address, size, flag, flag, irp)
44+ "IoAllocateErrorLogEntry" , // IoAllocateErrorLogEntry(object, size)
45+ "LocalAlloc" , // LocalAlloc(flags, size)
46+ "GlobalAlloc" , // GlobalAlloc(flags, size)
47+ "VirtualAlloc" // VirtualAlloc(address, size, type, flag)
48+ ] ) and
49+ sizeArg = 1
50+ or
51+ hasGlobalName ( [ "HeapAlloc" ] ) and // HeapAlloc(heap, flags, size)
52+ sizeArg = 2
53+ or
54+ hasGlobalName ( [
55+ "MmAllocatePagesForMdl" , // MmAllocatePagesForMdl(minaddress, maxaddress, skip, size)
56+ "MmAllocatePagesForMdlEx" , // MmAllocatePagesForMdlEx(minaddress, maxaddress, skip, size, type, flags)
57+ "MmAllocateNodePagesForMdlEx" // MmAllocateNodePagesForMdlEx(minaddress, maxaddress, skip, size, type, prefer, flags)
58+ ] ) and
59+ sizeArg = 3
10660 }
10761
10862 override int getSizeArg ( ) { result = sizeArg }
@@ -116,16 +70,11 @@ private class AllocaAllocationFunction extends AllocationFunction {
11670 int sizeArg ;
11771
11872 AllocaAllocationFunction ( ) {
119- exists ( string name |
120- hasGlobalName ( name ) and
121- (
122- // alloca(size)
123- name = "alloca" and sizeArg = 0
124- or
125- // __builtin_alloca(size)
126- name = "__builtin_alloca" and sizeArg = 0
127- )
128- )
73+ hasGlobalName ( [
74+ "alloca" , // // alloca(size)
75+ "__builtin_alloca" // __builtin_alloca(size)
76+ ] ) and
77+ sizeArg = 0
12978 }
13079
13180 override int getSizeArg ( ) { result = sizeArg }
@@ -142,11 +91,9 @@ private class CallocAllocationFunction extends AllocationFunction {
14291 int multArg ;
14392
14493 CallocAllocationFunction ( ) {
145- exists ( string name |
146- hasGlobalOrStdName ( name ) and
147- // calloc(num, size)
148- ( name = "calloc" and sizeArg = 1 and multArg = 0 )
149- )
94+ hasGlobalOrStdName ( "calloc" ) and // calloc(num, size)
95+ sizeArg = 1 and
96+ multArg = 0
15097 }
15198
15299 override int getSizeArg ( ) { result = sizeArg }
@@ -163,29 +110,22 @@ private class ReallocAllocationFunction extends AllocationFunction {
163110 int reallocArg ;
164111
165112 ReallocAllocationFunction ( ) {
166- exists ( string name |
167- hasGlobalOrStdName ( name ) and
168- // realloc(ptr, size)
169- ( name = "realloc" and sizeArg = 1 and reallocArg = 0 )
170- or
171- hasGlobalName ( name ) and
172- (
173- // LocalReAlloc(ptr, size, flags)
174- name = "LocalReAlloc" and sizeArg = 1 and reallocArg = 0
175- or
176- // GlobalReAlloc(ptr, size, flags)
177- name = "GlobalReAlloc" and sizeArg = 1 and reallocArg = 0
178- or
179- // HeapReAlloc(heap, flags, ptr, size)
180- name = "HeapReAlloc" and sizeArg = 3 and reallocArg = 2
181- or
182- // CoTaskMemRealloc(ptr, size)
183- name = "CoTaskMemRealloc" and sizeArg = 1 and reallocArg = 0
184- or
185- // CRYPTO_realloc(void *addr, size_t num, const char *file, int line);
186- name = "CRYPTO_realloc" and sizeArg = 1 and reallocArg = 0
187- )
188- )
113+ hasGlobalOrStdName ( "realloc" ) and // realloc(ptr, size)
114+ sizeArg = 1 and
115+ reallocArg = 0
116+ or
117+ hasGlobalName ( [
118+ "LocalReAlloc" , // LocalReAlloc(ptr, size, flags)
119+ "GlobalReAlloc" , // GlobalReAlloc(ptr, size, flags)
120+ "CoTaskMemRealloc" , // CoTaskMemRealloc(ptr, size)
121+ "CRYPTO_realloc" // CRYPTO_realloc(void *addr, size_t num, const char *file, int line)
122+ ] ) and
123+ sizeArg = 1 and
124+ reallocArg = 0
125+ or
126+ hasGlobalName ( "HeapReAlloc" ) and // HeapReAlloc(heap, flags, ptr, size)
127+ sizeArg = 3 and
128+ reallocArg = 2
189129 }
190130
191131 override int getSizeArg ( ) { result = sizeArg }
@@ -199,40 +139,18 @@ private class ReallocAllocationFunction extends AllocationFunction {
199139 */
200140private class SizelessAllocationFunction extends AllocationFunction {
201141 SizelessAllocationFunction ( ) {
202- exists ( string name |
203- hasGlobalName ( name ) and
204- (
205- // ExAllocateFromLookasideListEx(list)
206- name = "ExAllocateFromLookasideListEx"
207- or
208- // ExAllocateFromPagedLookasideList(list)
209- name = "ExAllocateFromPagedLookasideList"
210- or
211- // ExAllocateFromNPagedLookasideList(list)
212- name = "ExAllocateFromNPagedLookasideList"
213- or
214- // ExAllocateTimer(callback, context, attributes)
215- name = "ExAllocateTimer"
216- or
217- // IoAllocateWorkItem(object)
218- name = "IoAllocateWorkItem"
219- or
220- // MmMapLockedPagesWithReservedMapping(address, tag, list, type)
221- name = "MmMapLockedPagesWithReservedMapping"
222- or
223- // MmMapLockedPages(list, mode)
224- name = "MmMapLockedPages"
225- or
226- // MmMapLockedPagesSpecifyCache(list, mode, type, address, flag, flag)
227- name = "MmMapLockedPagesSpecifyCache"
228- or
229- // pool_get(pool, flags)
230- name = "pool_get"
231- or
232- // pool_cache_get(pool, flags)
233- name = "pool_cache_get"
234- )
235- )
142+ hasGlobalName ( [
143+ "ExAllocateFromLookasideListEx" , // ExAllocateFromLookasideListEx(list)
144+ "ExAllocateFromPagedLookasideList" , // ExAllocateFromPagedLookasideList(list)
145+ "ExAllocateFromNPagedLookasideList" , // ExAllocateFromNPagedLookasideList(list)
146+ "ExAllocateTimer" , // ExAllocateTimer(callback, context, attributes)
147+ "IoAllocateWorkItem" , // IoAllocateWorkItem(object)
148+ "MmMapLockedPagesWithReservedMapping" , // MmMapLockedPagesWithReservedMapping(address, tag, list, type)
149+ "MmMapLockedPages" , // MmMapLockedPages(list, mode)
150+ "MmMapLockedPagesSpecifyCache" , // MmMapLockedPagesSpecifyCache(list, mode, type, address, flag, flag)
151+ "pool_get" , // pool_get(pool, flags)
152+ "pool_cache_get" // pool_cache_get(pool, flags)
153+ ] )
236154 }
237155}
238156
0 commit comments