Add NetBSD support

This commit is contained in:
David Carlier 2020-12-04 16:09:42 +00:00 committed by Léo Lam
parent ed1564515b
commit 2c355b81f2
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
8 changed files with 43 additions and 14 deletions

View File

@ -19,7 +19,7 @@
#include <stdio.h> #include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ #if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
#include <sys/sysctl.h> #include <sys/sysctl.h>
#elif defined __HAIKU__ #elif defined __HAIKU__
#include <OS.h> #include <OS.h>
@ -156,7 +156,7 @@ size_t MemPhysical()
memInfo.dwLength = sizeof(MEMORYSTATUSEX); memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo); GlobalMemoryStatusEx(&memInfo);
return memInfo.ullTotalPhys; return memInfo.ullTotalPhys;
#elif defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ #elif defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
int mib[2]; int mib[2];
size_t physical_memory; size_t physical_memory;
mib[0] = CTL_HW; mib[0] = CTL_HW;
@ -164,7 +164,7 @@ size_t MemPhysical()
mib[1] = HW_MEMSIZE; mib[1] = HW_MEMSIZE;
#elif defined __FreeBSD__ #elif defined __FreeBSD__
mib[1] = HW_REALMEM; mib[1] = HW_REALMEM;
#elif defined __OpenBSD__ #elif defined __OpenBSD__ || defined __NetBSD__
mib[1] = HW_PHYSMEM; mib[1] = HW_PHYSMEM;
#endif #endif
size_t length = sizeof(size_t); size_t length = sizeof(size_t);

View File

@ -35,12 +35,16 @@
constexpr u32 CODEPAGE_SHIFT_JIS = 932; constexpr u32 CODEPAGE_SHIFT_JIS = 932;
constexpr u32 CODEPAGE_WINDOWS_1252 = 1252; constexpr u32 CODEPAGE_WINDOWS_1252 = 1252;
#else #else
#if defined(__NetBSD__)
#define LIBICONV_PLUG
#endif
#include <errno.h> #include <errno.h>
#include <iconv.h> #include <iconv.h>
#include <locale.h> #include <locale.h>
#endif #endif
#if !defined(_WIN32) && !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) #if !defined(_WIN32) && !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && \
!defined(__NetBSD__)
static locale_t GetCLocale() static locale_t GetCLocale()
{ {
static locale_t c_locale = newlocale(LC_ALL_MASK, "C", nullptr); static locale_t c_locale = newlocale(LC_ALL_MASK, "C", nullptr);
@ -133,11 +137,11 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
c_locale = _create_locale(LC_ALL, "C"); c_locale = _create_locale(LC_ALL, "C");
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args); writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
#else #else
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) #if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
locale_t previousLocale = uselocale(GetCLocale()); locale_t previousLocale = uselocale(GetCLocale());
#endif #endif
writtenCount = vsnprintf(out, outsize, format, args); writtenCount = vsnprintf(out, outsize, format, args);
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) #if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
uselocale(previousLocale); uselocale(previousLocale);
#endif #endif
#endif #endif
@ -174,7 +178,7 @@ std::string StringFromFormatV(const char* format, va_list args)
std::string temp = buf; std::string temp = buf;
delete[] buf; delete[] buf;
#else #else
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) #if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
locale_t previousLocale = uselocale(GetCLocale()); locale_t previousLocale = uselocale(GetCLocale());
#endif #endif
if (vasprintf(&buf, format, args) < 0) if (vasprintf(&buf, format, args) < 0)
@ -183,7 +187,7 @@ std::string StringFromFormatV(const char* format, va_list args)
buf = nullptr; buf = nullptr;
} }
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) #if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
uselocale(previousLocale); uselocale(previousLocale);
#endif #endif
@ -524,8 +528,13 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v
while (src_bytes != 0) while (src_bytes != 0)
{ {
size_t const iconv_result = size_t const iconv_result =
iconv(conv_desc, (char**)(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes); #if defined(__OpenBSD__) || defined(__NetBSD__)
iconv(conv_desc, reinterpret_cast<const char**>(&src_buffer), &src_bytes, &dst_buffer,
&dst_bytes);
#else
iconv(conv_desc, const_cast<char**>(reinterpret_cast<const char**>(&src_buffer)),
&src_bytes, &dst_buffer, &dst_bytes);
#endif
if ((size_t)-1 == iconv_result) if ((size_t)-1 == iconv_result)
{ {
if (EILSEQ == errno || EINVAL == errno) if (EILSEQ == errno || EINVAL == errno)

View File

@ -18,6 +18,8 @@
#include <mach/mach.h> #include <mach/mach.h>
#elif defined BSD4_4 || defined __FreeBSD__ || defined __OpenBSD__ #elif defined BSD4_4 || defined __FreeBSD__ || defined __OpenBSD__
#include <pthread_np.h> #include <pthread_np.h>
#elif defined __NetBSD__
#include <sched.h>
#elif defined __HAIKU__ #elif defined __HAIKU__
#include <OS.h> #include <OS.h>
#endif #endif
@ -119,7 +121,9 @@ void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
thread_policy_set(pthread_mach_thread_np(thread), THREAD_AFFINITY_POLICY, (integer_t*)&mask, 1); thread_policy_set(pthread_mach_thread_np(thread), THREAD_AFFINITY_POLICY, (integer_t*)&mask, 1);
#elif (defined __linux__ || defined BSD4_4 || defined __FreeBSD__) && !(defined ANDROID) #elif (defined __linux__ || defined BSD4_4 || defined __FreeBSD__ || defined __NetBSD__) && \
!(defined ANDROID)
#ifndef __NetBSD__
#ifdef __FreeBSD__ #ifdef __FreeBSD__
cpuset_t cpu_set; cpuset_t cpu_set;
#else #else
@ -132,6 +136,16 @@ void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
CPU_SET(i, &cpu_set); CPU_SET(i, &cpu_set);
pthread_setaffinity_np(thread, sizeof(cpu_set), &cpu_set); pthread_setaffinity_np(thread, sizeof(cpu_set), &cpu_set);
#else
cpuset_t* cpu_set = cpuset_create();
for (int i = 0; i != sizeof(mask) * 8; ++i)
if ((mask >> i) & 1)
cpuset_set(i, cpu_set);
pthread_setaffinity_np(thread, cpuset_size(cpu_set), cpu_set);
cpuset_destroy(cpu_set);
#endif
#endif #endif
} }
@ -156,6 +170,8 @@ void SetCurrentThreadName(const char* name)
pthread_setname_np(name); pthread_setname_np(name);
#elif defined __FreeBSD__ || defined __OpenBSD__ #elif defined __FreeBSD__ || defined __OpenBSD__
pthread_set_name_np(pthread_self(), name); pthread_set_name_np(pthread_self(), name);
#elif defined(__NetBSD__)
pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name));
#elif defined __HAIKU__ #elif defined __HAIKU__
rename_thread(find_thread(nullptr), name); rename_thread(find_thread(nullptr), name);
#else #else

View File

@ -383,7 +383,7 @@ private:
bool m_bba_link_up = false; bool m_bba_link_up = false;
bool m_bba_failure_notified = false; bool m_bba_failure_notified = false;
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ #if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) defined(__OpenBSD__) || defined(__NetBSD__)
sf::UdpSocket m_sf_socket; sf::UdpSocket m_sf_socket;
sf::IpAddress m_sf_recipient_ip; sf::IpAddress m_sf_recipient_ip;
char m_in_frame[9004]; char m_in_frame[9004];

View File

@ -15,7 +15,8 @@ typedef pollfd pollfd_t;
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
#elif defined(__linux__) or defined(__APPLE__) or defined(__FreeBSD__) or defined(__HAIKU__) #elif defined(__linux__) or defined(__APPLE__) or defined(__FreeBSD__) or defined(__NetBSD__) or \
defined(__HAIKU__)
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>

View File

@ -17,7 +17,7 @@
#include "Core/MachineContext.h" #include "Core/MachineContext.h"
#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/JitInterface.h"
#ifdef __FreeBSD__ #if defined(__FreeBSD__) || defined(__NetBSD__)
#include <signal.h> #include <signal.h>
#endif #endif
#ifndef _WIN32 #ifndef _WIN32

View File

@ -35,6 +35,8 @@ constexpr u32 m_os = OS_ALL | OS_LINUX;
constexpr u32 m_os = OS_ALL | OS_FREEBSD; constexpr u32 m_os = OS_ALL | OS_FREEBSD;
#elif __OpenBSD__ #elif __OpenBSD__
constexpr u32 m_os = OS_ALL | OS_OPENBSD; constexpr u32 m_os = OS_ALL | OS_OPENBSD;
#elif __NetBSD__
constexpr u32 m_os = OS_ALL | OS_NETBSD;
#endif #endif
static API m_api = API_OPENGL; static API m_api = API_OPENGL;

View File

@ -27,6 +27,7 @@ enum OS
OS_ANDROID = (1 << 4), OS_ANDROID = (1 << 4),
OS_FREEBSD = (1 << 5), OS_FREEBSD = (1 << 5),
OS_OPENBSD = (1 << 6), OS_OPENBSD = (1 << 6),
OS_NETBSD = (1 << 7),
}; };
// Enum of known vendors // Enum of known vendors
// Tegra and Nvidia are separated out due to such substantial differences // Tegra and Nvidia are separated out due to such substantial differences