shmem_close()

git-svn-id: svn://kolibrios.org@943 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2008-12-04 06:04:21 +00:00
parent 42ea13c96b
commit 07cb3855b0
3 changed files with 84 additions and 34 deletions

View File

@ -477,7 +477,7 @@ virtual at 0
end virtual end virtual
struc SHMEM struc SMEM
{ {
.bk dd ? .bk dd ?
.fd dd ? ;+4 .fd dd ? ;+4
@ -489,25 +489,25 @@ struc SHMEM
.sizeof: .sizeof:
} }
struc SHMAP struc SMAP
{ {
.magic dd ? ; SMEM .magic dd ? ; SMAP
.destroy dd ? ;internal destructor .destroy dd ? ;internal destructor
.fd dd ? ;next object in list .fd dd ? ;next object in list
.bk dd ? ;prev object in list .bk dd ? ;prev object in list
.pid dd ? ;owner id .pid dd ? ;owner id
.base dd ? ;mapped base .base dd ? ;mapped base
.parent dd ? ;SHMEM .parent dd ? ;SMEM
.sizeof: .sizeof:
} }
virtual at 0 virtual at 0
SHMEM SHMEM SMEM SMEM
end virtual end virtual
virtual at 0 virtual at 0
SHMAP SHMAP SMAP SMAP
end virtual end virtual

View File

@ -1152,17 +1152,17 @@ destroy_smap:
push ebx push ebx
mov ebx, eax mov ebx, eax
mov eax, [eax+SHMAP.base] mov eax, [eax+SMAP.base]
test eax, eax test eax, eax
jz @F jz @F
stdcall user_free, eax stdcall user_free, eax
@@: @@:
mov eax, [ebx+SHMAP.parent] mov eax, [ebx+SMAP.parent]
test eax, eax test eax, eax
jz @F jz @F
lock dec [eax+SHMEM.refcount] lock dec [eax+SMEM.refcount]
@@: @@:
mov eax, ebx mov eax, ebx
call destroy_kernel_object call destroy_kernel_object
@ -1221,12 +1221,12 @@ align 4
cmp esi, shmem_list cmp esi, shmem_list
je .not_found je .not_found
lea edx, [esi+SHMEM.name] ; link , base, size lea edx, [esi+SMEM.name] ; link , base, size
stdcall strncmp, edx, eax, 32 stdcall strncmp, edx, eax, 32
test eax, eax test eax, eax
je .found je .found
mov esi, [esi+SHMEM.fd] mov esi, [esi+SMEM.fd]
jmp @B jmp @B
.not_found: .not_found:
@ -1253,7 +1253,7 @@ align 4
and ecx, -4096 and ecx, -4096
mov [size], ecx mov [size], ecx
mov eax, SHMEM.sizeof mov eax, SMEM.sizeof
call malloc call malloc
test eax, eax test eax, eax
mov esi, eax mov esi, eax
@ -1270,20 +1270,20 @@ align 4
mov edx, [access] mov edx, [access]
and edx, SHM_ACCESS_MASK and edx, SHM_ACCESS_MASK
mov [esi+SHMEM.base], eax mov [esi+SMEM.base], eax
mov [esi+SHMEM.size], ecx mov [esi+SMEM.size], ecx
mov [esi+SHMEM.access], edx mov [esi+SMEM.access], edx
mov [esi+SHMEM.refcount], 0 mov [esi+SMEM.refcount], 0
mov [esi+SHMEM.name+28], 0 mov [esi+SMEM.name+28], 0
lea eax, [esi+SHMEM.name] lea eax, [esi+SMEM.name]
stdcall strncpy, eax, [name], 31 stdcall strncpy, eax, [name], 31
mov eax, [shmem_list.fd] mov eax, [shmem_list.fd]
mov [esi+SHMEM.bk], shmem_list mov [esi+SMEM.bk], shmem_list
mov [esi+SHMEM.fd], eax mov [esi+SMEM.fd], eax
mov [eax+SHMEM.bk], esi mov [eax+SMEM.bk], esi
mov [shmem_list.fd], esi mov [shmem_list.fd], esi
mov [action], SHM_OPEN mov [action], SHM_OPEN
@ -1307,7 +1307,7 @@ align 4
mov eax, [access] mov eax, [access]
and eax, SHM_ACCESS_MASK and eax, SHM_ACCESS_MASK
cmp eax, [esi+SHMEM.access] cmp eax, [esi+SMEM.access]
mov [access], eax mov [access], eax
mov edx, E_ACCESS mov edx, E_ACCESS
ja .exit ja .exit
@ -1315,7 +1315,7 @@ align 4
mov ebx, [CURRENT_TASK] mov ebx, [CURRENT_TASK]
shl ebx, 5 shl ebx, 5
mov ebx, [CURRENT_TASK+ebx+4] mov ebx, [CURRENT_TASK+ebx+4]
mov eax, SHMAP.sizeof mov eax, SMAP.sizeof
call create_kernel_object call create_kernel_object
test eax, eax test eax, eax
@ -1323,28 +1323,28 @@ align 4
mov edx, E_NOMEM mov edx, E_NOMEM
jz .exit jz .exit
mov [edi+SHMAP.magic], 'SMEM' mov [edi+SMAP.magic], 'SMAP'
mov [edi+SHMAP.destroy], destroy_smap mov [edi+SMAP.destroy], destroy_smap
mov [edi+SHMAP.base], 0 mov [edi+SMAP.base], 0
mov [edi+SHMAP.parent], 0 mov [edi+SMAP.parent], 0
stdcall user_alloc, [esi+SHMEM.size] stdcall user_alloc, [esi+SMEM.size]
test eax, eax test eax, eax
mov [mapped], eax mov [mapped], eax
mov edx, E_NOMEM mov edx, E_NOMEM
jz .cleanup2 jz .cleanup2
lock inc [esi+SHMEM.refcount] lock inc [esi+SMEM.refcount]
mov [edi+SHMAP.base], eax mov [edi+SMAP.base], eax
mov [edi+SHMAP.parent], esi mov [edi+SMAP.parent], esi
mov ecx, [esi+SHMEM.size] mov ecx, [esi+SMEM.size]
mov [size], ecx mov [size], ecx
shr ecx, 12 shr ecx, 12
shr eax, 10 shr eax, 10
mov esi, [esi+SHMEM.base] mov esi, [esi+SMEM.base]
shr esi, 10 shr esi, 10
lea edi, [page_tabs+eax] lea edi, [page_tabs+eax]
add esi, page_tabs add esi, page_tabs
@ -1385,3 +1385,44 @@ align 4
call destroy_smap call destroy_smap
jmp .exit jmp .exit
endp 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

View File

@ -1022,6 +1022,7 @@ f68call:
dd f68.20 dd f68.20
dd f68.21 dd f68.21
dd f68.22 dd f68.22
dd f68.23
align 4 align 4
@ -1033,7 +1034,7 @@ f68:
cmp eax, 11 cmp eax, 11
jb .fail jb .fail
cmp eax, 22 cmp eax, 23
ja .fail ja .fail
jmp dword [f68call+eax*4-11*4] jmp dword [f68call+eax*4-11*4]
@ -1121,6 +1122,14 @@ f68:
mov [esp+36], eax mov [esp+36], eax
ret ret
.23:
cmp ebx, OS_BASE
jae .fail
stdcall shmem_close, ebx
mov [esp+36], eax
ret
.fail: .fail:
xor eax, eax xor eax, eax
mov [esp+36], eax mov [esp+36], eax