diff --git a/common/unix.mk b/common/unix.mk index f836bdfc96..491801c37b 100644 --- a/common/unix.mk +++ b/common/unix.mk @@ -16,6 +16,14 @@ else ifeq (0,$(shell ld -ltbb -o /dev/null 2>/dev/null; echo $$?)) endif endif + +ifeq ($(shell uname -o),Haiku) + LIBS += -lroot -lnetwork -luuid +else + LIBS += -ldl +endif + + OBJDIRBASE := obj/$(BUILD) OBJDIR := $(OBJDIRBASE)/o/o/o diff --git a/library/unix/build.mk b/library/unix/build.mk index 9fa7c5385b..5ac6a48cda 100644 --- a/library/unix/build.mk +++ b/library/unix/build.mk @@ -2,7 +2,7 @@ CFLAGS += CXXFLAGS := $(CFLAGS) -std=c++11 -fpic DEFINES += -DTRACY_ENABLE INCLUDES := -LIBS := -lpthread -ldl +LIBS := -lpthread PROJECT := libtracy IMAGE := $(PROJECT)-$(BUILD).so SHARED_LIBRARY := yes diff --git a/nfd/nfd_haiku.cpp b/nfd/nfd_haiku.cpp new file mode 100644 index 0000000000..c8c0b316ee --- /dev/null +++ b/nfd/nfd_haiku.cpp @@ -0,0 +1,80 @@ +#include "nfd.h" + +#include +#include +#include +#include + +nfdresult_t NFD_Init(void) { + return NFD_OKAY; +} + +void NFD_Quit(void) {} + +static nfdresult_t dialog(BFilePanel &p, nfdnchar_t **outPath, + const nfdnfilteritem_t *filterList, + nfdfiltersize_t filterCount) { + p.Show(); + while (p.IsShowing()) + usleep(100000); + entry_ref sel; + if (p.GetNextSelectedRef(&sel) == B_OK) { + BEntry e(&sel); + BPath path; + if (e.GetPath(&path) == B_OK) { + outPath[0] = strdup(path.Path()); + return NFD_OKAY; + } + } + return NFD_CANCEL; +} + +class NFDFilter : public BRefFilter { + const nfdnfilteritem_t * _filter; + nfdfiltersize_t _count; +public: + NFDFilter(const nfdnfilteritem_t *filterList, nfdfiltersize_t filterCount) + : _filter(filterList) + , _count(filterCount) {} + + bool Filter(const entry_ref *ref, BNode *node, struct stat_beos *stat, + const char *mimeType) override { + BString name(ref->name); + if (node->IsDirectory()) + return true; + for (auto i = 0; i < _count; i++) + if (name.EndsWith(_filter[0].spec)) + return true; + return false; + } +}; + +nfdresult_t +NFD_OpenDialogN(nfdnchar_t **outPath, const nfdnfilteritem_t *filterList, + nfdfiltersize_t filterCount, const nfdnchar_t *defaultPath) { + NFDFilter f(filterList, filterCount); + BFilePanel p(B_OPEN_PANEL, NULL, NULL, 0, false, NULL, &f, true, true); + p.Window()->SetTitle(filterList[0].name); + if (defaultPath) + p.SetPanelDirectory(defaultPath); + return dialog(p, outPath, filterList, filterCount); +} + +nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, + const nfdnfilteritem_t* filterList, + nfdfiltersize_t filterCount, + const nfdnchar_t* defaultPath, + const nfdnchar_t* defaultName) { + NFDFilter f(filterList, filterCount); + BFilePanel p(B_SAVE_PANEL, NULL, NULL, 0, false, NULL, &f, true, true); + p.Window()->SetTitle(filterList[0].name); + if (defaultPath) + p.SetPanelDirectory(defaultPath); + if (defaultName) + p.SetSaveText(defaultName); + return dialog(p, outPath, filterList, filterCount); +} + +void NFD_FreePathN(nfdnchar_t* filePath) { + free(filePath); +} diff --git a/nfd/nfd_portal.cpp b/nfd/nfd_portal.cpp index 23e1f1f44e..0db2bb388b 100644 --- a/nfd/nfd_portal.cpp +++ b/nfd/nfd_portal.cpp @@ -16,7 +16,20 @@ #include #include // for access() -#if !defined(__has_include) || !defined(__linux__) +#if defined __HAIKU__ +#include +static inline size_t szmin(size_t a, size_t b) { + return a < b? a : b; +} +static inline ssize_t getrandom(unsigned char * buf, size_t buflen, unsigned int flags) { + for (size_t i = 0; i < buflen; i += sizeof(uuid_t)) { + uuid_t uuid; + uuid_generate_random(uuid); + memcpy(buf+i, uuid, szmin(buflen-i, sizeof(uuid))); + } + return buflen; +} +#elif !defined(__has_include) || !defined(__linux__) #include // for getrandom() - the random token string #elif __has_include() #include diff --git a/profiler/build/unix/build.mk b/profiler/build/unix/build.mk index 42a9ba0ad1..153dfb91ec 100644 --- a/profiler/build/unix/build.mk +++ b/profiler/build/unix/build.mk @@ -2,7 +2,7 @@ CFLAGS += CXXFLAGS := $(CFLAGS) -std=c++17 DEFINES += -DIMGUI_ENABLE_FREETYPE INCLUDES := -I../../../imgui $(shell pkg-config --cflags freetype2 capstone wayland-egl egl wayland-cursor xkbcommon) -LIBS := $(shell pkg-config --libs freetype2 capstone wayland-egl egl wayland-cursor xkbcommon) -lpthread -ldl +LIBS := $(shell pkg-config --libs freetype2 capstone wayland-egl egl wayland-cursor xkbcommon) -lpthread PROJECT := Tracy IMAGE := $(PROJECT)-$(BUILD) @@ -21,9 +21,14 @@ else INCLUDES += $(shell pkg-config --cflags gtk+-3.0) LIBS += $(shell pkg-config --libs gtk+-3.0) else - SRC += ../../../nfd/nfd_portal.cpp - INCLUDES += $(shell pkg-config --cflags dbus-1) - LIBS += $(shell pkg-config --libs dbus-1) + ifeq ($(shell uname -o),Haiku) + SRC += ../../../nfd/nfd_haiku.cpp + LIBS += -lbe -ltracker + else + SRC += ../../../nfd/nfd_portal.cpp + INCLUDES += $(shell pkg-config --cflags dbus-1) + LIBS += $(shell pkg-config --libs dbus-1) + endif endif endif diff --git a/profiler/build/unix/debug.mk b/profiler/build/unix/debug.mk index d9b31daf42..2afc422dc0 100644 --- a/profiler/build/unix/debug.mk +++ b/profiler/build/unix/debug.mk @@ -1,4 +1,5 @@ CFLAGS := -g3 -Wall +LDFLAGS := -g3 DEFINES := -DDEBUG BUILD := debug diff --git a/profiler/build/unix/legacy.mk b/profiler/build/unix/legacy.mk index dc2923c89c..f2410c7ade 100644 --- a/profiler/build/unix/legacy.mk +++ b/profiler/build/unix/legacy.mk @@ -2,7 +2,7 @@ CFLAGS += CXXFLAGS := $(CFLAGS) -std=c++17 DEFINES += -DIMGUI_ENABLE_FREETYPE INCLUDES := -I../../../imgui $(shell pkg-config --cflags glfw3 freetype2 capstone) -LIBS := $(shell pkg-config --libs glfw3 freetype2 capstone) -lpthread -ldl +LIBS := $(shell pkg-config --libs glfw3 freetype2 capstone) -lpthread PROJECT := Tracy IMAGE := $(PROJECT)-$(BUILD) @@ -23,9 +23,14 @@ else INCLUDES += $(shell pkg-config --cflags gtk+-3.0) LIBS += $(shell pkg-config --libs gtk+-3.0) else - SRC += ../../../nfd/nfd_portal.cpp - INCLUDES += $(shell pkg-config --cflags dbus-1) - LIBS += $(shell pkg-config --libs dbus-1) + ifeq ($(shell uname -o),Haiku) + SRC += ../../../nfd/nfd_haiku.cpp + LIBS += -lbe -ltracker + else + SRC += ../../../nfd/nfd_portal.cpp + INCLUDES += $(shell pkg-config --cflags dbus-1) + LIBS += $(shell pkg-config --libs dbus-1) + endif endif endif endif diff --git a/profiler/src/HttpRequest.cpp b/profiler/src/HttpRequest.cpp index 62181b447a..e3b81d83e5 100644 --- a/profiler/src/HttpRequest.cpp +++ b/profiler/src/HttpRequest.cpp @@ -68,6 +68,8 @@ static const char* GetOsInfo() sprintf( buf, "BSD (OpenBSD)" ); #elif defined __QNX__ sprintf( buf, "QNX" ); +#elif defined __HAIKU__ + sprintf( buf, "Haiku" ); #else sprintf( buf, "unknown" ); #endif diff --git a/profiler/src/imgui/imgui_impl_glfw.cpp b/profiler/src/imgui/imgui_impl_glfw.cpp index 211acc8d71..762aa81f72 100644 --- a/profiler/src/imgui/imgui_impl_glfw.cpp +++ b/profiler/src/imgui/imgui_impl_glfw.cpp @@ -117,7 +117,11 @@ #endif #define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwFocusWindow #define GLFW_HAS_FOCUS_ON_SHOW (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_FOCUS_ON_SHOW +#if defined __HAIKU__ +#define GLFW_HAS_MONITOR_WORK_AREA 0 // Crashes +#else #define GLFW_HAS_MONITOR_WORK_AREA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetMonitorWorkarea +#endif #define GLFW_HAS_OSX_WINDOW_POS_FIX (GLFW_VERSION_COMBINED >= 3301) // 3.3.1+ Fixed: Resizing window repositions it on MacOS #1553 #ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released? #define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR diff --git a/profiler/src/imgui/imgui_impl_opengl3_loader.h b/profiler/src/imgui/imgui_impl_opengl3_loader.h index 9aefdb7c41..616d1b4e34 100644 --- a/profiler/src/imgui/imgui_impl_opengl3_loader.h +++ b/profiler/src/imgui/imgui_impl_opengl3_loader.h @@ -685,7 +685,13 @@ static int open_libgl(void) libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL); if (!libgl) return GL3W_ERROR_LIBRARY_OPEN; - *(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB"); + *(void **)(&glx_get_proc_address) = dlsym(libgl, +#if defined __HAIKU__ + "_glapi_get_proc_address" +#else + "glXGetProcAddressARB" +#endif + ); return GL3W_OK; } diff --git a/public/client/TracyCallstack.h b/public/client/TracyCallstack.h index 2c7ecad9f3..8e9a8de7f1 100644 --- a/public/client/TracyCallstack.h +++ b/public/client/TracyCallstack.h @@ -28,6 +28,8 @@ # define TRACY_HAS_CALLSTACK 4 # elif defined BSD # define TRACY_HAS_CALLSTACK 6 +# elif defined __HAIKU__ +# define TRACY_HAS_CALLSTACK 2 # endif #endif diff --git a/public/client/TracyOverride.cpp b/public/client/TracyOverride.cpp index 591508a7ff..f26dec6123 100644 --- a/public/client/TracyOverride.cpp +++ b/public/client/TracyOverride.cpp @@ -1,5 +1,5 @@ #ifdef TRACY_ENABLE -# ifdef __linux__ +# if defined __linux__ || defined __HAIKU__ # include "TracyDebug.hpp" # ifdef TRACY_VERBOSE # include diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index ebdc83dcc2..c4504861dc 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -90,7 +90,7 @@ # endif #endif -#ifdef __APPLE__ +#if defined __APPLE__ || defined __HAIKU__ # ifndef TRACY_DELAYED_INIT # define TRACY_DELAYED_INIT # endif @@ -418,10 +418,31 @@ static const char* GetProcessName() if( buf ) processName = buf; #elif defined __QNX__ processName = __progname; +#elif defined __HAIKU__ + team_info ti; + get_team_info(B_CURRENT_TEAM, &ti); + static char name[B_OS_NAME_LENGTH]; + memcpy(name, ti.name, sizeof(name)); + processName = name; #endif return processName; } + +#if defined __HAIKU__ +#include +static char executable_path[MAXPATHLEN]; + +extern "C" void +initialize_before(image_id our_image) +{ + image_info ii; + get_image_info(our_image, &ii); + snprintf(executable_path, sizeof(executable_path), "%s", ii.name); +} +#endif + + static const char* GetProcessExecutablePath() { #ifdef _WIN32 @@ -459,6 +480,8 @@ static const char* GetProcessExecutablePath() static char buf[_PC_PATH_MAX + 1]; _cmdname(buf); return buf; +#elif defined __HAIKU__ + return executable_path; #else return nullptr; #endif @@ -539,6 +562,8 @@ static const char* GetHostInfo() ptr += sprintf( ptr, "OS: BSD (OpenBSD)\n" ); #elif defined __QNX__ ptr += sprintf( ptr, "OS: QNX\n" ); +#elif defined __HAIKU__ + ptr += sprintf( ptr, "OS: Haiku\n" ); #else ptr += sprintf( ptr, "OS: unknown\n" ); #endif @@ -726,6 +751,11 @@ static const char* GetHostInfo() } memSize = memSize / 1024 / 1024; ptr += sprintf( ptr, "RAM: %llu MB\n", memSize); +#elif defined __HAIKU__ + system_info si; + get_system_info(&si); + size_t memSize = si.max_pages * PAGESIZE; + ptr += sprintf( ptr, "RAM: %zu MB\n", memSize / 1024 / 1024); #else ptr += sprintf( ptr, "RAM: unknown\n" ); #endif diff --git a/public/client/TracyRingBuffer.hpp b/public/client/TracyRingBuffer.hpp index e9100e2d8b..17fb057959 100644 --- a/public/client/TracyRingBuffer.hpp +++ b/public/client/TracyRingBuffer.hpp @@ -1,7 +1,9 @@ #include #include #include +#if !defined __HAIKU__ #include +#endif #include #include #include diff --git a/public/client/TracySysTime.cpp b/public/client/TracySysTime.cpp index b690a91148..24100a49e5 100644 --- a/public/client/TracySysTime.cpp +++ b/public/client/TracySysTime.cpp @@ -78,6 +78,25 @@ void SysTime::ReadTimes() idle = data[4]; } +# elif defined __HAIKU__ + +void SysTime::ReadTimes() +{ + bigtime_t now = system_time(); + system_info si; + get_system_info(&si); + cpu_info ci[256]; + get_cpu_info(0, si.cpu_count, ci); + bigtime_t tot = 0; + for (uint32 i = 0; i < si.cpu_count; i++) + tot += ci[i].active_time; + used = tot / si.cpu_count; + static bigtime_t prev; + bigtime_t interval = now - prev; + idle = interval - used; + prev = now; +} + #endif SysTime::SysTime() @@ -97,7 +116,7 @@ float SysTime::Get() #if defined _WIN32 return diffUsed == 0 ? -1 : ( diffUsed - diffIdle ) * 100.f / diffUsed; -#elif defined __linux__ || defined __APPLE__ || defined BSD +#elif defined __linux__ || defined __APPLE__ || defined BSD || defined __HAIKU__ const auto total = diffUsed + diffIdle; return total == 0 ? -1 : diffUsed * 100.f / total; #endif diff --git a/public/client/TracySysTime.hpp b/public/client/TracySysTime.hpp index cb5ebe7361..e7fca3fbf9 100644 --- a/public/client/TracySysTime.hpp +++ b/public/client/TracySysTime.hpp @@ -1,7 +1,7 @@ #ifndef __TRACYSYSTIME_HPP__ #define __TRACYSYSTIME_HPP__ -#if defined _WIN32 || defined __linux__ || defined __APPLE__ +#if defined _WIN32 || defined __linux__ || defined __APPLE__ || defined __HAIKU__ # define TRACY_HAS_SYSTIME #else # include diff --git a/public/common/TracySocket.cpp b/public/common/TracySocket.cpp index 259678989e..f82648f260 100644 --- a/public/common/TracySocket.cpp +++ b/public/common/TracySocket.cpp @@ -37,6 +37,10 @@ # define MSG_NOSIGNAL 0 #endif +#if defined __HAIKU__ +#define TRACY_ONLY_IPV4 +#endif + namespace tracy { @@ -492,7 +496,7 @@ bool ListenSocket::Listen( uint16_t port, int backlog ) #if defined _WIN32 unsigned long val = 0; setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) ); -#elif defined BSD +#elif defined BSD || defined __HAIKU__ int val = 0; setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) ); val = 1; diff --git a/public/common/TracySystem.cpp b/public/common/TracySystem.cpp index 0e26aecae3..77b66d4460 100644 --- a/public/common/TracySystem.cpp +++ b/public/common/TracySystem.cpp @@ -31,6 +31,8 @@ #elif defined __QNX__ # include # include +#elif defined __HAIKU__ +# include #endif #ifdef __MINGW32__ @@ -86,6 +88,8 @@ TRACY_API uint32_t GetThreadHandleImpl() #elif defined __EMSCRIPTEN__ // Not supported, but let it compile. return 0; +#elif defined __HAIKU__ + return find_thread(0); #else // To add support for a platform, retrieve and return the kernel thread identifier here. // @@ -196,6 +200,8 @@ TRACY_API void SetThreadName( const char* name ) pthread_setname_np( pthread_self(), buf ); } }; +#elif defined __HAIKU__ + rename_thread(find_thread(0), name); #endif #ifdef TRACY_ENABLE { @@ -280,6 +286,10 @@ TRACY_API const char* GetThreadName( uint32_t id ) if (pthread_getname_np(static_cast(id), qnxNameBuf, _NTO_THREAD_NAME_MAX) == 0) { return qnxNameBuf; }; +#elif defined __HAIKU__ + thread_info ti; + get_thread_info(find_thread(NULL), &ti); + snprintf(buf, sizeof(buf), "%s", ti.name); #endif sprintf( buf, "%" PRIu32, id ); diff --git a/public/libbacktrace/config.h b/public/libbacktrace/config.h index 87e38a95b5..e22b3b0208 100644 --- a/public/libbacktrace/config.h +++ b/public/libbacktrace/config.h @@ -3,6 +3,12 @@ // include __WORDSIZE headers for musl # include #endif + +#ifdef __HAIKU__ +# include +# define __WORDSIZE __HAIKU_ARCH_BITS +#endif + #if __WORDSIZE == 64 # define BACKTRACE_ELF_SIZE 64 #else diff --git a/public/libbacktrace/elf.cpp b/public/libbacktrace/elf.cpp index 22a4ba2025..405a175999 100644 --- a/public/libbacktrace/elf.cpp +++ b/public/libbacktrace/elf.cpp @@ -71,6 +71,10 @@ POSSIBILITY OF SUCH DAMAGE. */ #endif #endif +#ifdef __HAIKU__ +# define ElfW(x) Elf_##x +#endif + namespace tracy { diff --git a/server/TracyFileRead.hpp b/server/TracyFileRead.hpp index dec67e9cbe..aa8b8e664e 100644 --- a/server/TracyFileRead.hpp +++ b/server/TracyFileRead.hpp @@ -16,7 +16,7 @@ #ifdef _MSC_VER # define stat64 _stat64 #endif -#if defined __APPLE__ || defined __FreeBSD__ +#if defined __APPLE__ || defined __FreeBSD__ || defined __HAIKU__ # define stat64 stat #endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 3584615ae7..5f4d8629be 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -31,6 +31,8 @@ #elif defined __APPLE__ || defined BSD # include # include +#elif defined __HAIKU__ +# include #endif #include "IconsFontAwesome6.h" @@ -141,6 +143,10 @@ void View::InitMemory() size_t sz = sizeof( memSize ); sysctlbyname( "hw.physmem", &memSize, &sz, nullptr, 0 ); m_totalMemory = memSize; +#elif defined __HAIKU__ + system_info sysInfo; + get_system_info(&sysInfo); + m_totalMemory = sysInfo.max_pages * PAGESIZE; #else m_totalMemory = 0; #endif diff --git a/server/TracyWeb.cpp b/server/TracyWeb.cpp index 91986f8c4b..1250089dcb 100644 --- a/server/TracyWeb.cpp +++ b/server/TracyWeb.cpp @@ -17,7 +17,7 @@ void OpenWebpage( const char* url ) { #ifdef _WIN32 ShellExecuteA( nullptr, nullptr, url, nullptr, nullptr, 0 ); -#elif defined __APPLE__ +#elif defined __APPLE__ || defined __HAIKU__ char buf[1024]; sprintf( buf, "open %s", url ); system( buf ); diff --git a/test/Makefile b/test/Makefile index 19b3438413..9f714b93fb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,12 @@ CFLAGS := $(OPTFLAGS) -Wall -DTRACY_ENABLE CXXFLAGS := $(CFLAGS) -std=gnu++11 DEFINES += INCLUDES := -I../public/tracy -LIBS := -lpthread -ldl +LIBS := -lpthread +ifeq ($(shell uname -o),Haiku) +LIBS += -lroot -lnetwork -lbsd +else +LIBS += -ldl +endif LDFLAGS := -rdynamic IMAGE := tracy_test diff --git a/update/src/update.cpp b/update/src/update.cpp index 0665043647..fe587b81a1 100644 --- a/update/src/update.cpp +++ b/update/src/update.cpp @@ -17,7 +17,7 @@ #include "OfflineSymbolResolver.h" -#ifdef __APPLE__ +#if defined __APPLE__ || defined __HAIKU__ # define ftello64(x) ftello(x) #elif defined _WIN32 # define ftello64(x) _ftelli64(x)