Skip to content

Commit eec49f3

Browse files
nichtverstehencommit-bot@chromium.org
authored andcommitted
Always truncate thread names on linux to 15 chars (16 with the null terminator).
On Linux it is an error for a thread name to exceed 16 bytes. Thus also changing the VM thread pool to use the shorter "DartWorker" name. Change-Id: I4c5cc2bfb831a5593a8652d6435631b9d3803720 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126163 Commit-Queue: Kirill Nikolaev <cyriln@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent 28fc037 commit eec49f3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

runtime/vm/os_thread_android.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include "vm/os_thread.h"
1010

11-
#include <errno.h> // NOLINT
11+
#include <errno.h> // NOLINT
12+
#include <stdio.h>
1213
#include <sys/time.h> // NOLINT
1314

1415
#include "platform/address_sanitizer.h"
@@ -119,8 +120,10 @@ static void* ThreadStart(void* data_ptr) {
119120
uword parameter = data->parameter();
120121
delete data;
121122

122-
// Set the thread name.
123-
pthread_setname_np(pthread_self(), name);
123+
// Set the thread name. There is 16 bytes limit on the name (including \0).
124+
char truncated_name[16];
125+
snprintf(truncated_name, ARRAY_SIZE(truncated_name), "%s", name);
126+
pthread_setname_np(pthread_self(), truncated_name);
124127

125128
// Create new OSThread object and set as TLS for new thread.
126129
OSThread* thread = OSThread::CreateOSThread();

runtime/vm/os_thread_linux.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include "vm/os_thread.h"
1010

11-
#include <errno.h> // NOLINT
11+
#include <errno.h> // NOLINT
12+
#include <stdio.h>
1213
#include <sys/resource.h> // NOLINT
1314
#include <sys/syscall.h> // NOLINT
1415
#include <sys/time.h> // NOLINT
@@ -121,8 +122,10 @@ static void* ThreadStart(void* data_ptr) {
121122
uword parameter = data->parameter();
122123
delete data;
123124

124-
// Set the thread name.
125-
pthread_setname_np(pthread_self(), name);
125+
// Set the thread name. There is 16 bytes limit on the name (including \0).
126+
char truncated_name[16];
127+
snprintf(truncated_name, ARRAY_SIZE(truncated_name), "%s", name);
128+
pthread_setname_np(pthread_self(), truncated_name);
126129

127130
// Create new OSThread object and set as TLS for new thread.
128131
OSThread* thread = OSThread::CreateOSThread();

runtime/vm/thread_pool.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void ThreadPool::Worker::StartThread() {
335335
ASSERT(task_ != nullptr);
336336
}
337337
#endif
338-
int result = OSThread::Start("Dart ThreadPool Worker", &Worker::Main,
338+
int result = OSThread::Start("DartWorker", &Worker::Main,
339339
reinterpret_cast<uword>(this));
340340
if (result != 0) {
341341
FATAL1("Could not start worker thread: result = %d.", result);

0 commit comments

Comments
 (0)