diff --git a/include/slang.h b/include/slang.h
index 368046d08..77225ce93 100644
--- a/include/slang.h
+++ b/include/slang.h
@@ -98,7 +98,7 @@ Most applications should not need to touch this section.
#define SLANG_WIN32 1
#elif defined(__ANDROID__)
#define SLANG_ANDROID 1
- #elif defined(__linux__) || defined(__CYGWIN__) /* note: __ANDROID__ implies __linux__ */
+ #elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) /* note: __ANDROID__ implies __linux__ */
#define SLANG_LINUX 1
#elif defined(__APPLE__)
#include "TargetConditionals.h"
@@ -548,7 +548,7 @@ SLANG_COMPILE_TIME_ASSERT((SLANG_PTR_IS_64 ? 8 : 4) == sizeof(void*));
#endif
// Backtrace
-#if SLANG_LINUX_FAMILY
+#if SLANG_LINUX_FAMILY && !defined(__FreeBSD__)
#include <features.h> // for __GLIBC__ define, if using GNU libc
#if defined(__GLIBC__) || (__ANDROID_API__ >= 33)
#define SLANG_HAS_BACKTRACE 1
diff --git a/prelude/slang-cpp-prelude.h b/prelude/slang-cpp-prelude.h
index aedc821a5..b0df204d8 100644
--- a/prelude/slang-cpp-prelude.h
+++ b/prelude/slang-cpp-prelude.h
@@ -142,7 +142,7 @@ Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSyst
#define SLANG_WIN32 1
#elif defined(__ANDROID__)
#define SLANG_ANDROID 1
-#elif defined(__linux__) || defined(__CYGWIN__) /* note: __ANDROID__ implies __linux__ */
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__)/* note: __ANDROID__ implies __linux__ */
#define SLANG_LINUX 1
#elif defined(__APPLE__) && !defined(SLANG_LLVM)
#include "TargetConditionals.h"
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 3c214ad1f..a8351eb73 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -22,7 +22,7 @@
// clang-format on
#endif
-#if defined(__linux__) || defined(__CYGWIN__) || SLANG_APPLE_FAMILY || SLANG_WASM
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || SLANG_APPLE_FAMILY || SLANG_WASM
#include <fcntl.h>
#include <unistd.h>
// For Path::find
@@ -42,6 +42,13 @@
#include <stdio.h>
#include <stdlib.h>
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <dlfcn.h>
+#include <limits.h>
+#endif
+
namespace Slang
{
@@ -1011,7 +1018,17 @@ static SlangResult _calcExectuablePath(char* outPath, size_t* ioSize)
return SLANG_E_BUFFER_TOO_SMALL;
#elif SLANG_LINUX_FAMILY
-#if defined(__linux__) || defined(__CYGWIN__)
+#if defined(__FreeBSD__)
+
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+ size_t len = bufferSize;
+
+ if (len < PATH_MAX)
+ return SLANG_E_BUFFER_TOO_SMALL;
+ if (sysctl(mib, 4, outPath, &len, nullptr, 0) == 0)
+ return SLANG_OK;
+ return SLANG_FAIL;
+#elif defined(__linux__) || defined(__CYGWIN__)
// https://linux.die.net/man/2/readlink
// Mark last byte with 0, so can check overrun
ssize_t resSize = ::readlink("/proc/self/exe", outPath, bufferSize);
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index c975738d7..2c4ea4283 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -282,7 +282,7 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
#else // _WIN32
/* static */ SlangResult PlatformUtil::getInstancePath([[maybe_unused]] StringBuilder& out)
{
-#if defined(__linux__) || defined(__CYGWIN__)
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__)
char path[PATH_MAX];
ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1);
if (len == -1)
diff --git a/source/core/slang-stream.cpp b/source/core/slang-stream.cpp
index d6cfcad45..7362e749b 100644
--- a/source/core/slang-stream.cpp
+++ b/source/core/slang-stream.cpp
@@ -8,6 +8,16 @@
#include <stdio.h>
#include <thread>
+#if defined(__FreeBSD__)
+#define fpos64_t fpos_t
+#define fgetpos64 fgetpos
+#define fsetpos64 fsetpos
+#define fseeko64 fseeko
+#define ftello64 ftello
+#define fopen64 fopen
+#define off64_t off_t
+#endif
+
namespace Slang
{
diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp
index dfc463ac9..73c1b8ea6 100644
--- a/source/core/unix/slang-unix-process.cpp
+++ b/source/core/unix/slang-unix-process.cpp
@@ -21,7 +21,11 @@
#include <time.h>
#include <unistd.h>
+#if defined(__FreeBSD__)
+extern char** environ __attribute__((weak));
+#else
extern char** environ;
+#endif
namespace Slang
{