Rev 517 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
589 | diamond | 1 | CHECK_FOR_LEAKS = 0 |
2 | if CHECK_FOR_LEAKS |
||
3 | uglobal |
||
4 | allocatedregions rd 1024 |
||
5 | endg |
||
6 | iglobal |
||
7 | numallocatedregions dd 0 |
||
8 | endg |
||
9 | end if |
||
474 | diamond | 10 | pgalloc: |
11 | ; in: ecx=size |
||
314 | diamond | 12 | ; out: eax=pointer or NULL |
474 | diamond | 13 | push ebx |
14 | push 68 |
||
15 | pop eax |
||
16 | push 12 |
||
17 | pop ebx |
||
517 | diamond | 18 | int 0x40 |
589 | diamond | 19 | if CHECK_FOR_LEAKS |
20 | test eax, eax |
||
21 | jz .no |
||
22 | .b: |
||
23 | mov ebx, [numallocatedregions] |
||
24 | cmp ebx, 1024 |
||
25 | jb @f |
||
26 | int3 |
||
27 | jmp $ |
||
28 | @@: |
||
29 | mov [allocatedregions+ebx*4], eax |
||
30 | inc [numallocatedregions] |
||
31 | .no: |
||
32 | end if |
||
474 | diamond | 33 | pop ebx |
34 | ret |
||
35 | |||
36 | pgfree: |
||
37 | ; in: ecx=pointer |
||
38 | ; destroys eax |
||
589 | diamond | 39 | if CHECK_FOR_LEAKS |
40 | jecxz .no |
||
41 | mov eax, [numallocatedregions] |
||
42 | @@: |
||
43 | dec eax |
||
44 | js .a |
||
45 | cmp [allocatedregions+eax*4], ecx |
||
46 | jnz @b |
||
47 | jmp @f |
||
48 | .a: |
||
49 | int3 |
||
50 | jmp $ |
||
51 | @@: |
||
52 | dec [numallocatedregions] |
||
53 | @@: |
||
54 | cmp eax, [numallocatedregions] |
||
55 | jae @f |
||
56 | push [allocatedregions+eax*4+4] |
||
57 | pop [allocatedregions+eax*4] |
||
58 | inc eax |
||
59 | jmp @b |
||
60 | @@: |
||
61 | .no: |
||
62 | end if |
||
474 | diamond | 63 | push ebx |
64 | push 68 |
||
65 | pop eax |
||
66 | push 13 |
||
67 | pop ebx |
||
517 | diamond | 68 | int 0x40 |
474 | diamond | 69 | pop ebx |
70 | ret |
||
71 | |||
72 | pgrealloc: |
||
73 | ; in: ecx=size, edx=pointer |
||
74 | ; out: eax=pointer |
||
75 | push ebx |
||
76 | push 68 |
||
77 | pop eax |
||
78 | push 20 |
||
79 | pop ebx |
||
517 | diamond | 80 | int 0x40 |
589 | diamond | 81 | if CHECK_FOR_LEAKS |
82 | test edx, edx |
||
83 | jz pgalloc.b |
||
84 | test eax, eax |
||
85 | jz .no |
||
86 | cmp eax, edx |
||
87 | jz .no |
||
88 | xor ebx, ebx |
||
89 | @@: |
||
90 | cmp ebx, [numallocatedregions] |
||
91 | jae .a |
||
92 | cmp [allocatedregions+ebx*4], edx |
||
93 | jz @f |
||
94 | inc ebx |
||
95 | jmp @b |
||
96 | @@: |
||
97 | mov [allocatedregions+ebx*4], eax |
||
98 | jmp .no |
||
99 | .a: |
||
100 | int3 |
||
101 | jmp $ |
||
102 | .no: |
||
103 | end if |
||
474 | diamond | 104 | pop ebx |
105 | ret |
||
106 | |||
107 | xpgalloc: |
||
108 | ; in: ecx=size |
||
109 | ; out: eax=pointer or NULL |
||
110 | call pgalloc |
||
314 | diamond | 111 | .common: |
112 | test eax, eax |
||
113 | jnz @f |
||
114 | call SayNoMem |
||
115 | xor eax, eax |
||
116 | @@: |
||
117 | ret |
||
118 | |||
474 | diamond | 119 | xpgrealloc: |
120 | ; in: edx=pointer, ecx=new size |
||
314 | diamond | 121 | ; out: eax=pointer or NULL |
474 | diamond | 122 | call pgrealloc |
123 | jmp xpgalloc.common |
||
314 | diamond | 124 | |
589 | diamond | 125 | getfreemem: |
126 | ; out: eax=size of free RAM in Kb |
||
127 | push ebx |
||
128 | push 18 |
||
129 | pop eax |
||
130 | push 16 |
||
131 | pop ebx |
||
132 | int 0x40 |
||
133 | pop ebx |
||
134 | ret |
||
135 | |||
314 | diamond | 136 | get_error_msg: |
137 | ; in: eax=error code |
||
138 | ; out: eax=pointer to message (in static buffer) |
||
139 | push esi edi |
||
140 | mov edi, error_msg |
||
141 | cmp eax, 11 |
||
142 | ja .no1 |
||
143 | mov esi, [errors1+eax*4] |
||
144 | jmp .copy |
||
145 | .no1: |
||
146 | cmp eax, 30 |
||
147 | jb .no2 |
||
148 | cmp eax, 32 |
||
149 | ja .no2 |
||
150 | mov esi, [errors2+(eax-30)*4] |
||
151 | .copy: |
||
152 | lodsb |
||
153 | stosb |
||
154 | test al, al |
||
155 | jnz .copy |
||
156 | .ret: |
||
157 | mov eax, error_msg |
||
158 | pop edi esi |
||
159 | ret |
||
160 | .no2: |
||
161 | mov esi, aUnknownError |
||
162 | push eax |
||
163 | @@: |
||
164 | lodsb |
||
165 | stosb |
||
166 | test al, al |
||
167 | jnz @b |
||
168 | pop eax |
||
589 | diamond | 169 | dec edi |
314 | diamond | 170 | push edx ecx |
171 | test eax, eax |
||
172 | jns @f |
||
173 | mov byte [edi], '-' |
||
174 | inc edi |
||
175 | neg eax |
||
176 | @@: |
||
177 | xor edx, edx |
||
178 | mov ecx, 10 |
||
179 | div ecx |
||
180 | add edx, '0' |
||
181 | mov byte [edi], dl |
||
182 | inc edi |
||
183 | test eax, eax |
||
184 | jnz @b |
||
185 | pop ecx edx |
||
186 | stosb |
||
187 | jmp .ret |
||
474 | diamond | 188 | |
189 | libini_alloc: |
||
190 | push ecx |
||
191 | mov ecx, [esp+8] |
||
192 | call xpgalloc |
||
193 | pop ecx |
||
194 | ret 4 |
||
195 | libini_free: |
||
196 | push ecx |
||
197 | mov ecx, [esp+8] |
||
198 | call pgfree |
||
199 | pop ecx |
||
200 | ret 4 |
||
201 | libini_realloc: |
||
202 | push ecx edx |
||
203 | mov edx, [esp+8+4] |
||
204 | mov ecx, [esp+8+8] |
||
205 | call xpgrealloc |
||
206 | pop edx ecx |
||
207 | ret 8 |
||
208 | |||
209 | libini_dllload: |
||
210 | push esi |
||
211 | mov esi, [esp+8] |
||
212 | .lib: |
||
213 | lodsd |
||
214 | test eax, eax |
||
215 | jz .ret |
||
216 | push eax |
||
217 | lodsd |
||
218 | xchg esi, [esp] |
||
219 | xor ebp, ebp ; no version control |
||
220 | call load_dll_and_import |
||
221 | pop esi |
||
222 | test eax, eax |
||
223 | jz .lib |
||
224 | .ret: |
||
225 | pop esi |
||
226 | ret 4 |
||
227 | |||
228 | load_dll_and_import: |
||
229 | cmp byte [eax], '/' |
||
230 | jz .do |
||
231 | push esi |
||
232 | mov edi, saved_file_name |
||
233 | push edi |
||
234 | mov esi, standard_dll_path |
||
235 | mov ecx, standard_dll_path_size |
||
236 | rep movsb |
||
237 | mov esi, eax |
||
238 | mov ecx, 1024-standard_dll_path_size |
||
239 | @@: |
||
240 | lodsb |
||
241 | stosb |
||
242 | test al, al |
||
243 | loopnz @b |
||
244 | pop eax |
||
245 | pop esi |
||
246 | jz .do |
||
589 | diamond | 247 | .big: |
248 | push esi |
||
474 | diamond | 249 | mov edi, aFileNameTooBig |
250 | .sayerr: |
||
251 | push dword aCannotLoadDLL |
||
252 | push edi |
||
253 | mov eax, esp |
||
254 | push dword aOk |
||
255 | push esp |
||
256 | push 1 |
||
257 | push eax |
||
258 | push 3 |
||
259 | call SayErr |
||
260 | add esp, 16 |
||
261 | xor eax, eax |
||
262 | inc eax |
||
263 | ret |
||
264 | .do: |
||
265 | push eax |
||
266 | mov ecx, eax |
||
267 | push 68 |
||
268 | pop eax |
||
269 | push 19 |
||
270 | pop ebx |
||
517 | diamond | 271 | int 0x40 |
474 | diamond | 272 | mov edi, aInvalidDLL |
273 | test eax, eax |
||
274 | jz .sayerr |
||
589 | diamond | 275 | mov edx, eax |
276 | cmp ebp, -1 |
||
277 | jnz @f |
||
278 | pop eax |
||
279 | xor eax, eax |
||
280 | ret |
||
281 | @@: |
||
474 | diamond | 282 | ; initialize import |
283 | mov edi, aMissingExport |
||
284 | .import_loop: |
||
285 | lodsd |
||
286 | test eax, eax |
||
287 | jz .import_done |
||
288 | call .find_exported_function |
||
289 | jc .sayerr |
||
290 | mov [esi-4], eax |
||
291 | jmp .import_loop |
||
292 | .import_done: |
||
293 | ; check version |
||
294 | test ebp, ebp |
||
295 | jz .version_ok |
||
296 | mov edi, aIncompatibleVersion |
||
297 | mov eax, aVersion |
||
298 | call .find_exported_function |
||
299 | jc .sayerr |
||
300 | cmp ax, bp |
||
301 | jb .sayerr |
||
302 | shr eax, 16 |
||
303 | cmp eax, ebp |
||
304 | ja .sayerr |
||
305 | .version_ok: |
||
306 | ; initialize library |
||
307 | mov eax, aStart |
||
308 | call .find_exported_function |
||
309 | jc @f |
||
310 | push 1 ; DLL_ENTRY |
||
311 | call eax |
||
312 | .ret0: |
||
313 | pop eax |
||
314 | xor eax, eax |
||
315 | ret |
||
316 | @@: |
||
317 | mov eax, aLibInit |
||
318 | call .find_exported_function |
||
319 | jc .ret0 |
||
320 | mov esi, eax |
||
321 | mov eax, libini_alloc |
||
322 | mov ebx, libini_free |
||
323 | mov ecx, libini_realloc |
||
324 | mov edx, libini_dllload |
||
325 | call esi |
||
326 | mov edi, aInitFailed |
||
327 | test eax, eax |
||
328 | jnz .sayerr |
||
329 | jmp .ret0 |
||
330 | |||
331 | .find_exported_function: |
||
332 | push edx |
||
333 | .import_loop_i: |
||
334 | mov ebx, [edx] |
||
335 | test ebx, ebx |
||
336 | jz .import_notfound |
||
337 | push eax |
||
338 | @@: |
||
339 | mov cl, [eax] |
||
340 | cmp cl, [ebx] |
||
341 | jnz .import_find_next |
||
342 | test cl, cl |
||
343 | jz .import_found |
||
344 | inc eax |
||
345 | inc ebx |
||
346 | jmp @b |
||
347 | .import_find_next: |
||
348 | pop eax |
||
349 | add edx, 8 |
||
350 | jmp .import_loop_i |
||
351 | .import_found: |
||
352 | pop eax |
||
353 | mov eax, [edx+4] |
||
354 | pop edx |
||
355 | ret |
||
356 | .import_notfound: |
||
357 | pop edx |
||
358 | stc |
||
359 | ret |