The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0dc52b72108e321a99022785713c58d278696af2

commit 0dc52b72108e321a99022785713c58d278696af2
Author:     Minsoo Choo <[email protected]>
AuthorDate: 2023-08-14 22:21:24 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2023-08-20 22:44:17 +0000

    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
---
 lib/libc/gen/Symbol.map         |  1 +
 lib/libc/gen/_pthread_stubs.c   | 13 +++++++++++++
 lib/libc/include/libc_private.h |  1 +
 lib/libthr/thread/thr_info.c    |  7 ++++---
 lib/libthr/thread/thr_init.c    |  1 +
 lib/libthr/thread/thr_private.h |  1 +
 6 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index 9dd7334728a4..bdd659197644 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -426,6 +426,7 @@ FBSD_1.6 {
        eventfd_write;
        getlogin_r;
        memalign;
+       pthread_getname_np;
        scandir_b;
        sigandset;
        sigisemptyset;
diff --git a/lib/libc/gen/_pthread_stubs.c b/lib/libc/gen/_pthread_stubs.c
index 6741c6a5ec51..25dfeb2cc270 100644
--- a/lib/libc/gen/_pthread_stubs.c
+++ b/lib/libc/gen/_pthread_stubs.c
@@ -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);
+}
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index 5c740edf3fcc..a9ad2ef21b0b 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -184,6 +184,7 @@ typedef enum {
        PJT_MUTEXATTR_SETROBUST,
        PJT_GETTHREADID_NP,
        PJT_ATTR_GET_NP,
+       PJT_GETNAME_NP,
        PJT_MAX
 } pjt_index_t;
 
diff --git a/lib/libthr/thread/thr_info.c b/lib/libthr/thread/thr_info.c
index b5b84b733db6..41ab7f0bcf0c 100644
--- a/lib/libthr/thread/thr_info.c
+++ b/lib/libthr/thread/thr_info.c
@@ -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);
 }
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index ef8c7d59d729..b59678c3f6c3 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -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;
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index fba3b78e43c5..3475029f8996 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -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 *);

Reply via email to