]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
converted mmap and mmap2
authorNicholas Nethercote <n.nethercote@gmail.com>
Mon, 15 Nov 2004 12:57:39 +0000 (12:57 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 15 Nov 2004 12:57:39 +0000 (12:57 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3003

coregrind/vg_syscalls.c
coregrind/x86-linux/core_platform.h
memcheck/tests/scalar.c
memcheck/tests/scalar.stderr.exp

index b7315ecdfe5ef7d8ba157f8a95f61818cdb8deec..a3be6ceaa3f76ef37211c742dcd6e760ab8f04fc 100644 (file)
@@ -4463,17 +4463,18 @@ PREx(sys_mkdir, MayBlock)
    PRE_MEM_RASCIIZ( "mkdir(pathname)", arg1 );
 }
 
-PRE(mmap2)
+PREx(sys_mmap2, 0)
 {
-   // Exactly like __NR_mmap except:
+   // Exactly like old_mmap() except:
    //  - all 6 args are passed in regs, rather than in a memory-block.
    //  - the file offset is specified in pagesize units rather than bytes,
    //    so that it can be used for files bigger than 2^32 bytes.
-   /* void* mmap2(void *start, size_t length, int prot, 
-                  int flags, int fd, off_t offset); 
-   */
-   PRINT("mmap2 ( %p, %llu, %d, %d, %d, %d )",
-               arg1, (ULong)arg2, arg3, arg4, arg5, arg6 );
+   PRINT("sys_mmap2 ( %p, %llu, %d, %d, %d, %d )",
+         arg1, (ULong)arg2, arg3, arg4, arg5, arg6 );
+   PRE_REG_READ6(long, "mmap2",
+                 unsigned long, start, unsigned long, length,
+                 unsigned long, prot,  unsigned long, flags,
+                 unsigned long, fd,    unsigned long, offset);
 
    if (arg4 & VKI_MAP_FIXED) {
       if (!valid_client_addr(arg1, arg2, tid, "mmap2"))
@@ -4487,44 +4488,49 @@ PRE(mmap2)
    }
 }
 
-POST(mmap2)
+POSTx(sys_mmap2)
 {
    vg_assert(valid_client_addr(res, arg2, tid, "mmap2"));
-   mmap_segment( (Addr)res, arg2, arg3, arg4, arg5, arg6 * (ULong)VKI_PAGE_SIZE );
+   mmap_segment( (Addr)res, arg2, arg3, arg4, arg5,
+                 arg6 * (ULong)VKI_PAGE_SIZE );
 }
 
-PRE(mmap)
+PREx(old_mmap, Special)
 {
-   /* void* mmap(void *start, size_t length, int prot, 
-      int flags, int fd, off_t offset); 
-   */
-
+   /* struct mmap_arg_struct {           
+         unsigned long addr;
+         unsigned long len;
+         unsigned long prot;
+         unsigned long flags;
+         unsigned long fd;
+         unsigned long offset;
+   }; */
    UInt a1, a2, a3, a4, a5, a6;
 
-   vg_assert(tid = tst->tid);
+   PRE_REG_READ1(long, "old_mmap", struct mmap_arg_struct *, args);
    PLATFORM_GET_MMAP_ARGS(tst, a1, a2, a3, a4, a5, a6);
 
-   PRINT("mmap ( %p, %llu, %d, %d, %d, %d )",
-               a1, (ULong)a2, a3, a4, a5, a6 );
+   PRINT("old_mmap ( %p, %llu, %d, %d, %d, %d )",
+         a1, (ULong)a2, a3, a4, a5, a6 );
 
    if (a4 & VKI_MAP_FIXED) {
-      if (!valid_client_addr(a1, a2, tid, "mmap")) {
-        PRINT("mmap failing: %p-%p\n", a1, a1+a2);
-        set_result( -VKI_ENOMEM );
+      if (!valid_client_addr(a1, a2, tid, "old_mmap")) {
+         PRINT("old_mmap failing: %p-%p\n", a1, a1+a2);
+         set_result( -VKI_ENOMEM );
       }
    } else {
       a1 = VG_(find_map_space)(a1, a2, True);
       if (a1 == 0)
-        set_result( -VKI_ENOMEM );
+         set_result( -VKI_ENOMEM );
       else
-        a4 |= VKI_MAP_FIXED;
+         a4 |= VKI_MAP_FIXED;
    }
 
    if (res != -VKI_ENOMEM) {
       PLATFORM_DO_MMAP(res, a1, a2, a3, a4, a5, a6);
 
       if (!VG_(is_kerror)(res)) {
-         vg_assert(valid_client_addr(res, a2, tid, "mmap"));
+         vg_assert(valid_client_addr(res, a2, tid, "old_mmap"));
          mmap_segment( (Addr)res, a2, a3, a4, a5, a6 );
       }
    }
@@ -4883,7 +4889,7 @@ PREx(old_select, MayBlock)
       };
    */
    PRE_REG_READ1(long, "old_select", struct sel_arg_struct *, args);
-   PRE_MEM_READ( "old_select(args)", arg1, 5*sizeof(UInt) );
+   PRE_MEM_READ( "old_select(args)", arg1, 5*sizeof(UWord) );
 
    {
       UInt* arg_struct = (UInt*)arg1;
@@ -6419,7 +6425,7 @@ static const struct sys_info sys_info[] = {
    //   (__NR_reboot,           sys_reboot),       // 88 * L
    //   (__NR_readdir,          old_readdir),      // 89 () L -- superseded
 
-   SYSB_(__NR_mmap,             old_mmap, Special), // 90  old_mmap
+   SYSX_(__NR_mmap,             old_mmap),         // 90 (x86) (P but not...)
    SYSXY(__NR_munmap,           sys_munmap),       // 91 * P
    SYSX_(__NR_truncate,         sys_truncate),     // 92 * P
    SYSX_(__NR_ftruncate,        sys_ftruncate),    // 93 * P
@@ -6544,7 +6550,7 @@ static const struct sys_info sys_info[] = {
    // Nb: we convert vfork() to fork() in VG_(pre_syscall)().
    //   (__NR_vfork,            sys_vfork),        // 190 -- Valgrind avoids
    SYSXY(__NR_ugetrlimit,       sys_getrlimit),    // 191 * (?)
-   SYSBA(__NR_mmap2,            sys_mmap2, 0),     // 192 
+   SYSXY(__NR_mmap2,            sys_mmap2),        // 192 (x86?) P?
    SYSX_(__NR_truncate64,       sys_truncate64),   // 193 %% (P?)
    SYSX_(__NR_ftruncate64,      sys_ftruncate64),  // 194 %% (P?)
    
index 81299ec2ede5dcc1dbdb6450440e7abd282f7b19..17ad5651a031c4ab89846d2831818a4241a39e17 100644 (file)
@@ -115,7 +115,7 @@ extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr );
 
 #define PLATFORM_GET_MMAP_ARGS(tst, a1, a2, a3, a4, a5, a6) do {\
    UInt *arg_block = (UInt*)PLATFORM_SYSCALL_ARG1(tst->arch);   \
-   PRE_MEM_READ( "mmap(args)", arg1, 6*sizeof(UWord) );         \
+   PRE_MEM_READ( "old_mmap(args)", arg1, 6*sizeof(UWord) );     \
    a1 = arg_block[0];                                           \
    a2 = arg_block[1];                                           \
    a3 = arg_block[2];                                           \
index 367f2d43e147bf5524e5b93bd85b619c118262be..f045fda02b0bb23c543a2a268d264caab8594eae 100644 (file)
@@ -360,9 +360,12 @@ int main(void)
    // __NR_readdir 89
    // (superseded, not handled by Valgrind)
 
-   // __NR_mmap 90
- //GO(__NR_mmap, ".s .m");
- //SY(__NR_mmap);
+   // __NR_mmap 90 --> old_mmap()
+   {
+      long args[6] = { x0, x0, x0, x0, x0-1, x0 };
+      GO(__NR_mmap, "1s 0m");
+      SY(__NR_mmap, args+x0);
+   }
 
    // __NR_munmap 91 --> sys_munmap()
    GO(__NR_munmap, "2s 0m");
@@ -776,9 +779,9 @@ int main(void)
    GO(__NR_ugetrlimit, "2s 1m");
    SY(__NR_ugetrlimit, x0, x0);
 
-   // __NR_mmap2 192
//GO(__NR_mmap2, ".s .m");
//SY(__NR_mmap2);
+   // __NR_mmap2 192 --> sys_mmap()
  GO(__NR_mmap2, "5s 0m");
  SY(__NR_mmap2, x0, x0, x0, x0, x0-1, x0);
 
    // __NR_truncate64 193 --> sys_truncate64()
    GO(__NR_truncate64, "3s 1m");
index 9118099c1d573967ce62c4d4de66e0c3d42a4153..62d41ac7112615fa1d186b23d1bbe8aea01e7964 100644 (file)
@@ -1040,6 +1040,14 @@ Syscall param readlink(buf) points to unaddressable byte(s)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
  Address 0x........ is not stack'd, malloc'd or (recently) free'd
+-----------------------------------------------------
+ 90:           __NR_mmap 1s 0m
+-----------------------------------------------------
+
+Syscall param old_mmap(args) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
 -----------------------------------------------------
  91:         __NR_munmap 2s 0m
 -----------------------------------------------------
@@ -1823,6 +1831,34 @@ Syscall param getrlimit(rlim) points to unaddressable byte(s)
    by 0x........: ...
  Address 0x........ is not stack'd, malloc'd or (recently) free'd
 -----------------------------------------------------
+192:          __NR_mmap2 5s 0m
+-----------------------------------------------------
+
+Syscall param mmap2(start) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param mmap2(length) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param mmap2(prot) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param mmap2(flags) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param mmap2(fd) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+-----------------------------------------------------
 193:     __NR_truncate64 3s 1m
 -----------------------------------------------------