glibc/sysdeps/mach/hurd/bits
Sergey Bugaev 27cb2bb93d hurd: Implement MAP_EXCL
MAP_FIXED is defined to silently replace any existing mappings at the
address range being mapped over. This, however, is a dangerous, and only
rarely desired behavior.

Various Unix systems provide replacements or additions to MAP_FIXED:

* SerenityOS and Linux provide MAP_FIXED_NOREPLACE. If the address space
  already contains a mapping in the requested range, Linux returns
  EEXIST. SerenityOS returns ENOMEM, however that is a bug, as the
  MAP_FIXED_NOREPLACE implementation is intended to be compatible with
  Linux.

* FreeBSD provides the MAP_EXCL flag that has to be used in combination
  with MAP_FIXED. It returns EINVAL if the requested range already
  contains existing mappings. This is directly analogous to the O_EXCL
  flag in the open () call.

* DragonFly BSD, NetBSD, and OpenBSD provide MAP_TRYFIXED, but with
  different semantics. DragonFly BSD returns ENOMEM if the requested
  range already contains existing mappings. NetBSD does not return an
  error, but instead creates the mapping at a different address if the
  requested range contains mappings. OpenBSD behaves the same, but also
  notes that this is the default behavior even without MAP_TRYFIXED
  (which is the case on the Hurd too).

Since the Hurd leans closer to the BSD side, add MAP_EXCL as the primary
API to request the behavior of not replacing existing mappings. Declare
MAP_FIXED_NOREPLACE and MAP_TRYFIXED as aliases of (MAP_FIXED|MAP_EXCL),
so any existing software that checks for either of those macros will
pick them up automatically. For compatibility with Linux, return EEXIST
if a mapping already exists.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230625231751.404120-5-bugaevc@gmail.com>
2023-07-03 01:38:14 +02:00
..
types hurd 64bit: Fix flock fields types 2023-05-01 15:05:09 +02:00
errno.h hurd: rule out some mach headers when generating errno.h 2023-05-11 01:53:49 +02:00
fcntl.h hurd 64bit: Fix flock fields types 2023-05-01 15:05:09 +02:00
ioctls.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
local_lim.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
mman_ext.h hurd: Implement MAP_EXCL 2023-07-03 01:38:14 +02:00
param.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
posix_opt.h Fix misspellings in sysdeps/ -- BZ 25337 2023-05-30 23:02:29 +00:00
signum-arch.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
socket.h hurd: Implement MSG_CMSG_CLOEXEC 2023-04-24 23:09:50 +02:00
stat.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
statfs.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
statvfs.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
stdio_lim.h libio: Do not autogenerate stdio_lim.h 2023-03-27 13:57:55 -03:00
sysmacros.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
timesize.h hurd: Fix __TIMESIZE on x86_64 2023-05-19 20:25:37 +02:00
typesizes.h hurd 64bit: Make dev_t word type 2023-05-02 21:29:26 +02:00
unistd_ext.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00