Integrate FR Main Flash port on Chrome/pepper
authorDan Schaffer <Dan.Schaffer@adobe.com>
Thu, 24 Jan 2013 12:00:39 -0800
changeset 7582 a099bc675915
parent 7581 c7b1844ed46d
child 7583 8d37a994952c
push id4262
push userdschaffe@adobe.com
push dateWed, 30 Jan 2013 19:01:31 +0000
bugs1134559, 1158035
Integrate FR Main Flash port on Chrome/pepper p4 integrate -1 -d -t flashruntime/code/...@1134559,1134559 avm/code/... p4 resolve -n | wc -l # 5 files to integrate p4 resolve -as p4 resolve -n | wc -l # 1 file to integrate avmplus/AVMPI/MMgcPortUnix.cpp # am p4 resolve -n | wc -l # 0 files to integrate p4 opened | wc -l # 5 files opened CL@1158035
AVMPI/MMgcPortUnix.cpp
MMgc/GCHeap.cpp
core/Date.cpp
extensions/SamplerScript.cpp
--- a/AVMPI/MMgcPortUnix.cpp
+++ b/AVMPI/MMgcPortUnix.cpp
@@ -141,17 +141,17 @@ void* AVMPI_allocateAlignedMemory(size_t
 void AVMPI_releaseAlignedMemory(void* address)
 {
     free(address);
 }
 
 
 // Note: the linux #define provided by the compiler.
 
-#ifdef linux
+#if defined(linux) && !defined(PEPPER_PLUGIN)
 
 size_t AVMPI_getPrivateResidentPageCount()
 {
    int fd;
    ssize_t n;
    char readData[64];
 
    //
@@ -294,18 +294,37 @@ uintptr_t AVMPI_getThreadStackBase()
     pthread_setspecific(stackTopKey, (void*)stack_base);
     return (uintptr_t)stack_base;
 }
 
 #elif defined AVMPLUS_UNIX
 
 pthread_key_t stackTopKey = 0;
 
+#if defined(PEPPER_PLUGIN) && !defined(__APPLE__)
+namespace {
+// In the Linux Pepper plugin we count on the constructor being run before the sandbox is imposed.
+// TODO(vtl): This is super-hacky, fragile, and ugly. We really should do something better.
+class MainThreadInfoGetter {
+  public:
+    MainThreadInfoGetter() {
+        // This will set the TLS value for the main thread if necessary.
+        AVMPI_getThreadStackBase();
+    }
+} g_only_for_construction;
+}  // namespace
+#endif
+
 uintptr_t AVMPI_getThreadStackBase()
 {
+// For Pepper, we currently compile using this file instead of MMgcPortMac.cpp (which would have
+// other issues). Our Mac version is taken verbatim from MMgcPortMac.cpp.
+#if defined(PEPPER_PLUGIN) && defined(__APPLE__)
+    return (uintptr_t)pthread_get_stackaddr_np(pthread_self());
+#else
     // FIXME: race condition
     if(stackTopKey == 0)
     {
 #ifdef DEBUG
         int res =
 #endif
         pthread_key_create(&stackTopKey, NULL);
         GCAssert(res == 0);
@@ -335,16 +354,17 @@ uintptr_t AVMPI_getThreadStackBase()
     pthread_attr_destroy(&attr);
 
     stackTop = (void*) ((size_t)s_base + sz);
     // stackTop has to be greater than current stack pointer
     GCAssert(stackTop > &sz);
     pthread_setspecific(stackTopKey, stackTop);
     return (uintptr_t)stackTop;
 
+#endif
 }
 
 #elif defined(linux) && defined(MMGC_ARM)
 
 uintptr_t AVMPI_getThreadStackBase()
 {
     void* sp;
     pthread_attr_t attr;
--- a/MMgc/GCHeap.cpp
+++ b/MMgc/GCHeap.cpp
@@ -2585,17 +2585,20 @@ namespace MMgc
         {
             // Guard against repeated jumps: ef->m_heap doubles as a flag.  We go Abort->longjmp->~EnterFrame->Leave
             // and Leave calls StatusChangeNotify and the host code might do another allocation during shutdown
             // in which case we want to go to VMPI_abort instead.  At that point m_heap will be NULL and the right
             // thing happens.
             if (ef->m_heap != NULL)
             {
                 ef->UnwindAllObjects();
+// longjmps are incorrect in C++ code, and will break the Pepper plugin.
+#if !defined(PEPPER_PLUGIN)
                 VMPI_longjmpNoUnwind(ef->jmpbuf, 1);
+#endif
             }
         }
         GCAssertMsg(false, "MMGC_ENTER missing or we allocated more memory trying to shutdown");
         VMPI_abort();
     }
 
     void GCHeap::Enter(EnterFrame *frame)
     {
--- a/core/Date.cpp
+++ b/core/Date.cpp
@@ -2,16 +2,21 @@
 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 #include "avmplus.h"
 
+#if defined(PEPPER_PLUGIN)
+// TODO(vtl): Move stuff to a "glue" file, so that avmplus doesn't potentially depend on Flash core.
+#include "flash/platform/pepper/pep_datetime.h"
+#endif
+
 namespace avmplus
 {
 #ifdef FIX_RECIPROCAL_BUG
     //
     // Visual C++ 6.0 optimizes division by turning it into multiplication
     // by the reciprocal.  This loses precision and results in inaccuracies
     // in date calculations.  Avoid this "optimization" by putting the
     // numbers in static variables.
@@ -162,36 +167,56 @@ namespace avmplus
             result = 7 + result;
         }
         return result;
     }
 
     /* This needs to be publicly available, for Mac edge code. (srj) */
     double UTC(double t)
     {
+#if defined(PEPPER_PLUGIN)
+        // TODO(vtl): This is just a clone of the code below; we should probably provide our own
+        // implementations of |VMPI_...()|.
+        double adj = pepper::GetTimeZoneAdjustment();
+        double dstAdjust = pepper::GetDaylightSavingTimeAdjustmentForTime(t - adj);
+        if (dstAdjust != 0) {
+            double dst2 = pepper::GetDaylightSavingTimeAdjustmentForTime(t - adj - kMsecPerHour);
+            if (dst2 == 0)
+                t += kMsecPerHour;
+        }
+        return (t - adj - dstAdjust);
+#else
         double adj = VMPI_getLocalTimeOffset();
 
         // If DST is in effect, and our time value is in a "gap" period
         // (e.g. between 2:00:00AM and 2:59:59AM when DST occurs at 2:00AM)
         // we need to adjust the time +1:00 to account for the "spring forward"
         double dstAdjust = VMPI_getDaylightSavingsTA(t - adj);
         if (dstAdjust != 0)
         {
             // Date/time falls in DST, check if this is a valid time
             double dst2 = VMPI_getDaylightSavingsTA(t - adj - kMsecPerHour);
             if (dst2 == 0)
             t += kMsecPerHour;
         }
 
         return (t - adj - dstAdjust);
+#endif
     }
 
     static double LocalTime(double t)
     {
+#if defined(PEPPER_PLUGIN)
+        // TODO(vtl): This is just a clone of the code below; we should probably provide our own
+        // implementations of |VMPI_...()|.
+        return t + pepper::GetTimeZoneAdjustment() +
+                pepper::GetDaylightSavingTimeAdjustmentForTime(t);
+#else
         return (t + VMPI_getLocalTimeOffset() + VMPI_getDaylightSavingsTA(t));
+#endif
     }
 
     // this needs to be publicly available, for data paraser
     double GetTimezoneOffset(double t)
     {
         return (t - LocalTime(t)) / kMsecPerMinute;
     }
 
--- a/extensions/SamplerScript.cpp
+++ b/extensions/SamplerScript.cpp
@@ -6,16 +6,17 @@
 
 
 // Adobe patent application tracking #P721, entitled Application Profiling, inventors: T. Reilly
 
 #ifdef AVMSHELL_BUILD
 #include "avmshell.h"
 #else
 // player
+#include "platformbuild.h"
 #include "avmplayer-classes.h"
 #include "SamplerScript.h"
 #endif
 
 using namespace MMgc;
 
 namespace avmplus
 {