Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/j9vm31/j9cel4ro64.h
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2021, 2021 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
#ifndef j9cel4ro64_h
24
#define j9cel4ro64_h
25
26
#include <stdint.h>
27
#include <string.h>
28
#include "jni.h" /* Needed for return argument type handling */
29
30
#ifdef __cplusplus
31
extern "C" {
32
#endif
33
34
/* Flags to control the behaviour of CEL4RO64. Used by controlBlock->flags */
35
#define J9_CEL4RO64_FLAG_LOAD_DLL 0x80000000
36
#define J9_CEL4RO64_FLAG_QUERY_TARGET_FUNC 0x40000000
37
#define J9_CEL4RO64_FLAG_EXECUTE_TARGET_FUNC 0x20000000
38
#define J9_CEL4RO64_FLAG_ALL_LOAD_QUERY_EXECUTE (J9_CEL4RO64_FLAG_LOAD_DLL | J9_CEL4RO64_FLAG_QUERY_TARGET_FUNC | J9_CEL4RO64_FLAG_EXECUTE_TARGET_FUNC)
39
40
/* Return codes for CEL4RO64 */
41
#define J9_CEL4RO64_RETCODE_OK 0x0
42
#define J9_CEL4RO64_RETCODE_ERROR_MULTITHREAD_INVOCATION 0x1
43
#define J9_CEL4RO64_RETCODE_ERROR_STORAGE_ISSUE 0x2
44
#define J9_CEL4RO64_RETCODE_ERROR_FAILED_AMODE64_ENV 0x3
45
#define J9_CEL4RO64_RETCODE_ERROR_FAILED_LOAD_TARGET_DLL 0x4
46
#define J9_CEL4RO64_RETCODE_ERROR_FAILED_QUERY_TARGET_FUNC 0x5
47
#define J9_CEL4RO64_RETCODE_ERROR_LE_RUNTIME_SUPPORT_NOT_FOUND 0x6
48
49
/* Fixed length Control Block structure RO64_CB */
50
typedef struct J9_CEL4RO64_controlBlock {
51
uint32_t version; /**< (Input) A integer which contains the version of RO64_INFO. */
52
uint32_t length; /**< (Input) A integer which contains the total length of RO64_INFO. */
53
uint32_t flags; /**< (Input) Flags to control the behavior of CEL4RO64. */
54
uint32_t moduleOffset; /**< (Input) Offset to RO64_module part from start of RO64_CB. Req'd for DLL load flag. */
55
uint32_t functionOffset; /**< (Input) Offset to RO64_function part from start of RO64_CB. Req'd for DLL query flag. */
56
uint32_t argumentsOffset; /**< (Input) Offset to RO64_args part from start of RO64_CB. Req'd for function execution flag. */
57
uint64_t dllHandle; /**< DLL handle of target program (Input) if DLL query flag. (Output) if DLL load flag. */
58
uint64_t functionDescriptor; /**< Function descriptor of target function (Input) if function exection flag. (Output) if DLL query flag. */
59
uint64_t gpr1ReturnValue; /**< (Output) Return buffer containing 64-bit GPR1 value of target program after execution. */
60
uint64_t gpr2ReturnValue; /**< (Output) Return buffer containing 64-bit GPR2 value of target program after execution. */
61
uint64_t gpr3ReturnValue; /**< (Output) Return buffer containing 64-bit GPR3 value of target program after execution. */
62
int32_t retcode; /**< (Output) Return code of CEL4RO64. */
63
} J9_CEL4RO64_controlBlock;
64
65
/* Module name to load */
66
typedef struct J9_CEL4RO64_module {
67
int32_t length; /**< Length of the module name. */
68
char moduleName[1]; /**< Pointer to variable length module name. */
69
} J9_CEL4RO64_module;
70
71
/* Internal struct to map function name definition in control block. */
72
typedef struct J9_CEL4RO64_function {
73
int32_t length; /**< Length of the function name. */
74
char functionName[1]; /**< Pointer to variable length function name. */
75
} J9_CEL4RO64_function;
76
77
/* Internal struct to track the RO64 control block and related variable length structures. */
78
typedef struct J9_CEL4RO64_infoBlock {
79
J9_CEL4RO64_module *ro64Module; /**< Pointer to the start of the module section of the control block. */
80
J9_CEL4RO64_function *ro64Function; /**< Pointer to the start of the function section of the control block. */
81
uint32_t *ro64Arguments; /**< Pointer to the start of the outgoing arguments section of the control block. */
82
J9_CEL4RO64_controlBlock ro64ControlBlock; /**< Pointer to the control block for CEL4RO64. */
83
} J9_CEL4RO64_infoBlock;
84
85
/**
86
* Types to facilitate argument construction and return values for calls to 64-bit.
87
*/
88
typedef enum J9_CEL4RO64_ArgType {
89
CEL4RO64_type_void,
90
CEL4RO64_type_jboolean,
91
CEL4RO64_type_jbyte,
92
CEL4RO64_type_jchar,
93
CEL4RO64_type_jshort,
94
CEL4RO64_type_jint,
95
CEL4RO64_type_jlong,
96
CEL4RO64_type_jfloat,
97
CEL4RO64_type_jdouble,
98
CEL4RO64_type_jsize,
99
CEL4RO64_type_jobject,
100
CEL4RO64_type_jweak,
101
CEL4RO64_type_jclass,
102
CEL4RO64_type_jstring,
103
CEL4RO64_type_jthrowable,
104
CEL4RO64_type_jarray,
105
CEL4RO64_type_uint32_ptr,
106
CEL4RO64_type_jmethodID,
107
CEL4RO64_type_jfieldID,
108
CEL4RO64_type_JNIEnv64,
109
CEL4RO64_type_JavaVM64,
110
CEL4RO64_type_EnsureWideEnum = 0x1000000 /* force 4-byte enum */
111
} J9_CEL4RO64_ArgType;
112
113
/**
114
* A helper routine to invoke a target function with outgoing arguments and return values.
115
* @param[in] functionDescriptor The 64-bit function descriptor of target function to invoke.
116
* @param[in] argTypes An array of argument types for call.
117
* @param[in] argsValues An uint64_t array of argument values.
118
* @param[in] numArgs Number of arguments.
119
* @param[in] returnType The return type of target function.
120
* @param[in] returnStorage The storage location to store return value.
121
*
122
* @return The return code of the CEL4RO64 call - 0 implies success.
123
*/
124
uint32_t
125
j9_cel4ro64_call_function(
126
uint64_t functionDescriptor, J9_CEL4RO64_ArgType *argTypes, uint64_t *argValues, uint32_t numArgs,
127
J9_CEL4RO64_ArgType returnType, void *returnStorage);
128
129
/**
130
* A helper routine to allocate the CEL4RO64 control blocks and related structures
131
* for module, function and arguments.
132
* @param[in] moduleName The name of the target library to load.
133
* @param[in] functionName The name of the target function to lookup.
134
* @param[in] argTypes An array of argument types for call.
135
* @param[in] argsValues An uint64_t array of argument values.
136
* @param[in] numArgs Number of arguments.
137
* @param[in] returnType The return type of target function.
138
* @param[in] returnStorage The storage location to store return value.
139
*
140
* @return The return code of the CEL4RO64 call - 0 implies success.
141
*/
142
uint32_t
143
j9_cel4ro64_load_query_call_function(
144
const char* moduleName, const char* functionName, J9_CEL4RO64_ArgType *argTypes,
145
uint64_t *argValues, uint32_t numArgs, J9_CEL4RO64_ArgType returnType, void *returnStorage);
146
147
/**
148
* A helper routine to confirm LE support of CEL4RO64
149
* @return whether CEL4RO64 runtime support is available.
150
*/
151
jboolean
152
j9_cel4ro64_isSupported(void);
153
154
/**
155
* A helper routine to return an error message associated with the CEL4RO64 return code.
156
* @param[in] retCode A CEL4RO64 return code.
157
*
158
* @return A message describing the conditions of the given error.
159
*/
160
const char *
161
j9_cel4ro64_get_error_message(int32_t retCode);
162
163
#ifdef __cplusplus
164
}
165
#endif
166
167
#endif /* j9cel4ro64_h */
168
169