Some FreeBSD fixes for examples and including Zydis in shared/static libraries

This commit is contained in:
fG! 2018-07-11 23:19:12 +01:00 committed by Joel Höner
parent 51686517c4
commit 9f0eae62c1
3 changed files with 22 additions and 2 deletions

View File

@ -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 ()

View File

@ -41,6 +41,10 @@
#elif defined(ZYDIS_LINUX)
# include <sys/time.h>
# include <pthread.h>
#elif defined(ZYDIS_FREEBSD)
# include <sys/time.h>
# include <pthread.h>
# include <pthread_np.h>
#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
}

View File

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