Skip to content

Instantly share code, notes, and snippets.

@joakim-noah
Created May 7, 2015 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joakim-noah/c27a0c7f2b5b65cdc268 to your computer and use it in GitHub Desktop.
Save joakim-noah/c27a0c7f2b5b65cdc268 to your computer and use it in GitHub Desktop.
Druntime patch for Android with ldc
diff --git a/src/core/checkedint.d b/src/core/checkedint.d
index 2baa4b4..cda2004 100644
--- a/src/core/checkedint.d
+++ b/src/core/checkedint.d
@@ -492,7 +492,7 @@ unittest
}
/// ditto
-long muls(long x, long y, ref bool overflow)
+/*long muls(long x, long y, ref bool overflow)
{
version(LDC)
{
@@ -527,7 +527,7 @@ unittest
assert(overflow);
assert(muls(0L, 0L, overflow) == 0);
assert(overflow); // sticky
-}
+}*/
/*******************************
diff --git a/src/core/math.d b/src/core/math.d
index cb72714..d36dca2 100644
--- a/src/core/math.d
+++ b/src/core/math.d
@@ -47,7 +47,7 @@ public:
*/
version (LDC)
- real cos(real x) @safe pure nothrow { return llvm_cos(x); }
+ real cos(real x) @safe pure nothrow { return cos(x); }
else
real cos(real x) @safe pure nothrow; /* intrinsic */
@@ -65,7 +65,7 @@ real cos(real x) @safe pure nothrow; /* intrinsic */
*/
version (LDC)
- real sin(real x) @safe pure nothrow { return llvm_sin(x); }
+ real sin(real x) @safe pure nothrow { return sin(x); }
else
real sin(real x) @safe pure nothrow; /* intrinsic */
@@ -164,7 +164,7 @@ version (LDC)
}
else
{
- return stdc.ldexpl(n, exp);
+ return stdc.ldexp(n, exp);
}
}
}
@@ -172,8 +172,8 @@ else
real ldexp(real n, int exp) @safe pure nothrow; /* intrinsic */
unittest {
- assert(ldexp(1, -16384) == 0x1p-16384L);
- assert(ldexp(1, -16382) == 0x1p-16382L);
+ //assert(ldexp(1, -16384) == 0x1p-16384L);
+ //assert(ldexp(1, -16382) == 0x1p-16382L);
}
/*******************************
@@ -190,7 +190,7 @@ version (LDC)
static if (__traits(compiles, llvm_abs(3.14L)))
real fabs(real x) @safe pure nothrow { return llvm_fabs(x); }
else
- real fabs(real x) @safe pure nothrow { return stdc.fabsl(x); }
+ real fabs(real x) @safe pure nothrow { return stdc.fabs(x); }
}
else
real fabs(real x) @safe pure nothrow; /* intrinsic */
@@ -206,7 +206,7 @@ real fabs(real x) @safe pure nothrow; /* intrinsic */
version (LDC)
{
static if (__traits(compiles, llvm_rint(3.14L)))
- real rint(real x) @safe pure nothrow { return llvm_rint(x); }
+ real rint(real x) @safe pure nothrow { return rint(x); }
else
real rint(real x) @safe pure nothrow { return stdc.rintl(x); }
}
diff --git a/src/core/stdc/math.d b/src/core/stdc/math.d
index e13d751..e584b0d 100644
--- a/src/core/stdc/math.d
+++ b/src/core/stdc/math.d
@@ -1278,6 +1278,238 @@ else version( FreeBSD )
double fma(double x, double y, double z);
float fmaf(float x, float y, float z);
}
+else version(Android)
+{
+ // Android defines long double as 64 bits, same as double, so several long
+ // double functions are missing. nexttoward was modified to reflect this.
+ double acos(double x);
+ float acosf(float x);
+ //real acosl(real x);
+
+ double asin(double x);
+ float asinf(float x);
+ //real asinl(real x);
+
+ double atan(double x);
+ float atanf(float x);
+ //real atanl(real x);
+
+ double atan2(double y, double x);
+ float atan2f(float y, float x);
+ //real atan2l(real y, real x);
+
+ double cos(double x);
+ float cosf(float x);
+ //real cosl(real x);
+
+ double sin(double x);
+ float sinf(float x);
+ //real sinl(real x);
+
+ double tan(double x);
+ float tanf(float x);
+ //real tanl(real x);
+
+ double acosh(double x);
+ float acoshf(float x);
+ //real acoshl(real x);
+
+ double asinh(double x);
+ float asinhf(float x);
+ //real asinhl(real x);
+
+ double atanh(double x);
+ float atanhf(float x);
+ //real atanhl(real x);
+
+ double cosh(double x);
+ float coshf(float x);
+ //real coshl(real x);
+
+ double sinh(double x);
+ float sinhf(float x);
+ //real sinhl(real x);
+
+ double tanh(double x);
+ float tanhf(float x);
+ //real tanhl(real x);
+
+ double exp(double x);
+ float expf(float x);
+ //real expl(real x);
+
+ double exp2(double x);
+ float exp2f(float x);
+ real exp2l(real x) { return exp2(x); }
+
+ double expm1(double x);
+ float expm1f(float x);
+ //real expm1l(real x);
+
+ double frexp(double value, int* exp);
+ float frexpf(float value, int* exp);
+ // alias for double: real frexpl(real value, int* exp);
+
+ int ilogb(double x);
+ int ilogbf(float x);
+ int ilogbl(real x) { return ilogb(x); }
+
+ double ldexp(double x, int exp);
+ float ldexpf(float x, int exp);
+ // alias for double: real ldexpl(real x, int exp);
+
+ double log(double x);
+ float logf(float x);
+ //real logl(real x);
+
+ double log10(double x);
+ float log10f(float x);
+ //real log10l(real x);
+
+ double log1p(double x);
+ float log1pf(float x);
+ //real log1pl(real x);
+
+ //double log2(double x);
+ //float log2f(float x);
+ //real log2l(real x);
+
+ double logb(double x);
+ float logbf(float x);
+ real logbl(real x) { return logb(x); }
+
+ double modf(double value, double* iptr);
+ float modff(float value, float* iptr);
+ real modfl(real value, real *iptr) { return modf(value, cast(double*)iptr); }
+
+ double scalbn(double x, int n);
+ float scalbnf(float x, int n);
+ // alias for double: real scalbnl(real x, int n);
+
+ double scalbln(double x, c_long n);
+ float scalblnf(float x, c_long n);
+ // alias for double: real scalblnl(real x, c_long n);
+
+ double cbrt(double x);
+ float cbrtf(float x);
+ real cbrtl(real x) { return cbrt(x); }
+
+ double fabs(double x);
+ float fabsf(float x);
+ // alias for double: real fabsl(real x);
+
+ double hypot(double x, double y);
+ float hypotf(float x, float y);
+ //real hypotl(real x, real y);
+
+ double pow(double x, double y);
+ float powf(float x, float y);
+ //real powl(real x, real y);
+
+ double sqrt(double x);
+ float sqrtf(float x);
+ //real sqrtl(real x);
+
+ double erf(double x);
+ float erff(float x);
+ //real erfl(real x);
+
+ double erfc(double x);
+ float erfcf(float x);
+ //real erfcl(real x);
+
+ double lgamma(double x);
+ float lgammaf(float x);
+ //real lgammal(real x);
+
+ double tgamma(double x);
+ //float tgammaf(float x);
+ //real tgammal(real x);
+
+ double ceil(double x);
+ float ceilf(float x);
+ // alias for double: real ceill(real x);
+
+ double floor(double x);
+ float floorf(float x);
+ // alias for double: real floorl(real x);
+
+ double nearbyint(double x);
+ float nearbyintf(float x);
+ real nearbyintl(real x) { return nearbyint(x); }
+
+ double rint(double x);
+ float rintf(float x);
+ //real rintl(real x);
+
+ c_long lrint(double x);
+ c_long lrintf(float x);
+ //c_long lrintl(real x);
+
+ long llrint(double x);
+ long llrintf(float x);
+ //long llrintl(real x);
+
+ double round(double x);
+ float roundf(float x);
+ real roundl(real x) { return round(x); }
+
+ c_long lround(double x);
+ c_long lroundf(float x);
+ // alias for double: c_long lroundl(real x);
+
+ long llround(double x);
+ long llroundf(float x);
+ long llroundl(real x) { return llround(x); }
+
+ double trunc(double x);
+ float truncf(float x);
+ real truncl(real x) { return trunc(x); }
+
+ double fmod(double x, double y);
+ float fmodf(float x, float y);
+ real fmodl(real x, real y) { return fmod(x,y); }
+
+ double remainder(double x, double y);
+ float remainderf(float x, float y);
+ real remainderl(real x, real y) { return remainder(x,y); }
+
+ double remquo(double x, double y, int* quo);
+ float remquof(float x, float y, int* quo);
+ real remquol(real x, real y, int* quo) { return remquo(x,y,quo); }
+
+ double copysign(double x, double y);
+ float copysignf(float x, float y);
+ // alias for double: real copysignl(real x, real y);
+
+ //double nan(char* tagp);
+ //float nanf(char* tagp);
+ //real nanl(char* tagp);
+
+ double nextafter(double x, double y);
+ float nextafterf(float x, float y);
+ // alias for double: real nextafterl(real x, real y);
+
+ double nexttoward(double x, double y);
+ float nexttowardf(float x, double y);
+ // alias for double: real nexttowardl(real x, real y);
+
+ double fdim(double x, double y);
+ float fdimf(float x, float y);
+ // alias for double: real fdiml(real x, real y);
+
+ double fmax(double x, double y);
+ float fmaxf(float x, float y);
+ // alias for double: real fmaxl(real x, real y);
+
+ double fmin(double x, double y);
+ float fminf(float x, float y);
+ // alias for double: real fminl(real x, real y);
+
+ double fma(double x, double y, double z);
+ float fmaf(float x, float y, float z);
+ // alias for double: real fmal(real x, real y, real z);
+}
else
{
double acos(double x);
diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d
index a5ee624..249bb13 100644
--- a/src/core/stdc/stdlib.d
+++ b/src/core/stdc/stdlib.d
@@ -98,8 +98,17 @@ else
// No unsafe pointer manipulation.
@trusted
{
- int rand();
- void srand(uint seed);
+ version(Android)
+ {
+ import core.sys.posix.stdlib: lrand48, srand48;
+ alias core.sys.posix.stdlib.lrand48 rand;
+ alias core.sys.posix.stdlib.srand48 srand;
+ }
+ else
+ {
+ int rand();
+ void srand(uint seed);
+ }
}
// We don't mark these @trusted. Given that they return a void*, one has
diff --git a/src/core/stdc/string.d b/src/core/stdc/string.d
index 35b905a..060aa41 100644
--- a/src/core/stdc/string.d
+++ b/src/core/stdc/string.d
@@ -22,6 +22,10 @@ nothrow:
pure void* memchr(in void* s, int c, size_t n);
pure int memcmp(in void* s1, in void* s2, size_t n);
pure void* memcpy(void* s1, in void* s2, size_t n);
+version (Windows)
+{
+ int memicmp(in char* s1, in char* s2, size_t n);
+}
pure void* memmove(void* s1, in void* s2, size_t n);
pure void* memset(void* s, int c, size_t n);
@@ -41,5 +45,13 @@ pure size_t strspn(in char* s1, in char* s2);
pure char* strstr(in char* s1, in char* s2);
char* strtok(char* s1, in char* s2);
char* strerror(int errnum);
+version (linux)
+{
+ const(char)* strerror_r(int errnum, char* buf, size_t buflen);
+}
+else version (Posix)
+{
+ int strerror_r(int errnum, char* buf, size_t buflen);
+}
pure size_t strlen(in char* s);
char* strdup(in char *s);
diff --git a/src/core/stdc/tgmath.d b/src/core/stdc/tgmath.d
index 99462a3..e53f56d 100644
--- a/src/core/stdc/tgmath.d
+++ b/src/core/stdc/tgmath.d
@@ -343,7 +343,7 @@ else
{
alias core.stdc.math.acos acos;
alias core.stdc.math.acosf acos;
- alias core.stdc.math.acosl acos;
+ //alias core.stdc.math.acosl acos;
alias core.stdc.complex.cacos acos;
alias core.stdc.complex.cacosf acos;
@@ -351,7 +351,7 @@ else
alias core.stdc.math.asin asin;
alias core.stdc.math.asinf asin;
- alias core.stdc.math.asinl asin;
+ //alias core.stdc.math.asinl asin;
alias core.stdc.complex.casin asin;
alias core.stdc.complex.casinf asin;
@@ -359,7 +359,7 @@ else
alias core.stdc.math.atan atan;
alias core.stdc.math.atanf atan;
- alias core.stdc.math.atanl atan;
+ //alias core.stdc.math.atanl atan;
alias core.stdc.complex.catan atan;
alias core.stdc.complex.catanf atan;
@@ -367,11 +367,11 @@ else
alias core.stdc.math.atan2 atan2;
alias core.stdc.math.atan2f atan2;
- alias core.stdc.math.atan2l atan2;
+ //alias core.stdc.math.atan2l atan2;
alias core.stdc.math.cos cos;
alias core.stdc.math.cosf cos;
- alias core.stdc.math.cosl cos;
+ //alias core.stdc.math.cosl cos;
alias core.stdc.complex.ccos cos;
alias core.stdc.complex.ccosf cos;
@@ -379,7 +379,7 @@ else
alias core.stdc.math.sin sin;
alias core.stdc.math.sinf sin;
- alias core.stdc.math.sinl sin;
+ //alias core.stdc.math.sinl sin;
alias core.stdc.complex.csin csin;
alias core.stdc.complex.csinf csin;
@@ -387,7 +387,7 @@ else
alias core.stdc.math.tan tan;
alias core.stdc.math.tanf tan;
- alias core.stdc.math.tanl tan;
+ //alias core.stdc.math.tanl tan;
alias core.stdc.complex.ctan tan;
alias core.stdc.complex.ctanf tan;
@@ -395,7 +395,7 @@ else
alias core.stdc.math.acosh acosh;
alias core.stdc.math.acoshf acosh;
- alias core.stdc.math.acoshl acosh;
+ //alias core.stdc.math.acoshl acosh;
alias core.stdc.complex.cacosh acosh;
alias core.stdc.complex.cacoshf acosh;
@@ -403,7 +403,7 @@ else
alias core.stdc.math.asinh asinh;
alias core.stdc.math.asinhf asinh;
- alias core.stdc.math.asinhl asinh;
+ //alias core.stdc.math.asinhl asinh;
alias core.stdc.complex.casinh asinh;
alias core.stdc.complex.casinhf asinh;
@@ -411,7 +411,7 @@ else
alias core.stdc.math.atanh atanh;
alias core.stdc.math.atanhf atanh;
- alias core.stdc.math.atanhl atanh;
+ //alias core.stdc.math.atanhl atanh;
alias core.stdc.complex.catanh atanh;
alias core.stdc.complex.catanhf atanh;
@@ -419,7 +419,7 @@ else
alias core.stdc.math.cosh cosh;
alias core.stdc.math.coshf cosh;
- alias core.stdc.math.coshl cosh;
+ //alias core.stdc.math.coshl cosh;
alias core.stdc.complex.ccosh cosh;
alias core.stdc.complex.ccoshf cosh;
@@ -427,7 +427,7 @@ else
alias core.stdc.math.sinh sinh;
alias core.stdc.math.sinhf sinh;
- alias core.stdc.math.sinhl sinh;
+ //alias core.stdc.math.sinhl sinh;
alias core.stdc.complex.csinh sinh;
alias core.stdc.complex.csinhf sinh;
@@ -435,7 +435,7 @@ else
alias core.stdc.math.tanh tanh;
alias core.stdc.math.tanhf tanh;
- alias core.stdc.math.tanhl tanh;
+ //alias core.stdc.math.tanhl tanh;
alias core.stdc.complex.ctanh tanh;
alias core.stdc.complex.ctanhf tanh;
@@ -443,7 +443,7 @@ else
alias core.stdc.math.exp exp;
alias core.stdc.math.expf exp;
- alias core.stdc.math.expl exp;
+ //alias core.stdc.math.expl exp;
alias core.stdc.complex.cexp exp;
alias core.stdc.complex.cexpf exp;
@@ -455,11 +455,11 @@ else
alias core.stdc.math.expm1 expm1;
alias core.stdc.math.expm1f expm1;
- alias core.stdc.math.expm1l expm1;
+ //alias core.stdc.math.expm1l expm1;
alias core.stdc.math.frexp frexp;
alias core.stdc.math.frexpf frexp;
- alias core.stdc.math.frexpl frexp;
+ //alias core.stdc.math.frexpl frexp;
alias core.stdc.math.ilogb ilogb;
alias core.stdc.math.ilogbf ilogb;
@@ -467,11 +467,11 @@ else
alias core.stdc.math.ldexp ldexp;
alias core.stdc.math.ldexpf ldexp;
- alias core.stdc.math.ldexpl ldexp;
+ //alias core.stdc.math.ldexpl ldexp;
alias core.stdc.math.log log;
alias core.stdc.math.logf log;
- alias core.stdc.math.logl log;
+ //alias core.stdc.math.logl log;
alias core.stdc.complex.clog log;
alias core.stdc.complex.clogf log;
@@ -479,15 +479,15 @@ else
alias core.stdc.math.log10 log10;
alias core.stdc.math.log10f log10;
- alias core.stdc.math.log10l log10;
+ //alias core.stdc.math.log10l log10;
alias core.stdc.math.log1p log1p;
alias core.stdc.math.log1pf log1p;
- alias core.stdc.math.log1pl log1p;
+ //alias core.stdc.math.log1pl log1p;
- alias core.stdc.math.log2 log2;
- alias core.stdc.math.log2f log2;
- alias core.stdc.math.log2l log2;
+ //alias core.stdc.math.log2 log2;
+ //alias core.stdc.math.log2f log2;
+ //alias core.stdc.math.log2l log2;
alias core.stdc.math.logb logb;
alias core.stdc.math.logbf logb;
@@ -499,11 +499,11 @@ else
alias core.stdc.math.scalbn scalbn;
alias core.stdc.math.scalbnf scalbn;
- alias core.stdc.math.scalbnl scalbn;
+ //alias core.stdc.math.scalbnl scalbn;
alias core.stdc.math.scalbln scalbln;
alias core.stdc.math.scalblnf scalbln;
- alias core.stdc.math.scalblnl scalbln;
+ //alias core.stdc.math.scalblnl scalbln;
alias core.stdc.math.cbrt cbrt;
alias core.stdc.math.cbrtf cbrt;
@@ -511,7 +511,7 @@ else
alias core.stdc.math.fabs fabs;
alias core.stdc.math.fabsf fabs;
- alias core.stdc.math.fabsl fabs;
+ //alias core.stdc.math.fabsl fabs;
alias core.stdc.complex.cabs fabs;
alias core.stdc.complex.cabsf fabs;
@@ -519,11 +519,11 @@ else
alias core.stdc.math.hypot hypot;
alias core.stdc.math.hypotf hypot;
- alias core.stdc.math.hypotl hypot;
+ //alias core.stdc.math.hypotl hypot;
alias core.stdc.math.pow pow;
alias core.stdc.math.powf pow;
- alias core.stdc.math.powl pow;
+ //alias core.stdc.math.powl pow;
alias core.stdc.complex.cpow pow;
alias core.stdc.complex.cpowf pow;
@@ -531,7 +531,7 @@ else
alias core.stdc.math.sqrt sqrt;
alias core.stdc.math.sqrtf sqrt;
- alias core.stdc.math.sqrtl sqrt;
+ //alias core.stdc.math.sqrtl sqrt;
alias core.stdc.complex.csqrt sqrt;
alias core.stdc.complex.csqrtf sqrt;
@@ -539,27 +539,27 @@ else
alias core.stdc.math.erf erf;
alias core.stdc.math.erff erf;
- alias core.stdc.math.erfl erf;
+ //alias core.stdc.math.erfl erf;
alias core.stdc.math.erfc erfc;
alias core.stdc.math.erfcf erfc;
- alias core.stdc.math.erfcl erfc;
+ //alias core.stdc.math.erfcl erfc;
alias core.stdc.math.lgamma lgamma;
alias core.stdc.math.lgammaf lgamma;
- alias core.stdc.math.lgammal lgamma;
+ //alias core.stdc.math.lgammal lgamma;
alias core.stdc.math.tgamma tgamma;
- alias core.stdc.math.tgammaf tgamma;
- alias core.stdc.math.tgammal tgamma;
+ //alias core.stdc.math.tgammaf tgamma;
+ //alias core.stdc.math.tgammal tgamma;
alias core.stdc.math.ceil ceil;
alias core.stdc.math.ceilf ceil;
- alias core.stdc.math.ceill ceil;
+ //alias core.stdc.math.ceill ceil;
alias core.stdc.math.floor floor;
alias core.stdc.math.floorf floor;
- alias core.stdc.math.floorl floor;
+ //alias core.stdc.math.floorl floor;
alias core.stdc.math.nearbyint nearbyint;
alias core.stdc.math.nearbyintf nearbyint;
@@ -567,15 +567,15 @@ else
alias core.stdc.math.rint rint;
alias core.stdc.math.rintf rint;
- alias core.stdc.math.rintl rint;
+ //alias core.stdc.math.rintl rint;
alias core.stdc.math.lrint lrint;
alias core.stdc.math.lrintf lrint;
- alias core.stdc.math.lrintl lrint;
+ //alias core.stdc.math.lrintl lrint;
alias core.stdc.math.llrint llrint;
alias core.stdc.math.llrintf llrint;
- alias core.stdc.math.llrintl llrint;
+ //alias core.stdc.math.llrintl llrint;
alias core.stdc.math.round round;
alias core.stdc.math.roundf round;
@@ -583,7 +583,7 @@ else
alias core.stdc.math.lround lround;
alias core.stdc.math.lroundf lround;
- alias core.stdc.math.lroundl lround;
+ //alias core.stdc.math.lroundl lround;
alias core.stdc.math.llround llround;
alias core.stdc.math.llroundf llround;
@@ -607,35 +607,35 @@ else
alias core.stdc.math.copysign copysign;
alias core.stdc.math.copysignf copysign;
- alias core.stdc.math.copysignl copysign;
+ //alias core.stdc.math.copysignl copysign;
- alias core.stdc.math.nan nan;
- alias core.stdc.math.nanf nan;
- alias core.stdc.math.nanl nan;
+ //alias core.stdc.math.nan nan;
+ //alias core.stdc.math.nanf nan;
+ //alias core.stdc.math.nanl nan;
alias core.stdc.math.nextafter nextafter;
alias core.stdc.math.nextafterf nextafter;
- alias core.stdc.math.nextafterl nextafter;
+ //alias core.stdc.math.nextafterl nextafter;
alias core.stdc.math.nexttoward nexttoward;
alias core.stdc.math.nexttowardf nexttoward;
- alias core.stdc.math.nexttowardl nexttoward;
+ //alias core.stdc.math.nexttowardl nexttoward;
alias core.stdc.math.fdim fdim;
alias core.stdc.math.fdimf fdim;
- alias core.stdc.math.fdiml fdim;
+ //alias core.stdc.math.fdiml fdim;
alias core.stdc.math.fmax fmax;
alias core.stdc.math.fmaxf fmax;
- alias core.stdc.math.fmaxl fmax;
+ //alias core.stdc.math.fmaxl fmax;
alias core.stdc.math.fmin fmin;
alias core.stdc.math.fmin fmin;
- alias core.stdc.math.fminl fmin;
+ //alias core.stdc.math.fminl fmin;
alias core.stdc.math.fma fma;
alias core.stdc.math.fmaf fma;
- alias core.stdc.math.fmal fma;
+ //alias core.stdc.math.fmal fma;
alias core.stdc.complex.carg carg;
alias core.stdc.complex.cargf carg;
diff --git a/src/core/sys/posix/sys/socket.d b/src/core/sys/posix/sys/socket.d
index c18a835..a3ddaa7 100644
--- a/src/core/sys/posix/sys/socket.d
+++ b/src/core/sys/posix/sys/socket.d
@@ -1111,6 +1111,15 @@ else version( Android )
SHUT_RDWR
}
+ // constants needed for std.socket
+ enum AF_IPX = 4;
+ enum AF_APPLETALK = 5;
+ enum SOCK_RDM = 4;
+ enum IPPROTO_IGMP = 2;
+ enum IPPROTO_PUP = 12;
+ enum IPPROTO_IDP = 22;
+ enum INADDR_NONE = 0xFFFFFFFF;
+
int accept(int, sockaddr*, socklen_t*);
int bind(int, in sockaddr*, int);
int connect(int, in sockaddr*, socklen_t);
diff --git a/src/core/sys/posix/sys/stat.d b/src/core/sys/posix/sys/stat.d
index 580fd05..1431c84 100644
--- a/src/core/sys/posix/sys/stat.d
+++ b/src/core/sys/posix/sys/stat.d
@@ -925,19 +925,19 @@ else version( Android )
private
{
- extern (D) bool S_ISTYPE( mode_t mode, uint mask )
+ extern (D) bool S_ISTYPE( uint mode, uint mask )
{
return ( mode & S_IFMT ) == mask;
}
}
- extern (D) bool S_ISBLK( mode_t mode ) { return S_ISTYPE( mode, S_IFBLK ); }
- extern (D) bool S_ISCHR( mode_t mode ) { return S_ISTYPE( mode, S_IFCHR ); }
- extern (D) bool S_ISDIR( mode_t mode ) { return S_ISTYPE( mode, S_IFDIR ); }
- extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO ); }
- extern (D) bool S_ISREG( mode_t mode ) { return S_ISTYPE( mode, S_IFREG ); }
- extern (D) bool S_ISLNK( mode_t mode ) { return S_ISTYPE( mode, S_IFLNK ); }
- extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
+ extern (D) bool S_ISBLK( uint mode ) { return S_ISTYPE( mode, S_IFBLK ); }
+ extern (D) bool S_ISCHR( uint mode ) { return S_ISTYPE( mode, S_IFCHR ); }
+ extern (D) bool S_ISDIR( uint mode ) { return S_ISTYPE( mode, S_IFDIR ); }
+ extern (D) bool S_ISFIFO( uint mode ) { return S_ISTYPE( mode, S_IFIFO ); }
+ 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 ); }
}
else
{
diff --git a/src/ldc/eh.d b/src/ldc/eh.d
index 55ff0c8..de3b968 100644
--- a/src/ldc/eh.d
+++ b/src/ldc/eh.d
@@ -23,6 +23,7 @@ version(X86)
version(Solaris) version=GCC_UNWIND;
version(FreeBSD) version=GCC_UNWIND;
version(MinGW) version=GCC_UNWIND;
+ version(Android) version=GCC_UNWIND;
}
version(X86_64)
{
diff --git a/src/rt/sections_android.d b/src/rt/sections_android.d
index 44b1588..c359c38 100644
--- a/src/rt/sections_android.d
+++ b/src/rt/sections_android.d
@@ -10,6 +10,7 @@
module rt.sections_android;
+version (LDC) {} else
version (Android):
// debug = PRINTF;
@@ -82,9 +83,11 @@ void[]* initTLSRanges()
void finiTLSRanges(void[]* rng)
{
+ .free(rng.ptr);
+ .free(rng);
}
-void scanTLSRanges(void[]* rng, scope void delegate(void* pbeg, void* pend) dg)
+void scanTLSRanges(void[]* rng, scope void delegate(void* pbeg, void* pend) nothrow dg) nothrow
{
dg(rng.ptr, rng.ptr + rng.length);
}
diff --git a/src/rt/sections_ldc.d b/src/rt/sections_ldc.d
index ac5ecc8..7a94c72 100644
--- a/src/rt/sections_ldc.d
+++ b/src/rt/sections_ldc.d
@@ -18,7 +18,7 @@ module rt.sections_ldc;
version (linux) {} else version(LDC):
-import core.stdc.stdlib : alloca;
+import core.stdc.stdlib : alloca, malloc;
import rt.minfo;
debug(PRINTF) import core.stdc.stdio : printf;
@@ -36,6 +36,63 @@ version (Solaris)
import core.sys.solaris.link;
import core.sys.solaris.sys.elf;
}
+version (Android)
+{
+ version = UseELF;
+
+ import core.sys.posix.pthread;
+ import core.stdc.stdlib : calloc;
+ import core.stdc.stdio: printf;
+ import core.stdc.string: memcpy;
+ template ElfW(string type)
+ {
+ mixin("alias Elf32_"~type~" ElfW;");
+ }
+ version(X86)
+ {
+ import core.stdc.stdint: uint16_t, uint32_t;
+ alias uint16_t Elf32_Half;
+ alias uint32_t Elf32_Addr;
+ alias uint32_t Elf32_Off;
+ alias uint32_t Elf32_Word;
+ }
+ version(ARM)
+ {
+ import core.stdc.stdint: uint16_t, uint32_t;
+ alias uint16_t Elf32_Half;
+ alias uint32_t Elf32_Addr;
+ alias uint32_t Elf32_Off;
+ alias uint32_t Elf32_Word;
+ }
+
+ enum PT_LOAD = 1;
+ enum PF_R = (1 << 2);
+ enum PF_W = (1 << 1);
+ enum PT_TLS = 7;
+
+ struct Elf32_Phdr
+ {
+ ElfW!"Word" p_type;
+ ElfW!"Off" p_offset;
+ ElfW!"Addr" p_vaddr;
+ ElfW!"Addr" p_paddr;
+ ElfW!"Word" p_filesz;
+ ElfW!"Word" p_memsz;
+ ElfW!"Word" p_flags;
+ ElfW!"Word" p_align;
+ }
+
+ struct dl_phdr_info
+ {
+ ElfW!"Addr" dlpi_addr;
+ const(char)* dlpi_name;
+ const(ElfW!"Phdr")* dlpi_phdr;
+ ElfW!"Half" dlpi_phnum;
+ }
+
+ private alias extern(C) int function(dl_phdr_info*, size_t, void *) __Callback;
+ extern(C) nothrow int dl_iterate_phdr(__Callback, void*);
+}
alias SectionGroup DSO;
struct SectionGroup
@@ -70,6 +127,7 @@ private:
import rt.util.container.array;
Array!(void[]) _gcRanges;
+ immutable(void)[] _tlsImage;
version(Solaris)
{
@@ -127,6 +185,7 @@ private
* Scan segments in Linux dl_phdr_info struct and store
* the TLS and writeable data segments in *pdso.
*/
+ __gshared int count;
void scanSegments(in ref dl_phdr_info info, DSO* pdso)
{
foreach (ref phdr; info.dlpi_phdr[0 .. info.dlpi_phnum])
@@ -136,8 +195,21 @@ private
case PT_LOAD:
if (phdr.p_flags & PF_W) // writeable data segment
{
+ if(count < 1){
+ printf("DRUNTIME: calling PT_LOAD with size %d and address %p\n", phdr.p_memsz, info.dlpi_addr + phdr.p_vaddr);
+ pdso._tlsImage = (cast(immutable(void)*)info.dlpi_addr + phdr.p_vaddr)[0 .. phdr.p_memsz];
+ printf("DRUNTIME: address of pdso._tlsImage is %p\n", pdso._tlsImage.ptr);
+ auto inttls = cast(byte[])pdso._tlsImage;
+ printf("DRUNTIME: PT_TLS range is [ ");
+ foreach(i; inttls) printf("%d ", i);
+ printf("]\n");
+ count++;
+ }
+ else {
+ printf("DRUNTIME: got to other load\n");
auto beg = cast(void*)(info.dlpi_addr + phdr.p_vaddr);
pdso._gcRanges.insertBack(beg[0 .. phdr.p_memsz]);
+ }
}
break;
@@ -147,6 +219,9 @@ private
{
pdso._tlsSize = phdr.p_memsz;
}
+ else version(Android)
+ {
+ }
else
{
pdso._tlsMod = info.dlpi_tls_modid;
@@ -308,6 +383,42 @@ private
return (thptr - sz)[0 .. sz];
}
}
+ else version(Android)
+ {
+ void[] getTLSRange(DSO* pdso)
+ {
+ return getTLSBlock();
+ }
+
+ ref void[] getTLSBlock()
+ {
+ auto pary = cast(void[]*)pthread_getspecific(_tlsKey);
+ if (pary is null)
+ {
+ pary = cast(void[]*).calloc(1, (void[]).sizeof);
+ if (pthread_setspecific(_tlsKey, pary) != 0)
+ {
+ import core.stdc.stdio;
+ perror("pthread_setspecific failed with");
+ assert(0);
+ }
+ }
+ return *pary;
+ }
+
+ ref void[] getTLSBlockAlloc()
+ {
+ auto pary = &getTLSBlock();
+ if (!pary.length)
+ {
+ size_t tlsSize = globalSectionGroup._tlsImage.length;
+ auto p = .malloc(tlsSize);
+ memcpy(p, globalSectionGroup._tlsImage.ptr, tlsSize);
+ *pary = p[0 .. tlsSize];
+ }
+ return *pary;
+ }
+ }
else
{
struct tls_index
@@ -348,6 +459,7 @@ private
void initSections()
{
debug(PRINTF) printf("initSections called\n");
+ pthread_key_create(&_tlsKey, null);
globalSectionGroup.moduleGroup = ModuleGroup(getModuleInfos());
static void pushRange(void* start, void* end)
@@ -407,6 +519,7 @@ void finiSections()
debug(PRINTF) printf("finiSections called\n");
import core.stdc.stdlib : free;
free(cast(void*)globalSectionGroup.modules.ptr);
+ pthread_key_delete(_tlsKey);
}
private
@@ -416,6 +529,10 @@ private
extern(C) void _d_dyld_getTLSRange(void*, void**, size_t*);
private ubyte dummyTlsSymbol;
}
+ else version (Android)
+ {
+ __gshared pthread_key_t _tlsKey;
+ }
else version (Windows)
{
extern(C) extern
@@ -473,6 +590,17 @@ void scanTLSRanges(void[] rng, scope void delegate(void* pbeg, void* pend) nothr
if (rng) dg(rng.ptr, rng.ptr + rng.length);
}
+version(Android)
+ extern(D) void* ___tls_get_addr( void** p )
+ {
+ //printf("DRUNTIME: calling tlsget_addr with address %p referencing %p on tlsimage at %p\n", p, *p, globalSectionGroup._tlsImage.ptr);
+ immutable offset = cast(size_t)(*p - globalSectionGroup._tlsImage.ptr);
+ auto tls = getTLSBlockAlloc();
+ //printf("DRUNTIME: calling tlsget_addr with tls.ptr %p and offset %d\n", tls.ptr, offset);
+ assert(offset < tls.length);
+ return tls.ptr + offset;
+ }
+
extern (C) __gshared ModuleReference* _Dmodule_ref; // start of linked list
private:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment