Skip to content
This repository has been archived by the owner on Sep 22, 2018. It is now read-only.

Commit

Permalink
Add FreeBSD support
Browse files Browse the repository at this point in the history
  • Loading branch information
blacklion committed Jun 3, 2017
1 parent d0f991c commit a92fbca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crypto/cryptonight_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, al
#if defined(__APPLE__)
ptr->long_state = (uint8_t*)mmap(0, MEMORY, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
#elif defined(__FreeBSD__)
ptr->long_state = (uint8_t*)mmap(0, MEMORY, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0);
#else
ptr->long_state = (uint8_t*)mmap(0, MEMORY, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
Expand Down
8 changes: 8 additions & 0 deletions minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
#include <mach/thread_policy.h>
#include <mach/thread_act.h>
#define SYSCTL_CORE_COUNT "machdep.cpu.core_count"
#elif defined(__FreeBSD__)
#include <pthread_np.h>
#endif


void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
{
#if defined(__APPLE__)
thread_port_t mach_thread;
thread_affinity_policy_data_t policy = { cpu_id };
mach_thread = pthread_mach_thread_np(h);
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1);
#elif defined(__FreeBSD__)
cpuset_t mn;
CPU_ZERO(&mn);
CPU_SET(cpu_id, &mn);
pthread_setaffinity_np(h, sizeof(cpuset_t), &mn);
#else
cpu_set_t mn;
CPU_ZERO(&mn);
Expand Down
5 changes: 4 additions & 1 deletion socks.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ inline const char* sock_gai_strerror(int err, char* buf, size_t len)
#include <unistd.h> /* Needed for close() */
#include <errno.h>
#include <string.h>
#if defined(__FreeBSD__)
#include <netinet/in.h> /* Needed for IPPROTO_TCP */
#endif

inline void sock_init() {}
typedef int SOCKET;
Expand All @@ -76,7 +79,7 @@ inline void sock_close(SOCKET s)
inline const char* sock_strerror(char* buf, size_t len)
{
buf[0] = '\0';
#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__FreeBSD__)
strerror_r(errno, buf, len);
return buf;
#else
Expand Down

0 comments on commit a92fbca

Please sign in to comment.