annotate Allocator.cpp @ 1555:9c4cf5b07e98

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