From: Alexander Köplinger Date: Mon, 8 Aug 2016 09:47:08 +0000 (+0200) Subject: Merge pull request #2903 from krytarowski/netbsd-support-4 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=8d1a18d611a7e44bf9cdac34039652d1c325f5b0;hp=f34c0223fce6b42ebfbe82ddc257095e5c490d10 Merge pull request #2903 from krytarowski/netbsd-support-4 Implement mremap(2) usage on NetBSD --- diff --git a/mono/utils/dlmalloc.c b/mono/utils/dlmalloc.c index 2ce2a6ea95e..3177f2d17a1 100644 --- a/mono/utils/dlmalloc.c +++ b/mono/utils/dlmalloc.c @@ -342,7 +342,7 @@ HAVE_MMAP default: 1 (true) able to unmap memory that may have be allocated using multiple calls to MMAP, so long as they are adjacent. -HAVE_MREMAP default: 1 on linux, else 0 +HAVE_MREMAP default: 1 on linux and NetBSD, else 0 If true realloc() uses mremap() to re-allocate large blocks and extend or shrink allocation spaces. @@ -536,11 +536,11 @@ DEFAULT_MMAP_THRESHOLD default: 256K #define MMAP_CLEARS 1 #endif /* MMAP_CLEARS */ #ifndef HAVE_MREMAP -#ifdef linux +#if defined(linux) || defined(__NetBSD__) #define HAVE_MREMAP 1 -#else /* linux */ +#else /* linux || __NetBSD__ */ #define HAVE_MREMAP 0 -#endif /* linux */ +#endif /* linux || __NetBSD__ */ #endif /* HAVE_MREMAP */ #ifndef MALLOC_FAILURE_ACTION #define MALLOC_FAILURE_ACTION errno = ENOMEM; @@ -1375,7 +1375,13 @@ static int win32munmap(void* ptr, size_t size) { #endif /* HAVE_MMAP */ #if HAVE_MMAP && HAVE_MREMAP +#if defined(linux) #define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) +#elif defined(__NetBSD__) +#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (addr), (nsz), (mv)) +#else +#define CALL_MREMAP(addr, osz, nsz, mv) MFAIL +#endif #else /* HAVE_MMAP && HAVE_MREMAP */ #define CALL_MREMAP(addr, osz, nsz, mv) MFAIL #endif /* HAVE_MMAP && HAVE_MREMAP */ diff --git a/support/map.c b/support/map.c index 136f2b71878..92fca755371 100644 --- a/support/map.c +++ b/support/map.c @@ -3922,12 +3922,17 @@ int Mono_Posix_ToMountFlags (guint64 x, guint64 *r) int Mono_Posix_FromMremapFlags (guint64 x, guint64 *r) { *r = 0; +#ifndef __NetBSD__ if ((x & Mono_Posix_MremapFlags_MREMAP_MAYMOVE) == Mono_Posix_MremapFlags_MREMAP_MAYMOVE) #ifdef MREMAP_MAYMOVE *r |= MREMAP_MAYMOVE; #else /* def MREMAP_MAYMOVE */ {errno = EINVAL; return -1;} #endif /* ndef MREMAP_MAYMOVE */ +#else /* def __NetBSD__ */ + if ((x & Mono_Posix_MremapFlags_MREMAP_MAYMOVE) != Mono_Posix_MremapFlags_MREMAP_MAYMOVE) + *r = MAP_FIXED; +#endif /* def __NetBSD__ */ if (x == 0) return 0; return 0; @@ -3936,12 +3941,17 @@ int Mono_Posix_FromMremapFlags (guint64 x, guint64 *r) int Mono_Posix_ToMremapFlags (guint64 x, guint64 *r) { *r = 0; +#ifndef __NetBSD__ if (x == 0) return 0; #ifdef MREMAP_MAYMOVE if ((x & MREMAP_MAYMOVE) == MREMAP_MAYMOVE) *r |= Mono_Posix_MremapFlags_MREMAP_MAYMOVE; #endif /* ndef MREMAP_MAYMOVE */ +#else /* def __NetBSD__ */ + if ((x & MAP_FIXED) != MAP_FIXED) + *r |= Mono_Posix_MremapFlags_MREMAP_MAYMOVE; +#endif return 0; } @@ -9314,4 +9324,3 @@ int Mono_Posix_ToXattrFlags (int x, int *r) #endif /* ndef XATTR_REPLACE */ return 0; } - diff --git a/support/sys-mman.c b/support/sys-mman.c index 3973bd6614f..15e125621d2 100644 --- a/support/sys-mman.c +++ b/support/sys-mman.c @@ -109,8 +109,15 @@ Mono_Posix_Syscall_mremap (void *old_address, mph_size_t old_size, if (Mono_Posix_FromMremapFlags (flags, &_flags) == -1) return MAP_FAILED; +#if defined(linux) return mremap (old_address, (size_t) old_size, (size_t) new_size, (unsigned long) _flags); +#elif defined(__NetBSD__) + return mremap (old_address, (size_t) old_size, old_address, + (size_t) new_size, (unsigned long) _flags); +#else +#error Port me +#endif } #endif /* def HAVE_MREMAP */