From 3d8d4a45c01832fb657c16a656b6e1566d77fb21 Mon Sep 17 00:00:00 2001 From: Nikolay Tolstokulakov Date: Thu, 4 Feb 2016 13:40:21 +0600 Subject: [PATCH] netbsd patch --- osmodel.mak | 3 + src/core/runtime.d | 16 + src/core/stdc/config.d | 2 + src/core/stdc/errno.d | 132 ++++++++ src/core/stdc/fenv.d | 46 +++ src/core/stdc/locale.d | 17 + src/core/stdc/math.d | 545 +++++++++++++++++++++++++++++++- src/core/stdc/stdio.d | 123 ++++++++ src/core/stdc/stdlib.d | 1 + src/core/stdc/string.d | 4 + src/core/stdc/tgmath.d | 549 +++++++++++++++++++++++++++++++++ src/core/stdc/time.d | 11 + src/core/thread.d | 27 ++ src/core/threadasm.S | 2 +- src/core/time.d | 18 ++ src/gc/os.d | 1 + src/rt/bss_section.c | 2 +- src/rt/dmain2.d | 4 + src/rt/sections.d | 2 + src/rt/sections_elf_shared.d | 33 ++ test/exceptions/line_trace.exp | 10 +- test/shared/src/load.d | 1 + 22 files changed, 1541 insertions(+), 8 deletions(-) diff --git a/osmodel.mak b/osmodel.mak index f56716a363..48e01f17d6 100644 --- a/osmodel.mak +++ b/osmodel.mak @@ -15,6 +15,9 @@ ifeq (,$(OS)) ifeq (OpenBSD,$(uname_S)) OS:=openbsd endif + ifeq (NetBSD,$(uname_S)) + OS:=netbsd + endif ifeq (Solaris,$(uname_S)) OS:=solaris endif diff --git a/src/core/runtime.d b/src/core/runtime.d index 184fed7b9a..4655391c5f 100644 --- a/src/core/runtime.d +++ b/src/core/runtime.d @@ -456,6 +456,8 @@ extern (C) bool runModuleUnitTests() import core.sys.darwin.execinfo; else version( FreeBSD ) import core.sys.freebsd.execinfo; + else version( NetBSD ) + import core.sys.netbsd.execinfo; else version( Windows ) import core.sys.windows.stacktrace; else version( Solaris ) @@ -538,6 +540,8 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) import core.sys.darwin.execinfo; else version( FreeBSD ) import core.sys.freebsd.execinfo; + else version( NetBSD ) + import core.sys.netbsd.execinfo; else version( Windows ) import core.sys.windows.stacktrace; else version( Solaris ) @@ -735,6 +739,18 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) symEnd = eptr - buf.ptr; } } + else version( NetBSD ) + { + // format is: 0x00000000 <_D6module4funcAFZv+0x78> at module + auto bptr = cast(char*) memchr( buf.ptr, '<', buf.length ); + auto eptr = cast(char*) memchr( buf.ptr, '+', buf.length ); + + if( bptr++ && eptr ) + { + symBeg = bptr - buf.ptr; + symEnd = eptr - buf.ptr; + } + } else version( Solaris ) { // format is object'symbol+offset [pc] diff --git a/src/core/stdc/config.d b/src/core/stdc/config.d index f5f4504d3f..f8931404c6 100644 --- a/src/core/stdc/config.d +++ b/src/core/stdc/config.d @@ -127,6 +127,8 @@ else version( DigitalMars ) alias real c_long_double; else version( OpenBSD ) alias real c_long_double; + else version( NetBSD ) + alias real c_long_double; else version( Solaris ) alias real c_long_double; else version( Darwin ) diff --git a/src/core/stdc/errno.d b/src/core/stdc/errno.d index 40f503e3ba..8d309b3a85 100644 --- a/src/core/stdc/errno.d +++ b/src/core/stdc/errno.d @@ -1110,6 +1110,138 @@ else version( FreeBSD ) enum EPROTO = 92; /// Protocol error enum ELAST = 92; /// Must be equal largest errno } +else version (NetBSD) +{ + // http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/sys/errno.h + enum EPERM = 1; + enum ENOENT = 2; + enum ESRCH = 3; + enum EINTR = 4; + enum EIO = 5; + enum ENXIO = 6; + enum E2BIG = 7; + enum ENOEXEC = 8; + enum EBADF = 9; + enum ECHILD = 10; + enum EDEADLK = 11; + /// + enum ENOMEM = 12; + enum EACCES = 13; + enum EFAULT = 14; + enum ENOTBLK = 15; + enum EBUSY = 16; + enum EEXIST = 17; + enum EXDEV = 18; + enum ENODEV = 19; + enum ENOTDIR = 20; + enum EISDIR = 21; + enum EINVAL = 22; + enum ENFILE = 23; + enum EMFILE = 24; + enum ENOTTY = 25; + enum ETXTBSY = 26; + enum EFBIG = 27; + enum ENOSPC = 28; + enum ESPIPE = 29; + enum EROFS = 30; + enum EMLINK = 31; + enum EPIPE = 32; + /// + enum EDOM = 33; + enum ERANGE = 34; + + /// + enum EAGAIN = 35; + enum EWOULDBLOCK = EAGAIN; + enum EINPROGRESS = 36; + enum EALREADY = 37; + + /// + enum ENOTSOCK = 38; + enum EDESTADDRREQ = 39; + enum EMSGSIZE = 40; + enum EPROTOTYPE = 41; + enum ENOPROTOOPT = 42; + enum EPROTONOSUPPORT = 43; + enum ESOCKTNOSUPPORT = 44; + enum EOPNOTSUPP = 45; + enum EPFNOSUPPORT = 46; + enum EAFNOSUPPORT = 47; + enum EADDRINUSE = 48; + enum EADDRNOTAVAIL = 49; + + /// + enum ENETDOWN = 50; + enum ENETUNREACH = 51; + enum ENETRESET = 52; + enum ECONNABORTED = 53; + enum ECONNRESET = 54; + enum ENOBUFS = 55; + enum EISCONN = 56; + enum ENOTCONN = 57; + enum ESHUTDOWN = 58; + enum ETOOMANYREFS = 59; + enum ETIMEDOUT = 60; + enum ECONNREFUSED = 61; + enum ELOOP = 62; + enum ENAMETOOLONG = 63; + + /// + enum EHOSTDOWN = 64; + enum EHOSTUNREACH = 65; + enum ENOTEMPTY = 66; + + /// + enum EPROCLIM = 67; + enum EUSERS = 68; + enum EDQUOT = 69; + + /// + enum ESTALE = 70; + enum EREMOTE = 71; + enum EBADRPC = 72; + enum ERPCMISMATCH = 73; + enum EPROGUNAVAIL = 74; + enum EPROGMISMATCH = 75; + enum EPROCUNAVAIL = 76; + + enum ENOLCK = 77; + enum ENOSYS = 78; + + enum EFTYPE = 79; + enum EAUTH = 80; + enum ENEEDAUTH = 81; + + /// + enum EIDRM = 82; + enum ENOMSG = 83; + enum EOVERFLOW = 84; + /// + enum EILSEQ = 85; + + /// + enum ENOTSUP = 86; + + /// + enum ECANCELED = 87; + + /// + enum EBADMSG = 88; + + /// + enum ENODATA = 89; + enum ENOSR = 90; + enum ENOSTR = 91; + enum ETIME = 92; + + /// + enum ENOATTR = 93; + + /// + enum EMULTIHOP = 94; + enum ENOLINK = 95; + enum EPROTO = 96; +} else version( OpenBSD ) { enum EPERM = 1; /// Operation not permitted diff --git a/src/core/stdc/fenv.d b/src/core/stdc/fenv.d index 08a98bd6d8..0739075210 100644 --- a/src/core/stdc/fenv.d +++ b/src/core/stdc/fenv.d @@ -196,6 +196,46 @@ else version ( FreeBSD ) alias ushort fexcept_t; } +else version ( NetBSD ) +{ + version(X86_64) + { + struct fenv_t + { + struct _x87 + { + uint control; /* Control word register */ + uint status; /* Status word register */ + uint tag; /* Tag word register */ + uint[4] others; /* EIP, Pointer Selector, etc */ + }; + _x87 x87; + + uint mxcsr; /* Control and status register */ + } + } + version(X86) + { + struct fenv_t + { + struct _x87 + { + ushort control; /* Control word register */ + ushort unused1; + ushort status; /* Status word register */ + ushort unused2; + ushort tag; /* Tag word register */ + ushort unused3; + uint[4] others; /* EIP, Pointer Selector, etc */ + }; + _x87 x87; + uint32_t mxcsr; /* Control and status register */ + }; + + } + + alias uint fexcept_t; +} else version ( OpenBSD ) { struct fenv_t @@ -326,6 +366,12 @@ else version( FreeBSD ) /// enum FE_DFL_ENV = &__fe_dfl_env; } +else version( NetBSD ) +{ + private extern const fenv_t __fe_dfl_env; + /// + enum FE_DFL_ENV = &__fe_dfl_env; +} else version( OpenBSD ) { private extern const fenv_t __fe_dfl_env; diff --git a/src/core/stdc/locale.d b/src/core/stdc/locale.d index 8e602943f0..aa7c61ed98 100644 --- a/src/core/stdc/locale.d +++ b/src/core/stdc/locale.d @@ -135,6 +135,23 @@ else version(FreeBSD) /// enum LC_MESSAGES = 6; } +else version(NetBSD) +{ + /// + enum LC_ALL = 0; + /// + enum LC_COLLATE = 1; + /// + enum LC_CTYPE = 2; + /// + enum LC_MONETARY = 3; + /// + enum LC_NUMERIC = 4; + /// + enum LC_TIME = 5; + /// + enum LC_MESSAGES = 6; +} else version(OpenBSD) { /// diff --git a/src/core/stdc/math.d b/src/core/stdc/math.d index d8c1441b5d..e58afce314 100644 --- a/src/core/stdc/math.d +++ b/src/core/stdc/math.d @@ -53,6 +53,13 @@ version (FreeBSD) /// enum int FP_ILOGBNAN = int.max; } +else version (NetBSD) +{ + /// + enum int FP_ILOGB0 = -int.max; + /// + enum int FP_ILOGBNAN = int.max; +} else version (OpenBSD) { /// @@ -972,6 +979,97 @@ else version( OpenBSD ) int signbit(real x) { return __signbit(x); } } } +else version( NetBSD ) +{ + enum + { + /// + FP_INFINITE = 0, + /// + FP_NAN = 1, + /// + FP_NORMAL = 2, + /// + FP_SUBNORMAL = 3, + /// + FP_ZERO = 4, + } + + enum + { + /// + FP_FAST_FMA = 0, + /// + FP_FAST_FMAF = 0, + /// + FP_FAST_FMAL = 0, + } + + uint __fpclassifyf(float x); + uint __fpclassifyd(double x); + uint __fpclassifyl(real x); + + extern (D) + { + //int fpclassify(real-floating x); + /// + int fpclassify(float x) { return __fpclassifyf(x); } + /// + int fpclassify(double x) { return __fpclassifyd(x); } + /// + int fpclassify(real x) + { + return (real.sizeof == double.sizeof) + ? __fpclassifyd(x) + : __fpclassifyl(x); + } + + //int isfinite(real-floating x); + /// + int isfinite(float x) { return fpclassify(x) >= FP_NORMAL; } + /// + int isfinite(double x) { return fpclassify(x) >= FP_NORMAL; } + /// + int isfinite(real x) { return fpclassify(x) >= FP_NORMAL; } + + //int isinf(real-floating x); + /// + int isinf(float x) { return fpclassify(x) == FP_INFINITE; } + /// + int isinf(double x) { return fpclassify(x) == FP_INFINITE; } + /// + int isinf(real x) { return fpclassify(x) == FP_INFINITE; } + + //int isnan(real-floating x); + /// + int isnan(float x) { return fpclassify(x) == FP_NAN; } + /// + int isnan(double x) { return fpclassify(x) == FP_NAN; } + /// + int isnan(real x) { return fpclassify(x) == FP_NAN; } + + //int isnormal(real-floating x); + /// + int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } + /// + int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } + /// + int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } + + //int signbit(real-floating x); + /// + int signbit(float x) { return (cast(short*)&(x))[1] & 0x8000; } + /// + int signbit(double x) { return (cast(short*)&(x))[3] & 0x8000; } + /// + int signbit(real x) + { + return (real.sizeof == double.sizeof) + ? (cast(short*)&(x))[3] & 0x8000 + : (cast(short*)&(x))[4] & 0x8000; + } + } +} else version( Solaris ) { int __isnanf(float x); @@ -1609,7 +1707,7 @@ else version( FreeBSD ) } else { - /// + /// real acosl(real x); /// real asinl(real x); @@ -2009,6 +2107,451 @@ else version( FreeBSD ) /// float fmaf(float x, float y, float z); } +else version(NetBSD) +{ + + /// + real acosl(real x); + /// + real asinl(real x); + /// + real atanl(real x); + /// + real atan2l(real y, real x); + /// + real cosl(real x); + /// + real sinl(real x); + /// + real tanl(real x); + /// + real exp2l(real x); + /// + real frexpl(real value, int* exp); + /// + int ilogbl(real x); + /// + real ldexpl(real x, int exp); + /// + real logbl(real x); + /// + real modfl(real value, real *iptr); + /// + real scalbnl(real x, int n); + /// + real scalblnl(real x, c_long n); + /// + real fabsl(real x); + /// + real hypotl(real x, real y); + /// + real sqrtl(real x); + /// + real ceill(real x); + /// + real floorl(real x); + /// + real nearbyintl(real x); + /// + real rintl(real x); + /// + c_long lrintl(real x) { return cast(c_long)rintl(x); } + /// + real roundl(real x); + /// + c_long lroundl(real x) { return cast(c_long)roundl(x);} + /// + long llroundl(real x) { return cast(long)roundl(x);} + /// + real truncl(real x); + /// + real fmodl(real x, real y); + /// + real remainderl(real x, real y) { return remainder(x,y); } + /// + real remquol(real x, real y, int* quo){ return remquo(x,y,quo); } + /// + real copysignl(real x, real y); + /// + double nan(char* tagp); + /// + float nanf(char* tagp); + /// + real nanl(char* tagp); + /// + real nextafterl(real x, real y); + /// + real nexttowardl(real x, real y) { return nexttoward(cast(double) x, cast(double) y); } + /// + real fdiml(real x, real y); + /// + real fmaxl(real x, real y); + /// + real fminl(real x, real y); + /// + real fmal(real x, real y, real z); + + /// + double acos(double x); + /// + float acosf(float x); + + /// + double asin(double x); + /// + float asinf(float x); + + /// + double atan(double x); + /// + float atanf(float x); + + /// + double atan2(double y, double x); + /// + float atan2f(float y, float x); + + /// + double cos(double x); + /// + float cosf(float x); + + /// + double sin(double x); + /// + float sinf(float x); + + /// + double tan(double x); + /// + float tanf(float 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); + + /// + double expm1(double x); + /// + float expm1f(float x); + /// + real expm1l(real x) { return expm1(cast(double) x); } + + /// + double frexp(double value, int* exp); + /// + float frexpf(float value, int* exp); + + /// + int ilogb(double x); + /// + int ilogbf(float x); + + /// + double ldexp(double x, int exp); + /// + float ldexpf(float x, int exp); + + /// + double log(double x); + /// + float logf(float x); + /// NetBSD has no logl. It is just alias log(double) + real logl(real x) + { + if(x<0) return real.nan; + if(x==0) return -real.infinity; + if(isnan(x) || isinf(x)) return x; + real rs = 0; + if(x>double.max) + { + immutable MAX = log(double.max); + for(; x>double.max; x /= double.max) + rs += MAX; + } + else if(xdouble.max) + { + immutable MAX = log10(double.max); + for(; x>double.max; x /= double.max) + rs += MAX; + } + else if(x + { + char[128] _mbstate8; + long _mbstateL; + } +} else version ( OpenBSD ) { enum @@ -435,6 +469,50 @@ else version( FreeBSD ) /// alias shared(__sFILE) FILE; } +else version( NetBSD ) +{ + /// + alias off_t fpos_t; + + /// + struct __sFILE + { + ubyte* _p; + int _r; + int _w; + ushort _flags; + short _file; + __sbuf _bf; + int _lbfsize; + + void* _cookie; + int function(void*) _close; + ssize_t function(void*, char*, size_t) _read; + fpos_t function(void*, fpos_t, int) _seek; + ssize_t function(void*, in char*, size_t) _write; + + __sbuf _ub; + ubyte* _up; + int _ur; + + ubyte[3] _ubuf; + ubyte[1] _nbuf; + + int function(void *) _flush; + /* Formerly used by fgetln/fgetwln; kept for binary compatibility */ + char[__sbuf.sizeof - _flush.sizeof] _lb_unused; + + + int _blksize; + off_t _offset; + static assert(off_t.sizeof==8); + } + + /// + alias __sFILE _iobuf; + /// + alias shared(__sFILE) FILE; +} else version( OpenBSD ) { /// @@ -741,6 +819,29 @@ else version( FreeBSD ) /// alias __stderrp stderr; } +else version( NetBSD ) +{ + enum + { + /// + _IOFBF = 0, + /// + _IOLBF = 1, + /// + _IONBF = 2, + } + + private extern __gshared FILE[3] __sF; + @property auto __stdin() { return &__sF[0]; } + @property auto __stdout() { return &__sF[1]; } + @property auto __stderr() { return &__sF[2]; } + /// + alias __stdin stdin; + /// + alias __stdout stdout; + /// + alias __stderr stderr; +} else version( OpenBSD ) { enum @@ -1158,6 +1259,28 @@ else version( FreeBSD ) /// int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); } +else version( NetBSD ) +{ + // No unsafe pointer manipulation. + @trusted + { + /// + void rewind(FILE*); + /// + pure void clearerr(FILE*); + /// + pure int feof(FILE*); + /// + pure int ferror(FILE*); + /// + int fileno(FILE*); + } + + /// + int snprintf(char* s, size_t n, in char* format, ...); + /// + int vsnprintf(char* s, size_t n, in char* format, va_list arg); +} else version( OpenBSD ) { // No unsafe pointer manipulation. diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d index 01b3722c9b..f3b8a7b7fb 100644 --- a/src/core/stdc/stdlib.d +++ b/src/core/stdc/stdlib.d @@ -75,6 +75,7 @@ version(Windows) enum RAND_MAX = 0x7fff; else version(CRuntime_Glibc) enum RAND_MAX = 0x7fffffff; else version(Darwin) enum RAND_MAX = 0x7fffffff; else version(FreeBSD) enum RAND_MAX = 0x7fffffff; +else version(NetBSD) enum RAND_MAX = 0x7fffffff; else version(OpenBSD) enum RAND_MAX = 0x7fffffff; else version(Solaris) enum RAND_MAX = 0x7fff; else version(CRuntime_Bionic) enum RAND_MAX = 0x7fffffff; diff --git a/src/core/stdc/string.d b/src/core/stdc/string.d index 103076de54..8135cfe9b5 100644 --- a/src/core/stdc/string.d +++ b/src/core/stdc/string.d @@ -89,6 +89,10 @@ else version (FreeBSD) { int strerror_r(int errnum, scope char* buf, size_t buflen); } +else version (NetBSD) +{ + int strerror_r(int errnum, char* buf, size_t buflen); +} else version (OpenBSD) { int strerror_r(int errnum, scope char* buf, size_t buflen); diff --git a/src/core/stdc/tgmath.d b/src/core/stdc/tgmath.d index d6fe71975f..8747008c2e 100644 --- a/src/core/stdc/tgmath.d +++ b/src/core/stdc/tgmath.d @@ -571,6 +571,555 @@ version( FreeBSD ) // alias core.stdc.complex.crealf creal; // alias core.stdc.complex.creall creal; } +version( NetBSD ) +{ + /// + alias core.stdc.math.acos acos; + /// + alias core.stdc.math.acosf acos; + /// + alias core.stdc.math.acosl acos; + + /// + alias core.stdc.complex.cacos acos; + /// + alias core.stdc.complex.cacosf acos; + /// + alias core.stdc.complex.cacosl acos; + + /// + alias core.stdc.math.asin asin; + /// + alias core.stdc.math.asinf asin; + /// + alias core.stdc.math.asinl asin; + + /// + alias core.stdc.complex.casin asin; + /// + alias core.stdc.complex.casinf asin; + /// + alias core.stdc.complex.casinl asin; + + /// + alias core.stdc.math.atan atan; + /// + alias core.stdc.math.atanf atan; + /// + alias core.stdc.math.atanl atan; + + /// + alias core.stdc.complex.catan atan; + /// + alias core.stdc.complex.catanf atan; + /// + alias core.stdc.complex.catanl atan; + + /// + alias core.stdc.math.atan2 atan2; + /// + alias core.stdc.math.atan2f 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.complex.ccos cos; + /// + alias core.stdc.complex.ccosf cos; + /// + alias core.stdc.complex.ccosl cos; + + /// + alias core.stdc.math.sin sin; + /// + alias core.stdc.math.sinf sin; + /// + alias core.stdc.math.sinl sin; + + /// + alias core.stdc.complex.csin csin; + /// + alias core.stdc.complex.csinf csin; + /// + alias core.stdc.complex.csinl csin; + + /// + alias core.stdc.math.tan tan; + /// + alias core.stdc.math.tanf tan; + /// + alias core.stdc.math.tanl tan; + + /// + alias core.stdc.complex.ctan tan; + /// + alias core.stdc.complex.ctanf tan; + /// + alias core.stdc.complex.ctanl tan; + + /// + alias core.stdc.math.acosh acosh; + /// + alias core.stdc.math.acoshf acosh; + /// + alias core.stdc.math.acoshl acosh; + + /// + alias core.stdc.complex.cacosh acosh; + /// + alias core.stdc.complex.cacoshf acosh; + /// + alias core.stdc.complex.cacoshl acosh; + + /// + alias core.stdc.math.asinh asinh; + /// + alias core.stdc.math.asinhf asinh; + /// + alias core.stdc.math.asinhl asinh; + + /// + alias core.stdc.complex.casinh asinh; + /// + alias core.stdc.complex.casinhf asinh; + /// + alias core.stdc.complex.casinhl asinh; + + /// + alias core.stdc.math.atanh atanh; + /// + alias core.stdc.math.atanhf atanh; + /// + alias core.stdc.math.atanhl atanh; + + /// + alias core.stdc.complex.catanh atanh; + /// + alias core.stdc.complex.catanhf atanh; + /// + alias core.stdc.complex.catanhl atanh; + + /// + alias core.stdc.math.cosh cosh; + /// + alias core.stdc.math.coshf cosh; + /// + alias core.stdc.math.coshl cosh; + + /// + alias core.stdc.complex.ccosh cosh; + /// + alias core.stdc.complex.ccoshf cosh; + /// + alias core.stdc.complex.ccoshl cosh; + + /// + alias core.stdc.math.sinh sinh; + /// + alias core.stdc.math.sinhf sinh; + /// + alias core.stdc.math.sinhl sinh; + + /// + alias core.stdc.complex.csinh sinh; + /// + alias core.stdc.complex.csinhf sinh; + /// + alias core.stdc.complex.csinhl sinh; + + /// + alias core.stdc.math.tanh tanh; + /// + alias core.stdc.math.tanhf tanh; + /// + alias core.stdc.math.tanhl tanh; + + /// + alias core.stdc.complex.ctanh tanh; + /// + alias core.stdc.complex.ctanhf tanh; + /// + alias core.stdc.complex.ctanhl tanh; + + /// + alias core.stdc.math.exp exp; + /// + alias core.stdc.math.expf exp; + /// + alias core.stdc.math.expl exp; + + /// + alias core.stdc.complex.cexp exp; + /// + alias core.stdc.complex.cexpf exp; + /// + alias core.stdc.complex.cexpl exp; + + /// + alias core.stdc.math.exp2 exp2; + /// + alias core.stdc.math.exp2f exp2; + /// + alias core.stdc.math.exp2l exp2; + + /// + alias core.stdc.math.expm1 expm1; + /// + alias core.stdc.math.expm1f 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.ilogb ilogb; + /// + alias core.stdc.math.ilogbf ilogb; + /// + alias core.stdc.math.ilogbl ilogb; + + /// + alias core.stdc.math.ldexp ldexp; + /// + alias core.stdc.math.ldexpf 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.complex.clog log; + /// + alias core.stdc.complex.clogf log; + /// + alias core.stdc.complex.clogl log; + + /// + alias core.stdc.math.log10 log10; + /// + alias core.stdc.math.log10f 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.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; + /// + alias core.stdc.math.logbl logb; + + /// + alias core.stdc.math.modf modf; + /// + alias core.stdc.math.modff modf; +// alias core.stdc.math.modfl modf; + + /// + alias core.stdc.math.scalbn scalbn; + /// + alias core.stdc.math.scalbnf 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.cbrt cbrt; + /// + alias core.stdc.math.cbrtf cbrt; + /// + alias core.stdc.math.cbrtl cbrt; + + /// + alias core.stdc.math.fabs fabs; + /// + alias core.stdc.math.fabsf fabs; + /// + alias core.stdc.math.fabsl fabs; + + /// + alias core.stdc.complex.cabs fabs; + /// + alias core.stdc.complex.cabsf fabs; + /// + alias core.stdc.complex.cabsl fabs; + + /// + alias core.stdc.math.hypot hypot; + /// + alias core.stdc.math.hypotf 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.complex.cpow pow; + /// + alias core.stdc.complex.cpowf pow; + /// + alias core.stdc.complex.cpowl pow; + + /// + alias core.stdc.math.sqrt sqrt; + /// + alias core.stdc.math.sqrtf sqrt; + /// + alias core.stdc.math.sqrtl sqrt; + + /// + alias core.stdc.complex.csqrt sqrt; + /// + alias core.stdc.complex.csqrtf sqrt; + /// + alias core.stdc.complex.csqrtl sqrt; + + /// + alias core.stdc.math.erf erf; + /// + alias core.stdc.math.erff 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.lgamma lgamma; + /// + alias core.stdc.math.lgammaf 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.ceil ceil; + /// + alias core.stdc.math.ceilf 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.nearbyint nearbyint; + /// + alias core.stdc.math.nearbyintf nearbyint; + /// + alias core.stdc.math.nearbyintl nearbyint; + + /// + alias core.stdc.math.rint rint; + /// + alias core.stdc.math.rintf 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.llrint llrint; + /// + alias core.stdc.math.llrintf llrint; + /// + alias core.stdc.math.llrintl llrint; + + /// + alias core.stdc.math.round round; + /// + alias core.stdc.math.roundf round; + /// + alias core.stdc.math.roundl round; + + /// + alias core.stdc.math.lround lround; + /// + alias core.stdc.math.lroundf lround; + /// + alias core.stdc.math.lroundl lround; + + /// + alias core.stdc.math.llround llroundl; + /// + alias core.stdc.math.llroundf llroundl; + /// + alias core.stdc.math.llroundl llroundl; + + /// + alias core.stdc.math.trunc trunc; + /// + alias core.stdc.math.truncf trunc; + /// + alias core.stdc.math.truncl trunc; + + /// + alias core.stdc.math.fmod fmod; + /// + alias core.stdc.math.fmodf fmod; + /// + alias core.stdc.math.fmodl fmod; + + /// + alias core.stdc.math.remainder remainder; + /// + alias core.stdc.math.remainderf remainder; + /// + alias core.stdc.math.remainderl remainder; + + /// + alias core.stdc.math.remquo remquo; + /// + alias core.stdc.math.remquof remquo; + /// + alias core.stdc.math.remquol remquo; + + /// + alias core.stdc.math.copysign copysign; + /// + alias core.stdc.math.copysignf 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.nextafter nextafter; + /// + alias core.stdc.math.nextafterf 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.fdim fdim; + /// + alias core.stdc.math.fdimf 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.fmin fmin; + /// + alias core.stdc.math.fmin 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.complex.carg carg; + /// + alias core.stdc.complex.cargf carg; + /// + alias core.stdc.complex.cargl carg; + + /// + alias core.stdc.complex.cimag cimag; + /// + alias core.stdc.complex.cimagf cimag; + /// + alias core.stdc.complex.cimagl cimag; + + /// + alias core.stdc.complex.conj conj; + /// + alias core.stdc.complex.conjf conj; + /// + alias core.stdc.complex.conjl conj; + + /// + alias core.stdc.complex.cproj cproj; + /// + alias core.stdc.complex.cprojf cproj; + /// + alias core.stdc.complex.cprojl cproj; + +// alias core.stdc.complex.creal creal; +// alias core.stdc.complex.crealf creal; +// alias core.stdc.complex.creall creal; +} + else version( OpenBSD ) { /// diff --git a/src/core/stdc/time.d b/src/core/stdc/time.d index 57ae25a064..4325ca3429 100644 --- a/src/core/stdc/time.d +++ b/src/core/stdc/time.d @@ -95,6 +95,10 @@ else version( FreeBSD ) { enum clock_t CLOCKS_PER_SEC = 128; } +else version( NetBSD ) +{ + enum clock_t CLOCKS_PER_SEC = 100; +} else version( OpenBSD ) { enum clock_t CLOCKS_PER_SEC = 100; @@ -162,6 +166,13 @@ else version( FreeBSD ) /// extern __gshared const(char)*[2] tzname; // non-standard } +else version( NetBSD ) +{ + /// + void tzset(); // non-standard + /// + extern __gshared const(char)*[2] tzname; // non-standard +} else version( OpenBSD ) { /// diff --git a/src/core/thread.d b/src/core/thread.d index 6beb3b034d..0c9904ce15 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -936,6 +936,12 @@ class Thread */ __gshared const int PRIORITY_DEFAULT; + version(NetBSD) + { + //NetBSD does not support priority for default policy + // and it is not possible change policy without root access + int fakePriority = int.max; + } /** * Gets the scheduling priority for the associated thread. @@ -952,6 +958,10 @@ class Thread { return GetThreadPriority( m_hndl ); } + else version(NetBSD) + { + return fakePriority==int.max? PRIORITY_DEFAULT : fakePriority; + } else version( Posix ) { int policy; @@ -1016,6 +1026,10 @@ class Thread if (priocntl(idtype_t.P_LWPID, P_MYID, PC_SETPARMS, &pcparm) == -1) throw new ThreadException( "Unable to set scheduling class" ); } + else version(NetBSD) + { + fakePriority = val; + } else version( Posix ) { static if(__traits(compiles, pthread_setschedprio)) @@ -3127,6 +3141,7 @@ extern (C) @nogc nothrow { version (CRuntime_Glibc) int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr); version (FreeBSD) int pthread_attr_get_np(pthread_t thread, pthread_attr_t* attr); + version (NetBSD) int pthread_attr_get_np(pthread_t thread, pthread_attr_t* attr); version (Solaris) int thr_stksegment(stack_t* stk); version (CRuntime_Bionic) int pthread_getattr_np(pthread_t thid, pthread_attr_t* attr); } @@ -3187,6 +3202,17 @@ private void* getStackBottom() nothrow @nogc pthread_attr_destroy(&attr); return addr + size; } + else version (NetBSD) + { + pthread_attr_t attr; + void* addr; size_t size; + + pthread_attr_init(&attr); + pthread_attr_get_np(pthread_self(), &attr); + pthread_attr_getstack(&attr, &addr, &size); + pthread_attr_destroy(&attr); + return addr + size; + } else version (Solaris) { stack_t stk; @@ -4397,6 +4423,7 @@ private: { version (Posix) import core.sys.posix.sys.mman; // mmap version (FreeBSD) import core.sys.freebsd.sys.mman : MAP_ANON; + version (NetBSD) import core.sys.netbsd.sys.mman : MAP_ANON; version (CRuntime_Glibc) import core.sys.linux.sys.mman : MAP_ANON; version (Darwin) import core.sys.darwin.sys.mman : MAP_ANON; diff --git a/src/core/threadasm.S b/src/core/threadasm.S index 94acbef7ba..6c068abd4b 100644 --- a/src/core/threadasm.S +++ b/src/core/threadasm.S @@ -13,7 +13,7 @@ * http://www.boost.org/LICENSE_1_0.txt) */ -#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__) +#if (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)) && defined(__ELF__) /* * Mark the resulting object file as not requiring execution permissions on * stack memory. The absence of this section would mark the whole resulting diff --git a/src/core/time.d b/src/core/time.d index 69c288d3b0..d3a734dda1 100644 --- a/src/core/time.d +++ b/src/core/time.d @@ -313,6 +313,13 @@ else version(FreeBSD) enum ClockType uptimeCoarse = 9, uptimePrecise = 10, } +else version(NetBSD) enum ClockType +{ + normal = 0, + coarse = 2, + precise = 3, + second = 6, +} else version(Solaris) enum ClockType { normal = 0, @@ -368,6 +375,17 @@ version(Posix) case second: assert(0); } } + else version(NetBSD) + { + import core.sys.netbsd.time; + with(ClockType) final switch(clockType) + { + case coarse: return CLOCK_MONOTONIC; + case normal: return CLOCK_MONOTONIC; + case precise: return CLOCK_MONOTONIC; + case second: assert(0); + } + } else version(Solaris) { import core.sys.solaris.time; diff --git a/src/gc/os.d b/src/gc/os.d index 2593d8f26c..f5eae0eb74 100644 --- a/src/gc/os.d +++ b/src/gc/os.d @@ -40,6 +40,7 @@ else version (Posix) import core.sys.posix.sys.mman; version (FreeBSD) import core.sys.freebsd.sys.mman : MAP_ANON; + version (NetBSD) import core.sys.netbsd.sys.mman : MAP_ANON; version (CRuntime_Glibc) import core.sys.linux.sys.mman : MAP_ANON; version (Darwin) import core.sys.darwin.sys.mman : MAP_ANON; import core.stdc.stdlib; diff --git a/src/rt/bss_section.c b/src/rt/bss_section.c index 939ecb2790..b00f40d51c 100644 --- a/src/rt/bss_section.c +++ b/src/rt/bss_section.c @@ -10,7 +10,7 @@ /* These symbols are defined in the linker script and bracket the * .bss, .lbss, .lrodata and .ldata sections. */ -#if defined(__linux__) || defined(__FreeBSD__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) // Need to use weak linkage to workaround a bug in ld.bfd (Bugzilla 13025). extern int __attribute__((weak)) __bss_start, _end; diff --git a/src/rt/dmain2.d b/src/rt/dmain2.d index f17ca91004..2473f2d880 100644 --- a/src/rt/dmain2.d +++ b/src/rt/dmain2.d @@ -35,6 +35,10 @@ version (FreeBSD) { import core.stdc.fenv; } +version (NetBSD) +{ + import core.stdc.fenv; +} extern (C) void _d_monitor_staticctor(); extern (C) void _d_monitor_staticdtor(); diff --git a/src/rt/sections.d b/src/rt/sections.d index 0cbd5e594f..a12b73fb13 100644 --- a/src/rt/sections.d +++ b/src/rt/sections.d @@ -23,6 +23,8 @@ version (CRuntime_Glibc) public import rt.sections_elf_shared; else version (FreeBSD) public import rt.sections_elf_shared; +else version (NetBSD) + public import rt.sections_elf_shared; else version (Solaris) public import rt.sections_solaris; else version (Darwin) diff --git a/src/rt/sections_elf_shared.d b/src/rt/sections_elf_shared.d index ba9ef98a89..a95328b5fb 100644 --- a/src/rt/sections_elf_shared.d +++ b/src/rt/sections_elf_shared.d @@ -12,6 +12,7 @@ module rt.sections_elf_shared; version (CRuntime_Glibc) enum SharedELF = true; else version (FreeBSD) enum SharedELF = true; +else version (NetBSD) enum SharedELF = true; else enum SharedELF = false; static if (SharedELF): @@ -32,6 +33,12 @@ else version (FreeBSD) import core.sys.freebsd.sys.elf; import core.sys.freebsd.sys.link_elf; } +else version (NetBSD) +{ + import core.sys.netbsd.dlfcn; + import core.sys.netbsd.sys.elf; + import core.sys.netbsd.sys.link_elf; +} else { static assert(0, "unimplemented"); @@ -114,6 +121,7 @@ __gshared bool _isRuntimeInitialized; version (FreeBSD) private __gshared void* dummy_ref; +version (NetBSD) private __gshared void* dummy_ref; /**** * Gets called on program startup just before GC is initialized. @@ -123,6 +131,7 @@ void initSections() nothrow @nogc _isRuntimeInitialized = true; // reference symbol to support weak linkage version (FreeBSD) dummy_ref = &_d_dso_registry; + version (NetBSD) dummy_ref = &_d_dso_registry; } @@ -252,6 +261,7 @@ private: // start of linked list for ModuleInfo references version (FreeBSD) deprecated extern (C) __gshared void* _Dmodule_ref; +version (NetBSD) deprecated extern (C) __gshared void* _Dmodule_ref; version (Shared) { @@ -663,6 +673,8 @@ version (Shared) strtab = cast(const(char)*)dyn.d_un.d_ptr; else version (FreeBSD) strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate + else version (NetBSD) + strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate else static assert(0, "unimplemented"); break; @@ -768,6 +780,23 @@ else version (FreeBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* resu { return !!_rtld_addr_phdr(addr, result); } +else version (NetBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc +{ + static struct DG { const(void)* addr; dl_phdr_info* result; } + + extern(C) int callback(dl_phdr_info* info, size_t sz, void* arg) nothrow @nogc + { + auto p = cast(DG*)arg; + if (findSegmentForAddr(*info, p.addr)) + { + if (p.result !is null) *p.result = *info; + return 1; // break; + } + return 0; // continue iteration + } + auto dg = DG(addr, result); + return dl_iterate_phdr(&callback, &dg) != 0; +} /********************************* * Determine if 'addr' lies within shared object 'info'. @@ -793,11 +822,13 @@ bool findSegmentForAddr(in ref dl_phdr_info info, in void* addr, ElfW!"Phdr"* re version (linux) import core.sys.linux.errno : program_invocation_name; // should be in core.sys.freebsd.stdlib version (FreeBSD) extern(C) const(char)* getprogname() nothrow @nogc; +version (NetBSD) extern(C) const(char)* getprogname() nothrow @nogc; @property const(char)* progname() nothrow @nogc { version (linux) return program_invocation_name; version (FreeBSD) return getprogname(); + version (NetBSD) return getprogname(); } const(char)[] dsoName(const char* dlpi_name) nothrow @nogc @@ -836,6 +867,8 @@ const(void)[] getCopyRelocSection() nothrow @nogc enum ElfW!"Addr" exeBaseAddr = 0; else version (FreeBSD) enum ElfW!"Addr" exeBaseAddr = 0; + else version (NetBSD) + enum ElfW!"Addr" exeBaseAddr = 0; dl_phdr_info info = void; findDSOInfoForAddr(bss_start, &info) || assert(0); diff --git a/test/exceptions/line_trace.exp b/test/exceptions/line_trace.exp index c0909b653b..d0111a0360 100644 --- a/test/exceptions/line_trace.exp +++ b/test/exceptions/line_trace.exp @@ -2,8 +2,8 @@ object.Exception@src/line_trace.d(17): exception ---------------- src/line_trace.d:17 void line_trace.f1() [ADDR] src/line_trace.d:5 _Dmain [ADDR] -src/rt/dmain2.d:472 _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [ADDR] -src/rt/dmain2.d:447 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(void delegate()) [ADDR] -src/rt/dmain2.d:472 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [ADDR] -src/rt/dmain2.d:447 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(void delegate()) [ADDR] -src/rt/dmain2.d:480 _d_run_main [ADDR] +src/rt/dmain2.d:476 _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [ADDR] +src/rt/dmain2.d:451 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(void delegate()) [ADDR] +src/rt/dmain2.d:476 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [ADDR] +src/rt/dmain2.d:451 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(void delegate()) [ADDR] +src/rt/dmain2.d:484 _d_run_main [ADDR] diff --git a/test/shared/src/load.d b/test/shared/src/load.d index 4b114a6d07..c23302117f 100644 --- a/test/shared/src/load.d +++ b/test/shared/src/load.d @@ -2,6 +2,7 @@ import core.runtime, core.stdc.stdio, core.thread; version (linux) import core.sys.linux.dlfcn; else version (FreeBSD) import core.sys.freebsd.dlfcn; +else version (NetBSD) import core.sys.netbsd.dlfcn; else static assert(0, "unimplemented"); void loadSym(T)(void* handle, ref T val, const char* mangle)