]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 499212 - mmap() with MAP_ALIGNED() returns unaligned pointer
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Jan 2025 08:44:24 +0000 (09:44 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Jan 2025 08:44:24 +0000 (09:44 +0100)
.gitignore
NEWS
coregrind/m_syswrap/syswrap-generic.c
include/vki/vki-freebsd.h
none/tests/freebsd/Makefile.am
none/tests/freebsd/bug499212.c [new file with mode: 0644]
none/tests/freebsd/bug499212.stderr.exp [new file with mode: 0644]
none/tests/freebsd/bug499212.stdout.exp [new file with mode: 0644]
none/tests/freebsd/bug499212.vgtest [new file with mode: 0644]

index 4a6874e5c1cbfe2606f2bbbb9ea6910b3357bb65..483b077ca389af78e2631db5f7866a1a2ac69ab8 100644 (file)
 /none/tests/freebsd/auxv
 /none/tests/freebsd/bug452274
 /none/tests/freebsd/bug498317
+none/tests/freebsd/bug499212
 /none/tests/freebsd/osrel
 /none/tests/freebsd/swapcontext
 /none/tests/freebsd/fexecve
diff --git a/NEWS b/NEWS
index 22744917eb42a0e1927a9bc8e4915237606a7781..f6f6e9d88f100df05a04653b4359d2642e5d0fd1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
         even though it's generated by --gen-suppressions=yes
 498143  False positive on EVIOCGRAB ioctl
 498492  none/tests/amd64/lzcnt64 crashes on FreeBSD compiled with clang
+499212  mmap() with MAP_ALIGNED() returns unaligned pointer
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index c281021a9f039b05410ec4fa39822a0798543be8..c3f916a1ed790e1808b77cdf99c85500bc8d7cda 100644 (file)
@@ -2630,7 +2630,7 @@ ML_(generic_PRE_sys_mmap) ( ThreadId tid,
    if (arg4 & VKI_MAP_FIXED) {
       mreq.rkind = MFixed;
    } else
-#if defined(VKI_MAP_ALIGN) /* Solaris specific */
+#if defined(VGO_solaris) && defined(VKI_MAP_ALIGN)
    if (arg4 & VKI_MAP_ALIGN) {
       mreq.rkind = MAlign;
       if (mreq.start == 0) {
@@ -2639,6 +2639,15 @@ ML_(generic_PRE_sys_mmap) ( ThreadId tid,
       /* VKI_MAP_FIXED and VKI_MAP_ALIGN don't like each other. */
       arg4 &= ~VKI_MAP_ALIGN;
    } else
+#endif
+#if defined(VGO_freebsd)
+   if (arg4 & VKI_MAP_ALIGNMENT_MASK) {
+      mreq.rkind = MAlign;
+      if (mreq.start == 0U) {
+         mreq.start = 1U << (arg4 >> VKI_MAP_ALIGNMENT_SHIFT);
+      }
+      arg4 &= ~VKI_MAP_ALIGNMENT_MASK;
+   } else
 #endif
    if (arg1 != 0) {
       mreq.rkind = MHint;
index a49650b2bc679d54b67094d5e21f7e21b5bc9d0e..b870025f0fa821d50fc6db78e6c5bd6d1cff280e 100644 (file)
@@ -1523,9 +1523,16 @@ typedef enum vki_idtype {
 #define VKI_MAP_PRIVATE 0x02     /* Changes are private */
 #define VKI_MAP_FIXED   0x10     /* Interpret addr exactly */
 #define VKI_MAP_NORESERVE  0x0040      /* don't check for reservations */
-#define  VKI_MAP_STACK  0x400
+#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_ANONYMOUS VKI_MAP_ANON
+
+#define VKI_MAP_ALIGNED(n)   ((n) << VKI_MAP_ALIGNMENT_SHIFT)
+#define VKI_MAP_ALIGNMENT_SHIFT     24
+#define VKI_MAP_ALIGNMENT_MASK      VKI_MAP_ALIGNED(0xff)
+#define VKI_MAP_ALIGNED_SUPER       VKI_MAP_ALIGNED(1) /* align on a superpage */
+
+
 
 //----------------------------------------------------------------------
 // From sys/stat.h
index d4c2474bbc5263520c88df3e122d79cf7e799630..d1f7759ec9ca3d850eaec78d382e6435b20a024f 100644 (file)
@@ -15,6 +15,9 @@ EXTRA_DIST = \
        bug452274.stderr.exp \
        bug498317.vgtest bug498317.stderr.exp \
        bug498317.supp \
+       bug499212.vgtest \
+       bug499212.stderr.exp \
+       bug499212.stdout.exp \
        cp.vgtest \
        cp.stderr.exp \
        osrel.vgtest \
@@ -63,8 +66,8 @@ EXTRA_DIST = \
        usrstack.stdout.exp
 
 check_PROGRAMS = \
-       auxv bug498317 osrel swapcontext hello_world fexecve bug452274 \
-        usrstack proc_pid_file sanity_level_thread umtx_shm_creat
+       auxv bug452274 bug498317 bug499212 fexecve hello_world osrel \
+        proc_pid_file sanity_level_thread swapcontext umtx_shm_creat usrstack
 
 AM_CFLAGS   += $(AM_FLAG_M3264_PRI)
 AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
diff --git a/none/tests/freebsd/bug499212.c b/none/tests/freebsd/bug499212.c
new file mode 100644 (file)
index 0000000..d6a81ce
--- /dev/null
@@ -0,0 +1,22 @@
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+
+int main(int argc, char **argv)
+{
+    void *buf =
+        mmap(NULL, 1 << 20, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_NOSYNC | MAP_ALIGNED(20) | MAP_ANON, -1, 0);
+    if (buf != MAP_FAILED)
+    {
+        assert(((uintptr_t)buf & 0xFFFFF) == 0);
+        if (((uintptr_t)buf & 0xFFFFF) != 0)
+        {
+            puts("Failure");
+            return EXIT_FAILURE;
+        }
+    }
+    puts("Success");
+    return EXIT_SUCCESS;
+}
diff --git a/none/tests/freebsd/bug499212.stderr.exp b/none/tests/freebsd/bug499212.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/freebsd/bug499212.stdout.exp b/none/tests/freebsd/bug499212.stdout.exp
new file mode 100644 (file)
index 0000000..3582111
--- /dev/null
@@ -0,0 +1 @@
+Success
diff --git a/none/tests/freebsd/bug499212.vgtest b/none/tests/freebsd/bug499212.vgtest
new file mode 100644 (file)
index 0000000..1e54676
--- /dev/null
@@ -0,0 +1,2 @@
+prog: bug499212
+vgopts: -q