annotate Allocator.cpp @ 1177:ce5ff6d32200

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