On Thu, Jun 26, 2014 at 12:28:18PM -0700, Matthew Dempsky wrote: > I just reviewed our mmap(2) flags to compare them against Linux, > FreeBSD, Solaris, and Darwin's flags. Of the flags listed below, none > of them are specified by POSIX, and none of them do anything > interesting on OpenBSD: MAP_COPY just gets rewritten to MAP_PRIVATE, > and the rest are silently ignored by UVM.
Feedback so far is the useless flags should go away. Diff below is a first step towards this: 1. MAP_COPY is redefined as an alias for MAP_PRIVATE, and the other useless MAP_* flags are redefined to 0. They're also hidden from the kernel to make sure no kernel code accidentally depends on them still. 2. Adds COMPAT_O55_MAP_COPY so we can stay binary compatible with any OpenBSD 5.5 programs that still use MAP_COPY (probably none, but it's trivial to do), and COMPAT_O55_MAP_NOOPMASK just to keep track of which bits were previously reserved for do-nothing flags. 3. Reshuffles the defines a little bit so the order makes more sense. Followup patch will add a deprecation warning for the MAP_* flags, but I think that'll need some ports testing, whereas this should be safe to commit now. ok? Index: sys/mman.h =================================================================== RCS file: /home/matthew/cvs-mirror/cvs/src/sys/sys/mman.h,v retrieving revision 1.24 diff -u -p -r1.24 mman.h --- sys/mman.h 13 Jun 2014 01:48:52 -0000 1.24 +++ sys/mman.h 26 Jun 2014 23:54:28 -0000 @@ -50,32 +50,43 @@ */ #define MAP_SHARED 0x0001 /* share changes */ #define MAP_PRIVATE 0x0002 /* changes are private */ -#define MAP_COPY 0x0004 /* "copy" region at mmap time */ + +/* + * Mapping type + */ +#define MAP_FILE 0x0000 /* map from file (default) */ +#define MAP_ANON 0x1000 /* allocated from memory, swap space */ /* * Other flags */ -#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ -#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */ -#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */ -#define MAP_INHERIT 0x0080 /* region is retained after exec */ -#define MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change file size */ -#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ -#define MAP_TRYFIXED 0x0400 /* attempt hint address, even within heap */ +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ +#define __MAP_NOREPLACE 0x0800 /* fail if address not available */ -#define __MAP_NOREPLACE 0x0800 /* fail if address not available */ +#ifdef _KERNEL +#define COMPAT_O55_MAP_COPY 0x0004 /* alias for MAP_PRIVATE */ +#define COMPAT_O55_MAP_NOOPMASK 0x07e0 /* formerly reserved flag bits */ +#endif + +#define MAP_FLAGMASK 0x1ff7 +#ifndef _KERNEL /* - * Error return from mmap() + * Deprecated flags with no significant meaning on OpenBSD. */ -#define MAP_FAILED ((void *)-1) +#define MAP_COPY MAP_PRIVATE +#define MAP_HASSEMAPHORE 0 +#define MAP_INHERIT 0 +#define MAP_NOEXTEND 0 +#define MAP_NORESERVE 0 +#define MAP_RENAME 0 +#define MAP_TRYFIXED 0 +#endif /* - * Mapping type + * Error return from mmap() */ -#define MAP_FILE 0x0000 /* map from file (default) */ -#define MAP_ANON 0x1000 /* allocated from memory, swap space */ -#define MAP_FLAGMASK 0x1ff7 +#define MAP_FAILED ((void *)-1) /* * POSIX memory advisory values. Index: uvm/uvm_mmap.c =================================================================== RCS file: /home/matthew/cvs-mirror/cvs/src/sys/uvm/uvm_mmap.c,v retrieving revision 1.94 diff -u -p -r1.94 uvm_mmap.c --- uvm/uvm_mmap.c 13 Apr 2014 23:14:15 -0000 1.94 +++ uvm/uvm_mmap.c 26 Jun 2014 23:49:39 -0000 @@ -345,8 +345,8 @@ sys_mmap(struct proc *p, void *v, regist return (EINVAL); if ((flags & MAP_FLAGMASK) != flags) return (EINVAL); - if (flags & MAP_COPY) - flags = (flags & ~MAP_COPY) | MAP_PRIVATE; + if (flags & COMPAT_O55_MAP_COPY) + flags = (flags & ~COMPAT_O55_MAP_COPY) | MAP_PRIVATE; if ((flags & (MAP_SHARED|MAP_PRIVATE)) == (MAP_SHARED|MAP_PRIVATE)) return (EINVAL); if ((flags & (MAP_FIXED|__MAP_NOREPLACE)) == __MAP_NOREPLACE)