VG_(core_panic)("can't use ML_(generic_PRE_sys_mmap) on Darwin");
# endif
- /* fd (arg4) is only used when flags (arg4) does not contain
- MAP_ANONYMOUS. ML_(fd_allowed) might just warn (with --track-fds)
+#if !defined(VKI_MAP_GUARD)
+// on platforms without MAP_GUARD the compiler should optimise away
+// the term using it below as it will always be true
+#define VKI_MAP_GUARD 0
+#endif
+
+#if !defined(VKI_MAP_STACK)
+// as above
+#define VKI_MAP_STACK 0
+#endif
+
+ /* fd (arg5) is only used when flags (arg4) does not contain
+ MAP_ANONYMOUS (or, on FreeBSD, MAP_GUARD and MAP_STACK).
+ ML_(fd_allowed) might just warn (with --track-fds)
and not fail, unless it is a Valgrind owned file descriptor.
So also check with fcntl (F_GETFD) to know if it really is a bad
fd. Fail early in that case with EBADF. */
if (!(arg4 & VKI_MAP_ANONYMOUS)
+ && !(arg4 & VKI_MAP_GUARD)
+ && !(arg4 & VKI_MAP_STACK)
&& (!ML_(fd_allowed)(arg5, "mmap", tid, False)
|| VG_(fcntl) (arg5, VKI_F_GETFD, 0) < 0)) {
return VG_(mk_SysRes_Error)( VKI_EBADF );
#define VKI_MAP_STACK 0x400
#define VKI_MAP_ANON 0x1000 /* don't use a file */
#define VKI_MAP_ANONYMOUS VKI_MAP_ANON
+#define VKI_MAP_GUARD 0x00002000
#define VKI_MAP_ALIGNED(n) ((n) << VKI_MAP_ALIGNMENT_SHIFT)
#define VKI_MAP_ALIGNMENT_SHIFT 24