1,6 → 1,6 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
140,7 → 140,7 |
|
mov ecx, [pg_data.kernel_pages] |
shl ecx, 12 |
sub ecx, HEAP_BASE+4096*MEM_BLOCK_SIZE |
sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK_SIZE |
mov [heap_size], ecx |
mov [heap_free], ecx |
mov [ebx+block_size], ecx |
759,6 → 759,102 |
endp |
|
align 4 |
proc user_alloc_at stdcall, address:dword, alloc_size:dword |
|
push ebx |
push esi |
push edi |
|
mov ebx, [current_slot] |
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] |
cmp edx, esi |
jb .error |
.scan: |
cmp esi, edi |
jae .error |
mov ebx, esi |
shr ebx, 12 |
mov eax, [page_tabs+ebx*4] |
mov ecx, eax |
and ecx, 0xFFFFF000 |
add ecx, esi |
cmp edx, ecx |
jb .found |
mov esi, ecx |
jmp .scan |
.error: |
xor eax, eax |
pop edi |
pop esi |
pop ebx |
ret |
.found: |
test al, FREE_BLOCK |
jz .error |
mov eax, ecx |
sub eax, edx |
sub eax, 0x1000 |
cmp eax, [alloc_size] |
jb .error |
|
; Here we have 1 big free block which includes requested area. |
; In general, 3 other blocks must be created instead: |
; free at [esi, edx); |
; busy at [edx, edx+0x1000+ALIGN_UP(alloc_size,0x1000)); |
; free at [edx+0x1000+ALIGN_UP(alloc_size,0x1000), ecx) |
; First or third block (or both) may be absent. |
mov eax, edx |
sub eax, esi |
jz .nofirst |
or al, FREE_BLOCK |
mov [page_tabs+ebx*4], eax |
.nofirst: |
mov eax, [alloc_size] |
add eax, 0x1FFF |
and eax, not 0xFFF |
mov ebx, edx |
add edx, eax |
shr ebx, 12 |
or al, USED_BLOCK |
mov [page_tabs+ebx*4], eax |
shr eax, 12 |
dec eax |
jz .second_nofill |
inc ebx |
.fill: |
mov dword [page_tabs+ebx*4], 2 |
inc ebx |
dec eax |
jnz .fill |
.second_nofill: |
sub ecx, edx |
jz .nothird |
or cl, FREE_BLOCK |
mov [page_tabs+ebx*4], ecx |
.nothird: |
|
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 |
|
mov eax, [address] |
|
pop edi |
pop esi |
pop ebx |
ret |
endp |
|
align 4 |
proc user_free stdcall, base:dword |
|
push esi |
1221,10 → 1317,10 |
and eax, SHM_OPEN_MASK |
mov [action], eax |
|
mov eax, [name] |
test eax, eax |
mov ebx, [name] |
test ebx, ebx |
mov edx, E_PARAM |
jz .exit |
jz .fail |
|
mov esi, [shmem_list.fd] |
align 4 |
1233,7 → 1329,7 |
je .not_found |
|
lea edx, [esi+SMEM.name] ; link , base, size |
stdcall strncmp, edx, eax, 32 |
stdcall strncmp, edx, ebx, 32 |
test eax, eax |
je .found |
|
1245,7 → 1341,7 |
|
cmp eax, SHM_OPEN |
mov edx, E_NOTFOUND |
je .exit |
je .fail |
|
cmp eax, SHM_CREATE |
mov edx, E_PARAM |
1252,13 → 1348,13 |
je .create_shm |
|
cmp eax, SHM_OPEN_ALWAYS |
jne .exit |
jne .fail |
|
.create_shm: |
|
mov ecx, [size] |
test ecx, ecx |
jz .exit |
jz .fail |
|
add ecx, 4095 |
and ecx, -4096 |
1269,7 → 1365,7 |
test eax, eax |
mov esi, eax |
mov edx, E_NOMEM |
jz .exit |
jz .fail |
|
stdcall kernel_alloc, [size] |
test eax, eax |
1312,7 → 1408,7 |
je .create_map |
|
cmp eax, SHM_OPEN_ALWAYS |
jne .exit |
jne .fail |
|
.create_map: |
|
1321,7 → 1417,7 |
cmp eax, [esi+SMEM.access] |
mov [access], eax |
mov edx, E_ACCESS |
ja .exit |
ja .fail |
|
mov ebx, [CURRENT_TASK] |
shl ebx, 5 |
1332,12 → 1428,14 |
test eax, eax |
mov edi, eax |
mov edx, E_NOMEM |
jz .exit |
jz .fail |
|
inc [esi+SMEM.refcount] |
|
mov [edi+SMAP.magic], 'SMAP' |
mov [edi+SMAP.destroy], destroy_smap |
mov [edi+SMAP.parent], esi |
mov [edi+SMAP.base], 0 |
mov [edi+SMAP.parent], 0 |
|
stdcall user_alloc, [esi+SMEM.size] |
test eax, eax |
1345,9 → 1443,7 |
mov edx, E_NOMEM |
jz .cleanup2 |
|
lock inc [esi+SMEM.refcount] |
mov [edi+SMAP.base], eax |
mov [edi+SMAP.parent], esi |
|
mov ecx, [esi+SMEM.size] |
mov [size], ecx |
1374,10 → 1470,10 |
xor edx, edx |
|
cmp [owner_access], 0 |
jne .exit |
|
jne .fail |
.exit: |
mov edx, [size] |
.exit: |
.fail: |
mov eax, [mapped] |
|
popfd |
1385,13 → 1481,14 |
pop esi |
pop ebx |
ret |
|
.cleanup: |
mov [size], edx |
mov eax, esi |
call free |
jmp .exit |
|
.cleanup2: |
mov [size], edx |
mov eax, edi |
call destroy_smap |
jmp .exit |
Property changes: |
Added: svn:mergeinfo |