Merge pull request #9309 from devnexen/netbsd_port

NetBSD support proposal.
This commit is contained in:
Léo Lam 2020-12-15 02:41:05 +01:00 committed by GitHub
commit dbf7c40886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 14 deletions

View File

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

View File

@ -35,12 +35,16 @@
constexpr u32 CODEPAGE_SHIFT_JIS = 932;
constexpr u32 CODEPAGE_WINDOWS_1252 = 1252;
#else
#if defined(__NetBSD__)
#define LIBICONV_PLUG
#endif
#include <errno.h>
#include <iconv.h>
#include <locale.h>
#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 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");
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
#else
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__)
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
locale_t previousLocale = uselocale(GetCLocale());
#endif
writtenCount = vsnprintf(out, outsize, format, args);
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__)
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
uselocale(previousLocale);
#endif
#endif
@ -174,7 +178,7 @@ std::string StringFromFormatV(const char* format, va_list args)
std::string temp = buf;
delete[] buf;
#else
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__)
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
locale_t previousLocale = uselocale(GetCLocale());
#endif
if (vasprintf(&buf, format, args) < 0)
@ -183,7 +187,7 @@ std::string StringFromFormatV(const char* format, va_list args)
buf = nullptr;
}
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__)
#if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
uselocale(previousLocale);
#endif
@ -524,8 +528,13 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v
while (src_bytes != 0)
{
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 (EILSEQ == errno || EINVAL == errno)

View File

@ -18,6 +18,8 @@
#include <mach/mach.h>
#elif defined BSD4_4 || defined __FreeBSD__ || defined __OpenBSD__
#include <pthread_np.h>
#elif defined __NetBSD__
#include <sched.h>
#elif defined __HAIKU__
#include <OS.h>
#endif
@ -119,7 +121,9 @@ void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
{
#ifdef __APPLE__
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__
cpuset_t cpu_set;
#else
@ -132,6 +136,16 @@ void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
CPU_SET(i, &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
}
@ -156,6 +170,8 @@ void SetCurrentThreadName(const char* name)
pthread_setname_np(name);
#elif defined __FreeBSD__ || defined __OpenBSD__
pthread_set_name_np(pthread_self(), name);
#elif defined(__NetBSD__)
pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name));
#elif defined __HAIKU__
rename_thread(find_thread(nullptr), name);
#else

View File

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

View File

@ -15,7 +15,8 @@ typedef pollfd pollfd_t;
#define MALLOC(x) HeapAlloc(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 <netdb.h>
#include <sys/ioctl.h>

View File

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

View File

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

View File

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