mirror of https://github.com/FWGS/xash3d-fwgs
platform/android/dlsym-weak: fix code style
This commit is contained in:
parent
ffe1ff326a
commit
96c367973a
|
@ -32,24 +32,26 @@
|
|||
#include <dlfcn.h>
|
||||
#include "linker.h"
|
||||
|
||||
static Elf_Sym* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
|
||||
static Elf_Sym* soinfo_elf_lookup( soinfo* si, unsigned hash, const char* name )
|
||||
{
|
||||
Elf_Sym* symtab = si->symtab;
|
||||
const char* strtab = si->strtab;
|
||||
|
||||
if( si->nbucket == 0 )
|
||||
return NULL;
|
||||
|
||||
for (unsigned n = si->bucket[hash % si->nbucket]; n != 0; n = si->chain[n]) {
|
||||
for( unsigned n = si->bucket[hash % si->nbucket]; n != 0; n = si->chain[n] )
|
||||
{
|
||||
Elf_Sym* s = symtab + n;
|
||||
if (strcmp(strtab + s->st_name, name)) continue;
|
||||
if( strcmp( strtab + s->st_name, name )) continue;
|
||||
|
||||
/* only concern ourselves with global and weak symbol definitions */
|
||||
switch (ELF_ST_BIND(s->st_info)) {
|
||||
switch( ELF_ST_BIND( s->st_info ))
|
||||
{
|
||||
case STB_GLOBAL:
|
||||
case STB_WEAK:
|
||||
if (s->st_shndx == SHN_UNDEF) {
|
||||
if( s->st_shndx == SHN_UNDEF )
|
||||
continue;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
@ -57,26 +59,30 @@ static Elf_Sym* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static Elf_Sym* soinfo_elf_lookup_reverse(soinfo* si, size_t addr) {
|
||||
static Elf_Sym* soinfo_elf_lookup_reverse(soinfo* si, size_t addr)
|
||||
{
|
||||
Elf_Sym* symtab = si->symtab;
|
||||
|
||||
if( si->nbucket == 0 )
|
||||
return NULL;
|
||||
|
||||
for(int j = 0; j < si->nbucket; j++)
|
||||
for (unsigned n = si->bucket[j]; n != 0; n = si->chain[n]) {
|
||||
Elf_Sym* s = symtab + n;
|
||||
if (s->st_value != addr) continue;
|
||||
for( int j = 0; j < si->nbucket; j++ )
|
||||
{
|
||||
for( unsigned n = si->bucket[j]; n != 0; n = si->chain[n] )
|
||||
{
|
||||
Elf_Sym* s = symtab + n;
|
||||
if( s->st_value != addr )continue;
|
||||
|
||||
/* only concern ourselves with global and weak symbol definitions */
|
||||
switch (ELF_ST_BIND(s->st_info)) {
|
||||
case STB_GLOBAL:
|
||||
case STB_LOCAL:
|
||||
case STB_WEAK:
|
||||
if (s->st_shndx == SHN_UNDEF) {
|
||||
continue;
|
||||
/* only concern ourselves with global and weak symbol definitions */
|
||||
switch( ELF_ST_BIND( s->st_info ))
|
||||
{
|
||||
case STB_GLOBAL:
|
||||
case STB_LOCAL:
|
||||
case STB_WEAK:
|
||||
if (s->st_shndx == SHN_UNDEF)
|
||||
continue;
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,11 +90,13 @@ static Elf_Sym* soinfo_elf_lookup_reverse(soinfo* si, size_t addr) {
|
|||
}
|
||||
|
||||
|
||||
static unsigned elfhash(const char* _name) {
|
||||
const unsigned char* name = (const unsigned char*) _name;
|
||||
static unsigned elfhash( const char* _name )
|
||||
{
|
||||
const unsigned char* name = ( const unsigned char* ) _name;
|
||||
unsigned h = 0, g;
|
||||
|
||||
while(*name) {
|
||||
while(*name)
|
||||
{
|
||||
h = (h << 4) + *name++;
|
||||
g = h & 0xf0000000;
|
||||
h ^= g;
|
||||
|
@ -106,8 +114,9 @@ static unsigned elfhash(const char* _name) {
|
|||
Binary Interface) where in Chapter 5 it discuss resolving "Shared
|
||||
Object Dependencies" in breadth first search order.
|
||||
*/
|
||||
static Elf_Sym* dlsym_handle_lookup(soinfo* si, const char* name) {
|
||||
return soinfo_elf_lookup(si, elfhash(name), name);
|
||||
static Elf_Sym* dlsym_handle_lookup( soinfo* si, const char* name )
|
||||
{
|
||||
return soinfo_elf_lookup( si, elfhash( name ), name );
|
||||
}
|
||||
|
||||
extern "C" void *ANDROID_LoadLibrary( const char *dllname );
|
||||
|
@ -117,7 +126,7 @@ static int dladdr_fallback( const void *addr, Dl_info *info )
|
|||
Elf_Sym *sym;
|
||||
|
||||
if( !server_info )
|
||||
server_info = (soinfo*)ANDROID_LoadLibrary( "server" );
|
||||
server_info = ( soinfo* )ANDROID_LoadLibrary( "server" );
|
||||
if( !server_info )
|
||||
return 0;
|
||||
//__android_log_print( ANDROID_LOG_ERROR, "dladdr_fb", "%p %p\n", addr, server_info );
|
||||
|
@ -141,35 +150,38 @@ static int dladdr_fallback( const void *addr, Dl_info *info )
|
|||
|
||||
extern "C" int __attribute__((visibility("hidden"))) dladdr( const void *addr, Dl_info *info )
|
||||
{
|
||||
static int (*pDladdr)( const void *addr, Dl_info *info );
|
||||
// __android_log_print( ANDROID_LOG_ERROR, "dladdr", "dladdr %p %p %p\n", addr, pDladdr, &dladdr );
|
||||
typedef int (*PFNDLADDR)( const void *addr, Dl_info *info );
|
||||
PFNDLADDR pfn_dladdr;
|
||||
|
||||
if(!pDladdr)
|
||||
if( !pfn_dladdr )
|
||||
{
|
||||
/* android does not have libdl, but have soinfo record for it from linker
|
||||
* use dlopen to get this record directly */
|
||||
void *lib = dlopen( "libdl.so", RTLD_NOW );
|
||||
|
||||
if( lib )
|
||||
*(void**)&pDladdr = dlsym( lib, "dladdr" );
|
||||
if( (void*)pDladdr == (void*)&dladdr )
|
||||
pDladdr = 0;
|
||||
if( !pDladdr )
|
||||
pDladdr = dladdr_fallback;
|
||||
pfn_dladdr = (PFNDLADDR)dlsym( lib, "dladdr" );
|
||||
if( pfn_dladdr == (PFNDLADDR)dladdr )
|
||||
pfn_dladdr = 0;
|
||||
if( !pfn_dladdr )
|
||||
pfn_dladdr = (PFNDLADDR)dladdr_fallback;
|
||||
}
|
||||
// __android_log_print( ANDROID_LOG_ERROR, "dladdr", "dladdr %p\n", addr );
|
||||
return pDladdr( addr, info );
|
||||
|
||||
return pfn_dladdr( addr, info );
|
||||
}
|
||||
|
||||
|
||||
extern "C" void* dlsym_weak(void* handle, const char* symbol) {
|
||||
extern "C" void* dlsym_weak( void* handle, const char* symbol ) {
|
||||
|
||||
soinfo* found = NULL;
|
||||
Elf_Sym* sym = NULL;
|
||||
found = reinterpret_cast<soinfo*>(handle);
|
||||
sym = dlsym_handle_lookup(found, symbol);
|
||||
found = reinterpret_cast<soinfo*>( handle );
|
||||
sym = dlsym_handle_lookup( found, symbol );
|
||||
|
||||
if (sym != NULL) {
|
||||
return reinterpret_cast<void*>(sym->st_value + found->base/*load_bias*/);
|
||||
if ( sym != NULL ) {
|
||||
return reinterpret_cast<void*>( sym->st_value + found->base /*load_bias*/ );
|
||||
}
|
||||
__android_log_print(ANDROID_LOG_ERROR, "dlsym-weak", "Failed when looking up %s\n", symbol);
|
||||
__android_log_print( ANDROID_LOG_ERROR, "dlsym-weak", "Failed when looking up %s\n", symbol );
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue