1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
Date: Mon, 27 Mar 2023 20:03:03 +1100
Subject: [PATCH] Teach os_dep and gcconfig.h about serenity
---
include/private/gcconfig.h | 32 +++++++++++++++++++++++++++++---
os_dep.c | 32 ++++++++++++++++++++++++--------
2 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
index 2de01af..8e9fb29 100644
--- a/include/private/gcconfig.h
+++ b/include/private/gcconfig.h
@@ -337,6 +337,15 @@ EXTERN_C_BEGIN
# endif
# 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(__BEOS__) || defined(__HAIKU__)) && defined(_X86_)
# define I386
# define HAIKU
@@ -1058,6 +1067,23 @@ EXTERN_C_BEGIN
# endif
# endif /* OPENBSD */
+# ifdef SERENITY
+# define OS_TYPE "SERENITY"
+ EXTERN_C_END
+# include <unistd.h>
+ 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[];
@@ -2703,7 +2729,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
@@ -2753,7 +2779,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. */
@@ -2880,7 +2906,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 eaf5bb0..afd73f7 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -854,6 +854,22 @@ GC_INNER size_t GC_page_size = 0;
# define HAVE_GET_STACK_BASE
#endif /* HAIKU */
+#ifdef SERENITY
+# include <serenity.h>
+ 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)
{
@@ -882,7 +898,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(HPUX) \
|| defined(HURD) || defined(NETBSD) || defined(FREEBSD)
@@ -899,7 +915,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(OPENBSD)
+ || defined(NETBSD) || defined(OPENBSD) || defined(SERENITY)
struct sigaction act;
act.sa_handler = h;
@@ -965,7 +981,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(OPENBSD)
+ || defined(NETBSD) || defined(OPENBSD) || defined(SERENITY)
(void) sigaction(SIGSEGV, &old_segv_act, 0);
# if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \
|| defined(HPUX) || defined(HURD) || defined(NETBSD) \
@@ -1253,7 +1269,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)) \
@@ -1356,7 +1372,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)
@@ -2647,7 +2663,7 @@ static void block_unmap_inner(ptr_t start_addr, size_t len)
ps3_free_mem(start_addr, len);
# elif defined(AIX) || defined(CYGWIN32) || defined(HAIKU) \
|| (defined(LINUX) && !defined(PREFER_MMAP_PROT_NONE)) \
- || 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 */
@@ -3140,7 +3156,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
# elif !defined(USE_WINALLOC)
# include <sys/mman.h>
# include <signal.h>
-# if !defined(CYGWIN32) && !defined(HAIKU)
+# if !defined(CYGWIN32) && !defined(HAIKU) && !defined(SERENITY)
# include <sys/syscall.h>
# endif
@@ -3255,7 +3271,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
|