Mercurial > pub > dyncall > dyncall
comparison dynload/dynload_unix.c @ 245:0ba6189a51dd
- dynload dlGetLibraryPath simplifications:
* removed mode bit checking on macOS, and assured dlopening files with same flags, instead
* consistency changes for OpenBSD
author | Tassilo Philipp |
---|---|
date | Thu, 04 May 2017 15:11:46 +0200 |
parents | 85b61e8facfe |
children | 06a354b2e120 |
comparison
equal
deleted
inserted
replaced
244:75093cde6d10 | 245:0ba6189a51dd |
---|---|
87 /* so "double-load" temporarily all already loaded images (just increases */ | 87 /* so "double-load" temporarily all already loaded images (just increases */ |
88 /* ref count) and compare handles until we found ours. Return the name. */ | 88 /* ref count) and compare handles until we found ours. Return the name. */ |
89 for(i=_dyld_image_count(); i>0;) /* iterate libs from end, more likely ours */ | 89 for(i=_dyld_image_count(); i>0;) /* iterate libs from end, more likely ours */ |
90 { | 90 { |
91 const char* libPath = _dyld_get_image_name(--i); | 91 const char* libPath = _dyld_get_image_name(--i); |
92 void* lib = dlopen(libPath, RTLD_LAZY); | 92 DLLib* lib = dlLoadLibrary(libPath); /* re-open same way for same handle */ |
93 if(lib) { | 93 if(lib) { |
94 dlclose(lib); | 94 dlFreeLibrary(lib); |
95 /* compare handle pointers' high bits (in low 2 bits some flags might */ | 95 if(pLib == lib) { |
96 /* be stored - should be safe b/c address needs alignment, anywas) */ | |
97 if(((intptr_t)pLib ^ (intptr_t)lib) < 4) { | |
98 l = strlen(libPath); | 96 l = strlen(libPath); |
99 if(l < bufSize) /* l+'\0' <= bufSize */ | 97 if(l < bufSize) /* l+'\0' <= bufSize */ |
100 strcpy(sOut, libPath); | 98 strcpy(sOut, libPath); |
101 break; | 99 break; |
102 } | 100 } |
126 int l = -1; | 124 int l = -1; |
127 iter_phdr_data* d = (iter_phdr_data*)data; | 125 iter_phdr_data* d = (iter_phdr_data*)data; |
128 /* unable to relate info->dlpi_addr directly to our dlopen handle, let's */ | 126 /* unable to relate info->dlpi_addr directly to our dlopen handle, let's */ |
129 /* do what we do on macOS above, re-dlopen the already loaded lib (just */ | 127 /* do what we do on macOS above, re-dlopen the already loaded lib (just */ |
130 /* increases ref count) and compare handles. */ | 128 /* increases ref count) and compare handles. */ |
131 void* lib = dlopen(info->dlpi_name, RTLD_LAZY); | 129 DLLib* lib = dlLoadLibrary(info->dlpi_name); /* re-open same way for same handle */ |
132 if(lib) { | 130 if(lib) { |
133 dlclose(lib); | 131 dlFreeLibrary(lib); |
134 if(lib == (void*)d->pLib) { | 132 if(lib == d->pLib) { |
135 l = strlen(info->dlpi_name); | 133 l = strlen(info->dlpi_name); |
136 if(l < d->bufSize) /* l+'\0' <= bufSize */ | 134 if(l < d->bufSize) /* l+'\0' <= bufSize */ |
137 strcpy(d->sOut, info->dlpi_name); | 135 strcpy(d->sOut, info->dlpi_name); |
138 } | 136 } |
139 } | 137 } |