Skip to content

Commit

Permalink
Initial support for Haiku.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtl1979 committed Sep 23, 2024
1 parent 35ff22f commit b67da71
Show file tree
Hide file tree
Showing 24 changed files with 2,052 additions and 5 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(NETBSD TRUE)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
set(HAIKU TRUE)
endif()

if(APPLE)
include_directories(SYSTEM /usr/include/malloc)
enable_language(ASM)
Expand All @@ -74,6 +78,9 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/Posix)
elseif(FREEBSD OR NETBSD OR OPENBSD)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/FreeBSD)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/Posix)
elseif(HAIKU)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/Haiku)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/Posix)
else()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/Linux)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Platform/Posix)
Expand All @@ -98,7 +105,7 @@ else()
# gcc for powerpc64 doesn't like variable-length arrays allocated on stack
add_definitions("-DFORCE_USE_HEAP")
endif()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR HAIKU)
# This option has no effect in glibc version less than 2.20.
# Since glibc 2.20 _BSD_SOURCE is deprecated, this macro is recomended instead
add_definitions("-D_DEFAULT_SOURCE" "-D_GNU_SOURCE")
Expand Down Expand Up @@ -239,7 +246,7 @@ endif()

if(MINGW)
set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock")
elseif(APPLE OR OPENBSD OR ANDROID)
elseif(APPLE OR OPENBSD OR ANDROID OR HAIKU)
set(Boost_LIBRARIES "${Boost_LIBRARIES}")
elseif(NOT MSVC)
set(Boost_LIBRARIES "${Boost_LIBRARIES};rt")
Expand Down Expand Up @@ -294,7 +301,7 @@ else()
endif()
if(MINGW)
set(EXTRA_LIBRARIES mswsock;ws2_32;iphlpapi)
elseif(APPLE OR OPENBSD OR ANDROID)
elseif(APPLE OR OPENBSD OR ANDROID OR HAIKU)
set(EXTRA_LIBRARIES "")
elseif(FREEBSD)
set(EXTRA_LIBRARIES execinfo)
Expand Down
2 changes: 1 addition & 1 deletion external/miniupnpc/miniupnpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#endif
#endif

#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(MACOSX) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun)
#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(MACOSX) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__HAIKU__)
#define HAS_IP_MREQN
#endif

Expand Down
5 changes: 5 additions & 0 deletions external/miniupnpc/portlistingparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "portlistingparse.h"
#include "minixml.h"

#if defined(__HAIKU__)
/* rename our private function because Haiku already defines a atoui() function */
#define atoui atoui2
#endif

/* list of the elements */
static const struct {
const portMappingElt code;
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ elseif(ANDROID)
endif()
elseif(FREEBSD OR NETBSD OR OPENBSD)
file(GLOB_RECURSE System System/* Platform/FreeBSD/System/* Platform/Posix/System/*)
elseif(HAIKU)
file(GLOB_RECURSE System System/* Platform/Haiku/System/* Platform/Posix/System/*)
else()
file(GLOB_RECURSE System System/* Platform/Linux/System/* Platform/Posix/System/*)
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/Common/int-util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2024, The Talleo developers
//
// This file is part of Bytecoin.
//
Expand All @@ -23,6 +24,10 @@
#include <string.h>
#include <sys/param.h>

#if defined(__HAIKU__)
#include <ByteOrder.h>
#endif

#if defined(_MSC_VER)
#include <stdlib.h>

Expand Down
44 changes: 44 additions & 0 deletions src/Platform/Haiku/System/Context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2022-2024, The Talleo developers
//
// This file is part of Karbo.
//
// Karbo is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Karbo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Karbo. If not, see <http://www.gnu.org/licenses/>.

#include <string.h>
#include <sys/types.h>
#include "Context.h"

void
makecontext(uctx *ucp, void (*func)(void), intptr_t arg)
{
long *sp;

memset(&ucp->uc_mcontext, 0, sizeof ucp->uc_mcontext);
ucp->uc_mcontext.mc_rdi = (long)arg;
sp = (long*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(long);
sp -= 1;
sp = (void*)((uintptr_t)sp - (uintptr_t)sp%16); /* 16-align for OS X */
*--sp = 0; /* return address */
ucp->uc_mcontext.mc_rip = (long)func;
ucp->uc_mcontext.mc_rsp = (long)sp;
}

int
swapcontext(uctx *oucp, const uctx *ucp)
{
if(getcontext(oucp) == 0)
setcontext(ucp);
return 0;
}
103 changes: 103 additions & 0 deletions src/Platform/Haiku/System/Context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
//
// This file is part of Karbo.
//
// Karbo is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Karbo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Karbo. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#define setcontext(u) _setmcontext(&(u)->uc_mcontext)
#define getcontext(u) _getmcontext(&(u)->uc_mcontext)

#ifdef __cplusplus
extern "C" {
#endif
#include <signal.h>
#include <stdlib.h>

typedef struct mcontext mctx;
typedef struct ucontext uctx;

extern int swapcontext(uctx*, const uctx*);
extern void makecontext(uctx*, void(*)(void), intptr_t);
extern int _getmcontext(mctx*);
extern void _setmcontext(const mctx*);

struct mcontext {
/*
* The first 20 fields must match the definition of
* sigcontext. So that we can support sigcontext
* and ucontext_t at the same time.
*/
long mc_onstack; /* XXX - sigcontext compat. */
long mc_rdi; /* machine state (struct trapframe) */
long mc_rsi;
long mc_rdx;
long mc_rcx;
long mc_r8;
long mc_r9;
long mc_rax;
long mc_rbx;
long mc_rbp;
long mc_r10;
long mc_r11;
long mc_r12;
long mc_r13;
long mc_r14;
long mc_r15;
long mc_trapno;
long mc_addr;
long mc_flags;
long mc_err;
long mc_rip;
long mc_cs;
long mc_rflags;
long mc_rsp;
long mc_ss;

long mc_len; /* sizeof(mcontext_t) */
#define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */
#define _MC_FPFMT_XMM 0x10002
long mc_fpformat;
#define _MC_FPOWNED_NONE 0x20000 /* FP state not used */
#define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */
#define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */
long mc_ownedfp;
/*
* See <machine/fpu.h> for the internals of mc_fpstate[].
*/
long mc_fpstate[64];
long mc_spare[8];
};

struct ucontext {
/*
* Keep the order of the first two fields. Also,
* keep them the first two fields in the structure.
* This way we can have a union with struct
* sigcontext and ucontext_t. This allows us to
* support them both at the same time.
* note: the union is not defined, though.
*/
sigset_t uc_sigmask;
mctx uc_mcontext;

struct __ucontext *uc_link;
stack_t uc_stack;
int __spare__[8];
};

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit b67da71

Please sign in to comment.