aboutsummaryrefslogtreecommitdiffstats
path: root/libtest/mmap.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-05-11 23:15:33 +0200
committerMattias Andrée <m@maandree.se>2026-05-11 23:15:33 +0200
commit86087e5f9cf4a0512ba36b4d01086b905574a47d (patch)
tree03ce90743ef4d9e3da6ba45b70f11494e12b667c /libtest/mmap.c
parentMisc (diff)
downloadlibrecrypt-86087e5f9cf4a0512ba36b4d01086b905574a47d.tar.gz
librecrypt-86087e5f9cf4a0512ba36b4d01086b905574a47d.tar.bz2
librecrypt-86087e5f9cf4a0512ba36b4d01086b905574a47d.tar.xz
Misc
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libtest/mmap.c')
-rw-r--r--libtest/mmap.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/libtest/mmap.c b/libtest/mmap.c
index d8a2a60..62ef06e 100644
--- a/libtest/mmap.c
+++ b/libtest/mmap.c
@@ -2,33 +2,38 @@
#include "common.h"
#ifndef TEST
-#include <sys/syscall.h>
-
-
#if !defined(__linux__)
# errno "Don't know how to implement mmap(3), mumap(3), and mremap(3)"
#endif
+#ifdef SYS_mmap2
+# define IF_MMAP2(A) (A)
+#else
+# define IF_MMAP2(A) ((void)0)
+#endif
+
+#if defined(__x86_64__) && defined(__ILP32__) /* x32 */
+# define SYSCALL_ARG_MAX LLONG_MAX
+#else
+# define SYSCALL_ARG_MAX LONG_MAX
+#endif
+
+
void *
libtest_real_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)
{
size_t pagesize = libtest_get_pagesize();
+ IF_MMAP2(assert(pagesize == 4096u));
if (off < 0 || off % (off_t)pagesize)
goto einval;
- off /= (off_t)pagesize;
+ IF_MMAP2(off /= (off_t)pagesize);
-#if defined(__x86_64__) && defined(__ILP32__) /* x32 */
- if (off > LLONG_MAX)
+ if (off > SYSCALL_ARG_MAX)
goto einval;
-#else
- if (off > LONG_MAX)
- goto einval;
-#endif
#ifdef SYS_mmap2
- assert(pagesize == 4096u);
return (void *)syscall(SYS_mmap2, addr, len, prot, flags, fd, off);
#else
return (void *)syscall(SYS_mmap, addr, len, prot, flags, fd, off);