Skip to content

Commit

Permalink
Fix broken GC_release() for WASI
Browse files Browse the repository at this point in the history
It was just using free() but it can be called in the middle of an allocation.

Instead, ignore shrink requests, since we can't do anything with them.
  • Loading branch information
agoode committed Mar 11, 2024
1 parent af7f6ea commit ce57803
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/gc/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ void shrinkHeap (GC_state s, GC_heap h, size_t keepSize) {
}
assert (isAligned (keepWithMapsSize, s->sysvals.pageSize));
assert (keepWithMapsSize <= h->withMapsSize);
#if HAS_SHRINK_HEAP
GC_release (h->start + keepWithMapsSize, h->withMapsSize - keepWithMapsSize);
#endif
h->size = keepSize;
h->withMapsSize = keepWithMapsSize;
}
Expand Down
4 changes: 4 additions & 0 deletions runtime/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#error HAS_REMAP not defined
#endif

#ifndef HAS_SHRINK_HEAP
#error HAS_SHRINK_HEAP not defined
#endif

#ifndef HAS_SIGALTSTACK
#error HAS_SIGALTSTACK not defined
#else
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/aix.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define HAS_MSG_DONTWAIT FALSE
#define HAS_PTRACE FALSE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/cygwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#define HAS_FEROUND FALSE
#define HAS_REMAP TRUE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK FALSE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN TRUE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define HAS_FEROUND TRUE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/freebsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define HAS_FEROUND TRUE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/hpux.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define HAS_FEROUND TRUE
#define HAS_MSG_DONTWAIT FALSE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/hurd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define HAS_FEROUND TRUE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP TRUE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#endif
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP TRUE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#if (defined (__hppa__))
#define NEEDS_SIGALTSTACK_EXEC TRUE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define HAS_FEROUND FALSE
#define HAS_MSG_DONTWAIT FALSE
#define HAS_REMAP TRUE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK FALSE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN TRUE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/netbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define HAS_FEROUND FALSE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/openbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define HAS_FEROUND FALSE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/solaris.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define HAS_FEROUND TRUE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP TRUE
#define HAS_SIGALTSTACK TRUE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down
1 change: 1 addition & 0 deletions runtime/platform/wasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define HAS_FEROUND TRUE
#define HAS_MSG_DONTWAIT TRUE
#define HAS_REMAP FALSE
#define HAS_SHRINK_HEAP FALSE
#define HAS_SIGALTSTACK FALSE
#define NEEDS_SIGALTSTACK_EXEC FALSE
#define HAS_SPAWN FALSE
Expand Down

0 comments on commit ce57803

Please sign in to comment.