diff --git a/Unix/base/user.c b/Unix/base/user.c index 911cee38e..09b78aac0 100644 --- a/Unix/base/user.c +++ b/Unix/base/user.c @@ -73,7 +73,7 @@ static int GetGroupName( static int _authCallback( int numMessages, -#if defined(CONFIG_OS_LINUX) || defined(CONFIG_OS_DARWIN) || defined(CONFIG_OS_BSD) +#if defined(CONFIG_OS_LINUX) || defined(CONFIG_OS_DARWIN) || defined(CONFIG_OS_BSD) || defined(CONFIG_OS_FREEBSD) const struct pam_message** messages, #else struct pam_message** messages, @@ -766,7 +766,7 @@ MI_Boolean ValidateGssCredentials(const char *credFilePath, const char *krb5KeyT } -#if defined(CONFIG_OS_LINUX) || defined(CONFIG_OS_DARWIN) +#if defined(CONFIG_OS_LINUX) || defined(CONFIG_OS_DARWIN) || defined(CONFIG_OS_FREEBSD) static int _SearchPermissionGroups(PermissionGroups *list, gid_t gid) { PermissionGroup *group = list->head; @@ -829,7 +829,7 @@ int IsUserAuthorized(const char *user, gid_t gid) int ngroups = MAX_GROUPS; int i; -#if defined(CONFIG_OS_LINUX) || defined(CONFIG_OS_DARWIN) +#if defined(CONFIG_OS_LINUX) || defined(CONFIG_OS_DARWIN) || defined(CONFIG_OS_FREEBSD) // get list of groups that user belongs to if (getgrouplist(user, gid, groups, &ngroups) == -1) { diff --git a/Unix/buildtool b/Unix/buildtool index c3e48796a..b639a840e 100755 --- a/Unix/buildtool +++ b/Unix/buildtool @@ -273,14 +273,21 @@ if [ -z "$target" ]; then compiler=GNU distro=`lsb_release -i | awk -F":" '{ print $2 }'` distro_version=`lsb_release -r | awk -F":" '{ print $2 }'` - ;; + ;; arm*:Linux:*) os=LINUX arch=ARM compiler=GNU distro=`lsb_release -i | awk -F":" '{ print $2 }'` distro_version=`lsb_release -r | awk -F":" '{ print $2 }'` - ;; + ;; + amd64:FreeBSD:*:*) + os=FREEBSD + arch=X86_64 + compiler=GNU + distro=`uname -s` + distro_version=`sysctl -n kern.osrelease | cut -f1 -d'-'` + ;; *) echo "$0: error: unsupported platform: $__m:$__s:$__r:$__v" exit 1 @@ -329,7 +336,7 @@ case "$platform" in compiler_minor_version=`echo $compiler_version | awk -F' ' '{ print $5}' | awk -F"." '{ print $2}'` compiler_revision=`echo $compiler_version | awk -F' ' '{ print $5}' | awk -F"." '{ print $3}'` ;; - DARWIN_IX86_GNU) + DARWIN_IX86_GNU|FREEBSD_X86_64_GNU) compiler_version=`clang --version | awk -F" " 'match($0, /version [0-9]*\.[0-9]*\.[0-9]*/){ print $4 }'` compiler_major_version=`echo $compiler_version | awk -F'.' '{ print $1}'` compiler_minor_version=`echo $compiler_version | awk -F'.' '{ print $2}'` @@ -438,7 +445,7 @@ if [ "$arg1" = "longhostname" ]; then MONTAVISTA*) hostname ;; - NETBSD*) + NETBSD*|FREEBSD*) hostname ;; DARWIN*) @@ -594,6 +601,9 @@ if [ "$arg1" = "cc" ]; then DARWIN_IX86_GNU) echo clang ;; + FREEBSD_X86_64_GNU) + echo clang + ;; esac exit @@ -635,6 +645,9 @@ if [ "$arg1" = "cxx" ]; then DARWIN_IX86_GNU) echo clang++ ;; + FREEBSD_X86_64_GNU) + echo clang++ + ;; esac exit @@ -714,6 +727,9 @@ if [ "$arg1" = "size" ]; then DARWIN_IX86_GNU) echo size ;; + FREEBSD_X86_64_GNU) + echo size + ;; *) echo "echo \'Unsuported platform: $platform\'" exit 1 @@ -927,6 +943,20 @@ if [ "$arg1" = "cflags" -o "$arg1" = "cxxflags" ]; then r="$r -fstack-protector-all" r="$r -DGSS_USE_IOV=1" ;; + FREEBSD_X86_64_GNU) + test -z "$debug_opt" && r="$r -O2" + test -n "$pic_opt" && r="$r -fPIC" + ## treat warnings as errors. + test -n "$errwarn_opt" && r="$r -Werror" + r="$r -Wall" + r="$r -I/usr/local/include" + r="$r -Dfreebsd -D__BSD_VISIBLE=1 -DPAL_NO_ALLOCA=1" + r="$r -fstack-protector-all" + r="$r -fno-strict-aliasing" + r="$r -D_GNU_SOURCE" + r="$r -D_XOPEN_SOURCE=700" + r="$r -DGSS_USE_IOV=1" + ;; esac echo $r @@ -984,6 +1014,9 @@ if [ "$arg1" = "cshlibflags" -o "$arg1" = "cxxshlibflags" ]; then ;; NETBSD_IX86_GNU) r="$r -shared" + ;; + FREEBSD_X86_64_GNU) + r="$r -shared -fuse-ld=lld" test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt" ;; SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO) @@ -1104,7 +1137,8 @@ if [ "$arg1" = "cprogflags" -o "$arg1" = "cxxprogflags" ]; then MONTAVISTA_IX86_GNU) test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt" ;; - NETBSD_IX86_GNU) + NETBSD_IX86_GNU|FREEBSD_X86_64_GNU) + r="$r -fuse-ld=lld" test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt" ;; SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO) @@ -1231,7 +1265,7 @@ if [ "$arg1" = "syslibs" ]; then MONTAVISTA_IX86_GNU) r="-lpthread -ldl -lpam" ;; - NETBSD_IX86_GNU) + NETBSD_IX86_GNU|FREEBSD_X86_64_GNU) r="-lpthread -ldl -lpam" ;; SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO) @@ -1285,7 +1319,7 @@ if [ "$arg1" = "libpath" ]; then r="$r -Wl,-rpath=$path" done ;; - NETBSD_IX86_GNU) + NETBSD_IX86_GNU|FREEBSD_X86_64_GNU) for path in $args do r="$r -Wl,-rpath=$path" @@ -1447,7 +1481,7 @@ if [ "$arg1" = "shlibname" ]; then MONTAVISTA_IX86_GNU) echo "lib$arg2.so" ;; - NETBSD_IX86_GNU) + NETBSD_IX86_GNU|FREEBSD_X86_64_GNU) echo "lib$arg2.so" ;; SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO) @@ -1491,7 +1525,7 @@ if [ "$arg1" = "shlibext" ]; then MONTAVISTA_IX86_GNU) echo "so" ;; - NETBSD_IX86_GNU) + NETBSD_IX86_GNU|FREEBSD_X86_64_GNU) echo "so" ;; SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO) @@ -1612,6 +1646,11 @@ if [ "$arg1" = "openssllibdir" ]; then libdir=/usr/lib fi ;; + FREEBSD_X86_64_GNU) + if [ -f "/usr/lib/libssl.so" ]; then + libdir=/usr/lib + fi + ;; *) echo "so" esac @@ -1967,6 +2006,9 @@ if [ "$arg1" = "gssapi_ext" ]; then DARWIN) echo "0" ;; + FREEBSD) + echo "1" + ;; *) # not-supported! echo "0" diff --git a/Unix/configure b/Unix/configure index 9c3ccb7e0..ec6c8c827 100755 --- a/Unix/configure +++ b/Unix/configure @@ -1433,6 +1433,14 @@ case $os in krblibpath=/System/Library/Frameworks/Kerberos.framework/Kerberos fi ;; + FREEBSD) + if [ disable_auth != 1 ] + then + gsslib=gssapi_krb5 + gsslibpath=libgssapi_krb5.so + krblibpath=libkrb5.so + fi + ;; *) echo "Unknown platform: " $os exit 1 @@ -1509,6 +1517,9 @@ if [ "$os" = "DARWIN" ]; then exit 1 fi fi +elif [ "$os" = "FREEBSD" ]; then + openssllibdir="/usr/lib" + openssllibs="-L$openssllibdir -lssl -lcrypto -lz" else if [ "$opensslcflags_found" != "1" ]; then opensslcflags=`$pkgconfig --cflags openssl` @@ -2570,7 +2581,7 @@ case $os in cp $root/scripts/installpam-sun9 $fn.tmp fi ;; - Darwin) + Darwin|FreeBSD) cp $root/scripts/installpam-rhel $fn.tmp ;; *) diff --git a/Unix/miapi/SafeHandle.c b/Unix/miapi/SafeHandle.c index 095defac2..2ef22e7b9 100644 --- a/Unix/miapi/SafeHandle.c +++ b/Unix/miapi/SafeHandle.c @@ -7,7 +7,7 @@ **============================================================================== */ -#if !defined(macos) +#if !defined(macos) && !defined(freebsd) #include #endif #include diff --git a/Unix/micxx/atomic.h b/Unix/micxx/atomic.h index 651a7e997..688b0a207 100644 --- a/Unix/micxx/atomic.h +++ b/Unix/micxx/atomic.h @@ -14,7 +14,7 @@ MI_BEGIN_NAMESPACE -#if !defined(macos) +#if !defined(macos) && !defined(freebsd) typedef struct _Atomic #else typedef struct _AtomicType diff --git a/Unix/nits/base/Run.h b/Unix/nits/base/Run.h index c001d78ad..58ae7ddc6 100644 --- a/Unix/nits/base/Run.h +++ b/Unix/nits/base/Run.h @@ -178,7 +178,7 @@ class Run bool m_finished; //Stops pipe thread. int *m_statistics; -#if !defined(macos) // Mac says this is not used +#if !defined(macos) && !defined(freebsd) // Mac and FreeBSD says this is not used int m_faultIterations; //Cumulative fault injection iteration total. #endif diff --git a/Unix/omi_error/omierror.c b/Unix/omi_error/omierror.c index d07b12868..090a4a8bc 100644 --- a/Unix/omi_error/omierror.c +++ b/Unix/omi_error/omierror.c @@ -332,7 +332,7 @@ MI_INLINE const MI_Char *Errno_ToString( _Out_writes_z_(len) MI_Char *buffer, MI_Uint32 len) { -#if defined(macos) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) +#if defined(macos) || defined(freebsd) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) int ret = strerror_r(OMI_Code, buffer, len); if (ret != 0) *buffer = '\0'; diff --git a/Unix/pal/cpu.c b/Unix/pal/cpu.c index 5adff123e..9e48f4aab 100644 --- a/Unix/pal/cpu.c +++ b/Unix/pal/cpu.c @@ -10,6 +10,27 @@ #include #include "cpu.h" +#if defined(CONFIG_OS_FREEBSD) +long timezone_calculated = 0; + +__attribute__((constructor)) static void InitializeTimeOffset(void) +{ + // Unlike SYSV, BSD does not have timezone with time offset. (It returns char* with name) + // We need to calculate it once. + struct tm gmt; + struct tm local; + + time_t now = time(NULL); + // Calculate GMT and local time + gmtime_r(&now, &gmt); + localtime_r(&now, &local); + + // calculate difference between local time and GMT + // Since it is only used on one place, pre-calculate to minutes. + timezone_calculated = (mktime(&gmt) - mktime(&local)) / -60; +} +#endif + _Success_(return == 0) int CPU_GetLocalTimestamp( _Out_ PAL_Datetime* current) @@ -28,7 +49,11 @@ int CPU_GetLocalTimestamp( current->u.timestamp.minute = tm.tm_min; current->u.timestamp.second = tm.tm_sec; current->u.timestamp.microseconds = tv.tv_usec; +#if defined(CONFIG_OS_FREEBSD) + current->u.timestamp.utc = timezone_calculated; +#else current->u.timestamp.utc = -timezone / 60; +#endif return 0; } diff --git a/Unix/pal/palcommon.h b/Unix/pal/palcommon.h index de0800373..21b9d00e0 100644 --- a/Unix/pal/palcommon.h +++ b/Unix/pal/palcommon.h @@ -219,7 +219,7 @@ typedef PAL_Char TChar; **============================================================================== */ -#if defined(linux) || defined(sun) || defined(hpux) || defined(aix) || defined(macos) +#if defined(linux) || defined(sun) || defined(hpux) || defined(aix) || defined(macos) || defined(freebsd) # define PAL_HAVE_POSIX #endif @@ -231,7 +231,7 @@ typedef PAL_Char TChar; **============================================================================== */ -#if defined(linux) | defined(sun) | defined(hpux) | defined(aix) | defined(macos) +#if defined(linux) | defined(sun) | defined(hpux) | defined(aix) | defined(macos) | defined(freebsd) # define PAL_HAVE_PTHREADS #endif diff --git a/Unix/pal/thread.h b/Unix/pal/thread.h index ebc498d2a..76ac4d800 100644 --- a/Unix/pal/thread.h +++ b/Unix/pal/thread.h @@ -79,6 +79,10 @@ int Thread_Equal( ThreadID Thread_ID(); +#if defined(freebsd) +int pthread_getthreadid_np(void); +#endif + PAL_INLINE PAL_Uint64 Thread_TID() { @@ -88,6 +92,8 @@ PAL_Uint64 Thread_TID() __uint64_t threadid; pthread_threadid_np(pthread_self(), &threadid); return threadid; +#elif defined(freebsd) + return (PAL_Uint64)pthread_getthreadid_np(); #else // Avoid using a cast here since pthread_self() may return a structure. // If so, we need to discover that and provide an alternative for that