diff --git import/core/stdc/errno.d import/core/stdc/errno.d
index da3f0e1..44c444c 100644
--- import/core/stdc/errno.d
+++ import/core/stdc/errno.d
@@ -281,7 +281,7 @@ else version( OSX )
     enum ETIME              = 101;      // STREAM ioctl timeout
     enum ELAST              = 101;      // Must be equal largest errno
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum EPERM              = 1;        // Operation not permitted
     enum ENOENT             = 2;        // No such file or directory
diff --git import/core/stdc/fenv.d import/core/stdc/fenv.d
index 89e5708..8263cc6 100644
--- import/core/stdc/fenv.d
+++ import/core/stdc/fenv.d
@@ -67,7 +67,7 @@ else version ( OSX )
         alias ushort fexcept_t;
     }
 }
-else version ( freebsd )
+else version ( FreeBSD )
 {
     struct fenv_t
     {
@@ -115,10 +115,10 @@ else version( OSX )
     private extern fenv_t _FE_DFL_ENV;
     fenv_t* FE_DFL_ENV = &_FE_DFL_ENV;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    private extern fenv_t __fe_dfl_env;
-    fenv_t* FE_DFL_ENV = &__fe_dfl_env;
+    private extern const fenv_t __fe_dfl_env;
+    const fenv_t* FE_DFL_ENV = &__fe_dfl_env;
 }
 else
 {
diff --git import/core/stdc/math.d import/core/stdc/math.d
index 117a95d..877cc44 100644
--- import/core/stdc/math.d
+++ import/core/stdc/math.d
@@ -367,7 +367,7 @@ else version( OSX )
     }
   }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum
     {
@@ -468,37 +468,39 @@ extern (D)
     int isunordered(real x, real y)        { return (x !<>= y); }
 }
 
-// NOTE: freebsd < 8-CURRENT doesn't appear to support *l, but we can
-//       approximate.
-version( freebsd )
+// NOTE: FreeBSD 8.0-RELEASE doesn't support log2* nor these *l functions:
+//         acoshl, asinhl, atanhl, coshl, sinhl, tanhl, cbrtl, powl, expl,
+//         expm1l, logl, log1pl, log10l, erfcl, erfl, lgammal, tgammal;
+//       but we can approximate.
+version( FreeBSD )
 {
     double  acos(double x);
     float   acosf(float x);
-    real    acosl(real x) { return acos(x); }
+    real    acosl(real x);
 
     double  asin(double x);
     float   asinf(float x);
-    real    asinl(real x) { return asin(x); }
+    real    asinl(real x);
 
     double  atan(double x);
     float   atanf(float x);
-    real    atanl(real x) { return atan(x); }
+    real    atanl(real x);
 
     double  atan2(double y, double x);
     float   atan2f(float y, float x);
-    real    atan2l(real y, real x) { return atan2(y, x); }
+    real    atan2l(real y, real x);
 
     double  cos(double x);
     float   cosf(float x);
-    real    cosl(real x) { return cos(x); }
+    real    cosl(real x);
 
     double  sin(double x);
     float   sinf(float x);
-    real    sinl(real x) { return sin(x); }
+    real    sinl(real x);
 
     double  tan(double x);
     float   tanf(float x);
-    real    tanl(real x) { return tan(x); }
+    real    tanl(real x);
 
     double  acosh(double x);
     float   acoshf(float x);
@@ -530,7 +532,7 @@ version( freebsd )
 
     double  exp2(double x);
     float   exp2f(float x);
-    real    exp2l(real x) { return exp2(x); }
+    real    exp2l(real x);
 
     double  expm1(double x);
     float   expm1f(float x);
@@ -538,15 +540,15 @@ version( freebsd )
 
     double  frexp(double value, int* exp);
     float   frexpf(float value, int* exp);
-    real    frexpl(real value, int* exp) { return frexp(value, exp); }
+    real    frexpl(real value, int* exp);
 
     int     ilogb(double x);
     int     ilogbf(float x);
-    int     ilogbl(real x) { return ilogb(x); }
+    int     ilogbl(real x);
 
     double  ldexp(double x, int exp);
     float   ldexpf(float x, int exp);
-    real    ldexpl(real x, int exp) { return ldexp(x, exp); }
+    real    ldexpl(real x, int exp);
 
     double  log(double x);
     float   logf(float x);
@@ -567,19 +569,19 @@ version( freebsd )
 
     double  logb(double x);
     float   logbf(float x);
-    real    logbl(real x) { return logb(x); }
+    real    logbl(real x);
 
     double  modf(double value, double* iptr);
     float   modff(float value, float* iptr);
-    //real    modfl(real value, real *iptr); // nontrivial conversion
+    real    modfl(real value, real *iptr);
 
     double  scalbn(double x, int n);
     float   scalbnf(float x, int n);
-    real    scalbnl(real x, int n) { return scalbn(x, n); }
+    real    scalbnl(real x, int n);
 
     double  scalbln(double x, c_long n);
     float   scalblnf(float x, c_long n);
-    real    scalblnl(real x, c_long n) { return scalbln(x, n); }
+    real    scalblnl(real x, c_long n);
 
 
     double  cbrt(double x);
@@ -588,11 +590,11 @@ version( freebsd )
 
     double  fabs(double x);
     float   fabsf(float x);
-    real    fabsl(real x) { return fabs(x); }
+    real    fabsl(real x);
 
     double  hypot(double x, double y);
     float   hypotf(float x, float y);
-    real    hypotl(real x, real y) { return hypot(x, y); }
+    real    hypotl(real x, real y);
 
     double  pow(double x, double y);
     float   powf(float x, float y);
@@ -600,7 +602,7 @@ version( freebsd )
 
     double  sqrt(double x);
     float   sqrtf(float x);
-    real    sqrtl(real x) { return sqrt(x); }
+    real    sqrtl(real x);
 
     double  erf(double x);
     float   erff(float x);
@@ -620,87 +622,87 @@ version( freebsd )
 
     double  ceil(double x);
     float   ceilf(float x);
-    real    ceill(real x) { return ceil(x); }
+    real    ceill(real x);
 
     double  floor(double x);
     float   floorf(float x);
-    real    floorl(real x) { return floor(x); }
+    real    floorl(real x);
 
     double  nearbyint(double x);
     float   nearbyintf(float x);
-    real    nearbyintl(real x) { return nearbyint(x); }
+    real    nearbyintl(real x);
 
     double  rint(double x);
     float   rintf(float x);
-    real    rintl(real x) { return rint(x); }
+    real    rintl(real x);
 
     c_long  lrint(double x);
     c_long  lrintf(float x);
-    c_long  lrintl(real x) { return lrint(x); }
+    c_long  lrintl(real x);
 
     long    llrint(double x);
     long    llrintf(float x);
-    long    llrintl(real x) { return llrint(x); }
+    long    llrintl(real x);
 
     double  round(double x);
     float   roundf(float x);
-    real    roundl(real x) { return round(x); }
+    real    roundl(real x);
 
     c_long  lround(double x);
     c_long  lroundf(float x);
-    c_long  lroundl(real x) { return lround(x); }
+    c_long  lroundl(real x);
 
     long    llround(double x);
     long    llroundf(float x);
-    long    llroundl(real x) { return llround(x); }
+    long    llroundl(real x);
 
     double  trunc(double x);
     float   truncf(float x);
-    real    truncl(real x) { return trunc(x); }
+    real    truncl(real x);
 
     double  fmod(double x, double y);
     float   fmodf(float x, float y);
-    real    fmodl(real x, real y) { return fmod(x, y); }
+    real    fmodl(real x, real y);
 
     double  remainder(double x, double y);
     float   remainderf(float x, float y);
-    real    remainderl(real x, real y) { return remainder(x, y); }
+    real    remainderl(real x, real 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); }
+    real    remquol(real x, real y, int* quo);
 
     double  copysign(double x, double y);
     float   copysignf(float x, float y);
-    real    copysignl(real x, real y) { return copysign(x, y); }
+    real    copysignl(real x, real y);
 
-//  double  nan(char* tagp);
-//  float   nanf(char* tagp);
-//  real    nanl(char* tagp);
+    double  nan(char* tagp);
+    float   nanf(char* tagp);
+    real    nanl(char* tagp);
 
     double  nextafter(double x, double y);
     float   nextafterf(float x, float y);
-    real    nextafterl(real x, real y) { return nextafter(x, y); }
+    real    nextafterl(real x, real y);
 
     double  nexttoward(double x, real y);
     float   nexttowardf(float x, real y);
-    real    nexttowardl(real x, real y) { return nexttoward(x, y); }
+    real    nexttowardl(real x, real y);
 
     double  fdim(double x, double y);
     float   fdimf(float x, float y);
-    real    fdiml(real x, real y) { return fdim(x, y); }
+    real    fdiml(real x, real y);
 
     double  fmax(double x, double y);
     float   fmaxf(float x, float y);
-    real    fmaxl(real x, real y) { return fmax(x, y); }
+    real    fmaxl(real x, real y);
 
     double  fmin(double x, double y);
     float   fminf(float x, float y);
-    real    fminl(real x, real y) { return fmin(x, y); }
+    real    fminl(real x, real y);
 
     double  fma(double x, double y, double z);
     float   fmaf(float x, float y, float z);
-    real    fmal(real x, real y, real z) { return fma(x, y, z); }
+    real    fmal(real x, real y, real z);
 }
 else
 {
diff --git import/core/stdc/stdio.d import/core/stdc/stdio.d
index 116dce0..d03218b 100644
--- import/core/stdc/stdio.d
+++ import/core/stdc/stdio.d
@@ -18,6 +18,8 @@ private
     import core.stdc.config;
     import core.stdc.stddef; // for size_t
     import core.stdc.stdarg; // for va_list
+
+    import core.sys.posix.sys.types;
 }
 
 extern (C):
@@ -89,17 +91,17 @@ else version ( FreeBSD )
         L_tmpnam     = 1024
     }
 
-    private
+    struct __sbuf
     {
-        struct __sbuf
-        {
-            ubyte *_base;
-            int _size;
-        }
-        struct __sFILEX
-        {
+        ubyte *_base;
+        int _size;
+    }
+    alias _iobuf __sFILE;
 
-        }
+    union __mbstate_t // <sys/_types.h>
+    {
+        char[128]   _mbstate8;
+        long        _mbstateL;
     }
 }
 else
@@ -180,31 +182,37 @@ struct _iobuf
     }
     else version( FreeBSD )
     {
-        ubyte*    _p;
-        int       _r;
-        int       _w;
-        short     _flags;
-        short     _file;
-        __sbuf    _bf;
-        int       _lbfsize;
-
-        void* function()                        _cookie;
-        int* function(void*)                    _close;
-        int* function(void*, char*, int)        _read;
-        fpos_t* function(void*, fpos_t, int)    _seek;
-        int* function(void*, char *, int)       _write;
-
-        __sbuf    _ub;
-        __sFILEX* _extra;
-        int       _ur;
-
-        ubyte[3]  _ubuf;
-        ubyte[1]  _nbuf;
-
-        __sbuf    _lb;
-
-        int       _blksize;
-        fpos_t    _offset;
+	ubyte*          _p;
+	int             _r;
+	int             _w;
+	short           _flags;
+	short           _file;
+	__sbuf          _bf;
+	int             _lbfsize;
+
+	void*           _cookie;
+	int     function(void*)                 _close;
+	int     function(void*, char*, int)     _read;
+	fpos_t  function(void*, fpos_t, int)    _seek;
+	int     function(void*, in char*, int)  _write;
+
+	__sbuf          _ub;
+	ubyte*          _up;
+	int             _ur;
+
+	ubyte[3]        _ubuf;
+	ubyte[1]        _nbuf;
+
+	__sbuf          _lb;
+
+	int             _blksize;
+	fpos_t          _offset;
+
+	pthread_mutex_t _fl_mutex;
+	pthread_t       _fl_owner;
+	int             _fl_count;
+	int             _orientation;
+	__mbstate_t     _mbstate;
     }
     else
     {
@@ -289,11 +297,20 @@ else version( OSX )
 }
 else version( FreeBSD )
 {
-    private extern shared FILE[3] __sF;
+    enum
+    {
+        _IOFBF = 0,
+        _IOLBF = 1,
+        _IONBF = 2,
+    }
 
-    shared stdin  = &__sF[0];
-    shared stdout = &__sF[1];
-    shared stderr = &__sF[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
 {
diff --git import/core/stdc/tgmath.d import/core/stdc/tgmath.d
index 7bc1b02..e6f8940 100644
--- import/core/stdc/tgmath.d
+++ import/core/stdc/tgmath.d
@@ -19,7 +19,7 @@ private static import core.stdc.complex;
 
 extern (C):
 
-version( freebsd )
+version( FreeBSD )
 {
     alias core.stdc.math.acos          acos;
     alias core.stdc.math.acosf         acos;
diff --git import/core/stdc/time.d import/core/stdc/time.d
index f41c0b0..bbc9e06 100644
--- import/core/stdc/time.d
+++ import/core/stdc/time.d
@@ -64,7 +64,7 @@ else version( OSX )
 {
     enum clock_t CLOCKS_PER_SEC = 100;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum clock_t CLOCKS_PER_SEC = 128;
 }
@@ -94,7 +94,7 @@ else version( linux )
 {
     void tzset(); // non-standard
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     void tzset(); // non-standard
 }
diff --git import/core/sys/posix/arpa/inet.d import/core/sys/posix/arpa/inet.d
index 7f454ea..09adb61 100644
--- import/core/sys/posix/arpa/inet.d
+++ import/core/sys/posix/arpa/inet.d
@@ -88,10 +88,10 @@ else version( OSX )
     char*     inet_ntop(int, in void*, char*, socklen_t);
     int       inet_pton(int, in char*, void*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    alias uint16_t in_port_t; // TODO: verify
-    alias uint32_t in_addr_t; // TODO: verify
+    alias uint16_t in_port_t;
+    alias uint32_t in_addr_t;
 
     struct in_addr
     {
@@ -105,10 +105,10 @@ else version( freebsd )
     uint32_t ntohl(uint32_t);
     uint16_t ntohs(uint16_t);
 
-    in_addr_t inet_addr(in char*);
-    char*     inet_ntoa(in_addr);
-    char*     inet_ntop(int, in void*, char*, socklen_t);
-    int       inet_pton(int, in char*, void*);
+    in_addr_t       inet_addr(in char*);
+    char*           inet_ntoa(in_addr);
+    const(char)*    inet_ntop(int, in void*, char*, socklen_t);
+    int             inet_pton(int, in char*, void*);
 }
 
 //
@@ -126,7 +126,7 @@ else version( OSX )
 {
     enum INET6_ADDRSTRLEN = 46;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum INET6_ADDRSTRLEN = 46;
 }
diff --git import/core/sys/posix/dirent.d import/core/sys/posix/dirent.d
index 6464762..1703e55 100644
--- import/core/sys/posix/dirent.d
+++ import/core/sys/posix/dirent.d
@@ -108,7 +108,7 @@ else version( OSX )
 
     dirent* readdir(DIR*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum
     {
@@ -129,24 +129,11 @@ else version( freebsd )
         uint      d_fileno;
         ushort    d_reclen;
         ubyte     d_type;
-        ubyte     d_namelen;
+        ubyte     d_namlen;
         char[256] d_name;
     }
 
-    struct _telldir;
-    struct DIR
-    {
-        int       dd_fd;
-        c_long    dd_loc;
-        c_long    dd_size;
-        char*     dd_buf;
-        int       dd_len;
-        c_long    dd_seek;
-        c_long    dd_rewind;
-        int       dd_flags;
-        void*     dd_lock;
-        _telldir* dd_td;
-    }
+    typedef void* DIR;
 
     dirent* readdir(DIR*);
 }
@@ -183,7 +170,7 @@ else version( OSX )
 {
     int readdir_r(DIR*, dirent*, dirent**);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int readdir_r(DIR*, dirent*, dirent**);
 }
@@ -201,3 +188,8 @@ version( linux )
     void   seekdir(DIR*, c_long);
     c_long telldir(DIR*);
 }
+else version( FreeBSD )
+{
+    void   seekdir(DIR*, c_long);
+    c_long telldir(DIR*);
+}
diff --git import/core/sys/posix/dlfcn.d import/core/sys/posix/dlfcn.d
index 98d2252..a9ae1dd 100644
--- import/core/sys/posix/dlfcn.d
+++ import/core/sys/posix/dlfcn.d
@@ -56,7 +56,7 @@ else version( OSX )
     void* dlopen(in char*, int);
     void* dlsym(void*, in char*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum RTLD_LAZY      = 1;
     enum RTLD_NOW       = 2;
diff --git import/core/sys/posix/fcntl.d import/core/sys/posix/fcntl.d
index 144aae9..4ffaeef 100644
--- import/core/sys/posix/fcntl.d
+++ import/core/sys/posix/fcntl.d
@@ -185,7 +185,7 @@ else version( OSX )
     int creat(in char*, mode_t);
     int open(in char*, int, ...);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum F_DUPFD        = 0;
     enum F_GETFD        = 1;
@@ -194,9 +194,13 @@ else version( freebsd )
     enum F_SETFL        = 4;
     enum F_GETOWN       = 5;
     enum F_SETOWN       = 6;
-    enum F_GETLK        = 7;
-    enum F_SETLK        = 8;
-    enum F_SETLKW       = 9;
+    enum F_GETLK        = 11;
+    enum F_SETLK        = 12;
+    enum F_SETLKW       = 13;
+    enum F_OGETLK       = 7;
+    enum F_OSETLK       = 8;
+    enum F_OSETLKW      = 9;
+    enum F_DUP2FD       = 10;
 
     enum FD_CLOEXEC     = 1;
 
@@ -206,7 +210,7 @@ else version( freebsd )
 
     enum O_CREAT        = 0x0200;
     enum O_EXCL         = 0x0800;
-    enum O_NOCTTY       = 0;
+    enum O_NOCTTY       = 0x8000;
     enum O_TRUNC        = 0x0400;
 
     enum O_RDONLY       = 0x0000;
@@ -227,6 +231,16 @@ else version( freebsd )
         pid_t   l_pid;
         short   l_type;
         short   l_whence;
+        int     l_sysid;
+    }
+
+    struct oflock
+    {
+        off_t   l_start;
+        off_t   l_len;
+        pid_t   l_pid;
+        short   l_type;
+        short   l_whence;
     }
 
     int creat(in char*, mode_t);
diff --git import/core/sys/posix/net/if_.d import/core/sys/posix/net/if_.d
index e4cd3ac..9ed3773 100644
--- import/core/sys/posix/net/if_.d
+++ import/core/sys/posix/net/if_.d
@@ -65,7 +65,7 @@ else version( OSX )
     if_nameindex_t* if_nameindex();
     void            if_freenameindex(if_nameindex_t*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct if_nameindex_t
     {
diff --git import/core/sys/posix/netinet/in_.d import/core/sys/posix/netinet/in_.d
index e926ff5..dc80663 100644
--- import/core/sys/posix/netinet/in_.d
+++ import/core/sys/posix/netinet/in_.d
@@ -116,10 +116,8 @@ else version( OSX )
     
     enum INET_ADDRSTRLEN       = 16;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    private enum __SOCK_SIZE__ = 16;
-
     struct sockaddr_in
     {
         ubyte       sin_len;
@@ -445,6 +443,148 @@ else version( OSX )
                ((cast(uint8_t*) addr)[1] & 0xf) == 0xe;
     }
 }
+else version( FreeBSD )
+{
+    struct in6_addr
+    {
+        union
+        {
+            uint8_t[16] s6_addr;
+            uint16_t[8] s6_addr16;
+            uint32_t[4] s6_addr32;
+        }
+    }
+
+    struct sockaddr_in6
+    {
+        uint8_t     sin6_len;
+        sa_family_t sin6_family;
+        in_port_t   sin6_port;
+        uint32_t    sin6_flowinfo;
+        in6_addr    sin6_addr;
+        uint32_t    sin6_scope_id;
+    }
+
+    extern const in6_addr in6addr_any;
+    extern const in6_addr in6addr_loopback;
+
+    struct ipv6_mreq
+    {
+        in6_addr    ipv6mr_multiaddr;
+        uint        ipv6mr_interface;
+    }
+
+    enum INET6_ADDRSTRLEN    = 46;
+    enum IPPROTO_IPV6        = 41; // <netinet/in.h>
+
+    enum
+    {
+        IPV6_SOCKOPT_RESERVED1  = 3,
+        IPV6_UNICAST_HOPS       = 4,
+        IPV6_MULTICAST_IF       = 9,
+        IPV6_MULTICAST_HOPS     = 10,
+        IPV6_MULTICAST_LOOP     = 11,
+        IPV6_JOIN_GROUP         = 12,
+        IPV6_LEAVE_GROUP        = 13,
+        IPV6_PORTRANGE          = 14,
+        ICMP6_FILTER            = 18,
+        IPV6_CHECKSUM           = 26,
+        IPV6_V6ONLY             = 27,
+    }
+
+    private enum
+    {
+        __IPV6_ADDR_SCOPE_NODELOCAL     = 0x01,
+        __IPV6_ADDR_SCOPE_INTFACELOCAL  = 0x01,
+        __IPV6_ADDR_SCOPE_LINKLOCAL     = 0x02,
+        __IPV6_ADDR_SCOPE_SITELOCAL     = 0x05,
+        __IPV6_ADDR_SCOPE_ORGLOCAL      = 0x08,
+        __IPV6_ADDR_SCOPE_GLOBAL        = 0x0e,
+    }
+
+    // macros
+    extern (D) int IN6_IS_ADDR_UNSPECIFIED( in in6_addr* a )
+    {
+        return (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[0]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[4]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[8]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[12]) == 0);
+    }
+
+    extern (D) int IN6_IS_ADDR_LOOPBACK( in in6_addr* a )
+    {
+        return (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[0]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[4]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[8]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[12]) == ntohl(1));
+    }
+
+    extern (D) int IN6_IS_ADDR_V4COMPAT( in in6_addr* a )
+    {
+        return (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[0]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[4]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[8]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[12]) != 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[12]) != ntohl(1));
+    }
+
+    extern (D) int IN6_IS_ADDR_V4MAPPED( in in6_addr* a )
+    {
+        return (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[0]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[4]) == 0) &&
+               (*cast(const uint32_t*) cast(const void*) (&a.s6_addr[8]) == ntohl(0x0000ffff));
+    }
+
+    extern (D) int IN6_IS_ADDR_LINKLOCAL( in in6_addr* a )
+    {
+        return a.s6_addr[0] == 0xfe && (a.s6_addr[1] & 0xc0) == 0x80;
+    }
+
+    extern (D) int IN6_IS_ADDR_SITELOCAL( in in6_addr* a )
+    {
+        return a.s6_addr[0] == 0xfe && (a.s6_addr[1] & 0xc0) == 0xc0;
+    }
+
+    extern (D) int IN6_IS_ADDR_MULTICAST( in in6_addr* a )
+    {
+        return a.s6_addr[0] == 0xff;
+    }
+
+    extern (D) uint8_t __IPV6_ADDR_MC_SCOPE( in in6_addr* a )
+    {
+        return a.s6_addr[1] & 0x0f;
+    }
+
+    extern (D) int IN6_IS_ADDR_MC_NODELOCAL( in in6_addr* a )
+    {
+        return IN6_IS_ADDR_MULTICAST(a) &&
+               __IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL;
+    }
+
+    extern (D) int IN6_IS_ADDR_MC_LINKLOCAL( in in6_addr* a )
+    {
+        return IN6_IS_ADDR_MULTICAST(a) &&
+               __IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL;
+    }
+
+    extern (D) int IN6_IS_ADDR_MC_SITELOCAL( in in6_addr* a )
+    {
+        return IN6_IS_ADDR_MULTICAST(a) &&
+               __IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL;
+    }
+
+    extern (D) int IN6_IS_ADDR_MC_ORGLOCAL( in in6_addr* a )
+    {
+        return IN6_IS_ADDR_MULTICAST(a) &&
+               __IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL;
+    }
+
+    extern (D) int IN6_IS_ADDR_MC_GLOBAL( in in6_addr* a )
+    {
+        return IN6_IS_ADDR_MULTICAST(a) &&
+               __IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL;
+    }
+}
 
 
 //
@@ -462,3 +602,7 @@ else version( OSX )
 {
     enum uint IPPROTO_RAW = 255;
 }
+else version( FreeBSD )
+{
+    enum uint IPPROTO_RAW = 255;
+}
diff --git import/core/sys/posix/netinet/tcp.d import/core/sys/posix/netinet/tcp.d
index 1d25cdc..8f70e6f 100644
--- import/core/sys/posix/netinet/tcp.d
+++ import/core/sys/posix/netinet/tcp.d
@@ -32,7 +32,7 @@ else version( OSX )
 {
     enum TCP_NODELAY = 1;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum TCP_NODELAY = 1;
 }
diff --git import/core/sys/posix/poll.d import/core/sys/posix/poll.d
index 00e6a53..882a196 100644
--- import/core/sys/posix/poll.d
+++ import/core/sys/posix/poll.d
@@ -105,8 +105,10 @@ else version( OSX )
 
     int poll(pollfd*, nfds_t, int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
+    alias uint nfds_t;
+
     struct pollfd
     {
         int     fd;
@@ -114,8 +116,6 @@ else version( freebsd )
         short   revents;
     };
 
-    alias uint nfds_t;
-
     enum
     {
         POLLIN      = 0x0001,
diff --git import/core/sys/posix/pthread.d import/core/sys/posix/pthread.d
index 80cf53b..bf135ee 100644
--- import/core/sys/posix/pthread.d
+++ import/core/sys/posix/pthread.d
@@ -18,6 +18,8 @@ public import core.sys.posix.sys.types;
 public import core.sys.posix.sched;
 public import core.sys.posix.time;
 
+import core.stdc.stdint;
+
 extern (C):
 
 //
@@ -168,6 +170,46 @@ else version( OSX )
         PTHREAD_PROCESS_SHARED  = 1
     }
 }
+else version( FreeBSD )
+{
+    enum
+    {
+        PTHREAD_DETACHED            = 0x1,
+        PTHREAD_INHERIT_SCHED       = 0x4,
+        PTHREAD_NOFLOAT             = 0x8,
+
+        PTHREAD_CREATE_DETACHED     = PTHREAD_DETACHED,
+        PTHREAD_CREATE_JOINABLE     = 0,
+        PTHREAD_EXPLICIT_SCHED      = 0,
+    }
+
+    enum
+    {
+        PTHREAD_PROCESS_PRIVATE     = 0,
+        PTHREAD_PROCESS_SHARED      = 1,
+    }
+
+    enum
+    {
+        PTHREAD_CANCEL_ENABLE       = 0,
+        PTHREAD_CANCEL_DISABLE      = 1,
+        PTHREAD_CANCEL_DEFERRED     = 0,
+        PTHREAD_CANCEL_ASYNCHRONOUS = 2,
+    }
+
+    enum PTHREAD_CANCELED = cast(void*) -1;
+
+    enum PTHREAD_NEEDS_INIT = 0;
+    enum PTHREAD_DONE_INIT  = 1;
+
+    //enum PTHREAD_ONCE_INIT = { PTHREAD_NEEDS_INIT, null };
+
+    enum PTHREAD_MUTEX_INITIALIZER              = null;
+    enum PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP  = null;
+    enum PTHREAD_COND_INITIALIZER               = null;
+    enum PTHREAD_RWLOCK_INITIALIZER             = null;
+}
+
 
 int pthread_atfork(void function(), void function(), void function());
 int pthread_attr_destroy(pthread_attr_t*);
@@ -243,6 +285,33 @@ else version( OSX )
         }
     }
 }
+else version( FreeBSD )
+{
+    alias void function(void*) _pthread_cleanup_routine;
+
+    struct _pthread_cleanup_info
+    {
+        uintptr_t[8]    pthread_cleanup_pad;
+    }
+
+    struct pthread_cleanup
+    {
+        _pthread_cleanup_info __cleanup_info__ = void;
+
+        void push()( _pthread_cleanup_routine cleanup_routine, void* cleanup_arg )
+        {
+            __pthread_cleanup_push_imp( cleanup_routine, cleanup_arg, &__cleanup_info__ );
+        }
+
+        void pop()( int execute )
+        {
+            __pthread_cleanup_pop_imp( execute );
+        }
+    }
+
+    void __pthread_cleanup_push_imp(_pthread_cleanup_routine, void*, _pthread_cleanup_info*);
+    void __pthread_cleanup_pop_imp(int);
+}
 else
 {
     void pthread_cleanup_push(void function(void*), void*);
@@ -315,6 +384,18 @@ version( linux )
     int pthread_barrierattr_init(pthread_barrierattr_t*);
     int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
 }
+else version( FreeBSD )
+{
+    enum PTHREAD_BARRIER_SERIAL_THREAD = -1;
+
+    int pthread_barrier_destroy(pthread_barrier_t*);
+    int pthread_barrier_init(pthread_barrier_t*, in pthread_barrierattr_t*, uint);
+    int pthread_barrier_wait(pthread_barrier_t*);
+    int pthread_barrierattr_destroy(pthread_barrierattr_t*);
+    int pthread_barrierattr_getpshared(in pthread_barrierattr_t*, int*);
+    int pthread_barrierattr_init(pthread_barrierattr_t*);
+    int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
+}
 
 //
 // Clock (CS)
@@ -343,6 +424,14 @@ version( linux )
     int pthread_spin_trylock(pthread_spinlock_t*);
     int pthread_spin_unlock(pthread_spinlock_t*);
 }
+else version( FreeBSD )
+{
+    int pthread_spin_init(pthread_spinlock_t*, int);
+    int pthread_spin_destroy(pthread_spinlock_t*);
+    int pthread_spin_lock(pthread_spinlock_t*);
+    int pthread_spin_trylock(pthread_spinlock_t*);
+    int pthread_spin_unlock(pthread_spinlock_t*);
+}
 
 //
 // XOpen (XSI)
@@ -389,7 +478,7 @@ else version( OSX )
     int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
     int pthread_setconcurrency(int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum
     {
@@ -420,6 +509,10 @@ version( linux )
 {
     int pthread_getcpuclockid(pthread_t, clockid_t*);
 }
+else version( FreeBSD )
+{
+    int pthread_getcpuclockid(pthread_t, clockid_t*);
+}
 
 //
 // Timeouts (TMO)
@@ -442,6 +535,12 @@ else version( OSX )
     int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
     int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
 }
+else version( FreeBSD )
+{
+    int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
+    int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
+    int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
+}
 
 //
 // Priority (TPI|TPP)
@@ -513,7 +612,7 @@ else version( OSX )
     int pthread_setschedparam(pthread_t, int, in sched_param*);
     //int pthread_setschedprio(pthread_t, int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum
     {
@@ -562,7 +661,7 @@ else version( OSX )
     int pthread_attr_setstackaddr(pthread_attr_t*, void*);
     int pthread_attr_setstacksize(pthread_attr_t*, size_t);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
     int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
@@ -583,3 +682,12 @@ int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
 int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*);
 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
 */
+version( FreeBSD )
+{
+    int pthread_condattr_getpshared(in pthread_condattr_t*, int*);
+    int pthread_condattr_setpshared(pthread_condattr_t*, int);
+    int pthread_mutexattr_getpshared(in pthread_mutexattr_t*, int*);
+    int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
+    int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*);
+    int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
+}
diff --git import/core/sys/posix/pwd.d import/core/sys/posix/pwd.d
index 7386ee6..19b6f9a 100644
--- import/core/sys/posix/pwd.d
+++ import/core/sys/posix/pwd.d
@@ -64,7 +64,7 @@ else version( OSX )
         time_t  pw_expire;
     }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct passwd
     {
@@ -103,7 +103,7 @@ else version( OSX )
     int getpwnam_r(in char*, passwd*, char*, size_t, passwd**);
     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int getpwnam_r(in char*, passwd*, char*, size_t, passwd**);
     int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
@@ -129,7 +129,7 @@ else version ( OSX )
     passwd* getpwent();
     void    setpwent();
 }
-else version ( freebsd )
+else version ( FreeBSD )
 {
     void    endpwent();
     passwd* getpwent();
diff --git import/core/sys/posix/sched.d import/core/sys/posix/sched.d
index 32d8618..3c62cfc 100644
--- import/core/sys/posix/sched.d
+++ import/core/sys/posix/sched.d
@@ -70,7 +70,7 @@ else version( OSX )
         byte[__PTHREAD_MUTEX_SIZE__]    __opaque;
     }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct sched_param
     {
@@ -80,7 +80,6 @@ else version( freebsd )
     enum SCHED_FIFO     = 1;
     enum SCHED_OTHER    = 2;
     enum SCHED_RR       = 3;
-    //SCHED_SPORADIC (SS|TSP)
 }
 
 int sched_getparam(pid_t, sched_param*);
@@ -103,7 +102,7 @@ else version( OSX )
 {
     int sched_yield();
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int sched_yield();
 }
@@ -129,7 +128,7 @@ else version( OSX )
     int sched_get_priority_max(int);
     //int sched_rr_get_interval(pid_t, timespec*); // FIXME: unavailable?
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int sched_get_priority_min(int);
     int sched_get_priority_max(int);
diff --git import/core/sys/posix/semaphore.d import/core/sys/posix/semaphore.d
index 4efc793..9caec53 100644
--- import/core/sys/posix/semaphore.d
+++ import/core/sys/posix/semaphore.d
@@ -61,11 +61,8 @@ else version( OSX )
 
     enum SEM_FAILED = cast(sem_t*) null;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    enum SEM_MAGIC  = 0x09fa4012;
-    enum SEM_USER   = 0;
-
     alias void* sem_t;
 
     enum SEM_FAILED = cast(sem_t*) null;
@@ -96,7 +93,7 @@ else version( OSX )
 {
     int sem_timedwait(sem_t*, in timespec*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int sem_timedwait(sem_t*, in timespec*);
 }
diff --git import/core/sys/posix/setjmp.d import/core/sys/posix/setjmp.d
index 6b44cba..22dcef7 100644
--- import/core/sys/posix/setjmp.d
+++ import/core/sys/posix/setjmp.d
@@ -73,6 +73,31 @@ version( linux )
     alias _setjmp setjmp; // see XOpen block
     void longjmp(jmp_buf, int);
 }
+else version( FreeBSD )
+{
+    // <machine/setjmp.h>
+    version( X86 )
+    {
+        enum _JBLEN = 11;
+        struct _jmp_buf { int[_JBLEN + 1] _jb; }
+    }
+    else version( X86_64)
+    {
+        enum _JBLEN = 12;
+        struct _jmp_buf { c_long[_JBLEN] _jb; }
+    }
+    else version( SPARC )
+    {
+        enum _JBLEN = 5;
+        struct _jmp_buf { c_long[_JBLEN + 1] _jb; }
+    }
+    else
+        static assert(0);
+    alias _jmp_buf[1] jmp_buf;
+
+    int  setjmp(jmp_buf);
+    void longjmp(jmp_buf, int);
+}
 
 //
 // C Extension (CX)
@@ -92,6 +117,34 @@ version( linux )
     alias __sigsetjmp sigsetjmp;
     void siglongjmp(sigjmp_buf, int);
 }
+else version( FreeBSD )
+{
+    // <machine/setjmp.h>
+    version( X86 )
+    {
+        struct _sigjmp_buf { int[_JBLEN + 1] _ssjb; }
+    }
+    else version( X86_64)
+    {
+        struct _sigjmp_buf { c_long[_JBLEN] _sjb; }
+    }
+    else version( SPARC )
+    {
+        enum _JBLEN         = 5;
+        enum _JB_FP         = 0;
+        enum _JB_PC         = 1;
+        enum _JB_SP         = 2;
+        enum _JB_SIGMASK    = 3;
+        enum _JB_SIGFLAG    = 5;
+        struct _sigjmp_buf { c_long[_JBLEN + 1] _sjb; }
+    }
+    else
+        static assert(0);
+    alias _sigjmp_buf[1] sigjmp_buf;
+
+    int  sigsetjmp(sigjmp_buf);
+    void siglongjmp(sigjmp_buf, int);
+}
 
 //
 // XOpen (XSI)
@@ -106,3 +159,8 @@ version( linux )
     int  _setjmp(jmp_buf);
     void _longjmp(jmp_buf, int);
 }
+else version( FreeBSD )
+{
+    int  _setjmp(jmp_buf);
+    void _longjmp(jmp_buf, int);
+}
diff --git import/core/sys/posix/signal.d import/core/sys/posix/signal.d
index e23713a..c188b4c 100644
--- import/core/sys/posix/signal.d
+++ import/core/sys/posix/signal.d
@@ -153,7 +153,7 @@ else version( OSX )
     enum SIGUSR2    = 31;
     enum SIGURG     = 16;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     //SIGABRT (defined in core.stdc.signal)
     enum SIGALRM    = 14;
@@ -178,25 +178,41 @@ else version( freebsd )
     enum SIGURG     = 16;
 }
 
-struct sigaction_t
+version( FreeBSD )
 {
-    static if( true /* __USE_POSIX199309 */ )
+    struct sigaction_t
     {
         union
         {
             sigfn_t     sa_handler;
             sigactfn_t  sa_sigaction;
         }
+        int      sa_flags;
+        sigset_t sa_mask;
     }
-    else
+}
+else
+{
+    struct sigaction_t
     {
-        sigfn_t     sa_handler;
-    }
-    sigset_t        sa_mask;
-    int             sa_flags;
+        static if( true /* __USE_POSIX199309 */ )
+        {
+            union
+            {
+                sigfn_t     sa_handler;
+                sigactfn_t  sa_sigaction;
+            }
+        }
+        else
+        {
+            sigfn_t     sa_handler;
+        }
+        sigset_t        sa_mask;
+        int             sa_flags;
 
-    version( OSX ) {} else {
-    void function() sa_restorer;
+        version( OSX ) {} else {
+        void function() sa_restorer;
+        }
     }
 }
 
@@ -433,7 +449,7 @@ else version( OSX )
     int sigsuspend(in sigset_t*);
     int sigwait(in sigset_t*, int*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct sigset_t
     {
@@ -484,7 +500,7 @@ else version( freebsd )
     }
 
     int kill(pid_t, int);
-    int sigaction(int, in sigaction_t*, sigaction_t);
+    int sigaction(int, in sigaction_t*, sigaction_t*);
     int sigaddset(sigset_t*, int);
     int sigdelset(sigset_t*, int);
     int sigemptyset(sigset_t *);
@@ -806,6 +822,125 @@ else version( OSX )
     int sigpause(int);
     int sigrelse(int);
 }
+else version( FreeBSD )
+{
+    // No SIGPOLL on *BSD
+    enum SIGPROF        = 27;
+    enum SIGSYS         = 12;
+    enum SIGTRAP        = 5;
+    enum SIGVTALRM      = 26;
+    enum SIGXCPU        = 24;
+    enum SIGXFSZ        = 25;
+
+    enum
+    {
+        SA_ONSTACK      = 0x0001,
+        SA_RESTART      = 0x0002,
+        SA_RESETHAND    = 0x0004,
+        SA_NODEFER      = 0x0010,
+        SA_NOCLDWAIT    = 0x0020,
+        SA_SIGINFO      = 0x0040,
+    }
+
+    enum
+    {
+        SS_ONSTACK = 0x0001,
+        SS_DISABLE = 0x0004,
+    }
+
+    enum MINSIGSTKSZ = 512 * 4;
+    enum SIGSTKSZ    = (MINSIGSTKSZ + 32768);
+;
+    //ucontext_t (defined in core.sys.posix.ucontext)
+    //mcontext_t (defined in core.sys.posix.ucontext)
+
+    struct stack_t
+    {
+        void*   ss_sp;
+        size_t  ss_size;
+        int     ss_flags;
+    }
+
+    struct sigstack
+    {
+        void*   ss_sp;
+        int     ss_onstack;
+    }
+
+    enum
+    {
+        ILL_ILLOPC = 1,
+        ILL_ILLOPN,
+        ILL_ILLADR,
+        ILL_ILLTRP,
+        ILL_PRVOPC,
+        ILL_PRVREG,
+        ILL_COPROC,
+        ILL_BADSTK,
+    }
+
+    enum
+    {
+        BUS_ADRALN = 1,
+        BUS_ADRERR,
+        BUS_OBJERR,
+    }
+
+    enum
+    {
+        SEGV_MAPERR = 1,
+        SEGV_ACCERR,
+    }
+
+    enum
+    {
+        FPE_INTOVF = 1,
+        FPE_INTDIV,
+        FPE_FLTDIV,
+        FPE_FLTOVF,
+        FPE_FLTUND,
+        FPE_FLTRES,
+        FPE_FLTINV,
+        FPE_FLTSUB,
+    }
+
+    enum
+    {
+        TRAP_BRKPT = 1,
+        TRAP_TRACE,
+    }
+
+    enum
+    {
+        CLD_EXITED = 1,
+        CLD_KILLED,
+        CLD_DUMPED,
+        CLD_TRAPPED,
+        CLD_STOPPED,
+        CLD_CONTINUED,
+    }
+
+    enum
+    {
+        POLL_IN = 1,
+        POLL_OUT,
+        POLL_MSG,
+        POLL_ERR,
+        POLL_PRI,
+        POLL_HUP,
+    }
+
+    //sigfn_t bsd_signal(int sig, sigfn_t func);
+    sigfn_t sigset(int sig, sigfn_t func);
+
+    int killpg(pid_t, int);
+    int sigaltstack(in stack_t*, stack_t*);
+    int sighold(int);
+    int sigignore(int);
+    int siginterrupt(int, int);
+    int sigpause(int);
+    int sigrelse(int);
+}
 
 //
 // Timer (TMR)
@@ -837,7 +972,7 @@ else version( OSX )
         c_long  tv_nsec;
     }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct timespec
     {
@@ -900,7 +1035,7 @@ version( linux )
     int sigtimedwait(in sigset_t*, siginfo_t*, in timespec*);
     int sigwaitinfo(in sigset_t*, siginfo_t*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct sigevent
     {
@@ -941,7 +1076,7 @@ else version( OSX )
     int pthread_kill(pthread_t, int);
     int pthread_sigmask(int, in sigset_t*, sigset_t*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int pthread_kill(pthread_t, int);
     int pthread_sigmask(int, in sigset_t*, sigset_t*);
diff --git import/core/sys/posix/stdlib.d import/core/sys/posix/stdlib.d
index 5a0c812..a5df25d 100644
--- import/core/sys/posix/stdlib.d
+++ import/core/sys/posix/stdlib.d
@@ -83,6 +83,10 @@ version( linux )
 {
     int posix_memalign(void**, size_t, size_t);
 }
+else version( FreeBSD )
+{
+    int posix_memalign(void**, size_t, size_t);
+}
 
 //
 // C Extension (CX)
@@ -106,7 +110,7 @@ else version( OSX )
 
     void* valloc(size_t); // LEGACY non-standard
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int setenv(in char*, in char*, int);
     int unsetenv(in char*);
@@ -129,7 +133,7 @@ else version( OSX )
 {
     int rand_r(uint*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int rand_r(uint*);
 }
@@ -268,7 +272,7 @@ else version( OSX )
     void   srandom(uint);
     int    unlockpt(int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     //WNOHANG     (defined in core.sys.posix.sys.wait)
     //WUNTRACED   (defined in core.sys.posix.sys.wait)
diff --git import/core/sys/posix/sys/ipc.d import/core/sys/posix/sys/ipc.d
index da1dc5a..ffe16ab 100644
--- import/core/sys/posix/sys/ipc.d
+++ import/core/sys/posix/sys/ipc.d
@@ -77,9 +77,9 @@ else version( OSX )
 {
 
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    struct ipc_perm
+    struct ipc_perm_old // <= FreeBSD7
     {
         ushort cuid;
         ushort cguid;
@@ -90,6 +90,17 @@ else version( freebsd )
         key_t key;
     }
 
+    struct ipc_perm
+    {
+        uid_t   cuid;
+        gid_t   cgid;
+        uid_t   uid;
+        gid_t   gid;
+        mode_t  mode;
+        ushort  seq;
+        key_t   key;
+    }
+
     enum IPC_CREAT      = 01000;
     enum IPC_EXCL       = 02000;
     enum IPC_NOWAIT     = 04000;
diff --git import/core/sys/posix/sys/mman.d import/core/sys/posix/sys/mman.d
index 55eb7bd..cea38a9 100644
--- import/core/sys/posix/sys/mman.d
+++ import/core/sys/posix/sys/mman.d
@@ -53,7 +53,7 @@ else version( OSX )
     enum POSIX_MADV_WILLNEED    = 3;
     enum POSIX_MADV_DONTNEED    = 4;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum POSIX_MADV_NORMAL      = 0;
     enum POSIX_MADV_RANDOM      = 1;
@@ -86,7 +86,7 @@ else version( OSX )
     enum PROT_WRITE     = 0x02;
     enum PROT_EXEC      = 0x04;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum PROT_NONE      = 0x00;
     enum PROT_READ      = 0x01;
@@ -122,7 +122,7 @@ else version( OSX )
     void* mmap(void*, size_t, int, int, int, off_t);
     int   munmap(void*, size_t);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     void* mmap(void*, size_t, int, int, int, off_t);
     int   munmap(void*, size_t);
@@ -177,7 +177,7 @@ else version( OSX )
 
     int msync(void*, size_t, int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum MAP_SHARED     = 0x0001;
     enum MAP_PRIVATE    = 0x0002;
@@ -221,7 +221,7 @@ else version( OSX )
     int mlockall(int);
     int munlockall();
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum MCL_CURRENT    = 0x0001;
     enum MCL_FUTURE     = 0x0002;
@@ -248,7 +248,7 @@ else version( OSX )
     int mlock(in void*, size_t);
     int munlock(in void*, size_t);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int mlock(in void*, size_t);
     int munlock(in void*, size_t);
@@ -265,7 +265,7 @@ version( OSX )
 {
     int mprotect(void*, size_t, int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int mprotect(void*, size_t, int);
 }
@@ -288,7 +288,7 @@ else version( OSX )
     int shm_open(in char*, int, mode_t);
     int shm_unlink(in char*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     int shm_open(in char*, int, mode_t);
     int shm_unlink(in char*);
diff --git import/core/sys/posix/sys/select.d import/core/sys/posix/sys/select.d
index 0214e54..9a8b984 100644
--- import/core/sys/posix/sys/select.d
+++ import/core/sys/posix/sys/select.d
@@ -164,17 +164,52 @@ else version( OSX )
     int pselect(int, fd_set*, fd_set*, fd_set*, in timespec*, in sigset_t*);
     int select(int, fd_set*, fd_set*, fd_set*, timeval*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     private
     {
-        enum uint _NFDBITS   = c_ulong.sizeof * 8;
+        alias c_ulong __fd_mask;
+        enum _NFDBITS = __fd_mask.sizeof * 8;
     }
 
     enum uint FD_SETSIZE = 1024;
 
     struct fd_set
     {
-        c_ulong fds_bits[(FD_SETSIZE + (_NFDBITS - 1)) / _NFDBITS];
+        __fd_mask __fds_bits[(FD_SETSIZE + (_NFDBITS - 1)) / _NFDBITS];
     }
+
+    extern (D) __fd_mask __fdset_mask(uint n)
+    {
+        return cast(__fd_mask) 1 << (n % _NFDBITS);
+    }
+
+    extern (D) void FD_CLR( int n, fd_set* p )
+    {
+        p.__fds_bits[n / _NFDBITS] &= ~__fdset_mask(n);
+    }
+
+    extern (D) bool FD_ISSET( int n, fd_set* p )
+    {
+        return (p.__fds_bits[n / _NFDBITS] & __fdset_mask(n)) != 0;
+    }
+
+    extern (D) void FD_SET( int n, fd_set* p )
+    {
+        p.__fds_bits[n / _NFDBITS] |= __fdset_mask(n);
+    }
+
+    extern (D) void FD_ZERO( fd_set* p )
+    {
+        fd_set *_p;
+        size_t _n;
+
+        _p = p;
+        _n = (FD_SETSIZE + (_NFDBITS - 1)) / _NFDBITS;
+        while (_n > 0)
+            _p.__fds_bits[--_n] = 0;
+    }
+
+    int pselect(int, fd_set*, fd_set*, fd_set*, in timespec*, in sigset_t*);
+    int select(int, fd_set*, fd_set*, fd_set*, timeval*);
 }
diff --git import/core/sys/posix/sys/shm.d import/core/sys/posix/sys/shm.d
index 018f685..e606dce 100644
--- import/core/sys/posix/sys/shm.d
+++ import/core/sys/posix/sys/shm.d
@@ -80,7 +80,7 @@ version( linux )
     int   shmdt(in void*);
     int   shmget(key_t, size_t, int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum SHM_RDONLY     = 010000;
     enum SHM_RND        = 020000;
@@ -88,21 +88,29 @@ else version( freebsd )
 
     alias c_ulong   shmatt_t;
 
+    struct shmid_ds_old // <= FreeBSD7
+    {
+        ipc_perm_old    shm_perm;
+        int             shm_segsz;
+        pid_t           shm_lpid;
+        pid_t           shm_cpid;
+        short           shm_nattch;
+        time_t          shm_atime;
+        time_t          shm_dtime;
+        time_t          shm_ctime;
+        void*           shm_internal;
+    }
+
     struct shmid_ds
     {
         ipc_perm    shm_perm;
-        size_t      shm_segsz;
+        int         shm_segsz;
+        pid_t       shm_lpid;
+        pid_t       shm_cpid;
+        short       shm_nattch;
         time_t      shm_atime;
-        c_ulong     __unused1;
         time_t      shm_dtime;
-        c_ulong     __unused2;
         time_t      shm_ctime;
-        c_ulong     __unused3;
-        pid_t       shm_cpid;
-        pid_t       shm_lpid;
-        shmatt_t    shm_nattch;
-        c_ulong     __unused4;
-        c_ulong     __unused5;
     }
 
     void* shmat(int, in void*, int);
diff --git import/core/sys/posix/sys/socket.d import/core/sys/posix/sys/socket.d
index c95c33f..30ea4d2 100644
--- import/core/sys/posix/sys/socket.d
+++ import/core/sys/posix/sys/socket.d
@@ -436,7 +436,7 @@ else version( OSX )
     int     sockatmark(int);
     int     socketpair(int, int, int, int[2]);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     alias uint   socklen_t;
     alias ubyte  sa_family_t;
@@ -488,17 +488,37 @@ else version( freebsd )
         SCM_RIGHTS = 0x01
     }
 
-    /+
-    CMSG_DATA(cmsg)     ((unsigned char *)(cmsg) + \
-                         ALIGN(sizeof(struct cmsghdr)))
-    CMSG_NXTHDR(mhdr, cmsg) \
-                        (((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len) + \
-                         ALIGN(sizeof(struct cmsghdr)) > \
-                         (unsigned char *)(mhdr)->msg_control +(mhdr)->msg_controllen) ? \
-                         (struct cmsghdr *)0 /* NULL */ : \
-                         (struct cmsghdr *)((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len)))
-    CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
-    +/
+    private // <machine/param.h>
+    {
+        enum _ALIGNBYTES = /+c_int+/ int.sizeof - 1;
+        extern (D) size_t _ALIGN( size_t p ) { return (p + _ALIGNBYTES) & ~_ALIGNBYTES; }
+    }
+
+    extern (D) ubyte* CMSG_DATA( cmsghdr* cmsg )
+    {
+        return cast(ubyte*) cmsg + _ALIGN( cmsghdr.sizeof );
+    }
+
+    extern (D) cmsghdr* CMSG_NXTHDR( msghdr* mhdr, cmsghdr* cmsg )
+    {
+        if( cmsg == null )
+        {
+           return CMSG_FIRSTHDR( mhdr );
+        }
+        else
+        {
+            if( cast(ubyte*) cmsg + _ALIGN( cmsg.cmsg_len ) + _ALIGN( cmsghdr.sizeof ) > 
+                    cast(ubyte*) mhdr.msg_control + mhdr.msg_controllen )
+                return null;
+            else
+                return cast(cmsghdr*) (cast(ubyte*) cmsg + _ALIGN( cmsg.cmsg_len ));
+        }
+    }
+
+    extern (D) cmsghdr* CMSG_FIRSTHDR( msghdr* mhdr )
+    {
+        return mhdr.msg_controllen >= cmsghdr.sizeof ? cast(cmsghdr*) mhdr.msg_control : null;
+    }
 
     struct linger
     {
@@ -526,7 +546,7 @@ else version( freebsd )
         SO_DONTROUTE    = 0x0010,
         SO_ERROR        = 0x1007,
         SO_KEEPALIVE    = 0x0008,
-        SO_LINGER       = 0x1080,
+        SO_LINGER       = 0x0080,
         SO_OOBINLINE    = 0x0100,
         SO_RCVBUF       = 0x1002,
         SO_RCVLOWAT     = 0x1004,
@@ -585,7 +605,7 @@ else version( freebsd )
     int     shutdown(int, int);
     int     socket(int, int, int);
     int     sockatmark(int);
-    int     socketpair(int, int, int, int[2]);
+    int     socketpair(int, int, int, int*);
 }
 
 //
@@ -609,7 +629,7 @@ else version( OSX )
         AF_INET6    = 30
     }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum
     {
@@ -638,7 +658,7 @@ else version( OSX )
         SOCK_RAW    = 3
     }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum
     {
diff --git import/core/sys/posix/sys/stat.d import/core/sys/posix/sys/stat.d
index 8baeaa9..14ca776 100644
--- import/core/sys/posix/sys/stat.d
+++ import/core/sys/posix/sys/stat.d
@@ -250,33 +250,24 @@ else version( OSX )
     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 ); }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct stat_t
     {
-        dev_t   st_dev;
-        ino_t   st_ino;
-        mode_t  st_mode;
-        nlink_t st_nlink;
-        uid_t   st_uid;
-        gid_t   st_gid;
-        dev_t   st_rdev;
-
-        timespec st_atimespec;
-        timespec st_mtimespec;
-        timespec st_ctimespec;
-        time_t st_atime()
-        {
-            return st_atimespec.tv_sec;
-        }
-        time_t st_mtime()
-        {
-            return st_mtimespec.tv_sec;
-        }
-        time_t st_ctime()
-        {
-            return st_ctimespec.tv_sec;
-        }
+        dev_t       st_dev;
+        ino_t       st_ino;
+        mode_t      st_mode;
+        nlink_t     st_nlink;
+        uid_t       st_uid;
+        gid_t       st_gid;
+        dev_t       st_rdev;
+
+        time_t      st_atime;
+        c_long      __st_atimensec;
+        time_t      st_mtime;
+        c_long      __st_mtimensec;
+        time_t      st_ctime;
+        c_long      __st_ctimensec;
 
         off_t       st_size;
         blkcnt_t    st_blocks;
@@ -284,9 +275,11 @@ else version( freebsd )
         fflags_t    st_flags;
         uint        st_gen;
         int         st_lspare;
-        timespec    st_birthtimespec;
 
-        byte[16 - timespec.sizeof] padding;
+        time_t      st_birthtime;
+        c_long      st_birthtimensec;
+
+        ubyte[16 - timespec.sizeof] padding;
     }
 
     enum S_IRUSR    = 0000400;
@@ -410,7 +403,7 @@ else version( OSX )
 
     int mknod(in char*, mode_t, dev_t);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum S_IFMT     = 0170000;
     enum S_IFBLK    = 0060000;
diff --git import/core/sys/posix/sys/time.d import/core/sys/posix/sys/time.d
index b76ee43..be0f771 100644
--- import/core/sys/posix/sys/time.d
+++ import/core/sys/posix/sys/time.d
@@ -95,7 +95,7 @@ else version( OSX )
     int setitimer(int, in itimerval*, itimerval*);
     int utimes(in char*, in timeval[2]);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct timeval
     {
@@ -119,5 +119,5 @@ else version( freebsd )
     int getitimer(int, itimerval*);
     int gettimeofday(timeval*, timezone_t*); // timezone_t* is normally void*
     int setitimer(int, in itimerval*, itimerval*);
-    int utimes(in char*, in timeval[2]);
+    int utimes(in char*, in timeval*);
 }
diff --git import/core/sys/posix/sys/types.d import/core/sys/posix/sys/types.d
index 7e332ba..3969470 100644
--- import/core/sys/posix/sys/types.d
+++ import/core/sys/posix/sys/types.d
@@ -80,7 +80,7 @@ else version( OSX )
     //time_t (defined in core.stdc.time)
     alias uint      uid_t;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     alias long      blkcnt_t;
     alias uint      blksize_t;
@@ -139,9 +139,9 @@ else version( OSX )
     alias int   suseconds_t;
     alias uint  useconds_t;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    //clock_t
+    // clock_t (defined in core.stdc.time)
     alias ulong     fsblkcnt_t;
     alias ulong     fsfilcnt_t;
     alias long      id_t;
@@ -345,7 +345,7 @@ else version( OSX )
 
     alias _opaque_pthread_t* pthread_t;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     alias int lwpid_t;
 
@@ -384,7 +384,7 @@ version( linux )
         int __pshared;
     }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     alias void* pthread_barrier_t;
     alias void* pthread_barrierattr_t;
@@ -405,7 +405,7 @@ else version( OSX )
 {
     //struct pthread_spinlock_t;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     alias void* pthread_spinlock_t;
 }
diff --git import/core/sys/posix/sys/uio.d import/core/sys/posix/sys/uio.d
index d1da2c0..52aa348 100644
--- import/core/sys/posix/sys/uio.d
+++ import/core/sys/posix/sys/uio.d
@@ -57,7 +57,7 @@ else version( OSX )
     ssize_t readv(int, in iovec*, int);
     ssize_t writev(int, in iovec*, int);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct iovec
     {
diff --git import/core/sys/posix/sys/wait.d import/core/sys/posix/sys/wait.d
index 35bd373..031ce18 100644
--- import/core/sys/posix/sys/wait.d
+++ import/core/sys/posix/sys/wait.d
@@ -89,11 +89,10 @@ else version( OSX )
     extern (D) int  WSTOPSIG( int status )     { return status >> 8;                     }
     extern (D) int  WTERMSIG( int status )     { return _WSTATUS( status );              }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum WNOHANG        = 1;
     enum WUNTRACED      = 2;
-    enum WCONTINUED     = 4;
 
     private
     {
@@ -171,3 +170,11 @@ else version( OSX )
 
     int waitid(idtype_t, id_t, siginfo_t*, int);    
 }
+else version (FreeBSD)
+{
+    enum WSTOPPED       = WUNTRACED;
+    enum WCONTINUED     = 4;
+    enum WNOWAIT        = 8;
+
+    // http://www.freebsd.org/projects/c99/
+}
diff --git import/core/sys/posix/termios.d import/core/sys/posix/termios.d
index b197357..2183533 100644
--- import/core/sys/posix/termios.d
+++ import/core/sys/posix/termios.d
@@ -345,7 +345,7 @@ else version( linux )
     int     tcsendbreak(int, int);
     int     tcsetattr(int, int, in termios*);
 }
-else version ( freebsd )
+else version ( FreeBSD )
 {
     alias ubyte cc_t;
     alias uint  speed_t;
@@ -526,3 +526,37 @@ version( linux )
 
     pid_t   tcgetsid(int);
 }
+else version( FreeBSD )
+{
+    enum IXANY      = 0x00000800;
+
+    enum ONLCR      = 0x00000002;
+    enum OCRNL      = 0x00000010;
+    enum ONOCR      = 0x00000020;
+    enum ONLRET     = 0x00000040;
+    //enum OFILL
+    //enum NLDLY
+    //enum     NL0
+    //enum     NL1
+    //enum CRDLY
+    //enum     CR0
+    //enum     CR1
+    //enum     CR2
+    //enum     CR3
+    enum TABDLY     = 0x00000004;
+    enum     TAB0   = 0x00000000;
+    //enum     TAB1
+    //enum     TAB2
+    enum     TAB3   = 0x00000004;
+    //enum BSDLY
+    //enum     BS0
+    //enum     BS1
+    //enum VTDLY
+    //enum     VT0
+    //enum     VT1
+    //enum FFDLY
+    //enum     FF0
+    //enum     FF1
+
+    pid_t   tcgetsid(int);
+}
diff --git import/core/sys/posix/time.d import/core/sys/posix/time.d
index f821634..c1075e4 100644
--- import/core/sys/posix/time.d
+++ import/core/sys/posix/time.d
@@ -43,7 +43,7 @@ else version( OSX )
 {
     time_t timegm(tm*); // non-standard
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     time_t timegm(tm*); // non-standard
 }
@@ -156,10 +156,9 @@ else version( OSX )
 {
     int nanosleep(in timespec*, timespec*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
-    enum CLOCK_PROCESS_CPUTIME_ID   = 2; // (TMR|CPT)
-    enum CLOCK_THREAD_CPUTIME_ID    = 3; // (TMR|TCT)
+    enum CLOCK_THREAD_CPUTIME_ID    = 15;
 
     // NOTE: See above for why this is commented out.
     //
@@ -178,7 +177,7 @@ else version( freebsd )
     enum CLOCK_REALTIME     = 0;
     enum TIMER_ABSTIME      = 0x01;
 
-    //alias int clockid_t;
+    alias int clockid_t; // <sys/_types.h>
     alias int timer_t;
 
     int clock_getres(clockid_t, timespec*);
@@ -217,7 +216,7 @@ else version( OSX )
     tm*   gmtime_r(in time_t*, tm*);
     tm*   localtime_r(in time_t*, tm*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     char* asctime_r(in tm*, char*);
     char* ctime_r(in time_t*, char*);
@@ -255,8 +254,6 @@ else version( OSX )
 }
 else version( FreeBSD )
 {
-    extern __gshared c_long timezone;
-
     //tm*   getdate(in char*);
     char* strptime(in char*, in char*, tm*);
 }
diff --git import/core/sys/posix/ucontext.d import/core/sys/posix/ucontext.d
index f8663f0..f30ee44 100644
--- import/core/sys/posix/ucontext.d
+++ import/core/sys/posix/ucontext.d
@@ -140,6 +140,65 @@ version( linux )
         }
     }
 }
+else version( FreeBSD )
+{
+    // <machine/ucontext.h>
+    version( X86 )
+    {
+        alias int __register_t;
+
+        struct mcontext_t
+        {
+            __register_t    mc_onstack;
+            __register_t    mc_gs;
+            __register_t    mc_fs;
+            __register_t    mc_es;
+            __register_t    mc_ds;
+            __register_t    mc_edi;
+            __register_t    mc_esi;
+            __register_t    mc_ebp;
+            __register_t    mc_isp;
+            __register_t    mc_ebx;
+            __register_t    mc_edx;
+            __register_t    mc_ecx;
+            __register_t    mc_eax;
+            __register_t    mc_trapno;
+            __register_t    mc_err;
+            __register_t    mc_eip;
+            __register_t    mc_cs;
+            __register_t    mc_eflags;
+            __register_t    mc_esp;
+            __register_t    mc_ss;
+
+            int             mc_len;
+            int             mc_fpformat;
+            int             mc_ownedfp;
+            int[1]          mc_spare1;
+
+            align(16)
+            int[128]        mc_fpstate;
+
+            __register_t    mc_fsbase;
+            __register_t    mc_gsbase;
+
+            int[6]          mc_spare2;
+        }
+    }
+
+    // <ucontext.h>
+    enum UCF_SWAPPED = 0x00000001;
+
+    struct ucontext_t
+    {
+        sigset_t        uc_sigmask;
+        mcontext_t      uc_mcontext;
+
+        ucontext_t*     uc_link;
+        stack_t         uc_stack;
+        int             uc_flags;
+        int[4]          __spare__;
+    }
+}
 
 //
 // Obsolescent (OB)
diff --git import/core/sys/posix/unistd.d import/core/sys/posix/unistd.d
index da8501c..c472b3d 100644
--- import/core/sys/posix/unistd.d
+++ import/core/sys/posix/unistd.d
@@ -107,7 +107,7 @@ version( linux )
     int   ftruncate(int, off_t);
   }
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     off_t lseek(int, off_t, int);
     int   ftruncate(int, off_t);
@@ -445,7 +445,7 @@ else version( OSX )
     enum F_TLOCK    = 2;
     enum F_TEST     = 3;
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     enum F_OK       = 0;
     enum R_OK       = 0x04;
@@ -473,6 +473,10 @@ else version( OSX )
 {
     int fsync(int);
 }
+else version( FreeBSD )
+{
+    int fsync(int);
+}
 
 //
 // Synchronized I/O (SIO)
@@ -586,7 +590,7 @@ else version( OSX )
     int        usleep(useconds_t);
     pid_t      vfork();
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     char*      crypt(in char*, in char*);
     //char*      ctermid(char*);
diff --git import/core/sys/posix/utime.d import/core/sys/posix/utime.d
index 3ee301a..260367f 100644
--- import/core/sys/posix/utime.d
+++ import/core/sys/posix/utime.d
@@ -51,7 +51,7 @@ else version( OSX )
 
     int utime(in char*, in utimbuf*);
 }
-else version( freebsd )
+else version( FreeBSD )
 {
     struct utimbuf
     {
diff --git src/rt/critical.c src/rt/critical.c
index cdbf52c..4a3f2db 100644
--- src/rt/critical.c
+++ src/rt/critical.c
@@ -82,7 +82,7 @@ void _STD_critical_term()
 
 /* ================================= linux ============================ */
 
-#if linux || __APPLE__
+#if linux || __APPLE__ || __FreeBSD__
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -90,8 +90,10 @@ void _STD_critical_term()
 
 // PTHREAD_MUTEX_RECURSIVE is the "standard" symbol,
 // while the _NP version is specific to Linux
-#ifndef PTHREAD_MUTEX_RECURSIVE
+#if linux
+#  ifndef PTHREAD_MUTEX_RECURSIVE
 #    define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
+#  endif
 #endif
 
 /******************************************
diff --git src/rt/dmain2.d src/rt/dmain2.d
index b6803b8..b931ecf 100644
--- src/rt/dmain2.d
+++ src/rt/dmain2.d
@@ -291,6 +291,22 @@ extern (C) int main(int argc, char **argv)
         __osx_stack_end = cast(void*)&argv;
     }
 
+    version (FreeBSD) version (D_InlineAsm_X86)
+    {
+        /*
+         * FreeBSD/i386 sets the FPU precision mode to 53 bit double.
+         * Make it 64 bit extended.
+         */
+        ushort fpucw;
+        asm
+        {
+            fstsw   fpucw;
+            or      fpucw, 0b11_00_111111; // 11: use 64 bit extended-precision
+                                           // 111111: mask all FP exceptions
+            fldcw   fpucw;
+        }
+    }
+
     version (Posix)
     {
         _STI_monitor_staticctor();
diff --git src/rt/memory.d src/rt/memory.d
index 4e5723c..568acb4 100644
--- src/rt/memory.d
+++ src/rt/memory.d
@@ -26,12 +26,7 @@ private
     }
     version( FreeBSD )
     {
-        version = SimpleLibcStackEnd;
-
-        version( SimpleLibcStackEnd )
-        {
-            extern (C) extern __gshared void* __libc_stack_end;
-        }
+        extern (C) int sysctlbyname( const(char)*, void*, size_t*, void*, size_t );
     }
     version( Solaris )
     {
@@ -87,7 +82,14 @@ extern (C) void* rt_stackBottom()
     }
     else version( FreeBSD )
     {
-        return __libc_stack_end;
+        static void* kern_usrstack;
+
+        if( kern_usrstack == kern_usrstack.init )
+        {
+            size_t len = kern_usrstack.sizeof;
+            sysctlbyname( "kern.usrstack", &kern_usrstack, &len, null, 0 );
+        }
+        return kern_usrstack;
     }
     else version( Solaris )
     {
diff --git src/rt/monitor.c src/rt/monitor.c
index 63e5d0d..4ab25c3 100644
--- src/rt/monitor.c
+++ src/rt/monitor.c
@@ -15,7 +15,7 @@
 #include <assert.h>
 
 #if _WIN32
-#elif linux || __APPLE__
+#elif linux || __APPLE__ || __FreeBSD__
 #define USE_PTHREADS    1
 #else
 #endif
@@ -130,8 +130,10 @@ void _d_monitor_unlock(Object *h)
 
 #if USE_PTHREADS
 
-#ifndef PTHREAD_MUTEX_RECURSIVE
+#ifdef linux
+#  ifndef PTHREAD_MUTEX_RECURSIVE
 #    define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
+#  endif
 #endif
 
 // Includes attribute fixes from David Friedman's GDC port
