Skip to content

Commit

Permalink
Use madvise() to return memory to OS on Cosmo
Browse files Browse the repository at this point in the history
Issue #666 (bdwgc).

Optionally, if -D FORCE_MPROTECT_BEFORE_MADVISE is passed to
CFLAGS_EXTRA, mprotect(PROT_NONE) is called before
madvise(MADV_DONTNEED).

* os_dep.c [USE_MUNMAP && !USE_WINALLOC && !SN_TARGET_PS3 && COSMO]
(block_unmap_inner): Call madvise(MADV_DONTNEED) instead of
mmap(PROT_NONE).
* os_dep.c [USE_MUNMAP && !USE_WINALLOC && !SN_TARGET_PS3 && COSMO
&& FORCE_MPROTECT_BEFORE_MADVISE] (block_unmap_inner): Call
mprotect(PROT_NONE).
* os_dep.c [USE_MUNMAP && !USE_WINALLOC && !SN_TARGET_PS3
&& !FORCE_MPROTECT_BEFORE_MADVISE&& COSMO] (GC_remap): Do nothing
instead of mprotect(PROT_READ|PROT_WRITE).
* os_dep.c [USE_MUNMAP && !USE_WINALLOC && COSMO
&& FORCE_MPROTECT_BEFORE_MADVISE] (GC_remap): Call
mmap(PROT_READ|PROT_WRITE).
  • Loading branch information
ivmai committed Oct 16, 2024
1 parent 8e8b451 commit a72ac8b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -2703,17 +2703,18 @@ block_unmap_inner(ptr_t start_addr, size_t len)
if (len != 0) {
# ifdef SN_TARGET_PS3
ps3_free_mem(start_addr, len);
# elif defined(AIX) || defined(CYGWIN32) || defined(HAIKU) \
|| (defined(LINUX) && !defined(PREFER_MMAP_PROT_NONE)) \
|| defined(HPUX)
# elif defined(AIX) || defined(COSMO) || defined(CYGWIN32) \
|| defined(HAIKU) || defined(HPUX) \
|| (defined(LINUX) && !defined(PREFER_MMAP_PROT_NONE))
/* 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 */
/* an existing memory map with MAP_FIXED is broken. */
/* However, calling mprotect() on the given address range */
/* with PROT_NONE seems to work fine. */
/* On Linux, low RLIMIT_AS value may lead to mmap failure. */
# if defined(LINUX) && !defined(FORCE_MPROTECT_BEFORE_MADVISE)
# if (defined(COSMO) || defined(LINUX)) \
&& !defined(FORCE_MPROTECT_BEFORE_MADVISE)
/* On Linux, at least, madvise() should be sufficient. */
# else
if (mprotect(start_addr, len, PROT_NONE))
Expand Down Expand Up @@ -2807,9 +2808,10 @@ GC_remap(ptr_t start, size_t bytes)
/* It was already remapped with PROT_NONE. */
{
# if !defined(SN_TARGET_PS3) && !defined(FORCE_MPROTECT_BEFORE_MADVISE) \
&& defined(LINUX) && !defined(PREFER_MMAP_PROT_NONE)
&& (defined(LINUX) && !defined(PREFER_MMAP_PROT_NONE) \
|| defined(COSMO))
/* Nothing to unprotect as madvise() is just a hint. */
# elif defined(NACL) || defined(NETBSD)
# elif defined(COSMO) || defined(NACL) || defined(NETBSD)
/* NaCl does not expose mprotect, but mmap should work fine. */
/* In case of NetBSD, mprotect fails (unlike mmap) even */
/* without PROT_EXEC if PaX MPROTECT feature is enabled. */
Expand Down

0 comments on commit a72ac8b

Please sign in to comment.