#
6f3f29c7 |
|
06-Jun-2023 |
Augustin Cavalier <waddlesplash@gmail.com> |
user_mutex: Refactor locking and unblocking mechanism. Suppose the following scenario: 1. Thread A holds a mutex. 2. Thread B goes to acquire the mutex, winds up in kernel waiting. 3. Thread A unlocks; first unsets the LOCKED flag. As WAITING is set, it calls the kernel; but instead of processing this immediately, the thread is suspended for any reason (locks, reschedule, etc.) 4. Thread B hits a timeout, or a signal. It then unblocks in the kernel, which causes the WAITING flag to be unset. 5. Thread C goes to acquire the lock. It sets the LOCKED flag. It sees the WAITING flag is not set, so it returns at once, having successfully acquired the lock. 6. Thread A, suspended back in step 3, resumes. Now we encounter the problem. Under the previous code, the following would occur. 7. Thread A sees that no threads are waiting. It thus unsets the LOCKED flag, and returns from the kernel. Now we have a mutex theoretically held by thread C but which (illegally) has no LOCKED flag set! 8. Some other thread tries to acquire the lock, and succeeds, for LOCKED is not set. We now have one lock owned by two separate threads. That's very bad! The solution, in this commit, is to (1) switch from using "atomic_or" to lock mutexes, to using "atomic_test_and_set", and (2) mandate that _kern_unblock_mutex must be invoked with the mutex already unlocked. Trying to solve the problem with (2) but without (1) produces other complications and would overall be more complicated. For instance, all existing userland code expected that it would set LOCKED, but then check LOCKED|WAITING. If _kern_mutex_unlock does not unset LOCKED, then whichever thread sets LOCKED when it was previously unset is now the mutex's undisputed owner, and if it fails to notice this, would deadlock. That could have been solved with extra checks at all lock points, but then that would mean locks would not be acquired "fairly": it would be possible for any thread to race with an unlocking thread, and acquire the lock before the kernel had a chance to wake anyone up. Given how fast atomics can be, and how slow invoking the kernel is comparatively, that would probably make our mutexes extremely "unfair." This would not violate the POSIX specification, but it does seem like a dangerous choice to make in implementing these APIs. Linux's "futex" API, which our API bears some similarities to, requires at least one atomic test-and-set for an uncontended acquisition, and multiple atomics more for even the simplest case of contended acquisition. If it works for them, it should work for us, too. Fixes #18436. Change-Id: Ib8c28acf04ce03234fe738e41aa0969ca1917540 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6537 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk> Reviewed-by: waddlesplash <waddlesplash@gmail.com>
|
#
44cceee6 |
|
15-Oct-2022 |
Han Pengfei <pengphei@qq.com> |
pthread: add pthread_{getname_np,setname_npp} - These two functions imported for Linux/BSD compability. Signed-off-by: Han Pengfei <pengphei@qq.com> Change-Id: I3e9cada26f1ed043bfaed83e8185dcfff3bd71e2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5746 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
|
#
d338200e |
|
30-May-2022 |
Trung Nguyen <trungnt282910@gmail.com> |
libs/posix: Implemented new locale functions Implemented the missing POSIX functions in <locale.h>: newlocale, duplocale, uselocale, and freelocale, and also provided missing type definitions for <locale.h>. Implemented missing POSIX locale-based function variants. Modified LocaleBackend so that it could support thread-local locales. Some glibc-like locale-related variables supporting ctype and printf family of functions have also been updated to reflect the thread-local variables present in the latest glibc sources. As there have been some modifications to global symbols in libroot, libroot_stubs.c has been regenerated. Bug: #17168 Change-Id: Ibf296c58c47d42d1d1dfb2ce64042442f2679431 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5351 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
|
#
914b10c1 |
|
11-Mar-2022 |
Jessica Hamilton <jessica.l.hamilton@gmail.com> |
wait_for_thread_etc: expose as syscall/make public. * This will be needed for the following commit that implements `pthread_tryjoin_np` and `pthread_timedjoin_np`. Change-Id: Idccb1aa588d6d10825294d14925d9bd046b65f19 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5098 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Jérôme Duval <jerome.duval@gmail.com> Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
|
#
f89943d8 |
|
09-Oct-2021 |
Jérôme Duval <jerome.duval@gmail.com> |
build/x86: also test the stack protector on x86 secondary arch on x86, gcc emits a local reference to __stack_chk_fail_local which can only be provided by a static library. as we don't have a libroot_nonshared, we use libgcc from gcc, in which libssp_nonshared was merged, from version 8.3.0_2019_05_24-11. Change-Id: I22bf26dec5c1fe69a3915a923bd716a494f846ce Reviewed-on: https://review.haiku-os.org/c/haiku/+/4564 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
|
#
af435dd1 |
|
09-Dec-2020 |
X512 <danger_mail@list.ru> |
libroot: remove delete_driver_settings It is not present in BeOS R5 and it just call unload_driver_settings. Replace delete_driver_settings usages with unload_driver_settings. Keep the symbol on x86 for binary compatibility. Change-Id: I1382710e3a4cb5c65d1249ea0e5880891e6800e4 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3485 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
|
#
fe357eb9 |
|
05-Nov-2020 |
Jérôme Duval <jerome.duval@gmail.com> |
POSIX: add posix_fallocate and a preallocate syscall the preallocate syscall will call the preallocate filesystem hook, if available. fix #6285 Change-Id: Ifff4595548610c8e009d4e5ffb64c37e0884e62d Reviewed-on: https://review.haiku-os.org/c/haiku/+/3382 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
|
#
b3bd6696 |
|
29-May-2020 |
Michael Lotz <mmlr@mlotz.ch> |
libroot/kernel: Implement MADV_FREE madvise() extension. It allows an application to signal that it no longer needs the data in the given address range and the underlying pages can be discarded and reused elsewhere. This is finer grained than working with full areas or mappings at a time and enables unmapping sections of partially used mappings without giving up its address space. Compared with punching holes into a mapping by "mapping over" with PROT_NONE and MAP_NORESERVE, this has the obvious advantage of not producing a lot of unused extra areas and saves the corresponding resources. It is also a lot "lighter" of an operation than cutting existing areas. This introduces madvise() alongside the existing posix_madvise() to allow for OS specific extensions. The constants for both functions are aliased, the POSIX_MADV_* being a subset of the MADV_* ones without the non-POSIX extensions. Internally posix_madvise() simply calls madvise(). MADV_FREE is commonly supported in other OSes with various subtle semantic differences as to when pages are actually freed/cleared and how or whether the pages are counted against the memory use of a process. In the variant implemented here, pages are always immediately discarded and memory counting is not altered. This behaviour should be considered an implementation detail and may be altered later. The actual unmap and discard could for example be delayed until pages are needed elsewhere to reduce overhead in case of repeated discarding and remapping. Note that MADV_FREE doesn't really align with the rest of the madvise() API as it works like a command (i.e. discard these pages) and does not add an attribute to the pages in the given range (i.e. mark these pages for quick access from now on). As such, an MADV_FREE does not need to be undone by setting a different advice later on, unlike how the other flags work. This discrepancy may be the reason why it is not part of POSIX. Change-Id: Icc093379125a43e465dc4409d8f5ae0f64e107e0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2844 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
|
#
016cc668 |
|
03-Sep-2019 |
Jaroslaw Pelczar <jarek@jpelczar.com> |
Remove arch_get_caller Use the gcc builtin instead, which generates more efficient code (it saves a function call) and means less platform specific code to write for us. Change-Id: I1d55b5703027b2ea4ecde2438ea306bd4850eb32 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1859 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
|
#
9ba45ef9 |
|
07-Mar-2019 |
Jérôme Duval <jerome.duval@gmail.com> |
Update libroot stubs.
|
#
e4103b1b |
|
25-Dec-2018 |
Michael Lotz <mmlr@mlotz.ch> |
libroot: Introduce thread specific heap init/exit hooks. This allows heap implementations to initialize and clean up any thread specific structures. The current default hoard heap does not use these. Note that the thread exit hook will not be called for the main thread as the heap may be needed during process termination (__cxa_finalize for example). Change-Id: I703fbd34dec0d9029d619a2125c5b19d8c1933aa Reviewed-on: https://review.haiku-os.org/799 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
|
#
defd975a |
|
06-Jul-2018 |
Jérôme Duval <jerome.duval@gmail.com> |
Update libroot stubs.
|
#
857d600a |
|
29-Jan-2018 |
Jérôme Duval <jerome.duval@gmail.com> |
Add missing libroot stub on x86 (different from x86_64).
|
#
f57e467b |
|
18-Nov-2017 |
Jérôme Duval <jerome.duval@gmail.com> |
Update libroot stubs.
|
#
33e68be4 |
|
01-Nov-2016 |
Jérôme Duval <jerome.duval@gmail.com> |
Update libroot stubs.
|
#
dbf060a3 |
|
29-Oct-2015 |
Simon South <ssouth@simonsouth.com> |
libroot: Add brk() and sbrk(). This commit replaces the placeholder implementation of sbrk(), which operated on a process' heap, with real implementations of brk() and sbrk() that adjust a process' program break. * unistd.h: Add standard definitions of brk() and sbrk(); include stdint.h for intptr_t. * thread.cpp: Recognize RLIMIT_AS and RLIMIT_DATA resource limits (both currently unlimited); order limit identifiers alphabetically. * arch-specific.cpp: Remove sbrk_hook(). * malloc_debug_api.cpp: Remove sbrk_hook(). * unistd/Jamfile: Build brk.c instead of sbrk.c. * unistd/brk.c: Add. * unistd/sbrk.c: Delete (placeholder implementation). * libroot_stubs.c: Remove sbrk_hook(). * libroot_stubs_legacy.c: Remove sbrk_hook(). * src/tests/.../posix/Jamfile: Build brk_test.c. * brk_test.c: Add (simple unit test that demonstrates behaviour of sbrk()). Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
|
#
f474606e |
|
12-Aug-2015 |
Michael Lotz <mmlr@mlotz.ch> |
libroot_debug: Merge guarded heap into libroot_debug. The individual debug heap implementations are now exposed via a structure of function pointers and a common frontend dispatches the malloc and malloc_debug APIs through them. The MALLOC_DEBUG environment variable can be used to select the guarded heap by adding 'g', otherwise the debug heap is used as the default. Consequently the separate libroot_guarded is not needed anymore and has been removed. To allow the use of environment variables this early, init_env_post_heap has been added and the heap dependent atfork() moved there. This allowed to fold the code of init_heap_post_env into init_heap so the former has been removed.
|
#
445257ff |
|
11-Aug-2014 |
Oliver Tappe <zooey@hirschkaefer.de> |
Fix missing symbols in <stubbed>libroot.so. * A couple of symbols reuse the same address (via weak symbols), so we adjust generate_stubs.py accordingly.
|
#
b2883f6a |
|
04-Aug-2014 |
Oliver Tappe <zooey@hirschkaefer.de> |
Add support for building <stubbed>libroot.so. * <stubbed>libroot.so is a shared library which contains all the symbols from libroot, but without any code. This library will be required by the (to be introduced) stage0 of the bootstrap process, in order to be able to link the shared gcc syslibs (libstdc++.so, libsupc++.so and libgcc_s.so).
|
#
f474606ee92a7afddb5b3b6350a97ffd31e22c42 |
|
12-Aug-2015 |
Michael Lotz <mmlr@mlotz.ch> |
libroot_debug: Merge guarded heap into libroot_debug. The individual debug heap implementations are now exposed via a structure of function pointers and a common frontend dispatches the malloc and malloc_debug APIs through them. The MALLOC_DEBUG environment variable can be used to select the guarded heap by adding 'g', otherwise the debug heap is used as the default. Consequently the separate libroot_guarded is not needed anymore and has been removed. To allow the use of environment variables this early, init_env_post_heap has been added and the heap dependent atfork() moved there. This allowed to fold the code of init_heap_post_env into init_heap so the former has been removed.
|
#
445257ffd662d791b35e94b0065e88f051aa3aee |
|
11-Aug-2014 |
Oliver Tappe <zooey@hirschkaefer.de> |
Fix missing symbols in <stubbed>libroot.so. * A couple of symbols reuse the same address (via weak symbols), so we adjust generate_stubs.py accordingly.
|
#
b2883f6a0dc07c455e81e39494645e31d713d7ac |
|
04-Aug-2014 |
Oliver Tappe <zooey@hirschkaefer.de> |
Add support for building <stubbed>libroot.so. * <stubbed>libroot.so is a shared library which contains all the symbols from libroot, but without any code. This library will be required by the (to be introduced) stage0 of the bootstrap process, in order to be able to link the shared gcc syslibs (libstdc++.so, libsupc++.so and libgcc_s.so).
|