Detect and reject misaligned args for mmap.  This makes
none/tests/map_unaligned work.  The PRE handlers for sys_mmap and
sys_old_mmap are more convoluted than I would like, and might benefit
from a rewrite.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3284 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c
index 4a5e664..8abdea9 100644
--- a/coregrind/vg_syscalls.c
+++ b/coregrind/vg_syscalls.c
@@ -4054,6 +4054,12 @@
       return;
    }
 
+   if (/*(a4 & VKI_MAP_FIXED) &&*/ (0 != (a1 & (VKI_PAGE_SIZE-1)))) {
+      /* zap any misaligned addresses. */
+      SET_RESULT( -VKI_EINVAL );
+      return;
+   }
+
    if (a4 & VKI_MAP_FIXED) {
       if (!VG_(valid_client_addr)(a1, a2, tid, "old_mmap")) {
          PRINT("old_mmap failing: %p-%p\n", a1, a1+a2);
@@ -4098,6 +4104,12 @@
       return;
    }
 
+   if (/*(ARG4 & VKI_MAP_FIXED) && */ (0 != (ARG1 & (VKI_PAGE_SIZE-1)))) {
+      /* zap any misaligned addresses. */
+      SET_RESULT( -VKI_EINVAL );
+      return;
+   }
+
    if (ARG4 & VKI_MAP_FIXED) {
       if (!VG_(valid_client_addr)(ARG1, ARG2, tid, "mmap2"))
 	 SET_RESULT( -VKI_ENOMEM );