Created
May 21, 2016 08:44
-
-
Save joakim-noah/069036835dd92cf648a8219bfe4d68c3 to your computer and use it in GitHub Desktop.
Android/ARM support for druntime, for ldc release-1.0.0 branch 2.070
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/gc/proxy.d b/src/gc/proxy.d | |
index e8d96cd..d905d32 100644 | |
--- a/src/gc/proxy.d | |
+++ b/src/gc/proxy.d | |
@@ -25,6 +25,7 @@ private | |
alias BlkInfo = core.memory.GC.BlkInfo; | |
extern (C) void thread_init(); | |
+ version(Android) extern (C) void thread_setGCSignals(int suspendSignalNo, int resumeSignalNo); | |
extern (C) void thread_term(); | |
struct Proxy | |
@@ -107,6 +108,10 @@ extern (C) | |
_gc.initialize(); | |
// NOTE: The GC must initialize the thread library | |
// before its first collection. | |
+ version(Android){ | |
+ import core.sys.posix.signal : SIGUSR1, SIGUSR2; | |
+ thread_setGCSignals(SIGUSR2, SIGUSR1); | |
+ } | |
thread_init(); | |
initProxy(); | |
} | |
diff --git a/src/rt/lifetime.d b/src/rt/lifetime.d | |
index 126dca5..60f3dd0 100644 | |
--- a/src/rt/lifetime.d | |
+++ b/src/rt/lifetime.d | |
@@ -2689,7 +2689,7 @@ unittest | |
} | |
// test class finalizers exception handling | |
-unittest | |
+version(Android) {} else unittest //passes but causes problems for later tests | |
{ | |
bool test(E)() | |
{ | |
@@ -2724,8 +2724,7 @@ unittest | |
} | |
// test struct finalizers exception handling | |
-debug(SENTINEL) {} else | |
-unittest | |
+version(Android) {} else unittest //passes but causes problems for later tests | |
{ | |
if (!callStructDtorsDuringGC) | |
return; | |
diff --git a/src/rt/sections_android.d b/src/rt/sections_android.d | |
index d4d06e6..cfab2c0 100644 | |
--- a/src/rt/sections_android.d | |
+++ b/src/rt/sections_android.d | |
@@ -62,10 +62,7 @@ private: | |
void initSections() | |
{ | |
pthread_key_create(&_tlsKey, null); | |
- | |
- auto mbeg = cast(immutable ModuleInfo**)&__start_minfo; | |
- auto mend = cast(immutable ModuleInfo**)&__stop_minfo; | |
- _sections.moduleGroup = ModuleGroup(mbeg[0 .. mend - mbeg]); | |
+ _sections.moduleGroup = ModuleGroup(getModuleInfos()); | |
auto pbeg = cast(void*)&_tlsend; | |
auto pend = cast(void*)&__bss_end__; | |
@@ -168,6 +165,38 @@ ref void[] getTLSBlockAlloc() | |
__gshared SectionGroup _sections; | |
+// This linked list is created by a compiler generated function inserted | |
+// into the .ctor list by the compiler. | |
+struct ModuleReference | |
+{ | |
+ ModuleReference* next; | |
+ ModuleInfo* mod; | |
+} | |
+ | |
+extern (C) __gshared immutable(ModuleReference*) _Dmodule_ref; // start of linked list | |
+ | |
+immutable(ModuleInfo*)[] getModuleInfos() | |
+out (result) | |
+{ | |
+ foreach(m; result) | |
+ assert(m !is null); | |
+} | |
+body | |
+{ | |
+ size_t len; | |
+ immutable(ModuleReference)* mr; | |
+ | |
+ for (mr = _Dmodule_ref; mr; mr = mr.next) | |
+ len++; | |
+ auto result = (cast(immutable(ModuleInfo)**).malloc(len * size_t.sizeof))[0 .. len]; | |
+ len = 0; | |
+ for (mr = _Dmodule_ref; mr; mr = mr.next) | |
+ { result[len] = mr.mod; | |
+ len++; | |
+ } | |
+ return cast(immutable)result; | |
+} | |
+ | |
extern(C) | |
{ | |
/* Symbols created by the compiler/linker and inserted into the | |
@@ -175,10 +204,8 @@ extern(C) | |
*/ | |
extern __gshared | |
{ | |
- void* __start_deh; | |
- void* __stop_deh; | |
- void* __start_minfo; | |
- void* __stop_minfo; | |
+ void* _deh_beg; | |
+ void* _deh_end; | |
size_t __bss_end__; | |
diff --git a/src/test_runner.d b/src/test_runner.d | |
index 54950d6..63ed3eb 100644 | |
--- a/src/test_runner.d | |
+++ b/src/test_runner.d | |
@@ -1,7 +1,11 @@ | |
+module test_runner; | |
import core.runtime, core.time : MonoTime; | |
import core.stdc.stdio; | |
+version(apk) import android.log, std.file: append; | |
+import std.stdio: File; | |
+import std.file: exists, isFile; | |
-ModuleInfo* getModuleInfo(string name) | |
+ModuleInfo* getModuleInfo(char[] name) | |
{ | |
foreach (m; ModuleInfo) | |
if (m.name == name) return m; | |
@@ -10,8 +14,16 @@ ModuleInfo* getModuleInfo(string name) | |
bool tester() | |
{ | |
- assert(Runtime.args.length == 2); | |
- auto name = Runtime.args[1]; | |
+ //assert(Runtime.args.length == 2); | |
+ //auto name = Runtime.args[1]; | |
+ string testList = "test.list"; | |
+ if(!testList.exists() || !testList.isFile) { | |
+ testList = "/sdcard/" ~ testList; | |
+ if(!testList.exists() || !testList.isFile) | |
+ return false; | |
+ } | |
+ foreach(name; File(testList).byLine()){ | |
+ version(apk) string output; | |
immutable pkg = ".package"; | |
immutable pkgLen = pkg.length; | |
@@ -32,20 +44,35 @@ bool tester() | |
printf("STARTING %.*s\n", | |
cast(uint)name.length, name.ptr); | |
fp(); | |
+ version(apk) { | |
+ char[11] time; | |
+ int timelen = snprintf(time.ptr, 11, "%.3f", (MonoTime.currTime - t0).total!"msecs" / 1000.0); | |
+ output ~= time[0 .. timelen] ~ "s PASS " ~ name ~ "\n"; | |
+ } else { | |
printf("%.3fs PASS %.*s %.*s\n", | |
(MonoTime.currTime - t0).total!"msecs" / 1000.0, | |
cast(uint)mode.length, mode.ptr, | |
cast(uint)name.length, name.ptr); | |
+ } | |
} | |
catch (Throwable e) | |
{ | |
auto msg = e.toString(); | |
+ version(apk) | |
+ output ~= "****** FAIL " ~ name ~ "\n" ~ msg ~ "\n"; | |
+ else { | |
printf("****** FAIL %.*s %.*s\n%.*s\n", | |
cast(uint)mode.length, mode.ptr, | |
cast(uint)name.length, name.ptr, | |
cast(uint)msg.length, msg.ptr); | |
- return false; | |
+ //return false; | |
+ } | |
} | |
+ version(apk){ | |
+ __android_log_print(android_LogPriority.ANDROID_LOG_INFO, "test_runner", output.ptr); | |
+ append("/sdcard/test.log", output); | |
+ } | |
+ } | |
} | |
return true; | |
} | |
@@ -55,6 +82,6 @@ shared static this() | |
Runtime.moduleUnitTester = &tester; | |
} | |
-void main() | |
+version(apk) {} else void main() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment