Merge "export setThreadName() and add NULL check"
diff --git a/vm/Ddm.h b/vm/Ddm.h
index f8c22ee..fe2fe75 100644
--- a/vm/Ddm.h
+++ b/vm/Ddm.h
@@ -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 1ebfca7..c3d944b 100644
--- a/vm/Thread.cpp
+++ b/vm/Thread.cpp
@@ -1179,11 +1179,17 @@
/*
* 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 @@
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 @@
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 19bd49c..0bf15e6 100644
--- a/vm/Thread.h
+++ b/vm/Thread.h
@@ -608,4 +608,11 @@
*/
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_