/*******************************************************************************1* Copyright (c) 2021, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122#ifndef j9cel4ro64_h23#define j9cel4ro64_h2425#include <stdint.h>26#include <string.h>27#include "jni.h" /* Needed for return argument type handling */2829#ifdef __cplusplus30extern "C" {31#endif3233/* Flags to control the behaviour of CEL4RO64. Used by controlBlock->flags */34#define J9_CEL4RO64_FLAG_LOAD_DLL 0x8000000035#define J9_CEL4RO64_FLAG_QUERY_TARGET_FUNC 0x4000000036#define J9_CEL4RO64_FLAG_EXECUTE_TARGET_FUNC 0x2000000037#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)3839/* Return codes for CEL4RO64 */40#define J9_CEL4RO64_RETCODE_OK 0x041#define J9_CEL4RO64_RETCODE_ERROR_MULTITHREAD_INVOCATION 0x142#define J9_CEL4RO64_RETCODE_ERROR_STORAGE_ISSUE 0x243#define J9_CEL4RO64_RETCODE_ERROR_FAILED_AMODE64_ENV 0x344#define J9_CEL4RO64_RETCODE_ERROR_FAILED_LOAD_TARGET_DLL 0x445#define J9_CEL4RO64_RETCODE_ERROR_FAILED_QUERY_TARGET_FUNC 0x546#define J9_CEL4RO64_RETCODE_ERROR_LE_RUNTIME_SUPPORT_NOT_FOUND 0x64748/* Fixed length Control Block structure RO64_CB */49typedef struct J9_CEL4RO64_controlBlock {50uint32_t version; /**< (Input) A integer which contains the version of RO64_INFO. */51uint32_t length; /**< (Input) A integer which contains the total length of RO64_INFO. */52uint32_t flags; /**< (Input) Flags to control the behavior of CEL4RO64. */53uint32_t moduleOffset; /**< (Input) Offset to RO64_module part from start of RO64_CB. Req'd for DLL load flag. */54uint32_t functionOffset; /**< (Input) Offset to RO64_function part from start of RO64_CB. Req'd for DLL query flag. */55uint32_t argumentsOffset; /**< (Input) Offset to RO64_args part from start of RO64_CB. Req'd for function execution flag. */56uint64_t dllHandle; /**< DLL handle of target program (Input) if DLL query flag. (Output) if DLL load flag. */57uint64_t functionDescriptor; /**< Function descriptor of target function (Input) if function exection flag. (Output) if DLL query flag. */58uint64_t gpr1ReturnValue; /**< (Output) Return buffer containing 64-bit GPR1 value of target program after execution. */59uint64_t gpr2ReturnValue; /**< (Output) Return buffer containing 64-bit GPR2 value of target program after execution. */60uint64_t gpr3ReturnValue; /**< (Output) Return buffer containing 64-bit GPR3 value of target program after execution. */61int32_t retcode; /**< (Output) Return code of CEL4RO64. */62} J9_CEL4RO64_controlBlock;6364/* Module name to load */65typedef struct J9_CEL4RO64_module {66int32_t length; /**< Length of the module name. */67char moduleName[1]; /**< Pointer to variable length module name. */68} J9_CEL4RO64_module;6970/* Internal struct to map function name definition in control block. */71typedef struct J9_CEL4RO64_function {72int32_t length; /**< Length of the function name. */73char functionName[1]; /**< Pointer to variable length function name. */74} J9_CEL4RO64_function;7576/* Internal struct to track the RO64 control block and related variable length structures. */77typedef struct J9_CEL4RO64_infoBlock {78J9_CEL4RO64_module *ro64Module; /**< Pointer to the start of the module section of the control block. */79J9_CEL4RO64_function *ro64Function; /**< Pointer to the start of the function section of the control block. */80uint32_t *ro64Arguments; /**< Pointer to the start of the outgoing arguments section of the control block. */81J9_CEL4RO64_controlBlock ro64ControlBlock; /**< Pointer to the control block for CEL4RO64. */82} J9_CEL4RO64_infoBlock;8384/**85* Types to facilitate argument construction and return values for calls to 64-bit.86*/87typedef enum J9_CEL4RO64_ArgType {88CEL4RO64_type_void,89CEL4RO64_type_jboolean,90CEL4RO64_type_jbyte,91CEL4RO64_type_jchar,92CEL4RO64_type_jshort,93CEL4RO64_type_jint,94CEL4RO64_type_jlong,95CEL4RO64_type_jfloat,96CEL4RO64_type_jdouble,97CEL4RO64_type_jsize,98CEL4RO64_type_jobject,99CEL4RO64_type_jweak,100CEL4RO64_type_jclass,101CEL4RO64_type_jstring,102CEL4RO64_type_jthrowable,103CEL4RO64_type_jarray,104CEL4RO64_type_uint32_ptr,105CEL4RO64_type_jmethodID,106CEL4RO64_type_jfieldID,107CEL4RO64_type_JNIEnv64,108CEL4RO64_type_JavaVM64,109CEL4RO64_type_EnsureWideEnum = 0x1000000 /* force 4-byte enum */110} J9_CEL4RO64_ArgType;111112/**113* A helper routine to invoke a target function with outgoing arguments and return values.114* @param[in] functionDescriptor The 64-bit function descriptor of target function to invoke.115* @param[in] argTypes An array of argument types for call.116* @param[in] argsValues An uint64_t array of argument values.117* @param[in] numArgs Number of arguments.118* @param[in] returnType The return type of target function.119* @param[in] returnStorage The storage location to store return value.120*121* @return The return code of the CEL4RO64 call - 0 implies success.122*/123uint32_t124j9_cel4ro64_call_function(125uint64_t functionDescriptor, J9_CEL4RO64_ArgType *argTypes, uint64_t *argValues, uint32_t numArgs,126J9_CEL4RO64_ArgType returnType, void *returnStorage);127128/**129* A helper routine to allocate the CEL4RO64 control blocks and related structures130* for module, function and arguments.131* @param[in] moduleName The name of the target library to load.132* @param[in] functionName The name of the target function to lookup.133* @param[in] argTypes An array of argument types for call.134* @param[in] argsValues An uint64_t array of argument values.135* @param[in] numArgs Number of arguments.136* @param[in] returnType The return type of target function.137* @param[in] returnStorage The storage location to store return value.138*139* @return The return code of the CEL4RO64 call - 0 implies success.140*/141uint32_t142j9_cel4ro64_load_query_call_function(143const char* moduleName, const char* functionName, J9_CEL4RO64_ArgType *argTypes,144uint64_t *argValues, uint32_t numArgs, J9_CEL4RO64_ArgType returnType, void *returnStorage);145146/**147* A helper routine to confirm LE support of CEL4RO64148* @return whether CEL4RO64 runtime support is available.149*/150jboolean151j9_cel4ro64_isSupported(void);152153/**154* A helper routine to return an error message associated with the CEL4RO64 return code.155* @param[in] retCode A CEL4RO64 return code.156*157* @return A message describing the conditions of the given error.158*/159const char *160j9_cel4ro64_get_error_message(int32_t retCode);161162#ifdef __cplusplus163}164#endif165166#endif /* j9cel4ro64_h */167168169