Bug 1693762 - Extend the thread name length limit to 63 characters on Mac. r=kaie NSPR_4_30_BETA1
authorFlorian Quèze <florian@queze.net>
Wed, 24 Feb 2021 19:50:59 +0100
changeset 4912 cbbfa71c7e4a155e62732a817f3a3d5c3d9647a9
parent 4911 339390f0f87dd9fa3e95d9106559e9e3ad4cb5cc
child 4913 b09175587dad2bfb923ec87250ac80461f620577
push id393
push userkaie@kuix.de
push dateWed, 24 Feb 2021 18:52:03 +0000
reviewerskaie
bugs1693762
Bug 1693762 - Extend the thread name length limit to 63 characters on Mac. r=kaie
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -1689,23 +1689,30 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThre
 #endif
 
     *(void**)(&dynamic_pthread_setname_np) =
         dlsym(RTLD_DEFAULT, "pthread_setname_np");
     if (!dynamic_pthread_setname_np) {
         return PR_SUCCESS;
     }
 
+#if defined(DARWIN)
+    /* Mac OS X has a length limit of 63 characters, but there is no API
+     * exposing it.
+     */
+#define SETNAME_LENGTH_CONSTRAINT 63
+#else
     /*
      * The 15-character name length limit is an experimentally determined
-     * length of a null-terminated string that most linux distros and OS X
-     * accept as an argument to pthread_setname_np.  Otherwise the E2BIG
+     * length of a null-terminated string that most linux distros accept
+     * as an argument to pthread_setname_np.  Otherwise the E2BIG
      * error is returned by the function.
      */
 #define SETNAME_LENGTH_CONSTRAINT 15
+#endif
 #define SETNAME_FRAGMENT1_LENGTH (SETNAME_LENGTH_CONSTRAINT >> 1)
 #define SETNAME_FRAGMENT2_LENGTH \
     (SETNAME_LENGTH_CONSTRAINT - SETNAME_FRAGMENT1_LENGTH - 1)
     char name_dup[SETNAME_LENGTH_CONSTRAINT + 1];
     if (nameLen > SETNAME_LENGTH_CONSTRAINT) {
         memcpy(name_dup, name, SETNAME_FRAGMENT1_LENGTH);
         name_dup[SETNAME_FRAGMENT1_LENGTH] = '~';
         /* Note that this also copies the null terminator. */