<feed xmlns='http://www.w3.org/2005/Atom'>
<title>musl/src/thread, branch v1.2.5</title>
<subtitle>musl - an implementation of the standard library for Linux-based systems</subtitle>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/'/>
<entry>
<title>riscv32: add thread support</title>
<updated>2024-02-29T21:36:55+00:00</updated>
<author>
<name>Stefan O'Rear</name>
<email>sorear@fastmail.com</email>
</author>
<published>2020-09-03T09:56:46+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=b28c44de8c3131b45588f61569b1711c987ba1c3'/>
<id>b28c44de8c3131b45588f61569b1711c987ba1c3</id>
<content type='text'>
Identical to riscv64 except for stack offsets in clone.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Identical to riscv64 except for stack offsets in clone.
</pre>
</div>
</content>
</entry>
<entry>
<title>loongarch64 __clone: align stack pointer mod 16</title>
<updated>2024-02-26T20:23:01+00:00</updated>
<author>
<name>wanghongliang</name>
<email>wanghongliang@loongson.cn</email>
</author>
<published>2024-02-25T18:12:28+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=80e3b09823a1d718664bc13704f3f7c19038a19e'/>
<id>80e3b09823a1d718664bc13704f3f7c19038a19e</id>
<content type='text'>
According to LoongArch ABI Specs, stack need to be 16 align to improve
performance and compiler layout of stack frames.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
According to LoongArch ABI Specs, stack need to be 16 align to improve
performance and compiler layout of stack frames.
</pre>
</div>
</content>
</entry>
<entry>
<title>add loongarch64 port</title>
<updated>2024-02-16T14:33:10+00:00</updated>
<author>
<name>Hongliang Wang</name>
<email>wanghongliang@loongson.cn</email>
</author>
<published>2023-09-26T01:12:01+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=522bd54edaa2fa404fd428f8ad0bcb0f0bec5639'/>
<id>522bd54edaa2fa404fd428f8ad0bcb0f0bec5639</id>
<content type='text'>
Author: Xiaojuan Zhai &lt;zhaixiaojuan@loongson.cn&gt;
Author: Meidan Li &lt;limeidan@loongson.cn&gt;
Author: Guoqi Chen &lt;chenguoqi@loongson.cn&gt;
Author: Xiaolin Zhao &lt;zhaoxiaolin@loongson.cn&gt;
Author: Fan peng &lt;fanpeng@loongson.cn&gt;
Author: Jiantao Shan &lt;shanjiantao@loongson.cn&gt;
Author: Xuhui Qiang &lt;qiangxuhui@loongson.cn&gt;
Author: Jingyun Hua &lt;huajingyun@loongson.cn&gt;
Author: Liu xue &lt;liuxue@loongson.cn&gt;
Author: Hongliang Wang &lt;wanghongliang@loongson.cn&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Author: Xiaojuan Zhai &lt;zhaixiaojuan@loongson.cn&gt;
Author: Meidan Li &lt;limeidan@loongson.cn&gt;
Author: Guoqi Chen &lt;chenguoqi@loongson.cn&gt;
Author: Xiaolin Zhao &lt;zhaoxiaolin@loongson.cn&gt;
Author: Fan peng &lt;fanpeng@loongson.cn&gt;
Author: Jiantao Shan &lt;shanjiantao@loongson.cn&gt;
Author: Xuhui Qiang &lt;qiangxuhui@loongson.cn&gt;
Author: Jingyun Hua &lt;huajingyun@loongson.cn&gt;
Author: Liu xue &lt;liuxue@loongson.cn&gt;
Author: Hongliang Wang &lt;wanghongliang@loongson.cn&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>synccall: add separate exit_sem to fix thread release logic bug</title>
<updated>2023-11-06T18:05:24+00:00</updated>
<author>
<name>Markus Wichmann</name>
<email>nullplan@gmx.net</email>
</author>
<published>2023-10-31T16:03:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=7f3a2925369c00abc33457400e33632e6dacb8ae'/>
<id>7f3a2925369c00abc33457400e33632e6dacb8ae</id>
<content type='text'>
The code intends for the sem_post() in line 97 (now 98) to only unblock
target threads waiting on line 29. But after the first thread is
released, the next sem_post() might also unblock a thread waiting on
line 36. That would cause the thread to return to the execution of user
code before all threads are done, leading to user code being executed in
a mixed-credentials environment.

What's more, if this happens more than once, then the mass release on
line 110 (now line 111) will cause multiple threads to execute the
callback at the same time, and the callbacks are currently not written
to cope with that situation.

Adding another semaphore allows the caller to say explicitly which
threads it wants to release.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The code intends for the sem_post() in line 97 (now 98) to only unblock
target threads waiting on line 29. But after the first thread is
released, the next sem_post() might also unblock a thread waiting on
line 36. That would cause the thread to return to the execution of user
code before all threads are done, leading to user code being executed in
a mixed-credentials environment.

What's more, if this happens more than once, then the mass release on
line 110 (now line 111) will cause multiple threads to execute the
callback at the same time, and the callbacks are currently not written
to cope with that situation.

Adding another semaphore allows the caller to say explicitly which
threads it wants to release.
</pre>
</div>
</content>
</entry>
<entry>
<title>fix pthread_detach inadvertently acting as cancellation point in race case</title>
<updated>2023-02-11T18:00:22+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2023-02-11T14:54:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=c3cd04fa5fecd2c349aefde090c602554ee4fa24'/>
<id>c3cd04fa5fecd2c349aefde090c602554ee4fa24</id>
<content type='text'>
disabling cancellation around the pthread_join call seems to be the
safest and logically simplest fix. i believe it would also be possible
to just perform the unmap directly here after __tl_sync, removing the
dependency on pthread_join, but such an approach duplicately encodes a
lot more implementation assumptions.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
disabling cancellation around the pthread_join call seems to be the
safest and logically simplest fix. i believe it would also be possible
to just perform the unmap directly here after __tl_sync, removing the
dependency on pthread_join, but such an approach duplicately encodes a
lot more implementation assumptions.
</pre>
</div>
</content>
</entry>
<entry>
<title>use libc-internal malloc for pthread_atfork</title>
<updated>2022-12-17T21:00:19+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2022-12-17T21:00:19+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=9532ae1318201d66b235a618df16aac0b3386630'/>
<id>9532ae1318201d66b235a618df16aac0b3386630</id>
<content type='text'>
while no lock is held here making it a lock-order issue, replacement
malloc is likely to want to use pthread_atfork, possibly making the
call to malloc infinitely recursive.

even if not, there is no reason to prefer an application-provided
malloc here.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
while no lock is held here making it a lock-order issue, replacement
malloc is likely to want to use pthread_atfork, possibly making the
call to malloc infinitely recursive.

even if not, there is no reason to prefer an application-provided
malloc here.
</pre>
</div>
</content>
</entry>
<entry>
<title>semaphores: fix missed wakes from ABA bug in waiter count logic</title>
<updated>2022-12-13T23:39:44+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2022-12-13T23:39:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=159d1f6c02569091c7a48bdb2e2e824b844a1902'/>
<id>159d1f6c02569091c7a48bdb2e2e824b844a1902</id>
<content type='text'>
because the has-waiters state in the semaphore value futex word is
only representable when the value is zero (the special value -1
represents "0 with potential new waiters"), it's lost if intervening
operations make the semaphore value positive again. this creates an
ABA issue in sem_post, whereby the post uses a stale waiters count
rather than re-evaluating it, skipping the futex wake if the stale
count was zero.

the fix here is based on a proposal by Alexey Izbyshev, with minor
changes to eliminate costly new spurious wake syscalls.

the basic idea is to replace the special value -1 with a sticky
waiters bit (repurposing the sign bit) preserved under both wait and
post. any post that takes place with the waiters bit set will perform
a futex wake.

to be useful, the waiters bit needs to be removable, and to remove it
safely, we perform a broadcast wake instead of a normal single-task
wake whenever removing the bit. this lets any un-accounted-for waiters
wake and re-add the waiters bit if they still need it.

there are multiple possible choices for when to perform this
broadcast, but the optimal choice seems to be doing it whenever the
observed waiters count is less than two (semantically, this means
exactly one, but we might see a stale count of zero). in this case,
the expected number of threads to be woken is one, with exactly the
same cost as a non-broadcast wake.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
because the has-waiters state in the semaphore value futex word is
only representable when the value is zero (the special value -1
represents "0 with potential new waiters"), it's lost if intervening
operations make the semaphore value positive again. this creates an
ABA issue in sem_post, whereby the post uses a stale waiters count
rather than re-evaluating it, skipping the futex wake if the stale
count was zero.

the fix here is based on a proposal by Alexey Izbyshev, with minor
changes to eliminate costly new spurious wake syscalls.

the basic idea is to replace the special value -1 with a sticky
waiters bit (repurposing the sign bit) preserved under both wait and
post. any post that takes place with the waiters bit set will perform
a futex wake.

to be useful, the waiters bit needs to be removable, and to remove it
safely, we perform a broadcast wake instead of a normal single-task
wake whenever removing the bit. this lets any un-accounted-for waiters
wake and re-add the waiters bit if they still need it.

there are multiple possible choices for when to perform this
broadcast, but the optimal choice seems to be doing it whenever the
observed waiters count is less than two (semantically, this means
exactly one, but we might see a stale count of zero). in this case,
the expected number of threads to be woken is one, with exactly the
same cost as a non-broadcast wake.
</pre>
</div>
</content>
</entry>
<entry>
<title>pthread_atfork: fix return value on malloc failure</title>
<updated>2022-11-12T17:22:38+00:00</updated>
<author>
<name>Alexey Izbyshev</name>
<email>izbyshev@ispras.ru</email>
</author>
<published>2022-11-12T13:31:01+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=377218cb963aa20c6eb91781b0c79ad606631e6f'/>
<id>377218cb963aa20c6eb91781b0c79ad606631e6f</id>
<content type='text'>
POSIX requires pthread_atfork to report errors via its return value,
not via errno. The only specified error is ENOMEM.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
POSIX requires pthread_atfork to report errors via its return value,
not via errno. The only specified error is ENOMEM.
</pre>
</div>
</content>
</entry>
<entry>
<title>fix async thread cancellation stack alignment</title>
<updated>2022-11-05T22:59:53+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2022-11-05T22:53:11+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=ad5dcd398b9509cf43672e3a7f02c4b18035998c'/>
<id>ad5dcd398b9509cf43672e3a7f02c4b18035998c</id>
<content type='text'>
if async cancellation is enabled and acted upon, the stack pointer is
not necessarily pointing to a __syscall_cp_asm stack frame. the
contents of the stack being wrong don't really matter, but if the
stack pointer is not suitably aligned, the procedure call ABI is
violated when calling back into C code via __cancel, and pthread_exit,
cancellation cleanup handlers, TSD destructors, etc. may malfunction
or crash.

for the async cancel case, just call __cancel directly like we did
prior to commit 102f6a01e249ce4495f1119ae6d963a2a4a53ce5. restore the
signal mask prior to doing this since the cancellation handler runs
with all signals blocked.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
if async cancellation is enabled and acted upon, the stack pointer is
not necessarily pointing to a __syscall_cp_asm stack frame. the
contents of the stack being wrong don't really matter, but if the
stack pointer is not suitably aligned, the procedure call ABI is
violated when calling back into C code via __cancel, and pthread_exit,
cancellation cleanup handlers, TSD destructors, etc. may malfunction
or crash.

for the async cancel case, just call __cancel directly like we did
prior to commit 102f6a01e249ce4495f1119ae6d963a2a4a53ce5. restore the
signal mask prior to doing this since the cancellation handler runs
with all signals blocked.
</pre>
</div>
</content>
</entry>
<entry>
<title>fix missing synchronization of pthread TSD keys with MT-fork</title>
<updated>2022-10-19T18:01:32+00:00</updated>
<author>
<name>Rich Felker</name>
<email>dalias@aerifal.cx</email>
</author>
<published>2022-10-08T01:36:25+00:00</published>
<link rel='alternate' type='text/html' href='http://git.musl-libc.org/cgit/musl/commit/?id=cf76df0e1fe09b0d504ca650fdaa01df5bf9ab72'/>
<id>cf76df0e1fe09b0d504ca650fdaa01df5bf9ab72</id>
<content type='text'>
commit 167390f05564e0a4d3fcb4329377fd7743267560 seems to have
overlooked the presence of a lock here, probably because it was one of
the exceptions not using LOCK() but a rwlock.

as such, it can't be added to the generic table of locks to take, so
add an explicit atfork function for the pthread keys table. the order
it is called does not particularly matter since nothing else in libc
but pthread_exit interacts with keys.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 167390f05564e0a4d3fcb4329377fd7743267560 seems to have
overlooked the presence of a lock here, probably because it was one of
the exceptions not using LOCK() but a rwlock.

as such, it can't be added to the generic table of locks to take, so
add an explicit atfork function for the pthread keys table. the order
it is called does not particularly matter since nothing else in libc
but pthread_exit interacts with keys.
</pre>
</div>
</content>
</entry>
</feed>
