From 8c2ef347b4099661391b943d260ea348aa20a32c Mon Sep 17 00:00:00 2001 From: jodom Date: Fri, 13 Jan 2006 00:00:47 +0000 Subject: [PATCH] Sets the brk pointer for save-the-world binaries to what it was when each dynamic library loaded by loadLibrary() is loaded. This forces the libraries to load in the correct location. --- dyninstAPI/src/BPatch_process.C | 7 ++++++- dyninstAPI/src/process.C | 11 +++++++---- dyninstAPI/src/process.h | 6 ++++-- dyninstAPI_RT/h/dyninstAPI_RT.h | 5 ++++- dyninstAPI_RT/make.module.tmpl | 6 +++++- dyninstAPI_RT/src/RTaix.c | 4 +++- dyninstAPI_RT/src/RTcommon.c | 4 +++- dyninstAPI_RT/src/RTlinux.c | 5 ++--- dyninstAPI_RT/src/RTmutatedBinary.c | 6 ++++-- dyninstAPI_RT/src/RTmutatedBinary_ELF.c | 5 +++-- dyninstAPI_RT/src/RTmutatedBinary_XCOFF.c | 16 ++++++++++++++-- dyninstAPI_RT/src/RTosf.c | 3 ++- dyninstAPI_RT/src/RTsolaris.c | 4 ++-- 13 files changed, 59 insertions(+), 23 deletions(-) diff --git a/dyninstAPI/src/BPatch_process.C b/dyninstAPI/src/BPatch_process.C index a87c33c..dfedf93 100644 --- a/dyninstAPI/src/BPatch_process.C +++ b/dyninstAPI/src/BPatch_process.C @@ -1435,10 +1435,15 @@ bool BPatch_process::loadLibraryInt(const char *libname, bool) BPatch_reportError(BPatchSerious, 124, dlerror_str); return false; } + BPatch_variableExpr *brk_ptr_var = + image->findVariable("gBRKptr"); + assert(NULL != brk_ptr_var); + void *brk_ptr; + brk_ptr_var->readValue(&brk_ptr, sizeof(void *)); #if defined(cap_save_the_world) && defined(BPATCH_LIBRARY) if(llproc->collectSaveWorldData && reload){ - llproc->saveWorldloadLibrary(libname); + llproc->saveWorldloadLibrary(libname, brk_ptr); } #endif return true; diff --git a/dyninstAPI/src/process.C b/dyninstAPI/src/process.C index ef77356..225c8a6 100644 --- a/dyninstAPI/src/process.C +++ b/dyninstAPI/src/process.C @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -// $Id: process.C,v 1.565 2006/01/11 15:41:30 chadd Exp $ +// $Id: process.C,v 1.566 2006/01/13 00:00:47 jodom Exp $ #include @@ -881,7 +881,7 @@ void process::saveWorldCreateHighMemSections( unsigned int startPage, stopPage; unsigned int numberUpdates=1; int startIndex, stopIndex; - void *data; + char *data; char name[50]; #if defined(sparc_sun_solaris2_4) \ || defined(i386_unknown_linux2_0) \ @@ -1082,7 +1082,7 @@ void process::saveWorldAddSharedLibs(void *ptr){ // ccw 14 may 2002 #endif for(unsigned i=0;i 1){ diff --git a/dyninstAPI/src/process.h b/dyninstAPI/src/process.h index c658f8e..c03b971 100644 --- a/dyninstAPI/src/process.h +++ b/dyninstAPI/src/process.h @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -/* $Id: process.h,v 1.343 2006/01/06 16:53:18 bernat Exp $ +/* $Id: process.h,v 1.344 2006/01/13 00:00:47 jodom Exp $ * process.h - interface to manage a process in execution. A process is a kernel * visible unit with a seperate code and data space. It might not be * the only unit running the code, but it is only one changed when @@ -375,8 +375,9 @@ char * systemPrelinkCommand; void *newElf); void saveWorldCreateDataSections(void* ptr); void saveWorldAddSharedLibs(void *ptr);//ccw 14 may 2002 - void saveWorldloadLibrary(pdstring tmp) { + void saveWorldloadLibrary(pdstring tmp, void *brk_ptr) { loadLibraryUpdates.push_back(tmp); + loadLibraryBRKs.push_back(brk_ptr); }; #if defined(os_aix) @@ -1044,6 +1045,7 @@ void inferiorFree(process *p, Address item, const pdvector &); pdvector dataUpdates;//ccw 26 nov 2001 pdvector loadLibraryCalls;//ccw 14 may 2002 pdvector loadLibraryUpdates;//ccw 14 may 2002 + pdvector loadLibraryBRKs; int requestTextMiniTramp; //ccw 20 jul 2002 diff --git a/dyninstAPI_RT/h/dyninstAPI_RT.h b/dyninstAPI_RT/h/dyninstAPI_RT.h index 4d28e22..d85f32d 100644 --- a/dyninstAPI_RT/h/dyninstAPI_RT.h +++ b/dyninstAPI_RT/h/dyninstAPI_RT.h @@ -40,7 +40,7 @@ */ /* - * $Id: dyninstAPI_RT.h,v 1.27 2005/10/17 15:49:23 legendre Exp $ + * $Id: dyninstAPI_RT.h,v 1.28 2006/01/13 00:00:48 jodom Exp $ * This file contains the standard instrumentation functions that are provided * by the run-time instrumentation layer. */ @@ -70,6 +70,9 @@ typedef unsigned char RT_Boolean; static const RT_Boolean RT_TRUE=1; static const RT_Boolean RT_FALSE=0; +extern char gLoadLibraryErrorString[]; +extern void *gBRKptr; + struct DYNINST_bootstrapStruct { int event; /* "event" values: 0 --> nothing diff --git a/dyninstAPI_RT/make.module.tmpl b/dyninstAPI_RT/make.module.tmpl index 8ce8348..7384448 100644 --- a/dyninstAPI_RT/make.module.tmpl +++ b/dyninstAPI_RT/make.module.tmpl @@ -2,7 +2,7 @@ # Common makefile template for rtinst library. This file is not # intended to be a useful Makefile in isolation; instead, it should be # included from within an architecture-specific Makefile. -# $Id: make.module.tmpl,v 1.19 2005/09/28 17:02:29 bernat Exp $ +# $Id: make.module.tmpl,v 1.20 2006/01/13 00:00:48 jodom Exp $ # SUITE_NAME = Dyninst @@ -23,6 +23,10 @@ ifdef USES_SHM_SAMPLING CFLAGS += -DSHM_SAMPLING endif +ifdef LIBELF_INC +CFLAGS += -I$(LIBELF_INC) +endif + all: $(TARGET) #OBJS = $(patsubst %.C, %.o, $(filter %.C,$(notdir $(SRCS)))) \ diff --git a/dyninstAPI_RT/src/RTaix.c b/dyninstAPI_RT/src/RTaix.c index a60837f..cc5c2f5 100644 --- a/dyninstAPI_RT/src/RTaix.c +++ b/dyninstAPI_RT/src/RTaix.c @@ -48,6 +48,7 @@ #include /* dlopen constants */ #include #include +#include /************************************************************************ * void DYNINSTos_init(void) @@ -70,13 +71,14 @@ void DYNINSTos_init(int calledByFork, int calledByAttach) #define NOT_SETUP_ERR 0x2468ace0 -char gLoadLibraryErrorString[ERROR_STRING_LENGTH]; int DYNINSTloadLibrary(char *libname) { void *res; char *err_str; gLoadLibraryErrorString[0]='\0'; + gBRKptr = sbrk(0); + if (NULL == (res = dlopen(libname, RTLD_NOW | RTLD_GLOBAL))) { /* An error has occurred */ perror( "DYNINSTloadLibrary -- dlopen" ); diff --git a/dyninstAPI_RT/src/RTcommon.c b/dyninstAPI_RT/src/RTcommon.c index e544a33..90a1f22 100644 --- a/dyninstAPI_RT/src/RTcommon.c +++ b/dyninstAPI_RT/src/RTcommon.c @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -/* $Id: RTcommon.c,v 1.49 2005/10/17 15:49:26 legendre Exp $ */ +/* $Id: RTcommon.c,v 1.50 2006/01/13 00:00:48 jodom Exp $ */ #include #include @@ -51,6 +51,8 @@ unsigned int DYNINSTobsCostLow; unsigned int DYNINSThasInitialized; unsigned DYNINST_max_num_threads; struct DYNINST_bootstrapStruct DYNINST_bootstrap_info; +char gLoadLibraryErrorString[ERROR_STRING_LENGTH]; +void *gBRKptr; /** * Allocate the Dyninst heaps diff --git a/dyninstAPI_RT/src/RTlinux.c b/dyninstAPI_RT/src/RTlinux.c index 487b007..253780e 100644 --- a/dyninstAPI_RT/src/RTlinux.c +++ b/dyninstAPI_RT/src/RTlinux.c @@ -40,7 +40,7 @@ */ /************************************************************************ - * $Id: RTlinux.c,v 1.35 2005/10/17 15:49:27 legendre Exp $ + * $Id: RTlinux.c,v 1.36 2006/01/13 00:00:48 jodom Exp $ * RTlinux.c: mutatee-side library function specific to Linux ************************************************************************/ @@ -147,8 +147,6 @@ typedef struct dlopen_args { void *(*DYNINST_do_dlopen)(dlopen_args_t *) = NULL; -char gLoadLibraryErrorString[ERROR_STRING_LENGTH]; - static int get_dlopen_error() { char *err_str; err_str = dlerror(); @@ -167,6 +165,7 @@ int DYNINSTloadLibrary(char *libname) { void *res; gLoadLibraryErrorString[0]='\0'; + gBRKptr = sbrk(0); res = dlopen(libname, RTLD_NOW | RTLD_GLOBAL); if (res) { diff --git a/dyninstAPI_RT/src/RTmutatedBinary.c b/dyninstAPI_RT/src/RTmutatedBinary.c index 91dee28..ad898a2 100644 --- a/dyninstAPI_RT/src/RTmutatedBinary.c +++ b/dyninstAPI_RT/src/RTmutatedBinary.c @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -/* $Id: RTmutatedBinary.c,v 1.8 2005/04/05 16:45:22 jodom Exp $ */ +/* $Id: RTmutatedBinary.c,v 1.9 2006/01/13 00:00:48 jodom Exp $ */ /* this file contains the code to restore the necessary data for a mutated binary @@ -75,7 +75,9 @@ void RTmutatedBinary_init(){ if (!init) { buffer = (char*) malloc(getpagesize()); isMutatedExec =checkMutatedFile(); - free(buffer); + /* Can't free this buffer, because we need the same memory footprint + for when we load in shared libraries */ + /* free(buffer); */ init++; } diff --git a/dyninstAPI_RT/src/RTmutatedBinary_ELF.c b/dyninstAPI_RT/src/RTmutatedBinary_ELF.c index 1813ab0..d1f2de5 100644 --- a/dyninstAPI_RT/src/RTmutatedBinary_ELF.c +++ b/dyninstAPI_RT/src/RTmutatedBinary_ELF.c @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -/* $Id: RTmutatedBinary_ELF.c,v 1.20 2006/01/11 15:41:31 chadd Exp $ */ +/* $Id: RTmutatedBinary_ELF.c,v 1.21 2006/01/13 00:00:48 jodom Exp $ */ /* this file contains the code to restore the necessary data for a mutated binary @@ -1194,7 +1194,8 @@ int checkMutatedFile(){ exit(9); } - tmpPtr += (strlen(tmpPtr) +1); + /* brk ptr not used for ELF */ + tmpPtr += (strlen(tmpPtr) +1 + sizeof(void *)); } diff --git a/dyninstAPI_RT/src/RTmutatedBinary_XCOFF.c b/dyninstAPI_RT/src/RTmutatedBinary_XCOFF.c index 9eb1da0..fd2d9b8 100644 --- a/dyninstAPI_RT/src/RTmutatedBinary_XCOFF.c +++ b/dyninstAPI_RT/src/RTmutatedBinary_XCOFF.c @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -/* $Id: RTmutatedBinary_XCOFF.c,v 1.9 2005/04/05 16:45:22 jodom Exp $ */ +/* $Id: RTmutatedBinary_XCOFF.c,v 1.10 2006/01/13 00:00:48 jodom Exp $ */ /* this file contains the code to restore the necessary @@ -189,11 +189,22 @@ int checkMutatedFile(){ /* use dlopen to load a list of shared libraries */ int len; + void *old_brk, *new_brk; data = (char*) XCOFFfile + currScnhdr->s_scnptr; + memcpy( &new_brk, data + strlen(data) + 1, sizeof(void *)); while(*data != '\0'){ + if ((old_brk = sbrk(0)) > new_brk) { + printf("current BRK 0x%p > desired BRK 0x%p for %s!\n", + old_brk, + new_brk, + data); + fflush(stdout); + } else { + brk(new_brk); + } DYNINSTloadLibrary(data); - data += (strlen(data) +1); + data += (strlen(data) +1 + sizeof(void *)); } }else if(!strcmp( currScnhdr->s_name, "dyn_dat")){ /* reload data */ @@ -376,6 +387,7 @@ int checkMutatedFile(){ memcpy((void*)currScnhdr->s_vaddr, oldPageData,oldPageDataSize ); } } + free(oldPageData); } } diff --git a/dyninstAPI_RT/src/RTosf.c b/dyninstAPI_RT/src/RTosf.c index 6a62a30..7dd1bd2 100644 --- a/dyninstAPI_RT/src/RTosf.c +++ b/dyninstAPI_RT/src/RTosf.c @@ -50,6 +50,7 @@ #include #include #include /* dlopen() */ +#include #include "dyninstAPI_RT/src/RTthread.h" /* The alpha does not have a divide instruction */ /* Division is emulated in software */ @@ -58,12 +59,12 @@ int divide(int a,int b) return (a/b); } -char gLoadLibraryErrorString[ERROR_STRING_LENGTH]; int DYNINSTloadLibrary(char *libname) { void *res; char *err_str; gLoadLibraryErrorString[0]='\0'; + gBRKptr = sbrk(0); if (NULL == (res = dlopen(libname, RTLD_NOW | RTLD_GLOBAL))) { // An error has occurred diff --git a/dyninstAPI_RT/src/RTsolaris.c b/dyninstAPI_RT/src/RTsolaris.c index c127dbf..dfe6e74 100644 --- a/dyninstAPI_RT/src/RTsolaris.c +++ b/dyninstAPI_RT/src/RTsolaris.c @@ -40,7 +40,7 @@ */ /************************************************************************ - * $Id: RTsolaris.c,v 1.22 2005/10/17 19:24:26 bernat Exp $ + * $Id: RTsolaris.c,v 1.23 2006/01/13 00:00:48 jodom Exp $ * RTsolaris.c: mutatee-side library function specific to Solaris ************************************************************************/ @@ -81,12 +81,12 @@ DYNINSTos_init(int calledByFork, int calledByAttach) /* setmemwrite(); */ } -char gLoadLibraryErrorString[ERROR_STRING_LENGTH]; int DYNINSTloadLibrary(char *libname) { void *res; char *err_str; gLoadLibraryErrorString[0]='\0'; + gBRKptr = sbrk(0); if (NULL == (res = dlopen(libname, RTLD_NOW | RTLD_GLOBAL))) { /* An error has occurred */ -- 1.8.3.1