< prev index next >

src/jdk.jdwp.agent/unix/native/libjdwp/linker_md.c

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * Machine Dependent implementation of the dynamic linking support
  28  * for java.  This routine is Unix specific.
  29  */
  30 
  31 #include <stdio.h>
  32 #include <dlfcn.h>
  33 #include <unistd.h>
  34 #include <stdlib.h>
  35 #include <string.h>
  36 

  37 #include "path_md.h"
  38 
  39 #ifdef __APPLE__
  40 #define LIB_SUFFIX "dylib"
  41 #else
  42 #define LIB_SUFFIX "so"
  43 #endif
  44 
  45 static void dll_build_name(char* buffer, size_t buflen,
  46                            const char* paths, const char* fname) {
  47     char *path, *paths_copy, *next_token;

  48 
  49     paths_copy = strdup(paths);
  50     if (paths_copy == NULL) {
  51         return;
  52     }
  53 
  54     next_token = NULL;
  55     path = strtok_r(paths_copy, PATH_SEPARATOR, &next_token);
  56 
  57     while (path != NULL) {
  58         snprintf(buffer, buflen, "%s/lib%s." LIB_SUFFIX, path, fname);
  59         if (access(buffer, F_OK) == 0) {



  60             break;
  61         }
  62         *buffer = '\0';
  63         path = strtok_r(NULL, PATH_SEPARATOR, &next_token);
  64     }
  65 
  66     free(paths_copy);
  67 }
  68 
  69 /*
  70  * create a string for the JNI native function name by adding the
  71  * appropriate decorations.
  72  */
  73 int
  74 dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex)
  75 {
  76     // On Unix, there is only one encoding method.
  77     if (encodingIndex == 0)
  78         return 1;
  79     return 0;
  80 }
  81 
  82 /*
  83  * create a string for the dynamic lib open call by adding the
  84  * appropriate pre and extensions to a filename and the path
  85  */
  86 void
  87 dbgsysBuildLibName(char *holder, int holderlen, const char *pname,
  88                    const char *fname)
  89 {
  90     const int pnamelen = pname ? strlen(pname) : 0;
  91 
  92     *holder = '\0';
  93     // Quietly truncate on buffer overflow.  Should be an error.
  94     if (pnamelen + (int)strlen(fname) + 10 > holderlen) {
  95         return;

  96     }
  97 
  98     if (pnamelen == 0) {
  99         (void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);
 100     } else {
 101       dll_build_name(holder, holderlen, pname, fname);
 102     }
 103 }
 104 
 105 void *
 106 dbgsysLoadLibrary(const char *name, char *err_buf, int err_buflen)
 107 {
 108     void * result;
 109     result = dlopen(name, RTLD_LAZY);
 110     if (result == NULL) {
 111         (void)strncpy(err_buf, dlerror(), err_buflen-2);
 112         err_buf[err_buflen-1] = '\0';
 113     }
 114     return result;
 115 }
 116 
 117 void dbgsysUnloadLibrary(void *handle)
 118 {


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * Machine Dependent implementation of the dynamic linking support
  28  * for java.  This routine is Unix specific.
  29  */
  30 
  31 #include <stdio.h>
  32 #include <dlfcn.h>
  33 #include <unistd.h>
  34 #include <stdlib.h>
  35 #include <string.h>
  36 
  37 #include "util.h"
  38 #include "path_md.h"
  39 
  40 #ifdef __APPLE__
  41 #define LIB_SUFFIX "dylib"
  42 #else
  43 #define LIB_SUFFIX "so"
  44 #endif
  45 
  46 static void dll_build_name(char* buffer, size_t buflen,
  47                            const char* paths, const char* fname) {
  48     char *path, *paths_copy, *next_token;
  49     *buffer = '\0';
  50 
  51     paths_copy = strdup(paths);
  52     if (paths_copy == NULL) {
  53         return;
  54     }
  55 
  56     next_token = NULL;
  57     path = strtok_r(paths_copy, PATH_SEPARATOR, &next_token);
  58 
  59     while (path != NULL) {
  60         size_t result_len = (size_t)snprintf(buffer, buflen, "%s/lib%s." LIB_SUFFIX, path, fname);
  61         if (result_len >= buflen) {
  62             EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "
  63                                                      "likely by sun.boot.library.path, is too long.");
  64         } else if (access(buffer, F_OK) == 0) {
  65             break;
  66         }
  67         *buffer = '\0';
  68         path = strtok_r(NULL, PATH_SEPARATOR, &next_token);
  69     }
  70 
  71     free(paths_copy);
  72 }
  73 
  74 /*
  75  * create a string for the JNI native function name by adding the
  76  * appropriate decorations.
  77  */
  78 int
  79 dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex)
  80 {
  81     // On Unix, there is only one encoding method.
  82     if (encodingIndex == 0)
  83         return 1;
  84     return 0;
  85 }
  86 
  87 /*
  88  * create a string for the dynamic lib open call by adding the
  89  * appropriate pre and extensions to a filename and the path
  90  */
  91 void
  92 dbgsysBuildLibName(char *holder, int holderlen, const char *pname,
  93                    const char *fname)
  94 {
  95     const int pnamelen = pname ? strlen(pname) : 0;
  96 
  97     if (pnamelen == 0) {

  98         if (pnamelen + (int)strlen(fname) + 10 > holderlen) {
  99             EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "
 100                                                      "likely by sun.boot.library.path, is too long.");
 101         }


 102         (void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);
 103     } else {
 104       dll_build_name(holder, holderlen, pname, fname);
 105     }
 106 }
 107 
 108 void *
 109 dbgsysLoadLibrary(const char *name, char *err_buf, int err_buflen)
 110 {
 111     void * result;
 112     result = dlopen(name, RTLD_LAZY);
 113     if (result == NULL) {
 114         (void)strncpy(err_buf, dlerror(), err_buflen-2);
 115         err_buf[err_buflen-1] = '\0';
 116     }
 117     return result;
 118 }
 119 
 120 void dbgsysUnloadLibrary(void *handle)
 121 {
< prev index next >