mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-26 16:37:30 +03:00
User-land ring buffers.
git-svn-id: svn://kolibrios.org@7967 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
8ac977e2e4
commit
d397ad5154
@ -1518,3 +1518,72 @@ proc shmem_close stdcall, name:dword
|
||||
ret
|
||||
endp
|
||||
|
||||
|
||||
|
||||
proc user_ring stdcall, size:dword
|
||||
|
||||
locals
|
||||
virt_ptr dd ?
|
||||
phys_ptr dd ?
|
||||
num_pages dd ?
|
||||
endl
|
||||
|
||||
; Size must be an exact multiple of pagesize
|
||||
mov eax, size
|
||||
test eax, PAGE_SIZE-1
|
||||
jnz .exit
|
||||
|
||||
; We must have at least one complete page
|
||||
shr eax, 12
|
||||
jz .exit
|
||||
mov [num_pages], eax
|
||||
|
||||
; Allocate double the virtual memory
|
||||
mov eax, [size]
|
||||
shl eax, 1
|
||||
jz .exit
|
||||
stdcall user_alloc, eax
|
||||
test eax, eax
|
||||
jz .exit
|
||||
mov [virt_ptr], eax
|
||||
|
||||
; Now allocate physical memory
|
||||
stdcall alloc_pages, [num_pages]
|
||||
test eax, eax
|
||||
jz .exit_free_virt
|
||||
mov [phys_ptr], eax
|
||||
|
||||
; Map first half of virtual memory to physical memory
|
||||
push ecx esi edi
|
||||
mov ecx, [num_pages]
|
||||
mov esi, [virt_ptr]
|
||||
mov edi, [phys_ptr]
|
||||
.loop1:
|
||||
stdcall map_page, esi, edi, PG_UWR
|
||||
add esi, PAGE_SIZE
|
||||
add edi, PAGE_SIZE
|
||||
dec ecx
|
||||
jnz .loop1
|
||||
|
||||
; Map second half of virtual memory to same physical memory
|
||||
mov ecx, [pages]
|
||||
mov edi, [phys_ptr]
|
||||
.loop2:
|
||||
stdcall map_page, esi, edi, PG_UWR
|
||||
add esi, PAGE_SIZE
|
||||
add edi, PAGE_SIZE
|
||||
dec ecx
|
||||
jnz .loop2
|
||||
pop edi esi ecx
|
||||
|
||||
mov eax, [virt_ptr]
|
||||
ret
|
||||
|
||||
.exit_free_virt:
|
||||
stdcall user_free, [virt_ptr]
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
endp
|
@ -1,6 +1,6 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; ;;
|
||||
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
||||
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
|
||||
;; Distributed under terms of the GNU General Public License ;;
|
||||
;; ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@ -78,7 +78,7 @@ proc alloc_pages stdcall, count:dword
|
||||
.find:
|
||||
mov edx, [count]
|
||||
mov edi, ecx
|
||||
.match:
|
||||
.match:
|
||||
cmp byte [ecx], 0xFF
|
||||
jne .next
|
||||
dec edx
|
||||
@ -86,14 +86,14 @@ proc alloc_pages stdcall, count:dword
|
||||
inc ecx
|
||||
cmp ecx, ebx
|
||||
jb .match
|
||||
.out_of_memory:
|
||||
.fail:
|
||||
.out_of_memory:
|
||||
.fail:
|
||||
xor eax, eax
|
||||
pop edi
|
||||
pop ebx
|
||||
popfd
|
||||
ret
|
||||
.next:
|
||||
.next:
|
||||
inc ecx
|
||||
cmp ecx, ebx
|
||||
jb .find
|
||||
@ -102,7 +102,7 @@ proc alloc_pages stdcall, count:dword
|
||||
popfd
|
||||
xor eax, eax
|
||||
ret
|
||||
.ok:
|
||||
.ok:
|
||||
sub ecx, edi
|
||||
inc ecx
|
||||
push esi
|
||||
@ -1103,7 +1103,7 @@ f68:
|
||||
jbe sys_sheduler
|
||||
cmp ebx, 11
|
||||
jb undefined_syscall
|
||||
cmp ebx, 28
|
||||
cmp ebx, 29
|
||||
ja undefined_syscall
|
||||
xor eax, eax
|
||||
jmp dword [f68call+ebx*4-11*4]
|
||||
@ -1220,6 +1220,11 @@ f68:
|
||||
stdcall kernel_free, ebp
|
||||
ret
|
||||
|
||||
.29:
|
||||
stdcall user_ring, ecx
|
||||
mov [esp+SYSCALL_STACK._eax], eax
|
||||
ret
|
||||
|
||||
.fail:
|
||||
mov [esp+SYSCALL_STACK._eax], eax
|
||||
ret
|
||||
@ -1245,6 +1250,7 @@ f68call: ; keep this table closer to main code
|
||||
dd f68.26 ; user_unmap
|
||||
dd f68.27 ; load_file_umode
|
||||
dd f68.28 ; loadFileUnicode
|
||||
dd f68.29 ; user_ring
|
||||
|
||||
align 4
|
||||
proc load_pe_driver stdcall, file:dword, cmdline:dword
|
||||
|
@ -3612,6 +3612,25 @@ Returned value:
|
||||
* edx = size of the loaded file, or zero
|
||||
Remarks:
|
||||
* function loads file and unpacks, if necessary
|
||||
======================================================================
|
||||
======== Function 68, subfunction 29 - allocate ring memory. =========
|
||||
======================================================================
|
||||
Parameters:
|
||||
* eax = 68 - function number
|
||||
* ebx = 29 - subfunction number
|
||||
* ecx = required size in bytes
|
||||
Returned value:
|
||||
* eax = 0 - failed
|
||||
* eax = pointer to the allocated ring
|
||||
Remarks:
|
||||
* The requested size must be an exact multiple of pagesize (4 Kb)
|
||||
* The function allocates memory in such a way that you can read and
|
||||
write beyond the size of the allocated memory and will reach the
|
||||
beginning of the buffer again.
|
||||
|
||||
---------------------- Constants for registers: ----------------------
|
||||
eax - SF_SYS_MISC (68)
|
||||
ebx - SSF_MEM_ALLOC_RING (29)
|
||||
|
||||
======================================================================
|
||||
====================== Function 69 - debugging. ======================
|
||||
|
Loading…
Reference in New Issue
Block a user