From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 24 Feb 2022 01:00:57 +0330 Subject: [PATCH] Teach os_dep and gcconfig.h about serenity --- include/private/gcconfig.h | 48 +++++++++++++++++++++++++++++++++++--- os_dep.c | 34 ++++++++++++++++++++------- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 1979c58..e9d1d42 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -351,6 +351,15 @@ EXTERN_C_BEGIN # define HAIKU # define mach_type_known # endif +# if defined(__serenity__) +# define SERENITY +# define mach_type_known +# if defined(_X86_) || defined (__i386__) +# define I386 +# elif defined(__x86_64__) +# define X86_64 +# endif +#endif # if defined(__HAIKU__) && (defined(__amd64__) || defined(__x86_64__)) # define X86_64 # define HAIKU @@ -1377,6 +1386,22 @@ EXTERN_C_BEGIN # define DYNAMIC_LOADING # define MPROTECT_VDB # endif +# ifdef SERENITY +# define OS_TYPE "SERENITY" + EXTERN_C_END +# include + EXTERN_C_BEGIN +# define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE) + extern int etext[], _end[]; +# define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff)) +# define DATAEND ((ptr_t)(_end)) +# define DYNAMIC_LOADING +# define MPROTECT_VDB +# define USE_MMAP_ANON +# ifndef USE_MMAP +# define USE_MMAP 1 +# endif +# endif # ifdef SOLARIS # define OS_TYPE "SOLARIS" extern int _etext[], _end[]; @@ -2727,6 +2752,23 @@ EXTERN_C_BEGIN # define DYNAMIC_LOADING # define MPROTECT_VDB # endif +# ifdef SERENITY +# define OS_TYPE "SERENITY" + EXTERN_C_END +# include + EXTERN_C_BEGIN +# define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE) +# define HEURISTIC2 + extern int etext[], _end[]; +# define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff)) +# define DATAEND ((ptr_t)(_end)) +# define DYNAMIC_LOADING +# define MPROTECT_VDB +# define USE_MMAP_ANON +# ifndef USE_MMAP +# define USE_MMAP 1 +# endif +# endif # ifdef SOLARIS # define OS_TYPE "SOLARIS" # define ELF_CLASS ELFCLASS64 @@ -3068,7 +3110,7 @@ EXTERN_C_BEGIN #if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \ || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \ || defined(DGUX) || defined(BSD) || defined(HAIKU) || defined(HURD) \ - || defined(AIX) || defined(DARWIN) || defined(OSF1) + || defined(AIX) || defined(DARWIN) || defined(OSF1) || defined(SERENITY) # define UNIX_LIKE /* Basic Unix-like system calls work. */ #endif @@ -3118,7 +3160,7 @@ EXTERN_C_BEGIN #if defined(DARWIN) || defined(FREEBSD) || defined(HAIKU) \ || defined(IRIX5) || defined(LINUX) || defined(NETBSD) \ - || defined(OPENBSD) || defined(SOLARIS) \ + || defined(OPENBSD) || defined(SOLARIS) || defined(SERENITY) \ || ((defined(CYGWIN32) || defined(USE_MMAP) || defined(USE_MUNMAP)) \ && !defined(USE_WINALLOC)) /* Try both sbrk and mmap, in that order. */ @@ -3223,7 +3265,7 @@ EXTERN_C_BEGIN #if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HAIKU) \ || defined(HURD) || defined(OPENBSD) \ - || defined(ARM32) \ + || defined(ARM32) || defined(SERENITY) \ || defined(AVR32) || defined(MIPS) \ || defined(NIOS2) || defined(OR1K))) \ || (defined(LINUX) && !defined(__gnu_linux__)) \ diff --git a/os_dep.c b/os_dep.c index b183423..a6d62b9 100644 --- a/os_dep.c +++ b/os_dep.c @@ -845,6 +845,22 @@ GC_INNER size_t GC_page_size = 0; # define HAVE_GET_STACK_BASE #endif /* HAIKU */ +#ifdef SERENITY +# include + GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb) + { + uintptr_t base; + size_t size; + if (get_stack_bounds(&base, &size) < 0) { + WARN("get_stack_bounds failed\n", 0); + return GC_UNIMPLEMENTED; + } + sb->mem_base = base + size; + return GC_SUCCESS; + } +# define HAVE_GET_STACK_BASE +#endif /* SERENITY */ + #ifdef OS2 GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb) { @@ -873,7 +889,7 @@ GC_INNER size_t GC_page_size = 0; # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \ || defined(HAIKU) || defined(HURD) || defined(FREEBSD) \ - || defined(NETBSD) + || defined(NETBSD) || defined(SERENITY) static struct sigaction old_segv_act; # if defined(_sigargs) /* !Irix6.x */ \ || defined(HURD) || defined(NETBSD) || defined(FREEBSD) @@ -890,7 +906,7 @@ GC_INNER size_t GC_page_size = 0; { # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \ || defined(HAIKU) || defined(HURD) || defined(FREEBSD) \ - || defined(NETBSD) + || defined(NETBSD) || defined(SERENITY) struct sigaction act; act.sa_handler = h; @@ -955,7 +971,7 @@ GC_INNER size_t GC_page_size = 0; { # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \ || defined(HAIKU) || defined(HURD) || defined(FREEBSD) \ - || defined(NETBSD) + || defined(NETBSD) || defined(SERENITY) (void) sigaction(SIGSEGV, &old_segv_act, 0); # if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \ || defined(HURD) || defined(NETBSD) @@ -1227,7 +1243,7 @@ GC_INNER size_t GC_page_size = 0; # define GET_MAIN_STACKBASE_SPECIAL #elif !defined(AMIGA) && !defined(HAIKU) && !defined(OS2) \ && !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32) \ - && !defined(GC_OPENBSD_THREADS) \ + && !defined(GC_OPENBSD_THREADS) && !defined(SERENITY) \ && (!defined(GC_SOLARIS_THREADS) || defined(_STRICT_STDC)) # if (defined(HAVE_PTHREAD_ATTR_GET_NP) || defined(HAVE_PTHREAD_GETATTR_NP)) \ @@ -1328,7 +1344,7 @@ GC_INNER size_t GC_page_size = 0; return(result); } # define GET_MAIN_STACKBASE_SPECIAL -#endif /* !AMIGA, !HAIKU, !OPENBSD, !OS2, !Windows */ +#endif /* !AMIGA, !HAIKU, !OPENBSD, !SERENITY, !OS2, !Windows */ #if (defined(HAVE_PTHREAD_ATTR_GET_NP) || defined(HAVE_PTHREAD_GETATTR_NP)) \ && defined(THREADS) && !defined(HAVE_GET_STACK_BASE) @@ -2584,7 +2600,7 @@ GC_INNER void GC_unmap(ptr_t start, size_t bytes) /* accidentally grabbing the same address space. */ { # if defined(AIX) || defined(CYGWIN32) || defined(HAIKU) \ - || defined(HPUX) + || defined(HPUX) || defined(SERENITY) /* On AIX, mmap(PROT_NONE) fails with ENOMEM unless the */ /* environment variable XPG_SUS_ENV is set to ON. */ /* On Cygwin, calling mmap() with the new protection flags on */ @@ -2715,7 +2731,7 @@ GC_INNER void GC_unmap_gap(ptr_t start1, size_t bytes1, ptr_t start2, if (len != 0) { /* Immediately remap as above. */ # if defined(AIX) || defined(CYGWIN32) || defined(HAIKU) \ - || defined(HPUX) + || defined(HPUX) || defined(SERENITY) if (mprotect(start_addr, len, PROT_NONE)) ABORT("mprotect(PROT_NONE) failed"); # else @@ -3035,7 +3051,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) # elif !defined(USE_WINALLOC) # include # include -# if !defined(CYGWIN32) && !defined(HAIKU) +# if !defined(CYGWIN32) && !defined(HAIKU) && !defined(SERENITY) # include # endif @@ -3160,7 +3176,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) # define CODE_OK (si -> si_code == 2 /* experimentally determined */) # elif defined(IRIX5) # define CODE_OK (si -> si_code == EACCES) -# elif defined(CYGWIN32) || defined(HAIKU) || defined(HURD) +# elif defined(CYGWIN32) || defined(HAIKU) || defined(HURD) || defined(SERENITY) # define CODE_OK TRUE # elif defined(LINUX) # define CODE_OK TRUE