Commit Graph

1892 Commits

Author SHA1 Message Date
DcraftBg
d2c5242267 Kernel: Fix ByteRingBuffer->back() 2026-05-02 20:48:02 +03:00
96ae432bcf fixup 2026-05-02 20:05:13 +03:00
d08f7b1dee Kernel: Cleanup inline assembly accessing cpu specific data 2026-05-02 18:29:07 +03:00
33ea0f07b7 Kernel: Calculate internet checksum in host endian
No need to swap bytes of every 16 bit word in the packet, we can just do
one swap at the return
2026-05-02 18:11:29 +03:00
3874e0ed1e Kernel: Pass current cpu index as a GDT limit
I had no idea LSL was an instruction. This cleans up code to get the
current cpu by a lot and does not require extra segment usage :D
2026-05-02 18:10:10 +03:00
73b03860f4 Kernel: Use empty string instead of nullptr for non existing proc name 2026-05-02 15:54:37 +03:00
b9754859b2 Kernel: Remove kmalloc_vaddr_of
This is no longer needed. It was only used for x86_64 paging and AP
stack initialization
2026-05-02 15:53:29 +03:00
da50b654ab Kernel: Wrap syscall macro value in paranthesis 2026-05-02 15:52:18 +03:00
8869cc7b8c Kernel: Stop stacktrace dump on null bp
This makes stack traces not crash before IDT is initialized
2026-05-02 15:51:12 +03:00
d2b9b49cb0 Kernel: Rewrite paging and AP initialization
Initial step of paging now just prepares fast page for heap, actual page
table initialization happens after heap is initialized which allows
x86_64 to never depend on kmalloc for pages.

Processor's stacks are now also spawned with PMM/VMM allocated stacks
instead of kmalloc identity mapped.
2026-05-02 15:45:08 +03:00
1486ad7aa5 Kernel: Don't map NIC buffers as uncached
There is no need for them to be uncached. Having them as uncached killed
the networking performance, over 90% time was spent in kernel out of
which 80% was in checksum calculation and memcpy, half each (measured in
qemu with e1000e)
2026-04-27 19:45:16 +03:00
ab8bcbec3e Kernel: Allow mapping dma regions as not uncached 2026-04-27 19:36:32 +03:00
cf2e8ffaff Kernel: Remove unnecessary custom RefPtr hashes
RefPtr now exposes its own default hash
2026-04-25 22:10:01 +03:00
6b43cadf3a Kernel: Implement stack trace dump with safe memcpy
This fixes kernel panic if the stack trace cannot be read. Manually
validating pointers is definitely not safe
2026-04-21 21:20:52 +03:00
b74812d669 Kernel: Remove unnused features from VirtualRange
On-demand paging has not been used ever since I made userspace stack be
a normal MemoryRegion.
2026-04-21 19:58:09 +03:00
8665195350 Kernel: Allow main thread to call pthread_exit
Apparently this is allowed. Also when last thread calls pthread_join
the process should also exit
2026-04-21 00:23:35 +03:00
72a24a0d38 Kernel: Reorder FUTEX_WAIT value and timeout check
Return EAGAIN rather than ETIMEDOUT if value does not match at futex
entry
2026-04-21 00:20:37 +03:00
0ee50032f3 Kernel: Fix 32 bit signal trapoline offset 2026-04-21 00:19:33 +03:00
a8e496310b Kernel: Use HashMap for fd->epoll_event mapping
I don't know why it was a static array :D
2026-04-21 00:14:24 +03:00
71649ffe09 Kernel Rework ThreadBlocker
I don't know why I though the block chain had to be stored fully in the
ThreadBlocker, that did not even fix the problem I was trying to fix
when I last rewrote it. Roll back to doubly linked list of block chain
and now just check that the node is contained within the ThreadBlocker
before removing and after acquiring the ThreadBlocker's lock. Also there
is no need to have a separate lock the node's blocker field. We can just
perform an atomic reads and writes to it. We can still get a blocker
that the node is no longer part of, but this can be resolved with a
simple check. This patch reduces ThreadBlocker's size from over 200
bytes to just 12 bytes +4 bytes padding
2026-04-20 12:50:09 +03:00
5b7b2d7ac3 Kernel: Fix memory leak when cleaning up inodes shared page cache 2026-04-19 17:52:21 +03:00
8e543195b1 Kernel: Check for null in pthread_join 2026-04-19 17:52:21 +03:00
e6284c3cf3 LibC/Kernel: Bump PATH_MAX to 4096 2026-04-19 17:52:21 +03:00
d471bbf856 Kernel: Cleanup bootloader headers
Also add custom load addresses for x86_64 target. This allows qemu to
load the kernel with -kernel argument. Without these addresses qemu
would refuse to load as it only supports 32 bit ELFs, but as our kernel
starts in 32 bit mode anyway, we can just load it!
2026-04-13 16:48:57 +03:00
c849293f3d Kernel: Add support for loading gzip compressed initrd 2026-04-13 16:48:57 +03:00
42964ad0b4 Kernel: Remove concept of OpenFile
This was just RefPtr<OpenFileDescription> and descriptor flags.
Descriptor flags only define O_CLOEXEC, so we can just store fd's
cloexec status in a bitmap rather than separate fields. This cuts down
the size of OpenFileDescriptorSet to basically half!
2026-04-12 04:42:08 +03:00
ac6e6f3ec1 Kernel: Add ioctl to sync rectangular areas in framebuffer
msync is not really the best API for framebuffer synchronization
2026-04-11 08:29:10 +03:00
2a9dad2dd8 LibC: Add SSE2 non-temporal memset and memcpy
Also cleanup other assembly by using local labels to emit them from the
assembled program.
2026-04-11 03:30:52 +03:00
d11160d2f7 Kernel: Fix si_addr reporting
Meaning of this is signal specific and not the instruction pointer
2026-04-11 03:30:52 +03:00
cd7d309fd1 Kernel: Push missing IP and SP to mcontext in signal handler
I was missing these two registers, messing up the whole siginfo_t
structure. This fixes libc's stack trace dump crashing :D
2026-04-11 03:30:52 +03:00
2f9b8b6fc9 Kernel/LibC: Rework userspace syscall interface
Kernel syscall API no longer zeros all unused argument registers and
libc now uses inlined syscall macro internally. This significantly
cleans up generated code for basic syscall wrapper functions.
2026-04-11 03:30:52 +03:00
9084d9305c Kernel: Change preemption condition
Instead of keeping track of the current time and rescheduling when
interval has passed, keep track of the next expected reschedule time.
This prevents theoretically missing every second pre-emption when
scheduler's timer is interrupting at same rate as the interval.
2026-04-11 03:30:52 +03:00
7e907b70f6 Kernel: Store memory region size as uint64_t
On 32 bit target, we were storing 32 bit physical region sizes which
would truncate regions > 4 GiB
2026-04-07 03:41:25 +03:00
1487c86262 Kernel: Resolve \\_S5 package elements on poweroff 2026-04-06 19:29:34 +03:00
e4c6539964 Kernel: Be more clever with physical memory
Initially allocate all physical memory except kernel memory and boot
modules. Before we just skipped all memory before kernel boot modules.
Also release memory used by boot modules after the kernel is up and
running. Once the boot modules are loaded, there is no need to keep them
in memory.
2026-04-06 19:29:34 +03:00
1e3ca7dc18 Kernel: Fix signal related syscalls
There were missing locks, out of order sigprocmask, incorrect signal
masking...
2026-04-05 02:31:30 +03:00
8ca3c5d778 Kernel: Clean up signal handling
We now appreciate sa_mask and SA_NODEFER and change the signal mask for
the duration of signal handler. This is done by making a sigprocmask
syscall at the end of the signal handler. Back-to-back signals will
still grow stack as original registers are popped AFTER the block mask
is updated. I guess this is why linux has sigreturn(?).
2026-04-05 02:25:59 +03:00
df257755f7 Kernel: If userspace sets fs or gs, dont overwrite it
Current cpu index is stored at either segment. If userspace sets that
segment, kernel will not overwrite it on every reschedule. This is fine
as long as user program does not use anything that relies on it :)
2026-04-04 23:48:43 +03:00
d7e292a9f8 Kernel: Drop 32 bit userspace stack to 4 MiB
32 bit userspace only has 256 MiB reserved for stacks, so with 32 MiB
stacks it only allowed total of 7 threads. Now we can have up to 62
threads
2026-04-04 23:48:43 +03:00
9fce114e8e Kernel: Don't clone entire kernel stack on fork
We only need to copy area between [ret_sp, stack_end]. This range is
always very small compared to the whole stack (64 KiB).
2026-04-04 23:48:43 +03:00
9d83424346 Kernel: Remove unnecessary stack pointer loading
Any time I started a thread I was loading the stack pointer which is
already correctly passed :D
2026-04-04 23:48:43 +03:00
a29681a524 Kernel: Fix signal generation
We need to have interrupts enabled when signal kills the process as
process does mutex locking. Also signals are now only checked when
returning to userspace in the same place where userspace segments are
loaded.
2026-04-04 23:48:43 +03:00
47d85eb281 Kernel: Pass the actual vaddr range to reserve pages 2026-04-04 23:48:43 +03:00
3f55be638d Kernel: Allow reserve_free_page{,s} to fail
Apparently I was asserting here before :D
2026-04-04 23:48:43 +03:00
664c824bc0 Kernel: Keep fast page always reserved
There was a bug where 32 bit target's reserve_free_page was allocating
the fast page address
2026-04-04 23:48:43 +03:00
675c215e6a Kernel: Add CoW support to MemoryBackedRegion
This speeds up fork by A LOT. Forking WindowServer took ~90 ms before
this and now its ~5 ms.
2026-04-03 01:54:59 +03:00
c09bca56f9 Kernel: Add fast write perm remove to page tables 2026-04-03 01:54:22 +03:00
7d8f7753d5 Kernel: Cleanup and fix page tables and better TLB shootdown 2026-04-03 01:53:30 +03:00
f77aa65dc5 Kernel: Cleanup accessing userspace memory
Instead of doing page validiation and loading manually we just do simple
memcpy and handle the possible page faults
2026-04-02 16:36:33 +03:00
9589b5984d Kernel: Move USERSPACE_END to lower half
This allows calculating distance to USERSPACE_END from lower half
address
2026-04-02 16:34:47 +03:00