Rev 485 | Rev 589 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
474 | diamond | 1 | pgalloc: |
2 | ; in: ecx=size |
||
314 | diamond | 3 | ; out: eax=pointer or NULL |
474 | diamond | 4 | push ebx |
5 | push 68 |
||
6 | pop eax |
||
7 | push 12 |
||
8 | pop ebx |
||
517 | diamond | 9 | int 0x40 |
474 | diamond | 10 | pop ebx |
11 | ret |
||
12 | |||
13 | pgfree: |
||
14 | ; in: ecx=pointer |
||
15 | ; destroys eax |
||
16 | push ebx |
||
17 | push 68 |
||
18 | pop eax |
||
19 | push 13 |
||
20 | pop ebx |
||
517 | diamond | 21 | int 0x40 |
474 | diamond | 22 | pop ebx |
23 | ret |
||
24 | |||
25 | pgrealloc: |
||
26 | ; in: ecx=size, edx=pointer |
||
27 | ; out: eax=pointer |
||
28 | push ebx |
||
29 | push 68 |
||
30 | pop eax |
||
31 | push 20 |
||
32 | pop ebx |
||
517 | diamond | 33 | int 0x40 |
474 | diamond | 34 | pop ebx |
35 | ret |
||
36 | |||
37 | xpgalloc: |
||
38 | ; in: ecx=size |
||
39 | ; out: eax=pointer or NULL |
||
40 | call pgalloc |
||
314 | diamond | 41 | .common: |
42 | test eax, eax |
||
43 | jnz @f |
||
44 | call SayNoMem |
||
45 | xor eax, eax |
||
46 | @@: |
||
47 | ret |
||
48 | |||
474 | diamond | 49 | xpgrealloc: |
50 | ; in: edx=pointer, ecx=new size |
||
314 | diamond | 51 | ; out: eax=pointer or NULL |
474 | diamond | 52 | call pgrealloc |
53 | jmp xpgalloc.common |
||
314 | diamond | 54 | |
55 | get_error_msg: |
||
56 | ; in: eax=error code |
||
57 | ; out: eax=pointer to message (in static buffer) |
||
58 | push esi edi |
||
59 | mov edi, error_msg |
||
60 | cmp eax, 11 |
||
61 | ja .no1 |
||
62 | mov esi, [errors1+eax*4] |
||
63 | jmp .copy |
||
64 | .no1: |
||
65 | cmp eax, 30 |
||
66 | jb .no2 |
||
67 | cmp eax, 32 |
||
68 | ja .no2 |
||
69 | mov esi, [errors2+(eax-30)*4] |
||
70 | .copy: |
||
71 | lodsb |
||
72 | stosb |
||
73 | test al, al |
||
74 | jnz .copy |
||
75 | .ret: |
||
76 | mov eax, error_msg |
||
77 | pop edi esi |
||
78 | ret |
||
79 | .no2: |
||
80 | mov esi, aUnknownError |
||
81 | push eax |
||
82 | @@: |
||
83 | lodsb |
||
84 | stosb |
||
85 | test al, al |
||
86 | jnz @b |
||
87 | pop eax |
||
88 | push edx ecx |
||
89 | test eax, eax |
||
90 | jns @f |
||
91 | mov byte [edi], '-' |
||
92 | inc edi |
||
93 | neg eax |
||
94 | @@: |
||
95 | xor edx, edx |
||
96 | mov ecx, 10 |
||
97 | div ecx |
||
98 | add edx, '0' |
||
99 | mov byte [edi], dl |
||
100 | inc edi |
||
101 | test eax, eax |
||
102 | jnz @b |
||
103 | pop ecx edx |
||
104 | stosb |
||
105 | jmp .ret |
||
474 | diamond | 106 | |
107 | libini_alloc: |
||
108 | push ecx |
||
109 | mov ecx, [esp+8] |
||
110 | call xpgalloc |
||
111 | pop ecx |
||
112 | ret 4 |
||
113 | libini_free: |
||
114 | push ecx |
||
115 | mov ecx, [esp+8] |
||
116 | call pgfree |
||
117 | pop ecx |
||
118 | ret 4 |
||
119 | libini_realloc: |
||
120 | push ecx edx |
||
121 | mov edx, [esp+8+4] |
||
122 | mov ecx, [esp+8+8] |
||
123 | call xpgrealloc |
||
124 | pop edx ecx |
||
125 | ret 8 |
||
126 | |||
127 | libini_dllload: |
||
128 | push esi |
||
129 | mov esi, [esp+8] |
||
130 | .lib: |
||
131 | lodsd |
||
132 | test eax, eax |
||
133 | jz .ret |
||
134 | push eax |
||
135 | lodsd |
||
136 | xchg esi, [esp] |
||
137 | xor ebp, ebp ; no version control |
||
138 | call load_dll_and_import |
||
139 | pop esi |
||
140 | test eax, eax |
||
141 | jz .lib |
||
142 | .ret: |
||
143 | pop esi |
||
144 | ret 4 |
||
145 | |||
146 | load_dll_and_import: |
||
147 | cmp byte [eax], '/' |
||
148 | jz .do |
||
149 | push esi |
||
150 | mov edi, saved_file_name |
||
151 | push edi |
||
152 | mov esi, standard_dll_path |
||
153 | mov ecx, standard_dll_path_size |
||
154 | rep movsb |
||
155 | mov esi, eax |
||
156 | mov ecx, 1024-standard_dll_path_size |
||
157 | @@: |
||
158 | lodsb |
||
159 | stosb |
||
160 | test al, al |
||
161 | loopnz @b |
||
162 | pop eax |
||
163 | pop esi |
||
164 | jz .do |
||
165 | push eax |
||
166 | mov edi, aFileNameTooBig |
||
167 | .sayerr: |
||
168 | push dword aCannotLoadDLL |
||
169 | push edi |
||
170 | mov eax, esp |
||
171 | push dword aOk |
||
172 | push esp |
||
173 | push 1 |
||
174 | push eax |
||
175 | push 3 |
||
176 | push -1 |
||
177 | push -1 |
||
178 | push dword aError |
||
179 | call SayErr |
||
180 | add esp, 16 |
||
181 | xor eax, eax |
||
182 | inc eax |
||
183 | ret |
||
184 | .do: |
||
185 | push eax |
||
186 | mov ecx, eax |
||
187 | push 68 |
||
188 | pop eax |
||
189 | push 19 |
||
190 | pop ebx |
||
517 | diamond | 191 | int 0x40 |
474 | diamond | 192 | mov edi, aInvalidDLL |
193 | test eax, eax |
||
194 | jz .sayerr |
||
195 | ; initialize import |
||
196 | mov edi, aMissingExport |
||
197 | mov edx, eax |
||
198 | .import_loop: |
||
199 | lodsd |
||
200 | test eax, eax |
||
201 | jz .import_done |
||
202 | call .find_exported_function |
||
203 | jc .sayerr |
||
204 | mov [esi-4], eax |
||
205 | jmp .import_loop |
||
206 | .import_done: |
||
207 | ; check version |
||
208 | test ebp, ebp |
||
209 | jz .version_ok |
||
210 | mov edi, aIncompatibleVersion |
||
211 | mov eax, aVersion |
||
212 | call .find_exported_function |
||
213 | jc .sayerr |
||
214 | cmp ax, bp |
||
215 | jb .sayerr |
||
216 | shr eax, 16 |
||
217 | cmp eax, ebp |
||
218 | ja .sayerr |
||
219 | .version_ok: |
||
220 | ; initialize library |
||
221 | mov eax, aStart |
||
222 | call .find_exported_function |
||
223 | jc @f |
||
224 | push 1 ; DLL_ENTRY |
||
225 | call eax |
||
226 | .ret0: |
||
227 | pop eax |
||
228 | xor eax, eax |
||
229 | ret |
||
230 | @@: |
||
231 | mov eax, aLibInit |
||
232 | call .find_exported_function |
||
233 | jc .ret0 |
||
234 | mov esi, eax |
||
235 | mov eax, libini_alloc |
||
236 | mov ebx, libini_free |
||
237 | mov ecx, libini_realloc |
||
238 | mov edx, libini_dllload |
||
239 | call esi |
||
240 | mov edi, aInitFailed |
||
241 | test eax, eax |
||
242 | jnz .sayerr |
||
243 | jmp .ret0 |
||
244 | |||
245 | .find_exported_function: |
||
246 | push edx |
||
247 | .import_loop_i: |
||
248 | mov ebx, [edx] |
||
249 | test ebx, ebx |
||
250 | jz .import_notfound |
||
251 | push eax |
||
252 | @@: |
||
253 | mov cl, [eax] |
||
254 | cmp cl, [ebx] |
||
255 | jnz .import_find_next |
||
256 | test cl, cl |
||
257 | jz .import_found |
||
258 | inc eax |
||
259 | inc ebx |
||
260 | jmp @b |
||
261 | .import_find_next: |
||
262 | pop eax |
||
263 | add edx, 8 |
||
264 | jmp .import_loop_i |
||
265 | .import_found: |
||
266 | pop eax |
||
267 | mov eax, [edx+4] |
||
268 | pop edx |
||
269 | ret |
||
270 | .import_notfound: |
||
271 | pop edx |
||
272 | stc |
||
273 | ret |