kernel.load_file_umode: allocate physical storage before unpacking
git-svn-id: svn://kolibrios.org@4237 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
89e5a3c15c
commit
145adf316e
|
@ -544,7 +544,6 @@ proc load_file_umode stdcall, file_name:dword
|
|||
push edi
|
||||
push ebx
|
||||
|
||||
|
||||
lea eax, [attr]
|
||||
stdcall get_fileinfo, [file_name], eax ;find file and get info
|
||||
test eax, eax
|
||||
|
@ -570,11 +569,26 @@ proc load_file_umode stdcall, file_name:dword
|
|||
|
||||
mov ebx, [eax+4] ;get real size of file
|
||||
mov [file_size], ebx
|
||||
stdcall user_alloc, ebx ;and allocate memory from user heap
|
||||
stdcall user_alloc, ebx ;and allocate space from user heap
|
||||
mov [um_file], eax
|
||||
test eax, eax
|
||||
jz .err_2
|
||||
|
||||
mov edx, [file_size] ;preallocate page memory
|
||||
shr eax, 10
|
||||
lea edi, [page_tabs+eax]
|
||||
add edx, 4095
|
||||
shr edx, 12
|
||||
@@:
|
||||
call alloc_page
|
||||
test eax, eax
|
||||
jz .err_3
|
||||
|
||||
or eax, PG_UW
|
||||
stosd
|
||||
dec edx
|
||||
jnz @B
|
||||
|
||||
pushad
|
||||
mov ecx, unpack_mutex
|
||||
call mutex_lock
|
||||
|
@ -587,15 +601,28 @@ proc load_file_umode stdcall, file_name:dword
|
|||
|
||||
stdcall kernel_free, [km_file] ;we don't need packed file anymore
|
||||
.exit:
|
||||
|
||||
mov edi, [um_file]
|
||||
mov esi, [um_file]
|
||||
mov eax, [file_size]
|
||||
mov edx, eax
|
||||
|
||||
add edi, eax ;cleanup remain space
|
||||
mov ecx, 4096 ;from file end
|
||||
and eax, 4095
|
||||
jz @f
|
||||
sub ecx, eax
|
||||
xor eax, eax
|
||||
cld
|
||||
rep stosb
|
||||
@@:
|
||||
mov eax, [um_file]
|
||||
mov edx, [file_size]
|
||||
|
||||
pop ebx
|
||||
pop edi
|
||||
pop esi
|
||||
ret
|
||||
|
||||
|
||||
.raw_file: ; sometimes we load unpacked file
|
||||
stdcall user_alloc, ebx ; allocate space from user heap
|
||||
mov [um_file], eax
|
||||
|
@ -619,13 +646,14 @@ proc load_file_umode stdcall, file_name:dword
|
|||
@@:
|
||||
lodsd
|
||||
and eax, 0xFFFFF000
|
||||
or eax, PG_USER
|
||||
or eax, PG_UW
|
||||
stosd
|
||||
loop @B
|
||||
|
||||
stdcall free_kernel_space, [km_file] ; release allocated kernel space
|
||||
jmp .exit ; physical pages still in use
|
||||
|
||||
.err_3:
|
||||
stdcall user_free, [um_file]
|
||||
.err_2:
|
||||
stdcall kernel_free, [km_file]
|
||||
.err_1:
|
||||
|
|
Loading…
Reference in New Issue