]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add function VG_(am_is_valid_for_aspacem_minAddr) so that the parser
authorFlorian Krohm <florian@eich-krohm.de>
Thu, 26 Mar 2015 21:55:00 +0000 (21:55 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Thu, 26 Mar 2015 21:55:00 +0000 (21:55 +0000)
for command line options does not need to know what addresses are valid
for aspacem_minAddr.
That information should be hidden in the address space manager.

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

coregrind/m_aspacemgr/aspacemgr-linux.c
coregrind/m_main.c
coregrind/pub_core_aspacemgr.h

index 2c750a8c219273688b04570de926e3c5cf04bab3..4568b7dc5018eebfd2bfec7b71e03778a01be47c 100644 (file)
@@ -1603,6 +1603,30 @@ static void read_maps_callback ( Addr addr, SizeT len, UInt prot,
    add_segment( &seg );
 }
 
+Bool
+VG_(am_is_valid_for_aspacem_minAddr)( Addr addr, const HChar **errmsg )
+{
+   const Addr min = 0x1000;      // 1 page   FIXME: VKI_PAGE_SIZE ?
+#if VG_WORDSIZE == 4
+   const Addr max = 0x40000000;  // 1Gb
+#else
+   const Addr max = 0x200000000; // 8Gb
+#endif
+   Bool ok = VG_IS_PAGE_ALIGNED(addr) && addr >= min && addr <= max;
+
+   if (errmsg) {
+      *errmsg = "";
+      if (! ok) {
+         const HChar fmt[] = "Must be a page aligned address between "
+                             "0x%lx and 0x%lx";
+         static HChar buf[sizeof fmt + 2 * 16];   // large enough
+         ML_(am_sprintf)(buf, fmt, min, max);
+         *errmsg = buf;
+      }
+   }
+   return ok;
+}
+
 /* See description in pub_core_aspacemgr.h */
 Addr VG_(am_startup) ( Addr sp_at_startup )
 {
index 0f902f1335ad5c66d0664099c3a5cc70b7a33bbb..365bb8212e3b991580552a6bf67e729d88b33d05 100644 (file)
@@ -1666,21 +1666,13 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
       if VG_BINT_CLO(argv[i], "--redzone-size", VG_(clo_redzone_size),
                      0, MAX_CLO_REDZONE_SZB) {}
       if VG_STR_CLO(argv[i], "--aspace-minaddr", tmp_str) {
-#        if VG_WORDSIZE == 4
-         const Addr max = (Addr) 0x40000000; // 1Gb
-#        else
-         const Addr max = (Addr) 0x200000000; // 8Gb
-#        endif
          Bool ok = VG_(parse_Addr) (&tmp_str, &VG_(clo_aspacem_minAddr));
          if (!ok)
             VG_(fmsg_bad_option)(argv[i], "Invalid address\n");
-
-         if (!VG_IS_PAGE_ALIGNED(VG_(clo_aspacem_minAddr))
-             || VG_(clo_aspacem_minAddr) < (Addr) 0x1000
-             || VG_(clo_aspacem_minAddr) > max) // 1Gb
-            VG_(fmsg_bad_option)(argv[i], 
-                                 "Must be a page aligned address between "
-                                 "0x1000 and 0x%lx\n", max);
+         const HChar *errmsg;
+         if (!VG_(am_is_valid_for_aspacem_minAddr)(VG_(clo_aspacem_minAddr),
+                                                   &errmsg))
+            VG_(fmsg_bad_option)(argv[i], "%s\n", errmsg);
       }
    }
 
index fde0f3262f1e0b771681397274b3e54eb3423fc9..531a7209acedc1a76477935056f2d7fbb87d048d 100644 (file)
    suggested end address (highest addressable byte) for the client's stack. */
 extern Addr VG_(am_startup) ( Addr sp_at_startup );
 
+/* Check whether ADDR is OK to be used as aspacem_minAddr. If not, *ERRMSG
+   will be set to identify what's wrong. ERRMSG may be NULL. */
+extern Bool VG_(am_is_valid_for_aspacem_minAddr)( Addr addr,
+                                                  const HChar **errmsg );
 
 //--------------------------------------------------------------
 // Querying current status