Commit Graph
100 Commits
Author SHA1 Message Date
Bananymous 8091127150 Kernel: Add page table api to map multiple fast pages
This is not currently used, but can be handy in the future
2026-05-04 20:26:02 +03:00
Bananymous 74127c0f45 Kernel: Cleanup inline assembly accessing cpu specific data 2026-05-04 20:26:02 +03:00
Bananymous 28499b890c LibC: Mark exit as noreturn 2026-05-04 20:26:02 +03:00
Bananymous 2f45349658 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-04 20:26:02 +03:00
Bananymous fde085e04b 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-04 20:26:02 +03:00
Bananymous 77ca525552 BAN: Fix HashSet 2026-05-04 20:26:02 +03:00
Bananymous 3b83daef17 Kernel: Use empty string instead of nullptr for non existing proc name 2026-05-04 20:26:01 +03:00
Bananymous f37d9dbdb1 Kernel: Remove kmalloc_vaddr_of
This is no longer needed. It was only used for x86_64 paging and AP
stack initialization
2026-05-04 20:26:01 +03:00
Bananymous b7cedad891 Kernel: Wrap syscall macro value in paranthesis 2026-05-04 20:26:01 +03:00
Bananymous cdf0de34fb Kernel: Stop stacktrace dump on null bp
This makes stack traces not crash before IDT is initialized
2026-05-04 20:26:01 +03:00
Bananymous 03fccdffe1 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-04 20:26:01 +03:00
Bananymous 1602b195c5 ports: Rework ssl certificates
ca-certificates:
 - update to 2026.03.19
 - install to /etc/cacert
 - extract individual ceritificates from the bundle

openssl:
 - depend on ca-certificates
 - install hashed symlinks to individual certs

curl:
 - don't depend on ca-certificates; openssl handles this
 - set both ca-bundle and ca-path
2026-04-28 02:23:46 +03:00
Bananymous 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
Bananymous ab8bcbec3e Kernel: Allow mapping dma regions as not uncached 2026-04-27 19:36:32 +03:00
Bananymous 0e00b72df6 BAN: Cleanup HashMap
Add a concept for HashMapFindable instead of manually specifying the
requries expression everywhere.

Allow HashMapFindable also for `remove`, `contains`, `operator[]`, `at`

Make Entry have a const Key. This allows iterator's operator* and
operator-> return values have const keys.
2026-04-25 22:10:01 +03:00
Bananymous a63818ec33 BAN: Cleanup HashSet
Add a concept for HashSetFindable instead of manually specifying the
requries expression everywhere.

Allow HashSetFindable also for `remove` and `contains`.

Remove non-const return values from iterator; you should never modify
the hashed value in place.

Don't require key to be move assignable, move construction is enough.
2026-04-25 22:10:01 +03:00
Bananymous cf2e8ffaff Kernel: Remove unnecessary custom RefPtr hashes
RefPtr now exposes its own default hash
2026-04-25 22:10:01 +03:00
Bananymous b5647ff258 BAN: Rewrite RefPtr,UniqPtr const semantics
const RefPtr<T> now allows accessing T as non-const. Also add default
hash function for RefPtr and UniqPtr based on the pointer value
2026-04-25 22:10:01 +03:00
Bananymous bef53c726b Userspace: Install libdl, libm, libpthread as symlinks to libc
Having dummy libraries was just unnecessary
2026-04-21 21:46:00 +03:00
Bananymous 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
Bananymous 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
Bananymous eea0154f18 LibC: Cleanup RNG and properly initialize to srand(1) at startup 2026-04-21 00:26:41 +03:00
Bananymous ea4c34fc0b LibC: Fix printf thread safety
I don't know why I was using a static buffer for value conversions :D
2026-04-21 00:25:56 +03:00
Bananymous 558ed8fd44 LibC: Define pthread_{equal,self} as macros
These really should get inlined :D
2026-04-21 00:25:16 +03:00
Bananymous 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
Bananymous 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
Bananymous 0ee50032f3 Kernel: Fix 32 bit signal trapoline offset 2026-04-21 00:19:33 +03:00
Bananymous 40f3546aca BAN: Rewrite HashMap as a wrapper around HashSet
There is really no need to have two implementation of the same thing.
Only difference now is that HashMap's value type has to be movable but
this wasn't an issue
2026-04-21 00:18:18 +03:00
Bananymous 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
Bananymous fe613e4274 BAN: Rewrite HashSet
Instead of representing the map as vector or linked lists which required
an allocation for every insertion and deallocation for removal, we now
store a single big contiguous block of memory and use hash chains to
handle collisions. This intuitively feels much better although I did not
run any benchmarks.
2026-04-21 00:14:24 +03:00
Bananymous 3264dcee44 BAN: Add Math::round_up_to_power_of_two 2026-04-21 00:14:24 +03:00
Bananymous 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
Bananymous 5b7b2d7ac3 Kernel: Fix memory leak when cleaning up inodes shared page cache 2026-04-19 17:52:21 +03:00
Bananymous 8e543195b1 Kernel: Check for null in pthread_join 2026-04-19 17:52:21 +03:00
Bananymous a24ec0da2b LibC: Don't complain about stack size until 8192 bytes
It was unnecessary as userspace stack is way bigger than that...
2026-04-19 17:52:21 +03:00
Bananymous e6284c3cf3 LibC/Kernel: Bump PATH_MAX to 4096 2026-04-19 17:52:21 +03:00
Bananymous c04ad65f7f LibC: Add mbsinit and wcsrtombs stubs 2026-04-17 18:40:18 +03:00
Bananymous af17b29414 ports: Add xz port 2026-04-17 18:39:18 +03:00
Bananymous 7badcf80cf ports: Add libarchive port 2026-04-17 18:37:41 +03:00
Bananymous 7f122d9e89 ports: Add bzip2 port 2026-04-17 18:37:30 +03:00
Bananymous 984c7c0a89 LibGUI: Fix packet sending and cleanup receiving 2026-04-15 21:52:51 +03:00
Bananymous ce318c7930 LibGUI: Cleanup packet {,de}serialization 2026-04-15 21:52:13 +03:00
Bananymous eff6c79e9e ports/xbanan: Update to a working version
Also don't depend on mesa or Xlib. We only need the protocol headers to
compile the project
2026-04-15 19:25:54 +03:00
Bananymous aaade52146 LibC: Use __builtin_thread_pointer for _get_uthread()
This generates much nicer assembly as it does not have to read thread
pointer for every access to TCB (errno, cancel_state, cancelled) and
instead it can read it once and use the same value for all accesses
2026-04-15 17:32:43 +03:00
Bananymous 1bf5e6a051 WindowServer: Fix xbanan access check 2026-04-15 16:40:30 +03:00
Bananymous 394719a909 userspace: Fix some includes found when compiling to linux 2026-04-15 16:39:36 +03:00
Bananymous 3ebadc5c74 LibDEFLATE: Optimize decompression
Instead of calculating bit-by-bit crc32, we now calculate a lookup table
during compile time. The old crc32 calculation was taking almost 50% of
the decompression time.

Also handle multiple symbols at once without outputting to user. It is
much more efficient to output many bytes instead of the up to 258 that a
single symbol can decode to :^)
2026-04-14 01:50:30 +03:00
Bananymous 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
Bananymous c849293f3d Kernel: Add support for loading gzip compressed initrd 2026-04-13 16:48:57 +03:00
Bananymous 0156d06cdc LibDEFLATE: Support decompressing to/from partial buffer
We no longer require the user to pass full compressed data in one go,
instead the decompressor reports to the user if it needs more input or
output space.
2026-04-13 03:04:55 +03:00
Bananymous ad12bf3e1d LibC: Cleanup environment variable code 2026-04-13 00:36:13 +03:00
Bananymous 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
Bananymous 87979b1627 LibImage: Don't allocate zlib stream to a contiguous buffer
We can now pass multiple buffers to the decoder!
2026-04-11 19:48:46 +03:00
Bananymous fed9dbefdf LibDEFLATE: Allow decompression from multiple byte spans
Before we required the compressed data to live in a single contiguous
chunch of memory.
2026-04-11 19:47:44 +03:00
Bananymous 2984927be5 WindowServer: Block without timeout when there is no damaged regions 2026-04-11 08:41:21 +03:00
Bananymous 2e654b53fa WindowServer: Use rectangular framebuffer syncs 2026-04-11 08:30:15 +03:00
Bananymous 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
Bananymous 2b97587e9f WindowServer: Rewrite damaged region tracking
Instead of immediately doing rerender of client data and syncing 60 Hz,
we now only keep track of the damaged regions and also do the rerender
step 60 Hz.
2026-04-11 08:26:22 +03:00
Bananymous 4bde088b28 WindowServer: Store rectangles as min and max bounds
This makes some math easier than x,y and w,h
2026-04-11 06:35:45 +03:00
Bananymous 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
Bananymous 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
Bananymous 7333008f40 LibC: Use IP instead of si_addr for faulting instruction
si_addr only means faulting instruction for SIGILL. For SIGSEGV it is
the faulting memory address.
2026-04-11 03:30:52 +03:00
Bananymous 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
Bananymous a4ba1da65a LibGUI/WindowServer: Rework packet serialization
Instead of sending while serializing (what even was that), we serialize
the whole packet into a buffer which can be sent in one go. First of all
this reduces the number of sends by a lot. This also fixes WindowServer
ending up sending partial packets when client is not responsive.
Previously we would just try sending once, if any send failed the send
was aborted while partial packet was already transmitted. This lead to
packet stream being out of sync leading to the client killing itself.
Now we allow 64 KiB outgoing buffer per client. If this buffer ever fills
up, we will not send partial packets.
2026-04-11 03:30:52 +03:00
Bananymous 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
Bananymous 279ac6b2b6 BAN: Implement some macro utilities
This contains stuff to count arguments, stringify, concatinate, for_each
2026-04-11 03:30:52 +03:00
Bananymous 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
Bananymous 80c4213501 LibC: Make errno macro directly access uthread
This allows inlining errno usages

This breaks libc ABI and requires toolchain rebuild
2026-04-11 03:30:32 +03:00
Bananymous e0af23a924 LibC: Move uthread definition to its own header
Use `__asm__` instead of `asm` to allow compilation with --std=c99 and
before
2026-04-11 03:30:32 +03:00
Bananymous 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
Bananymous 7fb27b16e8 LibC: Fix pthread cancellation
Install SIGCANCEL handler for all threads.

Remove unneeded atomic stores and loads. States are only changed within
the thread itself.

Define pthread_testcancel as a macro so it gets inlined inside
cancellation points
2026-04-07 03:41:25 +03:00
Bananymous 3fb903d991 LibGUI: Optimize invalidate and set alpha channel
If the window does not have an alpha channel, we now set every pixel's
alpha to 0xFF. This is needed by the WindowServer when it does alpha
blending, there used to be some weird stuff happening on overlapping
windows.

Also when we are invalidating a region with width of the whole window,
we can do a single memcpy instead of a memcpy for each row separately.
2026-04-06 19:29:34 +03:00
Bananymous 2a4a688c2d WindowServer: Optimize rendering
We now use SSE2 to do alpha blending on 4 pixels at a time where
possible and use memcpy instead of manual loops for non blended regions.
2026-04-06 19:29:34 +03:00
Bananymous 1487c86262 Kernel: Resolve \\_S5 package elements on poweroff 2026-04-06 19:29:34 +03:00
Bananymous 4d3751028b LibInput: Honor chroot and credentials when loading keymap 2026-04-06 19:29:34 +03:00
Bananymous 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
Bananymous 34b59f062b LibC: Implement blocking pthread_rwlock
pthread_rwlock now uses a mutex and condition variable internally so it
doesn't need to yield while waiting!
2026-04-06 19:29:34 +03:00
Bananymous ec4aa8d0b6 LibC: Fix shared pthread_barrier init
Initialize internal lock and cond as shared when the barrier is shared
2026-04-05 12:06:18 +03:00
Bananymous 1eebe85071 LibC: Fix pthread_cond_timedwait
If timeout occurred, I was not removing the entry from block list
2026-04-05 11:31:16 +03:00
Bananymous db0507e670 LibC: Mark pthread_exit noreturn 2026-04-05 11:30:45 +03:00
Bananymous 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
Bananymous 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
Bananymous 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
Bananymous 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
Bananymous 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
Bananymous 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
Bananymous 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
Bananymous 47d85eb281 Kernel: Pass the actual vaddr range to reserve pages 2026-04-04 23:48:43 +03:00
Bananymous 85f676c30a DynamicLoader: Calulate max loaded file count based on dtv size
dtv should be dynamic but i dont care right now :)
2026-04-04 23:48:43 +03:00
Bananymous 8c5fa1c0b8 DynamicLoader: Fix R_386_PC32 relocation
I was not accounting elf base with offset
2026-04-04 23:48:43 +03:00
Bananymous c7690053ae LibC: Don't crash on 32 bit pthread_create 2026-04-04 23:48:43 +03:00
Bananymous 3f55be638d Kernel: Allow reserve_free_page{,s} to fail
Apparently I was asserting here before :D
2026-04-04 23:48:43 +03:00
Bananymous 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
Bananymous e239d9ca55 ports/SDL2: Use 48 kHz floats instead of 44.1 kHz PCM16 2026-04-03 16:17:16 +03:00
Bananymous bf1d9662d7 LibAudio: Use floats instead of doubles for samples 2026-04-03 16:15:02 +03:00
Bananymous 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
Bananymous c09bca56f9 Kernel: Add fast write perm remove to page tables 2026-04-03 01:54:22 +03:00
Bananymous 7d8f7753d5 Kernel: Cleanup and fix page tables and better TLB shootdown 2026-04-03 01:53:30 +03:00
Bananymous 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
Bananymous 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