aboutsummaryrefslogtreecommitdiff
path: root/hurd/hurdsig.c
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2020-12-21 02:10:16 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-12-21 02:10:16 +0100
commit5c06743c8a6f2184fbd3792b13dffa30f473b7b7 (patch)
tree07a16aeb17241b84b149ea13a19861f214b945b1 /hurd/hurdsig.c
parent53432762ac2ff24794089e2c767b976e54c2dc0a (diff)
downloadglibc-5c06743c8a6f2184fbd3792b13dffa30f473b7b7.zip
glibc-5c06743c8a6f2184fbd3792b13dffa30f473b7b7.tar.gz
glibc-5c06743c8a6f2184fbd3792b13dffa30f473b7b7.tar.bz2
Hurd: make sigstates hold a reference on thread ports
This change is required in order to correctly release per-thread resources. Directly reusing the threading library reference isn't possible since the sigstate is also used early in the main thread, before threading is initialized. * hurd/hurd/signal.h (_hurd_self_sigstate): Drop thread reference after calling _hurd_thread_sigstate. (_hurd_critical_section_lock): Likewise. * hurd/hurdsig.c (_hurd_thread_sigstate): Add a reference on the thread. (_hurd_sigstate_delete): Drop thread reference.
Diffstat (limited to 'hurd/hurdsig.c')
-rw-r--r--hurd/hurdsig.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index 852ae7e..6fdbf38 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -114,6 +114,8 @@ _hurd_thread_sigstate (thread_t thread)
}
else
{
+ error_t err;
+
/* Use the global actions as a default for new threads. */
struct hurd_sigstate *s = _hurd_global_sigstate;
if (s)
@@ -127,6 +129,11 @@ _hurd_thread_sigstate (thread_t thread)
ss->next = _hurd_sigstates;
_hurd_sigstates = ss;
+
+ err = __mach_port_mod_refs (__mach_task_self (), thread,
+ MACH_PORT_RIGHT_SEND, 1);
+ if (err)
+ __libc_fatal ("hurd: Can't add reference on Mach thread\n");
}
}
__mutex_unlock (&_hurd_siglock);
@@ -135,8 +142,7 @@ _hurd_thread_sigstate (thread_t thread)
libc_hidden_def (_hurd_thread_sigstate)
/* Destroy a sigstate structure. Called by libpthread just before the
- * corresponding thread is terminated (the kernel thread port must remain valid
- * until this function is called.) */
+ * corresponding thread is terminated. */
void
_hurd_sigstate_delete (thread_t thread)
{
@@ -153,7 +159,12 @@ _hurd_sigstate_delete (thread_t thread)
__mutex_unlock (&_hurd_siglock);
if (ss)
- free (ss);
+ {
+ if (ss->thread != MACH_PORT_NULL)
+ __mach_port_deallocate (__mach_task_self (), ss->thread);
+
+ free (ss);
+ }
}
/* Make SS a global receiver, with pthread signal semantics. */