public class DynCall
extends java.lang.Object
The dyncall library encapsulates architecture-, OS- and compiler-specific function call semantics in a virtual "bind argument parameters from left to right and then call" interface allowing programmers to call C functions in a completely dynamic manner.
In other words, instead of calling a function directly, the dyncall library provides a mechanism to push the function parameters manually and to issue the call afterwards.
Since the idea behind this concept is similar to call dispatching mechanisms of virtual machines, the object that can be dynamically loaded with
arguments, and then used to actually invoke the call, is called CallVM. It is possible to change the calling convention used by the
CallVM at run-time. Due to the fact that nearly every platform comes with one or more distinct calling conventions, the dyncall library project
intends to be a portable and open-source approach to the variety of compiler-specific binary interfaces, platform specific subtleties, and so on...
| Modifier and Type | Field and Description |
|---|---|
static int |
DC_CALL_C_ARM_ARM
Supported calling convention modes.
|
static int |
DC_CALL_C_ARM_ARM_EABI
Supported calling convention modes.
|
static int |
DC_CALL_C_ARM_ARMHF
Supported calling convention modes.
|
static int |
DC_CALL_C_ARM_THUMB
Supported calling convention modes.
|
static int |
DC_CALL_C_ARM_THUMB_EABI
Supported calling convention modes.
|
static int |
DC_CALL_C_ARM64
Supported calling convention modes.
|
static int |
DC_CALL_C_DEFAULT
Supported calling convention modes.
|
static int |
DC_CALL_C_ELLIPSIS
Supported calling convention modes.
|
static int |
DC_CALL_C_ELLIPSIS_VARARGS
Supported calling convention modes.
|
static int |
DC_CALL_C_MIPS32_EABI
Supported calling convention modes.
|
static int |
DC_CALL_C_MIPS32_O32
Supported calling convention modes.
|
static int |
DC_CALL_C_MIPS64_N32
Supported calling convention modes.
|
static int |
DC_CALL_C_MIPS64_N64
Supported calling convention modes.
|
static int |
DC_CALL_C_PPC32_DARWIN
Supported calling convention modes.
|
static int |
DC_CALL_C_PPC32_LINUX
Supported calling convention modes.
|
static int |
DC_CALL_C_PPC32_OSX
Supported calling convention modes.
|
static int |
DC_CALL_C_PPC32_SYSV
Supported calling convention modes.
|
static int |
DC_CALL_C_PPC64
Supported calling convention modes.
|
static int |
DC_CALL_C_PPC64_LINUX
Supported calling convention modes.
|
static int |
DC_CALL_C_SPARC32
Supported calling convention modes.
|
static int |
DC_CALL_C_SPARC64
Supported calling convention modes.
|
static int |
DC_CALL_C_X64_SYSV
Supported calling convention modes.
|
static int |
DC_CALL_C_X64_WIN64
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_CDECL
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_PLAN9
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_WIN32_FAST_GNU
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_WIN32_FAST_MS
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_WIN32_STD
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_WIN32_THIS_GNU
Supported calling convention modes.
|
static int |
DC_CALL_C_X86_WIN32_THIS_MS
Supported calling convention modes.
|
static int |
DC_CALL_SYS_DEFAULT
Supported calling convention modes.
|
static int |
DC_CALL_SYS_PPC32
Supported calling convention modes.
|
static int |
DC_CALL_SYS_PPC64
Supported calling convention modes.
|
static int |
DC_CALL_SYS_X86_INT80H_BSD
Supported calling convention modes.
|
static int |
DC_CALL_SYS_X86_INT80H_LINUX
Supported calling convention modes.
|
static int |
DC_ERROR_NONE
Error codes.
|
static int |
DC_ERROR_UNSUPPORTED_MODE
Error codes.
|
static int |
DC_FALSE
Boolean values.
|
static char |
DC_SIGCHAR_BOOL
Signatures.
|
static char |
DC_SIGCHAR_CHAR
Signatures.
|
static char |
DC_SIGCHAR_DOUBLE
Signatures.
|
static char |
DC_SIGCHAR_ENDARG
Signatures.
|
static char |
DC_SIGCHAR_FLOAT
Signatures.
|
static char |
DC_SIGCHAR_INT
Signatures.
|
static char |
DC_SIGCHAR_LONG
Signatures.
|
static char |
DC_SIGCHAR_LONGLONG
Signatures.
|
static char |
DC_SIGCHAR_POINTER
Signatures.
|
static char |
DC_SIGCHAR_SHORT
Signatures.
|
static char |
DC_SIGCHAR_STRING
Signatures.
|
static char |
DC_SIGCHAR_STRUCT
Signatures.
|
static char |
DC_SIGCHAR_UCHAR
Signatures.
|
static char |
DC_SIGCHAR_UINT
Signatures.
|
static char |
DC_SIGCHAR_ULONG
Signatures.
|
static char |
DC_SIGCHAR_ULONGLONG
Signatures.
|
static char |
DC_SIGCHAR_USHORT
Signatures.
|
static char |
DC_SIGCHAR_VOID
Signatures.
|
static int |
DC_TRUE
Boolean values.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
dcArgBool(long vm,
boolean value)
Binds a
bool argument. |
static void |
dcArgChar(long vm,
byte value)
Binds a
char argument. |
static void |
dcArgDouble(long vm,
double value)
Binds a
double argument. |
static void |
dcArgFloat(long vm,
float value)
Binds a
float argument. |
static void |
dcArgInt(long vm,
int value)
Binds an
int argument. |
static void |
dcArgLong(long vm,
long value)
Binds a
long argument. |
static void |
dcArgLongLong(long vm,
long value)
Binds a
long long argument. |
static void |
dcArgPointer(long vm,
long value)
Binds a pointer argument.
|
static void |
dcArgShort(long vm,
short value)
Binds a
short argument. |
static void |
dcArgStruct(long vm,
long s,
long value)
Binds a struct argument.
|
static boolean |
dcCallBool(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static byte |
dcCallChar(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static double |
dcCallDouble(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static float |
dcCallFloat(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static int |
dcCallInt(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static long |
dcCallLong(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static long |
dcCallLongLong(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static long |
dcCallPointer(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static short |
dcCallShort(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static void |
dcCallStruct(long vm,
long funcptr,
long s,
long returnValue)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static void |
dcCallVoid(long vm,
long funcptr)
Calls the function specified by
funcptr with the arguments bound to the CallVM and returns. |
static void |
dcCloseStruct(long s)
Completes the struct definition.
|
static long |
dcDefineStruct(java.nio.ByteBuffer signature)
Creates a new struct type using a signature string.
|
static long |
dcDefineStruct(java.lang.CharSequence signature)
Creates a new struct type using a signature string.
|
static void |
dcFree(long vm)
Frees a
CallVM object. |
static void |
dcFreeStruct(long s)
Frees the specified struct object.
|
static int |
dcGetError(long vm)
Returns the most recent error state code.
|
static void |
dcMode(long vm,
int mode)
Sets the calling convention to use.
|
static long |
dcNewCallVM(long size)
Creates a new
CallVM object. |
static long |
dcNewStruct(long fieldCount,
int alignment)
Creates a new struct type.
|
static void |
dcReset(long vm)
Resets the internal stack of arguments and prepares it for a new call.
|
static long |
dcStructAlignment(long s)
Returns the alignment, in bytes, of the specified struct.
|
static void |
dcStructField(long s,
int type,
int alignment,
long arrayLength)
Adds a field to the specified struct.
|
static long |
dcStructSize(long s)
Returns the size, in bytes, of the specified struct.
|
static void |
dcSubStruct(long s,
long fieldCount,
int alignment,
long arrayLength)
Adds a nested struct to the specified struct
|
static void |
ndcArgBool(long vm,
int value)
Unsafe version of:
ArgBool |
static void |
ndcArgChar(long vm,
byte value)
Unsafe version of:
ArgChar |
static void |
ndcArgDouble(long vm,
double value)
Unsafe version of:
ArgDouble |
static void |
ndcArgFloat(long vm,
float value)
Unsafe version of:
ArgFloat |
static void |
ndcArgInt(long vm,
int value)
Unsafe version of:
ArgInt |
static void |
ndcArgLong(long vm,
long value)
Unsafe version of:
ArgLong |
static void |
ndcArgLongLong(long vm,
long value)
Unsafe version of:
ArgLongLong |
static void |
ndcArgPointer(long vm,
long value)
Unsafe version of:
ArgPointer |
static void |
ndcArgShort(long vm,
short value)
Unsafe version of:
ArgShort |
static void |
ndcArgStruct(long vm,
long s,
long value)
Unsafe version of:
ArgStruct |
static int |
ndcCallBool(long vm,
long funcptr)
Unsafe version of:
CallBool |
static byte |
ndcCallChar(long vm,
long funcptr)
Unsafe version of:
CallChar |
static double |
ndcCallDouble(long vm,
long funcptr)
Unsafe version of:
CallDouble |
static float |
ndcCallFloat(long vm,
long funcptr)
Unsafe version of:
CallFloat |
static int |
ndcCallInt(long vm,
long funcptr)
Unsafe version of:
CallInt |
static long |
ndcCallLong(long vm,
long funcptr)
Unsafe version of:
CallLong |
static long |
ndcCallLongLong(long vm,
long funcptr)
Unsafe version of:
CallLongLong |
static long |
ndcCallPointer(long vm,
long funcptr)
Unsafe version of:
CallPointer |
static short |
ndcCallShort(long vm,
long funcptr)
Unsafe version of:
CallShort |
static void |
ndcCallStruct(long vm,
long funcptr,
long s,
long returnValue)
Unsafe version of:
CallStruct |
static void |
ndcCallVoid(long vm,
long funcptr)
Unsafe version of:
CallVoid |
static void |
ndcCloseStruct(long s)
Unsafe version of:
CloseStruct |
static long |
ndcDefineStruct(long signature)
Unsafe version of:
DefineStruct |
static void |
ndcFree(long vm)
Unsafe version of:
Free |
static void |
ndcFreeStruct(long s)
Unsafe version of:
FreeStruct |
static int |
ndcGetError(long vm)
Unsafe version of:
GetError |
static void |
ndcMode(long vm,
int mode)
Unsafe version of:
Mode |
static void |
ndcReset(long vm)
Unsafe version of:
Reset |
static long |
ndcStructAlignment(long s)
Unsafe version of:
StructAlignment |
static void |
ndcStructField(long s,
int type,
int alignment,
long arrayLength)
Unsafe version of:
StructField |
static long |
ndcStructSize(long s)
Unsafe version of:
StructSize |
static void |
ndcSubStruct(long s,
long fieldCount,
int alignment,
long arrayLength)
Unsafe version of:
SubStruct |
public static final int DC_CALL_C_DEFAULT
public static final int DC_CALL_C_ELLIPSIS
public static final int DC_CALL_C_ELLIPSIS_VARARGS
public static final int DC_CALL_C_X86_CDECL
public static final int DC_CALL_C_X86_WIN32_STD
public static final int DC_CALL_C_X86_WIN32_FAST_MS
public static final int DC_CALL_C_X86_WIN32_FAST_GNU
public static final int DC_CALL_C_X86_WIN32_THIS_MS
public static final int DC_CALL_C_X86_WIN32_THIS_GNU
public static final int DC_CALL_C_X64_WIN64
public static final int DC_CALL_C_X64_SYSV
public static final int DC_CALL_C_PPC32_DARWIN
public static final int DC_CALL_C_PPC32_OSX
public static final int DC_CALL_C_ARM_ARM_EABI
public static final int DC_CALL_C_ARM_THUMB_EABI
public static final int DC_CALL_C_ARM_ARMHF
public static final int DC_CALL_C_MIPS32_EABI
public static final int DC_CALL_C_PPC32_SYSV
public static final int DC_CALL_C_PPC32_LINUX
public static final int DC_CALL_C_ARM_ARM
public static final int DC_CALL_C_ARM_THUMB
public static final int DC_CALL_C_MIPS32_O32
public static final int DC_CALL_C_MIPS64_N32
public static final int DC_CALL_C_MIPS64_N64
public static final int DC_CALL_C_X86_PLAN9
public static final int DC_CALL_C_SPARC32
public static final int DC_CALL_C_SPARC64
public static final int DC_CALL_C_ARM64
public static final int DC_CALL_C_PPC64
public static final int DC_CALL_C_PPC64_LINUX
public static final int DC_CALL_SYS_DEFAULT
public static final int DC_CALL_SYS_X86_INT80H_LINUX
public static final int DC_CALL_SYS_X86_INT80H_BSD
public static final int DC_CALL_SYS_PPC32
public static final int DC_CALL_SYS_PPC64
public static final int DC_ERROR_NONE
public static final int DC_ERROR_UNSUPPORTED_MODE
public static final int DC_TRUE
public static final int DC_FALSE
public static final char DC_SIGCHAR_VOID
public static final char DC_SIGCHAR_BOOL
public static final char DC_SIGCHAR_CHAR
public static final char DC_SIGCHAR_UCHAR
public static final char DC_SIGCHAR_SHORT
public static final char DC_SIGCHAR_USHORT
public static final char DC_SIGCHAR_INT
public static final char DC_SIGCHAR_UINT
public static final char DC_SIGCHAR_LONG
public static final char DC_SIGCHAR_ULONG
public static final char DC_SIGCHAR_LONGLONG
public static final char DC_SIGCHAR_ULONGLONG
public static final char DC_SIGCHAR_FLOAT
public static final char DC_SIGCHAR_DOUBLE
public static final char DC_SIGCHAR_POINTER
public static final char DC_SIGCHAR_STRING
public static final char DC_SIGCHAR_STRUCT
public static final char DC_SIGCHAR_ENDARG
public static long dcNewCallVM(long size)
CallVM object.
Use Free to destroy the CallVM object.
size - the max size of the internal stack that will be allocated and used to bind arguments topublic static void ndcFree(long vm)
Freepublic static void dcFree(long vm)
CallVM object.vm - a CallVM instancepublic static void ndcReset(long vm)
Resetpublic static void dcReset(long vm)
Mode), but
prior to binding arguments to the CallVM. Use it also when reusing a CallVM, as arguments don’t get flushed automatically after a
function call invocation.
Note: you should also call this function after initial creation of the a CallVM object, as NewCallVM doesn’t do this, implicitly.
vm - a CallVM instancepublic static void ndcMode(long vm,
int mode)
Modepublic static void dcMode(long vm,
int mode)
CALL_C_DEFAULT is the default standard C call on the target platform. It uses the standard C calling convention. CALL_C_ELLIPSIS is used for C
ellipsis calls which allow to build up a variable argument list. On many platforms, there is only one C calling convention. The X86 platform provides a
rich family of different calling conventions.
vm - a CallVM instancemode - the calling convention. One of:public static void ndcArgBool(long vm,
int value)
ArgBoolpublic static void dcArgBool(long vm,
boolean value)
bool argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgChar(long vm,
byte value)
ArgCharpublic static void dcArgChar(long vm,
byte value)
char argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgShort(long vm,
short value)
ArgShortpublic static void dcArgShort(long vm,
short value)
short argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgInt(long vm,
int value)
ArgIntpublic static void dcArgInt(long vm,
int value)
int argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgLong(long vm,
long value)
ArgLongpublic static void dcArgLong(long vm,
long value)
long argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgLongLong(long vm,
long value)
ArgLongLongpublic static void dcArgLongLong(long vm,
long value)
long long argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgFloat(long vm,
float value)
ArgFloatpublic static void dcArgFloat(long vm,
float value)
float argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgDouble(long vm,
double value)
ArgDoublepublic static void dcArgDouble(long vm,
double value)
double argument.vm - a CallVM instancevalue - the argument valuepublic static void ndcArgPointer(long vm,
long value)
ArgPointerpublic static void dcArgPointer(long vm,
long value)
vm - a CallVM instancevalue - the argument valuepublic static void ndcArgStruct(long vm,
long s,
long value)
ArgStructpublic static void dcArgStruct(long vm,
long s,
long value)
vm - a CallVM instancevalue - the argument valuepublic static void ndcCallVoid(long vm,
long funcptr)
CallVoidpublic static void dcCallVoid(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static int ndcCallBool(long vm,
long funcptr)
CallBoolpublic static boolean dcCallBool(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static byte ndcCallChar(long vm,
long funcptr)
CallCharpublic static byte dcCallChar(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static short ndcCallShort(long vm,
long funcptr)
CallShortpublic static short dcCallShort(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static int ndcCallInt(long vm,
long funcptr)
CallIntpublic static int dcCallInt(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static long ndcCallLong(long vm,
long funcptr)
CallLongpublic static long dcCallLong(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static long ndcCallLongLong(long vm,
long funcptr)
CallLongLongpublic static long dcCallLongLong(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static float ndcCallFloat(long vm,
long funcptr)
CallFloatpublic static float dcCallFloat(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static double ndcCallDouble(long vm,
long funcptr)
CallDoublepublic static double dcCallDouble(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static long ndcCallPointer(long vm,
long funcptr)
CallPointerpublic static long dcCallPointer(long vm,
long funcptr)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static void ndcCallStruct(long vm,
long funcptr,
long s,
long returnValue)
CallStructpublic static void dcCallStruct(long vm,
long funcptr,
long s,
long returnValue)
funcptr with the arguments bound to the CallVM and returns.
After the invocation of the foreign function call, the argument values are still bound and a second call using the same arguments can be issued. If you
need to clear the argument bindings, you have to reset the CallVM.
vm - a CallVM instancefuncptr - the function pointerpublic static int ndcGetError(long vm)
GetErrorpublic static int dcGetError(long vm)
vm - a CallVM instancepublic static long dcNewStruct(long fieldCount,
int alignment)
fieldCount - the number of fieldsalignment - a custom struct alignment, or 0 to calculate automaticallypublic static void ndcStructField(long s,
int type,
int alignment,
long arrayLength)
StructFieldpublic static void dcStructField(long s,
int type,
int alignment,
long arrayLength)
s - the structtype - the field type. One of:alignment - a custom field alignment, or 0 to calculate automaticallyarrayLength - 1 or a higher value if the field is an arraypublic static void ndcSubStruct(long s,
long fieldCount,
int alignment,
long arrayLength)
SubStructpublic static void dcSubStruct(long s,
long fieldCount,
int alignment,
long arrayLength)
s - the structfieldCount - the number of fields in the nested structalignment - a custom nested struct alignment, or 0 to calculate automaticallyarrayLength - 1 or a higher value if the nested struct is an arraypublic static void ndcCloseStruct(long s)
CloseStructpublic static void dcCloseStruct(long s)
s - the struct to closepublic static long ndcStructSize(long s)
StructSizepublic static long dcStructSize(long s)
s - the structpublic static long ndcStructAlignment(long s)
StructAlignmentpublic static long dcStructAlignment(long s)
s - the structpublic static void ndcFreeStruct(long s)
FreeStructpublic static void dcFreeStruct(long s)
s - the struct to freepublic static long ndcDefineStruct(long signature)
DefineStructpublic static long dcDefineStruct(java.nio.ByteBuffer signature)
signature - the struct signaturepublic static long dcDefineStruct(java.lang.CharSequence signature)
signature - the struct signatureCopyright LWJGL. All Rights Reserved. License terms.