<rdar://problem/7879485> Leopard: Crash after opening Software Update dialog
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Apr 2010 20:05:01 +0000 (20:05 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Apr 2010 20:05:01 +0000 (20:05 +0000)
Reviewed by Sam Weinig.

* JSUtils.cpp:
(unprotectGlobalObject): Use the version of JSGlueAPIEntry that doesn't
call pthread_getspecific, since it's not safe to call pthread_getspecific
from a thread-specific data destructor. (<rdar://problem/7889842>
pthread_getspecific returns 0 when called from thread-specific data
destructor function)

(getThreadGlobalObject): Make sure to set the currentIdentifierTable
when first constructing our JSGlobalObject, since JSGlueAPIEntry has not
yet had an opportunity to do so.

(JSGlueAPIEntry::JSGlueAPIEntry):
* JSUtils.h: New version of JSGlueAPIEntry that doesn't call
pthread_getspecific.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@58009 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptGlue/ChangeLog
JavaScriptGlue/JSUtils.cpp
JavaScriptGlue/JSUtils.h

index 65637fb..69a8208 100644 (file)
@@ -1,3 +1,24 @@
+2010-04-21  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <rdar://problem/7879485> Leopard: Crash after opening Software Update dialog
+
+        * JSUtils.cpp:
+        (unprotectGlobalObject): Use the version of JSGlueAPIEntry that doesn't
+        call pthread_getspecific, since it's not safe to call pthread_getspecific
+        from a thread-specific data destructor. (<rdar://problem/7889842>
+        pthread_getspecific returns 0 when called from thread-specific data
+        destructor function)
+
+        (getThreadGlobalObject): Make sure to set the currentIdentifierTable
+        when first constructing our JSGlobalObject, since JSGlueAPIEntry has not
+        yet had an opportunity to do so.
+
+        (JSGlueAPIEntry::JSGlueAPIEntry):
+        * JSUtils.h: New version of JSGlueAPIEntry that doesn't call
+        pthread_getspecific.
+
 2010-04-21  Gavin Barraclough  <barraclough@apple.com>
 
         Reviewed by NOBODY (build fix).
index a4a2ba7..f2b7e64 100644 (file)
@@ -395,8 +395,9 @@ static pthread_once_t globalObjectKeyOnce = PTHREAD_ONCE_INIT;
 
 static void unprotectGlobalObject(void* data) 
 {
-    JSGlueAPIEntry entry;
-    gcUnprotect(static_cast<JSGlueGlobalObject*>(data));
+    JSGlobalObject* jsGlobalObject = static_cast<JSGlueGlobalObject*>(data);
+    JSGlueAPIEntry entry(jsGlobalObject);
+    gcUnprotect(jsGlobalObject);
 }
 
 static void initializeGlobalObjectKey()
@@ -409,8 +410,14 @@ static JSGlueGlobalObject* getThreadGlobalObject()
     pthread_once(&globalObjectKeyOnce, initializeGlobalObjectKey);
     JSGlueGlobalObject* globalObject = static_cast<JSGlueGlobalObject*>(pthread_getspecific(globalObjectKey));
     if (!globalObject) {
-        globalObject = new (&JSGlobalData::sharedInstance()) JSGlueGlobalObject(JSGlueGlobalObject::createStructure(jsNull()));
+        JSGlobalData& globalData = JSGlobalData::sharedInstance();
+
+        IdentifierTable* storedIdentifierTable = wtfThreadData().currentIdentifierTable();
+        wtfThreadData().setCurrentIdentifierTable(globalData.identifierTable);
+        globalObject = new (&globalData) JSGlueGlobalObject(JSGlueGlobalObject::createStructure(jsNull()));
         gcProtect(globalObject);
+        wtfThreadData().setCurrentIdentifierTable(storedIdentifierTable);
+
         pthread_setspecific(globalObjectKey, globalObject);
     }
     return globalObject;
@@ -433,6 +440,13 @@ JSGlueAPIEntry::JSGlueAPIEntry()
     wtfThreadData().setCurrentIdentifierTable(getThreadGlobalObject()->globalExec()->globalData().identifierTable);
 }
 
+JSGlueAPIEntry::JSGlueAPIEntry(JSGlobalObject* jsGlobalObject)
+    : m_lock(LockForReal)
+    , m_storedIdentifierTable(wtfThreadData().currentIdentifierTable())
+{
+    wtfThreadData().setCurrentIdentifierTable(jsGlobalObject->globalExec()->globalData().identifierTable);
+}
+
 JSGlueAPIEntry::~JSGlueAPIEntry()
 {
     wtfThreadData().setCurrentIdentifierTable(m_storedIdentifierTable);
index 05bce62..cbd9912 100644 (file)
@@ -80,6 +80,7 @@ enum {
 class JSGlueAPIEntry {
 public:
     JSGlueAPIEntry();
+    JSGlueAPIEntry(JSGlobalObject*); // For use when it's not safe for JSGlueAPIEntry() to call getThreadGlobalObject() -- for example, from a thread-specific data destructor.
     ~JSGlueAPIEntry();
 
 private: