Merge pull request #3182 from SChernykh/dev

DragonflyBSD compilation fixes
This commit is contained in:
xmrig 2022-12-17 20:24:01 +07:00 committed by GitHub
commit 4d0b8c9daf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 17 deletions

View file

@ -15,7 +15,7 @@ else()
set(XMRIG_OS_ANDROID ON) set(XMRIG_OS_ANDROID ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(XMRIG_OS_LINUX ON) set(XMRIG_OS_LINUX ON)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL DragonFly)
set(XMRIG_OS_FREEBSD ON) set(XMRIG_OS_FREEBSD ON)
endif() endif()
endif() endif()

View file

@ -27,7 +27,7 @@
#if __ARM_FEATURE_CRYPTO && !defined(__APPLE__) #if __ARM_FEATURE_CRYPTO && !defined(__APPLE__)
# include <sys/auxv.h> # include <sys/auxv.h>
# if !defined(__FreeBSD__) && !defined(__DragonFly__) # if !defined(XMRIG_OS_FREEBSD)
# include <asm/hwcap.h> # include <asm/hwcap.h>
# else # else
# include <stdint.h> # include <stdint.h>
@ -71,7 +71,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
# if __ARM_FEATURE_CRYPTO # if __ARM_FEATURE_CRYPTO
# if defined(__APPLE__) # if defined(__APPLE__)
m_flags.set(FLAG_AES, true); m_flags.set(FLAG_AES, true);
# elif defined(__FreeBSD__) || defined(__DragonFly__) # elif defined(XMRIG_OS_FREEBSD)
uint64_t isar0 = READ_SPECIALREG(id_aa64isar0_el1); uint64_t isar0 = READ_SPECIALREG(id_aa64isar0_el1);
m_flags.set(FLAG_AES, ID_AA64ISAR0_AES_VAL(isar0) >= ID_AA64ISAR0_AES_BASE); m_flags.set(FLAG_AES, ID_AA64ISAR0_AES_VAL(isar0) >= ID_AA64ISAR0_AES_BASE);
# else # else

View file

@ -16,10 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#if defined(__FreeBSD__) || defined(__DragonFly__) #ifdef XMRIG_OS_FREEBSD
# include <sys/types.h> # include <sys/types.h>
# include <sys/param.h> # include <sys/param.h>
# ifndef __DragonFly__
# include <sys/cpuset.h> # include <sys/cpuset.h>
# endif
# include <pthread_np.h> # include <pthread_np.h>
#endif #endif
@ -41,11 +43,6 @@
#include "version.h" #include "version.h"
#if defined(__FreeBSD__) || defined(__DragonFly__)
typedef cpuset_t cpu_set_t;
#endif
char *xmrig::Platform::createUserAgent() char *xmrig::Platform::createUserAgent()
{ {
constexpr const size_t max = 256; constexpr const size_t max = 256;
@ -74,6 +71,19 @@ char *xmrig::Platform::createUserAgent()
#ifndef XMRIG_FEATURE_HWLOC #ifndef XMRIG_FEATURE_HWLOC
#ifdef __DragonFly__
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
return true;
}
#else
#ifdef XMRIG_OS_FREEBSD
typedef cpuset_t cpu_set_t;
#endif
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{ {
cpu_set_t mn; cpu_set_t mn;
@ -89,7 +99,9 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result; return result;
} }
#endif
#endif // __DragonFly__
#endif // XMRIG_FEATURE_HWLOC
void xmrig::Platform::setProcessPriority(int) void xmrig::Platform::setProcessPriority(int)

View file

@ -57,6 +57,15 @@
# define MAP_HUGE_MASK 0x3f # define MAP_HUGE_MASK 0x3f
#endif #endif
#ifdef XMRIG_OS_FREEBSD
# ifndef MAP_ALIGNED_SUPER
# define MAP_ALIGNED_SUPER 0
# endif
# ifndef MAP_PREFAULT_READ
# define MAP_PREFAULT_READ 0
# endif
#endif
#ifdef XMRIG_SECURE_JIT #ifdef XMRIG_SECURE_JIT
# define SECURE_PROT_EXEC 0 # define SECURE_PROT_EXEC 0
@ -65,7 +74,7 @@
#endif #endif
#if defined(XMRIG_OS_LINUX) || (!defined(XMRIG_OS_APPLE) && !defined(__FreeBSD__) && !defined(__DragonFly__)) #if defined(XMRIG_OS_LINUX) || (!defined(XMRIG_OS_APPLE) && !defined(XMRIG_OS_FREEBSD))
static inline int hugePagesFlag(size_t size) static inline int hugePagesFlag(size_t size)
{ {
return (static_cast<int>(log2(size)) & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; return (static_cast<int>(log2(size)) & MAP_HUGE_MASK) << MAP_HUGE_SHIFT;
@ -135,7 +144,7 @@ void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size, bool hugePages
# ifdef XMRIG_ARM # ifdef XMRIG_ARM
pthread_jit_write_protect_np(false); pthread_jit_write_protect_np(false);
# endif # endif
# elif defined(__FreeBSD__) || defined(__DragonFly__) # elif defined(XMRIG_OS_FREEBSD)
void *mem = nullptr; void *mem = nullptr;
if (hugePages) { if (hugePages) {
@ -168,7 +177,7 @@ void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size)
{ {
# if defined(XMRIG_OS_APPLE) # if defined(XMRIG_OS_APPLE)
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
# elif defined(__FreeBSD__) || defined(__DragonFly__) # elif defined(XMRIG_OS_FREEBSD)
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0); void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0);
# else # else
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE | hugePagesFlag(hugePageSize()), 0, 0); void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE | hugePagesFlag(hugePageSize()), 0, 0);

View file

@ -31,7 +31,7 @@
#include <unistd.h> #include <unistd.h>
#include <cstdio> #include <cstdio>
#if defined(__FreeBSD__) || defined(__DragonFly__) #ifdef XMRIG_OS_FREEBSD
# include <kenv.h> # include <kenv.h>
#endif #endif
@ -288,7 +288,7 @@ static off_t address_from_efi()
const char *filename; const char *filename;
char linebuf[64]; char linebuf[64];
off_t address = 0; off_t address = 0;
# elif defined(__FreeBSD__) || defined(__DragonFly__) # elif defined(XMRIG_OS_FREEBSD)
char addrstr[KENV_MVALLEN + 1]; char addrstr[KENV_MVALLEN + 1];
# endif # endif
@ -310,7 +310,7 @@ static off_t address_from_efi()
fclose(efi_systab); fclose(efi_systab);
return address; return address;
# elif defined(__FreeBSD__) || defined(__DragonFly__) # elif defined(XMRIG_OS_FREEBSD)
if (kenv(KENV_GET, "hint.smbios.0.mem", addrstr, sizeof(addrstr)) == -1) { if (kenv(KENV_GET, "hint.smbios.0.mem", addrstr, sizeof(addrstr)) == -1) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }