shmem_open()

git-svn-id: svn://kolibrios.org@940 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2008-11-30 19:04:25 +00:00
parent 13ea3979bb
commit 4ac08fc6e9
5 changed files with 383 additions and 258 deletions

View File

@ -362,6 +362,8 @@ PG_NOCACHE equ 0x018
PG_LARGE equ 0x080
PG_GLOBAL equ 0x100
PG_SHARED equ 0x200
;;;;;;;;;;;boot time variables
;BOOT_BPP equ 0x9000 ;byte bits per pixel
@ -475,6 +477,40 @@ virtual at 0
end virtual
struc SHMEM
{
.bk dd ?
.fd dd ? ;+4
.base dd ? ;+8
.size dd ? ;+12
.access dd ? ;+16
.refcount dd ? ;+20
.name rb 32 ;+24
.sizeof:
}
struc SHMAP
{
.magic dd ? ; SMEM
.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
.sizeof:
}
virtual at 0
SHMEM SHMEM
end virtual
virtual at 0
SHMAP SHMAP
end virtual
struc HEAP_DATA
{
.mutex rd 1

View File

@ -704,7 +704,7 @@ l_0:
and eax, 0xFFFFF000
cmp eax, ecx ;alloc_size
jb m_next
jz @f
jz @f
lea edx, [esi+ecx]
sub eax, ecx
@ -786,6 +786,8 @@ proc user_free stdcall, base:dword
xchg eax, [page_tabs+esi*4]
test al, 1
jz @F
test eax, PG_SHARED
jnz @F
call free_page
mov eax, esi
shl eax, 12
@ -1074,9 +1076,9 @@ user_realloc:
xor eax, eax
xchg eax, [page_tabs+ecx*4]
mov [page_tabs+esi*4], eax
mov eax, ecx
shl eax, 12
invlpg [eax]
mov eax, ecx
shl eax, 12
invlpg [eax]
inc esi
inc ecx
dec ebx
@ -1133,3 +1135,253 @@ proc alloc_service
endp
end if
;;;;;;;;;;;;;; SHARED ;;;;;;;;;;;;;;;;;
; param
; eax= shm_map object
align 4
destroy_smap:
pushfd
cli
push ebx
mov ebx, eax
mov eax, [eax+SHMAP.base]
test eax, eax
jz @F
stdcall user_free, eax
@@:
mov eax, [ebx+SHMAP.parent]
test eax, eax
jz @F
lock dec [eax+SHMEM.refcount]
@@:
mov eax, ebx
call destroy_kernel_object
pop ebx
popfd
ret
E_NOTFOUND equ 5
E_ACCESS equ 10
E_NOMEM equ 30
E_PARAM equ 33
SHM_READ equ 0
SHM_WRITE equ 1
SHM_ACCESS_MASK equ 3
SHM_OPEN equ (0 shl 2)
SHM_OPEN_ALWAYS equ (1 shl 2)
SHM_CREATE equ (2 shl 2)
SHM_OPEN_MASK equ (3 shl 2)
align 4
proc shmem_open stdcall name:dword, size:dword, access:dword
locals
action dd ?
owner_access dd ?
mapped dd ?
endl
push ebx
push esi
push edi
mov [mapped], 0
mov [owner_access], 0
pushfd ;mutex required
cli
mov eax, [access]
and eax, SHM_OPEN_MASK
mov [action], eax
mov eax, [name]
test eax, eax
mov edx, E_PARAM
jz .exit
mov esi, [shmem_list.fd]
align 4
@@:
cmp esi, shmem_list
je .not_found
lea edx, [esi+SHMEM.name] ; link , base, size
stdcall strncmp, edx, eax, 32
test eax, eax
je .found
mov esi, [esi+SHMEM.fd]
jmp @B
.not_found:
mov eax, [action]
cmp eax, SHM_OPEN
mov edx, E_NOTFOUND
je .exit
cmp eax, SHM_CREATE
mov edx, E_PARAM
je .create_shm
cmp eax, SHM_OPEN_ALWAYS
jne .exit
.create_shm:
mov ecx, [size]
test ecx, ecx
jz .exit
add ecx, 4095
and ecx, -4096
mov [size], ecx
mov eax, SHMEM.sizeof
call malloc
test eax, eax
mov esi, eax
mov edx, E_NOMEM
jz .exit
stdcall kernel_alloc, [size]
test eax, eax
mov [mapped], eax
mov edx, E_NOMEM
jz .cleanup
mov ecx, [size]
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
lea eax, [esi+SHMEM.name]
stdcall strncpy, eax, [name], 31
mov eax, [shmem_list.fd]
mov [esi+SHMEM.bk], shmem_list
mov [esi+SHMEM.fd], eax
mov [eax+SHMEM.bk], esi
mov [shmem_list.fd], esi
mov [action], SHM_OPEN
mov [owner_access], SHM_WRITE
.found:
mov eax, [action]
cmp eax, SHM_CREATE
mov edx, E_ACCESS
je .exit
cmp eax, SHM_OPEN
mov edx, E_PARAM
je .create_map
cmp eax, SHM_OPEN_ALWAYS
jne .exit
.create_map:
mov eax, [access]
and eax, SHM_ACCESS_MASK
cmp eax, [esi+SHMEM.access]
mov [access], eax
mov edx, E_ACCESS
ja .exit
mov ebx, [CURRENT_TASK]
shl ebx, 5
mov ebx, [CURRENT_TASK+ebx+4]
mov eax, SHMAP.sizeof
call create_kernel_object
test eax, eax
mov edi, eax
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
stdcall user_alloc, [esi+SHMEM.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
mov ecx, [esi+SHMEM.size]
mov [size], ecx
shr ecx, 12
shr eax, 10
mov esi, [esi+SHMEM.base]
shr esi, 10
lea edi, [page_tabs+eax]
add esi, page_tabs
mov edx, [access]
or edx, [owner_access]
shl edx, 1
or edx, PG_USER+PG_SHARED
@@:
lodsd
and eax, 0xFFFFF000
or eax, edx
stosd
loop @B
xor edx, edx
cmp [owner_access], 0
jne .exit
mov edx, [size]
.exit:
mov eax, [mapped]
popfd
pop edi
pop esi
pop ebx
ret
.cleanup:
mov eax, esi
call free
jmp .exit
.cleanup2:
mov eax, edi
call destroy_smap
jmp .exit
endp

View File

@ -1009,51 +1009,61 @@ sysfn_meminfo:
ret
align 4
new_services:
f68call:
dd f68.11
dd f68.12
dd f68.13
dd f68.14
dd f68.15
dd f68.16
dd f68.17
dd f68.18
dd f68.19
dd f68.20
dd f68.21
dd f68.22
align 4
f68:
cmp eax,4
jle sys_sheduler
cmp eax, 11
jb .fail
ja @f
cmp eax, 22
ja .fail
jmp dword [f68call+eax*4-11*4]
.11:
call init_heap
mov [esp+36], eax
ret
@@:
cmp eax, 12
ja @f
.12:
stdcall user_alloc, ebx
mov [esp+36], eax
ret
@@:
cmp eax, 13
ja @f
.13:
stdcall user_free, ebx
mov [esp+36], eax
ret
@@:
cmp eax, 14
ja @f
.14:
cmp ebx, OS_BASE
jae .fail
stdcall get_event_ex, ebx, ecx
mov [esp+36], eax
ret
@@:
cmp eax, 15
ja @f
.15:
mov ecx, [current_slot]
mov eax, [ecx+APPDATA.fpu_handler]
mov [ecx+APPDATA.fpu_handler], ebx
mov [esp+36], eax
ret
@@:
cmp eax, 16
ja @f
.16:
test ebx, ebx
jz .fail
cmp ebx, OS_BASE
@ -1061,38 +1071,28 @@ new_services:
stdcall get_service, ebx
mov [esp+36], eax
ret
@@:
cmp eax, 17
ja @f
.17:
call srv_handlerEx ;ebx
mov [esp+36], eax
ret
@@:
cmp eax, 18
ja @f
.18:
mov ecx, [current_slot]
mov eax, [ecx+APPDATA.sse_handler]
mov [ecx+APPDATA.sse_handler], ebx
mov [esp+36], eax
ret
@@:
cmp eax, 19
ja @f
.19:
cmp ebx, OS_BASE
jae .fail
stdcall load_library, ebx
mov [esp+36], eax
ret
@@:
cmp eax, 20
ja @F
.20:
mov eax, ecx
call user_realloc
mov [esp+36], eax
ret
@@:
cmp eax, 21 ;for test purposes only
ja @f ;will be removed soon
.21:
cmp ebx, OS_BASE
jae .fail
@ -1112,7 +1112,14 @@ new_services:
@@:
mov [esp+36], eax
ret
.22:
cmp ebx, OS_BASE
jae .fail
stdcall shmem_open, ebx, ecx, edx
mov [esp+28], edx
mov [esp+36], eax
ret
.fail:
xor eax, eax
@ -1309,181 +1316,3 @@ endp
if 0
; under constuction
shmem_list:
.bk dd shmem_list
.fd dd shmem_list
shmem
.bk dd ?
.fd dd ?
.base dd ?
.size dd ?
.access dd ?
.refcount dd ?
.name rb 32
align 4
proc shmem_open stdcall name:dword, size:dword, access:dword
locals
mapped dd ?
shm dd ?
pages dd ?
endl
push esi
push edi
mov [mapped], 0
mov eax, [name]
test eax, eax
jz .exit
pushfd ;mutex required
cli
mov ebx, [shmem_list.fd]
@@:
cmp ebx, shmem_list
je .not_found
lea edx, [edx+24] ; link , base, size
stdcall strncmp, edx, eax, 32
test eax, eax
je .found
mov ebx, [ebx+4]
jmp @B
.found: ;check access rights
mov eax, [access]
test eax, SHM_CREATE
mov ecx, [ebx+8]
jnz .fail_exist
and eax, ACC_MASK
and ecx, ACC_MASK
cmp eax, ecx
jne .fail_acc
stdcall user_alloc, [ebx+12]
test eax, eax
mov [mapped], eax
jz .fail_mem
mov eax, [ebx+4]
mov ecx, [ebx+12]
shr ecx, 12
mov ebx, [mapped]
call commit_pages
.exit:
mov eax, [mapped]
pop edi
pop esi
ret
.not_found:
mov eax, [access]
test eax, SHM_CREATE
mov ebx, E_NOTFOUND
jz .exit
;create shmem
mov ecx, [size]
test ecx, ecx
mov ebx, E_PARAM
jz .exit
add ecx, 4095
and ecx, -4096
mov [size], ecx
stdcall user_alloc, ecx
test eax, eax
mov [mapped], eax
mov ebx, E_NOMEM
jz .exit
mov eax, 24+32
call malloc
test eax, eax
mov [shm], eax
mov ebx, E_NOMEM
jz .exit ;FIXME cleanup
mov [eax+24+28], dword 0
lea edx, [eax+24]
stdcall strncpy, edx, [name], 31
mov eax, [size]
shr eax, 12
mov esi, eax
stdcall alloc_pages, eax
test eax, eax
mov [pages], eax
mov ebx, E_NOMEM
jz .exit ;FIXME cleanup
mov edi, eax
add edi, [size]
and esi, 7
add esi, -8
jz @F
;release unused pages
.release:
mov eax, edi
add edi, 4096
call free_page
dec esi
jnz .release
mov eax, [ebx+4]
mov ecx, [ebx+12]
shr ecx, 12
mov ebx, [mapped]
call commit_pages
mov eax, [access]
and eax, ACC_MASK
or eax, [pages]
mov ebx, [mapped]
mov ecx, [size]
shr ecx, 12
call commit_pages
mov edx, [shm]
mov ecx, [pages]
mov [edx+8], ecx
mov ecx, [size]
mov [edx+12], ecx
; mov [edx], shmem
; mov [edx+4], [shmem.fd]
; mov [shmem.fd.bk], edx
; mov [shmem.fd], edx
xor ebx, ebx
jmp .exit
.fail_exist:
mov ebx, E_EXIST
xor eax, eax
ret
.fail_access:
mov ebx, E_ACCESS
xor eax, eax
ret
.fail_mem:
mov ebx, E_NOMEM
xor eax, eax
ret
endp
end if

View File

@ -123,13 +123,13 @@ iglobal
dd 0
dd 0
dd 0
dd sys_midi ; 20-ResetMidi and OutputMidi
dd sys_setup ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,.
dd sys_settime ; 22-setting date,time,clock and alarm-clock
dd sys_midi ; 20-ResetMidi and OutputMidi
dd sys_setup ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,.
dd sys_settime ; 22-setting date,time,clock and alarm-clock
dd 0
dd syscall_cdaudio ; 24-PlayCdTrack,StopCd and GetCdPlaylist
dd syscall_cdaudio ; 24-PlayCdTrack,StopCd and GetCdPlaylist
dd 0 ;
dd sys_getsetup ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,.
dd sys_getsetup ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,.
dd 0
dd 0 ;
dd 0
@ -140,42 +140,42 @@ iglobal
dd 0
dd 0
dd 0
dd readmousepos ; 37-GetMousePosition_ScreenRelative,.
dd 0 ; 38-DrawLine
dd sys_getbackground ; 39-GetBackgroundSize,ReadBgrData,.
dd readmousepos ; 37-GetMousePosition_ScreenRelative,.
dd 0 ; 38-DrawLine
dd sys_getbackground ; 39-GetBackgroundSize,ReadBgrData,.
dd 0
dd 0
dd 0
dd sys_outport ; 43-SendDeviceData
dd sys_outport ; 43-SendDeviceData
dd 0
dd 0
dd syscall_reserveportarea ; 46-ReservePortArea and FreePortArea
dd display_number ; 47-WriteNum
dd display_settings ; 48-SetRedrawType and SetButtonType
dd sys_apm ; 49-Advanced Power Management (APM)
dd display_number ; 47-WriteNum
dd display_settings ; 48-SetRedrawType and SetButtonType
dd sys_apm ; 49-Advanced Power Management (APM)
dd random_shaped_window ; 50-Window shape & scale
dd syscall_threads ; 51-Threads
dd stack_driver_stat ; 52-Stack driver status
dd socket ; 53-Socket interface
dd syscall_threads ; 51-Threads
dd stack_driver_stat ; 52-Stack driver status
dd socket ; 53-Socket interface
dd 0
dd sound_interface ; 55-Sound interface
dd sound_interface ; 55-Sound interface
dd 0
dd sys_pcibios ; 57-PCI BIOS32
dd file_system ; 58-Common file system interface
dd sys_pcibios ; 57-PCI BIOS32
dd file_system ; 58-Common file system interface
dd 0
dd sys_IPC ; 60-Inter Process Communication
dd sys_gs ; 61-Direct graphics access
dd sys_pci ; 62-PCI functions
dd sys_msg_board ; 63-System message board
dd sys_IPC ; 60-Inter Process Communication
dd sys_gs ; 61-Direct graphics access
dd sys_pci ; 62-PCI functions
dd sys_msg_board ; 63-System message board
dd sys_resize_app_memory ; 64-Resize application memory usage
dd syscall_putimage_palette; 65-PutImagePalette
dd sys_process_def ; 66-Process definitions - keyboard
dd sys_window_move ; 67-Window move or resize
dd new_services ; 68-Some internal services
dd sys_debug_services ; 69-Debug
dd file_system_lfn ; 70-Common file system interface, version 2
dd sys_process_def ; 66-Process definitions - keyboard
dd sys_window_move ; 67-Window move or resize
dd f68 ; 68-Some internal services
dd sys_debug_services ; 69-Debug
dd file_system_lfn ; 70-Common file system interface, version 2
dd syscall_windowsettings ; 71-Window settings
dd sys_sendwindowmsg ; 72-Send window message
dd sys_sendwindowmsg ; 72-Send window message
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NEW SYSTEM FUNCTIONS TABLE ;;

View File

@ -110,8 +110,15 @@ vmode db '/sys/drivers/VMODE.MDR',0
vrr_m db 'VRR_M',0
kernel_file db 'KERNEL MNT'
align 4
;supported videomodes
shmem_list:
.bk dd shmem_list
.fd dd shmem_list
; supported videomodes
mode_1280_1024_32:
dw 1280,1024,32,60
mode_1280_1024_24:
@ -283,36 +290,37 @@ irq15read rd 16
irq_tab rd 16
mem_block_map rb 512
event_map rb 64
event_map rb 64
mem_block_list rd 64
large_block_list rd 31
mem_block_mask rd 2
large_block_mask rd 1
mem_used.fd rd 1
mem_used.bk rd 1
mem_used.fd rd 1
mem_used.bk rd 1
mem_block_arr rd 1
mem_block_start rd 1
mem_block_end rd 1
heap_mutex rd 1
heap_size rd 1
heap_free rd 1
heap_blocks rd 1
free_blocks rd 1
heap_mutex rd 1
heap_size rd 1
heap_free rd 1
heap_blocks rd 1
free_blocks rd 1
mst MEM_STATE
page_start rd 1
page_end rd 1
events rd 1
event_start rd 1
event_end rd 1
event_uid rd 1
page_start rd 1
page_end rd 1
events rd 1
event_start rd 1
event_end rd 1
event_uid rd 1
sys_page_map rd 1
os_stack_seg rd 1
srv.fd rd 1
srv.bk rd 1