fixed bug in dll.inc (net branch)

git-svn-id: svn://kolibrios.org@2604 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-04-12 14:47:26 +00:00
parent f10b2375d4
commit 705460f746

View File

@ -1,155 +1,158 @@
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
proc mem.Alloc size ;///////////////////////////////////////////////////////// proc mem.Alloc size ;/////////////////////////////////////////////////////////
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
push ebx ecx push ebx ecx
mov eax,[size] mov eax,[size]
lea ecx,[eax+4+4095] lea ecx,[eax+4+4095]
and ecx,not 4095 and ecx, not 4095
mcall 68,12 mcall 68,12
add ecx,-4 test eax, eax
mov [eax],ecx jz @f
add eax,4 add ecx,-4
pop ecx ebx mov [eax],ecx
ret add eax,4
@@:
pop ecx ebx
ret
endp endp
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
proc mem.ReAlloc mptr,size;/////////////////////////////////////////////////// proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
push ebx ecx esi edi eax push ebx ecx esi edi eax
mov eax,[mptr] mov eax,[mptr]
mov ebx,[size] mov ebx,[size]
or eax,eax or eax,eax
jz @f jz @f
lea ecx,[ebx+4+4095] lea ecx,[ebx+4+4095]
and ecx,not 4095 and ecx,not 4095
add ecx,-4 add ecx,-4
cmp ecx,[eax-4] cmp ecx,[eax-4]
je .exit je .exit
@@: mov eax,ebx @@: mov eax,ebx
call mem.Alloc call mem.Alloc
xchg eax,[esp] xchg eax,[esp]
or eax,eax or eax,eax
jz .exit jz .exit
mov esi,eax mov esi,eax
xchg eax,[esp] xchg eax,[esp]
mov edi,eax mov edi,eax
mov ecx,[esi-4] mov ecx,[esi-4]
cmp ecx,[edi-4] cmp ecx,[edi-4]
jbe @f jbe @f
mov ecx,[edi-4] mov ecx,[edi-4]
@@: add ecx,3 @@: add ecx,3
shr ecx,2 shr ecx,2
cld cld
rep movsd rep movsd
xchg eax,[esp] xchg eax,[esp]
call mem.Free call mem.Free
.exit: .exit:
pop eax edi esi ecx ebx pop eax edi esi ecx ebx
ret ret
endp endp
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
proc mem.Free mptr ;////////////////////////////////////////////////////////// proc mem.Free mptr ;//////////////////////////////////////////////////////////
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
mov eax,[mptr] mov eax,[mptr]
or eax,eax or eax,eax
jz @f jz @f
push ebx ecx push ebx ecx
lea ecx,[eax-4] lea ecx,[eax-4]
mcall 68,13 mcall 68,13
pop ecx ebx pop ecx ebx
@@: ret @@: ret
endp endp
proc dll.Load, import_table:dword proc dll.Load, import_table:dword
mov esi,[import_table] mov esi,[import_table]
.next_lib: mov edx,[esi] .next_lib: mov edx,[esi]
or edx,edx or edx,edx
jz .exit jz .exit
push esi push esi
mov esi,[esi+4] mov esi,[esi+4]
mov edi,s_libdir.fname mov edi,s_libdir.fname
@@: lodsb @@: lodsb
stosb stosb
or al,al or al,al
jnz @b jnz @b
mcall 68,19,s_libdir mcall 68,19,s_libdir
or eax,eax or eax,eax
jz .fail jz .fail
stdcall dll.Link,eax,edx stdcall dll.Link,eax,edx
stdcall dll.Init,[eax+4] stdcall dll.Init,[eax+4]
pop esi pop esi
add esi,8 add esi,8
jmp .next_lib jmp .next_lib
.exit: xor eax,eax .exit: xor eax,eax
ret ret
.fail: add esp,4 .fail: add esp,4
xor eax,eax xor eax,eax
inc eax inc eax
ret ret
endp endp
proc dll.Link, exp:dword,imp:dword proc dll.Link, exp:dword,imp:dword
push eax push eax
mov esi,[imp] mov esi,[imp]
test esi,esi test esi,esi
jz .done jz .done
.next: lodsd .next: lodsd
test eax,eax test eax,eax
jz .done jz .done
stdcall dll.GetProcAddress,[exp],eax stdcall dll.GetProcAddress,[exp],eax
or eax,eax or eax,eax
jz @f jz @f
mov [esi-4],eax mov [esi-4],eax
jmp .next jmp .next
@@: mov dword[esp],0 @@: mov dword[esp],0
.done: pop eax .done: pop eax
ret ret
endp endp
proc dll.Init, dllentry:dword proc dll.Init, dllentry:dword
pushad pushad
mov eax,mem.Alloc mov eax,mem.Alloc
mov ebx,mem.Free mov ebx,mem.Free
mov ecx,mem.ReAlloc mov ecx,mem.ReAlloc
mov edx,dll.Load mov edx,dll.Load
stdcall [dllentry] stdcall [dllentry]
popad popad
ret ret
endp endp
proc dll.GetProcAddress, exp:dword,sz_name:dword proc dll.GetProcAddress, exp:dword,sz_name:dword
mov edx,[exp] mov edx,[exp]
xor eax,eax xor eax,eax
.next: or edx,edx .next: or edx,edx
jz .end jz .end
cmp dword[edx],0 cmp dword[edx],0
jz .end jz .end
stdcall strcmp,[edx],[sz_name] stdcall strcmp,[edx],[sz_name]
test eax,eax test eax,eax
jz .ok jz .ok
add edx,8 add edx,8
jmp .next jmp .next
.ok: mov eax,[edx+4] .ok: mov eax,[edx+4]
.end: ret .end: ret
endp endp
proc strcmp, str1:dword,str2:dword proc strcmp, str1:dword,str2:dword
push esi edi push esi edi
mov esi,[str1] mov esi,[str1]
mov edi,[str2] mov edi,[str2]
xor eax,eax xor eax,eax
@@: lodsb @@: lodsb
scasb scasb
jne .fail jne .fail
or al,al or al,al
jnz @b jnz @b
jmp .ok jmp .ok
.fail: or eax,-1 .fail: or eax,-1
.ok: pop edi esi .ok: pop edi esi
ret ret
endp endp
s_libdir: s_libdir: