From: Florian Krohm Date: Thu, 26 Mar 2015 21:55:00 +0000 (+0000) Subject: Add function VG_(am_is_valid_for_aspacem_minAddr) so that the parser X-Git-Tag: svn/VALGRIND_3_11_0~552 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=913972366f9b6c461a12ac0381a4825c5f846e18;p=thirdparty%2Fvalgrind.git Add function VG_(am_is_valid_for_aspacem_minAddr) so that the parser 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 --- diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 2c750a8c21..4568b7dc50 100644 --- a/coregrind/m_aspacemgr/aspacemgr-linux.c +++ b/coregrind/m_aspacemgr/aspacemgr-linux.c @@ -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 ) { diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 0f902f1335..365bb8212e 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -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); } } diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h index fde0f3262f..531a7209ac 100644 --- a/coregrind/pub_core_aspacemgr.h +++ b/coregrind/pub_core_aspacemgr.h @@ -61,6 +61,10 @@ 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