Skip to content

Commit

Permalink
libc, libthr: coordinate stubs for pthread_{suspend,resume}_all_np
Browse files Browse the repository at this point in the history
If libthr isn't linked into the process, then we don't have any pthreads
to worry about and our stubs can just return success -- there are none
to suspend/resume.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D47350
  • Loading branch information
kevans91 committed Nov 14, 2024
1 parent 092e2ff commit 83aafcd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/libc/gen/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ FBSD_1.0 {
pthread_mutexattr_init;
pthread_mutexattr_settype;
pthread_once;
pthread_resume_all_np;
pthread_rwlock_destroy;
pthread_rwlock_init;
pthread_rwlock_rdlock;
Expand All @@ -59,6 +60,7 @@ FBSD_1.0 {
pthread_setcanceltype;
pthread_setspecific;
pthread_sigmask;
pthread_suspend_all_np;
pthread_testcancel;
alarm;
arc4random;
Expand Down
4 changes: 4 additions & 0 deletions lib/libc/gen/_pthread_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = {
[PJT_GETTHREADID_NP] = {PJT_DUAL_ENTRY(stub_zero)},
[PJT_ATTR_GET_NP] = {PJT_DUAL_ENTRY(stub_esrch)},
[PJT_GETNAME_NP] = {PJT_DUAL_ENTRY(stub_getname_np)},
[PJT_SUSPEND_ALL_NP] = {PJT_DUAL_ENTRY(stub_null)},
[PJT_RESUME_ALL_NP] = {PJT_DUAL_ENTRY(stub_null)},
};

/*
Expand Down Expand Up @@ -291,6 +293,8 @@ STUB_FUNC1(_pthread_cancel_enter, PJT_CANCEL_ENTER, void, int)
STUB_FUNC1(_pthread_cancel_leave, PJT_CANCEL_LEAVE, void, int)
STUB_FUNC2(pthread_attr_get_np, PJT_ATTR_GET_NP, int, pthread_t, pthread_attr_t *)
STUB_FUNC3(pthread_getname_np, PJT_GETNAME_NP, int, pthread_t, char *, size_t)
STUB_FUNC(pthread_suspend_all_np, PJT_SUSPEND_ALL_NP, void);
STUB_FUNC(pthread_resume_all_np, PJT_RESUME_ALL_NP, void);

static int
stub_zero(void)
Expand Down
2 changes: 2 additions & 0 deletions lib/libc/include/libc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ typedef enum {
PJT_GETTHREADID_NP,
PJT_ATTR_GET_NP,
PJT_GETNAME_NP,
PJT_SUSPEND_ALL_NP,
PJT_RESUME_ALL_NP,
PJT_MAX
} pjt_index_t;

Expand Down
2 changes: 2 additions & 0 deletions lib/libthr/thread/thr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ static pthread_func_t jmp_table[][2] = {
[PJT_GETTHREADID_NP] = {DUAL_ENTRY(_thr_getthreadid_np)},
[PJT_ATTR_GET_NP] = {DUAL_ENTRY(_thr_attr_get_np)},
[PJT_GETNAME_NP] = {DUAL_ENTRY(_thr_getname_np)},
[PJT_SUSPEND_ALL_NP] = {DUAL_ENTRY(_thr_suspend_all_np)},
[PJT_RESUME_ALL_NP] = {DUAL_ENTRY(_thr_resume_all_np)},
};

static int init_once = 0;
Expand Down
2 changes: 2 additions & 0 deletions lib/libthr/thread/thr_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ void _thr_signal_postfork(void) __hidden;
void _thr_signal_postfork_child(void) __hidden;
void _thr_suspend_all_lock(struct pthread *) __hidden;
void _thr_suspend_all_unlock(struct pthread *) __hidden;
void _thr_suspend_all_np(void) __hidden;
void _thr_resume_all_np(void) __hidden;
void _thr_try_gc(struct pthread *, struct pthread *) __hidden;
int _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
struct sched_param *param) __hidden;
Expand Down
5 changes: 3 additions & 2 deletions lib/libthr/thread/thr_resume_np.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#include "thr_private.h"

__weak_reference(_pthread_resume_np, pthread_resume_np);
__weak_reference(_pthread_resume_all_np, pthread_resume_all_np);
__weak_reference(_thr_resume_all_np, pthread_resume_all_np);
__weak_reference(_thr_resume_all_np, _pthread_resume_all_np);

static void resume_common(struct pthread *thread);

Expand All @@ -59,7 +60,7 @@ _pthread_resume_np(pthread_t thread)
}

void
_pthread_resume_all_np(void)
_thr_resume_all_np(void)
{
struct pthread *curthread = _get_curthread();
struct pthread *thread;
Expand Down
5 changes: 3 additions & 2 deletions lib/libthr/thread/thr_suspend_np.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ static int suspend_common(struct pthread *, struct pthread *,
int);

__weak_reference(_pthread_suspend_np, pthread_suspend_np);
__weak_reference(_pthread_suspend_all_np, pthread_suspend_all_np);
__weak_reference(_thr_suspend_all_np, pthread_suspend_all_np);
__weak_reference(_thr_suspend_all_np, _pthread_suspend_all_np);

/* Suspend a thread: */
int
Expand Down Expand Up @@ -101,7 +102,7 @@ _thr_suspend_all_unlock(struct pthread *curthread)
}

void
_pthread_suspend_all_np(void)
_thr_suspend_all_np(void)
{
struct pthread *curthread = _get_curthread();
struct pthread *thread;
Expand Down

0 comments on commit 83aafcd

Please sign in to comment.