Class DynCall
- java.lang.Object
-
- org.lwjgl.system.dyncall.DynCall
-
public class DynCall extends java.lang.ObjectNative bindings to \"dyncall.h\".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 theCallVMat 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...
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddcArgBool(long vm, boolean value)Binds aboolargument.static voiddcArgChar(long vm, byte value)Binds acharargument.static voiddcArgDouble(long vm, double value)Binds adoubleargument.static voiddcArgFloat(long vm, float value)Binds afloatargument.static voiddcArgInt(long vm, int value)Binds anintargument.static voiddcArgLong(long vm, long value)Binds alongargument.static voiddcArgLongLong(long vm, long value)Binds along longargument.static voiddcArgPointer(long vm, long value)Binds a pointer argument.static voiddcArgShort(long vm, short value)Binds ashortargument.static voiddcArgStruct(long vm, long s, long value)Binds a struct argument.static booleandcCallBool(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static bytedcCallChar(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static doubledcCallDouble(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static floatdcCallFloat(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static intdcCallInt(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static longdcCallLong(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static longdcCallLongLong(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static longdcCallPointer(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static shortdcCallShort(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static voiddcCallStruct(long vm, long funcptr, long s, long returnValue)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static voiddcCallVoid(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand returns.static voiddcCloseStruct(long s)Completes the struct definition.static longdcDefineStruct(java.lang.CharSequence signature)Creates a new struct type using a signature string.static longdcDefineStruct(java.nio.ByteBuffer signature)Creates a new struct type using a signature string.static voiddcFree(long vm)Frees aCallVMobject.static voiddcFreeStruct(long s)Frees the specified struct object.static intdcGetError(long vm)Returns the most recent error state code.static voiddcMode(long vm, int mode)Sets the calling convention to use.static longdcNewCallVM(long size)Creates a newCallVMobject.static longdcNewStruct(long fieldCount, int alignment)Creates a new struct type.static voiddcReset(long vm)Resets the internal stack of arguments and prepares it for a new call.static longdcStructAlignment(long s)Returns the alignment, in bytes, of the specified struct.static voiddcStructField(long s, int type, int alignment, long arrayLength)Adds a field to the specified struct.static longdcStructSize(long s)Returns the size, in bytes, of the specified struct.static voiddcSubStruct(long s, long fieldCount, int alignment, long arrayLength)Adds a nested struct to the specified structstatic voidndcArgBool(long vm, int value)Unsafe version of:ArgBoolstatic voidndcArgChar(long vm, byte value)Unsafe version of:ArgCharstatic voidndcArgDouble(long vm, double value)Unsafe version of:ArgDoublestatic voidndcArgFloat(long vm, float value)Unsafe version of:ArgFloatstatic voidndcArgInt(long vm, int value)Unsafe version of:ArgIntstatic voidndcArgLong(long vm, long value)Unsafe version of:ArgLongstatic voidndcArgLongLong(long vm, long value)Unsafe version of:ArgLongLongstatic voidndcArgPointer(long vm, long value)Unsafe version of:ArgPointerstatic voidndcArgShort(long vm, short value)Unsafe version of:ArgShortstatic voidndcArgStruct(long vm, long s, long value)Unsafe version of:ArgStructstatic intndcCallBool(long vm, long funcptr)Unsafe version of:CallBoolstatic bytendcCallChar(long vm, long funcptr)Unsafe version of:CallCharstatic doublendcCallDouble(long vm, long funcptr)Unsafe version of:CallDoublestatic floatndcCallFloat(long vm, long funcptr)Unsafe version of:CallFloatstatic intndcCallInt(long vm, long funcptr)Unsafe version of:CallIntstatic longndcCallLong(long vm, long funcptr)Unsafe version of:CallLongstatic longndcCallLongLong(long vm, long funcptr)Unsafe version of:CallLongLongstatic longndcCallPointer(long vm, long funcptr)Unsafe version of:CallPointerstatic shortndcCallShort(long vm, long funcptr)Unsafe version of:CallShortstatic voidndcCallStruct(long vm, long funcptr, long s, long returnValue)Unsafe version of:CallStructstatic voidndcCallVoid(long vm, long funcptr)Unsafe version of:CallVoidstatic voidndcCloseStruct(long s)Unsafe version of:CloseStructstatic longndcDefineStruct(long signature)Unsafe version of:DefineStructstatic voidndcFree(long vm)Unsafe version of:Freestatic voidndcFreeStruct(long s)Unsafe version of:FreeStructstatic intndcGetError(long vm)Unsafe version of:GetErrorstatic voidndcMode(long vm, int mode)Unsafe version of:Modestatic voidndcReset(long vm)Unsafe version of:Resetstatic longndcStructAlignment(long s)Unsafe version of:StructAlignmentstatic voidndcStructField(long s, int type, int alignment, long arrayLength)Unsafe version of:StructFieldstatic longndcStructSize(long s)Unsafe version of:StructSizestatic voidndcSubStruct(long s, long fieldCount, int alignment, long arrayLength)Unsafe version of:SubStruct
-
-
-
Field Detail
-
DC_CALL_C_DEFAULT, DC_CALL_C_ELLIPSIS, DC_CALL_C_ELLIPSIS_VARARGS, DC_CALL_C_X86_CDECL, DC_CALL_C_X86_WIN32_STD, DC_CALL_C_X86_WIN32_FAST_MS, DC_CALL_C_X86_WIN32_FAST_GNU, DC_CALL_C_X86_WIN32_THIS_MS, DC_CALL_C_X86_WIN32_THIS_GNU, DC_CALL_C_X64_WIN64, DC_CALL_C_X64_SYSV, DC_CALL_C_PPC32_DARWIN, DC_CALL_C_PPC32_OSX, DC_CALL_C_ARM_ARM_EABI, DC_CALL_C_ARM_THUMB_EABI, DC_CALL_C_ARM_ARMHF, DC_CALL_C_MIPS32_EABI, DC_CALL_C_PPC32_SYSV, DC_CALL_C_PPC32_LINUX, DC_CALL_C_ARM_ARM, DC_CALL_C_ARM_THUMB, DC_CALL_C_MIPS32_O32, DC_CALL_C_MIPS64_N32, DC_CALL_C_MIPS64_N64, DC_CALL_C_X86_PLAN9, DC_CALL_C_SPARC32, DC_CALL_C_SPARC64, DC_CALL_C_ARM64, DC_CALL_C_PPC64, DC_CALL_C_PPC64_LINUX, DC_CALL_SYS_DEFAULT, DC_CALL_SYS_X86_INT80H_LINUX, DC_CALL_SYS_X86_INT80H_BSD, DC_CALL_SYS_PPC32, DC_CALL_SYS_PPC64
Supported calling convention modes.
-
DC_ERROR_NONE, DC_ERROR_UNSUPPORTED_MODE
Error codes.
-
DC_SIGCHAR_VOID, DC_SIGCHAR_BOOL, DC_SIGCHAR_CHAR, DC_SIGCHAR_UCHAR, DC_SIGCHAR_SHORT, DC_SIGCHAR_USHORT, DC_SIGCHAR_INT, DC_SIGCHAR_UINT, DC_SIGCHAR_LONG, DC_SIGCHAR_ULONG, DC_SIGCHAR_LONGLONG, DC_SIGCHAR_ULONGLONG, DC_SIGCHAR_FLOAT, DC_SIGCHAR_DOUBLE, DC_SIGCHAR_POINTER, DC_SIGCHAR_STRING, DC_SIGCHAR_STRUCT, DC_SIGCHAR_ENDARG
Signatures.
-
-
Method Detail
-
dcNewCallVM
public static long dcNewCallVM(long size)
Creates a newCallVMobject.Use
Freeto destroy theCallVMobject.- Parameters:
size- the max size of the internal stack that will be allocated and used to bind arguments to
-
ndcFree
public static void ndcFree(long vm)
Unsafe version of:Free
-
dcFree
public static void dcFree(long vm)
Frees aCallVMobject.- Parameters:
vm- aCallVMinstance
-
ndcReset
public static void ndcReset(long vm)
Unsafe version of:Reset
-
dcReset
public static void dcReset(long vm)
Resets the internal stack of arguments and prepares it for a new call. This function should be called after setting the call mode (usingMode), but prior to binding arguments to theCallVM. Use it also when reusing aCallVM, 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
CallVMobject, asNewCallVMdoesn’t do this, implicitly.- Parameters:
vm- aCallVMinstance
-
ndcMode
public static void ndcMode(long vm, int mode)Unsafe version of:Mode
-
dcMode
public static void dcMode(long vm, int mode)Sets the calling convention to use.CALL_C_DEFAULTis the default standard C call on the target platform. It uses the standard C calling convention.CALL_C_ELLIPSISis 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.- Parameters:
vm- aCallVMinstancemode- the calling convention. One of:
-
ndcArgBool
public static void ndcArgBool(long vm, int value)Unsafe version of:ArgBool
-
dcArgBool
public static void dcArgBool(long vm, boolean value)Binds aboolargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgChar
public static void ndcArgChar(long vm, byte value)Unsafe version of:ArgChar
-
dcArgChar
public static void dcArgChar(long vm, byte value)Binds acharargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgShort
public static void ndcArgShort(long vm, short value)Unsafe version of:ArgShort
-
dcArgShort
public static void dcArgShort(long vm, short value)Binds ashortargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgInt
public static void ndcArgInt(long vm, int value)Unsafe version of:ArgInt
-
dcArgInt
public static void dcArgInt(long vm, int value)Binds anintargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgLong
public static void ndcArgLong(long vm, long value)Unsafe version of:ArgLong
-
dcArgLong
public static void dcArgLong(long vm, long value)Binds alongargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgLongLong
public static void ndcArgLongLong(long vm, long value)Unsafe version of:ArgLongLong
-
dcArgLongLong
public static void dcArgLongLong(long vm, long value)Binds along longargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgFloat
public static void ndcArgFloat(long vm, float value)Unsafe version of:ArgFloat
-
dcArgFloat
public static void dcArgFloat(long vm, float value)Binds afloatargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgDouble
public static void ndcArgDouble(long vm, double value)Unsafe version of:ArgDouble
-
dcArgDouble
public static void dcArgDouble(long vm, double value)Binds adoubleargument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgPointer
public static void ndcArgPointer(long vm, long value)Unsafe version of:ArgPointer
-
dcArgPointer
public static void dcArgPointer(long vm, long value)Binds a pointer argument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcArgStruct
public static void ndcArgStruct(long vm, long s, long value)Unsafe version of:ArgStruct
-
dcArgStruct
public static void dcArgStruct(long vm, long s, long value)Binds a struct argument.- Parameters:
vm- aCallVMinstancevalue- the argument value
-
ndcCallVoid
public static void ndcCallVoid(long vm, long funcptr)Unsafe version of:CallVoid
-
dcCallVoid
public static void dcCallVoid(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallBool
public static int ndcCallBool(long vm, long funcptr)Unsafe version of:CallBool
-
dcCallBool
public static boolean dcCallBool(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallChar
public static byte ndcCallChar(long vm, long funcptr)Unsafe version of:CallChar
-
dcCallChar
public static byte dcCallChar(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallShort
public static short ndcCallShort(long vm, long funcptr)Unsafe version of:CallShort
-
dcCallShort
public static short dcCallShort(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallInt
public static int ndcCallInt(long vm, long funcptr)Unsafe version of:CallInt
-
dcCallInt
public static int dcCallInt(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallLong
public static long ndcCallLong(long vm, long funcptr)Unsafe version of:CallLong
-
dcCallLong
public static long dcCallLong(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallLongLong
public static long ndcCallLongLong(long vm, long funcptr)Unsafe version of:CallLongLong
-
dcCallLongLong
public static long dcCallLongLong(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallFloat
public static float ndcCallFloat(long vm, long funcptr)Unsafe version of:CallFloat
-
dcCallFloat
public static float dcCallFloat(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallDouble
public static double ndcCallDouble(long vm, long funcptr)Unsafe version of:CallDouble
-
dcCallDouble
public static double dcCallDouble(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallPointer
public static long ndcCallPointer(long vm, long funcptr)Unsafe version of:CallPointer
-
dcCallPointer
public static long dcCallPointer(long vm, long funcptr)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcCallStruct
public static void ndcCallStruct(long vm, long funcptr, long s, long returnValue)Unsafe version of:CallStruct
-
dcCallStruct
public static void dcCallStruct(long vm, long funcptr, long s, long returnValue)Calls the function specified byfuncptrwith the arguments bound to theCallVMand 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.- Parameters:
vm- aCallVMinstancefuncptr- the function pointer
-
ndcGetError
public static int ndcGetError(long vm)
Unsafe version of:GetError
-
dcGetError
public static int dcGetError(long vm)
Returns the most recent error state code.- Parameters:
vm- aCallVMinstance
-
dcNewStruct
public static long dcNewStruct(long fieldCount, int alignment)Creates a new struct type.- Parameters:
fieldCount- the number of fieldsalignment- a custom struct alignment, or 0 to calculate automatically
-
ndcStructField
public static void ndcStructField(long s, int type, int alignment, long arrayLength)Unsafe version of:StructField
-
dcStructField
public static void dcStructField(long s, int type, int alignment, long arrayLength)Adds a field to the specified struct.- Parameters:
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 array
-
ndcSubStruct
public static void ndcSubStruct(long s, long fieldCount, int alignment, long arrayLength)Unsafe version of:SubStruct
-
dcSubStruct
public static void dcSubStruct(long s, long fieldCount, int alignment, long arrayLength)Adds a nested struct to the specified struct- Parameters:
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 array
-
ndcCloseStruct
public static void ndcCloseStruct(long s)
Unsafe version of:CloseStruct
-
dcCloseStruct
public static void dcCloseStruct(long s)
Completes the struct definition.- Parameters:
s- the struct to close
-
ndcStructSize
public static long ndcStructSize(long s)
Unsafe version of:StructSize
-
dcStructSize
public static long dcStructSize(long s)
Returns the size, in bytes, of the specified struct.- Parameters:
s- the struct
-
ndcStructAlignment
public static long ndcStructAlignment(long s)
Unsafe version of:StructAlignment
-
dcStructAlignment
public static long dcStructAlignment(long s)
Returns the alignment, in bytes, of the specified struct.- Parameters:
s- the struct
-
ndcFreeStruct
public static void ndcFreeStruct(long s)
Unsafe version of:FreeStruct
-
dcFreeStruct
public static void dcFreeStruct(long s)
Frees the specified struct object.- Parameters:
s- the struct to free
-
ndcDefineStruct
public static long ndcDefineStruct(long signature)
Unsafe version of:DefineStruct
-
dcDefineStruct
public static long dcDefineStruct(java.nio.ByteBuffer signature) public static long dcDefineStruct(java.lang.CharSequence signature)
Creates a new struct type using a signature string.- Parameters:
signature- the struct signature
-
-