jdk/src/solaris/back/linker_md.c
author sla
Tue, 05 Mar 2013 19:25:35 +0100
changeset 16057 16a81953a291
parent 14698 9294fcf94c46
child 16726 f76b2e6bd199
permissions -rw-r--r--
8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12047
diff changeset
     2
 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Adapted from JDK 1.2 linker_md.c v1.37. Note that we #define
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NATIVE here, whether or not we're running solaris native threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Outside the VM, it's unclear how we can do the locking that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * done in the green threads version of the code below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Machine Dependent implementation of the dynamic linking support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * for java.  This routine is Solaris specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "path_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#ifndef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "iomgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "threads_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    51
#ifdef __APPLE__
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    52
#define LIB_SUFFIX "dylib"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    53
#else
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    54
#define LIB_SUFFIX "so"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    55
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    56
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    57
static void dll_build_name(char* buffer, size_t buflen,
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    58
                           const char* pname, const char* fname) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    59
    // Based on os_solaris.cpp
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    60
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    61
    char *path_sep = PATH_SEPARATOR;
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    62
    char *pathname = (char *)pname;
16057
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    63
    *buffer = '\0';
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    64
    while (strlen(pathname) > 0) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    65
        char *p = strchr(pathname, *path_sep);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    66
        if (p == NULL) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    67
            p = pathname + strlen(pathname);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    68
        }
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    69
        /* check for NULL path */
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    70
        if (p == pathname) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    71
            continue;
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    72
        }
16057
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    73
        (void)snprintf(buffer, buflen, "%.*s/lib%s." LIB_SUFFIX, (int)(p - pathname),
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    74
                       pathname, fname);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    75
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    76
        if (access(buffer, F_OK) == 0) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    77
            break;
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    78
        }
16057
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    79
        if (*p == '\0') {
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    80
            pathname = p;
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    81
        } else {
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    82
            pathname = p + 1;
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
    83
        }
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    84
        *buffer = '\0';
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    85
    }
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    86
}
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
    87
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * create a string for the JNI native function name by adding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * appropriate decorations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  /* On Solaris, there is only one encoding method. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (encodingIndex == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * create a string for the dynamic lib open call by adding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * appropriate pre and extensions to a filename and the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    const int pnamelen = pname ? strlen(pname) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
   110
    *holder = '\0';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /* Quietly truncate on buffer overflow.  Should be an error. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    if (pnamelen + (int)strlen(fname) + 10 > holderlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    if (pnamelen == 0) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   117
        (void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    } else {
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 14342
diff changeset
   119
      dll_build_name(holder, holderlen, pname, fname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#ifndef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
extern int thr_main(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
dbgsysLoadLibrary(const char *name, char *err_buf, int err_buflen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    void * result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#ifdef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    result = dlopen(name, RTLD_LAZY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    sysMonitorEnter(greenThreadSelf(), &_dl_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    result = dlopen(name, RTLD_NOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    sysMonitorExit(greenThreadSelf(), &_dl_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * This is a bit of bulletproofing to catch the commonly occurring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * problem of people loading a library which depends on libthread into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * the VM.  thr_main() should always return -1 which means that libthread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * isn't loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    if (thr_main() != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         VM_CALL(panic)("libthread loaded into green threads");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    if (result == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        (void)strncpy(err_buf, dlerror(), err_buflen-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        err_buf[err_buflen-1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
void dbgsysUnloadLibrary(void *handle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
#ifndef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    sysMonitorEnter(greenThreadSelf(), &_dl_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    (void)dlclose(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#ifndef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    sysMonitorExit(greenThreadSelf(), &_dl_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
void * dbgsysFindLibraryEntry(void *handle, const char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    void * sym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#ifndef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    sysMonitorEnter(greenThreadSelf(), &_dl_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    sym =  dlsym(handle, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
#ifndef NATIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    sysMonitorExit(greenThreadSelf(), &_dl_lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return sym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}