diff options
author | William Roberts <wroberts@tresys.com> | 2013-10-29 15:19:22 -0700 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2014-01-17 00:19:50 -0800 |
commit | 258f631e86c4a78888ff49719e3eb9eaeb1ed835 (patch) | |
tree | 91f4361d88402204c8060badb46ac0cac93b0628 | |
parent | 9e32e7e27c85d4a2e4781e24fe97c02d2d623ade (diff) | |
download | android_dalvik-258f631e86c4a78888ff49719e3eb9eaeb1ed835.tar.gz android_dalvik-258f631e86c4a78888ff49719e3eb9eaeb1ed835.tar.bz2 android_dalvik-258f631e86c4a78888ff49719e3eb9eaeb1ed835.zip |
export setThreadName() and add NULL check
Change-Id: I9b69a23b308fe851ed49722c0da3953433b3f5b8
-rw-r--r-- | vm/Ddm.h | 3 | ||||
-rw-r--r-- | vm/Thread.cpp | 12 | ||||
-rw-r--r-- | vm/Thread.h | 7 |
3 files changed, 19 insertions, 3 deletions
@@ -19,6 +19,9 @@ #ifndef DALVIK_DDM_H_ #define DALVIK_DDM_H_ +#include <stdbool.h> +#include "Thread.h" + /* * Handle a packet full of DDM goodness. * diff --git a/vm/Thread.cpp b/vm/Thread.cpp index 1ebfca74c..c3d944b0c 100644 --- a/vm/Thread.cpp +++ b/vm/Thread.cpp @@ -1179,11 +1179,17 @@ static bool createFakeRunFrame(Thread* thread) /* * Helper function to set the name of the current thread */ -static void setThreadName(const char *threadName) +void dvmSetThreadName(const char *threadName) { int hasAt = 0; int hasDot = 0; const char *s = threadName; + + if (s == NULL) { + ALOGW("Unable to set the name of current thread to NULL"); + return; + } + while (*s) { if (*s == '.') hasDot = 1; else if (*s == '@') hasAt = 1; @@ -1462,7 +1468,7 @@ static void* interpThreadStart(void* arg) Thread* self = (Thread*) arg; std::string threadName(dvmGetThreadName(self)); - setThreadName(threadName.c_str()); + dvmSetThreadName(threadName.c_str()); /* * Finish initializing the Thread struct. @@ -1724,7 +1730,7 @@ static void* internalThreadStart(void* arg) jniArgs.name = pArgs->name; jniArgs.group = reinterpret_cast<jobject>(pArgs->group); - setThreadName(pArgs->name); + dvmSetThreadName(pArgs->name); /* use local jniArgs as stack top */ if (dvmAttachCurrentThread(&jniArgs, pArgs->isDaemon)) { diff --git a/vm/Thread.h b/vm/Thread.h index 19bd49c3b..0bf15e637 100644 --- a/vm/Thread.h +++ b/vm/Thread.h @@ -608,4 +608,11 @@ void dvmDumpAllThreadsEx(const DebugOutputTarget* target, bool grabLock); */ void dvmNukeThread(Thread* thread); +/* + * Sets the thread's name as pointed to by threadName in task_struct->comm. + * Note this field has a limited width, and larger values will be truncated + * to this width starting from the end. + */ +void dvmSetThreadName(const char *threadName); + #endif // DALVIK_THREAD_H_ |