Improved readability, no semantic changes.

git-svn-id: svn://kolibrios.org@7965 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2020-05-21 13:55:36 +00:00
parent 709f961e4c
commit 9ab5b699d5
3 changed files with 307 additions and 315 deletions

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License. ;; ;; Distributed under terms of the GNU General Public License. ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -1228,7 +1228,7 @@ proc load_library stdcall, file_name:dword, encoding:dword
mov [eax+HDLL.parent], esi mov [eax+HDLL.parent], esi
mov edx, ebx mov edx, ebx
shr edx, 12 shr edx, 12
or dword [page_tabs+(edx-1)*4], DONT_FREE_BLOCK or dword [page_tabs+(edx-1)*4], MEM_BLOCK_DONT_FREE
; copy entries of page table from kernel-side image to usermode ; copy entries of page table from kernel-side image to usermode
; use copy-on-write for user-mode image, so map as readonly ; use copy-on-write for user-mode image, so map as readonly
xor edi, edi xor edi, edi

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -18,18 +18,10 @@ struct MEM_BLOCK
handle dd ? ;+28 handle dd ? ;+28
ends ends
FREE_BLOCK = 4 MEM_BLOCK_RESERVED = 0x02 ; Will be allocated on first access (lazy allocation)
USED_BLOCK = 8 MEM_BLOCK_FREE = 0x04
DONT_FREE_BLOCK = 10h MEM_BLOCK_USED = 0x08
MEM_BLOCK_DONT_FREE = 0x10
block_next equ MEM_BLOCK.next_block
block_prev equ MEM_BLOCK.prev_block
list_fd equ MEM_BLOCK.list.next
list_bk equ MEM_BLOCK.list.prev
block_base equ MEM_BLOCK.base
block_size equ MEM_BLOCK.size
block_flags equ MEM_BLOCK.flags
macro calc_index op macro calc_index op
{ shr op, 12 { shr op, 12
@ -43,8 +35,8 @@ macro calc_index op
align 4 align 4
md: md:
.add_to_used: .add_to_used:
mov eax, [esi+block_base] mov eax, [esi + MEM_BLOCK.base]
mov ebx, [esi+block_base] mov ebx, [esi + MEM_BLOCK.base]
shr ebx, 6 shr ebx, 6
add eax, ebx add eax, ebx
shr ebx, 6 shr ebx, 6
@ -55,8 +47,8 @@ md:
lea ecx, [mem_used_list + eax*8] lea ecx, [mem_used_list + eax*8]
list_add esi, ecx list_add esi, ecx
mov [esi+block_flags], USED_BLOCK mov [esi + MEM_BLOCK.flags], MEM_BLOCK_USED
mov eax, [esi+block_size] mov eax, [esi + MEM_BLOCK.size]
sub [heap_free], eax sub [heap_free], eax
ret ret
align 4 align 4
@ -73,11 +65,11 @@ align 4
lea ebx, [mem_used_list + ecx*8] lea ebx, [mem_used_list + ecx*8]
mov esi, ebx mov esi, ebx
.next: .next:
mov esi, [esi+list_fd] mov esi, [esi + MEM_BLOCK.list.next]
cmp esi, ebx cmp esi, ebx
je .fail je .fail
cmp eax, [esi+block_base] cmp eax, [esi + MEM_BLOCK.base]
jne .next jne .next
ret ret
@ -91,7 +83,7 @@ align 4
test esi, esi test esi, esi
jz .done jz .done
cmp [esi+block_flags], USED_BLOCK cmp [esi + MEM_BLOCK.flags], MEM_BLOCK_USED
jne .fatal jne .fatal
dec [mem_hash_cnt + ecx*4] dec [mem_hash_cnt + ecx*4]
@ -104,9 +96,9 @@ align 4
;Initial heap state ;Initial heap state
; ;
;+heap_size terminator USED_BLOCK ; + heap_size terminator MEM_BLOCK_USED
;+4096*MEM_BLOCK.sizeof free space FREE_BLOCK ; + 4096*MEM_BLOCK.sizeof free space MEM_BLOCK_FREE
;HEAP_BASE heap_descriptors USED_BLOCK ;HEAP_BASE heap_descriptors MEM_BLOCK_USED
; ;
align 4 align 4
@ -140,33 +132,33 @@ proc init_kernel_heap
mov ecx, HEAP_BASE + sizeof.MEM_BLOCK*2 ;terminator mov ecx, HEAP_BASE + sizeof.MEM_BLOCK*2 ;terminator
xor eax, eax xor eax, eax
mov [edi+block_next], ebx mov [edi + MEM_BLOCK.next_block], ebx
mov [edi+block_prev], eax mov [edi + MEM_BLOCK.prev_block], eax
mov [edi+list_fd], eax mov [edi + MEM_BLOCK.list.next], eax
mov [edi+list_bk], eax mov [edi + MEM_BLOCK.list.prev], eax
mov [edi+block_base], HEAP_BASE mov [edi + MEM_BLOCK.base], HEAP_BASE
mov [edi+block_size], 4096*sizeof.MEM_BLOCK mov [edi + MEM_BLOCK.size], 4096*sizeof.MEM_BLOCK
mov [edi+block_flags], USED_BLOCK mov [edi + MEM_BLOCK.flags], MEM_BLOCK_USED
mov [ecx+block_next], eax mov [ecx + MEM_BLOCK.next_block], eax
mov [ecx+block_prev], ebx mov [ecx + MEM_BLOCK.prev_block], ebx
mov [ecx+list_fd], eax mov [ecx + MEM_BLOCK.list.next], eax
mov [ecx+list_bk], eax mov [ecx + MEM_BLOCK.list.prev], eax
mov [ecx+block_base], eax mov [ecx + MEM_BLOCK.base], eax
mov [ecx+block_size], eax mov [ecx + MEM_BLOCK.size], eax
mov [ecx+block_flags], USED_BLOCK mov [ecx + MEM_BLOCK.flags], MEM_BLOCK_USED
mov [ebx+block_next], ecx mov [ebx + MEM_BLOCK.next_block], ecx
mov [ebx+block_prev], edi mov [ebx + MEM_BLOCK.prev_block], edi
mov [ebx+block_base], HEAP_BASE+4096*sizeof.MEM_BLOCK mov [ebx + MEM_BLOCK.base], HEAP_BASE + 4096*sizeof.MEM_BLOCK
mov ecx, [pg_data.kernel_pages] mov ecx, [pg_data.kernel_pages]
shl ecx, 12 shl ecx, 12
sub ecx, HEAP_BASE-OS_BASE + 4096*sizeof.MEM_BLOCK sub ecx, HEAP_BASE-OS_BASE + 4096*sizeof.MEM_BLOCK
mov [heap_size], ecx mov [heap_size], ecx
mov [heap_free], ecx mov [heap_free], ecx
mov [ebx+block_size], ecx mov [ebx + MEM_BLOCK.size], ecx
mov [ebx+block_flags], FREE_BLOCK mov [ebx + MEM_BLOCK.flags], MEM_BLOCK_FREE
mov [mem_block_mask], eax mov [mem_block_mask], eax
mov [mem_block_mask + 4], 0x80000000 mov [mem_block_mask + 4], 0x80000000
@ -183,7 +175,7 @@ proc init_kernel_heap
add eax, sizeof.MEM_BLOCK add eax, sizeof.MEM_BLOCK
loop @B loop @B
mov [eax-sizeof.MEM_BLOCK], dword 0 mov dword[eax-sizeof.MEM_BLOCK], 0
mov ecx, heap_mutex mov ecx, heap_mutex
call mutex_init call mutex_init
@ -228,10 +220,10 @@ get_small_block:
lea ecx, [mem_block_list + ebx*8] lea ecx, [mem_block_list + ebx*8]
mov edi, ecx mov edi, ecx
.next: .next:
mov edi, [edi+list_fd] mov edi, [edi + MEM_BLOCK.list.next]
cmp edi, ecx cmp edi, ecx
je .err je .err
cmp eax, [edi+block_size] cmp eax, [edi + MEM_BLOCK.size]
ja .next ja .next
ret ret
.err: .err:
@ -249,11 +241,12 @@ get_small_block:
align 4 align 4
free_mem_block: free_mem_block:
mov ebx, [next_memblock] mov ebx, [next_memblock]
mov [eax], ebx mov [eax], ebx
mov [next_memblock], eax mov [next_memblock], eax
xor ebx, ebx
xor ebx, ebx
mov dword[eax + 4], ebx mov dword[eax + 4], ebx
mov dword[eax + 8], ebx mov dword[eax + 8], ebx
mov dword[eax + 12], ebx mov dword[eax + 12], ebx
@ -261,7 +254,9 @@ free_mem_block:
; mov dword[eax + 20], 0 ;don't clear block size ; mov dword[eax + 20], 0 ;don't clear block size
mov dword[eax + 24], ebx mov dword[eax + 24], ebx
mov dword[eax + 28], ebx mov dword[eax + 28], ebx
inc [free_blocks] inc [free_blocks]
ret ret
align 4 align 4
@ -288,12 +283,12 @@ proc alloc_kernel_space stdcall, size:dword
test edi, edi test edi, edi
jz .error_unlock jz .error_unlock
cmp [edi+block_flags], FREE_BLOCK cmp [edi + MEM_BLOCK.flags], MEM_BLOCK_FREE
jne .error_unlock jne .error_unlock
mov [block_ind], ebx ;index of allocated block mov [block_ind], ebx ;index of allocated block
mov eax, [edi+block_size] mov eax, [edi + MEM_BLOCK.size]
cmp eax, [size] cmp eax, [size]
je .m_eq_size je .m_eq_size
@ -305,22 +300,22 @@ proc alloc_kernel_space stdcall, size:dword
mov eax, [esi] mov eax, [esi]
mov [next_memblock], eax mov [next_memblock], eax
mov [esi+block_next], edi mov [esi + MEM_BLOCK.next_block], edi
mov eax, [edi+block_prev] mov eax, [edi + MEM_BLOCK.prev_block]
mov [esi+block_prev], eax mov [esi + MEM_BLOCK.prev_block], eax
mov [edi+block_prev], esi mov [edi + MEM_BLOCK.prev_block], esi
mov [esi+list_fd], 0 mov [esi + MEM_BLOCK.list.next], 0
mov [esi+list_bk], 0 mov [esi + MEM_BLOCK.list.prev], 0
mov [eax+block_next], esi mov [eax + MEM_BLOCK.next_block], esi
mov ebx, [edi+block_base] mov ebx, [edi + MEM_BLOCK.base]
mov [esi+block_base], ebx mov [esi + MEM_BLOCK.base], ebx
mov edx, [size] mov edx, [size]
mov [esi+block_size], edx mov [esi + MEM_BLOCK.size], edx
add [edi+block_base], edx add [edi + MEM_BLOCK.base], edx
sub [edi+block_size], edx sub [edi + MEM_BLOCK.size], edx
mov eax, [edi+block_size] mov eax, [edi + MEM_BLOCK.size]
calc_index eax calc_index eax
cmp eax, [block_ind] cmp eax, [block_ind]
je .add_used je .add_used
@ -341,7 +336,7 @@ proc alloc_kernel_space stdcall, size:dword
call md.add_to_used call md.add_to_used
spin_unlock_irqrestore heap_mutex spin_unlock_irqrestore heap_mutex
mov eax, [esi+block_base] mov eax, [esi + MEM_BLOCK.base]
pop edi pop edi
pop esi pop esi
pop ebx pop ebx
@ -378,20 +373,20 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
test esi, esi test esi, esi
jz .fail jz .fail
mov eax, [esi+block_size] mov eax, [esi + MEM_BLOCK.size]
add [heap_free], eax add [heap_free], eax
mov edi, [esi+block_next] mov edi, [esi + MEM_BLOCK.next_block]
cmp [edi+block_flags], FREE_BLOCK cmp [edi + MEM_BLOCK.flags], MEM_BLOCK_FREE
jne .prev jne .prev
list_del edi list_del edi
mov edx, [edi+block_next] mov edx, [edi + MEM_BLOCK.next_block]
mov [esi+block_next], edx mov [esi + MEM_BLOCK.next_block], edx
mov [edx+block_prev], esi mov [edx + MEM_BLOCK.prev_block], esi
mov ecx, [edi+block_size] mov ecx, [edi + MEM_BLOCK.size]
add [esi+block_size], ecx add [esi + MEM_BLOCK.size], ecx
calc_index ecx calc_index ecx
@ -403,21 +398,21 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
mov eax, edi mov eax, edi
call free_mem_block call free_mem_block
.prev: .prev:
mov edi, [esi+block_prev] mov edi, [esi + MEM_BLOCK.prev_block]
cmp [edi+block_flags], FREE_BLOCK cmp [edi + MEM_BLOCK.flags], MEM_BLOCK_FREE
jne .insert jne .insert
mov edx, [esi+block_next] mov edx, [esi + MEM_BLOCK.next_block]
mov [edi+block_next], edx mov [edi + MEM_BLOCK.next_block], edx
mov [edx+block_prev], edi mov [edx + MEM_BLOCK.prev_block], edi
mov eax, esi mov eax, esi
call free_mem_block call free_mem_block
mov ecx, [edi+block_size] mov ecx, [edi + MEM_BLOCK.size]
mov eax, [esi+block_size] mov eax, [esi + MEM_BLOCK.size]
add eax, ecx add eax, ecx
mov [edi+block_size], eax mov [edi + MEM_BLOCK.size], eax
calc_index eax ;new index calc_index eax ;new index
calc_index ecx ;old index calc_index ecx ;old index
@ -443,8 +438,8 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
not eax not eax
ret ret
.insert: .insert:
mov [esi+block_flags], FREE_BLOCK mov [esi + MEM_BLOCK.flags], MEM_BLOCK_FREE
mov eax, [esi+block_size] mov eax, [esi + MEM_BLOCK.size]
calc_index eax calc_index eax
mov edi, esi mov edi, esi
jmp .add_block jmp .add_block
@ -532,13 +527,13 @@ proc kernel_free stdcall, base:dword
mov eax, [base] mov eax, [base]
call md.find_used call md.find_used
cmp [esi+block_flags], USED_BLOCK cmp [esi + MEM_BLOCK.flags], MEM_BLOCK_USED
jne .fail jne .fail
spin_unlock_irqrestore heap_mutex spin_unlock_irqrestore heap_mutex
mov eax, [esi+block_base] mov eax, [esi + MEM_BLOCK.base]
mov ecx, [esi+block_size] mov ecx, [esi + MEM_BLOCK.size]
shr ecx, 12 shr ecx, 12
call release_pages ;eax, ecx call release_pages ;eax, ecx
stdcall free_kernel_space, [base] stdcall free_kernel_space, [base]
@ -551,13 +546,6 @@ proc kernel_free stdcall, base:dword
ret ret
endp endp
restore block_next
restore block_prev
restore block_list
restore block_base
restore block_size
restore block_flags
;;;;;;;;;;;;;; USER HEAP ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;; USER HEAP ;;;;;;;;;;;;;;;;;
HEAP_TOP = 0x80000000 HEAP_TOP = 0x80000000
@ -588,22 +576,25 @@ proc init_heap
shr esi, 10 shr esi, 10
mov ecx, eax mov ecx, eax
sub eax, PAGE_SIZE sub eax, PAGE_SIZE
or ecx, FREE_BLOCK or ecx, MEM_BLOCK_FREE
mov [page_tabs + esi], ecx mov [page_tabs + esi], ecx
ret ret
endp endp
align 4 align 4
proc user_alloc stdcall, alloc_size:dword proc user_alloc stdcall, alloc_size:dword
push ebx esi edi push ebx esi edi
mov ebx, [current_process] mov ebx, [current_process]
lea ecx, [ebx + PROC.heap_lock] lea ecx, [ebx + PROC.heap_lock]
call mutex_lock call mutex_lock
mov ecx, [alloc_size] mov ecx, [alloc_size]
add ecx, (4095 + PAGE_SIZE) add ecx, (4095 + PAGE_SIZE)
and ecx, not 4095 and ecx, not 4095
mov esi, dword [ebx+PROC.heap_base] ; heap_base mov esi, [ebx + PROC.heap_base]
mov edi, dword [ebx+PROC.heap_top] ; heap_top mov edi, [ebx + PROC.heap_top]
.scan: .scan:
cmp esi, edi cmp esi, edi
jae .m_exit jae .m_exit
@ -611,7 +602,7 @@ proc user_alloc stdcall, alloc_size:dword
mov ebx, esi mov ebx, esi
shr ebx, 12 shr ebx, 12
mov eax, [page_tabs + ebx*4] mov eax, [page_tabs + ebx*4]
test al, FREE_BLOCK test al, MEM_BLOCK_FREE
jz .test_used jz .test_used
and eax, 0xFFFFF000 and eax, 0xFFFFF000
cmp eax, ecx ;alloc_size cmp eax, ecx ;alloc_size
@ -620,18 +611,18 @@ proc user_alloc stdcall, alloc_size:dword
lea edx, [esi + ecx] lea edx, [esi + ecx]
sub eax, ecx sub eax, ecx
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
shr edx, 12 shr edx, 12
mov [page_tabs + edx*4], eax mov [page_tabs + edx*4], eax
@@: @@:
or ecx, USED_BLOCK or ecx, MEM_BLOCK_USED
mov [page_tabs + ebx*4], ecx mov [page_tabs + ebx*4], ecx
shr ecx, 12 shr ecx, 12
inc ebx inc ebx
dec ecx dec ecx
jz .no jz .no
@@: @@:
mov dword [page_tabs+ebx*4], 2 mov dword [page_tabs + ebx*4], MEM_BLOCK_RESERVED
inc ebx inc ebx
dec ecx dec ecx
jnz @B jnz @B
@ -653,10 +644,10 @@ proc user_alloc stdcall, alloc_size:dword
pop ebx pop ebx
ret ret
.test_used: .test_used:
test al, USED_BLOCK test al, MEM_BLOCK_USED
jz .m_exit jz .m_exit
and eax, 0xFFFFF000 and eax, 0xFFFFF000 ; not PAGESIZE
.m_next: .m_next:
add esi, eax add esi, eax
jmp .scan jmp .scan
@ -716,7 +707,7 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
pop ebx pop ebx
ret ret
.found: .found:
test al, FREE_BLOCK test al, MEM_BLOCK_FREE
jz .error jz .error
mov eax, ecx mov eax, ecx
sub eax, edx sub eax, edx
@ -733,7 +724,7 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
mov eax, edx mov eax, edx
sub eax, esi sub eax, esi
jz .nofirst jz .nofirst
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
mov [page_tabs + ebx*4], eax mov [page_tabs + ebx*4], eax
.nofirst: .nofirst:
mov eax, [alloc_size] mov eax, [alloc_size]
@ -742,14 +733,14 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
mov ebx, edx mov ebx, edx
add edx, eax add edx, eax
shr ebx, 12 shr ebx, 12
or al, USED_BLOCK or al, MEM_BLOCK_USED
mov [page_tabs + ebx*4], eax mov [page_tabs + ebx*4], eax
shr eax, 12 shr eax, 12
dec eax dec eax
jz .second_nofill jz .second_nofill
inc ebx inc ebx
.fill: .fill:
mov dword [page_tabs+ebx*4], 2 mov dword [page_tabs + ebx*4], MEM_BLOCK_RESERVED
inc ebx inc ebx
dec eax dec eax
jnz .fill jnz .fill
@ -757,7 +748,7 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
.second_nofill: .second_nofill:
sub ecx, edx sub ecx, edx
jz .nothird jz .nothird
or cl, FREE_BLOCK or cl, MEM_BLOCK_FREE
mov [page_tabs + ebx*4], ecx mov [page_tabs + ebx*4], ecx
.nothird: .nothird:
@ -796,14 +787,14 @@ proc user_free stdcall, base:dword
xor ebx, ebx xor ebx, ebx
shr esi, 12 shr esi, 12
mov eax, [page_tabs + (esi-1)*4] mov eax, [page_tabs + (esi-1)*4]
test al, USED_BLOCK test al, MEM_BLOCK_USED
jz .cantfree jz .cantfree
test al, DONT_FREE_BLOCK test al, MEM_BLOCK_DONT_FREE
jnz .cantfree jnz .cantfree
and eax, not 4095 and eax, not 4095
mov ecx, eax mov ecx, eax
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
mov [page_tabs + (esi-1)*4], eax mov [page_tabs + (esi-1)*4], eax
sub ecx, 4096 sub ecx, 4096
mov ebx, ecx mov ebx, ecx
@ -873,9 +864,9 @@ proc user_unmap stdcall, base:dword, offset:dword, size:dword
shr ebx, 12 ; chek block attributes shr ebx, 12 ; chek block attributes
lea ebx, [page_tabs + ebx*4] lea ebx, [page_tabs + ebx*4]
mov eax, [ebx-4] ; block attributes mov eax, [ebx-4] ; block attributes
test al, USED_BLOCK test al, MEM_BLOCK_USED
jz .error jz .error
test al, DONT_FREE_BLOCK test al, MEM_BLOCK_DONT_FREE
jnz .error jnz .error
shr edx, 12 shr edx, 12
@ -902,12 +893,12 @@ proc user_unmap stdcall, base:dword, offset:dword, size:dword
jz @F jz @F
test eax, PG_SHARED ; page shared ? test eax, PG_SHARED ; page shared ?
jnz @F jnz @F
mov [edx], dword 2 mov dword[edx], MEM_BLOCK_RESERVED
; mark page as reserved ; mark page as reserved
invlpg [ebx] ; when we start using invlpg [ebx] ; when we start using
call free_page ; empty c-o-w page instead this ? call free_page ; empty c-o-w page instead this ?
@@: @@:
add ebx, 4096 add ebx, 4096 ; PAGESIZE?
add edx, 4 add edx, 4
dec ecx dec ecx
jnz .unmap jnz .unmap
@ -930,13 +921,13 @@ user_normalize:
shr edi, 12 shr edi, 12
@@: @@:
mov eax, [page_tabs + esi*4] mov eax, [page_tabs + esi*4]
test al, USED_BLOCK test al, MEM_BLOCK_USED
jz .test_free jz .test_free
shr eax, 12 shr eax, 12
add esi, eax add esi, eax
jmp @B jmp @B
.test_free: .test_free:
test al, FREE_BLOCK test al, MEM_BLOCK_FREE
jz .err jz .err
mov edx, eax mov edx, eax
shr edx, 12 shr edx, 12
@ -945,7 +936,7 @@ user_normalize:
jae .exit jae .exit
mov ebx, [page_tabs + edx*4] mov ebx, [page_tabs + edx*4]
test bl, USED_BLOCK test bl, MEM_BLOCK_USED
jz .next_free jz .next_free
shr ebx, 12 shr ebx, 12
@ -953,12 +944,12 @@ user_normalize:
mov esi, edx mov esi, edx
jmp @B jmp @B
.next_free: .next_free:
test bl, FREE_BLOCK test bl, MEM_BLOCK_FREE
jz .err jz .err
and dword[page_tabs + edx*4], 0 and dword[page_tabs + edx*4], 0
add eax, ebx add eax, ebx
and eax, not 4095 and eax, not 4095 ; not (PAGESIZE - 1) ?
or eax, FREE_BLOCK or eax, MEM_BLOCK_FREE
mov [page_tabs + esi*4], eax mov [page_tabs + esi*4], eax
jmp @B jmp @B
.exit: .exit:
@ -990,7 +981,7 @@ user_realloc:
lea ecx, [eax - 0x1000] lea ecx, [eax - 0x1000]
shr ecx, 12 shr ecx, 12
mov edx, [page_tabs + ecx*4] mov edx, [page_tabs + ecx*4]
test dl, USED_BLOCK test dl, MEM_BLOCK_USED
jnz @f jnz @f
; attempt to realloc invalid pointer ; attempt to realloc invalid pointer
.ret0: .ret0:
@ -1002,7 +993,7 @@ user_realloc:
xor eax, eax xor eax, eax
ret ret
@@: @@:
test dl, DONT_FREE_BLOCK test dl, MEM_BLOCK_DONT_FREE
jnz .ret0 jnz .ret0
add ebx, 0x1FFF add ebx, 0x1FFF
shr edx, 12 shr edx, 12
@ -1036,7 +1027,7 @@ user_realloc:
mov ebx, [edx + PROC.mem_used] mov ebx, [edx + PROC.mem_used]
sub ebx, eax sub ebx, eax
add ebx, 0x1000 add ebx, 0x1000
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
mov [page_tabs + ecx*4], eax mov [page_tabs + ecx*4], eax
push esi edi push esi edi
mov esi, [edx + PROC.heap_base] mov esi, [edx + PROC.heap_base]
@ -1048,7 +1039,7 @@ user_realloc:
.nofreeall: .nofreeall:
sub edx, ecx sub edx, ecx
shl ebx, 12 shl ebx, 12
or ebx, USED_BLOCK or ebx, MEM_BLOCK_USED
xchg [page_tabs + ecx*4], ebx xchg [page_tabs + ecx*4], ebx
shr ebx, 12 shr ebx, 12
sub ebx, edx sub ebx, edx
@ -1074,7 +1065,7 @@ user_realloc:
cmp edx, esi cmp edx, esi
jae .merge_done jae .merge_done
mov eax, [page_tabs + edx*4] mov eax, [page_tabs + edx*4]
test al, USED_BLOCK test al, MEM_BLOCK_USED
jnz .merge_done jnz .merge_done
and dword [page_tabs + edx*4], 0 and dword [page_tabs + edx*4], 0
shr eax, 12 shr eax, 12
@ -1084,7 +1075,7 @@ user_realloc:
jmp @b jmp @b
.merge_done: .merge_done:
pop esi pop esi
or ebx, FREE_BLOCK or ebx, MEM_BLOCK_FREE
mov [page_tabs + ecx*4], ebx mov [page_tabs + ecx*4], ebx
.ret: .ret:
mov ecx, [current_process] mov ecx, [current_process]
@ -1101,7 +1092,7 @@ user_realloc:
cmp edx, eax cmp edx, eax
jae .cant_inplace jae .cant_inplace
mov eax, [page_tabs + edx*4] mov eax, [page_tabs + edx*4]
test al, FREE_BLOCK test al, MEM_BLOCK_FREE
jz .cant_inplace jz .cant_inplace
shr eax, 12 shr eax, 12
add eax, edx add eax, edx
@ -1109,13 +1100,13 @@ user_realloc:
jb .cant_inplace jb .cant_inplace
jz @f jz @f
shl eax, 12 shl eax, 12
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
mov [page_tabs + ebx*4], eax mov [page_tabs + ebx*4], eax
@@: @@:
mov eax, ebx mov eax, ebx
sub eax, ecx sub eax, ecx
shl eax, 12 shl eax, 12
or al, USED_BLOCK or al, MEM_BLOCK_USED
mov [page_tabs + ecx*4], eax mov [page_tabs + ecx*4], eax
lea eax, [ecx + 1] lea eax, [ecx + 1]
shl eax, 12 shl eax, 12
@ -1150,7 +1141,7 @@ user_realloc:
cmp esi, edi cmp esi, edi
jae .place_not_found jae .place_not_found
mov eax, [page_tabs + esi*4] mov eax, [page_tabs + esi*4]
test al, FREE_BLOCK test al, MEM_BLOCK_FREE
jz .next_place jz .next_place
shr eax, 12 shr eax, 12
cmp eax, ebx cmp eax, ebx
@ -1170,13 +1161,13 @@ user_realloc:
push esi push esi
add esi, ebx add esi, ebx
shl eax, 12 shl eax, 12
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
mov [page_tabs + esi*4], eax mov [page_tabs + esi*4], eax
pop esi pop esi
@@: @@:
mov eax, ebx mov eax, ebx
shl eax, 12 shl eax, 12
or al, USED_BLOCK or al, MEM_BLOCK_USED
mov [page_tabs + esi*4], eax mov [page_tabs + esi*4], eax
inc esi inc esi
mov eax, esi mov eax, esi
@ -1184,7 +1175,7 @@ user_realloc:
push eax push eax
mov eax, [page_tabs + ecx*4] mov eax, [page_tabs + ecx*4]
and eax, not 0xFFF and eax, not 0xFFF
or al, FREE_BLOCK or al, MEM_BLOCK_FREE
sub edx, ecx sub edx, ecx
mov [page_tabs + ecx*4], eax mov [page_tabs + ecx*4], eax
inc ecx inc ecx
@ -1210,7 +1201,7 @@ user_realloc:
add [edx + PROC.mem_used], ebx add [edx + PROC.mem_used], ebx
pop ebx pop ebx
@@: @@:
mov dword [page_tabs+esi*4], 2 mov dword [page_tabs + esi*4], MEM_BLOCK_RESERVED
inc esi inc esi
dec ebx dec ebx
jnz @b jnz @b
@ -1526,3 +1517,4 @@ proc shmem_close stdcall, name:dword
.fail: .fail:
ret ret
endp endp

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; Copyright (C) KolibriOS team 2004-2020. All rights reserved.
;; PROGRAMMING: ;; PROGRAMMING:
;; Ivan Poddubny ;; Ivan Poddubny
;; Marat Zakiyanov (Mario79) ;; Marat Zakiyanov (Mario79)
@ -2799,7 +2799,7 @@ align 4
jz .nomem jz .nomem
mov ebx, eax mov ebx, eax
shr ebx, 12 shr ebx, 12
or dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK or dword [page_tabs+(ebx-1)*4], MEM_BLOCK_DONT_FREE
mov esi, [img_background] mov esi, [img_background]
shr esi, 12 shr esi, 12
mov ecx, [mem_BACKGROUND] mov ecx, [mem_BACKGROUND]
@ -2844,7 +2844,7 @@ nosb6:
mov ebx, ecx mov ebx, ecx
shr eax, 12 shr eax, 12
mov ecx, [page_tabs+(eax-1)*4] mov ecx, [page_tabs+(eax-1)*4]
test cl, USED_BLOCK+DONT_FREE_BLOCK test cl, MEM_BLOCK_USED or MEM_BLOCK_DONT_FREE
jz .err jz .err
jnp .err jnp .err
push eax push eax
@ -2862,7 +2862,7 @@ align 4
inc eax inc eax
loop @b loop @b
pop eax pop eax
and dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK and dword [page_tabs+(eax-1)*4], not MEM_BLOCK_DONT_FREE
stdcall user_free, ebx stdcall user_free, ebx
mov [esp+32], eax mov [esp+32], eax
and [bgrlockpid], 0 and [bgrlockpid], 0