Class 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 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...

    • Method Detail

      • dcNewCallVM

        public static long dcNewCallVM​(long size)
        Creates a new CallVM object.

        Use Free to destroy the CallVM object.

        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 a CallVM object.
        Parameters:
        vm - a CallVM instance
      • 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 (using 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.

        Parameters:
        vm - a CallVM instance
      • ndcMode

        public static void ndcMode​(long vm,
                                   int mode)
        Unsafe version of: Mode
      • ndcArgBool

        public static void ndcArgBool​(long vm,
                                      int value)
        Unsafe version of: ArgBool
      • dcArgBool

        public static void dcArgBool​(long vm,
                                     boolean value)
        Binds a bool argument.
        Parameters:
        vm - a CallVM instance
        value - 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 a char argument.
        Parameters:
        vm - a CallVM instance
        value - 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 a short argument.
        Parameters:
        vm - a CallVM instance
        value - 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 an int argument.
        Parameters:
        vm - a CallVM instance
        value - the argument value
      • ndcArgLong

        public static void ndcArgLong​(long vm,
                                      int value)
        Unsafe version of: ArgLong
      • dcArgLong

        public static void dcArgLong​(long vm,
                                     int value)
        Binds a long argument.
        Parameters:
        vm - a CallVM instance
        value - 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 a long long argument.
        Parameters:
        vm - a CallVM instance
        value - 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 a float argument.
        Parameters:
        vm - a CallVM instance
        value - 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 a double argument.
        Parameters:
        vm - a CallVM instance
        value - 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 - a CallVM instance
        value - 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 - a CallVM instance
        value - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - the function pointer
      • ndcCallLong

        public static int ndcCallLong​(long vm,
                                      long funcptr)
        Unsafe version of: CallLong
      • dcCallLong

        public static int dcCallLong​(long vm,
                                     long funcptr)
        Calls the function specified by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 by 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.

        Parameters:
        vm - a CallVM instance
        funcptr - 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 - a CallVM instance
      • dcNewStruct

        public static long dcNewStruct​(long fieldCount,
                                       int alignment)
        Creates a new struct type.
        Parameters:
        fieldCount - the number of fields
        alignment - 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
      • 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 struct
        fieldCount - the number of fields in the nested struct
        alignment - a custom nested struct alignment, or 0 to calculate automatically
        arrayLength - 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