annotate Allocator.cpp @ 1311:1dee26137a92

added books h file
author Gloval
date Tue, 25 Jun 2013 00:05:51 +0400
parents 0aeac0b9ca30
children c4ab816fcc5e
rev   line source
1165
29a8defbad9e temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents: 1093
diff changeset
1 #ifdef _MSC_VER
29a8defbad9e temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents: 1093
diff changeset
2 #define _CRT_SECURE_NO_WARNINGS
29a8defbad9e temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents: 1093
diff changeset
3 #endif
29a8defbad9e temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents: 1093
diff changeset
4
0
Ritor1
parents:
diff changeset
5 #include <string.h>
Ritor1
parents:
diff changeset
6 #include <stdio.h>
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8 #include "Allocator.h"
Ritor1
parents:
diff changeset
9
Ritor1
parents:
diff changeset
10 #include "mm7_data.h"
Ritor1
parents:
diff changeset
11
Ritor1
parents:
diff changeset
12
Ritor1
parents:
diff changeset
13
Ritor1
parents:
diff changeset
14 Allocator *pAllocator; // idb
Ritor1
parents:
diff changeset
15
Ritor1
parents:
diff changeset
16
Ritor1
parents:
diff changeset
17
Ritor1
parents:
diff changeset
18
Ritor1
parents:
diff changeset
19
Ritor1
parents:
diff changeset
20 void __fastcall CheckMemoryAccessibility(void *pBase, DWORD uSize);
Ritor1
parents:
diff changeset
21
Ritor1
parents:
diff changeset
22
Ritor1
parents:
diff changeset
23
Ritor1
parents:
diff changeset
24 //----- (00426755) --------------------------------------------------------
Ritor1
parents:
diff changeset
25 void *Allocator::AllocNamedChunk(const void *pPrevPtrValue, unsigned int uSize, const char *pName)
Ritor1
parents:
diff changeset
26 {
705
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
27
1093
c59ac5ea63f5 * stru154::GetFacePlane mistake fixed
zipi
parents: 705
diff changeset
28 if ( pPrevPtrValue && !aborting_app )
c59ac5ea63f5 * stru154::GetFacePlane mistake fixed
zipi
parents: 705
diff changeset
29 AbortWithError();
c59ac5ea63f5 * stru154::GetFacePlane mistake fixed
zipi
parents: 705
diff changeset
30 if (!uSize)
c59ac5ea63f5 * stru154::GetFacePlane mistake fixed
zipi
parents: 705
diff changeset
31 return 0;
705
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
32 return malloc(uSize);
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
33 /*
0
Ritor1
parents:
diff changeset
34 //Allocator *v4; // esi@1
Ritor1
parents:
diff changeset
35 unsigned int v5; // eax@7
Ritor1
parents:
diff changeset
36 void *result; // eax@8
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
37 // unsigned int *pNumBuffersUsed; // ebx@12
0
Ritor1
parents:
diff changeset
38 unsigned int v8; // edi@15
Ritor1
parents:
diff changeset
39 char v9; // zf@15
Ritor1
parents:
diff changeset
40 int v10; // eax@16
Ritor1
parents:
diff changeset
41 void **v11; // ebx@19
Ritor1
parents:
diff changeset
42 void *v12; // eax@22
Ritor1
parents:
diff changeset
43 unsigned int Size; // [sp+14h] [bp+Ch]@16
Ritor1
parents:
diff changeset
44
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
45 int aligned_size;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
46
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
47
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
48 if ( pPrevPtrValue && !aborting_app )
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
49 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
50 if ( !bBigBufferAllocated && !aborting_app )
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
51 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
52
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
53 if (!uSize)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
54 return 0;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
55
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
56 if (((uSize & 0x80000000u) != 0) && !aborting_app)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
57 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
58
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
59 if (uNumBuffersUsed == 6000 && !aborting_app)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
60 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
61
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
62 ++uNumBuffersUsed;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
63
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
64 if (!bUseBigBuffer)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
65 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
66 pMemoryBuffers[uNumBuffersUsed] = malloc(uSize);
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
67 if (pMemoryBuffers[uNumBuffersUsed])
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
68 uMemoryBuffersSizes[uNumBuffersUsed] = uSize;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
69 else
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
70 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
71 if ( !aborting_app )
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
72 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
73 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
74 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
75 else
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
76 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
77
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
78 aligned_size =(uSize&0xFFFFFFFC) + 4;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
79
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
80 if ((uNextFreeOffsetInBigBuffer +aligned_size) > uBigBufferSizeAligned)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
81 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
82 printf("Id: %s Size: %i", pName, aligned_size);
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
83 CreateFileDump( "Memory");
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
84 if ( !aborting_app )
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
85 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
86 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
87
697
2dfb67633b01 GUIButton Release
zipi
parents: 363
diff changeset
88 pMemoryBuffers[uNumBuffersUsed] = (char *)pBigMemoryBuffer + uNextFreeOffsetInBigBuffer;//(char *)(pBigBufferAligned) + uNextFreeOffsetInBigBuffer;
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
89 uMemoryBuffersSizes[uNumBuffersUsed] =aligned_size;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
90
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
91 if (pName)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
92 strncpy(pMemoryBuffersNames[uNumBuffersUsed], pName, 11);
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
93 uNextFreeOffsetInBigBuffer += aligned_size;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
94 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
95 return pMemoryBuffers[uNumBuffersUsed];
705
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
96 */
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
97 /*
0
Ritor1
parents:
diff changeset
98 //v4 = this;
Ritor1
parents:
diff changeset
99 if ( pPrevPtrValue && !aborting_app )
Ritor1
parents:
diff changeset
100 AbortWithError();
Ritor1
parents:
diff changeset
101 if ( !bBigBufferAllocated && !aborting_app )
Ritor1
parents:
diff changeset
102 AbortWithError();
Ritor1
parents:
diff changeset
103 v5 = uSize;
Ritor1
parents:
diff changeset
104 if ( uSize )
Ritor1
parents:
diff changeset
105 {
Ritor1
parents:
diff changeset
106 if ( (uSize & 0x80000000u) != 0 && !aborting_app )
Ritor1
parents:
diff changeset
107 {
Ritor1
parents:
diff changeset
108 AbortWithError();
Ritor1
parents:
diff changeset
109 v5 = uSize;
Ritor1
parents:
diff changeset
110 }
Ritor1
parents:
diff changeset
111 pNumBuffersUsed = &uNumBuffersUsed;
Ritor1
parents:
diff changeset
112 if (uNumBuffersUsed == 6000 && !aborting_app)
Ritor1
parents:
diff changeset
113 {
Ritor1
parents:
diff changeset
114 AbortWithError();
Ritor1
parents:
diff changeset
115 v5 = uSize;
Ritor1
parents:
diff changeset
116 }
Ritor1
parents:
diff changeset
117 v8 = *pNumBuffersUsed;
Ritor1
parents:
diff changeset
118 v9 = bUseBigBuffer == 0;
Ritor1
parents:
diff changeset
119 ++*pNumBuffersUsed;
Ritor1
parents:
diff changeset
120 if ( v9 )
Ritor1
parents:
diff changeset
121 {
Ritor1
parents:
diff changeset
122 v12 = malloc(v5);
Ritor1
parents:
diff changeset
123 v11 = &pMemoryBuffers[v8];
Ritor1
parents:
diff changeset
124 *v11 = v12;
Ritor1
parents:
diff changeset
125 if ( v12 )
Ritor1
parents:
diff changeset
126 {
Ritor1
parents:
diff changeset
127 uMemoryBuffersSizes[v8] = uSize;
Ritor1
parents:
diff changeset
128 }
Ritor1
parents:
diff changeset
129 else
Ritor1
parents:
diff changeset
130 {
Ritor1
parents:
diff changeset
131 if ( !aborting_app )
Ritor1
parents:
diff changeset
132 AbortWithError();
Ritor1
parents:
diff changeset
133 }
Ritor1
parents:
diff changeset
134 }
Ritor1
parents:
diff changeset
135 else
Ritor1
parents:
diff changeset
136 {
Ritor1
parents:
diff changeset
137 LOBYTE(v5) = v5 & 0xFC;
Ritor1
parents:
diff changeset
138 v10 = v5 + 4;
Ritor1
parents:
diff changeset
139 Size = v10;
Ritor1
parents:
diff changeset
140 if ( v10 + uNextFreeOffsetInBigBuffer > uBigBufferSizeAligned )
Ritor1
parents:
diff changeset
141 {
Ritor1
parents:
diff changeset
142 printf("Id: %s Size: %i\n", pName, v10);
Ritor1
parents:
diff changeset
143 CreateFileDump("Memory");
Ritor1
parents:
diff changeset
144 if ( !aborting_app )
Ritor1
parents:
diff changeset
145 AbortWithError();
Ritor1
parents:
diff changeset
146 }
Ritor1
parents:
diff changeset
147 v11 = &pMemoryBuffers[v8];
Ritor1
parents:
diff changeset
148 *v11 = (char *)pBigMemoryBuffer + uNextFreeOffsetInBigBuffer;
Ritor1
parents:
diff changeset
149 uMemoryBuffersSizes[v8] = Size;
Ritor1
parents:
diff changeset
150 if (pName)
Ritor1
parents:
diff changeset
151 strncpy(pMemoryBuffersNames[v8], pName, 11);
Ritor1
parents:
diff changeset
152 uNextFreeOffsetInBigBuffer += Size;
Ritor1
parents:
diff changeset
153 }
Ritor1
parents:
diff changeset
154 result = *v11;
Ritor1
parents:
diff changeset
155 }
Ritor1
parents:
diff changeset
156 else
Ritor1
parents:
diff changeset
157 {
Ritor1
parents:
diff changeset
158 result = 0;
Ritor1
parents:
diff changeset
159 }
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
160 return result;*/
0
Ritor1
parents:
diff changeset
161 }
Ritor1
parents:
diff changeset
162 // 720018: using guessed type int aborting_app;
Ritor1
parents:
diff changeset
163
Ritor1
parents:
diff changeset
164
Ritor1
parents:
diff changeset
165
Ritor1
parents:
diff changeset
166 //----- (004266CD) --------------------------------------------------------
Ritor1
parents:
diff changeset
167 bool Allocator::Initialize(unsigned int uNumKBytes)
Ritor1
parents:
diff changeset
168 {
Ritor1
parents:
diff changeset
169 if (bBigBufferAllocated)
Ritor1
parents:
diff changeset
170 return false;
Ritor1
parents:
diff changeset
171
Ritor1
parents:
diff changeset
172 if (!uNumKBytes)
Ritor1
parents:
diff changeset
173 return false;
Ritor1
parents:
diff changeset
174
Ritor1
parents:
diff changeset
175 pBigMemoryBuffer = malloc(uNumKBytes * 1024);
Ritor1
parents:
diff changeset
176 if (!pBigMemoryBuffer)
Ritor1
parents:
diff changeset
177 return false;
Ritor1
parents:
diff changeset
178
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
179 pBigBufferAligned = (void *)((unsigned int)(pBigMemoryBuffer) & 0xFFFF0000 + 4096);
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
180 //(char *)pBigMemoryBuffer + -((unsigned __int16)pBigMemoryBuffer & 0xFFF) + 4096;
0
Ritor1
parents:
diff changeset
181 uBigBufferSizeAligned = (uNumKBytes * 1024) - 4096;
Ritor1
parents:
diff changeset
182
Ritor1
parents:
diff changeset
183 uNumBuffersUsed = 0;
Ritor1
parents:
diff changeset
184 uNextFreeOffsetInBigBuffer = 0;
Ritor1
parents:
diff changeset
185
Ritor1
parents:
diff changeset
186 bUseBigBuffer = true;
Ritor1
parents:
diff changeset
187 return bBigBufferAllocated = true;
Ritor1
parents:
diff changeset
188 }
Ritor1
parents:
diff changeset
189
Ritor1
parents:
diff changeset
190
Ritor1
parents:
diff changeset
191 //----- (00426474) --------------------------------------------------------
Ritor1
parents:
diff changeset
192 void Allocator::FreeChunk(void *ptr)
Ritor1
parents:
diff changeset
193 {
705
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
194 free(ptr);
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
195 return;
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
196 /* Allocator *v2; // esi@1
0
Ritor1
parents:
diff changeset
197 unsigned int v3; // eax@5
Ritor1
parents:
diff changeset
198 signed int i; // edi@5
Ritor1
parents:
diff changeset
199 unsigned int v5; // eax@13
Ritor1
parents:
diff changeset
200 signed int v6; // ecx@16
Ritor1
parents:
diff changeset
201 signed int j; // edx@16
Ritor1
parents:
diff changeset
202 char v8; // zf@20
Ritor1
parents:
diff changeset
203
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
204
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
205
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
206 unsigned int uBuffindx;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
207 unsigned int indx;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
208
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
209 if (ptr)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
210 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
211 if ((!bBigBufferAllocated)&& (!aborting_app ))
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
212 AbortWithError();
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
213 for (indx = 0; indx <=uNumBuffersUsed; ++indx)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
214 if (pMemoryBuffers[indx] == ptr)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
215 break;
702
efde64b3e147 sub_4BDAAF clean
zipi
parents: 697
diff changeset
216 //if ((indx>uNumBuffersUsed)&& !aborting_app )
efde64b3e147 sub_4BDAAF clean
zipi
parents: 697
diff changeset
217 //AbortWithError(); //to detect memory problems - uncomment
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
218 if (!bUseBigBuffer)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
219 free(pMemoryBuffers[indx]);
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
220 pMemoryBuffers[indx] = NULL;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
221 uMemoryBuffersSizes[indx] = 0;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
222 pMemoryBuffersNames[indx][0] = 0;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
223 if (indx == (uNumBuffersUsed-1))
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
224 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
225 if (indx>0)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
226 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
227 uBuffindx = 0;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
228 for (j = 0; j < uNumBuffersUsed-1; ++j)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
229 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
230 if (pMemoryBuffers[j])
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
231 uBuffindx = j;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
232 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
233 uNumBuffersUsed = uBuffindx + 1;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
234 if (bUseBigBuffer)
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
235 uNextFreeOffsetInBigBuffer =
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
236 ((long)((char*)pMemoryBuffers[uBuffindx] -(char*)pBigBufferAligned)+ uMemoryBuffersSizes[uBuffindx]);
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
237 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
238 else
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
239 {
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
240 uNumBuffersUsed = 0;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
241 uNextFreeOffsetInBigBuffer = 0;
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
242 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
243 }
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
244 }
705
e39702f35283 memory allocation partly reworked
zipi
parents: 702
diff changeset
245 */
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
246 /*
0
Ritor1
parents:
diff changeset
247 v2 = this;
Ritor1
parents:
diff changeset
248 if ( ptr )
Ritor1
parents:
diff changeset
249 {
Ritor1
parents:
diff changeset
250 if ( !this->bBigBufferAllocated && !aborting_app )
Ritor1
parents:
diff changeset
251 AbortWithError();
Ritor1
parents:
diff changeset
252 v3 = v2->uNumBuffersUsed;
Ritor1
parents:
diff changeset
253 for ( i = 0; i < (signed int)v3; ++i )
Ritor1
parents:
diff changeset
254 {
Ritor1
parents:
diff changeset
255 if ( v2->pMemoryBuffers[i] == ptr )
Ritor1
parents:
diff changeset
256 break;
Ritor1
parents:
diff changeset
257 }
Ritor1
parents:
diff changeset
258 if ( i >= (signed int)v3 && !aborting_app )
Ritor1
parents:
diff changeset
259 AbortWithError();
Ritor1
parents:
diff changeset
260 if ( !v2->bUseBigBuffer )
Ritor1
parents:
diff changeset
261 free(v2->pMemoryBuffers[i]);
Ritor1
parents:
diff changeset
262 v2->pMemoryBuffers[i] = 0;
Ritor1
parents:
diff changeset
263 v2->uMemoryBuffersSizes[i] = 0;
Ritor1
parents:
diff changeset
264 LOBYTE(v2->pMemoryBuffers[3 * i + 12000]) = 0;
Ritor1
parents:
diff changeset
265 v5 = v2->uNumBuffersUsed;
Ritor1
parents:
diff changeset
266 if ( i == v5 - 1 )
Ritor1
parents:
diff changeset
267 {
Ritor1
parents:
diff changeset
268 if ( i )
Ritor1
parents:
diff changeset
269 {
Ritor1
parents:
diff changeset
270 v6 = 0;
Ritor1
parents:
diff changeset
271 for ( j = 0; j < (signed int)v5; ++j )
Ritor1
parents:
diff changeset
272 {
Ritor1
parents:
diff changeset
273 if ( v2->pMemoryBuffers[j] )
Ritor1
parents:
diff changeset
274 v6 = j;
Ritor1
parents:
diff changeset
275 }
Ritor1
parents:
diff changeset
276 v8 = v2->bUseBigBuffer == 0;
Ritor1
parents:
diff changeset
277 v2->uNumBuffersUsed = v6 + 1;
Ritor1
parents:
diff changeset
278 if ( !v8 )
Ritor1
parents:
diff changeset
279 v2->uNextFreeOffsetInBigBuffer = (char *)v2->pMemoryBuffers[v6]
Ritor1
parents:
diff changeset
280 + v2->uMemoryBuffersSizes[v6]
Ritor1
parents:
diff changeset
281 - v2->pBigMemoryBuffer;
Ritor1
parents:
diff changeset
282 }
Ritor1
parents:
diff changeset
283 else
Ritor1
parents:
diff changeset
284 {
Ritor1
parents:
diff changeset
285 v2->uNextFreeOffsetInBigBuffer = 0;
Ritor1
parents:
diff changeset
286 v2->uNumBuffersUsed = 0;
Ritor1
parents:
diff changeset
287 }
Ritor1
parents:
diff changeset
288 }
363
2bc1c8d68f41 Allocator and SpellCost Tip
Gloval
parents: 0
diff changeset
289 }*/
0
Ritor1
parents:
diff changeset
290 }
Ritor1
parents:
diff changeset
291 // 720018: using guessed type int aborting_app;
Ritor1
parents:
diff changeset
292
Ritor1
parents:
diff changeset
293
Ritor1
parents:
diff changeset
294
Ritor1
parents:
diff changeset
295 //----- (00426429) --------------------------------------------------------
Ritor1
parents:
diff changeset
296 Allocator::Allocator()
Ritor1
parents:
diff changeset
297 {
Ritor1
parents:
diff changeset
298 Allocator *v1; // eax@1
Ritor1
parents:
diff changeset
299 signed int v2; // ecx@1
Ritor1
parents:
diff changeset
300 int v3; // edx@1
Ritor1
parents:
diff changeset
301
Ritor1
parents:
diff changeset
302 v1 = this;
Ritor1
parents:
diff changeset
303 v2 = 0;
Ritor1
parents:
diff changeset
304 v1->uBigBufferSizeAligned = 0;
Ritor1
parents:
diff changeset
305 v1->bBigBufferAllocated = 0;
Ritor1
parents:
diff changeset
306 v3 = (int)v1->pMemoryBuffersNames;
Ritor1
parents:
diff changeset
307 do
Ritor1
parents:
diff changeset
308 {
Ritor1
parents:
diff changeset
309 v1->pMemoryBuffers[v2] = 0;
Ritor1
parents:
diff changeset
310 v1->uMemoryBuffersSizes[v2] = 0;
Ritor1
parents:
diff changeset
311 *(char *)v3 = 0;
Ritor1
parents:
diff changeset
312 ++v2;
Ritor1
parents:
diff changeset
313 v3 += 12;
Ritor1
parents:
diff changeset
314 }
Ritor1
parents:
diff changeset
315 while ( v2 < 6000 );
Ritor1
parents:
diff changeset
316 v1->uDumpsCount = 0;
Ritor1
parents:
diff changeset
317 }
Ritor1
parents:
diff changeset
318
Ritor1
parents:
diff changeset
319
Ritor1
parents:
diff changeset
320 //----- (0042654C) --------------------------------------------------------
Ritor1
parents:
diff changeset
321 bool Allocator::CreateFileDump(const char *a1)
Ritor1
parents:
diff changeset
322 {
Ritor1
parents:
diff changeset
323 Allocator *v2; // esi@1
Ritor1
parents:
diff changeset
324 unsigned int v3; // ST44_4@1
Ritor1
parents:
diff changeset
325 FILE *v4; // eax@1
Ritor1
parents:
diff changeset
326 FILE *v5; // edi@1
Ritor1
parents:
diff changeset
327 bool result; // eax@2
Ritor1
parents:
diff changeset
328 unsigned int v7; // ecx@5
Ritor1
parents:
diff changeset
329 int v8; // edx@5
Ritor1
parents:
diff changeset
330 int v9; // eax@6
Ritor1
parents:
diff changeset
331 int v10; // eax@8
Ritor1
parents:
diff changeset
332 int v11; // ecx@8
Ritor1
parents:
diff changeset
333 signed int v12; // ebx@8
Ritor1
parents:
diff changeset
334 signed int v13; // ebx@10
Ritor1
parents:
diff changeset
335 struct _MEMORYSTATUS memstat; // [sp+8h] [bp-38h]@5
Ritor1
parents:
diff changeset
336 char Filename[20]; // [sp+28h] [bp-18h]@1
Ritor1
parents:
diff changeset
337 unsigned int *v16; // [sp+3Ch] [bp-4h]@11
Ritor1
parents:
diff changeset
338 int a1a; // [sp+48h] [bp+8h]@11
Ritor1
parents:
diff changeset
339
Ritor1
parents:
diff changeset
340 v2 = this;
Ritor1
parents:
diff changeset
341 v3 = this->uDumpsCount;
Ritor1
parents:
diff changeset
342 this->uDumpsCount = v3 + 1;
Ritor1
parents:
diff changeset
343 sprintf(Filename, "Mem%03i.txt", v3);
Ritor1
parents:
diff changeset
344 v4 = fopen(Filename, "w");
Ritor1
parents:
diff changeset
345 v5 = v4;
Ritor1
parents:
diff changeset
346 if ( v4 )
Ritor1
parents:
diff changeset
347 {
Ritor1
parents:
diff changeset
348 if ( a1 )
Ritor1
parents:
diff changeset
349 fprintf(v4, "%s\n\n", a1);
Ritor1
parents:
diff changeset
350 fprintf(v5, "Windows Memory Status");
Ritor1
parents:
diff changeset
351 GlobalMemoryStatus(&memstat);
Ritor1
parents:
diff changeset
352 fprintf(v5, "dwLength: %d\n\n", memstat.dwLength);
Ritor1
parents:
diff changeset
353 fprintf(v5, "dwMemoryLoad: %d\n", memstat.dwMemoryLoad);
Ritor1
parents:
diff changeset
354 fprintf(v5, "dwTotalPhys: %d\n", memstat.dwTotalPhys);
Ritor1
parents:
diff changeset
355 fprintf(v5, "dwAvailPhys: %d\n", memstat.dwAvailPhys);
Ritor1
parents:
diff changeset
356 fprintf(v5, "dwTotalPageFile: %d\n", memstat.dwTotalPageFile);
Ritor1
parents:
diff changeset
357 fprintf(v5, "dwAvailPageFile: %d\n", memstat.dwAvailPageFile);
Ritor1
parents:
diff changeset
358 fprintf(v5, "dwTotalVirtual: %d\n", memstat.dwTotalVirtual);
Ritor1
parents:
diff changeset
359 fprintf(v5, "dwAvailVirtual: %d\n\n\n", memstat.dwAvailVirtual);
Ritor1
parents:
diff changeset
360 v7 = v2->uNumBuffersUsed;
Ritor1
parents:
diff changeset
361 v8 = 0;
Ritor1
parents:
diff changeset
362 if ( (signed int)v7 > 0 )
Ritor1
parents:
diff changeset
363 {
Ritor1
parents:
diff changeset
364 v9 = (int)v2->uMemoryBuffersSizes;
Ritor1
parents:
diff changeset
365 do
Ritor1
parents:
diff changeset
366 {
Ritor1
parents:
diff changeset
367 v8 += *(int *)v9;
Ritor1
parents:
diff changeset
368 v9 += 4;
Ritor1
parents:
diff changeset
369 --v7;
Ritor1
parents:
diff changeset
370 }
Ritor1
parents:
diff changeset
371 while ( v7 );
Ritor1
parents:
diff changeset
372 }
Ritor1
parents:
diff changeset
373 v10 = 0;
Ritor1
parents:
diff changeset
374 v11 = (int)v2->uMemoryBuffersSizes;
Ritor1
parents:
diff changeset
375 v12 = 6000;
Ritor1
parents:
diff changeset
376 do
Ritor1
parents:
diff changeset
377 {
Ritor1
parents:
diff changeset
378 v10 += *(int *)v11;
Ritor1
parents:
diff changeset
379 v11 += 4;
Ritor1
parents:
diff changeset
380 --v12;
Ritor1
parents:
diff changeset
381 }
Ritor1
parents:
diff changeset
382 while ( v12 );
Ritor1
parents:
diff changeset
383 fprintf(v5, "Size: %i %i %i\n\n", v2->uNumBuffersUsed, v8, v10);
Ritor1
parents:
diff changeset
384 v13 = 0;
Ritor1
parents:
diff changeset
385 if ( (signed int)v2->uNumBuffersUsed > 0 )
Ritor1
parents:
diff changeset
386 {
Ritor1
parents:
diff changeset
387 v16 = v2->uMemoryBuffersSizes;
Ritor1
parents:
diff changeset
388 a1a = (int)v2->pMemoryBuffersNames;
Ritor1
parents:
diff changeset
389 do
Ritor1
parents:
diff changeset
390 {
Ritor1
parents:
diff changeset
391 fprintf(v5, "%10i %10i %s\n", v13, *v16, a1a);
Ritor1
parents:
diff changeset
392 a1a += 12;
Ritor1
parents:
diff changeset
393 ++v16;
Ritor1
parents:
diff changeset
394 ++v13;
Ritor1
parents:
diff changeset
395 }
Ritor1
parents:
diff changeset
396 while ( v13 < (signed int)v2->uNumBuffersUsed );
Ritor1
parents:
diff changeset
397 }
Ritor1
parents:
diff changeset
398 fclose(v5);
Ritor1
parents:
diff changeset
399 result = 0;
Ritor1
parents:
diff changeset
400 }
Ritor1
parents:
diff changeset
401 else
Ritor1
parents:
diff changeset
402 {
Ritor1
parents:
diff changeset
403 result = 1;
Ritor1
parents:
diff changeset
404 }
Ritor1
parents:
diff changeset
405 return result;
Ritor1
parents:
diff changeset
406 }
Ritor1
parents:
diff changeset
407
Ritor1
parents:
diff changeset
408
Ritor1
parents:
diff changeset
409
Ritor1
parents:
diff changeset
410
Ritor1
parents:
diff changeset
411
Ritor1
parents:
diff changeset
412
Ritor1
parents:
diff changeset
413
Ritor1
parents:
diff changeset
414
Ritor1
parents:
diff changeset
415 //----- (00426892) --------------------------------------------------------
Ritor1
parents:
diff changeset
416 static void __fastcall CheckMemoryAccessibility(void *pBase, DWORD uSize)
Ritor1
parents:
diff changeset
417 {
Ritor1
parents:
diff changeset
418 DWORD v2; // edi@1
Ritor1
parents:
diff changeset
419 DWORD i; // eax@1
Ritor1
parents:
diff changeset
420 struct _SYSTEM_INFO SystemInfo; // [sp+8h] [bp-24h]@1
Ritor1
parents:
diff changeset
421
Ritor1
parents:
diff changeset
422 v2 = uSize;
Ritor1
parents:
diff changeset
423 GetSystemInfo(&SystemInfo);
Ritor1
parents:
diff changeset
424 for ( i = 16 * SystemInfo.dwPageSize; i < v2; i += SystemInfo.dwPageSize )
Ritor1
parents:
diff changeset
425 ;
Ritor1
parents:
diff changeset
426 }