summaryrefslogtreecommitdiff
path: root/Ports
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-02-24 03:05:53 +0330
committerLinus Groh <mail@linusgroh.de>2022-03-08 22:29:53 +0100
commitce9f355b1233b3f6d858eedc7837a0a2e6994fc1 (patch)
tree75b0a5bd35014a19ae184ce0b2475f9cc54b6c38 /Ports
parent5d51e26caff61516d6fcf612c2e9ba72a82b699f (diff)
downloadserenity-ce9f355b1233b3f6d858eedc7837a0a2e6994fc1.zip
Ports: Add a bdwgc (aka libgc) port
For all your ports' garbage collection needs :^)
Diffstat (limited to 'Ports')
-rw-r--r--Ports/AvailablePorts.md1
-rwxr-xr-xPorts/bdwgc/package.sh25
-rw-r--r--Ports/bdwgc/patches/0001-Teach-os_dep-and-gcconfig.h-about-serenity.patch215
-rw-r--r--Ports/bdwgc/patches/0002-Error-on-unknown-arch.patch25
-rw-r--r--Ports/bdwgc/patches/0003-Teach-dyn_load.c-about-serenity.patch67
-rw-r--r--Ports/bdwgc/patches/0004-Teach-bdwgc-about-serenity-signals.patch66
-rw-r--r--Ports/bdwgc/patches/0005-Explicitly-link-with-pthread.patch73
-rw-r--r--Ports/bdwgc/patches/0006-Make-the-collector-build-with-threads.patch52
-rw-r--r--Ports/bdwgc/patches/ReadMe.md44
9 files changed, 568 insertions, 0 deletions
diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md
index 7c91622007..df22938137 100644
--- a/Ports/AvailablePorts.md
+++ b/Ports/AvailablePorts.md
@@ -9,6 +9,7 @@ Please make sure to keep this list up to date when adding and updating ports. :^
| [`bash`](bash/) | GNU Bash | 5.1.16 | https://www.gnu.org/software/bash/ |
| [`bass`](bass/) | Beneath a Steel Sky | cd-1.2 | https://www.scummvm.org/games |
| [`bc`](bc/) | bc | 5.1.1 | https://github.com/gavinhoward/bc |
+| [`bdwgc`](bdwgc/) | Boehm-Demers-Weiser Garbage Collector (libgc) | 8.0.6 | https://github.com/ivmai/bdwgc |
| [`binutils`](binutils/) | GNU Binutils | 2.38 | https://www.gnu.org/software/binutils/ |
| [`bison`](bison/) | GNU Bison | 1.25 | https://www.gnu.org/software/bison/ |
| [`bochs`](bochs/) | Bochs x86 PC emulator | 2.7 | https://sourceforge.net/projects/bochs/ |
diff --git a/Ports/bdwgc/package.sh b/Ports/bdwgc/package.sh
new file mode 100755
index 0000000000..54b6b388f1
--- /dev/null
+++ b/Ports/bdwgc/package.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env -S bash ../.port_include.sh
+
+port=bdwgc
+version=8.0.6
+use_fresh_config_sub=true
+files="https://github.com/ivmai/bdwgc/releases/download/v$version/gc-$version.tar.gz bdwgc.tar.gz 3b4914abc9fa76593596773e4da671d7ed4d5390e3d46fbf2e5f155e121bea11"
+depends=(libatomic_ops)
+workdir=gc-$version
+auth_type=sha256
+
+build() {
+ cd $workdir
+ mkdir build || true
+ cd build
+ cmake .. \
+ -Denable_threads=ON \
+ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="$DESTDIR/usr/local/bin" \
+ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="$DESTDIR/usr/local/lib"
+ cmake --build .
+}
+
+install() {
+ cd ..
+ cp -r include "$DESTDIR/usr/local/include/gc"
+}
diff --git a/Ports/bdwgc/patches/0001-Teach-os_dep-and-gcconfig.h-about-serenity.patch b/Ports/bdwgc/patches/0001-Teach-os_dep-and-gcconfig.h-about-serenity.patch
new file mode 100644
index 0000000000..23ea7049d8
--- /dev/null
+++ b/Ports/bdwgc/patches/0001-Teach-os_dep-and-gcconfig.h-about-serenity.patch
@@ -0,0 +1,215 @@
+From 1e6a332dc87920d79eca1b1ddb66033c7f369d38 Mon Sep 17 00:00:00 2001
+From: Ali Mohammad Pur <ali.mpfard@gmail.com>
+Date: Thu, 24 Feb 2022 01:00:57 +0330
+Subject: [PATCH 1/6] 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 <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[];
+@@ -2727,6 +2752,23 @@ EXTERN_C_BEGIN
+ # define DYNAMIC_LOADING
+ # define MPROTECT_VDB
+ # endif
++# ifdef SERENITY
++# define OS_TYPE "SERENITY"
++ EXTERN_C_END
++# include <unistd.h>
++ 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 <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)
+ {
+@@ -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 <sys/mman.h>
+ # include <signal.h>
+-# if !defined(CYGWIN32) && !defined(HAIKU)
++# if !defined(CYGWIN32) && !defined(HAIKU) && !defined(SERENITY)
+ # include <sys/syscall.h>
+ # 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
+--
+2.35.1
+
diff --git a/Ports/bdwgc/patches/0002-Error-on-unknown-arch.patch b/Ports/bdwgc/patches/0002-Error-on-unknown-arch.patch
new file mode 100644
index 0000000000..f6245174aa
--- /dev/null
+++ b/Ports/bdwgc/patches/0002-Error-on-unknown-arch.patch
@@ -0,0 +1,25 @@
+From 044ec10fa839e67da2adb0990a60d5a02de205a8 Mon Sep 17 00:00:00 2001
+From: Ali Mohammad Pur <ali.mpfard@gmail.com>
+Date: Thu, 24 Feb 2022 01:50:40 +0330
+Subject: [PATCH 2/6] Error on unknown arch
+
+---
+ include/private/gcconfig.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
+index e9d1d42..8e48b66 100644
+--- a/include/private/gcconfig.h
++++ b/include/private/gcconfig.h
+@@ -358,6 +358,8 @@ EXTERN_C_BEGIN
+ # define I386
+ # elif defined(__x86_64__)
+ # define X86_64
++# else
++# error "Invalid arch for serenity"
+ # endif
+ #endif
+ # if defined(__HAIKU__) && (defined(__amd64__) || defined(__x86_64__))
+--
+2.35.1
+
diff --git a/Ports/bdwgc/patches/0003-Teach-dyn_load.c-about-serenity.patch b/Ports/bdwgc/patches/0003-Teach-dyn_load.c-about-serenity.patch
new file mode 100644
index 0000000000..15f9675fb1
--- /dev/null
+++ b/Ports/bdwgc/patches/0003-Teach-dyn_load.c-about-serenity.patch
@@ -0,0 +1,67 @@
+From a7fd9227e9111502a6134666d6636a8695c36f4e Mon Sep 17 00:00:00 2001
+From: Ali Mohammad Pur <ali.mpfard@gmail.com>
+Date: Thu, 24 Feb 2022 01:54:50 +0330
+Subject: [PATCH 3/6] Teach dyn_load.c about serenity
+
+---
+ dyn_load.c | 23 ++++++++++++++++++++---
+ 1 file changed, 20 insertions(+), 3 deletions(-)
+
+diff --git a/dyn_load.c b/dyn_load.c
+index d857246..734643d 100644
+--- a/dyn_load.c
++++ b/dyn_load.c
+@@ -60,7 +60,7 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
+ && !(defined(FREEBSD) && defined(__ELF__)) \
+ && !((defined(LINUX) || defined(NACL)) && defined(__ELF__)) \
+ && !(defined(NETBSD) && defined(__ELF__)) \
+- && !defined(HAIKU) && !defined(HURD) \
++ && !defined(HAIKU) && !defined(HURD) && !defined(SERENITY) \
+ && !(defined(OPENBSD) && (defined(__ELF__) || defined(M68K))) \
+ && !defined(CPPCHECK)
+ # error We only know how to find data segments of dynamic libraries for above.
+@@ -88,7 +88,7 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
+ # endif
+ #endif /* OPENBSD */
+
+-#if defined(SCO_ELF) || defined(DGUX) || defined(HURD) \
++#if defined(SCO_ELF) || defined(DGUX) || defined(HURD) || defined(SERENITY) \
+ || (defined(__ELF__) && (defined(LINUX) || defined(FREEBSD) \
+ || defined(NACL) || defined(NETBSD) \
+ || defined(OPENBSD)))
+@@ -98,6 +98,23 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
+ /* Exclude Android because linker.h below includes its own version. */
+ # include <elf.h>
+ # endif
++# ifdef SERENITY
++# include <link.h>
++ struct link_map {
++ uintptr_t l_addr;
++ char* l_name;
++ uintptr_t l_ld;
++ struct link_map* l_next;
++ struct link_map* l_prev;
++ };
++ struct r_debug {
++ int32_t r_version;
++ struct link_map* r_map;
++ void (*r_brk)(void);
++ int32_t r_state;
++ uintptr_t r_ldbase;
++ };
++# endif
+ # ifdef HOST_ANDROID
+ /* If you don't need the "dynamic loading" feature, you may build */
+ /* the collector with -D IGNORE_DYNAMIC_LOADING. */
+@@ -259,7 +276,7 @@ GC_INNER void GC_register_dynamic_libraries(void)
+ # endif /* !USE_PROC ... */
+ # endif /* SOLARISDL */
+
+-#if defined(SCO_ELF) || defined(DGUX) || defined(HURD) \
++#if defined(SCO_ELF) || defined(DGUX) || defined(HURD) || defined(SERENITY) \
+ || (defined(__ELF__) && (defined(LINUX) || defined(FREEBSD) \
+ || defined(NACL) || defined(NETBSD) \
+ || defined(OPENBSD)))
+--
+2.35.1
+
diff --git a/Ports/bdwgc/patches/0004-Teach-bdwgc-about-serenity-signals.patch b/Ports/bdwgc/patches/0004-Teach-bdwgc-about-serenity-signals.patch
new file mode 100644
index 0000000000..04889f36a9
--- /dev/null
+++ b/Ports/bdwgc/patches/0004-Teach-bdwgc-about-serenity-signals.patch
@@ -0,0 +1,66 @@
+From d37f9022e78b9df4959f9be265f91e611e84e03a Mon Sep 17 00:00:00 2001
+From: Ali Mohammad Pur <ali.mpfard@gmail.com>
+Date: Thu, 24 Feb 2022 03:30:02 +0330
+Subject: [PATCH 4/6] Teach bdwgc about serenity signals
+
+Serenity doesn't have the realtime POSIX signals, so use SIGXCPU and
+SIGXFSZ instead.
+---
+ include/gc_config_macros.h | 4 +++-
+ include/private/gc_priv.h | 2 +-
+ pthread_stop_world.c | 4 +++-
+ 3 files changed, 7 insertions(+), 3 deletions(-)
+
+diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h
+index 14c65ee..c19b050 100644
+--- a/include/gc_config_macros.h
++++ b/include/gc_config_macros.h
+@@ -72,7 +72,7 @@
+
+ #if defined(GC_AIX_THREADS) || defined(GC_DARWIN_THREADS) \
+ || defined(GC_DGUX386_THREADS) || defined(GC_FREEBSD_THREADS) \
+- || defined(GC_HPUX_THREADS) \
++ || defined(GC_HPUX_THREADS) || defined(GC_SERENITY_THREADS) \
+ || defined(GC_IRIX_THREADS) || defined(GC_LINUX_THREADS) \
+ || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS) \
+ || defined(GC_OSF1_THREADS) || defined(GC_SOLARIS_THREADS) \
+@@ -83,6 +83,8 @@
+ #elif defined(GC_THREADS)
+ # if defined(__linux__)
+ # define GC_LINUX_THREADS
++# elif defined(__serenity__)
++# define GC_SERENITY_THREADS
+ # elif defined(__OpenBSD__)
+ # define GC_OPENBSD_THREADS
+ # elif defined(_PA_RISC1_1) || defined(_PA_RISC2_0) || defined(hppa) \
+diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
+index 629418f..1278091 100644
+--- a/include/private/gc_priv.h
++++ b/include/private/gc_priv.h
+@@ -2641,7 +2641,7 @@ GC_INNER void *GC_store_debug_info_inner(void *p, word sz, const char *str,
+ /* Linuxthreads itself uses SIGUSR1 and SIGUSR2. */
+ # define SIG_SUSPEND SIGPWR
+ # endif
+-# elif defined(GC_OPENBSD_THREADS)
++# elif defined(GC_OPENBSD_THREADS) || defined(GC_SERENITY_THREADS)
+ # ifndef GC_OPENBSD_UTHREADS
+ # define SIG_SUSPEND SIGXFSZ
+ # endif
+diff --git a/pthread_stop_world.c b/pthread_stop_world.c
+index 4b2c429..25eb2a5 100644
+--- a/pthread_stop_world.c
++++ b/pthread_stop_world.c
+@@ -146,7 +146,9 @@ STATIC volatile AO_t GC_world_is_stopped = FALSE;
+ * pointer(s) and acknowledge.
+ */
+ #ifndef SIG_THR_RESTART
+-# if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) \
++# if defined(SERENITY)
++# define SIG_THR_RESTART SIGUSR1
++# elif defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) \
+ || defined(GC_NETBSD_THREADS) || defined(GC_USESIGRT_SIGNALS)
+ # if defined(_SIGRTMIN) && !defined(CPPCHECK)
+ # define SIG_THR_RESTART _SIGRTMIN + 5
+--
+2.35.1
+
diff --git a/Ports/bdwgc/patches/0005-Explicitly-link-with-pthread.patch b/Ports/bdwgc/patches/0005-Explicitly-link-with-pthread.patch
new file mode 100644
index 0000000000..4f2032c19a
--- /dev/null
+++ b/Ports/bdwgc/patches/0005-Explicitly-link-with-pthread.patch
@@ -0,0 +1,73 @@
+From 3c107421a9541856ba7f5a495bb3aac35a377583 Mon Sep 17 00:00:00 2001
+From: Ali Mohammad Pur <ali.mpfard@gmail.com>
+Date: Thu, 24 Feb 2022 03:47:50 +0330
+Subject: [PATCH 5/6] Explicitly link with pthread
+
+The cmakelists was using the wrong variable to link against pthread.
+---
+ CMakeLists.txt | 5 +++--
+ tests/CMakeLists.txt | 12 ++++++------
+ 2 files changed, 9 insertions(+), 8 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index c8ebd9b..e9c52f1 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -52,7 +52,8 @@ IF(enable_threads)
+ FIND_PACKAGE(Threads REQUIRED)
+ MESSAGE("Thread Model: ${CMAKE_THREAD_LIBS_INIT}" )
+ INCLUDE_DIRECTORIES(${Threads_INCLUDE_DIR})
+- SET(LIBS ${LIBS} ${Threads_LIBRARIES})
++ SET(LIBS ${LIBS} ${Threads_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
++ MESSAGE("Libs: ${LIBS}" )
+ ENDIF(enable_threads)
+
+ OPTION(enable_handle_fork "Attempt to ensure a usable collector after fork()" ON)
+@@ -235,7 +236,7 @@ ENDIF(enable_checksums)
+ ADD_LIBRARY( gc-lib STATIC ${SRC})
+ SET_TARGET_PROPERTIES(gc-lib PROPERTIES
+ COMPILE_DEFINITIONS GC_NOT_DLL)
+-#TODO TARGET_LINK_LIBRARIES(... ... ${LIBS})
++TARGET_LINK_LIBRARIES(gc-lib ${LIBS})
+
+ ADD_LIBRARY( gcmt-dll SHARED ${SRC})
+
+diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
+index 3c84220..5e15727 100644
+--- a/tests/CMakeLists.txt
++++ b/tests/CMakeLists.txt
+@@ -23,25 +23,25 @@ SET_SOURCE_FILES_PROPERTIES(
+ PROPERTIES LANGUAGE CXX)
+
+ ADD_EXECUTABLE(gctest WIN32 test.c)
+-TARGET_LINK_LIBRARIES(gctest gc-lib)
++TARGET_LINK_LIBRARIES(gctest gc-lib ${LIBS})
+ ADD_TEST(NAME gctest COMMAND gctest)
+
+ ADD_EXECUTABLE(hugetest huge_test.c)
+-TARGET_LINK_LIBRARIES(hugetest gc-lib)
++TARGET_LINK_LIBRARIES(hugetest gc-lib ${LIBS})
+ ADD_TEST(NAME hugetest COMMAND hugetest)
+
+ ADD_EXECUTABLE(leaktest leak_test.c)
+-TARGET_LINK_LIBRARIES(leaktest gc-lib)
++TARGET_LINK_LIBRARIES(leaktest gc-lib ${LIBS})
+ ADD_TEST(NAME leaktest COMMAND leaktest)
+
+ ADD_EXECUTABLE(middletest middle.c)
+-TARGET_LINK_LIBRARIES(middletest gc-lib)
++TARGET_LINK_LIBRARIES(middletest gc-lib ${LIBS})
+ ADD_TEST(NAME middletest COMMAND middletest)
+
+ ADD_EXECUTABLE(realloc_test realloc_test.c)
+-TARGET_LINK_LIBRARIES(realloc_test gc-lib)
++TARGET_LINK_LIBRARIES(realloc_test gc-lib ${LIBS})
+ ADD_TEST(NAME realloc_test COMMAND realloc_test)
+
+ ADD_EXECUTABLE(smashtest smash_test.c)
+-TARGET_LINK_LIBRARIES(smashtest gc-lib)
++TARGET_LINK_LIBRARIES(smashtest gc-lib ${LIBS})
+ ADD_TEST(NAME smashtest COMMAND smashtest)
+--
+2.35.1
+
diff --git a/Ports/bdwgc/patches/0006-Make-the-collector-build-with-threads.patch b/Ports/bdwgc/patches/0006-Make-the-collector-build-with-threads.patch
new file mode 100644
index 0000000000..5e83d7d941
--- /dev/null
+++ b/Ports/bdwgc/patches/0006-Make-the-collector-build-with-threads.patch
@@ -0,0 +1,52 @@
+From 825f33e226dbe842fb6588ba73c31b9fbb079f11 Mon Sep 17 00:00:00 2001
+From: Ali Mohammad Pur <ali.mpfard@gmail.com>
+Date: Fri, 25 Feb 2022 04:53:53 +0330
+Subject: [PATCH 6/6] Make the collector build with threads
+
+In an extremely limited way for now:
+- No extra threads
+ More threads always lead to exactly one borked thread that's stuck
+ in no man's land, doing who-knows-what, and definitely not
+ responding to signals.
+ However, the APIs are there and they work, so they *can* be used to
+ make threads.
+- No fork handling
+ Seems borked for unknown reasons.
+---
+ CMakeLists.txt | 6 +++++-
+ tests/test.c | 2 +-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e9c52f1..7c9daad 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -56,7 +56,11 @@ IF(enable_threads)
+ MESSAGE("Libs: ${LIBS}" )
+ ENDIF(enable_threads)
+
+-OPTION(enable_handle_fork "Attempt to ensure a usable collector after fork()" ON)
++IF(DEBUG_THREADS)
++ ADD_DEFINITIONS("-DDEBUG_THREADS")
++ENDIF()
++
++OPTION(enable_handle_fork "Attempt to ensure a usable collector after fork()" OFF)
+
+ OPTION(enable_thread_local_alloc "Turn on thread-local allocation optimization" ON)
+
+diff --git a/tests/test.c b/tests/test.c
+index 8e2e3a6..f38fb22 100644
+--- a/tests/test.c
++++ b/tests/test.c
+@@ -40,7 +40,7 @@
+ #include "gc.h"
+
+ #ifndef NTHREADS /* Number of additional threads to fork. */
+-# define NTHREADS 5 /* excludes main thread, which also runs a test. */
++# define NTHREADS 0 /* excludes main thread, which also runs a test. */
+ /* Not respected by PCR test. */
+ #endif
+
+--
+2.35.1
+
diff --git a/Ports/bdwgc/patches/ReadMe.md b/Ports/bdwgc/patches/ReadMe.md
new file mode 100644
index 0000000000..216abbd188
--- /dev/null
+++ b/Ports/bdwgc/patches/ReadMe.md
@@ -0,0 +1,44 @@
+# Patches for bdwgc on SerenityOS
+
+## `0001-Teach-os_dep-and-gcconfig.h-about-serenity.patch`
+
+Teach os_dep and gcconfig.h about serenity
+
+
+## `0002-Error-on-unknown-arch.patch`
+
+Error on unknown arch
+
+
+## `0003-Teach-dyn_load.c-about-serenity.patch`
+
+Teach dyn_load.c about serenity
+
+
+## `0004-Teach-bdwgc-about-serenity-signals.patch`
+
+Teach bdwgc about serenity signals
+
+Serenity doesn't have the realtime POSIX signals, so use SIGXCPU and
+SIGXFSZ instead.
+
+## `0005-Explicitly-link-with-pthread.patch`
+
+Explicitly link with pthread
+
+The cmakelists was using the wrong variable to link against pthread.
+
+## `0006-Make-the-collector-build-with-threads.patch`
+
+Make the collector build with threads
+
+In an extremely limited way for now:
+- No extra threads
+ More threads always lead to exactly one borked thread that's stuck
+ in no man's land, doing who-knows-what, and definitely not
+ responding to signals.
+ However, the APIs are there and they work, so they *can* be used to
+ make threads.
+- No fork handling
+ Seems borked for unknown reasons.
+