Implement mremap(2) usage on NetBSD
authorKamil Rytarowski <n54@gmx.com>
Sun, 17 Apr 2016 00:46:57 +0000 (02:46 +0200)
committerKamil Rytarowski <n54@gmx.com>
Sun, 17 Apr 2016 00:46:57 +0000 (02:46 +0200)
commitb522eab5ff5466debaacf9e971e26cfc464ebba5
tree64f0462c4d7d92049d4423f6beb0ed08c3c9991c
parent2d68253ca7c846736dbf27a812acd11f1c7a1e1f
Implement mremap(2) usage on NetBSD

The NetBSD version of mremap takes additional argument "newp" to hint
new position of a mapped range.

     void *
     mremap(void *oldp, size_t oldsize, void *newp, size_t newsize,
         int flags);

  -- NetBSD's mremap(2)

While Linux by default sets old_address and fails if the resize
operation cannot be finished for the original address.

       void *mremap(void *old_address, size_t old_size,
                    size_t new_size, int flags, ... /* void *new_address */);

  -- Linux's mremap(2)

NetBSD offers inversed logic with the MAP_FIXED flag to Linux's MREMAP_MAYMOVE:

     MAP_FIXED          newp is tried and mremap() fails if that address can't
                        be used as new base address for the range.  Otherwise,
                        oldp and newp are used as hints for the position,
                        factoring in the given alignment.

  -- NetBSD's mremap(2)

       MREMAP_MAYMOVE
              By default, if there is not sufficient space to expand a mapping
              at its current location, then mremap() fails.  If this flag is
              specified, then  the  kernel  is permitted to relocate the
              mapping to a new virtual address, if necessary.  If the mapping
              is relocated, then absolute pointers into the old mapping
              location become invalid (offsets relative to the starting address
              of the mapping should be employed).

  -- Linux's mremap(2)

The thing that bothers is calling mremap(2) syntax from Linux "posix", but we
cannot do anything with it, for now just simulate the Linux behavior on NetBSD.
mono/utils/dlmalloc.c
support/map.c
support/sys-mman.c