Commit Graph

48 Commits

Author SHA1 Message Date
Peter Limkilde Svendsen 06fec0b843 Add various basic docstrings 2024-10-27 23:25:57 +01:00
4lDO2 6e5959b3fa Convert a bunch of c_int to Result<(), Errno>. 2024-09-26 16:21:34 +02:00
4lDO2 4bd0d2a1ef Move pthread::Errno to separate module. 2024-09-11 23:22:29 +02:00
JustAnotherDev 7df5b16f9e set deny(unsafe_op_in_unsafe_fn) for 2024-09-11 20:55:05 +01:00
4lDO2 4c20a9abb2 Enable syscall restart in futex_wait. 2024-07-16 11:55:06 +02:00
Derick Eddington 802748b611 Fix Rwlock::acquire_write_lock to avoid blocking indefinitely.
Without this fix, `tests/bins_static/pthread/rwlock_randtest` would sometimes get stuck blocking
forever with only 1+ threads all doing `pthread_rwlock_wrlock()` but all the other threads
having finished.
2024-07-06 22:47:55 -07:00
4lDO2 6e86e64fdf Move pthread into TCB. 2024-06-08 11:36:22 +02:00
Jacob Lorentzon 1fba2ef10a Various futex fixes 2024-04-05 20:31:06 +00:00
4lDO2 e0a3811736 Protect fork() and clone() behind a rwlock.
rlct_clone will acquire a read lock, whereas fork will acquire a write
lock. The write lock is necessary because the fork will clone the file
table, which would result in other threads' fork/clone file descriptors
not being closed. If an address space switch fd never gets closed, fork
child processes and new threads, may never switch address spaces before
they are started, which has resulted in hard-to-debug RIP=0 instr fetch
page faults.
2024-03-27 10:30:49 +01:00
Jacob Lorentzon f7ac690c45 Fix pthread rwlock code 2024-03-26 15:46:32 +00:00
Jacob Lorentzon e0b640d530 Implement new low-level signal trampoline 2024-03-17 16:58:42 +00:00
Noa df6f4678e8 Fix warnings 2023-05-30 13:46:17 -05:00
4lDO2 cdd0f67b23 Rustfmt. 2023-05-17 15:28:10 +02:00
4lDO2 9040c2a2a2 fix semaphores 2023-05-11 17:18:12 -06:00
4lDO2 a7708a9fc8 Fix AtomicPtr::as_ptr compiler version problem. 2023-05-07 11:17:04 +02:00
4lDO2 439b054486 Rustify pthread_rwlock_t. 2023-05-06 17:02:54 +02:00
4lDO2 79dfddf82c Switch to a boring mutex+condvar based barrier.
While the atomic version might be better, at the moment the priority is
to just to get RLCT working reliably.
2023-05-06 17:02:53 +02:00
4lDO2 4e5596698d Hack to support multiple compiler versions. 2023-05-06 17:02:53 +02:00
4lDO2 a3e1eed100 Wake all when unlocking internal mutexes.
This is because we don't yet count the number of waiting threads,
instead just flagging where or not there are any waiters.
2023-05-06 17:02:53 +02:00
4lDO2 e6df6ccfb3 Fix once and try to improve barrier. 2023-05-06 17:02:53 +02:00
4lDO2 714e73112d Simplify Mutex implementation, for now. 2023-05-06 17:02:52 +02:00
4lDO2 beac24828d Use futex directly in waitval. 2023-05-06 17:02:52 +02:00
4lDO2 4faa315591 Use broadcast in Cond, for now. 2023-05-06 17:02:52 +02:00
4lDO2 1d989d5cb6 Improve barrier.
Maybe it would be better to simply stick to a mutex and condvar, as
libstd does. Optimization is for later anyway.
2023-05-06 17:02:52 +02:00
4lDO2 9356098fb2 WIP: More complete pthread mutex implementation. 2023-05-06 17:02:52 +02:00
4lDO2 38f89cb4bb Improved barrier implementation. 2023-05-06 17:02:51 +02:00
4lDO2 cf34e2512e Move condvar impl to a mostly-safe module. 2023-05-06 17:02:51 +02:00
4lDO2 22ffed707f Fix embarrasing deadlock! 2023-05-06 17:02:51 +02:00
4lDO2 b455e2e374 Misc improvements, move barrier to safe module. 2023-05-06 17:02:51 +02:00
4lDO2 b9f19f4326 Get pcid to work using this pthread impl. 2023-05-06 17:02:51 +02:00
4lDO2 6a658bc33d Add needed functions for acid to link. 2023-05-06 17:02:51 +02:00
4lDO2 2593101ea7 Get it to compile 2023-05-06 17:02:50 +02:00
4lDO2 558d43082c WIP: Expand native pthreads implementation. 2023-05-06 17:02:50 +02:00
Jeremy Soller 6516695519 Format 2022-12-16 17:39:30 -07:00
Jeremy Soller da4d277f12 Use futex again for semaphore 2022-12-01 14:05:12 -07:00
Jeremy Soller 9b04c2e5d3 Add missing imports 2022-12-01 10:50:27 -07:00
Jeremy Soller df75b8d037 Semaphore improvements 2022-12-01 10:48:53 -07:00
Jeremy Soller 16abc91341 cargo fmt and cargo fix 2022-11-11 13:27:18 -07:00
Jeremy Soller e7b6252bd3 Make semaphore always sched_yield 2022-09-01 15:43:11 -06:00
Jeremy Soller 53c8f0facd Simplify semaphore for debugging 2022-09-01 10:56:18 -06:00
4lDO2 5e74d173ab Fix ld.so access function on Redox. 2022-08-13 19:16:48 +02:00
Jeremy Soller 8576b99759 Add timeout to futex_wait calls 2022-04-04 20:23:29 -06:00
Mateusz Tabaka a7480ea656 Fix global symbols relocations
Instead of a single source of symbols, now linker keeps a list of DSO (former Library) objects
with their own symbols map. That helps to process R_X86_64_COPY relocations correctly.
For example, if 'a.out' executable with dependencies ['libstdc++.so', 'libc.so'] is being loaded
and 'a.out' uses 'stdout' symbol from 'libc.so', its relocation process goes as follows:
- linker processes relocation entry 'stdout' of type R_X86_64_GLOB_DAT from 'libc.so',
- it goes through object list ['a.out', 'libstdc++.so', 'libc.so'] to find first object
  that exports 'stdout' symbol. The symbol is in 'a.out' with the value e.g. '0x404070',
- linker sets 'stdout' symbol GOT entry in 'libc.so' to '0x404070',
....
- linker processes relocation entry 'stdout' of type R_X86_64_COPY from 'a.out',
- it goes through object list excluding 'a.out': ['libstdc++.so', 'libc.so']. The symbol is found in 'libc.so',
- linker copies the 'stdout' symbol content from 'libc.so' to memory at address '0x404070' (in 'a.out' object).

Objects are relocated in reverse order they were loaded. So in the example above, linker starts with relocating
'libc.so' and ends with 'a.out'. It is necessary e.g. when linking with 'libstdc++.so' - there are many
relocations which symbols are found in 'libstdc++.so', so they need to be resolved before their contents are
copied to 'a.out'. That also matches GNU ld.so behavior.
2021-01-03 16:04:40 +01:00
Jeremy Soller 2f69f0e7f1 Add simple semaphore implementation using futex 2020-12-23 12:18:17 -07:00
jD91mZM2 b8c50c7c64 Format 2019-08-04 19:05:45 +02:00
jD91mZM2 c7d499d4f2 Upgrade to the 2018 edition
I didn't think it'd be this useful first, but thank god for `cargo fix --edition`!
2019-08-04 19:05:45 +02:00
jD91mZM2 43ff8801bc Format 2019-08-04 19:05:44 +02:00
jD91mZM2 35c1d5210c Implement the Once<T> synchronization structure
Not sure if I should add a RwLock for the ptrace state too...
2019-08-04 19:05:44 +02:00