Compare commits

..
Author SHA1 Message Date
Leency 36854f1382 kernel/net: allocate socket rings from non-contiguous pages
Check kernel codestyle / Check kernel codestyle (pull_request) Successful in 34s
Test PR / Build (en_US) (pull_request) Successful in 2m38s
Test PR / Build (es_ES) (pull_request) Successful in 2m30s
Test PR / Build (ru_RU) (pull_request) Successful in 2m26s
2026-09-30 13:49:15 +03:00
Leency f990a48b98 kernel/net: check that STREAM_SOCKET fits in SOCKET_STRUCT_SIZE 2026-09-30 13:49:14 +03:00
Leency fb2906bc1d kernel: release address space when kernel_alloc fails 2026-09-30 13:49:13 +03:00
Leency 9c58dc1f04 kernel: flush the mirror half in create_ring_buffer 2026-09-30 13:49:11 +03:00
3 changed files with 85 additions and 18 deletions

No files matched your search

+8 -1
View File
@@ -463,7 +463,7 @@ proc kernel_alloc stdcall, size:dword
and eax, -PAGE_SIZE;
mov [size], eax
and eax, eax
jz .err
jz .err0
mov ebx, eax
shr ebx, 12
mov [pages_count], ebx
@@ -509,6 +509,13 @@ proc kernel_alloc stdcall, size:dword
pop ebx
ret
.err:
mov eax, [lin_addr]
test eax, eax
jz .err0
mov ecx, [pages_count]
call release_pages
stdcall free_kernel_space, [lin_addr]
.err0:
xor eax, eax
pop edi
pop ebx
+72 -16
View File
@@ -1233,27 +1233,25 @@ f68:
mov eax, [ecx + SRV.entry]
test eax, eax
jz .fail
mov eax, -2 ;error free RAM
cmp [ecx + SRV.base], 0
je .fail
push ecx ;save handl
push ecx ;save handl
mov ebp, esp ;START may be cdecl or stdcall
push edx ;cmdline
push DRV_EXIT
call [ecx + SRV.entry] ;the result is not checked
mov esp, ebp
pop esi
call eax ;the result is not checked
lea esp, [esp+8]
push ecx
mov eax, [esi + SRV.fd]
mov edx, [esi + SRV.bk]
mov ebx, [ecx + SRV.base]
mov eax, -2 ;error free RAM
test ebx, ebx
jz .fail
stdcall kernel_free, ebx ;del driver
mov eax, [ecx + SRV.fd]
mov edx, [ecx + SRV.bk]
mov [edx + SRV.fd], eax
mov [eax + SRV.bk], edx
push eax
stdcall kernel_free, [esi + SRV.base] ;del driver
mov eax, esi
call free ;eax = mem
pop eax
stdcall free, ecx
;dec [count_services]
mov [esp + SYSCALL_STACK.eax], eax
@@ -1399,7 +1397,9 @@ proc create_ring_buffer stdcall, size:dword, flags:dword
mov [page_tabs + edi], eax
mov [page_tabs + edi + edx], eax
invlpg [ebx]
invlpg [ebx+0x10000]
add ebx, [size]
invlpg [ebx] ; the mirror half
sub ebx, [size]
add eax, 0x1000
add ebx, 0x1000
add edi, 4
@@ -1418,6 +1418,62 @@ proc create_ring_buffer stdcall, size:dword, flags:dword
ret
endp
; Same as create_ring_buffer, but from non-contiguous pages.
; Not for DMA. Free with kernel_free.
align 4
proc create_ring_buffer_sparse stdcall, size:dword, flags:dword
locals
buf_ptr dd ?
endl
mov eax, [size]
test eax, eax
jz .fail
add eax, eax
stdcall alloc_kernel_space, eax
test eax, eax
jz .fail
mov [buf_ptr], eax
push ebx esi edi
mov ebx, eax ; page being mapped
mov esi, [size] ; distance to its mirror
mov edi, esi
shr edi, 12 ; pages left
.page:
call alloc_page
test eax, eax
jz .mm_fail
or eax, [flags]
mov edx, ebx
shr edx, 12
mov [page_tabs + edx*4], eax
invlpg [ebx]
lea edx, [ebx + esi]
shr edx, 12
mov [page_tabs + edx*4], eax
invlpg [ebx + esi]
add ebx, PAGE_SIZE
dec edi
jnz .page
mov eax, [buf_ptr]
pop edi esi ebx
ret
.mm_fail:
mov eax, [buf_ptr]
mov ecx, [size]
shr ecx, 11 ; both halves, in pages
call release_pages
stdcall free_kernel_space, [buf_ptr]
pop edi esi ebx
xor eax, eax
.fail:
ret
endp
align 4
proc print_mem
+5 -1
View File
@@ -198,6 +198,10 @@ ends
SOCKET_STRUCT_SIZE = 4096 ; in bytes
if sizeof.STREAM_SOCKET > SOCKET_STRUCT_SIZE
err "STREAM_SOCKET does not fit in SOCKET_STRUCT_SIZE"
end if
SOCKET_QUEUE_SIZE = 10 ; maximum number of incoming packets queued for 1 socket
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
SOCKET_QUEUE_LOCATION = (SOCKET_STRUCT_SIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
@@ -1647,7 +1651,7 @@ socket_ring_create:
mov esi, eax
push edx
stdcall create_ring_buffer, SOCKET_BUFFER_SIZE, PG_SWR
stdcall create_ring_buffer_sparse, SOCKET_BUFFER_SIZE, PG_SWR
pop edx
test eax, eax
jz .fail