Index: dlfcn.c =================================================================== --- dlfcn.c (revision 19) +++ dlfcn.c (working copy) @@ -1,6 +1,6 @@ /* * dlfcn-win32 - * Copyright (c) 2007 Ramiro Polla + * Copyright (c) 2007, 2010 Ramiro Polla, Tycho Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,7 +18,9 @@ */ #include +#include #include +#include #include "dlfcn.h" @@ -75,7 +77,6 @@ return; pobject->next = nobject; - nobject->next = NULL; nobject->previous = pobject; nobject->hModule = hModule; } @@ -228,6 +229,15 @@ save_err_str( lpFileName ); else if( (mode & RTLD_GLOBAL) ) global_add( hModule ); + else if( (mode & RTLD_NOLOAD) ) + { + global_object *pobject = global_search( hModule ); + + // when RLTD_NOLOAD is set, POSIX says that the module handle + // returned is NULL when the object was not previously loaded. + if(!pobject) + hModule = NULL; + } } /* Return to previous state of the error-mode bit flags. */ @@ -312,3 +322,45 @@ return error_pointer; } + +// adapted from http://gcc.gnu.org/ml/java-patches/2006-q2/msg00511.html +int dladdr(void *addr, Dl_info *info) +{ + MEMORY_BASIC_INFORMATION mbi; + HMODULE hMod; + + printf("addr: %p\n", addr); + + if (!VirtualQuery (addr, &mbi, sizeof (mbi))) + { + save_err_str("VirtualQuery() failed!\n"); + return 0; + } + hMod = (HMODULE) mbi.AllocationBase; + + char module_name[MAX_PATH]; + + // FIXME: We explicitly use the ANSI variant of the function here. + if (!GetModuleFileNameA (hMod, module_name, sizeof (module_name))) + { + save_err_str("GetModuleFileNameA() failed!"); + return 0; + } + + strcpy (info->dli_fname, module_name); + + info->dli_fbase = mbi.BaseAddress; + + // this is *probably* right + info->dli_saddr = addr; + strcpy (info->dli_sname, module_name); + + return 1; +} + +void *dlvsym(void *handle, char *symbol, char *version) +{ + // FIXME + save_err_str("dlvsym() not implemented"); + return NULL; +} Index: dlfcn.h =================================================================== --- dlfcn.h (revision 19) +++ dlfcn.h (working copy) @@ -1,6 +1,6 @@ /* * dlfcn-win32 - * Copyright (c) 2007 Ramiro Polla + * Copyright (c) 2007, 2010 Ramiro Polla, Tycho Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,6 +29,7 @@ #define RTLD_GLOBAL (1 << 1) #define RTLD_LOCAL (1 << 2) +#define RTLD_NOLOAD (1 << 3) /* These two were added in The Open Group Base Specifications Issue 6. * Note: All other RTLD_* flags in any dlfcn.h are not standard compliant. @@ -42,4 +43,16 @@ void *dlsym ( void *handle, const char *name ); char *dlerror( void ); +/* these are extensions for _GNU_SOURCE */ + +typedef struct { + const char *dli_fname;/* Filename of defining object */ + void *dli_fbase; /* Load address of that object */ + const char *dli_sname;/* Name of nearest lower symbol */ + void *dli_saddr; /* Exact value of nearest symbol */ +} Dl_info; + +int dladdr(void *addr, Dl_info *info); +void *dlvsym(void *handle, char *symbol, char *version); + #endif /* DLFCN_H */