Bananymous
bc622c8b51
LibC: Fix pthread default guard size and name
2026-07-20 06:58:30 +03:00
Bananymous
46e2d665e9
LibC: Make pthread_once block with a futex instead of yielding
2026-07-20 04:07:23 +03:00
Bananymous
390a7674b1
LibC: Fix uthread deallocation
...
Update dtv[0] to the max loadad module when loading dynamic modules
Free uthread if stack allocation or mprotect fails on pthread_create
Don't unmap the currently used stack when detached thread exits
2026-07-20 04:07:23 +03:00
Bananymous
917321eb5f
LibC: Wait for thread before returning from pthread_create
...
We now make sure the thread starts up and sets its id. There was a race
condition where a process could create a thread and immediately try to
join it. If the thread had not initialized itself the join would fail
with EINVAL as we passed -1 as its id.
2026-07-03 02:14:10 +03:00
Bananymous
50fd526e6f
LibC: Implement pthread_{get,set}name_np
2026-07-02 20:02:24 +03:00
Bananymous
c0e091b647
LibC: Implement pthread_{get,set}attr_default_np
2026-07-02 20:02:24 +03:00
Bananymous
372da006d0
LibC: Implement pthread_getattr_np
2026-07-02 20:02:24 +03:00
Bananymous
0dc74beb0f
Kernel/LibC: Allocate thread stacks in userspace
...
This adds support for pthread function for stack manipulation.
Also keep track of main threads stack in the uthread
2026-07-02 20:02:24 +03:00
Bananymous
7bdd9d19d0
LibC: Cleanup uthread initialization
...
This is now done in a constructor function in pthread.cpp
2026-07-02 20:02:24 +03:00
Bananymous
b19b7f064a
LibC: Make pthread_t pointer to uthread instead of a thread id
...
This will allow getting info about other threads in userspace!
2026-07-02 20:02:24 +03:00
Bananymous
f449ca8161
Kenrel: Separate pthread API from kernel API
...
It didn't really make sense for the syscalls to be named as the pthread
equivalents. Now the kernel just uses thread ids
2026-07-02 20:02:24 +03:00
Bananymous
6f002f0c07
LibC: Make pthread_{equal,self,testcancel} static inline
...
This allows using ::pthread_self or &pthread_self
2026-06-30 20:14:38 +03:00
Bananymous
9c79971bdc
LibC/Kernel: Add support for detached pthreads
2026-05-17 00:40:56 +03:00
Bananymous
ff75c15ba3
LibC: Move pthread keys to TCB
...
This removes all TLS relocations from libc which may become handy ;)
2026-05-17 00:29:20 +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
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
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
c7690053ae
LibC: Don't crash on 32 bit pthread_create
2026-04-04 23:48:43 +03:00
Bananymous
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
Bananymous
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
Bananymous
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
Bananymous
fb61cab70d
LibC: Rewrite pthread_mutex using a futex
2025-08-21 02:52:49 +03:00
Bananymous
eb7922ab88
LibC: Implement pthread_cond_* using a futex
2025-08-05 03:09:24 +03:00
Bananymous
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
Bananymous
57c9f5a8a8
LibC: lock mutex when pthread_cond_timedwait times out
2025-08-05 03:09:24 +03:00
Bananymous
d25a5034db
LibC: Update thread id on fork
2025-08-05 03:09:24 +03:00
Bananymous
f197d39aaf
LibC: Don't allow pthread_join to return EINTR
2025-08-05 03:09:24 +03:00
Bananymous
4a95343936
LibC: Make _get_uthread a macro
...
This allows nice inlining :)
2025-08-05 03:09:24 +03:00
Bananymous
4e705a91af
LibC: Fix pthread keys
...
I had misunderstood how these are supposed to work :D
2025-08-05 03:09:24 +03:00
Bananymous
0f2c02fb04
LibC: Add stubs for pthread_{get,set}schedparam
2025-06-28 16:55:13 +03:00
Bananymous
f9451915b9
LibC: Use pause in pthread spinlock locking
2025-06-16 15:07:58 +03:00
Bananymous
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
Bananymous
df7f245cf8
LibC: Implement pthread_atfork
...
Again this code is not tested but *feels* right :D
2025-06-01 13:48:03 +03:00
Bananymous
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
Bananymous
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
Bananymous
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
Bananymous
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
Bananymous
60cb392e97
LibC: Implement pthread_barrier
...
This is yet another bad sched_yield implementation :D
2025-04-21 19:52:14 +03:00
Bananymous
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
Bananymous
5d8dd090a9
LibC: Implement pthread_once
2025-04-21 14:17:17 +03:00
Bananymous
265b4c2b22
LibC: Implement thread_equal
2025-04-20 03:27:16 +03:00
Bananymous
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
Bananymous
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
Bananymous
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
Bananymous
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
Bananymous
01626b4c9f
LibC: Add stub for pthread_detach
2025-04-20 03:11:41 +03:00
Bananymous
a85841ca76
LibC: Add stub for pthread_attr_setstacksize
2025-04-20 03:11:41 +03:00
Bananymous
fe6c4cd0b5
LibC: Implement POSIX TLD area (pthread_key*)
2025-04-20 03:11:41 +03:00