Commit Graph

39 Commits

Author SHA1 Message Date
1d07d8e08e LibC/DynamicLoader: Add support for dynamically loaded TLS
Previously I failed to dlopen if any of the objects contained TLS
section
2026-03-17 20:01:51 +02:00
2961a49dc7 Kernel: Optimize futexes
Add support for processor local futexes. These work the exact same way
as global ones, but only lock a process specific lock and use a process
specific hash map.

Also reduce the time futex lock is held. There was no need to hold the
global lock while validating addresses in the process' address space.
2026-01-09 22:27:59 +02:00
89c0ff1a9d Kernel/LibC: Replace SYS_{GET,SET}_TLS with SYS_{SET,GET}_{FS,GS}BASE
This allows userspace to use both registers
2025-11-13 04:20:53 +02:00
fb61cab70d LibC: Rewrite pthread_mutex using a futex 2025-08-21 02:52:49 +03:00
eb7922ab88 LibC: Implement pthread_cond_* using a futex 2025-08-05 03:09:24 +03:00
658a001d91 LibC: Make pthread_barrier safe
It used to deadlock and it was not safe if more threads than the target
were attempting to wait on it.
2025-08-05 03:09:24 +03:00
57c9f5a8a8 LibC: lock mutex when pthread_cond_timedwait times out 2025-08-05 03:09:24 +03:00
d25a5034db LibC: Update thread id on fork 2025-08-05 03:09:24 +03:00
f197d39aaf LibC: Don't allow pthread_join to return EINTR 2025-08-05 03:09:24 +03:00
4a95343936 LibC: Make _get_uthread a macro
This allows nice inlining :)
2025-08-05 03:09:24 +03:00
4e705a91af LibC: Fix pthread keys
I had misunderstood how these are supposed to work :D
2025-08-05 03:09:24 +03:00
0f2c02fb04 LibC: Add stubs for pthread_{get,set}schedparam 2025-06-28 16:55:13 +03:00
f9451915b9 LibC: Use pause in pthread spinlock locking 2025-06-16 15:07:58 +03:00
5ad7d7edb1 DynamicLoader: Fix TLS on 32 bit platform
There were two problems with my previous implementation
- TLS was not allocated if nothing used it. There is a fallback
  initialization in _init_libc, but this was not enough if one of the
  init functions tried to access errno.
- __tls_get_addr was not resolved. If __tls_get_addr was called through
  a plt entry, everything would just break :(
2025-06-06 16:27:07 +03:00
df7f245cf8 LibC: Implement pthread_atfork
Again this code is not tested but *feels* right :D
2025-06-01 13:48:03 +03:00
dbdefa0f4a LibC: Implement pthread cancelation
This code is not tested at all but it looks correct xD
2025-06-01 13:48:03 +03:00
c957f1ddca LibC: Cleanup pthread code and add some pthread_attr functions
errno, pthread cleanup and pthread id are now stored in uthread. This
allows using these without TLS
2025-06-01 13:48:03 +03:00
b774f147da LibC: Implement dummy pthread_attr_{get,set}detachstate
detached threads are not yet supported, but this allows implementation
to make sure threads are joinable.
2025-04-21 19:58:01 +03:00
2a5921b9c9 LibC: Implement pthread_barrier
This is not fully working but should be fine for most cases
2025-04-21 19:53:38 +03:00
60cb392e97 LibC: Implement pthread_barrier
This is yet another bad sched_yield implementation :D
2025-04-21 19:52:14 +03:00
1c88d0d7f7 LibC: Implement pthread_rwlock
This uses the same dumb sched_yield instead of actually blocking :D
2025-04-21 18:48:47 +03:00
5d8dd090a9 LibC: Implement pthread_once 2025-04-21 14:17:17 +03:00
265b4c2b22 LibC: Implement thread_equal 2025-04-20 03:27:16 +03:00
db9db2cc40 LibC: Implement basic pthread mutexes
This implementation is just calling sched_yield if it could not get
mutex. This is not optimal as it does not allow the CPU to idle, but it
works for now :)

Also I did not test this code at all, but it feels correct :D
2025-04-20 03:27:16 +03:00
3642eabac0 LibC: Use BAN::atomic_* functions in pthread spinlock
This allows us not to reinterpret_cast pthread_spin_t to
BAN::Atomic<pthread_spin_t> which is much better :)
2025-04-20 03:11:41 +03:00
1ccff9478f LibC: Don't define __tls_get_addr if TLS is disabled
This makes linking fail if something tries to use TLS :)
2025-04-20 03:11:41 +03:00
85f9b585f5 LibC: Don't yield on pthread_spin_lock
Thats kinda the whole point of spinlocks :D
2025-04-20 03:11:41 +03:00
01626b4c9f LibC: Add stub for pthread_detach 2025-04-20 03:11:41 +03:00
a85841ca76 LibC: Add stub for pthread_attr_setstacksize 2025-04-20 03:11:41 +03:00
fe6c4cd0b5 LibC: Implement POSIX TLD area (pthread_key*) 2025-04-20 03:11:41 +03:00
ac90800c3c Kernel/LibC/DynamicLoader: Implement thread local storage
For some reason this does not work on 32 bit version, so it is disabled
on that platform. I'll have to look into it later to find the bug :)
2025-04-15 23:33:39 +03:00
08f5833ca8 Kernel/LibC: Implement pthread_attr_init 2025-04-15 23:31:17 +03:00
36baf7b0af Kernel/LibC/DynamicLoader: Update process start ABI
We now use SysV abi for process startup
2025-04-15 23:05:52 +03:00
5539d5eed0 LibC: Implement pthread_cleanup_{pop,push} 2025-04-15 21:48:38 +03:00
be786be67d Kernel/LibC: Implement pthread_join 2025-04-02 12:58:39 +03:00
e85b18e206 LibC: Fix pthread stack alignment 2025-04-02 12:58:39 +03:00
f32f62dfc1 LibC: Implement pthread_spin_* functions 2025-04-02 12:58:39 +03:00
5549696c3a Kernel/LibC: Implement pthread_self 2025-04-02 02:39:29 +03:00
c1618e2b5d Kernel/LibC: Add basic support for pthread_{create,exit} 2025-04-01 23:26:13 +03:00