Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/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* Maintains a list of currently loaded DLLs (Dynamic Link Libraries)27* and their associated handles. Library names are case-insensitive.28*/2930#include <windows.h>31#include <stdio.h>32#include <string.h>33#include <errno.h>34#include <io.h>3536#include "sys.h"3738#include "util.h"39#include "path_md.h"4041static void dll_build_name(char* buffer, size_t buflen,42const char* paths, const char* fname) {43char *path, *paths_copy, *next_token;44*buffer = '\0';4546paths_copy = jvmtiAllocate((int)strlen(paths) + 1);47strcpy(paths_copy, paths);48if (paths_copy == NULL) {49return;50}5152next_token = NULL;53path = strtok_s(paths_copy, PATH_SEPARATOR, &next_token);5455while (path != NULL) {56size_t result_len = (size_t)_snprintf(buffer, buflen, "%s\\%s.dll", path, fname);57if (result_len >= buflen) {58EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "59"likely by sun.boot.library.path, is too long.");60} else if (_access(buffer, 0) == 0) {61break;62}63*buffer = '\0';64path = strtok_s(NULL, PATH_SEPARATOR, &next_token);65}6667jvmtiDeallocate(paths_copy);68}6970/*71* From system_md.c v1.5472*/73int74dbgsysGetLastErrorString(char *buf, int len)75{76long errval;7778if ((errval = GetLastError()) != 0) {79/* DOS error */80int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,81NULL, errval,820, buf, len, NULL);83if (n > 3) {84/* Drop final '.', CR, LF */85if (buf[n - 1] == '\n') n--;86if (buf[n - 1] == '\r') n--;87if (buf[n - 1] == '.') n--;88buf[n] = '\0';89}90return n;91}9293if (errno != 0) {94/* C runtime error that has no corresponding DOS error code */95const char *s = strerror(errno);96int n = (int)strlen(s);97if (n >= len) n = len - 1;98strncpy(buf, s, n);99buf[n] = '\0';100return n;101}102103return 0;104}105106/*107* Build a machine dependent library name out of a path and file name.108*/109void110dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname)111{112const int pnamelen = pname ? (int)strlen(pname) : 0;113114if (pnamelen == 0) {115if (pnamelen + (int)strlen(fname) + 10 > holderlen) {116EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "117"likely by sun.boot.library.path, is too long.");118}119sprintf(holder, "%s.dll", fname);120} else {121dll_build_name(holder, holderlen, pname, fname);122}123}124125void *126dbgsysLoadLibrary(const char * name, char *err_buf, int err_buflen)127{128void *result = LoadLibrary(name);129if (result == NULL) {130/* Error message is pretty lame, try to make a better guess. */131long errcode = GetLastError();132if (errcode == ERROR_MOD_NOT_FOUND) {133strncpy(err_buf, "Can't find dependent libraries", err_buflen-2);134err_buf[err_buflen-1] = '\0';135} else {136dbgsysGetLastErrorString(err_buf, err_buflen);137}138}139return result;140}141142void dbgsysUnloadLibrary(void *handle)143{144FreeLibrary(handle);145}146147void * dbgsysFindLibraryEntry(void *handle, const char *name)148{149return GetProcAddress(handle, name);150}151152153