diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:48 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:48 -0800 |
commit | 4e468ed2eb86a2406e14f1eca82072ee501d05fd (patch) | |
tree | 4e05b3c66eef86531e464521a3bf96a1864d4bf5 /linker | |
parent | a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349 (diff) | |
download | bionic-4e468ed2eb86a2406e14f1eca82072ee501d05fd.zip bionic-4e468ed2eb86a2406e14f1eca82072ee501d05fd.tar.gz bionic-4e468ed2eb86a2406e14f1eca82072ee501d05fd.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'linker')
-rw-r--r-- | linker/debugger.c | 20 | ||||
-rw-r--r-- | linker/linker.c | 32 | ||||
-rw-r--r-- | linker/linker_debug.h | 10 |
3 files changed, 40 insertions, 22 deletions
diff --git a/linker/debugger.c b/linker/debugger.c index 68997c5..542cf8d 100644 --- a/linker/debugger.c +++ b/linker/debugger.c @@ -16,20 +16,20 @@ void debugger_signal_handler(int n) { unsigned tid; int s; - - /* avoid picking up GC interrupts */ + + /* avoid picking up GC interrupts */ signal(SIGUSR1, SIG_IGN); - + tid = gettid(); s = socket_local_client("android:debuggerd", ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); - + if(s >= 0) { - /* debugger knows our pid from the credentials on the - ** local socket but we need to tell it our tid. It - ** is paranoid and will verify that we are giving a tid - ** that's actually in our process - */ + /* debugger knows our pid from the credentials on the + * local socket but we need to tell it our tid. It + * is paranoid and will verify that we are giving a tid + * that's actually in our process + */ write(s, &tid, sizeof(unsigned)); read(s, &tid, 1); @@ -37,7 +37,7 @@ void debugger_signal_handler(int n) close(s); } - /* remove our net so we fault for real when we return */ + /* remove our net so we fault for real when we return */ signal(n, SIG_IGN); } diff --git a/linker/linker.c b/linker/linker.c index 88e3ea2..34ed80e 100644 --- a/linker/linker.c +++ b/linker/linker.c @@ -7,6 +7,7 @@ #include <fcntl.h> #include <errno.h> #include <dlfcn.h> +#include <sys/stat.h> //#include <pthread.h> @@ -409,6 +410,21 @@ static const char *sopaths[] = { 0 }; +static int _open_lib(const char *name) +{ + int fd; + struct stat filestat; + + if ((stat(name, &filestat) >= 0) && S_ISREG(filestat.st_mode)) { + if ((fd = open(name, O_RDONLY)) >= 0) + return fd; + } + + return -1; +} + +/* TODO: Need to add support for initializing the so search path with + * LD_LIBRARY_PATH env variable for non-setuid programs. */ static int open_library(const char *name) { int fd; @@ -417,16 +433,16 @@ static int open_library(const char *name) TRACE("[ %5d opening %s ]\n", pid, name); - if(strlen(name) > 256) return -1; if(name == 0) return -1; + if(strlen(name) > 256) return -1; - fd = open(name, O_RDONLY); - if(fd != -1) return fd; + if ((name[0] == '/') && ((fd = _open_lib(name)) >= 0)) + return fd; - for(path = sopaths; *path; path++){ - sprintf(buf,"%s/%s", *path, name); - fd = open(buf, O_RDONLY); - if(fd != -1) return fd; + for (path = sopaths; *path; path++) { + snprintf(buf, sizeof(buf), "%s/%s", *path, name); + if ((fd = _open_lib(buf)) >= 0) + return fd; } return -1; @@ -1026,7 +1042,7 @@ unsigned unload_library(soinfo *si) } else { si->refcount--; - ERROR("%5d not unloading '%s', decrementing refcount to %d\n", + PRINT("%5d not unloading '%s', decrementing refcount to %d\n", pid, si->name, si->refcount); } return si->refcount; diff --git a/linker/linker_debug.h b/linker/linker_debug.h index 10ae7b1..fa2a1a1 100644 --- a/linker/linker_debug.h +++ b/linker/linker_debug.h @@ -27,15 +27,17 @@ #define TRUE 1 #define FALSE 0 + +#define __PRINTVF(v,f,x...) do { \ + (debug_verbosity > (v)) && (printf(x), ((f) && fflush(stdout))); \ + } while (0) /* Only use printf() during debugging. We have seen occasional memory * corruption when the linker uses printf(). */ #if LINKER_DEBUG extern int debug_verbosity; #warning "*** LINKER IS USING printf(); DO NOT CHECK THIS IN ***" -#define _PRINTVF(v,f,x...) do { \ - (debug_verbosity > (v)) && (printf(x), ((f) && fflush(stdout))); \ - } while (0) +#define _PRINTVF(v,f,x...) __PRINTVF(v,f,x) #else /* !LINKER_DEBUG */ #define _PRINTVF(v,f,x...) do {} while(0) #endif /* LINKER_DEBUG */ @@ -46,7 +48,7 @@ extern int debug_verbosity; #define WARN(fmt,args...) \ _PRINTVF(-1, TRUE, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args) #define ERROR(fmt,args...) \ - _PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args) + __PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args) #if TRACE_DEBUG #define DEBUG(x...) _PRINTVF(2, TRUE, "DEBUG: " x) |