Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/back/linker_md.c
32285 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Adapted from JDK 1.2 linker_md.c v1.37. Note that we #define27* NATIVE here, whether or not we're running solaris native threads.28* Outside the VM, it's unclear how we can do the locking that is29* done in the green threads version of the code below.30*/31#define NATIVE3233/*34* Machine Dependent implementation of the dynamic linking support35* for java. This routine is Solaris specific.36*/3738#include <stdio.h>39#include <dlfcn.h>40#include <unistd.h>41#include <stdlib.h>42#include <string.h>4344#include "util.h"45#include "path_md.h"46#ifndef NATIVE47#include "iomgr.h"48#include "threads_md.h"49#endif5051#ifdef __APPLE__52#define LIB_SUFFIX "dylib"53#else54#define LIB_SUFFIX "so"55#endif5657static void dll_build_name(char* buffer, size_t buflen,58const char* paths, const char* fname) {59char *path, *paths_copy, *next_token;60*buffer = '\0';6162paths_copy = jvmtiAllocate((int)strlen(paths) + 1);63strcpy(paths_copy, paths);64if (paths_copy == NULL) {65return;66}6768next_token = NULL;69path = strtok_r(paths_copy, PATH_SEPARATOR, &next_token);7071while (path != NULL) {72size_t result_len = (size_t)snprintf(buffer, buflen, "%s/lib%s." LIB_SUFFIX, path, fname);73if (result_len >= buflen) {74EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "75"likely by sun.boot.library.path, is too long.");76} else if (access(buffer, F_OK) == 0) {77break;78}79*buffer = '\0';80path = strtok_r(NULL, PATH_SEPARATOR, &next_token);81}8283jvmtiDeallocate(paths_copy);84}8586/*87* create a string for the JNI native function name by adding the88* appropriate decorations.89*/90int91dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex)92{93/* On Solaris, there is only one encoding method. */94if (encodingIndex == 0)95return 1;96return 0;97}9899/*100* create a string for the dynamic lib open call by adding the101* appropriate pre and extensions to a filename and the path102*/103void104dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname)105{106const int pnamelen = pname ? strlen(pname) : 0;107108if (pnamelen == 0) {109if (pnamelen + (int)strlen(fname) + 10 > holderlen) {110EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "111"likely by sun.boot.library.path, is too long.");112}113(void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);114} else {115dll_build_name(holder, holderlen, pname, fname);116}117}118119#ifndef NATIVE120extern int thr_main(void);121#endif122123void *124dbgsysLoadLibrary(const char *name, char *err_buf, int err_buflen)125{126void * result;127#ifdef NATIVE128result = dlopen(name, RTLD_LAZY);129#else130sysMonitorEnter(greenThreadSelf(), &_dl_lock);131result = dlopen(name, RTLD_NOW);132sysMonitorExit(greenThreadSelf(), &_dl_lock);133/*134* This is a bit of bulletproofing to catch the commonly occurring135* problem of people loading a library which depends on libthread into136* the VM. thr_main() should always return -1 which means that libthread137* isn't loaded.138*/139if (thr_main() != -1) {140VM_CALL(panic)("libthread loaded into green threads");141}142#endif143if (result == NULL) {144(void)strncpy(err_buf, dlerror(), err_buflen-2);145err_buf[err_buflen-1] = '\0';146}147return result;148}149150void dbgsysUnloadLibrary(void *handle)151{152#ifndef NATIVE153sysMonitorEnter(greenThreadSelf(), &_dl_lock);154#endif155(void)dlclose(handle);156#ifndef NATIVE157sysMonitorExit(greenThreadSelf(), &_dl_lock);158#endif159}160161void * dbgsysFindLibraryEntry(void *handle, const char *name)162{163void * sym;164#ifndef NATIVE165sysMonitorEnter(greenThreadSelf(), &_dl_lock);166#endif167sym = dlsym(handle, name);168#ifndef NATIVE169sysMonitorExit(greenThreadSelf(), &_dl_lock);170#endif171return sym;172}173174175