diff --git a/makefile b/makefile index 82ad2a7..0255d37 100644 --- a/makefile +++ b/makefile @@ -52,7 +52,7 @@ # ARCHID=2 # Windows Console x86 64 bit # ARCHID=3 # Windows Service x86 32 bit # ARCHID=4 # Windows Service x86 64 bit -# make macos ARCHID=16 # Mac OS x86 64 bit +# make macos ARCHID=16 # Mac OS x86 64 bit # make linux ARCHID=5 # Linux x86 32 bit # make linux ARCHID=6 # Linux x86 64 bit # make linux ARCHID=7 # Linux MIPS @@ -66,7 +66,7 @@ # make linux ARCHID=25 # Linux ARM 32 bit HardFloat (Raspberry Pi, etc) # make linux ARCHID=26 # Linux ARM 64 bit # make pi KVM=1 ARCHID=25 # Linux ARM 32 bit HardFloat, compiled on the Pi. -# +# gmake freebsd ARCHID=30 # FreeBSD x86 64 bit # Microstack & Microscript SOURCES = microstack/ILibAsyncServerSocket.c microstack/ILibAsyncSocket.c microstack/ILibAsyncUDPSocket.c microstack/ILibParsers.c microstack/ILibMulticastSocket.c @@ -257,6 +257,15 @@ CFLAGS += -D_NOFSWATCHER CEXTRA = -fno-strict-aliasing endif +# Official FreeBSD x86-64 +ifeq ($(ARCHID),30) +ARCHNAME = freebsd_x86-64 +CC = clang +KVM = 0 +LMS = 0 +endif + + ifeq ($(WEBLOG),1) CFLAGS += -D_REMOTELOGGINGSERVER -D_REMOTELOGGING endif @@ -293,9 +302,11 @@ SOURCES += microstack/nossl/sha384-512.c microstack/nossl/sha224-256.c microstac CFLAGS += -DMICROSTACK_NOTLS LINUXSSL = MACSSL = +BSDSSL = else LINUXSSL = -Lopenssl/libstatic/linux/$(ARCHNAME) MACSSL = -Lopenssl/libstatic/macos/$(ARCHNAME) +BSDSSL = -Lopenssl/libstatic/bsd/$(ARCHNAME) CFLAGS += -DMICROSTACK_TLS_DETECT LDEXTRA += -lssl -lcrypto endif @@ -412,4 +423,6 @@ macos: $(MAKE) $(MAKEFILE) EXENAME="$(EXENAME)_$(ARCHNAME)" ADDITIONALSOURCES="$(MACOSKVMSOURCES)" CFLAGS="-arch x86_64 -mmacosx-version-min=10.5 -std=gnu99 -Wall -DMESH_AGENTID=$(ARCHID) -D_POSIX -D_NOILIBSTACKDEBUG -D_NOHECI -DMICROSTACK_PROXY -D__APPLE__ $(CWEBLOG) -fno-strict-aliasing $(INCDIRS) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(MACSSL) $(MACOSFLAGS) -L. -lpthread -ldl -lz -lutil -framework IOKit -framework ApplicationServices -framework SystemConfiguration -framework CoreFoundation -fconstant-cfstrings $(LDFLAGS) $(LDEXTRA)" $(STRIP) +freebsd: + $(MAKE) EXENAME="$(EXENAME)_$(ARCHNAME)$(EXENAME2)" AID="$(ARCHID)" CFLAGS="-std=gnu99 -Wall -DMESH_AGENTID=$(ARCHID) -D_POSIX -D_FREEBSD -D_NOHECI -D_NOILIBSTACKDEBUG -DMICROSTACK_PROXY -fno-strict-aliasing $(INCDIRS) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(BSDSSL) -L. -lpthread -ldl -lz -lutil $(LDFLAGS) $(LDEXTRA)" diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 10b8c63..ee6dde2 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -4488,7 +4488,11 @@ int MeshAgent_Start(MeshAgentHostContainer *agentHost, int paramLen, char **para agentHost->exePath = exePath; #elif defined(NACL) #else + #ifdef _FREEBSD + x = readlink("/proc/curproc/file", exePath, 1024); + #else x = readlink("/proc/self/exe", exePath, 1024); + #endif if (x < 0 || x >= 1024) ILIBCRITICALEXIT(246); exePath[x] = 0; #endif diff --git a/meshcore/meshinfo.c b/meshcore/meshinfo.c index f2a050d..fde5a46 100644 --- a/meshcore/meshinfo.c +++ b/meshcore/meshinfo.c @@ -42,8 +42,9 @@ limitations under the License. #include #include #include -#include - +#ifndef _FREEBSD + #include +#endif #define inaddrr(x) (*(struct in_addr *) &ifr->x[sizeof sa.sin_port]) #define IFRSIZE ((int)(size * sizeof (struct ifreq))) @@ -333,7 +334,7 @@ int info_GetDefaultGateway(char* ifname, char** gateway) // This is the POSIX implementation of a method that gets information about local interfaces int info_GetLocalInterfaces(char* data, int maxdata) { -#ifdef NACL +#if defined NACL || defined(_FREEBSD) return 0; #else @@ -510,7 +511,7 @@ int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force) #endif } -#elif _VX_CPU // If VxWorks, we still need to implement this. +#elif defined(_VX_CPU) || defined(_FREEBSD) // If VxWorks, we still need to implement this. int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force) { diff --git a/microscript/ILibDuktape_HECI.c b/microscript/ILibDuktape_HECI.c index 2ba594a..39741dd 100644 --- a/microscript/ILibDuktape_HECI.c +++ b/microscript/ILibDuktape_HECI.c @@ -24,6 +24,7 @@ limitations under the License. #include "../microstack/ILibProcessPipe.h" #include "../microstack/ILibRemoteLogging.h" +#ifndef _NOHECI #ifdef WIN32 #include @@ -1143,3 +1144,6 @@ void ILibDuktape_HECI_Init(duk_context *ctx) { ILibDuktape_ModSearch_AddHandler(ctx, "heci", ILibDuktape_HECI_Push); } + +#endif + diff --git a/microscript/ILibDuktape_ScriptContainer.c b/microscript/ILibDuktape_ScriptContainer.c index fd8355c..aa223a0 100644 --- a/microscript/ILibDuktape_ScriptContainer.c +++ b/microscript/ILibDuktape_ScriptContainer.c @@ -27,10 +27,10 @@ limitations under the License. #ifndef NO_IFADDR #include #endif -#ifndef __APPLE__ -#include -#else -#include +#ifdef __APPLE__ + #include +#elif !defined(_FREEBSD) + #include #endif #include #endif @@ -467,7 +467,11 @@ void ILibDuktape_ScriptContainer_CheckEmbedded(char **script, int *scriptLen) if (_NSGetExecutablePath(exePath, &len) != 0) ILIBCRITICALEXIT(247); exePath[len] = 0; #elif defined(NACL) -#else +#elif defined(_FREEBSD) + int x = readlink("/proc/curproc/file", exePath, sizeof(exePath)); + if (x < 0 || x >= sizeof(exePath)) ILIBCRITICALEXIT(246); + exePath[x] = 0; +#elif int x = readlink("/proc/self/exe", exePath, sizeof(exePath)); if (x < 0 || x >= sizeof(exePath)) ILIBCRITICALEXIT(246); exePath[x] = 0; @@ -1015,6 +1019,8 @@ void ILibDuktape_ScriptContainer_Process_Init(duk_context *ctx, char **argList) duk_push_string(ctx, "win32"); #elif defined(__APPLE__) duk_push_string(ctx, "darwin"); +#elif defined(_FREEBSD) + duk_push_string(ctx, "freebsd"); #else duk_push_string(ctx, "linux"); #endif @@ -1346,7 +1352,7 @@ int ILibDuktape_ScriptContainer_os_isWirelessInterface(char *interfaceName) return(retVal); } #endif -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(_FREEBSD) duk_ret_t ILibDuktape_ScriptContainer_OS_networkInterfaces(duk_context *ctx) { #if !defined(WIN32) @@ -1607,7 +1613,7 @@ void ILibDuktape_ScriptContainer_OS_Push(duk_context *ctx, void *chain) ILibDuktape_CreateInstanceMethod(ctx, "arch", ILibDuktape_ScriptContainer_OS_arch, 0); ILibDuktape_CreateInstanceMethod(ctx, "platform", ILibDuktape_ScriptContainer_OS_platform, 0); -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(_FREEBSD) ILibDuktape_CreateInstanceMethod(ctx, "networkInterfaces", ILibDuktape_ScriptContainer_OS_networkInterfaces, 0); #endif ILibDuktape_CreateInstanceMethod(ctx, "hostname", ILibDuktape_ScriptContainer_OS_hostname, 0); diff --git a/microscript/ILibDuktape_fs.c b/microscript/ILibDuktape_fs.c index ee8fb7e..9a5d4f1 100644 --- a/microscript/ILibDuktape_fs.c +++ b/microscript/ILibDuktape_fs.c @@ -39,8 +39,8 @@ limitations under the License. #ifdef _POSIX #include -#if !defined(_NOFSWATCHER) && !defined(__APPLE__) -#include +#if !defined(_NOFSWATCHER) && !defined(__APPLE__) && !defined(_FREEBSD) + #include #endif #endif #ifdef __APPLE__ @@ -905,7 +905,7 @@ duk_ret_t ILibDuktape_fs_watcher_close(duk_context *ctx) ILibProcessPipe_WaitHandle_Remove(data->pipeManager, data->overlapped.hEvent); CloseHandle(data->h); data->h = NULL; -#elif defined(_POSIX) && !defined(__APPLE__) +#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) ILibHashtable_Remove(data->linuxWatcher->watchTable, data->wd.p, NULL, 0); if (inotify_rm_watch(data->linuxWatcher->fd, data->wd.i) != 0) { ILibRemoteLogging_printf(ILibChainGetLogger(Duktape_GetChain(ctx)), ILibRemoteLogging_Modules_Agent_GuardPost | ILibRemoteLogging_Modules_ConsolePrint, ILibRemoteLogging_Flags_VerbosityLevel_1, "FSWatcher.close(): Error removing wd[%d] from fd[%d]", data->wd.i, data->linuxWatcher->fd); } else @@ -1046,7 +1046,7 @@ duk_ret_t ILibDuktape_fs_watcher_finalizer(duk_context *ctx) return 0; } -#if defined(_POSIX) && !defined(__APPLE__) +#if defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) void ILibDuktape_fs_notifyDispatcher_PreSelect(void* object, fd_set *readset, fd_set *writeset, fd_set *errorset, int* blocktime) { ILibDuktape_fs_linuxWatcher *data = (ILibDuktape_fs_linuxWatcher*)object; @@ -1296,7 +1296,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx) duk_pop(ctx); // ... } #elif defined(_POSIX) -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(_FREEBSD) // Linux ILibDuktape_fs_linuxWatcher *notifyDispatcher = NULL; duk_push_this(ctx); // [fs] @@ -1320,7 +1320,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx) duk_put_prop_string(ctx, -2, FS_NOTIFY_DISPATCH_PTR); // [fs] duk_pop(ctx); // ... } -#else +#elif defined(__APPLE__) // MacOS ILibDuktape_fs_appleWatcher *watcher = NULL; duk_push_this(ctx); // [fs] @@ -1363,7 +1363,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx) data->chain = chain; data->pipeManager = pipeMgr; data->recursive = recursive; -#elif defined(_POSIX) && !defined(__APPLE__) +#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) data->linuxWatcher = notifyDispatcher; #endif #ifdef __APPLE__ @@ -1396,7 +1396,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx) return(ILibDuktape_Error(ctx, "fs.watch(): Error creating watcher")); } ILibProcessPipe_WaitHandle_Add(pipeMgr, data->overlapped.hEvent, data, ILibDuktape_fs_watch_iocompletion); -#elif defined(_POSIX) && !defined(__APPLE__) +#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) data->wd.i = inotify_add_watch(data->linuxWatcher->fd, path, IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_FROM | IN_MOVED_TO); if (data->wd.i < 0) { diff --git a/microstack/ILibAsyncServerSocket.h b/microstack/ILibAsyncServerSocket.h index c6c0a38..120ffa3 100644 --- a/microstack/ILibAsyncServerSocket.h +++ b/microstack/ILibAsyncServerSocket.h @@ -28,7 +28,7 @@ limitations under the License. #if defined(WIN32) || defined(_WIN32_WCE) #include #elif defined(_POSIX) -#if !defined(__APPLE__) && !defined(_VX_CPU) +#if !defined(__APPLE__) && !defined(_VX_CPU) && !defined(_FREEBSD) #include #endif #endif diff --git a/microstack/ILibAsyncSocket.h b/microstack/ILibAsyncSocket.h index 191c9b1..f424368 100644 --- a/microstack/ILibAsyncSocket.h +++ b/microstack/ILibAsyncSocket.h @@ -28,7 +28,7 @@ limitations under the License. #if defined(WIN32) || defined(_WIN32_WCE) #include #elif defined(_POSIX) -#if !defined(__APPLE__) && !defined(_VX_CPU) +#if !defined(__APPLE__) && !defined(_VX_CPU) && !defined(_FREEBSD) #include #endif #endif diff --git a/microstack/ILibAsyncUDPSocket.h b/microstack/ILibAsyncUDPSocket.h index b95d7dd..0274519 100644 --- a/microstack/ILibAsyncUDPSocket.h +++ b/microstack/ILibAsyncUDPSocket.h @@ -28,7 +28,7 @@ limitations under the License. #if defined(WIN32) || defined(_WIN32_WCE) #include #elif defined(_POSIX) -#if !defined(__APPLE__) && !defined(_VX_CPU) +#if !defined(__APPLE__) && !defined(_VX_CPU) && !defined(_FREEBSD) #include #endif #endif diff --git a/microstack/ILibIPAddressMonitor.c b/microstack/ILibIPAddressMonitor.c index 2cd36cb..be41c8d 100644 --- a/microstack/ILibIPAddressMonitor.c +++ b/microstack/ILibIPAddressMonitor.c @@ -28,7 +28,7 @@ limitations under the License. #include "ILibParsers.h" -#if defined(_POSIX) && !defined(__APPLE__) && !defined(NO_IPADDR_MONITOR) +#if defined(_POSIX) && !defined(__APPLE__) && !defined(NO_IPADDR_MONITOR) && !defined(_FREEBSD) #include #include #include @@ -47,7 +47,7 @@ typedef struct _ILibIPAddressMonitor SOCKET mSocket; DWORD bytesReturned; OVERLAPPED *reserved; - #elif defined (_POSIX) && !defined(__APPLE__) + #elif defined (_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) int mSocket; struct sockaddr_nl addr; #endif @@ -96,13 +96,13 @@ void ILibIPAddressMonitor_Destroy(void *object) obj->reserved->hEvent = NULL; closesocket(obj->mSocket); obj->mSocket = INVALID_SOCKET; -#elif defined(_POSIX) && !defined(__APPLE__) +#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) close(obj->mSocket); obj->mSocket = -1; #endif } -#if defined(_POSIX) && !defined(__APPLE__) +#if defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) void ILibIPAddressMonitor_PreSelect(void* object, fd_set *readset, fd_set *writeset, fd_set *errorset, int* blocktime) { _ILibIPAddressMonitor *obj = (_ILibIPAddressMonitor*)object; @@ -148,7 +148,7 @@ ILibIPAddressMonitor ILibIPAddressMonitor_Create(void *chain, ILibIPAddressMonit obj->reserved->hEvent = (HANDLE)obj; obj->mSocket = socket(AF_INET, SOCK_DGRAM, 0); WSAIoctl(obj->mSocket, SIO_ADDRESS_LIST_CHANGE, NULL, 0, NULL, 0, &(obj->bytesReturned), obj->reserved, ILibIPAddressMonitor_dispatch); -#elif defined (_POSIX) && !defined(__APPLE__) +#elif defined (_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) obj->mSocket = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); int flags = fcntl(obj->mSocket, F_GETFL, 0); fcntl(obj->mSocket, F_SETFL, O_NONBLOCK | flags); diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index 2966348..4a4746e 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -25,8 +25,12 @@ limitations under the License. #include "chrome/nacl.h" #endif #if defined(_POSIX) - #ifndef _VX_CPU - #include + #if !defined(_VX_CPU) && !defined(_FREEBSD) + #include + #endif + #ifdef _FREEBSD + #include + #include #endif #include #ifndef _NOILIBSTACKDEBUG @@ -8117,7 +8121,7 @@ int ILibGetCurrentTimezoneOffset_Minutes() { return(-1*(int)((u.QuadPart - l.QuadPart ) / 10000000 / 60)); } -#elif defined(_ANDROID) +#elif defined(_ANDROID) || defined(_FREEBSD) return 0; // TODO #else int offset; @@ -8144,8 +8148,12 @@ int ILibIsDaylightSavingsTime() #elif defined(_ANDROID) return 0; // TODO #else - tzset(); - return daylight; + #ifdef _FREEBSD + return(0); + #else + tzset(); + return daylight; + #endif #endif } diff --git a/microstack/ILibParsers.h b/microstack/ILibParsers.h index 0dd4e74..09f5f8d 100644 --- a/microstack/ILibParsers.h +++ b/microstack/ILibParsers.h @@ -87,7 +87,7 @@ struct sockaddr_in6; #ifndef __APPLE__ #include #endif -#if !defined(__APPLE__) && !defined(_VX_CPU) +#if !defined(__APPLE__) && !defined(_VX_CPU) && !defined(_FREEBSD) #include #endif #include @@ -95,7 +95,7 @@ struct sockaddr_in6; #define UNREFERENCED_PARAMETER(P) #endif -#if defined(_POSIX) && !defined(__APPLE__) +#if defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) #include #endif diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index 7bc1cd4..4df6a3c 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -35,7 +35,7 @@ limitations under the License. #include #include #include -#ifndef __APPLE__ +#if !defined( __APPLE__) && !defined(_FREEBSD) #include #endif #endif diff --git a/microstack/ILibWebClient.h b/microstack/ILibWebClient.h index 19c582e..66b0657 100644 --- a/microstack/ILibWebClient.h +++ b/microstack/ILibWebClient.h @@ -47,7 +47,7 @@ extern "C" { #if defined(WIN32) || defined(_WIN32_WCE) #include #elif defined(_POSIX) -#if !defined(__APPLE__) && !defined(_VX_CPU) +#if !defined(__APPLE__) && !defined(_VX_CPU) && !defined(_FREEBSD) #include #endif #endif diff --git a/openssl/libstatic/bsd/freebsd_x86-64/libcrypto.a b/openssl/libstatic/bsd/freebsd_x86-64/libcrypto.a new file mode 100644 index 0000000..b7de797 Binary files /dev/null and b/openssl/libstatic/bsd/freebsd_x86-64/libcrypto.a differ diff --git a/openssl/libstatic/bsd/freebsd_x86-64/libssl.a b/openssl/libstatic/bsd/freebsd_x86-64/libssl.a new file mode 100644 index 0000000..263a2cb Binary files /dev/null and b/openssl/libstatic/bsd/freebsd_x86-64/libssl.a differ