Rev 314 | Rev 517 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 314 | Rev 474 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | xmalloc: |
1 | pgalloc: |
2 | ; in: eax=size |
2 | ; in: ecx=size |
3 | ; out: eax=pointer or NULL |
3 | ; out: eax=pointer or NULL |
- | 4 | push ebx |
|
- | 5 | push 68 |
|
- | 6 | pop eax |
|
- | 7 | push 12 |
|
- | 8 | pop ebx |
|
- | 9 | int 0x40 |
|
- | 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 |
|
- | 21 | int 0x40 |
|
- | 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 |
|
- | 33 | int 0x40 |
|
- | 34 | pop ebx |
|
- | 35 | ret |
|
- | 36 | ||
- | 37 | xpgalloc: |
|
- | 38 | ; in: ecx=size |
|
- | 39 | ; out: eax=pointer or NULL |
|
4 | call mf_alloc |
40 | call pgalloc |
5 | .common: |
41 | .common: |
6 | test eax, eax |
42 | test eax, eax |
7 | jnz @f |
43 | jnz @f |
8 | call SayNoMem |
44 | call SayNoMem |
9 | xor eax, eax |
45 | xor eax, eax |
10 | @@: |
46 | @@: |
11 | ret |
47 | ret |
Line 12... | Line 48... | ||
12 | 48 | ||
13 | xrealloc: |
49 | xpgrealloc: |
14 | ; in: eax=pointer, ebx=new size |
50 | ; in: edx=pointer, ecx=new size |
15 | ; out: eax=pointer or NULL |
51 | ; out: eax=pointer or NULL |
16 | call mf_realloc |
52 | call pgrealloc |
Line 17... | Line 53... | ||
17 | jmp xmalloc.common |
53 | jmp xpgalloc.common |
18 | 54 | ||
19 | get_error_msg: |
55 | get_error_msg: |
20 | ; in: eax=error code |
56 | ; in: eax=error code |
Line 65... | Line 101... | ||
65 | test eax, eax |
101 | test eax, eax |
66 | jnz @b |
102 | jnz @b |
67 | pop ecx edx |
103 | pop ecx edx |
68 | stosb |
104 | stosb |
69 | jmp .ret |
105 | jmp .ret |
- | 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 |
|
- | 191 | int 0x40 |
|
- | 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 |