User-land ring buffers.

git-svn-id: svn://kolibrios.org@7967 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2020-05-22 15:38:59 +00:00
parent 8ac977e2e4
commit d397ad5154
3 changed files with 101 additions and 7 deletions

View File

@ -1518,3 +1518,72 @@ proc shmem_close stdcall, name:dword
ret ret
endp 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

View File

@ -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 ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -78,7 +78,7 @@ proc alloc_pages stdcall, count:dword
.find: .find:
mov edx, [count] mov edx, [count]
mov edi, ecx mov edi, ecx
.match: .match:
cmp byte [ecx], 0xFF cmp byte [ecx], 0xFF
jne .next jne .next
dec edx dec edx
@ -86,14 +86,14 @@ proc alloc_pages stdcall, count:dword
inc ecx inc ecx
cmp ecx, ebx cmp ecx, ebx
jb .match jb .match
.out_of_memory: .out_of_memory:
.fail: .fail:
xor eax, eax xor eax, eax
pop edi pop edi
pop ebx pop ebx
popfd popfd
ret ret
.next: .next:
inc ecx inc ecx
cmp ecx, ebx cmp ecx, ebx
jb .find jb .find
@ -102,7 +102,7 @@ proc alloc_pages stdcall, count:dword
popfd popfd
xor eax, eax xor eax, eax
ret ret
.ok: .ok:
sub ecx, edi sub ecx, edi
inc ecx inc ecx
push esi push esi
@ -1103,7 +1103,7 @@ f68:
jbe sys_sheduler jbe sys_sheduler
cmp ebx, 11 cmp ebx, 11
jb undefined_syscall jb undefined_syscall
cmp ebx, 28 cmp ebx, 29
ja undefined_syscall ja undefined_syscall
xor eax, eax xor eax, eax
jmp dword [f68call+ebx*4-11*4] jmp dword [f68call+ebx*4-11*4]
@ -1220,6 +1220,11 @@ f68:
stdcall kernel_free, ebp stdcall kernel_free, ebp
ret ret
.29:
stdcall user_ring, ecx
mov [esp+SYSCALL_STACK._eax], eax
ret
.fail: .fail:
mov [esp+SYSCALL_STACK._eax], eax mov [esp+SYSCALL_STACK._eax], eax
ret ret
@ -1245,6 +1250,7 @@ f68call: ; keep this table closer to main code
dd f68.26 ; user_unmap dd f68.26 ; user_unmap
dd f68.27 ; load_file_umode dd f68.27 ; load_file_umode
dd f68.28 ; loadFileUnicode dd f68.28 ; loadFileUnicode
dd f68.29 ; user_ring
align 4 align 4
proc load_pe_driver stdcall, file:dword, cmdline:dword proc load_pe_driver stdcall, file:dword, cmdline:dword

View File

@ -3612,6 +3612,25 @@ Returned value:
* edx = size of the loaded file, or zero * edx = size of the loaded file, or zero
Remarks: Remarks:
* function loads file and unpacks, if necessary * 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. ====================== ====================== Function 69 - debugging. ======================