From: Nicholas Nethercote Date: Sun, 1 Aug 2004 22:36:40 +0000 (+0000) Subject: Cleaned up vg_include.h: X-Git-Tag: svn/VALGRIND_2_2_0~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a31e70a799fdfee1d506ea04ea5ac4c075323bc;p=thirdparty%2Fvalgrind.git Cleaned up vg_include.h: - removed various things that are no longer used - made (module-)local some things that were global - improved the formatting in places Removed about 160 lines of code, and non-trivially reduced the number of global entities. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2541 --- diff --git a/coregrind/vg_from_ucode.c b/coregrind/vg_from_ucode.c index 31673d4e75..73dcfeee47 100644 --- a/coregrind/vg_from_ucode.c +++ b/coregrind/vg_from_ucode.c @@ -2172,7 +2172,8 @@ static void emit_ret ( void ) /* Predicate used in sanity checks elsewhere - returns true if any jump-site is an actual chained jump */ -Bool VG_(is_chained_jumpsite)(Addr a) +__attribute__((unused)) +static Bool is_chained_jumpsite(Addr a) { UChar *cp = (UChar *)a; @@ -2192,7 +2193,7 @@ Bool is_fresh_jumpsite(UChar *cp) /* Predicate used in sanity checks elsewhere - returns true if all jump-sites are calls to VG_(patch_me) */ -Bool VG_(is_unchained_jumpsite)(Addr a) +static Bool is_unchained_jumpsite(Addr a) { UChar *cp = (UChar *)a; Int delta = ((Addr)&VG_(patch_me)) - (a + VG_PATCHME_CALLSZ); @@ -2232,7 +2233,7 @@ void VG_(unchain_jumpsite)(Addr a) Int delta = ((Addr)&VG_(patch_me)) - (a + VG_PATCHME_CALLSZ); UChar *cp = (UChar *)a; - if (VG_(is_unchained_jumpsite)(a)) + if (is_unchained_jumpsite(a)) return; /* don't write unnecessarily */ if (!is_fresh_jumpsite(cp)) diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index eecdc4e726..29ac330256 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -139,15 +139,6 @@ #define PGROUNDUP(p) ROUNDUP(p, VKI_BYTES_PER_PAGE) -/* --------------------------------------------------------------------- - Basic types - ------------------------------------------------------------------ */ - -/* Just pray that gcc's constant folding works properly ... */ -#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \ - ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \ - | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0)) - /* --------------------------------------------------------------------- Command-line-settable options ------------------------------------------------------------------ */ @@ -278,13 +269,9 @@ extern Bool VG_(clo_pointercheck); extern void VG_(intercept_libc_freeres_wrapper)(Addr); /* --------------------------------------------------------------------- - Debugging and profiling stuff + Profiling stuff ------------------------------------------------------------------ */ -/* Create a log file into which messages can be dumped. */ -extern void VG_(startup_logging) ( void ); -extern void VG_(shutdown_logging)( void ); - extern void VGP_(init_profiling) ( void ); extern void VGP_(done_profiling) ( void ); @@ -323,7 +310,6 @@ typedef struct { Bool libc_freeres; Bool core_errors; - Bool skin_errors; Bool basic_block_discards; Bool shadow_regs; @@ -398,11 +384,6 @@ extern void VG_(mallocSanityCheckAll) ( void ); extern void VG_(show_all_arena_stats) ( void ); extern Bool VG_(is_empty_arena) ( ArenaId aid ); -/* Returns True if aa is inside any block mmap'd /dev/zero - by our low-level memory manager. */ -extern Bool VG_(is_inside_segment_mmapd_by_low_level_MM)( Addr aa ); - - /* --------------------------------------------------------------------- Exports of vg_intercept.c ------------------------------------------------------------------ */ @@ -629,12 +610,9 @@ typedef struct _LDT_ENTRY { #define VG_LDT_ENTRY_SIZE 8 /* Alloc & copy, and dealloc. */ -extern VgLdtEntry* - VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt ); -extern void - VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt ); -extern void - VG_(clear_TLS_for_thread) ( VgLdtEntry* tls ); +extern VgLdtEntry* VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt ); +extern void VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt ); +extern void VG_(clear_TLS_for_thread) ( VgLdtEntry* tls ); /* Simulate the modify_ldt syscall. */ extern Int VG_(sys_modify_ldt) ( ThreadId tid, @@ -1082,18 +1060,13 @@ extern void VG_(route_signals) ( void ); /* Fake system calls for signal handling. */ extern void VG_(do__NR_sigaltstack) ( ThreadId tid ); extern void VG_(do__NR_sigaction) ( ThreadId tid ); -extern void VG_(do__NR_sigprocmask) ( ThreadId tid, - Int how, +extern void VG_(do__NR_sigprocmask) ( ThreadId tid, Int how, vki_ksigset_t* set, vki_ksigset_t* oldset ); -extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid, - Int how, +extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid, Int how, vki_ksigset_t* set, vki_ksigset_t* oldset ); -extern void VG_(send_signal_to_thread) ( ThreadId thread, - Int signo ); - -extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set ); +extern void VG_(send_signal_to_thread) ( ThreadId thread, Int signo ); /* Modify the current thread's state once we have detected it is @@ -1137,14 +1110,7 @@ extern void VG_(core_panic) ( Char* str ); extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); -extern Int VG_(select)( Int n, - vki_fd_set* readfds, - vki_fd_set* writefds, - vki_fd_set* exceptfds, - struct vki_timeval * timeout ); extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout); -extern Int VG_(nanosleep)( const struct vki_timespec *req, - struct vki_timespec *rem ); /* system/mman.h */ extern void* VG_(mmap)( void* start, UInt length, UInt prot, UInt flags, @@ -1162,8 +1128,6 @@ extern Int VG_(write_socket)( Int sd, void *msg, Int count ); extern Int VG_(connect_via_socket)( UChar* str ); /* Environment manipulations */ -extern Char **VG_(env_clone) ( Char **oldenv ); -extern Char* VG_(env_getenv) ( Char **env, Char* varname ); extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname, const Char *val ); extern void VG_(env_unsetenv) ( Char **env, const Char *varname ); @@ -1176,17 +1140,6 @@ extern void VG_(env_unsetenv) ( Char **env, const Char *varname ); extern void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes ); -/* --------------------------------------------------------------------- - Definitions for the JITter (vg_translate.c, vg_to_ucode.c, - vg_from_ucode.c). - ------------------------------------------------------------------ */ - -#define VG_IS_FLAG_SUBSET(set1,set2) \ - (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) ) - -#define VG_UNION_FLAG_SETS(set1,set2) \ - ( ((FlagSet)set1) | ((FlagSet)set2) ) - /* --------------------------------------------------------------------- Exports of vg_demangle.c ------------------------------------------------------------------ */ @@ -1204,8 +1157,6 @@ extern void VG_(print_UInstr_histogram) ( void ); extern void VG_(unchain_jumpsite) ( Addr jumpsite ); extern Addr VG_(get_jmp_dest) ( Addr jumpsite ); -extern Bool VG_(is_unchained_jumpsite) ( Addr jumpsite ); -extern Bool VG_(is_chained_jumpsite) ( Addr jumpsite ); /* --------------------------------------------------------------------- Exports of vg_to_ucode.c @@ -1376,8 +1327,8 @@ extern void VG_(read_procselfmaps) ( void ); extern void VG_(parse_procselfmaps) ( void (*record_mapping)( Addr addr, UInt len, Char rr, Char ww, Char xx, - UInt dev, UInt ino, ULong foff, const UChar *filename ) -); + UInt dev, UInt ino, ULong foff, + const UChar *filename ) ); /* --------------------------------------------------------------------- @@ -1389,7 +1340,6 @@ typedef struct _Segment Segment; extern Bool VG_(is_object_file) ( const void *hdr ); extern void VG_(mini_stack_dump) ( Addr eips[], UInt n_eips ); extern SegInfo * VG_(read_seg_symbols) ( Segment *seg ); -extern void VG_(unload_symbols) ( Addr start, UInt length ); extern void VG_(symtab_incref) ( SegInfo * ); extern void VG_(symtab_decref) ( SegInfo *, Addr a, UInt len ); @@ -1399,11 +1349,7 @@ extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname ); extern void VG_(setup_code_redirect_table) ( void ); /* Redirection machinery */ -extern void VG_(add_redirect_sym)(const Char *from_lib, const Char *from_sym, - const Char *to_lib, const Char *to_sym); -extern void VG_(add_redirect_addr)(const Char *from_lib, const Char *from_sym, - Addr to_addr); -extern Addr VG_(code_redirect) (Addr orig); +extern Addr VG_(code_redirect) ( Addr orig ); /* --------------------------------------------------------------------- Exports of vg_main.c @@ -1463,23 +1409,9 @@ extern UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W]; extern Int VG_(vg_argc); extern Char **VG_(vg_argv); -/* Indicates presence, and holds address of client's sysinfo page, a - feature of some modern kernels used to provide vsyscalls, etc. */ -extern Bool VG_(sysinfo_page_exists); -extern Addr VG_(sysinfo_page_addr); - -/* Walk through a colon separated list variable, removing entries - which match pattern. */ -extern void VG_(mash_colon_env)(Char *varp, const Char *pattern); - /* Something of a function looking for a home ... start up debugger. */ extern void VG_(start_debugger) ( Int tid ); -/* VG_(bbs_done) in include/vg_skin.h */ - -/* 64-bit counter for the number of bbs to go before a debug exit. */ -extern ULong VG_(bbs_to_go); - /* Counts downwards in vg_run_innerloop. */ extern UInt VG_(dispatch_ctr); @@ -1537,10 +1469,6 @@ extern UInt VG_(sanity_slow_count); extern UInt VG_(num_scheduling_events_MINOR); extern UInt VG_(num_scheduling_events_MAJOR); -/* Insert and extract the D flag from eflags */ -UInt VG_(insertDflag)(UInt eflags, Int d); -Int VG_(extractDflag)(UInt eflags); - /* --------------------------------------------------------------------- Exports of vg_memory.c ------------------------------------------------------------------ */ @@ -1550,21 +1478,21 @@ Int VG_(extractDflag)(UInt eflags); We try to encode everything we know about a particular segment here. */ -#define SF_FIXED (1 << 0) /* client asked for MAP_FIXED */ -#define SF_SHARED (1 << 1) /* shared */ -#define SF_SHM (1 << 2) /* SYSV SHM (also SF_SHARED) */ -#define SF_MMAP (1 << 3) /* mmap memory */ -#define SF_FILE (1 << 4) /* mapping is backed by a file */ -#define SF_STACK (1 << 5) /* is a stack */ -#define SF_GROWDOWN (1 << 6) /* segment grows down */ -#define SF_GROWUP (1 << 7) /* segment grows up */ -#define SF_EXEC (1 << 8) /* segment created by exec */ -#define SF_DYNLIB (1 << 9) /* mapped from dynamic library */ -#define SF_NOSYMS (1 << 10) /* don't load syms, even if present */ -#define SF_BRK (1 << 11) /* brk segment */ -#define SF_CORE (1 << 12) /* allocated by core on behalf of the client */ -#define SF_VALGRIND (1 << 13) /* a valgrind-internal mapping - not in client*/ -#define SF_CODE (1 << 14) /* segment contains cached code */ +#define SF_FIXED (1 << 0) // client asked for MAP_FIXED +#define SF_SHARED (1 << 1) // shared +#define SF_SHM (1 << 2) // SYSV SHM (also SF_SHARED) +#define SF_MMAP (1 << 3) // mmap memory +#define SF_FILE (1 << 4) // mapping is backed by a file +#define SF_STACK (1 << 5) // is a stack +#define SF_GROWDOWN (1 << 6) // segment grows down +#define SF_GROWUP (1 << 7) // segment grows up +#define SF_EXEC (1 << 8) // segment created by exec +#define SF_DYNLIB (1 << 9) // mapped from dynamic library +#define SF_NOSYMS (1 << 10) // don't load syms, even if present +#define SF_BRK (1 << 11) // brk segment +#define SF_CORE (1 << 12) // allocated by core on behalf of the client +#define SF_VALGRIND (1 << 13) // a valgrind-internal mapping - not in client +#define SF_CODE (1 << 14) // segment contains cached code struct _Segment { UInt prot; /* VKI_PROT_* */ @@ -1628,9 +1556,9 @@ extern void VG_(proxy_abort_syscall) ( ThreadId tid ); extern void VG_(proxy_waitsig) ( void ); extern void VG_(proxy_wait_sys) (ThreadId tid, Bool restart); -extern void VG_(proxy_shutdown) ( void ); /* shut down the syscall workers */ -extern Int VG_(proxy_resfd) ( void ); /* FD something can select on to know - a syscall finished */ +extern void VG_(proxy_shutdown) ( void ); // shut down the syscall workers +extern Int VG_(proxy_resfd) ( void ); // FD something can select on to know + // a syscall finished /* Sanity-check the whole proxy-LWP machinery */ void VG_(proxy_sanity)(void); @@ -1641,10 +1569,6 @@ __attribute__ ((__noreturn__)) extern void VG_(proxy_handlesig)( const vki_ksiginfo_t *siginfo, const struct vki_sigcontext *sigcontext ); -/* Get the PID/TID of the ProxyLWP. */ -extern Int VG_(proxy_id)(ThreadId tid); - - /* --------------------------------------------------------------------- Exports of vg_syscalls.c ------------------------------------------------------------------ */ @@ -1653,7 +1577,6 @@ extern Char *VG_(resolve_filename)(Int fd); extern Bool VG_(pre_syscall) ( ThreadId tid ); extern void VG_(post_syscall)( ThreadId tid, Bool restart ); -extern void VG_(restart_syscall) ( ThreadId tid ); extern Bool VG_(is_kerror) ( Int res ); @@ -1665,6 +1588,10 @@ extern void VG_(atfork)(vg_atfork_t pre, vg_atfork_t parent, vg_atfork_t child); extern void VG_(init_preopened_fds) ( void ); extern void VG_(fd_stats) ( void ); +/* Walk through a colon separated list variable, removing entries + which match pattern. */ +extern void VG_(mash_colon_env)(Char *varp, const Char *pattern); + /* --------------------------------------------------------------------- Exports of vg_transtab.c ------------------------------------------------------------------ */ @@ -1672,8 +1599,6 @@ extern void VG_(fd_stats) ( void ); /* The fast-cache for tt-lookup. */ extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE]; -extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used ); - extern void VG_(add_to_trans_tab) ( Addr orig_addr, Int orig_size, Addr trans_addr, Int trans_size, UShort jumps[VG_MAX_JUMPS]); @@ -1685,8 +1610,6 @@ extern void VG_(init_tt_tc) ( void ); extern void VG_(sanity_check_tc_tt) ( void ); extern Addr VG_(search_transtab) ( Addr original_addr ); - - /* --------------------------------------------------------------------- Exports of vg_syscall.S ------------------------------------------------------------------ */ diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index 86ca8e1dd2..d314e267ec 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -116,11 +116,6 @@ vki_rlimit VG_(client_rlimit_data); SSE/fxsave/fxrestor features. */ Bool VG_(have_ssestate); -/* Indicates presence, and holds address of client's sysinfo page, a - feature of some modern kernels used to provide vsyscalls, etc. */ -Bool VG_(sysinfo_page_exists) = False; -Addr VG_(sysinfo_page_addr) = 0; - /* stage1 (main) executable */ Int VG_(vgexecfd) = -1; @@ -1675,9 +1670,7 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname ) for (auxp = client_auxv; auxp[0] != VKI_AT_NULL; auxp += 2) { switch(auxp[0]) { case VKI_AT_SYSINFO: - VG_(sysinfo_page_exists) = True; auxp[1] = (Int)(VG_(client_trampoline_code) + VG_(tramp_syscall_offset)); - VG_(sysinfo_page_addr) = auxp[1]; break; } } @@ -2173,29 +2166,6 @@ UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; static Int baB_off = 0; -UInt VG_(insertDflag)(UInt eflags, Int d) -{ - vg_assert(d == 1 || d == -1); - eflags &= ~EFlagD; - - if (d < 0) - eflags |= EFlagD; - - return eflags; -} - -Int VG_(extractDflag)(UInt eflags) -{ - Int ret; - - if (eflags & EFlagD) - ret = -1; - else - ret = 1; - - return ret; -} - /* Returns the offset, in words. */ static Int alloc_BaB ( Int words ) { @@ -3074,8 +3044,7 @@ int main(int argc, char **argv) //-------------------------------------------------------------- switch (src) { case VgSrc_ExitSyscall: /* the normal way out */ - vg_assert(VG_(last_run_tid) > 0 - && VG_(last_run_tid) < VG_N_THREADS); + vg_assert(VG_(last_run_tid) > 0 && VG_(last_run_tid) < VG_N_THREADS); VG_(proxy_shutdown)(); /* The thread's %EBX at the time it did __NR_exit() will hold diff --git a/coregrind/vg_malloc2.c b/coregrind/vg_malloc2.c index a3ddbd3a58..10a8bac4a5 100644 --- a/coregrind/vg_malloc2.c +++ b/coregrind/vg_malloc2.c @@ -298,28 +298,6 @@ void ensure_mm_init ( void ) } -/* Returns True if aa is inside any segment mmap'd /dev/zero - by our low-level memory manager. */ -Bool VG_(is_inside_segment_mmapd_by_low_level_MM)( Addr aa ) -{ - ArenaId ar; - Superblock* sb; - - ensure_mm_init(); - - for (ar = 0; ar < VG_N_ARENAS; ar++) { - for (sb = vg_arena[ar].sblocks; sb; sb = sb->next) { - Addr sb_first_word = (Addr)sb; - Addr sb_last_word - = (Addr)&(sb->payload_words[sb->n_payload_words-1]); - if (aa >= sb_first_word && aa <= sb_last_word) - return True; - } - } - return False; -} - - /*------------------------------------------------------------*/ /*--- Superblock management stuff ---*/ /*------------------------------------------------------------*/ diff --git a/coregrind/vg_messages.c b/coregrind/vg_messages.c index 98e7c227d0..5c0fd892d0 100644 --- a/coregrind/vg_messages.c +++ b/coregrind/vg_messages.c @@ -1,7 +1,7 @@ /*--------------------------------------------------------------------*/ /*--- For sending error/informative messages. ---*/ -/*--- vg_message.c ---*/ +/*--- vg_messages.c ---*/ /*--------------------------------------------------------------------*/ /* @@ -126,15 +126,6 @@ void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes ) } } - -void VG_(startup_logging) ( void ) -{ -} - -void VG_(shutdown_logging) ( void ) -{ -} - /*--------------------------------------------------------------------*/ -/*--- end vg_message.c ---*/ +/*--- end vg_messages.c ---*/ /*--------------------------------------------------------------------*/ diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c index 860e8c9e85..b5cf91dbea 100644 --- a/coregrind/vg_mylibc.c +++ b/coregrind/vg_mylibc.c @@ -334,24 +334,6 @@ Int VG_(fcntl) ( Int fd, Int cmd, Int arg ) return VG_(is_kerror)(res) ? -1 : res; } -/* Returns -1 on error. */ -Int VG_(select)( Int n, - vki_fd_set* readfds, - vki_fd_set* writefds, - vki_fd_set* exceptfds, - struct vki_timeval * timeout ) -{ - Int res; - UInt args[5]; - args[0] = n; - args[1] = (UInt)readfds; - args[2] = (UInt)writefds; - args[3] = (UInt)exceptfds; - args[4] = (UInt)timeout; - res = VG_(do_syscall)(__NR_select, (UInt)(&(args[0])) ); - return VG_(is_kerror)(res) ? -1 : res; -} - Int VG_(poll)( struct vki_pollfd *ufds, UInt nfds, Int timeout) { Int res = VG_(do_syscall)(__NR_poll, ufds, nfds, timeout); @@ -359,17 +341,6 @@ Int VG_(poll)( struct vki_pollfd *ufds, UInt nfds, Int timeout) return res; } -/* Returns -1 on error, 0 if ok, 1 if interrupted. */ -Int VG_(nanosleep)( const struct vki_timespec *req, - struct vki_timespec *rem ) -{ - Int res; - res = VG_(do_syscall)(__NR_nanosleep, (UInt)req, (UInt)rem); - if (res == -VKI_EINVAL) return -1; - if (res == -VKI_EINTR) return 1; - return 0; -} - /* --------------------------------------------------------------------- printf implementation. The key function, vg_vprintf(), emits chars @@ -1146,7 +1117,6 @@ static void report_and_quit ( const Char* report ) report); VG_(printf)("In the bug report, send all the above text, the valgrind\n"); VG_(printf)("version, and what Linux distro you are using. Thanks.\n\n"); - VG_(shutdown_logging)(); VG_(exit)(1); } @@ -1350,7 +1320,7 @@ Bool VG_(getcwd_alloc) ( Char** out ) ------------------------------------------------------------------ */ /* clone the environment */ -Char **VG_(env_clone) ( Char **oldenv ) +static Char **env_clone ( Char **oldenv ) { Char **oldenvp; Char **newenvp; @@ -1432,12 +1402,14 @@ Char **VG_(env_setenv) ( Char ***envp, const Char* varname, const Char *val ) return oldenv; } -Char* VG_(env_getenv) ( Char **env, Char* varname ) +/* We do getenv without libc's help by snooping around in + VG_(client_envp) as determined at startup time. */ +Char *VG_(getenv)(Char *varname) { Int i, n; n = VG_(strlen)(varname); - for (i = 0; env[i] != NULL; i++) { - Char* s = env[i]; + for (i = 0; VG_(client_envp)[i] != NULL; i++) { + Char* s = VG_(client_envp)[i]; if (VG_(strncmp)(varname, s, n) == 0 && s[n] == '=') { return & s[n+1]; } @@ -1445,13 +1417,6 @@ Char* VG_(env_getenv) ( Char **env, Char* varname ) return NULL; } -/* We do getenv without libc's help by snooping around in - VG_(client_envp) as determined at startup time. */ -Char *VG_(getenv)(Char *varname) -{ - return VG_(env_getenv)(VG_(client_envp), varname); -} - /* Support for getrlimit. */ Int VG_(getrlimit) (Int resource, struct vki_rlimit *rlim) { @@ -1547,7 +1512,7 @@ Int VG_(system) ( Char* cmd ) Char* ld_library_path_str = NULL; Char* buf; - envp = VG_(env_clone)(VG_(client_envp)); + envp = env_clone(VG_(client_envp)); for (i = 0; envp[i] != NULL; i++) { if (VG_(strncmp)(envp[i], "LD_PRELOAD=", 11) == 0) diff --git a/coregrind/vg_needs.c b/coregrind/vg_needs.c index da4bc9cfee..f41328d657 100644 --- a/coregrind/vg_needs.c +++ b/coregrind/vg_needs.c @@ -125,7 +125,6 @@ void VG_(sanity_check_needs) ( void) } #undef CHECK_NOT -#undef INVALID_Bool } /*--------------------------------------------------------------------*/ diff --git a/coregrind/vg_proxylwp.c b/coregrind/vg_proxylwp.c index b069201bda..3d7e88d01f 100644 --- a/coregrind/vg_proxylwp.c +++ b/coregrind/vg_proxylwp.c @@ -1372,12 +1372,11 @@ void VG_(proxy_sanity)(void) } /* Get the PID/TID of the ProxyLWP. */ -Int VG_(proxy_id)(ThreadId tid) +__attribute__((unused)) +static Int proxy_id(ThreadId tid) { ThreadState *tst = VG_(get_ThreadState)(tid); - ProxyLWP *proxy = tst->proxy; - - return proxy->lwp; + return tst->proxy->lwp; } /*--------------------------------------------------------------------*/ diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index 740b41d855..e1e772324c 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -332,6 +332,19 @@ ThreadId VG_(get_current_or_recent_tid) ( void ) return vg_tid_last_in_baseBlock; } +static UInt insertDflag(UInt eflags, Int d) +{ + vg_assert(d == 1 || d == -1); + eflags &= ~EFlagD; + if (d < 0) eflags |= EFlagD; + return eflags; +} + +static Int extractDflag(UInt eflags) +{ + return ( eflags & EFlagD ? -1 : 1 ); +} + /* Copy the saved state of a thread into VG_(baseBlock), ready for it to be run. */ void VG_(load_thread_state) ( ThreadId tid ) @@ -359,7 +372,7 @@ void VG_(load_thread_state) ( ThreadId tid ) VG_(baseBlock)[VGOFF_(m_eflags)] = VG_(threads)[tid].m_eflags & ~EFlagD; VG_(baseBlock)[VGOFF_(m_dflag)] - = VG_(extractDflag)(VG_(threads)[tid].m_eflags); + = extractDflag(VG_(threads)[tid].m_eflags); VG_(baseBlock)[VGOFF_(m_eip)] = VG_(threads)[tid].m_eip; for (i = 0; i < VG_SIZE_OF_SSESTATE_W; i++) @@ -451,8 +464,8 @@ void VG_(save_thread_state) ( ThreadId tid ) VG_(threads)[tid].m_ebp = VG_(baseBlock)[VGOFF_(m_ebp)]; VG_(threads)[tid].m_esp = VG_(baseBlock)[VGOFF_(m_esp)]; VG_(threads)[tid].m_eflags - = VG_(insertDflag)(VG_(baseBlock)[VGOFF_(m_eflags)], - VG_(baseBlock)[VGOFF_(m_dflag)]); + = insertDflag(VG_(baseBlock)[VGOFF_(m_eflags)], + VG_(baseBlock)[VGOFF_(m_dflag)]); VG_(threads)[tid].m_eip = VG_(baseBlock)[VGOFF_(m_eip)]; for (i = 0; i < VG_SIZE_OF_SSESTATE_W; i++) @@ -1048,8 +1061,7 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode ) = VG_(search_transtab) ( VG_(threads)[tid].m_eip ); if (trans_addr == (Addr)0) { /* Not found; we need to request a translation. */ - create_translation_for( - tid, VG_(threads)[tid].m_eip ); + create_translation_for( tid, VG_(threads)[tid].m_eip ); trans_addr = VG_(search_transtab) ( VG_(threads)[tid].m_eip ); if (trans_addr == (Addr)0) VG_(core_panic)("VG_TRC_INNER_FASTMISS: missing tt_fast entry"); diff --git a/coregrind/vg_symtab2.c b/coregrind/vg_symtab2.c index 62263233bc..cd4d79aee2 100644 --- a/coregrind/vg_symtab2.c +++ b/coregrind/vg_symtab2.c @@ -830,6 +830,10 @@ VG_(intercept_demangle)(const Char* symbol, Char* result, Int nbytes) return True; } +// Forward declaration +static void add_redirect_addr(const Char *from_lib, const Char *from_sym, + Addr to_addr); + static void handle_intercept( SegInfo* si, Char* symbol, Elf32_Sym* sym) { @@ -843,7 +847,7 @@ void handle_intercept( SegInfo* si, Char* symbol, Elf32_Sym* sym) while(*func != ':') func--; *func = '\0'; - VG_(add_redirect_addr)(lib, func+1, si->offset + sym->st_value); + add_redirect_addr(lib, func+1, si->offset + sym->st_value); VG_(free)(lib); } @@ -1595,7 +1599,7 @@ SegInfo *VG_(read_seg_symbols) ( Segment *seg ) accuracy of error messages, but we need to do it in order to maintain the no-overlapping invariant. */ -void VG_(unload_symbols) ( Addr start, UInt length ) +static void unload_symbols ( Addr start, UInt length ) { SegInfo *prev, *curr; @@ -1633,7 +1637,7 @@ void VG_(symtab_decref)(SegInfo *si, Addr start, UInt len) { vg_assert(si->ref >= 1); if (--si->ref == 0) - VG_(unload_symbols)(si->start, si->size); + unload_symbols(si->start, si->size); } void VG_(symtab_incref)(SegInfo *si) @@ -2449,8 +2453,8 @@ static Bool resolve_redir_allsegs(CodeRedirect *redir) } /* Redirect a lib/symbol reference to a function at lib/symbol */ -void VG_(add_redirect_sym)(const Char *from_lib, const Char *from_sym, - const Char *to_lib, const Char *to_sym) +static void add_redirect_sym(const Char *from_lib, const Char *from_sym, + const Char *to_lib, const Char *to_sym) { CodeRedirect *redir = VG_(SkipNode_Alloc)(&sk_resolved_redir); @@ -2475,8 +2479,8 @@ void VG_(add_redirect_sym)(const Char *from_lib, const Char *from_sym, } /* Redirect a lib/symbol reference to a function at lib/symbol */ -void VG_(add_redirect_addr)(const Char *from_lib, const Char *from_sym, - Addr to_addr) +static void add_redirect_addr(const Char *from_lib, const Char *from_sym, + Addr to_addr) { CodeRedirect *redir = VG_(SkipNode_Alloc)(&sk_resolved_redir); @@ -2522,30 +2526,29 @@ void VG_(setup_code_redirect_table) ( void ) Int i; for(i = 0; i < sizeof(redirects)/sizeof(*redirects); i++) { - VG_(add_redirect_sym)("soname:libc.so.6", redirects[i].from, - "soname:libpthread.so.0", redirects[i].to); + add_redirect_sym("soname:libc.so.6", redirects[i].from, + "soname:libpthread.so.0", redirects[i].to); } /* Redirect _dl_sysinfo_int80, which is glibc's default system call routine, to the routine in our trampoline page so that the special sysinfo unwind hack in vg_execontext.c will kick in. */ - VG_(add_redirect_addr)("soname:ld-linux.so.2", "_dl_sysinfo_int80", - VG_(client_trampoline_code)+VG_(tramp_syscall_offset)); + add_redirect_addr("soname:ld-linux.so.2", "_dl_sysinfo_int80", + VG_(client_trampoline_code)+VG_(tramp_syscall_offset)); /* Overenthusiastic use of PLT bypassing by the glibc people also means we need to patch the following functions to our own implementations of said, in mac_replace_strmem.c. */ - VG_(add_redirect_sym)("soname:libc.so.6", "stpcpy", - "*vgpreload_memcheck.so*", "stpcpy"); - VG_(add_redirect_sym)("soname:libc.so.6", "strnlen", - "*vgpreload_memcheck.so*", "strnlen"); - - VG_(add_redirect_sym)("soname:ld-linux.so.2", "stpcpy", - "*vgpreload_memcheck.so*", "stpcpy"); - VG_(add_redirect_sym)("soname:ld-linux.so.2", "strchr", - "*vgpreload_memcheck.so*", "strchr"); + add_redirect_sym("soname:libc.so.6", "stpcpy", + "*vgpreload_memcheck.so*", "stpcpy"); + add_redirect_sym("soname:libc.so.6", "strnlen", + "*vgpreload_memcheck.so*", "strnlen"); + add_redirect_sym("soname:ld-linux.so.2", "stpcpy", + "*vgpreload_memcheck.so*", "stpcpy"); + add_redirect_sym("soname:ld-linux.so.2", "strchr", + "*vgpreload_memcheck.so*", "strchr"); } /*------------------------------------------------------------*/ diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c index e1532260f6..eae5c86282 100644 --- a/coregrind/vg_syscalls.c +++ b/coregrind/vg_syscalls.c @@ -5908,6 +5908,34 @@ Bool VG_(pre_syscall) ( ThreadId tid ) return syscall_done; } +static void restart_syscall(ThreadId tid) +{ + ThreadState* tst; + tst = VG_(get_ThreadState)(tid); + + vg_assert(tst != NULL); + vg_assert(tst->status == VgTs_WaitSys); + vg_assert(tst->syscallno != -1); + + tst->m_eax = tst->syscallno; + tst->m_eip -= 2; /* sizeof(int $0x80) */ + + /* Make sure our caller is actually sane, and we're really backing + back over a syscall. + + int $0x80 == CD 80 + */ + { + UChar *p = (UChar *)tst->m_eip; + + if (p[0] != 0xcd || p[1] != 0x80) + VG_(message)(Vg_DebugMsg, + "?! restarting over syscall at %p %02x %02x\n", + tst->m_eip, p[0], p[1]); + + vg_assert(p[0] == 0xcd && p[1] == 0x80); + } +} void VG_(post_syscall) ( ThreadId tid, Bool restart ) { @@ -5954,7 +5982,7 @@ void VG_(post_syscall) ( ThreadId tid, Bool restart ) if (restart) { restarted = True; - VG_(restart_syscall)(tid); + restart_syscall(tid); } else tst->m_eax = -VKI_EINTR; } @@ -5984,35 +6012,6 @@ void VG_(post_syscall) ( ThreadId tid, Bool restart ) VGP_POPCC(VgpCoreSysWrap); } -void VG_(restart_syscall)(ThreadId tid) -{ - ThreadState* tst; - tst = VG_(get_ThreadState)(tid); - - vg_assert(tst != NULL); - vg_assert(tst->status == VgTs_WaitSys); - vg_assert(tst->syscallno != -1); - - tst->m_eax = tst->syscallno; - tst->m_eip -= 2; /* sizeof(int $0x80) */ - - /* Make sure our caller is actually sane, and we're really backing - back over a syscall. - - int $0x80 == CD 80 - */ - { - UChar *p = (UChar *)tst->m_eip; - - if (p[0] != 0xcd || p[1] != 0x80) - VG_(message)(Vg_DebugMsg, - "?! restarting over syscall at %p %02x %02x\n", - tst->m_eip, p[0], p[1]); - - vg_assert(p[0] == 0xcd && p[1] == 0x80); - } -} - /*--------------------------------------------------------------------*/ /*--- end vg_syscalls.c ---*/ /*--------------------------------------------------------------------*/ diff --git a/coregrind/vg_translate.c b/coregrind/vg_translate.c index 696ef01bc2..c3ac29849b 100644 --- a/coregrind/vg_translate.c +++ b/coregrind/vg_translate.c @@ -42,6 +42,12 @@ /*--- Basics ---*/ /*------------------------------------------------------------*/ +#define VG_IS_FLAG_SUBSET(set1,set2) \ + (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) ) + +#define VG_UNION_FLAG_SETS(set1,set2) \ + ( ((FlagSet)set1) | ((FlagSet)set2) ) + /* This one is called by the core */ UCodeBlock* VG_(alloc_UCodeBlock) ( void ) {