1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-18 02:19:39 +00:00

libc: export pthread_getname_np stub

pthread_getname_np needs to be provided by libc in order to import
jemalloc 5.3.0.

A stub implementation for libc pthread_getname_np() is added for
_pthread_stubs.c, which always reports empty name for the main thread.

Internal _pthread_getname_np() is not exported, but provided for libc
own use.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D41461
This commit is contained in:
Minsoo Choo 2023-08-14 18:21:24 -04:00 committed by Konstantin Belousov
parent ed3fb74e44
commit 0dc52b7210
6 changed files with 21 additions and 3 deletions

View File

@ -426,6 +426,7 @@ FBSD_1.6 {
eventfd_write;
getlogin_r;
memalign;
pthread_getname_np;
scandir_b;
sigandset;
sigisemptyset;

View File

@ -58,6 +58,7 @@ static int stub_fail(void);
static int stub_true(void);
static void stub_exit(void);
static int stub_esrch(void);
static int stub_getname_np(pthread_t, char *, size_t);
#define PJT_DUAL_ENTRY(entry) \
(pthread_func_t)entry, (pthread_func_t)entry
@ -131,6 +132,7 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = {
[PJT_MUTEXATTR_SETROBUST] = {PJT_DUAL_ENTRY(stub_zero)},
[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)},
};
/*
@ -289,6 +291,7 @@ STUB_FUNC3(__pthread_cleanup_push_imp, PJT_CLEANUP_PUSH_IMP, void, void *,
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)
static int
stub_zero(void)
@ -337,3 +340,13 @@ stub_esrch(void)
{
return (ESRCH);
}
static int
stub_getname_np(pthread_t thread, char *buf, size_t len)
{
if (thread != &main_thread)
return (ESRCH);
if (len >= 1)
buf[0] = '\0';
return (0);
}

View File

@ -184,6 +184,7 @@ typedef enum {
PJT_MUTEXATTR_SETROBUST,
PJT_GETTHREADID_NP,
PJT_ATTR_GET_NP,
PJT_GETNAME_NP,
PJT_MAX
} pjt_index_t;

View File

@ -114,9 +114,10 @@ thr_get_name_np(struct pthread *thread, char *buf, size_t len)
buf[0] = '\0';
}
__weak_reference(_pthread_getname_np, pthread_getname_np);
__weak_reference(_thr_getname_np, pthread_getname_np);
__weak_reference(_thr_getname_np, _pthread_getname_np);
int
_pthread_getname_np(pthread_t thread, char *buf, size_t len)
_thr_getname_np(pthread_t thread, char *buf, size_t len)
{
struct pthread *curthread;
int res;
@ -147,5 +148,5 @@ __weak_reference(_pthread_get_name_np, pthread_get_name_np);
void
_pthread_get_name_np(pthread_t thread, char *buf, size_t len)
{
(void)_pthread_getname_np(thread, buf, len);
(void)_thr_getname_np(thread, buf, len);
}

View File

@ -271,6 +271,7 @@ static pthread_func_t jmp_table[][2] = {
[PJT_MUTEXATTR_SETROBUST] = {DUAL_ENTRY(_thr_mutexattr_setrobust)},
[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)},
};
static int init_once = 0;

View File

@ -1073,6 +1073,7 @@ int _thr_cond_wait(pthread_cond_t *, pthread_mutex_t *);
int _thr_detach(pthread_t);
int _thr_equal(pthread_t, pthread_t);
void _Tthr_exit(void *);
int _thr_getname_np(pthread_t, char *, size_t);
int _thr_key_create(pthread_key_t *, void (*)(void *));
int _thr_key_delete(pthread_key_t);
int _thr_setspecific(pthread_key_t, const void *);