From: Nicholas Nethercote Date: Mon, 26 Jul 2004 15:43:57 +0000 (+0000) Subject: Added some comments. X-Git-Tag: svn/VALGRIND_2_2_0~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4421ac53b708b420ae99d9b855d4682c4e09ac48;p=thirdparty%2Fvalgrind.git Added some comments. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2531 --- diff --git a/coregrind/ume.c b/coregrind/ume.c index c0bdb0a8b1..89ffe8e05d 100644 --- a/coregrind/ume.c +++ b/coregrind/ume.c @@ -667,6 +667,8 @@ static int do_exec_inner(const char *exe, struct exeinfo *info) return ret; } +// See ume.h for an indication of which entries of 'info' are inputs, which +// are outputs, and which are both. int do_exec(const char *exe, struct exeinfo *info) { info->interp_name = NULL; diff --git a/coregrind/ume.h b/coregrind/ume.h index 70008e1815..1155edecda 100644 --- a/coregrind/ume.h +++ b/coregrind/ume.h @@ -54,26 +54,32 @@ typedef ESZ(Addr) addr_t; /*--- Loading ELF files ---*/ /*------------------------------------------------------------*/ +// Info needed to load and run a program. IN/INOUT/OUT refers to the +// inputs/outputs of do_exec(). struct exeinfo { - addr_t map_base; // INPUT: if non-zero, base address of mappings - char** argv; // INPUT: the original argv + addr_t map_base; // IN: if non-zero, base address of mappings + char** argv; // IN: the original argv addr_t exe_base; // INOUT: lowest (allowed) address of exe addr_t exe_end; // INOUT: highest (allowed) address - addr_t phdr; // address phdr was mapped at - int phnum; // number of phdrs - addr_t interp_base; // where interpreter (ld.so) was mapped - addr_t entry; // entrypoint in main executable - addr_t init_eip; // initial eip - addr_t brkbase; // base address of brk segment + addr_t phdr; // OUT: address phdr was mapped at + int phnum; // OUT: number of phdrs + addr_t interp_base; // OUT: where interpreter (ld.so) was mapped + addr_t entry; // OUT: entrypoint in main executable + addr_t init_eip; // OUT: initial eip + addr_t brkbase; // OUT: base address of brk segment // These are the extra args added by #! scripts - char* interp_name; // INPUT: the interpreter name - char* interp_args; // INPUT: the args for the interpreter + char* interp_name; // OUT: the interpreter name + char* interp_args; // OUT: the args for the interpreter }; +// Does everything short of actually running 'exe': finds the file, +// checks execute permissions, sets up interpreter if program is a script, +// reads headers, maps file into memory, and returns important info about +// the program. int do_exec(const char *exe, struct exeinfo *info); /*------------------------------------------------------------*/ @@ -84,6 +90,7 @@ void foreach_map(int (*fn)(void *start, void *end, const char *perm, off_t offset, int maj, int min, int ino)); +// Padding functions used at startup to force things where we want them. void as_pad(void *start, void *end); void as_unpad(void *start, void *end); void as_closepadfile(void); diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index f3470c5516..c3f45232e3 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -1445,13 +1445,13 @@ static void load_client(char* cl_argv[], const char* exec, Int need_help, } info->map_base = VG_(client_mapbase); - info->exe_base = VG_(client_base); info->exe_end = VG_(client_end); info->argv = cl_argv; if (need_help) { VG_(clexecfd) = -1; + // Set the minimal number of entries in 'info' to continue. info->interp_name = NULL; info->interp_args = NULL; } else { @@ -1459,7 +1459,8 @@ static void load_client(char* cl_argv[], const char* exec, Int need_help, VG_(clexecfd) = VG_(open)(exec, O_RDONLY, VKI_S_IRUSR); ret = do_exec(exec, info); if (ret != 0) { - fprintf(stderr, "valgrind: do_exec(%s) failed: %s\n", exec, strerror(ret)); + fprintf(stderr, "valgrind: do_exec(%s) failed: %s\n", + exec, strerror(ret)); exit(127); } }