about summary refs log tree commit diff
path: root/src/aio
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-07-05 23:29:55 -0400
committerRich Felker <dalias@aerifal.cx>2014-07-05 23:29:55 -0400
commit83dc6eb087633abcf5608ad651d3b525ca2ec35e (patch)
tree1bed298fdfcf4167d63fed54d055a3c66af4f0f0 /src/aio
parent4c48501ee2a022a0dd207a2db4d346a00f9927a1 (diff)
downloadmusl-83dc6eb087633abcf5608ad651d3b525ca2ec35e.tar.gz
musl-83dc6eb087633abcf5608ad651d3b525ca2ec35e.tar.xz
musl-83dc6eb087633abcf5608ad651d3b525ca2ec35e.zip
eliminate use of cached pid from thread structure
the main motivation for this change is to remove the assumption that
the tid of the main thread is also the pid of the process. (the value
returned by the set_tid_address syscall was used to fill both fields
despite it semantically being the tid.) this is historically and
presently true on linux and unlikely to change, but it conceivably
could be false on other systems that otherwise reproduce the linux
syscall api/abi.

only a few parts of the code were actually still using the cached pid.
in a couple places (aio and synccall) it was a minor optimization to
avoid a syscall. caching could be reintroduced, but lazily as part of
the public getpid function rather than at program startup, if it's
deemed important for performance later. in other places (cancellation
and pthread_kill) the pid was completely unnecessary; the tkill
syscall can be used instead of tgkill. this is actually a rather
subtle issue, since tgkill is supposedly a solution to race conditions
that can affect use of tkill. however, as documented in the commit
message for commit 7779dbd2663269b465951189b4f43e70839bc073, tgkill
does not actually solve this race; it just limits it to happening
within one process rather than between processes. we use a lock that
avoids the race in pthread_kill, and the use in the cancellation
signal handler is self-targeted and thus not subject to tid reuse
races, so both are safe regardless of which syscall (tgkill or tkill)
is used.
Diffstat (limited to 'src/aio')
-rw-r--r--src/aio/aio_readwrite.c2
-rw-r--r--src/aio/lio_listio.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/aio/aio_readwrite.c b/src/aio/aio_readwrite.c
index 0de3d4fb..22782265 100644
--- a/src/aio/aio_readwrite.c
+++ b/src/aio/aio_readwrite.c
@@ -17,7 +17,7 @@ static void notify_signal(struct sigevent *sev)
 		.si_signo = sev->sigev_signo,
 		.si_value = sev->sigev_value,
 		.si_code = SI_ASYNCIO,
-		.si_pid = __pthread_self()->pid,
+		.si_pid = getpid(),
 		.si_uid = getuid()
 	};
 	__syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
diff --git a/src/aio/lio_listio.c b/src/aio/lio_listio.c
index 61d7f20e..75ed2257 100644
--- a/src/aio/lio_listio.c
+++ b/src/aio/lio_listio.c
@@ -44,7 +44,7 @@ static void notify_signal(struct sigevent *sev)
 		.si_signo = sev->sigev_signo,
 		.si_value = sev->sigev_value,
 		.si_code = SI_ASYNCIO,
-		.si_pid = __pthread_self()->pid,
+		.si_pid = getpid(),
 		.si_uid = getuid()
 	};
 	__syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);