author | dlong |
Mon, 26 Sep 2016 14:21:22 -0400 | |
changeset 41364 | 46913f218c6b |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
16726
diff
changeset
|
2 |
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* Maintains a list of currently loaded DLLs (Dynamic Link Libraries) |
|
28 |
* and their associated handles. Library names are case-insensitive. |
|
29 |
*/ |
|
30 |
||
31 |
#include <windows.h> |
|
32 |
#include <stdio.h> |
|
33 |
#include <string.h> |
|
34 |
#include <errno.h> |
|
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
35 |
#include <io.h> |
23566
760a74c1b589
8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents:
23010
diff
changeset
|
36 |
#include <stdlib.h> |
2 | 37 |
|
38 |
#include "sys.h" |
|
39 |
||
40 |
#include "path_md.h" |
|
41 |
||
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
42 |
static void dll_build_name(char* buffer, size_t buflen, |
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
43 |
const char* paths, const char* fname) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
44 |
char *path, *paths_copy, *next_token; |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
45 |
|
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
46 |
paths_copy = strdup(paths); |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
47 |
if (paths_copy == NULL) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
48 |
return; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
49 |
} |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
50 |
|
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
51 |
next_token = NULL; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
52 |
path = strtok_s(paths_copy, PATH_SEPARATOR, &next_token); |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
53 |
|
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
54 |
while (path != NULL) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
55 |
_snprintf(buffer, buflen, "%s\\%s.dll", path, fname); |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
56 |
if (_access(buffer, 0) == 0) { |
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
57 |
break; |
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
58 |
} |
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
59 |
*buffer = '\0'; |
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
60 |
path = strtok_s(NULL, PATH_SEPARATOR, &next_token); |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
61 |
} |
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
62 |
|
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
63 |
free(paths_copy); |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
64 |
} |
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
65 |
|
2 | 66 |
/* |
67 |
* From system_md.c v1.54 |
|
68 |
*/ |
|
69 |
int |
|
70 |
dbgsysGetLastErrorString(char *buf, int len) |
|
71 |
{ |
|
72 |
long errval; |
|
73 |
||
74 |
if ((errval = GetLastError()) != 0) { |
|
75 |
/* DOS error */ |
|
76 |
int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, |
|
77 |
NULL, errval, |
|
78 |
0, buf, len, NULL); |
|
79 |
if (n > 3) { |
|
80 |
/* Drop final '.', CR, LF */ |
|
81 |
if (buf[n - 1] == '\n') n--; |
|
82 |
if (buf[n - 1] == '\r') n--; |
|
83 |
if (buf[n - 1] == '.') n--; |
|
84 |
buf[n] = '\0'; |
|
85 |
} |
|
86 |
return n; |
|
87 |
} |
|
88 |
||
89 |
if (errno != 0) { |
|
90 |
/* C runtime error that has no corresponding DOS error code */ |
|
91 |
const char *s = strerror(errno); |
|
92 |
int n = (int)strlen(s); |
|
93 |
if (n >= len) n = len - 1; |
|
94 |
strncpy(buf, s, n); |
|
95 |
buf[n] = '\0'; |
|
96 |
return n; |
|
97 |
} |
|
98 |
||
99 |
return 0; |
|
100 |
} |
|
101 |
||
102 |
/* |
|
103 |
* Build a machine dependent library name out of a path and file name. |
|
104 |
*/ |
|
105 |
void |
|
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
106 |
dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname) |
2 | 107 |
{ |
108 |
const int pnamelen = pname ? (int)strlen(pname) : 0; |
|
109 |
||
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
110 |
*holder = '\0'; |
2 | 111 |
/* Quietly truncates on buffer overflow. Should be an error. */ |
112 |
if (pnamelen + (int)strlen(fname) + 10 > holderlen) { |
|
113 |
return; |
|
114 |
} |
|
115 |
||
116 |
if (pnamelen == 0) { |
|
117 |
sprintf(holder, "%s.dll", fname); |
|
118 |
} else { |
|
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
5506
diff
changeset
|
119 |
dll_build_name(holder, holderlen, pname, fname); |
2 | 120 |
} |
121 |
} |
|
122 |
||
123 |
void * |
|
124 |
dbgsysLoadLibrary(const char * name, char *err_buf, int err_buflen) |
|
125 |
{ |
|
126 |
void *result = LoadLibrary(name); |
|
127 |
if (result == NULL) { |
|
128 |
/* Error message is pretty lame, try to make a better guess. */ |
|
129 |
long errcode = GetLastError(); |
|
130 |
if (errcode == ERROR_MOD_NOT_FOUND) { |
|
131 |
strncpy(err_buf, "Can't find dependent libraries", err_buflen-2); |
|
132 |
err_buf[err_buflen-1] = '\0'; |
|
133 |
} else { |
|
134 |
dbgsysGetLastErrorString(err_buf, err_buflen); |
|
135 |
} |
|
136 |
} |
|
137 |
return result; |
|
138 |
} |
|
139 |
||
140 |
void dbgsysUnloadLibrary(void *handle) |
|
141 |
{ |
|
142 |
FreeLibrary(handle); |
|
143 |
} |
|
144 |
||
145 |
void * dbgsysFindLibraryEntry(void *handle, const char *name) |
|
146 |
{ |
|
147 |
return GetProcAddress(handle, name); |
|
148 |
} |