forked from KolibriOS/kolibrios
fix double-unlock in free(); make free() always save edi; update test
git-svn-id: svn://kolibrios.org@3126 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
17d524a010
commit
a221c289a3
@ -341,10 +341,9 @@ free:
|
|||||||
; insert_chunk(p,psize);
|
; insert_chunk(p,psize);
|
||||||
|
|
||||||
mov eax, esi
|
mov eax, esi
|
||||||
pop esi
|
|
||||||
mov ecx, edi
|
mov ecx, edi
|
||||||
pop edi
|
call insert_chunk
|
||||||
jmp insert_chunk
|
jmp .fail2
|
||||||
.unl_large:
|
.unl_large:
|
||||||
|
|
||||||
; unlink_large_chunk((tchunkptr)next);
|
; unlink_large_chunk((tchunkptr)next);
|
||||||
@ -364,10 +363,9 @@ free:
|
|||||||
; insert_chunk(p,psize);
|
; insert_chunk(p,psize);
|
||||||
|
|
||||||
mov eax, esi
|
mov eax, esi
|
||||||
pop esi
|
|
||||||
mov ecx, edi
|
mov ecx, edi
|
||||||
pop edi
|
call insert_chunk
|
||||||
jmp insert_chunk
|
jmp .fail2
|
||||||
.fix_next:
|
.fix_next:
|
||||||
|
|
||||||
; (p+psize)->prev_foot = psize;
|
; (p+psize)->prev_foot = psize;
|
||||||
@ -386,10 +384,9 @@ free:
|
|||||||
; insert_chunk(p,psize);
|
; insert_chunk(p,psize);
|
||||||
|
|
||||||
mov eax, esi
|
mov eax, esi
|
||||||
pop esi
|
|
||||||
mov ecx, edi
|
mov ecx, edi
|
||||||
pop edi
|
call insert_chunk
|
||||||
jmp insert_chunk
|
jmp .fail2
|
||||||
|
|
||||||
; param
|
; param
|
||||||
; ecx = chunk
|
; ecx = chunk
|
||||||
@ -418,15 +415,11 @@ insert_chunk:
|
|||||||
mov [esi+8], edx ;P->fd = F
|
mov [esi+8], edx ;P->fd = F
|
||||||
mov [esi+12], eax ;P->bk = B
|
mov [esi+12], eax ;P->bk = B
|
||||||
pop esi
|
pop esi
|
||||||
mov ecx, mst.mutex
|
|
||||||
call mutex_unlock
|
|
||||||
ret
|
ret
|
||||||
.large:
|
.large:
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
call insert_large_chunk
|
call insert_large_chunk
|
||||||
pop esi
|
pop esi
|
||||||
mov ecx, mst.mutex
|
|
||||||
call mutex_unlock
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ run_test2:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
run_test3:
|
run_test3:
|
||||||
; 1024000 times run random operation.
|
; 1024 times run random operation.
|
||||||
; Randomly select malloc(random size from 1 to 1023)
|
; Randomly select malloc(random size from 1 to 1023)
|
||||||
; or free(random of previously allocated areas)
|
; or free(random of previously allocated areas)
|
||||||
mov edi, 0x12345678
|
mov edi, 0x12345678
|
||||||
xor esi, esi ; 0 areas allocated
|
xor esi, esi ; 0 areas allocated
|
||||||
mov ebx, 1024000
|
mov ebx, 1024
|
||||||
.loop:
|
.loop:
|
||||||
imul edi, 1103515245
|
imul edi, 1103515245
|
||||||
add edi, 12345
|
add edi, 12345
|
||||||
@ -78,7 +78,11 @@ run_test3:
|
|||||||
push eax
|
push eax
|
||||||
; mov ecx, [saved_state_num]
|
; mov ecx, [saved_state_num]
|
||||||
; mov [saved_state+ecx*8], eax
|
; mov [saved_state+ecx*8], eax
|
||||||
|
push edi
|
||||||
call malloc_with_test
|
call malloc_with_test
|
||||||
|
pop ecx
|
||||||
|
cmp ecx, edi
|
||||||
|
jnz edi_destroyed
|
||||||
; mov ecx, [saved_state_num]
|
; mov ecx, [saved_state_num]
|
||||||
; mov [saved_state+ecx*8+4], eax
|
; mov [saved_state+ecx*8+4], eax
|
||||||
; inc [saved_state_num]
|
; inc [saved_state_num]
|
||||||
@ -113,7 +117,11 @@ run_test3:
|
|||||||
jnz memory_destroyed
|
jnz memory_destroyed
|
||||||
pop eax edi
|
pop eax edi
|
||||||
push ebx edx
|
push ebx edx
|
||||||
|
push edi
|
||||||
call free
|
call free
|
||||||
|
pop ecx
|
||||||
|
cmp ecx, edi
|
||||||
|
jnz edi_destroyed
|
||||||
pop edx ebx
|
pop edx ebx
|
||||||
dec esi
|
dec esi
|
||||||
pop eax ecx
|
pop eax ecx
|
||||||
@ -150,8 +158,14 @@ malloc_with_test:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; Stubs for kernel procedures used by heap code
|
; Stubs for kernel procedures used by heap code
|
||||||
wait_mutex:
|
mutex_init:
|
||||||
inc dword [ebx]
|
and dword [ecx], 0
|
||||||
|
ret
|
||||||
|
mutex_lock:
|
||||||
|
inc dword [ecx]
|
||||||
|
ret
|
||||||
|
mutex_unlock:
|
||||||
|
dec dword [ecx]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
kernel_alloc:
|
kernel_alloc:
|
||||||
@ -174,7 +188,7 @@ generic_malloc_fail:
|
|||||||
jmp error_with_code
|
jmp error_with_code
|
||||||
|
|
||||||
check_mutex:
|
check_mutex:
|
||||||
cmp [mst.mutex], 0
|
cmp dword [mst.mutex], 0
|
||||||
jnz @f
|
jnz @f
|
||||||
ret
|
ret
|
||||||
@@:
|
@@:
|
||||||
@ -195,6 +209,10 @@ memory_destroyed:
|
|||||||
mov eax, 5
|
mov eax, 5
|
||||||
jmp error_with_code
|
jmp error_with_code
|
||||||
|
|
||||||
|
edi_destroyed:
|
||||||
|
mov eax, 6
|
||||||
|
jmp error_with_code
|
||||||
|
|
||||||
error_with_code:
|
error_with_code:
|
||||||
mov edx, saved_state_num
|
mov edx, saved_state_num
|
||||||
; eax = error code
|
; eax = error code
|
||||||
@ -208,6 +226,7 @@ error_with_code:
|
|||||||
|
|
||||||
; Include main heap code
|
; Include main heap code
|
||||||
include '../proc32.inc'
|
include '../proc32.inc'
|
||||||
|
include '../struct.inc'
|
||||||
include '../const.inc'
|
include '../const.inc'
|
||||||
include 'malloc.inc'
|
include 'malloc.inc'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user