dyncall library encapsulates architecture-, OS- and compiler-speciﬁc 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-speciﬁc binary interfaces, platform speciﬁc subtleties, and so on…
The core of the library consists of dynamic implementations of diﬀerent calling conventions written in assembler. Although the library aims to be highly portable, some assembler code needs to be written for nearly every platform/compiler/OS combination. Unfortunately, there are architectures we just don’t have at home or work. If you want to see dyncall running on such a platform, feel free to send in code and patches, or even to donate hardware you don’t need anymore. Check the supported platforms section for an overview of the supported platforms and the diﬀerent calling convention sections for details about the support.
- A portable and extendable function call interface for the C programming language.
- Ports to major platforms including Windows, Mac OS X, Linux, BSD derivates, iPhone and embedded devices and more, including lesser known and/or older platforms like Plan 9, Playstation Portable, Nintendo DS, etc..
- Add-on language bindings to Python, R, Ruby, Go, Erlang, Java, Lua, sh, ...
- High-level state machine design using C to model calling convention parameter transfer.
- One assembly hybrid call routine per calling convention.
- Formatted call, vararg function API.
- Comprehensive test suite.
Foreign function call in C
return ( ( double (*)(double) )funptr)(x);
double call_as_sqrt(void* funptr, double x)
DCCallVM* vm = dcNewCallVM(4096);
r = dcCallDouble(vm, funptr);
As you can see, this is more code after all, but completely dynamic. And deﬁnitely less than generated glue-code for each function call, if used correctly.
return pydc.call(funptr,"d)d", x)
The feature matrix below gives a brief overview of the currently supported platforms. Diﬀerent colors are
used, where a green cell indicates a supported platform, yellow a platform that might work (but is untested)
and red a platform that is currently unsupported. Gray cells are combinations that don’t exist at the time of
writing, or that are not taken into account.
Light green cells mark complete feature support, as in dyncall and dyncallback. Dark green means basic support but lacking features (e.g. dyncall support, but not dyncallback). Please note that a green cell (even a light-green one) doesn’t imply that all existing calling conventions/features/build tools are supported for that platform (but the most important). For detailed info about a platform’s support consult the calling convention appendix.
The library needs at least a c99 compiler with additional support for anonymous structs/unions (which were introduced oﬃcially in c11). Given that those are generally supported by pretty much all major c99 conforming compilers (as default extension), it should build ﬁne with a c99 toolchain.