From 2eb553fdb72d5605c3f17324580859127a93d674 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 10 Jun 2015 22:15:11 -0700 Subject: [PATCH 1/4] Fix FreeBSD build --- Source/Core/Common/FileUtil.cpp | 2 +- Source/Core/Common/MemoryUtil.cpp | 8 ++++++-- Source/Core/Common/Thread.cpp | 10 ++++++++-- Source/Core/Core/HW/EXI_DeviceEthernet.h | 2 +- Source/Core/Core/IPC_HLE/WII_Socket.h | 2 +- Source/Core/DolphinWX/CMakeLists.txt | 6 +++++- Source/Core/VideoBackends/OGL/CMakeLists.txt | 4 +++- Source/Core/VideoCommon/DriverDetails.cpp | 2 ++ Source/Core/VideoCommon/DriverDetails.h | 1 + 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 925e3f1ed3d3..4709c011b24f 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -42,7 +42,7 @@ #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif -#ifdef BSD4_4 +#if defined BSD4_4 || defined __FreeBSD__ #define stat64 stat #define fstat64 fstat #endif diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp index 510b258b09e0..c2befe56a66d 100644 --- a/Source/Core/Common/MemoryUtil.cpp +++ b/Source/Core/Common/MemoryUtil.cpp @@ -20,7 +20,7 @@ #include #include #include -#ifdef __APPLE__ +#if defined __APPLE__ || defined __FreeBSD__ #include #else #include @@ -256,11 +256,15 @@ size_t MemPhysical() memInfo.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&memInfo); return memInfo.ullTotalPhys; -#elif defined(__APPLE__) +#elif defined __APPLE__ || defined __FreeBSD__ int mib[2]; size_t physical_memory; mib[0] = CTL_HW; +#ifdef __APPLE__ mib[1] = HW_MEMSIZE; +#elif defined __FreeBSD__ + mib[1] = HW_REALMEM; +#endif size_t length = sizeof(size_t); sysctl(mib, 2, &physical_memory, &length, NULL, 0); return physical_memory; diff --git a/Source/Core/Common/Thread.cpp b/Source/Core/Common/Thread.cpp index fb091ee2a7f7..1e60fbb29f85 100644 --- a/Source/Core/Common/Thread.cpp +++ b/Source/Core/Common/Thread.cpp @@ -8,7 +8,7 @@ #ifdef __APPLE__ #include -#elif defined BSD4_4 +#elif defined BSD4_4 || defined __FreeBSD__ #include #endif @@ -94,8 +94,12 @@ 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 ANDROID) +#elif (defined __linux__ || defined BSD4_4 || defined __FreeBSD__) && !(defined ANDROID) +#ifdef __FreeBSD__ + cpuset_t cpu_set; +#else cpu_set_t cpu_set; +#endif CPU_ZERO(&cpu_set); for (int i = 0; i != sizeof(mask) * 8; ++i) @@ -125,6 +129,8 @@ void SetCurrentThreadName(const char* szThreadName) { #ifdef __APPLE__ pthread_setname_np(szThreadName); +#elif defined __FreeBSD__ + pthread_set_name_np(pthread_self(), szThreadName); #else pthread_setname_np(pthread_self(), szThreadName); #endif diff --git a/Source/Core/Core/HW/EXI_DeviceEthernet.h b/Source/Core/Core/HW/EXI_DeviceEthernet.h index db5e92bc43f0..465bf408939b 100644 --- a/Source/Core/Core/HW/EXI_DeviceEthernet.h +++ b/Source/Core/Core/HW/EXI_DeviceEthernet.h @@ -327,7 +327,7 @@ class CEXIETHERNET : public IEXIDevice DWORD mMtu; OVERLAPPED mReadOverlapped; static VOID CALLBACK ReadWaitCallback(PVOID lpParameter, BOOLEAN TimerFired); -#elif defined(__linux__) || defined(__APPLE__) +#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) int fd; std::thread readThread; std::atomic readEnabled; diff --git a/Source/Core/Core/IPC_HLE/WII_Socket.h b/Source/Core/Core/IPC_HLE/WII_Socket.h index a38d1bb60db2..edbb6ee60d71 100644 --- a/Source/Core/Core/IPC_HLE/WII_Socket.h +++ b/Source/Core/Core/IPC_HLE/WII_Socket.h @@ -15,7 +15,7 @@ typedef pollfd pollfd_t; #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) -#elif defined(__linux__) or defined(__APPLE__) +#elif defined(__linux__) or defined(__APPLE__) or defined(__FreeBSD__) #include #include #include diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index f378716dd2af..d9cdb9bd9b91 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -64,7 +64,11 @@ if(USE_X11) set(NOGUI_SRCS ${NOGUI_SRCS} X11Utils.cpp) endif() -set(WXLIBS ${wxWidgets_LIBRARIES} dl) +set(WXLIBS ${wxWidgets_LIBRARIES}) + +if(NOT CMAKE_SYSTEM_NAME MATCHES FreeBSD) + set(WXLIBS ${WXLIBS} dl) +endif() list(APPEND LIBS core uicommon) diff --git a/Source/Core/VideoBackends/OGL/CMakeLists.txt b/Source/Core/VideoBackends/OGL/CMakeLists.txt index 85964a3185fb..b4ece69de1ea 100644 --- a/Source/Core/VideoBackends/OGL/CMakeLists.txt +++ b/Source/Core/VideoBackends/OGL/CMakeLists.txt @@ -45,8 +45,10 @@ set(LIBS ${LIBS} videocommon SOIL common - dl ${X11_LIBRARIES}) +if(NOT CMAKE_SYSTEM_NAME MATCHES FreeBSD) + set(LIBS ${LIBS} dl) +endif() if(USE_EGL) set(LIBS ${LIBS} EGL) endif() diff --git a/Source/Core/VideoCommon/DriverDetails.cpp b/Source/Core/VideoCommon/DriverDetails.cpp index aa2e34d184cd..d3b1883cb3bb 100644 --- a/Source/Core/VideoCommon/DriverDetails.cpp +++ b/Source/Core/VideoCommon/DriverDetails.cpp @@ -30,6 +30,8 @@ namespace DriverDetails const u32 m_os = OS_ALL | OS_OSX; #elif __linux__ const u32 m_os = OS_ALL | OS_LINUX; +#elif __FreeBSD__ + const u32 m_os = OS_ALL | OS_FREEBSD; #endif static Vendor m_vendor = VENDOR_UNKNOWN; diff --git a/Source/Core/VideoCommon/DriverDetails.h b/Source/Core/VideoCommon/DriverDetails.h index 86fc2b04b63b..cdc5026dc2d3 100644 --- a/Source/Core/VideoCommon/DriverDetails.h +++ b/Source/Core/VideoCommon/DriverDetails.h @@ -14,6 +14,7 @@ namespace DriverDetails OS_LINUX = (1 << 2), OS_OSX = (1 << 3), OS_ANDROID = (1 << 4), + OS_FREEBSD = (1 << 5), }; // Enum of known vendors // Tegra and Nvidia are separated out due to such substantial differences From a6437f629c68169983bf61c2188b743937f19ff3 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 11 Jun 2015 00:44:37 -0700 Subject: [PATCH 2/4] Common: Use more portable invocation of shm_open --- Source/Core/Common/MemArena.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/MemArena.cpp b/Source/Core/Common/MemArena.cpp index 291a23ed1f15..31ed7f9c8f8c 100644 --- a/Source/Core/Common/MemArena.cpp +++ b/Source/Core/Common/MemArena.cpp @@ -63,7 +63,7 @@ void MemArena::GrabSHMSegment(size_t size) #else for (int i = 0; i < 10000; i++) { - std::string file_name = StringFromFormat("dolphinmem.%d", i); + std::string file_name = StringFromFormat("/dolphinmem.%d", i); fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); if (fd != -1) { From fff113b64ffbb673d803d18c28f833c7d2b6c02d Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 11 Jun 2015 23:34:16 -0700 Subject: [PATCH 3/4] Fix 64-bit FreeBSD build --- CMakeLists.txt | 1 + Source/Core/Core/MemTools.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 789060e8a65c..98d4a7bec359 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,7 @@ endif() if(NOT ENABLE_GENERIC) if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR + ${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR APPLE) if(_ARCH_64) set(_M_X86 1) diff --git a/Source/Core/Core/MemTools.cpp b/Source/Core/Core/MemTools.cpp index e028b40faad6..2c1f688d5b9a 100644 --- a/Source/Core/Core/MemTools.cpp +++ b/Source/Core/Core/MemTools.cpp @@ -18,6 +18,9 @@ #ifndef _M_GENERIC #include "Core/PowerPC/JitCommon/JitBase.h" #endif +#ifdef __FreeBSD__ +#include +#endif namespace EMM { @@ -256,7 +259,11 @@ static void sigsegv_handler(int sig, siginfo_t *info, void *raw_context) void InstallExceptionHandler() { stack_t signal_stack; +#ifdef __FreeBSD__ + signal_stack.ss_sp = (char*)malloc(SIGSTKSZ); +#else signal_stack.ss_sp = malloc(SIGSTKSZ); +#endif signal_stack.ss_size = SIGSTKSZ; signal_stack.ss_flags = 0; if (sigaltstack(&signal_stack, nullptr)) From ccb56ddf97dded3af5b2d6e3a41367f56ca7d672 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Mon, 20 Jul 2015 10:04:18 +0200 Subject: [PATCH 4/4] CFrame: Claim all keyboard events on OS X. --- Source/Core/DolphinWX/Frame.cpp | 14 ++++++++++++++ Source/Core/DolphinWX/Frame.h | 2 -- Source/Core/DolphinWX/FrameTools.cpp | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index b41cdbb4616c..d2b396aa3d1c 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -1068,6 +1068,20 @@ bool TASInputHasFocus() return false; } +void CFrame::OnKeyDown(wxKeyEvent& event) +{ + // On OS X, we claim all keyboard events while + // emulation is running to avoid wxWidgets sounding + // the system beep for unhandled key events when + // receiving pad/Wiimote keypresses which take an + // entirely different path through the HID subsystem. +#ifndef __APPLE__ + // On other platforms, we leave the key event alone + // so it can be passed on to the windowing system. + event.Skip(); +#endif +} + void CFrame::OnMouse(wxMouseEvent& event) { // next handlers are all for FreeLook, so we don't need to check them if disabled diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index 4460593497f1..abb712b3c1ed 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -320,8 +320,6 @@ class CFrame : public CRenderFrame void OnToggleWindow(wxCommandEvent& event); void OnKeyDown(wxKeyEvent& event); // Keyboard - void OnKeyUp(wxKeyEvent& event); - void OnMouse(wxMouseEvent& event); // Mouse void OnFocusChange(wxFocusEvent& event); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index d56a8486b2c0..a54677423db2 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -1046,6 +1046,7 @@ void CFrame::StartGame(const std::string& filename) m_RenderParent->SetFocus(); + wxTheApp->Bind(wxEVT_KEY_DOWN, &CFrame::OnKeyDown, this); wxTheApp->Bind(wxEVT_RIGHT_DOWN, &CFrame::OnMouse, this); wxTheApp->Bind(wxEVT_RIGHT_UP, &CFrame::OnMouse, this); wxTheApp->Bind(wxEVT_MIDDLE_DOWN, &CFrame::OnMouse, this);