* Fixed memory leak in new_mem_resize (caused by off-by-one error).

* user_alloc and user_free now update memory size information.

git-svn-id: svn://kolibrios.org@294 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2007-01-25 13:42:23 +00:00
parent 73aa6c6d6a
commit 3f37e88368
2 changed files with 53 additions and 32 deletions

View File

@ -613,6 +613,7 @@ proc init_heap
mov esi, [PROC_BASE+APPDATA.mem_size+ebx] mov esi, [PROC_BASE+APPDATA.mem_size+ebx]
add esi, 4095 add esi, 4095
and esi, not 4095 and esi, not 4095
mov [PROC_BASE+APPDATA.mem_size+ebx], esi
mov eax, HEAP_TOP mov eax, HEAP_TOP
mov [PROC_BASE+APPDATA.heap_base+ebx], esi mov [PROC_BASE+APPDATA.heap_base+ebx], esi
mov [PROC_BASE+APPDATA.heap_top+ebx], eax mov [PROC_BASE+APPDATA.heap_top+ebx], eax
@ -664,7 +665,7 @@ l_0:
shr edx, 12 shr edx, 12
mov [pages_tab+edx*4], eax mov [pages_tab+edx*4], eax
@@: @@:
or ecx, USED_BLOCK or ecx, USED_BLOCK
mov [pages_tab+ebx*4], ecx mov [pages_tab+ebx*4], ecx
shr ecx, 12 shr ecx, 12
@ -676,6 +677,14 @@ l_0:
dec ecx dec ecx
jnz @B jnz @B
mov edx, [CURRENT_TASK]
shl edx, 8
mov ebx, [alloc_size]
add ebx, 0xFFF
and ebx, not 0xFFF
add ebx, [PROC_BASE+APPDATA.mem_size+edx]
call update_mem_size
mov eax, esi mov eax, esi
add eax, 4096 add eax, 4096
sub eax, new_app_base sub eax, new_app_base
@ -702,6 +711,7 @@ proc user_free stdcall, base:dword
test esi, esi test esi, esi
jz .exit jz .exit
xor ebx, ebx
sub esi, 4096 sub esi, 4096
shr esi, 12 shr esi, 12
mov eax, [pages_tab+esi*4] mov eax, [pages_tab+esi*4]
@ -715,6 +725,7 @@ proc user_free stdcall, base:dword
inc esi inc esi
sub ecx, 4096 sub ecx, 4096
shr ecx, 12 shr ecx, 12
mov ebx, ecx
.release: .release:
xor eax, eax xor eax, eax
xchg eax, [pages_tab+esi*4] xchg eax, [pages_tab+esi*4]
@ -726,10 +737,13 @@ proc user_free stdcall, base:dword
dec ecx dec ecx
jnz .release jnz .release
.not_used: .not_used:
mov ebx, [CURRENT_TASK] mov edx, [CURRENT_TASK]
shl ebx, 8 shl edx, 8
mov esi, dword [ebx+PROC_BASE+APPDATA.heap_base]; heap_base mov esi, dword [edx+PROC_BASE+APPDATA.heap_base]; heap_base
mov edi, dword [ebx+PROC_BASE+APPDATA.heap_top]; heap_top mov edi, dword [edx+PROC_BASE+APPDATA.heap_top]; heap_top
sub ebx, [edx+PROC_BASE+APPDATA.mem_size]
neg ebx
call update_mem_size
add esi, new_app_base add esi, new_app_base
add edi, new_app_base add edi, new_app_base
shr esi, 12 shr esi, 12

View File

@ -475,33 +475,9 @@ proc new_mem_resize stdcall, new_size:dword
jb @B jb @B
.update_size: .update_size:
mov ebx, [new_size]
call update_mem_size
mov ebx, [new_size]
mov [PROC_BASE+0x8c+edx],ebx
;search threads and update
;application memory size infomation
mov ecx,[PROC_BASE+0xb8+edx]
mov eax,2
.search_threads:
;eax = current slot
;ebx = new memory size
;ecx = page directory
cmp eax,[TASK_COUNT]
jg .search_threads_end
mov edx,eax
shl edx,5
cmp word [CURRENT_TASK+edx+0xa],9 ;if slot empty?
jz .search_threads_next
shl edx,3
cmp [PROC_BASE+edx+0xb8],ecx ;if it is our thread?
jnz .search_threads_next
mov [PROC_BASE+edx+0x8c],ebx ;update memory size
.search_threads_next:
inc eax
jmp .search_threads
.search_threads_end:
xor eax, eax xor eax, eax
dec [pg_data.pg_mutex] dec [pg_data.pg_mutex]
ret ret
@ -561,7 +537,7 @@ proc new_mem_resize stdcall, new_size:dword
add esi, 0x1000 add esi, 0x1000
cmp esi, edi cmp esi, edi
jna @B jb @B
jmp .update_size jmp .update_size
.exit: .exit:
@ -571,6 +547,37 @@ proc new_mem_resize stdcall, new_size:dword
ret ret
endp endp
update_mem_size:
; in: edx = slot shl 8
; ebx = new memory size
; destroys eax,ecx,edx
mov [PROC_BASE+APPDATA.mem_size+edx],ebx
;search threads and update
;application memory size infomation
mov ecx,[PROC_BASE+APPDATA.dir_table+edx]
mov eax,2
.search_threads:
;eax = current slot
;ebx = new memory size
;ecx = page directory
cmp eax,[TASK_COUNT]
jg .search_threads_end
mov edx,eax
shl edx,5
cmp word [CURRENT_TASK+edx+TASKDATA.state],9 ;if slot empty?
jz .search_threads_next
shl edx,3
cmp [PROC_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread?
jnz .search_threads_next
mov [PROC_BASE+edx+APPDATA.mem_size],ebx ;update memory size
.search_threads_next:
inc eax
jmp .search_threads
.search_threads_end:
ret
; param ; param
; eax= linear address ; eax= linear address
; ;