Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Unix/base/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
60 changes: 51 additions & 9 deletions Unix/buildtool
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}'`
Expand Down Expand Up @@ -438,7 +445,7 @@ if [ "$arg1" = "longhostname" ]; then
MONTAVISTA*)
hostname
;;
NETBSD*)
NETBSD*|FREEBSD*)
hostname
;;
DARWIN*)
Expand Down Expand Up @@ -594,6 +601,9 @@ if [ "$arg1" = "cc" ]; then
DARWIN_IX86_GNU)
echo clang
;;
FREEBSD_X86_64_GNU)
echo clang
;;
esac

exit
Expand Down Expand Up @@ -635,6 +645,9 @@ if [ "$arg1" = "cxx" ]; then
DARWIN_IX86_GNU)
echo clang++
;;
FREEBSD_X86_64_GNU)
echo clang++
;;
esac

exit
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1967,6 +2006,9 @@ if [ "$arg1" = "gssapi_ext" ]; then
DARWIN)
echo "0"
;;
FREEBSD)
echo "1"
;;
*)
# not-supported!
echo "0"
Expand Down
13 changes: 12 additions & 1 deletion Unix/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
;;
*)
Expand Down
2 changes: 1 addition & 1 deletion Unix/miapi/SafeHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
**==============================================================================
*/

#if !defined(macos)
#if !defined(macos) && !defined(freebsd)
#include <malloc.h>
#endif
#include <MI.h>
Expand Down
2 changes: 1 addition & 1 deletion Unix/micxx/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

MI_BEGIN_NAMESPACE

#if !defined(macos)
#if !defined(macos) && !defined(freebsd)
typedef struct _Atomic
#else
typedef struct _AtomicType
Expand Down
2 changes: 1 addition & 1 deletion Unix/nits/base/Run.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Unix/omi_error/omierror.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
21 changes: 21 additions & 0 deletions Unix/pal/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
#include <sys/time.h>
#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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is now use?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at CPU_GetLocalTimestampz() @JumpingYang001. On Linux, timezone is extern long with offset to GMT. BSD does not have that. (or OSX/MacOS) Since I failed to figure out what we do for Mac, I simply calculate once difference between GMT and local.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I found there is a char* timezone() function in FreeBSD.

I think OSX should use exist logic, I don't know much about how BSD dealt with it.
I just surprise the now variable here isn't used?
:)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. there were two lines missing - I probably somehow nuke them in final cleanup. I also add more comments. I hope the code makes more sense now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we don't have verification for u.timestamp.utc in https://github.com/Microsoft/omi/blob/eb689db8a63de6e466f149cd80136de26c53b40c/Unix/tests/pal/test_pal.cpp#L1021 , if you can add one that would be nice, e.g. TEST_ASSERT(now.u.timestamp.utc>= "2018/12/12 00:00AM UTC"'s utc);, just an example that means it will be greater than a recent past utc time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if my condition is good, just a thought. :)


// 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)
Expand All @@ -28,7 +45,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;
}

Expand Down
4 changes: 2 additions & 2 deletions Unix/pal/palcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions Unix/pal/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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
Expand Down