Class DynCall
- java.lang.Object
-
- org.lwjgl.system.dyncall.DynCall
-
public class DynCall extends java.lang.Object
Native 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 theCallVM
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...
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static void
dcArgBool(long vm, boolean value)
Binds abool
argument.static void
dcArgChar(long vm, byte value)
Binds achar
argument.static void
dcArgDouble(long vm, double value)
Binds adouble
argument.static void
dcArgFloat(long vm, float value)
Binds afloat
argument.static void
dcArgInt(long vm, int value)
Binds anint
argument.static void
dcArgLong(long vm, int value)
Binds along
argument.static void
dcArgLongLong(long vm, long value)
Binds along long
argument.static void
dcArgPointer(long vm, long value)
Binds a pointer argument.static void
dcArgShort(long vm, short value)
Binds ashort
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 byfuncptr
with the arguments bound to theCallVM
and returns.static byte
dcCallChar(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static double
dcCallDouble(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static float
dcCallFloat(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static int
dcCallInt(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static int
dcCallLong(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static long
dcCallLongLong(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static long
dcCallPointer(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static short
dcCallShort(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static void
dcCallStruct(long vm, long funcptr, long s, long returnValue)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
and returns.static void
dcCallVoid(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
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 aCallVM
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 newCallVM
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
-
-
-
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 newCallVM
object.Use
Free
to destroy theCallVM
object.- Parameters:
size
- the max size of the internal stack that will be allocated and used to bind arguments to
-
dcFree
public static void dcFree(long vm)
Frees aCallVM
object.- Parameters:
vm
- aCallVM
instance
-
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
CallVM
object, asNewCallVM
doesn’t do this, implicitly.- Parameters:
vm
- aCallVM
instance
-
dcMode
public static void dcMode(long vm, int mode)
Sets the calling convention to use.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.- Parameters:
vm
- aCallVM
instancemode
- the calling convention. One of:
-
dcArgBool
public static void dcArgBool(long vm, boolean value)
Binds abool
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgChar
public static void dcArgChar(long vm, byte value)
Binds achar
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgShort
public static void dcArgShort(long vm, short value)
Binds ashort
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgInt
public static void dcArgInt(long vm, int value)
Binds anint
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgLong
public static void dcArgLong(long vm, int value)
Binds along
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgLongLong
public static void dcArgLongLong(long vm, long value)
Binds along long
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgFloat
public static void dcArgFloat(long vm, float value)
Binds afloat
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgDouble
public static void dcArgDouble(long vm, double value)
Binds adouble
argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgPointer
public static void dcArgPointer(long vm, long value)
Binds a pointer argument.- Parameters:
vm
- aCallVM
instancevalue
- the argument value
-
dcArgStruct
public static void dcArgStruct(long vm, long s, long value)
Binds a struct argument.- Parameters:
vm
- aCallVM
instances
-value
- the argument value
-
dcCallVoid, dcCallBool, dcCallChar, dcCallShort, dcCallInt, dcCallLong, dcCallLongLong, dcCallFloat, dcCallDouble, dcCallPointer
public static void dcCallVoid(long vm, long funcptr) public static boolean dcCallBool(long vm, long funcptr) public static byte dcCallChar(long vm, long funcptr) public static short dcCallShort(long vm, long funcptr) public static int dcCallInt(long vm, long funcptr) public static int dcCallLong(long vm, long funcptr) public static long dcCallLongLong(long vm, long funcptr) public static float dcCallFloat(long vm, long funcptr) public static double dcCallDouble(long vm, long funcptr) public static long dcCallPointer(long vm, long funcptr)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
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
.- Parameters:
vm
- aCallVM
instancefuncptr
- the function pointer
-
dcCallStruct
public static void dcCallStruct(long vm, long funcptr, long s, long returnValue)
Calls the function specified byfuncptr
with the arguments bound to theCallVM
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
.- Parameters:
vm
- aCallVM
instancefuncptr
- the function pointers
-returnValue
-
-
dcGetError
public static int dcGetError(long vm)
Returns the most recent error state code.- Parameters:
vm
- aCallVM
instance
-
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
-
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 typealignment
- a custom field alignment, or 0 to calculate automaticallyarrayLength
- 1 or a higher value if the field is an array
-
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
-
dcCloseStruct
public static void dcCloseStruct(long s)
Completes the struct definition.- Parameters:
s
- the struct to close
-
dcStructSize
public static long dcStructSize(long s)
Returns the size, in bytes, of the specified struct.- Parameters:
s
- the struct
-
dcStructAlignment
public static long dcStructAlignment(long s)
Returns the alignment, in bytes, of the specified struct.- Parameters:
s
- the struct
-
dcFreeStruct
public static void dcFreeStruct(long s)
Frees the specified struct object.- Parameters:
s
- the struct to free
-
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
-
-