Created
May 1, 2017 16:35
-
-
Save joakim-noah/a9beb4375d7621a938661cc3db4cb89e to your computer and use it in GitHub Desktop.
Android/ARM support for druntime, for ldc release-1.2.x branch 2.072
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/core/memory.d b/src/core/memory.d | |
index 0a427055..28408cb7 100644 | |
--- a/src/core/memory.d | |
+++ b/src/core/memory.d | |
@@ -38,7 +38,7 @@ | |
* | |
* Notes_to_implementors: | |
* $(UL | |
- * $(LI On POSIX systems, the signals SIGUSR1 and SIGUSR2 are reserved | |
+ * $(LI On POSIX systems, the signals `SIGRTMIN` and `SIGRTMIN + 1` are reserved | |
* by this module for use in the garbage collector implementation. | |
* Typically, they will be used to stop and resume other threads | |
* when performing a collection, but an implementation may choose | |
diff --git a/src/core/stdc/math.d b/src/core/stdc/math.d | |
index 8d1d38b0..f5b10ea7 100644 | |
--- a/src/core/stdc/math.d | |
+++ b/src/core/stdc/math.d | |
@@ -2459,7 +2459,7 @@ else version(CRuntime_Bionic) | |
double tan(double x); | |
/// | |
float tanf(float x); | |
- //real tanl(real x); | |
+ real tanl(real x); | |
/// | |
double acosh(double x); | |
@@ -2554,7 +2554,7 @@ else version(CRuntime_Bionic) | |
float log1pf(float x); | |
//real log1pl(real x); | |
- //double log2(double x); | |
+ double log2(double x); | |
//float log2f(float x); | |
//real log2l(real x); | |
diff --git a/src/core/sys/posix/fcntl.d b/src/core/sys/posix/fcntl.d | |
index 3e12f81e..795aa6b0 100644 | |
--- a/src/core/sys/posix/fcntl.d | |
+++ b/src/core/sys/posix/fcntl.d | |
@@ -626,6 +626,8 @@ else version( CRuntime_Bionic ) | |
int creat(in char*, mode_t); | |
int open(in char*, int, ...); | |
+ | |
+ enum AT_FDCWD = -100; | |
} | |
else | |
{ | |
diff --git a/src/core/sys/posix/pthread.d b/src/core/sys/posix/pthread.d | |
index 9ef96063..82e92e50 100644 | |
--- a/src/core/sys/posix/pthread.d | |
+++ b/src/core/sys/posix/pthread.d | |
@@ -450,7 +450,7 @@ else version( CRuntime_Bionic ) | |
struct __pthread_cleanup_t | |
{ | |
__pthread_cleanup_t* __cleanup_prev; | |
- __pthread_cleanup_func_t __cleanup_routine; | |
+ _pthread_cleanup_routine __cleanup_routine; | |
void* __cleanup_arg; | |
} | |
diff --git a/src/core/sys/posix/stdlib.d b/src/core/sys/posix/stdlib.d | |
index 4afd346d..95ce05a8 100644 | |
--- a/src/core/sys/posix/stdlib.d | |
+++ b/src/core/sys/posix/stdlib.d | |
@@ -108,6 +108,14 @@ else version( Solaris ) | |
{ | |
int posix_memalign(void**, size_t, size_t); | |
} | |
+else version( Darwin ) | |
+{ | |
+ int posix_memalign(void**, size_t, size_t); | |
+} | |
+else version( CRuntime_Bionic ) | |
+{ | |
+ int posix_memalign(void**, size_t, size_t); | |
+} | |
// | |
// C Extension (CX) | |
diff --git a/src/core/sys/posix/sys/stat.d b/src/core/sys/posix/sys/stat.d | |
index 2fa4f86f..61c2a225 100644 | |
--- a/src/core/sys/posix/sys/stat.d | |
+++ b/src/core/sys/posix/sys/stat.d | |
@@ -1048,6 +1048,9 @@ else version( CRuntime_Bionic ) | |
extern (D) bool S_ISREG( uint mode ) { return S_ISTYPE( mode, S_IFREG ); } | |
extern (D) bool S_ISLNK( uint mode ) { return S_ISTYPE( mode, S_IFLNK ); } | |
extern (D) bool S_ISSOCK( uint mode ) { return S_ISTYPE( mode, S_IFSOCK ); } | |
+ | |
+ int utimensat(int dirfd, const char *pathname, | |
+ ref const(timespec)[2] times, int flags); | |
} | |
else | |
{ | |
diff --git a/src/core/thread.d b/src/core/thread.d | |
index 5f9a2d81..f1b15731 100644 | |
--- a/src/core/thread.d | |
+++ b/src/core/thread.d | |
@@ -1908,7 +1908,7 @@ version( CoreDdoc ) | |
{ | |
/** | |
* Instruct the thread module, when initialized, to use a different set of | |
- * signals besides SIGUSR1 and SIGUSR2 for suspension and resumption of threads. | |
+ * signals besides `SIGRTMIN` and `SIGRTMIN + 1` for suspension and resumption of threads. | |
* This function should be called at most once, prior to thread_init(). | |
* This function is Posix-only. | |
*/ | |
@@ -1964,14 +1964,17 @@ extern (C) void thread_init() | |
} | |
else version( Posix ) | |
{ | |
+enum SIGRTMIN = 32; | |
+enum SIGRTMAX = 64; | |
if( suspendSignalNumber == 0 ) | |
{ | |
- suspendSignalNumber = SIGUSR1; | |
+ suspendSignalNumber = SIGRTMIN; | |
} | |
if( resumeSignalNumber == 0 ) | |
{ | |
- resumeSignalNumber = SIGUSR2; | |
+ resumeSignalNumber = SIGRTMIN + 1; | |
+ assert(resumeSignalNumber <= SIGRTMAX); | |
} | |
int status; | |
@@ -3949,6 +3952,10 @@ version( LDC ) | |
version( X86 ) version = CheckFiberMigration; | |
version( X86_64 ) version = CheckFiberMigration; | |
} | |
+ version( Android ) | |
+ { | |
+ version( ARM ) version = CheckFiberMigration; | |
+ } | |
} | |
// Fiber support for SjLj style exceptions | |
diff --git a/src/rt/sections_android.d b/src/rt/sections_android.d | |
index 60ca9a9a..a662887d 100644 | |
--- a/src/rt/sections_android.d | |
+++ b/src/rt/sections_android.d | |
@@ -62,12 +62,9 @@ private: | |
void initSections() | |
{ | |
pthread_key_create(&_tlsKey, null); | |
+ _sections.moduleGroup = ModuleGroup(getModuleInfos()); | |
- auto mbeg = cast(immutable ModuleInfo**)&__start_minfo; | |
- auto mend = cast(immutable ModuleInfo**)&__stop_minfo; | |
- _sections.moduleGroup = ModuleGroup(mbeg[0 .. mend - mbeg]); | |
- | |
- auto pbeg = cast(void*)&_tls_end; | |
+ auto pbeg = cast(void*)&_tlsend; | |
auto pend = cast(void*)&__bss_end__; | |
_sections._gcRanges[0] = pbeg[0 .. pend - pbeg]; | |
} | |
@@ -167,6 +164,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 | |
@@ -174,10 +203,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 0fddcc22..18684a10 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,7 +14,8 @@ ModuleInfo* getModuleInfo(string name) | |
bool tester() | |
{ | |
- return Runtime.args.length > 1 ? testModules() : testAll(); | |
+ //return Runtime.args.length > 1 ? testModules() : testAll(); | |
+ return testModules(); | |
} | |
string mode; | |
@@ -18,8 +23,14 @@ string mode; | |
bool testModules() | |
{ | |
+ string testList = "test.list"; | |
+ if(!testList.exists() || !testList.isFile) { | |
+ testList = "/sdcard/" ~ testList; | |
+ if(!testList.exists() || !testList.isFile) | |
+ return false; | |
+ } | |
bool ret = true; | |
- foreach(name; Runtime.args[1..$]) | |
+ foreach(name; File(testList).byLine()) | |
{ | |
immutable pkg = ".package"; | |
immutable pkgLen = pkg.length; | |
@@ -50,24 +61,39 @@ void doTest(ModuleInfo* moduleInfo, ref bool ret) | |
if (auto fp = moduleInfo.unitTest) | |
{ | |
auto name = moduleInfo.name; | |
+ version(apk) string output; | |
try | |
{ | |
immutable t0 = MonoTime.currTime; | |
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); | |
- ret = false; | |
+ //ret = false; | |
+ } | |
} | |
+ version(apk){ | |
+ __android_log_print(android_LogPriority.ANDROID_LOG_INFO, "test_runner", output.ptr); | |
+ append("/sdcard/test.log", output); | |
+ } | |
} | |
} | |
@@ -88,6 +114,6 @@ shared static this() | |
else static assert(0, "You must be from the future!"); | |
} | |
-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