alignment of sections in COFF libraries is now loaded from header

git-svn-id: svn://kolibrios.org@1296 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2009-11-28 16:13:10 +00:00
parent 71fc5965d7
commit d6647dd32a

View File

@ -1018,6 +1018,29 @@ proc load_driver stdcall, driver_name:dword
ret ret
endp endp
; in: edx -> COFF_SECTION struct
; out: eax = alignment as mask for bits to drop
coff_get_align:
; Rules:
; - if alignment is not given, use default = 4K;
; - if alignment is given and is no more than 4K, use it;
; - if alignment is more than 4K, revert to 4K.
push ecx
mov cl, byte [edx+CFS.Characteristics+2]
mov eax, 1
shr cl, 4
dec cl
js .default
cmp cl, 12
jbe @f
.default:
mov cl, 12
@@:
shl eax, cl
pop ecx
dec eax
ret
align 4 align 4
proc load_library stdcall, file_name:dword proc load_library stdcall, file_name:dword
locals locals
@ -1136,9 +1159,11 @@ proc load_library stdcall, file_name:dword
add edx, 20 add edx, 20
@@: @@:
call coff_get_align
add ebx, eax
not eax
and ebx, eax
add ebx, [edx+CFS.SizeOfRawData] add ebx, [edx+CFS.SizeOfRawData]
add ebx, 15
and ebx, not 15
add edx, COFF_SECTION_SIZE add edx, COFF_SECTION_SIZE
dec ecx dec ecx
jnz @B jnz @B
@ -1172,9 +1197,14 @@ proc load_library stdcall, file_name:dword
movzx ebx, [edx+CFH.nSections] movzx ebx, [edx+CFH.nSections]
mov edi, eax mov edi, eax
add edx, 20 add edx, 20
xor eax, eax
cld cld
@@: @@:
call coff_get_align
add ecx, eax
add edi, eax
not eax
and ecx, eax
and edi, eax
mov [edx+CFS.VirtualAddress], ecx mov [edx+CFS.VirtualAddress], ecx
add ecx, [edx+CFS.SizeOfRawData] add ecx, [edx+CFS.SizeOfRawData]
mov esi, [edx+CFS.PtrRawData] mov esi, [edx+CFS.PtrRawData]
@ -1182,6 +1212,7 @@ proc load_library stdcall, file_name:dword
mov ecx, [edx+CFS.SizeOfRawData] mov ecx, [edx+CFS.SizeOfRawData]
test esi, esi test esi, esi
jnz .copy jnz .copy
xor eax, eax
rep stosb rep stosb
jmp .next jmp .next
.copy: .copy:
@ -1189,10 +1220,6 @@ proc load_library stdcall, file_name:dword
rep movsb rep movsb
.next: .next:
pop ecx pop ecx
add edi, 15 ;-new_app_base
add ecx, 15
and edi, -16
and ecx, -16
add edx, COFF_SECTION_SIZE add edx, COFF_SECTION_SIZE
dec ebx dec ebx
jnz @B jnz @B