From 8c4037718d33c1d6ce3dede28d5f477b98f8452b Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Fri, 24 Feb 2012 21:47:01 +0000 Subject: [PATCH] new 68.26 user_unmap(void* block_base, unsigned int offset, size_t unmap_size); git-svn-id: svn://kolibrios.org@2400 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/heap.inc | 65 ++++++++++++++++++++++++++++++++++++ kernel/trunk/core/memory.inc | 10 ++++-- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/kernel/trunk/core/heap.inc b/kernel/trunk/core/heap.inc index 6055f5ad6e..67c9d0216c 100644 --- a/kernel/trunk/core/heap.inc +++ b/kernel/trunk/core/heap.inc @@ -848,6 +848,71 @@ proc user_free stdcall, base:dword ret endp + +align 4 +proc user_unmap stdcall, base:dword, offset:dword, size:dword + + push ebx + + mov ebx, [base] ; must be valid pointer + test ebx, ebx + jz .error + + mov edx, [offset] ; check offset + add edx, ebx ; must be below 2Gb app limit + js .error + + shr ebx, 12 ; chek block attributes + lea ebx, [page_tabs+ebx*4] + mov eax, [ebx-4] ; block attributes + test al, USED_BLOCK + jz .error + test al, DONT_FREE_BLOCK + jnz .error + + shr edx, 12 + lea edx, [page_tabs+edx*4] ; unmap offset + + mov ecx, [size] + add ecx, 4095 + shr ecx, 12 ; unmap size in pages + + shr eax, 12 ; block size + 1 page + lea ebx, [ebx+eax*4-4] ; block end ptr + lea eax, [edx+ecx*4] ; unmap end ptr + + cmp eax, ebx ; check for overflow + ja .error + + mov ebx, [offset] + and ebx, not 4095 ; is it required ? + +.unmap: + mov eax, [edx] ; get page addres + test al, 1 ; page mapped ? + jz @F + test eax, PG_SHARED ; page shared ? + jnz @F + mov [page_tabs+edx*4], dword 2 + ; mark page as reserved + invlpg [ebx] ; when we start using + call free_page ; empty c-o-w page instead this ? +@@: + add ebx, 4096 + add edx, 4 + dec ecx + jnz .unmap + + pop ebx + or al, 1 ; return non zero on success + ret +.error: + pop ebx + xor eax, eax ; something wrong + ret +endp + +align 4 user_normalize: ; in: esi=heap_base, edi=heap_top ; out: eax=0 <=> OK diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index a2e36309c5..54e57ec1a4 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -1307,6 +1307,11 @@ f68: @@: ret +.26: + stdcall user_unmap, ecx, edx, esi + mov [esp+32], eax + ret + .fail: xor eax, eax mov [esp+32], eax @@ -1329,8 +1334,9 @@ f68call: ; keep this table closer to main code dd f68.21 ; load_driver dd f68.22 ; shmem_open dd f68.23 ; shmem_close - dd f68.24 - dd f68.25 + dd f68.24 ; set exception handler + dd f68.25 ; unmask exception + dd f68.26 ; user_unmap align 4