Skip to content

Commit c11ed1a

Browse files
trungnt2910jessicah
andcommitted
Haiku: Add Haiku support for CoreCLR/PAL
This contains a part of the code required to build CoreCLR and get `paltests` to pass on Haiku. This commit covers `src/coreclr/pal/**`. Co-authored-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
1 parent bb61fb5 commit c11ed1a

File tree

23 files changed

+147
-36
lines changed

23 files changed

+147
-36
lines changed

src/coreclr/pal/inc/pal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ extern bool g_arm64_atomics_present;
126126
#endif // !_MSC_VER
127127
#endif // !THROW_DECL
128128

129-
#ifdef __sun
129+
#if defined(__sun) || defined(__HAIKU__)
130130
#define MATH_THROW_DECL
131131
#else
132132
#define MATH_THROW_DECL THROW_DECL
@@ -2651,6 +2651,8 @@ PALIMPORT BOOL PALAPI PAL_GetUnwindInfoSize(SIZE_T baseAddress, ULONG64 ehFrameH
26512651
#define PAL_CS_NATIVE_DATA_SIZE 96
26522652
#elif defined(__linux__) && defined(__riscv) && __riscv_xlen == 64
26532653
#define PAL_CS_NATIVE_DATA_SIZE 96
2654+
#elif defined(__HAIKU__) && defined(__x86_64__)
2655+
#define PAL_CS_NATIVE_DATA_SIZE 56
26542656
#else
26552657
#error PAL_CS_NATIVE_DATA_SIZE is not defined for this architecture
26562658
#endif
@@ -3960,7 +3962,9 @@ unsigned int __cdecl _rotr(unsigned int value, int shift)
39603962
PALIMPORT DLLEXPORT char * __cdecl PAL_getenv(const char *);
39613963
PALIMPORT DLLEXPORT int __cdecl _putenv(const char *);
39623964

3965+
#ifndef ERANGE
39633966
#define ERANGE 34
3967+
#endif
39643968

39653969
PALIMPORT WCHAR __cdecl PAL_ToUpperInvariant(WCHAR);
39663970
PALIMPORT WCHAR __cdecl PAL_ToLowerInvariant(WCHAR);

src/coreclr/pal/inc/rt/safecrt.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,6 @@ typedef int errno_t; /* standard */
112112
/* error codes */
113113
#if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED)
114114
#define _SECURECRT_ERRCODE_VALUES_DEFINED
115-
#if !defined(EINVAL)
116-
#define EINVAL 22
117-
#endif
118-
#if !defined(ERANGE)
119-
#define ERANGE 34
120-
#endif
121-
#if !defined(EILSEQ)
122-
#define EILSEQ 42
123-
#endif
124115
#if !defined(STRUNCATE)
125116
#define STRUNCATE 80
126117
#endif

src/coreclr/pal/src/arch/amd64/signalhandlerhelper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do
88
#include "pal/context.h"
99
#include "pal/signal.hpp"
1010
#include "pal/utils.h"
11+
12+
#if HAVE_SYS_UCONTEXT_H
1113
#include <sys/ucontext.h>
14+
#endif
1215

1316
/*++
1417
Function :

src/coreclr/pal/src/config.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#cmakedefine01 HAVE_AUXV_HWCAP_H
2424
#cmakedefine01 HAVE_SYS_PTRACE_H
2525
#cmakedefine01 HAVE_SYS_UCONTEXT_H
26-
#cmakedefine01 HAVE_SYS_USER_H
2726
#cmakedefine01 HAVE_SYS_MOUNT_H
2827
#cmakedefine01 HAVE_UCONTEXT_H
2928
#cmakedefine01 HAVE_GETAUXVAL

src/coreclr/pal/src/configure.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ check_include_files(sys/prctl.h HAVE_PRCTL_H)
4949
check_include_files("sys/auxv.h;asm/hwcap.h" HAVE_AUXV_HWCAP_H)
5050
check_include_files("sys/ptrace.h" HAVE_SYS_PTRACE_H)
5151
check_include_files("sys/ucontext.h" HAVE_SYS_UCONTEXT_H)
52-
check_include_files("sys/user.h" HAVE_SYS_USER_H)
5352
check_include_files("sys/mount.h" HAVE_SYS_MOUNT_H)
5453
check_include_files(ucontext.h HAVE_UCONTEXT_H)
5554
check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)

src/coreclr/pal/src/debug/debug.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SET_DEFAULT_DEBUG_CHANNEL(DEBUG); // some headers have code with asserts, so do
4545
#include <unistd.h>
4646
#elif defined(HAVE_TTRACE) // HAVE_PROCFS_CTL
4747
#include <sys/ttrace.h>
48-
#else // defined(HAVE_TTRACE)
48+
#elif HAVE_SYS_PTRACE_H
4949
#include <sys/ptrace.h>
5050
#endif // HAVE_PROCFS_CTL
5151
#if HAVE_VM_READ
@@ -635,7 +635,7 @@ PAL_CloseProcessMemory(
635635
PAL_ReadProcessMemory
636636
637637
Abstract
638-
Reads process memory.
638+
Reads process memory.
639639
640640
Parameter
641641
handle : from PAL_OpenProcessMemory
@@ -753,7 +753,7 @@ PAL_ProbeMemory(
753753

754754
flags = fcntl(fds[0], F_GETFL, 0);
755755
fcntl(fds[0], F_SETFL, flags | O_NONBLOCK);
756-
756+
757757
flags = fcntl(fds[1], F_GETFL, 0);
758758
fcntl(fds[1], F_SETFL, flags | O_NONBLOCK);
759759

src/coreclr/pal/src/exception/seh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ PAL_ERROR SEHEnable(CPalThread *pthrCurrent)
305305
{
306306
#if HAVE_MACH_EXCEPTIONS
307307
return pthrCurrent->EnableMachExceptions();
308-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun)
308+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__)
309309
return NO_ERROR;
310310
#else// HAVE_MACH_EXCEPTIONS
311311
#error not yet implemented
@@ -330,7 +330,7 @@ PAL_ERROR SEHDisable(CPalThread *pthrCurrent)
330330
{
331331
#if HAVE_MACH_EXCEPTIONS
332332
return pthrCurrent->DisableMachExceptions();
333-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun)
333+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__)
334334
return NO_ERROR;
335335
#else // HAVE_MACH_EXCEPTIONS
336336
#error not yet implemented

src/coreclr/pal/src/exception/signal.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do
4343
#include "pal/utils.h"
4444

4545
#include <string.h>
46-
#include <sys/ucontext.h>
4746
#include <sys/utsname.h>
4847
#include <unistd.h>
4948
#include <sys/mman.h>
5049

50+
#if HAVE_SYS_UCONTEXT_H
51+
#include <sys/ucontext.h>
52+
#endif // HAVE_SYS_UCONTEXT_H
5153

5254
#endif // !HAVE_MACH_EXCEPTIONS
5355
#include "pal/context.h"

src/coreclr/pal/src/file/file.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ SET_DEFAULT_DEBUG_CHANNEL(FILE); // some headers have code with asserts, so do t
3232
#include <sys/types.h>
3333
#include <sys/stat.h>
3434
#include <sys/param.h>
35-
#include <sys/mount.h>
3635
#include <errno.h>
3736
#include <limits.h>
3837

38+
#if HAVE_SYS_MOUNT_H
39+
#include <sys/mount.h>
40+
#endif
41+
3942
using namespace CorUnix;
4043

4144
int MaxWCharToAcpLengthFactor = 3;

src/coreclr/pal/src/include/pal/context.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ extern "C"
3333
/* A type to wrap the native context type, which is ucontext_t on some
3434
* platforms and another type elsewhere. */
3535
#if HAVE_UCONTEXT_T
36+
#if HAVE_UCONTEXT_H
3637
#include <ucontext.h>
38+
#endif // HAVE_UCONTEXT_H
3739

3840
typedef ucontext_t native_context_t;
3941
#else // HAVE_UCONTEXT_T
@@ -874,6 +876,41 @@ inline void *FPREG_Xstate_Hi16Zmm(const ucontext_t *uc, uint32_t *featureSize)
874876
*featureSize = sizeof(_STRUCT_ZMM_REG) * 16;
875877
return reinterpret_cast<void *>(&((_STRUCT_X86_AVX512_STATE64&)FPSTATE(uc)).__fpu_zmm16);
876878
}
879+
#elif defined(TARGET_HAIKU)
880+
881+
#define MCREG_Rbp(mc) ((mc).rbp)
882+
#define MCREG_Rip(mc) ((mc).rip)
883+
#define MCREG_Rsp(mc) ((mc).rsp)
884+
#define MCREG_Rsi(mc) ((mc).rsi)
885+
#define MCREG_Rdi(mc) ((mc).rdi)
886+
#define MCREG_Rbx(mc) ((mc).rbx)
887+
#define MCREG_Rdx(mc) ((mc).rdx)
888+
#define MCREG_Rcx(mc) ((mc).rcx)
889+
#define MCREG_Rax(mc) ((mc).rax)
890+
#define MCREG_R8(mc) ((mc).r8)
891+
#define MCREG_R9(mc) ((mc).r9)
892+
#define MCREG_R10(mc) ((mc).r10)
893+
#define MCREG_R11(mc) ((mc).r11)
894+
#define MCREG_R12(mc) ((mc).r12)
895+
#define MCREG_R13(mc) ((mc).r13)
896+
#define MCREG_R14(mc) ((mc).r14)
897+
#define MCREG_R15(mc) ((mc).r15)
898+
#define MCREG_EFlags(mc) ((mc).rflags)
899+
// Haiku: missing SegCs
900+
901+
#define FPSTATE(uc) ((uc)->uc_mcontext.fpu)
902+
#define FPREG_ControlWord(uc) FPSTATE(uc).fp_fxsave.control
903+
#define FPREG_StatusWord(uc) FPSTATE(uc).fp_fxsave.status
904+
#define FPREG_TagWord(uc) FPSTATE(uc).fp_fxsave.tag
905+
#define FPREG_MxCsr(uc) FPSTATE(uc).fp_fxsave.mxcsr
906+
#define FPREG_MxCsr_Mask(uc) FPSTATE(uc).fp_fxsave.mscsr_mask
907+
#define FPREG_ErrorOffset(uc) *(DWORD*) &(FPSTATE(uc).fp_fxsave.rip)
908+
#define FPREG_ErrorSelector(uc) *((WORD*) &(FPSTATE(uc).fp_fxsave.rip) + 2)
909+
#define FPREG_DataOffset(uc) *(DWORD*) &(FPSTATE(uc).fp_fxsave.rdp)
910+
#define FPREG_DataSelector(uc) *((WORD*) &(FPSTATE(uc).fp_fxsave.rdp) + 2)
911+
912+
#define FPREG_Xmm(uc, index) *(M128A*) &(FPSTATE(uc).fp_fxsave.xmm[index])
913+
#define FPREG_St(uc, index) *(M128A*) &(FPSTATE(uc).fp_fxsave.fp[index].value)
877914
#else //TARGET_OSX
878915

879916
// For FreeBSD, as found in x86/ucontext.h

0 commit comments

Comments
 (0)