diff --git a/src/core/runtime.d b/src/core/runtime.d index 53d51d57bc..0794f9e02d 100644 --- a/src/core/runtime.d +++ b/src/core/runtime.d @@ -407,6 +407,8 @@ extern (C) bool runModuleUnitTests() import core.sys.osx.execinfo; else version( FreeBSD ) import core.sys.freebsd.execinfo; + else version( DragonFlyBSD ) + import core.sys.dragonflybsd.execinfo; else version( Windows ) import core.sys.windows.stacktrace; else version( Solaris ) @@ -489,6 +491,8 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) import core.sys.osx.execinfo; else version( FreeBSD ) import core.sys.freebsd.execinfo; + else version( DragonFlyBSD ) + import core.sys.dragonflybsd.execinfo; else version( Windows ) import core.sys.windows.stacktrace; else version( Solaris ) @@ -650,6 +654,18 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) symEnd = eptr - buf.ptr; } } + else version( DragonFlyBSD ) + { + // 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 71f1f11acb..90fa9f7240 100644 --- a/src/core/stdc/config.d +++ b/src/core/stdc/config.d @@ -116,6 +116,8 @@ else version( DigitalMars ) alias real c_long_double; else version( FreeBSD ) alias real c_long_double; + else version( DragonFlyBSD ) + alias real c_long_double; else version( Solaris ) alias real c_long_double; else version( OSX ) diff --git a/src/core/stdc/errno.d b/src/core/stdc/errno.d index 0715e74a95..cff4a1ab72 100644 --- a/src/core/stdc/errno.d +++ b/src/core/stdc/errno.d @@ -1101,6 +1101,109 @@ else version( FreeBSD ) enum EPROTO = 92; /// Protocol error enum ELAST = 92; /// Must be equal largest errno } +else version( DragonFlyBSD ) +{ + 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 ENOTSUP = 45; + enum EOPNOTSUPP = ENOTSUP; + 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 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 ECANCELED = 85; + enum EILSEQ = 86; + enum ENOATTR = 87; + enum EDOOFUS = 88; + enum EBADMSG = 89; + enum EMULTIHOP = 90; + enum ENOLINK = 91; + enum EPROTO = 92; + enum ENOMEDIUM = 93; + enum EUNUSED94 = 94; + enum EUNUSED95 = 95; + enum EUNUSED96 = 96; + enum EUNUSED97 = 97; + enum EUNUSED98 = 98; + enum EASYNC = 99; + enum ELAST = 99; +} else version (Solaris) { enum EPERM = 1 /** Not super-user */; diff --git a/src/core/stdc/fenv.d b/src/core/stdc/fenv.d index 8438f0f024..3cb237f811 100644 --- a/src/core/stdc/fenv.d +++ b/src/core/stdc/fenv.d @@ -190,6 +190,24 @@ else version ( FreeBSD ) alias ushort fexcept_t; } +else version ( DragonFlyBSD ) +{ + struct fenv_t + { + struct _x87 + { + uint control; + uint status; + uint tag; + uint[4] others; + }; + _x87 x87; + + uint mxcsr; + } + + alias uint fexcept_t; +} else version( CRuntime_Bionic ) { version(X86) @@ -304,6 +322,12 @@ else version( FreeBSD ) /// enum FE_DFL_ENV = &__fe_dfl_env; } +else version( DragonFlyBSD ) +{ + private extern const fenv_t __fe_dfl_env; + /// + enum FE_DFL_ENV = &__fe_dfl_env; +} else version( CRuntime_Bionic ) { private extern const fenv_t __fe_dfl_env; diff --git a/src/core/stdc/locale.d b/src/core/stdc/locale.d index 99acd3f1c2..b8ea04cab8 100644 --- a/src/core/stdc/locale.d +++ b/src/core/stdc/locale.d @@ -126,6 +126,23 @@ else version(FreeBSD) /// enum LC_MESSAGES = 6; } +else version(DragonFlyBSD) +{ + /// + 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(Solaris) { enum LC_CTYPE = 0; diff --git a/src/core/stdc/math.d b/src/core/stdc/math.d index 9f9f30f3c3..5a1667c4ce 100644 --- a/src/core/stdc/math.d +++ b/src/core/stdc/math.d @@ -45,6 +45,13 @@ version (FreeBSD) /// enum int FP_ILOGBNAN = int.max; } +else version (DragonFlyBSD) +{ + /// + enum int FP_ILOGB0 = -int.max; + /// + enum int FP_ILOGBNAN = int.max; +} else version (CRuntime_Bionic) { /// @@ -813,6 +820,70 @@ else version( FreeBSD ) int signbit(real x) { return __signbit(x); } } } +else version( DragonFlyBSD ) +{ + enum + { + FP_INFINITE = 0x01, + FP_NAN = 0x02, + FP_NORMAL = 0x04, + FP_SUBNORMAL = 0x08, + FP_ZERO = 0x10, + } + + /* + * /usr/include/math.h : martynas@openbsd believes only F version is true. + enum FP_FAST_FMA = 1; + enum FP_FAST_FMAL = 1; + */ + enum FP_FAST_FMAF = 1; + + int __fpclassifyd(double); + int __fpclassifyf(float); + int __fpclassifyl(real); + int __isfinite(double); + int __isfinitef(float); + int __isfinitel(real); + int __isinf(double); + int __isinff(float); + int __isinfl(real); + int __isnan(double); + int __isnanf(float); + int __isnanl(real); + int __isnormal(double); + int __isnormalf(float); + int __isnormall(real); + int __signbit(double); + int __signbitf(float); + int __signbitl(real); + + extern (D) + { + int fpclassify(float x) { return __fpclassifyf(x); } + int fpclassify(double x) { return __fpclassifyd(x); } + int fpclassify(real x) { return __fpclassifyl(x); } + + int isfinite(float x) { return __isfinitef(x); } + int isfinite(double x) { return __isfinite(x); } + int isfinite(real x) { return __isfinitel(x); } + + int isinf(float x) { return __isinff(x); } + int isinf(double x) { return __isinf(x); } + int isinf(real x) { return __isinfl(x); } + + int isnan(float x) { return __isnanf(x); } + int isnan(double x) { return __isnan(x); } + int isnan(real x) { return __isnanl(x); } + + int isnormal(float x) { return __isnormalf(x); } + int isnormal(double x) { return __isnormal(x); } + int isnormal(real x) { return __isnormall(x); } + + int signbit(float x) { return __signbitf(x); } + int signbit(double x) { return __signbit(x); } + int signbit(real x) { return __signbitl(x); } + } +} else version( Solaris ) { int __isnanf(float x); @@ -1850,6 +1921,250 @@ else version( FreeBSD ) /// float fmaf(float x, float y, float z); } +else version(DragonFlyBSD) +{ + /* double */ + double acos(double x); + double asin(double x); + double atan(double x); + double atan2(double, double); + double cos(double x); + double sin(double x); + double tan(double x); + + double cosh(double x); + double sinh(double x); + double tanh(double x); + + double exp(double x); + double frexp(double, int *exp); + double ldexp(double, int exp); + double log(double x); + double log10(double x); + double modf(double x, double *iptr); + + double pow(double x, double y); + double sqrt(double x); + + double ceil(double x); + double fabs(double x); + double floor(double x); + double fmod(double x, double); + + double acosh(double x); + double asinh(double x); + double atanh(double x); + + double exp2(double x); + double expm1(double x); + int ilogb(double x); + double log1p(double x); + double log2(double x); + double logb(double x); + double scalbn(double x, int n); + double scalbln(double x, c_long n); + + double cbrt(double x); + double hypot(double x, double y); + + double erf(double x); + double erfc(double x); + double lgamma(double x); + double tgamma(double x); + + double nearbyint(double x); + double rint(double x); + c_long lrint(double x); + long llrint(double x); + double round(double x); + c_long lround(double x); + long llround(double x); + double trunc(double x); + + double remainder(double x , double y); + double remquo(double x, double y, int * quo); + + double copysign(double x, double y); + double nan(const char *); + double nextafter(double x, double y); + double nexttoward(double x, real y); + + double fdim(double x, double y); + double fmax(double x, double y); + double fmin(double x, double y); + + double fma(double x, double y, double z); + + double j0(double x); + double j1(double x); + double jn(int, double); + double y0(double x); + double y1(double x); + double yn(int, double); + + double gamma(double x); + double scalb(double x, double y); + + double drem(double x, double y); + int finite(double x); + double gamma_r(double x, int *); + double lgamma_r(double x, int *); + + double significand(double x); + + /* float */ + float acosf(float x); + float asinf(float x); + float atanf(float x); + float atan2f(float x, float y); + float cosf(float x); + float sinf(float x); + float tanf(float x); + + float acoshf(float x); + float asinhf(float x); + float atanhf(float x); + float coshf(float x); + float sinhf(float x); + float tanhf(float x); + + float expf(float x); + float exp2f(float x); + float expm1f(float x); + float frexpf(float x, int *exp); + int ilogbf(float x); + float ldexpf(float x, int exp); + float logf(float x); + float log10f(float x); + float log1pf(float x); + float log2f(float x); + float logbf(float x); + float modff(float x, float *iptr); + float scalbnf(float x, int y); + float scalblnf(float x, c_long y); + + float cbrtf(float x); + float fabsf(float x); + float hypotf(float x, float y); + float powf(float x, float y); + float sqrtf(float x); + + float erff(float x); + float erfcf(float x); + float lgammaf(float x); + float tgammaf(float x); + + float ceilf(float x); + float floorf(float x); + float nearbyintf(float x); + float rintf(float x); + c_long lrintf(float x); + long llrintf(float x); + float roundf(float x); + c_long lroundf(float x); + long llroundf(float x); + float truncf(float x); + + float fmodf(float x, float y); + float remainderf(float x, float y); + float remquof(float x, float y, int *iptr); + + float copysignf(float x, float y); + float nanf(const char *); + float nextafterf(float x, float y); + float nexttowardf(float x, real y); + + float fdimf(float x, float y); + float fmaxf(float x, float y); + float fminf(float x, float y); + + float fmaf(float x, float y, float z); + + float j0f(float x); + float j1f(float x); + float jnf(int, float); + float scalbf(float x, float); + float y0f(float x); + float y1f(float x); + float ynf(int, float); + float gammaf(float x); + float dremf(float x, float); + int finitef(float x); + int isinff(float x); + int isnanf(float x); + + float gammaf_r(float x, int *); + float lgammaf_r(float x, int *); + float significandf(float x); + + /* real */ + real acosl(real x); + real asinl(real x); + real atanl(real x); + real atan2l(real x, real y); + real cosl(real x); + real sinl(real x); + real tanl(real x); + + real acoshl(real x); + real asinhl(real x); + real atanhl(real x); + real coshl(real x); + real sinhl(real x); + real tanhl(real x); + + real expl(real x); + real exp2l(real x); + real expm1l(real x); + real frexpl(real x, int *exp); + int ilogbl(real x); + real ldexpl(real x, int exp); + real logl(real x); + real log10l(real x); + real log1pl(real x); + real log2l(real x); + real logbl(real x); + real modfl(real x, real *iptr); + real scalbnl(real x, int y); + real scalblnl(real x, c_long y); + + real cbrtl(real x); + real fabsl(real x); + real hypotl(real x, real y); + real powl(real x, real y); + real sqrtl(real x); + + real erfl(real x); + real erfcl(real x); + real lgammal(real x); + real tgammal(real x); + + real ceill(real x); + real floorl(real x); + real nearbyintl(real x); + real rintl(real x); + c_long lrintl(real x); + long llrintl(real x); + real roundl(real x); + c_long lroundl(real x); + long llroundl(real x); + real truncl(real x); + + real fmodl(real x, real); + real remainderl(real x, real); + real remquol(real x, real y, int *iptr); + + real copysignl(real x, real y); + real nanl(const char *); + real nextafterl(real x, real y); + real nexttowardl(real x, real y); + + real fdiml(real x, real y); + real fmaxl(real x, real y); + real fminl(real x, real y); + + real fmal(real x, real, real); +} else version(CRuntime_Bionic) { // Bionic defines long double as 64 bits, same as double, so several long diff --git a/src/core/stdc/stdio.d b/src/core/stdc/stdio.d index 3ffca8c089..8a71e5b275 100644 --- a/src/core/stdc/stdio.d +++ b/src/core/stdc/stdio.d @@ -25,6 +25,10 @@ private { import core.sys.posix.sys.types; } + else version (DragonFlyBSD) + { + import core.sys.posix.sys.types; + } } extern (C): @@ -166,6 +170,45 @@ else version ( FreeBSD ) long _mbstateL; } } +else version ( DragonFlyBSD ) +{ + enum + { + BUFSIZ = 1024, + EOF = -1, + FOPEN_MAX = 20, + FILENAME_MAX = 1024, + TMP_MAX = 308915776, + L_tmpnam = 1024 + } + + struct __sbuf { // + byte* s_buf; // storage buffer + int function(void *, const char *, int) sbuf_drain_func; + void* s_drain_arg; // user-supplied drain argument + int s_error; // current error code + ssize_t s_size; // size of storage buffer + ssize_t s_len; // current length of string + int s_flags; // flags + ssize_t s_sect_len; // current length of section + }; + + enum { + SBUF_FIXEDLEN = 0x00000000, // fixed length buffer (default) + SBUF_AUTOEXTEND = 0x00000001, // automatically extend buffer + SBUF_USRFLAGMSK = 0x0000ffff, // mask of flags the user may specify + SBUF_DYNAMIC = 0x00010000, // s_buf must be freed + SBUF_FINISHED = 0x00020000, // set by sbuf_finish() + SBUF_DYNSTRUCT = 0x00080000, // sbuf must be freed + SBUF_INSECTION = 0x00100000, // set by sbuf_start_section() + } + + union __mbstate_t // + { + char[128] _mbstate8; + long _mbstateL; + } +} else version (Solaris) { enum @@ -409,6 +452,24 @@ else version( FreeBSD ) /// alias shared(__sFILE) FILE; } +else version( DragonFlyBSD ) +{ + alias off_t fpos_t; + + /// See /usr/include/stdio.h + struct __FILE_public + { + ubyte* *_p; /* current position in (some) buffer */ + int _flags; /* flags, below; this FILE is free if 0 */ + int _fileno; /* fileno, if Unix descriptor, else -1 */ + ssize_t _r; /* read space left for getc() */ + ssize_t _w; /* write space left for putc() */ + ssize_t _lbfsize; /* 0 or -_bf._size, for inline putc */ + } + + alias __FILE_public _iobuf; + alias shared(__FILE_public) FILE; +} else version (Solaris) { import core.stdc.wchar_ : __mbstate_t; @@ -695,6 +756,23 @@ else version( FreeBSD ) /// alias __stderrp stderr; } +else version( DragonFlyBSD ) +{ + enum + { + _IOFBF = 0, + _IOLBF = 1, + _IONBF = 2, + } + + private extern shared FILE* __stdinp; + private extern shared FILE* __stdoutp; + private extern shared FILE* __stderrp; + + alias __stdinp stdin; + alias __stdoutp stdout; + alias __stderrp stderr; +} else version (Solaris) { enum @@ -995,6 +1073,37 @@ else version( FreeBSD ) /// int vsnprintf(char* s, size_t n, in char* format, va_list arg); } +else version( DragonFlyBSD ) +{ + // No unsafe pointer manipulation. + @trusted + { + void rewind(FILE*); + pure void clearerr(FILE*); + pure int feof(FILE*); + pure int ferror(FILE*); + int fileno(FILE*); + } + enum __SLBF = 0x0001; + enum __SNBF = 0x0002; + enum __SRD = 0x0004; + enum __SWR = 0x0008; + enum __SRW = 0x0010; + enum __SEOF = 0x0020; + enum __SERR = 0x0040; + enum __SMBF = 0x0080; + enum __SAPP = 0x0100; + enum __SSTR = 0x0200; + enum __SOPT = 0x0400; + enum __SNPT = 0x0800; + enum __SOFF = 0x1000; + enum __SMOD = 0x2000; + enum __SALC = 0x4000; + enum __SIGN = 0x8000; + + int snprintf(scope char* s, size_t n, scope const char* format, ...); + int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); +} else version (Solaris) { // No unsafe pointer manipulation. diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d index cecb0f184e..4cffdd25f1 100644 --- a/src/core/stdc/stdlib.d +++ b/src/core/stdc/stdlib.d @@ -66,6 +66,7 @@ version(Windows) enum RAND_MAX = 0x7fff; else version(CRuntime_Glibc) enum RAND_MAX = 0x7fffffff; else version(OSX) enum RAND_MAX = 0x7fffffff; else version(FreeBSD) enum RAND_MAX = 0x7fffffff; +else version(DragonFlyBSD) enum RAND_MAX = 0x7fffffff; else version(Solaris) enum RAND_MAX = 0x7fff; else version(CRuntime_Bionic) enum RAND_MAX = 0x7fffffff; else static assert( false, "Unsupported platform" ); diff --git a/src/core/stdc/string.d b/src/core/stdc/string.d index 1ed6e3a237..d1a12da9bf 100644 --- a/src/core/stdc/string.d +++ b/src/core/stdc/string.d @@ -84,6 +84,10 @@ else version (Solaris) { int strerror_r(int errnum, char* buf, size_t buflen); } +else version (DragonFlyBSD) +{ + int strerror_r(int errnum, char* buf, size_t buflen); +} else version (CRuntime_Bionic) { /// diff --git a/src/core/stdc/time.d b/src/core/stdc/time.d index 9bb3afc7fb..5f265d88d1 100644 --- a/src/core/stdc/time.d +++ b/src/core/stdc/time.d @@ -82,6 +82,10 @@ else version( FreeBSD ) { enum clock_t CLOCKS_PER_SEC = 128; } +else version( DragonFlyBSD ) +{ + enum clock_t CLOCKS_PER_SEC = 128; +} else version (CRuntime_Glibc) { enum clock_t CLOCKS_PER_SEC = 1_000_000; @@ -145,6 +149,13 @@ else version( FreeBSD ) /// extern __gshared const(char)*[2] tzname; // non-standard } +else version( DragonFlyBSD ) +{ + /// + void tzset(); // non-standard + /// + extern __gshared const(char)*[2] tzname; // non-standard +} else version (Solaris) { /// diff --git a/src/core/sys/dragonflybsd/pthread_np.d b/src/core/sys/dragonflybsd/pthread_np.d index 15fee1c715..7912b3b8d1 100644 --- a/src/core/sys/dragonflybsd/pthread_np.d +++ b/src/core/sys/dragonflybsd/pthread_np.d @@ -4,7 +4,7 @@ * Authors: Martin Nowak,Diederik de Groot(port:DragonFlyBSD) * Copied: From core/sys/freebsd/sys */ -module core.sys.dragonflybsd.pthread; +module core.sys.dragonflybsd.pthread_np; version (DragonFlyBSD): diff --git a/src/core/sys/freebsd/sys/elf_common.d b/src/core/sys/freebsd/sys/elf_common.d index fb8fcba1a4..98cdb0ce2d 100644 --- a/src/core/sys/freebsd/sys/elf_common.d +++ b/src/core/sys/freebsd/sys/elf_common.d @@ -78,6 +78,7 @@ enum ELFOSABI_NSK = 14; enum ELFOSABI_AROS = 15; enum ELFOSABI_ARM = 97; enum ELFOSABI_STANDALONE = 255; +enum ELFOSABI_DRAGONFLYBSD = ELFOSABI_NONE; extern (D) { diff --git a/src/core/sys/linux/elf.d b/src/core/sys/linux/elf.d index 235806a38a..e123119867 100644 --- a/src/core/sys/linux/elf.d +++ b/src/core/sys/linux/elf.d @@ -121,6 +121,7 @@ enum ELFOSABI_OPENBSD = 12; enum ELFOSABI_ARM_AEABI = 64; enum ELFOSABI_ARM = 97; enum ELFOSABI_STANDALONE = 255; +enum ELFOSABI_DRAGONFLYBSD = ELFOSABI_NONE; enum EI_ABIVERSION = 8; diff --git a/src/core/sys/osx/sys/mman.d b/src/core/sys/osx/sys/mman.d index 1a29903aa7..25a9099615 100644 --- a/src/core/sys/osx/sys/mman.d +++ b/src/core/sys/osx/sys/mman.d @@ -1,5 +1,5 @@ /** - * D header file for FreeBSD + * D header file for OSX * * Authors: Martin Nowak */ diff --git a/src/core/sys/solaris/sys/elf.d b/src/core/sys/solaris/sys/elf.d index 5b59f22abd..9b5035e19b 100644 --- a/src/core/sys/solaris/sys/elf.d +++ b/src/core/sys/solaris/sys/elf.d @@ -229,6 +229,7 @@ enum ELFOSABI_NSK = 14; enum ELFOSABI_AROS = 15; enum ELFOSABI_ARM = 97; enum ELFOSABI_STANDALONE = 255; +enum ELFOSABI_DRAGONFLYBSD = ELFOSABI_NONE; enum EAV_SUNW_NONE = 0; enum EAV_SUNW_CURRENT = 1; diff --git a/src/core/thread.d b/src/core/thread.d index 82aa41505c..edc2ee393d 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -979,7 +979,7 @@ class Thread } else { - // NOTE: pthread_setschedprio is not implemented on OSX or FreeBSD, so use + // NOTE: pthread_setschedprio is not implemented on Darwin, FreeBSD or DragonFlyBSD, so use // the more complicated get/set sequence below. int policy; sched_param param; @@ -3195,6 +3195,7 @@ extern (C) 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 (DragonFlyBSD) 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); } @@ -3322,6 +3323,17 @@ private void* getStackBottom() nothrow pthread_attr_destroy(&attr); return addr + size; } + else version (DragonFlyBSD) + { + 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; @@ -4668,6 +4680,7 @@ private: { version (Posix) import core.sys.posix.sys.mman; // mmap version (FreeBSD) import core.sys.freebsd.sys.mman : MAP_ANON; + version (DragonFlyBSD) import core.sys.dragonflybsd.sys.mman : MAP_ANON; version (CRuntime_Glibc) import core.sys.linux.sys.mman : MAP_ANON; version (OSX) import core.sys.osx.sys.mman : MAP_ANON; @@ -5874,6 +5887,27 @@ version (FreeBSD) unittest thr.join(); } +version (DragonFlyBSD) unittest +{ + static void loop() + { + pthread_attr_t attr; + pthread_attr_init(&attr); + auto thr = pthread_self(); + foreach (i; 0 .. 50) + pthread_attr_get_np(thr, &attr); + pthread_attr_destroy(&attr); + } + + auto thr = new Thread(&loop).start(); + foreach (i; 0 .. 50) + { + thread_suspendAll(); + thread_resumeAll(); + } + thr.join(); +} + unittest { // use >PAGESIZE to avoid stack overflow (e.g. in an syscall) diff --git a/src/core/threadasm.S b/src/core/threadasm.S index 97cb59fa0d..1660d47296 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 (__linux__ || __FreeBSD__ || __NetBSD__ || __DragonFly__) && __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 65c748abd4..763e2cc86e 100644 --- a/src/core/time.d +++ b/src/core/time.d @@ -186,7 +186,7 @@ version(CoreDdoc) enum ClockType extremely frequently (e.g. hundreds of thousands of times a second) but don't care about high precision, the coarse clock might be appropriate. - Currently, only Linux and FreeBSD support a coarser clock, and on other + Currently, only Linux and FreeBSD/DragonFlyBSD support a coarser clock, and on other platforms, it's treated as $(D ClockType.normal). +/ coarse = 2, @@ -198,7 +198,7 @@ version(CoreDdoc) enum ClockType more precise clock than the normal one, it's treated as equivalent to $(D ClockType.normal). - Currently, only FreeBSD supports a more precise clock, where it uses + Currently, only FreeBSD/DragonFlyBSD supports a more precise clock, where it uses $(D CLOCK_MONOTONIC_PRECISE) for the monotonic time and $(D CLOCK_REALTIME_PRECISE) for the wall clock time. +/ @@ -222,7 +222,7 @@ version(CoreDdoc) enum ClockType Uses a clock that has a precision of one second (contrast to the coarse clock, which has sub-second precision like the normal clock does). - FreeBSD is the only system which specifically has a clock set up for + FreeBSD/DragonFlyBSD are the only systems which specifically have a clock set up for this (it has $(D CLOCK_SECOND) to use with $(D clock_gettime) which takes advantage of an in-kernel cached value), but on other systems, the fastest function available will be used, and the resulting $(D SysTime) @@ -304,6 +304,16 @@ else version(FreeBSD) enum ClockType uptimeCoarse = 9, uptimePrecise = 10, } +else version(DragonFlyBSD) enum ClockType +{ + normal = 0, + coarse = 2, + precise = 3, + second = 6, + uptime = 8, + uptimeCoarse = 9, + uptimePrecise = 10, +} else version(Solaris) enum ClockType { normal = 0, @@ -372,6 +382,20 @@ version(Posix) case second: assert(0); } } + else version(DragonFlyBSD) + { + import core.sys.dragonflybsd.time; + with(ClockType) final switch(clockType) + { + case coarse: return CLOCK_MONOTONIC_FAST; + case normal: return CLOCK_MONOTONIC; + case precise: return CLOCK_MONOTONIC_PRECISE; + case uptime: return CLOCK_UPTIME; + case uptimeCoarse: return CLOCK_UPTIME_FAST; + case uptimePrecise: return CLOCK_UPTIME_PRECISE; + case second: assert(0); + } + } else // It needs to be decided (and implemented in an appropriate // version branch here) which clock types new platforms are going diff --git a/src/gc/os.d b/src/gc/os.d index a842f06245..921816a023 100644 --- a/src/gc/os.d +++ b/src/gc/os.d @@ -31,6 +31,7 @@ else version (Posix) { import core.sys.posix.sys.mman; version (FreeBSD) import core.sys.freebsd.sys.mman : MAP_ANON; + version (DragonFlyBSD) import core.sys.dragonflybsd.sys.mman : MAP_ANON; version (CRuntime_Glibc) import core.sys.linux.sys.mman : MAP_ANON; version (OSX) import core.sys.osx.sys.mman : MAP_ANON; import core.stdc.stdlib; diff --git a/src/rt/bss_section.c b/src/rt/bss_section.c index 939ecb2790..55c2c3e094 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(__DragonFly__) // 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 e0f8ad5e8b..ababe1b0a1 100644 --- a/src/rt/dmain2.d +++ b/src/rt/dmain2.d @@ -36,6 +36,10 @@ version (FreeBSD) { import core.stdc.fenv; } +version (DragonFlyBSD) +{ + import core.stdc.fenv; +} extern (C) void _d_monitor_staticctor(); extern (C) void _d_monitor_staticdtor(); diff --git a/src/rt/qsort.d b/src/rt/qsort.d index 986e393f92..66ac33d1c3 100644 --- a/src/rt/qsort.d +++ b/src/rt/qsort.d @@ -48,6 +48,21 @@ else version (FreeBSD) return a; } } +else version (DragonFlyBSD) +{ + alias extern (C) int function(void *, const void *, const void *) Cmp; + extern (C) void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, Cmp cmp); + + extern (C) void[] _adSort(void[] a, TypeInfo ti) + { + extern (C) int cmp(void* ti, in void* p1, in void* p2) + { + return (cast(TypeInfo)ti).compare(p1, p2); + } + qsort_r(a.ptr, a.length, ti.tsize, cast(void*)ti, &cmp); + return a; + } +} else version (OSX) { alias extern (C) int function(void *, const void *, const void *) Cmp; diff --git a/src/rt/sections.d b/src/rt/sections.d index c0e6decca4..01d861607b 100644 --- a/src/rt/sections.d +++ b/src/rt/sections.d @@ -16,6 +16,8 @@ version (CRuntime_Glibc) public import rt.sections_elf_shared; else version (FreeBSD) public import rt.sections_elf_shared; +else version (DragonFlyBSD) + public import rt.sections_elf_shared; else version (Solaris) public import rt.sections_solaris; else version (OSX) diff --git a/src/rt/sections_elf_shared.d b/src/rt/sections_elf_shared.d index 4076953bc4..f28223e3a1 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 (DragonFlyBSD) 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 (DragonFlyBSD) +{ + import core.sys.dragonflybsd.dlfcn; + import core.sys.dragonflybsd.sys.elf; + import core.sys.dragonflybsd.sys.link_elf; +} else { static assert(0, "unimplemented"); @@ -115,6 +122,7 @@ __gshared bool _isRuntimeInitialized; version (FreeBSD) private __gshared void* dummy_ref; +version (DragonFlyBSD) private __gshared void* dummy_ref; /**** * Gets called on program startup just before GC is initialized. @@ -124,6 +132,7 @@ void initSections() _isRuntimeInitialized = true; // reference symbol to support weak linkage version (FreeBSD) dummy_ref = &_d_dso_registry; + version (DragonFlyBSD) dummy_ref = &_d_dso_registry; } @@ -243,6 +252,7 @@ private: // start of linked list for ModuleInfo references version (FreeBSD) deprecated extern (C) __gshared void* _Dmodule_ref; +version (DragonFlyBSD) deprecated extern (C) __gshared void* _Dmodule_ref; version (Shared) { @@ -649,6 +659,8 @@ nothrow: 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 (DragonFlyBSD) + strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate else static assert(0, "unimplemented"); break; @@ -754,6 +766,10 @@ else version (FreeBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* resu { return !!_rtld_addr_phdr(addr, result); } +else version (DragonFlyBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc +{ + return !!_rtld_addr_phdr(addr, result); +} /********************************* * Determine if 'addr' lies within shared object 'info'. @@ -779,11 +795,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 (DragonFlyBSD) extern(C) const(char)* getprogname() nothrow @nogc; @property const(char)* progname() nothrow @nogc { version (linux) return program_invocation_name; version (FreeBSD) return getprogname(); + version (DragonFlyBSD) return getprogname(); } nothrow diff --git a/src/rt/sections_ldc.d b/src/rt/sections_ldc.d index 8500a6b67c..64acb8f576 100644 --- a/src/rt/sections_ldc.d +++ b/src/rt/sections_ldc.d @@ -16,7 +16,10 @@ module rt.sections_ldc; -version (linux) {} else version (FreeBSD) {} else version(LDC): +version (linux) {} +else version (FreeBSD) {} +else version (DragonFlyBSD) {} +else version(LDC): import core.stdc.stdlib : alloca; import rt.minfo; diff --git a/test/shared/src/load.d b/test/shared/src/load.d index 4b114a6d07..ef4bbaea13 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 (DragonFlyBSD) import core.sys.dragonflybsd.dlfcn; else static assert(0, "unimplemented"); void loadSym(T)(void* handle, ref T val, const char* mangle)