rewritten new_mem_resize

git-svn-id: svn://kolibrios.org@2594 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2012-04-09 13:19:32 +00:00
parent d08512f2e7
commit fdbd14a1ca

View File

@ -442,72 +442,82 @@ endp
align 4 align 4
proc new_mem_resize stdcall, new_size:dword proc new_mem_resize stdcall, new_size:dword
mov ecx, pg_data.mutex push ebx
call mutex_lock push esi
push edi
mov edx, [current_slot]
cmp [edx+APPDATA.heap_base], 0
jne .exit
mov edi, [new_size] mov edi, [new_size]
add edi, 4095 add edi, 4095
and edi, not 4095 and edi, not 4095
mov [new_size], edi mov [new_size], edi
mov edx, [current_slot]
cmp [edx+APPDATA.heap_base], 0
jne .exit
mov esi, [edx+APPDATA.mem_size] mov esi, [edx+APPDATA.mem_size]
add esi, 4095 add esi, 4095
and esi, not 4095 and esi, not 4095
cmp edi, esi cmp edi, esi
jae .expand ja .expand
je .exit
mov ebx, edi
shr edi, 12 shr edi, 12
shr esi, 12 shr esi, 12
mov ecx, pg_data.mutex
call mutex_lock
@@: @@:
mov eax, [app_page_tabs+edi*4] mov eax, [app_page_tabs+edi*4]
test eax, 1 test eax, 1
jz .next jz .next
mov dword [app_page_tabs+edi*4], 2
mov ebx, edi mov dword [app_page_tabs+edi*4], 0
shl ebx, 12
push eax
invlpg [ebx] invlpg [ebx]
pop eax
call free_page call free_page
.next: .next:
add edi, 1 inc edi
cmp edi, esi cmp edi, esi
jb @B jb @B
.update_size:
mov ebx, [new_size]
call update_mem_size
mov ecx, pg_data.mutex mov ecx, pg_data.mutex
call mutex_unlock call mutex_unlock
.update_size:
mov edx, [current_slot]
mov ebx, [new_size]
call update_mem_size
.exit:
pop edi
pop esi
pop ebx
xor eax, eax xor eax, eax
ret ret
.expand: .expand:
push esi mov ecx, pg_data.mutex
push edi call mutex_lock
xchg esi, edi
push esi ;new size
push edi ;old size
add edi, 0x3FFFFF add edi, 0x3FFFFF
and edi, not(0x3FFFFF) and edi, not(0x3FFFFF)
add esi, 0x3FFFFF add esi, 0x3FFFFF
and esi, not(0x3FFFFF) and esi, not(0x3FFFFF)
cmp esi, edi cmp edi, esi
jae .grow jae .grow
xchg esi, edi
@@: @@:
call alloc_page call alloc_page
test eax, eax test eax, eax
jz .exit_pop jz .exit_fail
stdcall map_page_table, edi, eax stdcall map_page_table, edi, eax
@ -524,51 +534,38 @@ proc new_mem_resize stdcall, new_size:dword
cmp edi, esi cmp edi, esi
jb @B jb @B
.grow: .grow:
;//- pop edi ;old size
pop edi pop ecx ;new size
push edi
mov esi, [pg_data.pages_free]
sub esi, 1
shr edi, 12
cmp esi, edi
jle .out_of_memory
;//-
pop edi
pop esi
@@:
call alloc_page
test eax, eax
jz .exit
stdcall map_page, esi, eax, dword PG_UW
push edi shr edi, 10
mov edi, esi shr ecx, 10
xor eax, eax sub ecx, edi
mov ecx, 1024 shr ecx, 2 ;pages count
cld mov eax, 2
add edi, app_page_tabs
rep stosd rep stosd
pop edi
add esi, 0x1000
cmp esi, edi
jb @B
jmp .update_size
;//-
.exit_pop:
.out_of_memory:
;//-
pop edi
pop esi
.exit:
mov ecx, pg_data.mutex mov ecx, pg_data.mutex
call mutex_unlock call mutex_unlock
jmp .update_size
.exit_fail:
mov ecx, pg_data.mutex
call mutex_unlock
add esp, 8
pop edi
pop esi
pop ebx
xor eax, eax xor eax, eax
inc eax inc eax
ret ret
endp endp
align 4
update_mem_size: update_mem_size:
; in: edx = slot base ; in: edx = slot base
; ebx = new memory size ; ebx = new memory size