Skip to content

Commit

Permalink
lang/smalltalk: use modern memory management
Browse files Browse the repository at this point in the history
The memory allocator defaults to some horrifying complex code to manage
mmap'd allocations.  On system where MAP_NORESERVE is defined (Linux) it
uses a much simpler approach relying on memory overcommit.  Enable this
code on FreeBSD by defining MAP_NORESERVE to 0 (all allocations
are MAP_NORESERVE on FreeBSD unless a sysctl is set).

Entierly disable the other code path as it (somewhat gratutiously) uses
sbrk.

Approved by:	danfe (maintainer)
Sponsord by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42974
  • Loading branch information
brooksdavis committed Dec 11, 2023
1 parent af6504f commit f2348b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lang/smalltalk/Makefile
@@ -1,6 +1,6 @@
PORTNAME= smalltalk
PORTVERSION= 3.2.5
PORTREVISION= 17
PORTREVISION= 18
CATEGORIES= lang
MASTER_SITES= GNU

Expand All @@ -10,10 +10,7 @@ WWW= https://smalltalk.gnu.org/

LICENSE= GPLv2+

BROKEN_aarch64= Fails to link: undefined reference to sbrk
BROKEN_powerpc64= Fails to build: gst-package: did not understand #~
BROKEN_riscv64= Fails to link: undefined reference to sbrk
BROKEN_sparc64= Fails to install

BUILD_DEPENDS= zip:archivers/zip \
gawk:lang/gawk
Expand Down
59 changes: 59 additions & 0 deletions lang/smalltalk/files/patch-libgst_sysdep_posix_mem.c
@@ -0,0 +1,59 @@
--- libgst/sysdep/posix/mem.c.orig
+++ libgst/sysdep/posix/mem.c
@@ -92,20 +92,27 @@
#if defined MAP_AUTORESRV && !defined MAP_NORESERVE
# define MAP_NORESERVE MAP_AUTORESRV
#endif
+#if !defined(MAP_NORESERVE) && defined(__FreeBSD__)
+#define MAP_NORESERVE 0 /* always true */
+#endif
#ifdef MAP_NORESERVE
static PTR noreserve_reserve (PTR, size_t);
static void noreserve_decommit (PTR, size_t);
#endif
+#ifndef __FreeBSD__
static mst_Boolean anon_mmap_check (void);
static PTR anon_mmap_reserve (PTR, size_t);
static void anon_mmap_release (PTR, size_t);
+#endif
static PTR anon_mmap_commit (PTR, size_t);

struct heap_implementation heap_impl_tab[] = {
#ifdef MAP_NORESERVE
{ NULL, noreserve_reserve, _gst_osmem_free, anon_mmap_commit, noreserve_decommit },
#endif
+#ifndef __FreeBSD__
{ anon_mmap_check, anon_mmap_reserve, anon_mmap_release, anon_mmap_commit, _gst_osmem_free },
+#endif
{ NULL, NULL, NULL, NULL, NULL }
};

@@ -195,6 +202,7 @@

static char *baseaddr;

+#ifndef __FreeBSD__
PTR
anon_mmap_reserve (PTR address, size_t size)
{
@@ -220,6 +228,7 @@
if ((char *) baseaddr == (char *) base + size)
baseaddr = base;
}
+#endif

PTR
anon_mmap_commit (PTR base, size_t size)
@@ -231,6 +240,7 @@
return UNCOMMON (result == MAP_FAILED) ? NULL : result;
}

+#ifndef __FreeBSD__
/* This is hairy and a hack. We have to find a place for our heaps... */

/* This signal handler is used if it is the only means to decide if
@@ -360,3 +370,4 @@
return (true);
}
}
+#endif

0 comments on commit f2348b3

Please sign in to comment.