Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/ddr/ddrmain.c
5991 views
1
/*******************************************************************************
2
* Copyright (c) 1998, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#if defined(WIN32)
24
/* windows.h defined UDATA. Ignore its definition */
25
#define UDATA UDATA_win32_
26
#include <windows.h>
27
#undef UDATA /* this is safe because our UDATA is a typedef, not a macro */
28
#endif
29
#include <stdlib.h>
30
#include <string.h>
31
32
#include "j9comp.h"
33
#include "j9port.h"
34
#include "j9ddr.h"
35
36
#if defined(J9ZOS390)
37
#include "atoe.h"
38
#endif
39
40
#define VMOPT_XUSE_CEEHDLR "-XCEEHDLR"
41
42
UDATA ddrSignalProtectedMain(struct OMRPortLibrary* portLibrary, void *arg);
43
static UDATA genericSignalHandler(struct OMRPortLibrary* portLibrary, U_32 gpType, void* gpInfo, void* userData);
44
45
#if defined(WIN32)
46
int
47
translated_main(int argc, char ** argv, char ** envp)
48
#else
49
int
50
main(int argc, char ** argv, char ** envp)
51
#endif
52
{
53
OMRPortLibrary j9portLibrary;
54
J9DDRCmdlineOptions options;
55
int rc = 257;
56
UDATA result;
57
58
options.shutdownPortLib = FALSE;
59
60
#if defined(J9ZOS390)
61
iconv_init();
62
{ /* translate argv strings to ascii */
63
int i;
64
for (i = 0; i < argc; i++) {
65
argv[i] = e2a_string(argv[i]);
66
}
67
}
68
#endif
69
70
if (0 == omrthread_init_library()) {
71
omrthread_t attachedThread = NULL;
72
if (0 == omrthread_attach_ex(&attachedThread, J9THREAD_ATTR_DEFAULT)) {
73
/* Use portlibrary version which we compiled against, and have allocated space
74
* for on the stack. This version may be different from the one in the linked DLL.
75
*/
76
if (0 == omrport_init_library(&j9portLibrary, sizeof(OMRPortLibrary))) {
77
options.argc = argc;
78
options.argv = argv;
79
options.envp = envp;
80
options.portLibrary = &j9portLibrary;
81
options.shutdownPortLib = TRUE;
82
83
{
84
/* signal options needs to be set before sig_protect is called, parse and set them now */
85
int i;
86
U_32 sigOptions = 0;
87
88
for (i = 0; i < argc ; i++) {
89
if (0 == strcmp(VMOPT_XUSE_CEEHDLR, argv[i])) {
90
sigOptions |= J9PORT_SIG_OPTIONS_ZOS_USE_CEEHDLR;
91
}
92
}
93
94
j9portLibrary.sig_set_options(&j9portLibrary, sigOptions);
95
}
96
97
if (j9portLibrary.sig_protect(&j9portLibrary,
98
ddrSignalProtectedMain, &options,
99
genericSignalHandler, NULL,
100
J9PORT_SIG_FLAG_SIGALLSYNC,
101
&result) == 0
102
) {
103
rc = (int)result;
104
}
105
106
/* CMVC 130066 : as a result of failing to destroy the VM, the VM may still be
107
* holding onto (and using) port library resources.
108
*/
109
if (options.shutdownPortLib) {
110
j9portLibrary.port_shutdown_library(&j9portLibrary);
111
omrthread_detach(attachedThread);
112
omrthread_shutdown_library();
113
}
114
}
115
}
116
}
117
118
return rc;
119
}
120
121
#if defined(WIN32)
122
int
123
wmain(int argc, wchar_t ** argv, wchar_t ** envp)
124
{
125
char **translated_argv = NULL;
126
char **translated_envp = NULL;
127
char* cursor;
128
int i, length, envc;
129
int rc;
130
131
/* Translate argv to UTF-8 */
132
length = argc; /* 1 null terminator per string */
133
for(i = 0; i < argc; i++) {
134
length += (int)(wcslen(argv[i]) * 3);
135
}
136
translated_argv = (char**)malloc(length + ((argc + 1) * sizeof(char*))); /* + array entries */
137
cursor = (char*)&translated_argv[argc + 1];
138
for(i = 0; i < argc; i++) {
139
int utf8Length;
140
141
translated_argv[i] = cursor;
142
if(0 == (utf8Length = WideCharToMultiByte(OS_ENCODING_CODE_PAGE, OS_ENCODING_WC_FLAGS, argv[i], -1, cursor, length, NULL, NULL))) {
143
return -1;
144
}
145
cursor += utf8Length;
146
*cursor++ = '\0';
147
length -= utf8Length;
148
}
149
translated_argv[argc] = NULL; /* NULL terminated the new argv */
150
151
/* Translate argv to UTF-8 */
152
if(envp) {
153
envc = 0;
154
while(NULL != envp[envc]) {
155
envc++;
156
}
157
length = envc; /* 1 null terminator per string */
158
for(i = 0; i < envc; i++) {
159
length += (int)(wcslen(envp[i]) * 3);
160
}
161
translated_envp = (char**)malloc(length + ((envc + 1) * sizeof(char*))); /* + array entries */
162
cursor = (char*)&translated_envp[envc + 1];
163
for(i = 0; i < envc; i++) {
164
int utf8Length;
165
translated_envp[i] = cursor;
166
if(0 == (utf8Length = WideCharToMultiByte(OS_ENCODING_CODE_PAGE, OS_ENCODING_WC_FLAGS, envp[i], -1, cursor, length, NULL, NULL))) {
167
return -1;
168
}
169
cursor += utf8Length;
170
*cursor++ = '\0';
171
length -= utf8Length;
172
}
173
translated_envp[envc] = NULL; /* NULL terminated the new envp */
174
}
175
176
rc = translated_main(argc, translated_argv, translated_envp);
177
178
/* Free the translated strings */
179
free(translated_argv);
180
free(translated_envp);
181
182
return rc;
183
}
184
#endif
185
186
static UDATA
187
genericSignalHandler(struct OMRPortLibrary* portLibrary, U_32 gpType, void* gpInfo, void* userData)
188
{
189
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
190
U_32 category;
191
192
omrtty_printf("\nAn unhandled error (%d) has occurred.\n", gpType);
193
for (category=0 ; category<J9PORT_SIG_NUM_CATEGORIES ; category++) {
194
U_32 infoCount = omrsig_info_count(gpInfo, category) ;
195
U_32 infoKind, index;
196
void *value;
197
const char* name;
198
199
for (index=0 ; index < infoCount ; index++) {
200
infoKind = omrsig_info(gpInfo, category, index, &name, &value);
201
202
switch (infoKind) {
203
case J9PORT_SIG_VALUE_32:
204
omrtty_printf("%s=%08.8x\n", name, *(U_32 *)value);
205
break;
206
case J9PORT_SIG_VALUE_64:
207
case J9PORT_SIG_VALUE_FLOAT_64:
208
omrtty_printf("%s=%016.16llx\n", name, *(U_64 *)value);
209
break;
210
case J9PORT_SIG_VALUE_STRING:
211
omrtty_printf("%s=%s\n", name, (const char *)value);
212
break;
213
case J9PORT_SIG_VALUE_ADDRESS:
214
omrtty_printf("%s=%p\n", name, *(void**)value);
215
break;
216
}
217
}
218
}
219
220
abort();
221
222
/* UNREACHABLE */
223
return 0;
224
}
225
226