diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b3f42f..2016a61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,9 @@ function (_set_common_flags target) "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") target_compile_options("${target}" PRIVATE "-std=c99") endif () + if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + target_compile_options("${target}" PRIVATE "-fPIC") + endif () endfunction () add_library("Zydis") @@ -210,6 +213,10 @@ if (ZYDIS_BUILD_EXAMPLES) find_package(Threads REQUIRED) target_link_libraries("ZydisPerfTest" Threads::Threads) endif () + if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + find_package(Threads REQUIRED) + target_link_libraries("ZydisPerfTest" Threads::Threads) + endif () endif () endif () diff --git a/examples/ZydisPerfTest.c b/examples/ZydisPerfTest.c index cc9d121..28de703 100644 --- a/examples/ZydisPerfTest.c +++ b/examples/ZydisPerfTest.c @@ -41,6 +41,10 @@ #elif defined(ZYDIS_LINUX) # include # include +#elif defined(ZYDIS_FREEBSD) +# include +# include +# include #else # error "Unsupported platform detected" #endif @@ -95,7 +99,7 @@ double GetCounter() return (double)elapsed * timebaseInfo.numer / timebaseInfo.denom / 1000000; } -#elif defined(ZYDIS_LINUX) +#elif defined(ZYDIS_LINUX) || defined(ZYDIS_FREEBSD) struct timeval t1; void StartCounter() @@ -138,12 +142,18 @@ void adjustProcessAndThreadPriority() } } #endif -#ifdef ZYDIS_LINUX +#if defined(ZYDIS_LINUX) pthread_t thread = pthread_self(); cpu_set_t cpus; CPU_ZERO(&cpus); CPU_SET(0, &cpus); pthread_setaffinity_np(thread, sizeof(cpus), &cpus); +#elif defined(ZYDIS_FREEBSD) + pthread_t thread = pthread_self(); + cpuset_t cpus; + CPU_ZERO(&cpus); + CPU_SET(0, &cpus); + pthread_setaffinity_np(thread, sizeof(cpus), &cpus); #endif } diff --git a/include/Zydis/Defines.h b/include/Zydis/Defines.h index a15b778..dbf9eb7 100644 --- a/include/Zydis/Defines.h +++ b/include/Zydis/Defines.h @@ -66,6 +66,9 @@ #elif defined(__linux) # define ZYDIS_LINUX # define ZYDIS_POSIX +#elif defined(__FreeBSD__) +# define ZYDIS_FREEBSD +# define ZYDIS_POSIX #elif defined(__unix) # define ZYDIS_UNIX # define ZYDIS_POSIX