diff --git a/kernel/trunk/const.inc b/kernel/trunk/const.inc index c2386809d..82f672d53 100644 --- a/kernel/trunk/const.inc +++ b/kernel/trunk/const.inc @@ -477,7 +477,7 @@ virtual at 0 end virtual -struc SHMEM +struc SMEM { .bk dd ? .fd dd ? ;+4 @@ -489,25 +489,25 @@ struc SHMEM .sizeof: } -struc SHMAP +struc SMAP { - .magic dd ? ; SMEM + .magic dd ? ; SMAP .destroy dd ? ;internal destructor .fd dd ? ;next object in list .bk dd ? ;prev object in list .pid dd ? ;owner id .base dd ? ;mapped base - .parent dd ? ;SHMEM + .parent dd ? ;SMEM .sizeof: } virtual at 0 - SHMEM SHMEM + SMEM SMEM end virtual virtual at 0 - SHMAP SHMAP + SMAP SMAP end virtual diff --git a/kernel/trunk/core/heap.inc b/kernel/trunk/core/heap.inc index 7a0e2d731..c88fe8c9f 100644 --- a/kernel/trunk/core/heap.inc +++ b/kernel/trunk/core/heap.inc @@ -1152,17 +1152,17 @@ destroy_smap: push ebx mov ebx, eax - mov eax, [eax+SHMAP.base] + mov eax, [eax+SMAP.base] test eax, eax jz @F stdcall user_free, eax @@: - mov eax, [ebx+SHMAP.parent] + mov eax, [ebx+SMAP.parent] test eax, eax jz @F - lock dec [eax+SHMEM.refcount] + lock dec [eax+SMEM.refcount] @@: mov eax, ebx call destroy_kernel_object @@ -1221,12 +1221,12 @@ align 4 cmp esi, shmem_list je .not_found - lea edx, [esi+SHMEM.name] ; link , base, size + lea edx, [esi+SMEM.name] ; link , base, size stdcall strncmp, edx, eax, 32 test eax, eax je .found - mov esi, [esi+SHMEM.fd] + mov esi, [esi+SMEM.fd] jmp @B .not_found: @@ -1253,7 +1253,7 @@ align 4 and ecx, -4096 mov [size], ecx - mov eax, SHMEM.sizeof + mov eax, SMEM.sizeof call malloc test eax, eax mov esi, eax @@ -1270,20 +1270,20 @@ align 4 mov edx, [access] and edx, SHM_ACCESS_MASK - mov [esi+SHMEM.base], eax - mov [esi+SHMEM.size], ecx - mov [esi+SHMEM.access], edx - mov [esi+SHMEM.refcount], 0 - mov [esi+SHMEM.name+28], 0 + mov [esi+SMEM.base], eax + mov [esi+SMEM.size], ecx + mov [esi+SMEM.access], edx + mov [esi+SMEM.refcount], 0 + mov [esi+SMEM.name+28], 0 - lea eax, [esi+SHMEM.name] + lea eax, [esi+SMEM.name] stdcall strncpy, eax, [name], 31 mov eax, [shmem_list.fd] - mov [esi+SHMEM.bk], shmem_list - mov [esi+SHMEM.fd], eax + mov [esi+SMEM.bk], shmem_list + mov [esi+SMEM.fd], eax - mov [eax+SHMEM.bk], esi + mov [eax+SMEM.bk], esi mov [shmem_list.fd], esi mov [action], SHM_OPEN @@ -1307,7 +1307,7 @@ align 4 mov eax, [access] and eax, SHM_ACCESS_MASK - cmp eax, [esi+SHMEM.access] + cmp eax, [esi+SMEM.access] mov [access], eax mov edx, E_ACCESS ja .exit @@ -1315,7 +1315,7 @@ align 4 mov ebx, [CURRENT_TASK] shl ebx, 5 mov ebx, [CURRENT_TASK+ebx+4] - mov eax, SHMAP.sizeof + mov eax, SMAP.sizeof call create_kernel_object test eax, eax @@ -1323,28 +1323,28 @@ align 4 mov edx, E_NOMEM jz .exit - mov [edi+SHMAP.magic], 'SMEM' - mov [edi+SHMAP.destroy], destroy_smap - mov [edi+SHMAP.base], 0 - mov [edi+SHMAP.parent], 0 + mov [edi+SMAP.magic], 'SMAP' + mov [edi+SMAP.destroy], destroy_smap + mov [edi+SMAP.base], 0 + mov [edi+SMAP.parent], 0 - stdcall user_alloc, [esi+SHMEM.size] + stdcall user_alloc, [esi+SMEM.size] test eax, eax mov [mapped], eax mov edx, E_NOMEM jz .cleanup2 - lock inc [esi+SHMEM.refcount] - mov [edi+SHMAP.base], eax - mov [edi+SHMAP.parent], esi + lock inc [esi+SMEM.refcount] + mov [edi+SMAP.base], eax + mov [edi+SMAP.parent], esi - mov ecx, [esi+SHMEM.size] + mov ecx, [esi+SMEM.size] mov [size], ecx shr ecx, 12 shr eax, 10 - mov esi, [esi+SHMEM.base] + mov esi, [esi+SMEM.base] shr esi, 10 lea edi, [page_tabs+eax] add esi, page_tabs @@ -1385,3 +1385,44 @@ align 4 call destroy_smap jmp .exit endp + +align 4 +proc shmem_close stdcall, name:dword + + mov eax, [name] + test eax, eax + jz .fail + + push esi + push edi + + mov esi, [current_slot] + add esi, APP_OBJ_OFFSET +.next: + mov eax, [esi+APPOBJ.fd] + test eax, eax + jz @F + + cmp eax, esi + mov esi, eax + je @F + + cmp [eax+SMAP.magic], 'SMAP' + jne .next + + mov edi, [eax+SMAP.parent] + test edi, edi + jz .next + + lea eax, [edi+SMEM.name] + stdcall strncmp, [name], edi, 32 + test eax, eax + jne .next + + call [esi+APPOBJ.destroy] +@@: + pop edi + pop esi +.fail: + ret +endp diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index d2ae25468..a993097b5 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -1022,6 +1022,7 @@ f68call: dd f68.20 dd f68.21 dd f68.22 + dd f68.23 align 4 @@ -1033,7 +1034,7 @@ f68: cmp eax, 11 jb .fail - cmp eax, 22 + cmp eax, 23 ja .fail jmp dword [f68call+eax*4-11*4] @@ -1121,6 +1122,14 @@ f68: mov [esp+36], eax ret +.23: + cmp ebx, OS_BASE + jae .fail + + stdcall shmem_close, ebx + mov [esp+36], eax + ret + .fail: xor eax, eax mov [esp+36], eax