]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added assertion checking to a whole bunch of mmap() and munmap() calls. I used
authorNicholas Nethercote <n.nethercote@gmail.com>
Sat, 10 Jul 2004 17:49:17 +0000 (17:49 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sat, 10 Jul 2004 17:49:17 +0000 (17:49 +0000)
assertions because if these calls fail, it's a bug in Valgrind.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2474

coregrind/vg_main.c
coregrind/vg_scheduler.c
coregrind/vg_symtab2.c
coregrind/vg_syscalls.c

index 70873438df8fecec2bf609f6d3bda4cc18f42035..14c302b78725e76026c8fe5890876a8754a16f81 100644 (file)
@@ -501,6 +501,9 @@ static void layout_client_space(Addr argc_addr)
 
 static void layout_remaining_space(float ratio)
 {
+   Int   ires;
+   void* vres;
+   
    /* This tries to give the client as large as possible address space while
     * taking into account the tool's shadow needs.  */
    addr_t client_size = ROUNDDN((VG_(valgrind_base) - REDZONE_SIZE) / (1. + ratio), 
@@ -542,17 +545,21 @@ static void layout_remaining_space(float ratio)
 #undef SEGSIZE
 
    // Ban redzone
-   mmap((void *)VG_(client_end), REDZONE_SIZE, PROT_NONE,
-       MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
+   vres = mmap((void *)VG_(client_end), REDZONE_SIZE, PROT_NONE,
+               MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
+   vg_assert((void*)-1 != vres);
 
    // Make client hole
-   munmap((void*)VG_(client_base), client_size);
+   ires = munmap((void*)VG_(client_base), client_size);
+   vg_assert(0 == ires);
 
    // Map shadow memory.
    // Initially all inaccessible, incrementally initialized as it is used
-   if (shadow_size != 0)
-      mmap((char *)VG_(shadow_base), shadow_size, PROT_NONE,
-         MAP_PRIVATE|MAP_ANON|MAP_FIXED, -1, 0);
+   if (shadow_size != 0) {
+      vres = mmap((char *)VG_(shadow_base), shadow_size, PROT_NONE,
+                  MAP_PRIVATE|MAP_ANON|MAP_FIXED, -1, 0);
+      vg_assert((void*)-1 != vres);
+   }
 }
 
 /*====================================================================*/
@@ -980,6 +987,7 @@ static Addr setup_client_stack(char **orig_argv, char **orig_envp,
                               const struct exeinfo *info,
                                UInt** client_auxv)
 {
+   void* res;
    char **cpp;
    char *strtab;               /* string table */
    char *stringbase;
@@ -1066,11 +1074,10 @@ static Addr setup_client_stack(char **orig_argv, char **orig_envp,
    /* ==================== allocate space ==================== */
 
    /* allocate a stack - mmap enough space for the stack */
-   mmap((void *)PGROUNDDN(cl_esp),
-       VG_(client_end) - PGROUNDDN(cl_esp),
-       PROT_READ | PROT_WRITE | PROT_EXEC, 
-       MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
-   
+   res = mmap((void *)PGROUNDDN(cl_esp), VG_(client_end) - PGROUNDDN(cl_esp),
+             PROT_READ | PROT_WRITE | PROT_EXEC, 
+             MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
+   vg_assert((void*)-1 != res); 
 
    /* ==================== copy client stack ==================== */
 
index dd6f1658d6850c99fef530108aa24696fcd5832d..b8efb724f12d2ee0aa9cb7939644dd9e208601ed 100644 (file)
@@ -1939,8 +1939,9 @@ void do__apply_in_new_thread ( ThreadId parent_tid,
       if (VG_(threads)[tid].stack_size > 0)
          VG_(client_free)(VG_(threads)[tid].stack_base);
       new_stack = VG_(client_alloc)(0, new_stk_szb, 
-                                   VKI_PROT_READ | VKI_PROT_WRITE | VKI_PROT_EXEC, 
+                                   VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC, 
                                    SF_STACK);
+      vg_assert(0 != new_stack);
       VG_(threads)[tid].stack_base = new_stack;
       VG_(threads)[tid].stack_size = new_stk_szb;
       VG_(threads)[tid].stack_highest_word
index 2fafa8d2c76b7e793317ff605b5d0af17da19028..029be637b072cd877a3928a544ceb20600f38787 100644 (file)
@@ -1105,7 +1105,8 @@ Addr open_debug_file( Char* name, UInt crc, UInt* size )
    VG_(close)(fd);
    
    if (calc_gnu_debuglink_crc32(0, (UChar*)addr, *size) != crc) {
-      VG_(munmap)((void*)addr, *size);
+      int res = VG_(munmap)((void*)addr, *size);
+      vg_assert(0 == res);
       return 0;
    }
    
@@ -1492,11 +1493,17 @@ Bool vg_read_lib_symbols ( SegInfo* si )
    }
    res = True;
 
-  out:
+  out: {
+   Int m_res;
    /* Last, but not least, heave the image(s) back overboard. */
-   if (dimage) VG_(munmap) ( (void*)dimage, n_dimage );
-   VG_(munmap) ( (void*)oimage, n_oimage );
+   if (dimage) {
+      m_res = VG_(munmap) ( (void*)dimage, n_dimage );
+      vg_assert(0 == m_res);
+   }
+   m_res = VG_(munmap) ( (void*)oimage, n_oimage );
+   vg_assert(0 == m_res);
    return res;
+  } 
 }
 
 /*------------------------------------------------------------*/
index 1cd85247abd7f5d8bcf3b0c5fe9fa10d44e6d33b..e8d844fdbdb10faf24d6e905a921f3c24cb9eeb1 100644 (file)
@@ -998,7 +998,8 @@ static Addr do_brk(Addr newbrk)
                        current, newaddr, current-newaddr);
 
         if (newaddr != current) {
-           VG_(munmap)((void *)newaddr, current - newaddr);
+           int res = VG_(munmap)((void *)newaddr, current - newaddr);
+            vg_assert(0 == res);
         }
         ret = newbrk;
       }