changeset 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 75093cde6d10
children 06a354b2e120
files dynload/dynload_unix.c test/dynload_plain/dynload_plain.c
diffstat 2 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dynload/dynload_unix.c	Thu May 04 13:54:29 2017 +0200
+++ b/dynload/dynload_unix.c	Thu May 04 15:11:46 2017 +0200
@@ -89,12 +89,10 @@
   for(i=_dyld_image_count(); i>0;) /* iterate libs from end, more likely ours */
   {
     const char* libPath = _dyld_get_image_name(--i);
-    void* lib = dlopen(libPath, RTLD_LAZY);
+    DLLib* lib = dlLoadLibrary(libPath); /* re-open same way for same handle */
     if(lib) {
-      dlclose(lib);
-      /* compare handle pointers' high bits (in low 2 bits some flags might */
-      /* be stored - should be safe b/c address needs alignment, anywas) */
-      if(((intptr_t)pLib ^ (intptr_t)lib) < 4) {
+      dlFreeLibrary(lib);
+      if(pLib == lib) {
         l = strlen(libPath);
         if(l < bufSize) /* l+'\0' <= bufSize */
           strcpy(sOut, libPath);
@@ -128,10 +126,10 @@
   /* unable to relate info->dlpi_addr directly to our dlopen handle, let's */
   /* do what we do on macOS above, re-dlopen the already loaded lib (just  */
   /* increases ref count) and compare handles. */
-  void* lib = dlopen(info->dlpi_name, RTLD_LAZY);
+  DLLib* lib = dlLoadLibrary(info->dlpi_name); /* re-open same way for same handle */
   if(lib) {
-    dlclose(lib);
-    if(lib == (void*)d->pLib) {
+    dlFreeLibrary(lib);
+    if(lib == d->pLib) {
       l = strlen(info->dlpi_name);
       if(l < d->bufSize) /* l+'\0' <= bufSize */
         strcpy(d->sOut, info->dlpi_name);
--- a/test/dynload_plain/dynload_plain.c	Thu May 04 13:54:29 2017 +0200
+++ b/test/dynload_plain/dynload_plain.c	Thu May 04 15:11:46 2017 +0200
@@ -47,7 +47,6 @@
     "/lib/libc.so",
     "/lib/libc.so.6",
     "/lib/libc.so.7",
-    "/lib/libc.so.39.3", /* hack: for OpenBSD used in dyncall test env */
     "/lib64/libc.so",
     "/lib64/libc.so.6",
     "/lib64/libc.so.7",
@@ -57,6 +56,7 @@
     "/usr/lib/libc.so",
     "/usr/lib/libc.so.6",
     "/usr/lib/libc.so.7",
+    "/usr/lib/libc.so.39.3", /* hack: for OpenBSD used in dyncall test env */
     "/usr/lib/system/libsystem_c.dylib",
     "/usr/lib/libc.dylib",
     "\\ReactOS\\system32\\msvcrt.dll",
@@ -97,7 +97,7 @@
         int b;
         printf("path of lib looked up via handle: %s\n", queriedPath);
         b = (stat(path, &st0) != -1) && (stat(queriedPath, &st1) != -1);
-        printf("lib (inode:%d) and looked up lib (inode:%d) are same: %d\n", b?st0.st_ino:-1, b?st1.st_ino:-1, b && (st0.st_ino == st1.st_ino));
+        printf("lib (inode:%d) and looked up lib (inode:%d) are same: %d\n", b?st0.st_ino:-1, b?st1.st_ino:-1, b && (st0.st_ino == st1.st_ino)); //@@@ on windows, inode numbers returned here are always 0
         r += b && (st0.st_ino == st1.st_ino); /* compare if same lib using inode */
 /*@@@ check of resolved path is absolute*/