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
4 changed files with 79 additions and 50 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
+59 -1
View File
@@ -1397,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
@@ -1416,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
+7 -47
View File
@@ -23,7 +23,6 @@ ARP_AWAITING_RESPONSE = 2
ARP_RESPONSE_TIMEOUT = 3
ARP_REQUEST_TTL = 31 ; 20 s
ARP_WAIT_TICKS = 100 ; 1 s
ARP_ENTRY_TTL = 937 ; 600 s
ARP_STATIC_ENTRY = -1
@@ -566,10 +565,10 @@ arp_ip_to_mac:
; Now send a request packet on the network
pop edi eax ; IP in eax, device number in ebx, for ARP_output_request
push eax esi edi ; arp_output_request trashes eax
push esi edi
mov ebx, [net_device_list + edi]
call arp_output_request
pop edi esi eax
pop edi esi
.found_it:
cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING ; Does it have a MAC assigned?
je .valid
@@ -578,50 +577,11 @@ if ARP_BLOCK
cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE ; Are we waiting for reply from remote end?
jne .give_up
; Only applications may wait for the reply, kernel threads give up at once
push ecx edx
mov edx, [current_slot]
cmp [edx + APPDATA.priority], MAX_PRIORITY
je .wait_over
mov edx, [timer_ticks]
add edx, ARP_WAIT_TICKS
.wait:
push ebx
mov ebx, 1 ; sleep 10 ms
call delay_hs
pop ebx
; The entry may have moved (arp_del_entry), find it again
cmp [esi + ARP_entry.IP], eax
je .same_entry
mov ecx, [ARP_entries + edi]
test ecx, ecx
jz .wait_over
mov esi, edi
imul esi, (sizeof.ARP_entry * ARP_TABLE_SIZE)/4
add esi, ARP_table + ARP_entry.IP
.rescan:
cmp [esi], eax
je .same_entry
add esi, sizeof.ARP_entry
dec ecx
jnz .rescan
jmp .wait_over
.same_entry:
cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING
je .wait_done
cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE
jne .wait_over
mov ecx, [timer_ticks]
sub ecx, edx
js .wait
.wait_over:
pop edx ecx
jmp .give_up
.wait_done:
pop edx ecx
push esi
mov esi, 10 ; wait 10 ms
call delay_ms
pop esi
jmp .found_it ; now check again
else
+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