annotate Allocator.cpp @ 1017:af20650a052f

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