566,25 → 566,26 |
proc init_heap |
|
mov ebx, [current_slot] |
mov eax, [ebx+APPDATA.heap_top] |
mov ebx, [ebx+APPDATA.process] |
mov eax, [ebx+PROC.heap_top] |
test eax, eax |
jz @F |
sub eax, [ebx+APPDATA.heap_base] |
sub eax, 4096 |
sub eax, [ebx+PROC.heap_base] |
sub eax, PAGE_SIZE |
ret |
@@: |
mov esi, [ebx+APPDATA.mem_size] |
mov esi, [ebx+PROC.mem_used] |
add esi, 4095 |
and esi, not 4095 |
mov [ebx+APPDATA.mem_size], esi |
mov [ebx+PROC.mem_used], esi |
mov eax, HEAP_TOP |
mov [ebx+APPDATA.heap_base], esi |
mov [ebx+APPDATA.heap_top], eax |
mov [ebx+PROC.heap_base], esi |
mov [ebx+PROC.heap_top], eax |
|
sub eax, esi |
shr esi, 10 |
mov ecx, eax |
sub eax, 4096 |
sub eax, PAGE_SIZE |
or ecx, FREE_BLOCK |
mov [page_tabs+esi], ecx |
ret |
598,24 → 599,25 |
push edi |
|
mov ecx, [alloc_size] |
add ecx, (4095+4096) |
add ecx, (4095+PAGE_SIZE) |
and ecx, not 4095 |
|
mov ebx, [current_slot] |
mov esi, dword [ebx+APPDATA.heap_base] ; heap_base |
mov edi, dword [ebx+APPDATA.heap_top] ; heap_top |
l_0: |
mov ebx, [ebx+APPDATA.process] |
mov esi, dword [ebx+PROC.heap_base] ; heap_base |
mov edi, dword [ebx+PROC.heap_top] ; heap_top |
.scan: |
cmp esi, edi |
jae m_exit |
jae .m_exit |
|
mov ebx, esi |
shr ebx, 12 |
mov eax, [page_tabs+ebx*4] |
test al, FREE_BLOCK |
jz test_used |
jz .test_used |
and eax, 0xFFFFF000 |
cmp eax, ecx ;alloc_size |
jb m_next |
jb .m_next |
jz @f |
|
lea edx, [esi+ecx] |
638,11 → 640,12 |
.no: |
|
mov edx, [current_slot] |
mov edx, [edx+APPDATA.process] |
|
mov ebx, [alloc_size] |
add ebx, 0xFFF |
and ebx, not 0xFFF |
add ebx, [edx+APPDATA.mem_size] |
call update_mem_size |
add [edx+PROC.mem_used], ebx |
|
lea eax, [esi+4096] |
|
650,15 → 653,15 |
pop esi |
pop ebx |
ret |
test_used: |
.test_used: |
test al, USED_BLOCK |
jz m_exit |
jz .m_exit |
|
and eax, 0xFFFFF000 |
m_next: |
.m_next: |
add esi, eax |
jmp l_0 |
m_exit: |
jmp .scan |
.m_exit: |
xor eax, eax |
pop edi |
pop esi |
674,13 → 677,15 |
push edi |
|
mov ebx, [current_slot] |
mov ebx, [ebx+APPDATA.process] |
|
mov edx, [address] |
and edx, not 0xFFF |
mov [address], edx |
sub edx, 0x1000 |
jb .error |
mov esi, [ebx+APPDATA.heap_base] |
mov edi, [ebx+APPDATA.heap_top] |
mov esi, [ebx+PROC.heap_base] |
mov edi, [ebx+PROC.heap_top] |
cmp edx, esi |
jb .error |
.scan: |
748,13 → 753,13 |
mov [page_tabs+ebx*4], ecx |
|
.nothird: |
mov edx, [current_slot] |
mov edx, [edx+APPDATA.process] |
|
mov edx, [current_slot] |
mov ebx, [alloc_size] |
add ebx, 0xFFF |
and ebx, not 0xFFF |
add ebx, [edx+APPDATA.mem_size] |
call update_mem_size |
add [edx+PROC.mem_used], ebx |
|
mov eax, [address] |
|
811,11 → 816,12 |
push edi |
|
mov edx, [current_slot] |
mov esi, dword [edx+APPDATA.heap_base] |
mov edi, dword [edx+APPDATA.heap_top] |
sub ebx, [edx+APPDATA.mem_size] |
mov edx, [edx+APPDATA.process] |
mov esi, dword [edx+PROC.heap_base] |
mov edi, dword [edx+PROC.heap_top] |
sub ebx, [edx+PROC.mem_used] |
neg ebx |
call update_mem_size |
mov [edx+PROC.mem_used], ebx |
call user_normalize |
pop edi |
pop ebx |
999,15 → 1005,16 |
mov eax, [page_tabs+ecx*4] |
and eax, not 0xFFF |
mov edx, [current_slot] |
mov ebx, [APPDATA.mem_size+edx] |
mov edx, [edx+APPDATA.process] |
mov ebx, [edx+PROC.mem_used] |
sub ebx, eax |
add ebx, 0x1000 |
or al, FREE_BLOCK |
mov [page_tabs+ecx*4], eax |
push esi edi |
mov esi, [APPDATA.heap_base+edx] |
mov edi, [APPDATA.heap_top+edx] |
call update_mem_size |
mov esi, [edx+PROC.heap_base] |
mov edi, [edx+PROC.heap_top] |
mov [edx+PROC.mem_used], ebx |
call user_normalize |
pop edi esi |
jmp .ret0 ; all freed |
1020,10 → 1027,11 |
sub ebx, edx |
push ebx ecx edx |
mov edx, [current_slot] |
mov edx, [edx+APPDATA.process] |
shl ebx, 12 |
sub ebx, [APPDATA.mem_size+edx] |
sub ebx, [edx+PROC.mem_used] |
neg ebx |
call update_mem_size |
mov [edx+PROC.mem_used], ebx |
pop edx ecx ebx |
lea eax, [ecx+1] |
shl eax, 12 |
1034,7 → 1042,8 |
jz .ret |
push esi |
mov esi, [current_slot] |
mov esi, [APPDATA.heap_top+esi] |
mov esi, [esi+APPDATA.process] |
mov esi, [esi+PROC.heap_top] |
shr esi, 12 |
@@: |
cmp edx, esi |
1058,7 → 1067,8 |
.realloc_add: |
; get some additional memory |
mov eax, [current_slot] |
mov eax, [APPDATA.heap_top+eax] |
mov eax, [eax+APPDATA.process] |
mov eax, [eax+PROC.heap_top] |
shr eax, 12 |
cmp edx, eax |
jae .cant_inplace |
1091,16 → 1101,17 |
rep stosd |
pop edi |
mov edx, [current_slot] |
mov edx, [edx+APPDATA.process] |
shl ebx, 12 |
add ebx, [APPDATA.mem_size+edx] |
call update_mem_size |
add [edx+PROC.mem_used], ebx |
pop eax edx ecx |
ret |
.cant_inplace: |
push esi edi |
mov eax, [current_slot] |
mov esi, [APPDATA.heap_base+eax] |
mov edi, [APPDATA.heap_top+eax] |
mov eax, [eax+APPDATA.process] |
mov esi, [eax+PROC.heap_base] |
mov edi, [eax+PROC.heap_top] |
shr esi, 12 |
shr edi, 12 |
sub ebx, ecx |
1164,9 → 1175,9 |
.no: |
push ebx |
mov edx, [current_slot] |
mov edx, [eax+APPDATA.process] |
shl ebx, 12 |
add ebx, [APPDATA.mem_size+edx] |
call update_mem_size |
add [edx+PROC.mem_used], ebx |
pop ebx |
@@: |
mov dword [page_tabs+esi*4], 2 |
1176,47 → 1187,11 |
pop eax edi esi edx ecx |
ret |
|
if 0 |
align 4 |
proc alloc_dll |
pushf |
cli |
bsf eax, [dll_map] |
jnz .find |
popf |
xor eax, eax |
ret |
.find: |
btr [dll_map], eax |
popf |
shl eax, 5 |
add eax, dll_tab |
ret |
endp |
|
align 4 |
proc alloc_service |
pushf |
cli |
bsf eax, [srv_map] |
jnz .find |
popf |
xor eax, eax |
ret |
.find: |
btr [srv_map], eax |
popf |
shl eax, 0x02 |
lea eax, [srv_tab+eax+eax*8] ;srv_tab+eax*36 |
ret |
endp |
|
end if |
;;;;;;;;;;;;;; SHARED MEMORY ;;;;;;;;;;;;;;;;; |
|
|
;;;;;;;;;;;;;; SHARED ;;;;;;;;;;;;;;;;; |
|
|
; param |
; eax= shm_map object |
|