Mercurial > pub > dyncall > dyncall
view doc/manual/manual_overview.tex @ 110:9aa75a74614c
- working mips32 eabi callbacks
- mips32 eabi doc update
- switched some mips32 eabi call assembly to use more portable pseudo instructions for storing floats
- fixed weird type use of var declaration in mips callbacks
- ToDo update
- converted some // comments to old c-style
- test code build fix for some test suites on some platforms
author | cslag |
---|---|
date | Sat, 18 Jun 2016 19:38:22 +0200 |
parents | 5c3fa8897e0e |
children | 6da2a7ee2a86 |
line wrap: on
line source
%////////////////////////////////////////////////////////////////////////////// % % Copyright (c) 2007,2009 Daniel Adler <dadler@uni-goettingen.de>, % Tassilo Philipp <tphilipp@potion-studios.com> % % Permission to use, copy, modify, and distribute this software for any % purpose with or without fee is hereby granted, provided that the above % copyright notice and this permission notice appear in all copies. % % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. % %////////////////////////////////////////////////////////////////////////////// \newpage \section{Overview} The \product{dyncall} library encapsulates architecture-, OS- and compiler-specific function call semantics in a virtual % % \casehtml{\Tg<span class="marker">}{\begin{center}}% \emph{bind argument parameters from left to right and then call} \casehtml{\Tg</span>}{\end{center}}% % interface allowing programmers to call C functions in a completely dynamic manner. In other words, instead of calling a function directly, the \product{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 \product{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\ldots\\ \\ The core of the library consists of dynamic implementations of different 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 \product{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 \textbf{supported platforms} section for an overview of the supported platforms and the different calling convention sections for details about the support. \\ \begin{comment} @@@ A typical binary library consists of symbolic names that map to variables and functions, the latter being pre-compiled for a specific calling convention and architecture. Given \product{dyncall} has been ported to that binary platform, it is possible to call such a function dynamically without writing glue code or prototypes or even knowing its C declaration - all that is needed is a pointer to it.\\ To avoid confusion, note that from the point of view of the library all parameters are handled the same way, even though the implementation might use other ways to pass parameters in order to suit specific calling conventions.\\ \end{comment} \subsection{Features} \begin{itemize} \item A portable and extendable function call interface for the C programming language. \item 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.. \item Add-on language bindings to Python, R, Ruby, Go, Erlang, Java, Lua, sh, ... \item High-level state machine design using C to model calling convention parameter transfer. \item One assembly \emph{hybrid} call routine per calling convention. \item Formatted call, vararg function API. \item Comprehensive test suite. \end{itemize} \pagebreak \subsection{Showcase} \paragraph{Foreign function call in C} This section demonstrates how the foreign function call is issued without, and then with, the help of the \product{dyncall} library and scripting language bindings. \begin{lstlisting}[language=c,caption=Foreign function call in C] double call_as_sqrt(void* funptr, double x) { return ( ( double (*)(double) )funptr)(x); } \end{lstlisting} \paragraph{\product{Dyncall} C library example} The same operation can be broken down into atomic pieces (specify calling convention, binding arguments, invoking the call) using the \dc\ library. \begin{lstlisting}[language=c,caption=Dyncall C library example] #include <dyncall.h> double call_as_sqrt(void* funptr, double x) { double r; DCCallVM* vm = dcNewCallVM(4096); dcMode(vm, DC_CALL_C_DEFAULT); dcReset(vm); dcArgDouble(vm, x); r = dcCallDouble(vm, funptr); dcFree(vm); return r; } \end{lstlisting} As you can see, this is more code after all, but completely dynamic. And definitely less than generated glue-code for each function call, if used correctly. The following are examples from script bindings: \paragraph{Python example} \begin{lstlisting}[language=python,caption=Dyncall Python bindings example] import pydc def call_as_sqrt(funptr,x): return pydc.call(funptr,"d)d", x) \end{lstlisting} \paragraph{R example} \begin{lstlisting}[language=R,caption=Dyncall R bindings example,escapeinside={TEX}{XET}] % escapeinside is a workaround for issues with '<' in lstlisting+tex4ht library(rdyncall) call.as.sqrt TEX\textlessXET- function(funptr,x) .dyncall(funptr,"d)d", x) \end{lstlisting} \pagebreak \subsection{Supported platforms/architectures} The feature matrix below gives a brief overview of the currently supported platforms. Different 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. \begin{table}[h] \begin{tabular}{r|*{15}{c}} & & & & & & & & & & & & & & & \\ & \ninetyb {\bf Alpha}\ninetye & \ninetyb {\bf ARM}\ninetye & \ninetyb {\bf ARM64}\ninetye & \ninetyb {\bf MIPS}\ninetye & \ninetyb {\bf MIPS64}\ninetye & \ninetyb {\bf SuperH}\ninetye & \ninetyb {\bf PowerPC}\ninetye & \ninetyb {\bf PowerPC64}\ninetye & \ninetyb {\bf m68k}\ninetye & \ninetyb {\bf m88k}\ninetye & \ninetyb {\bf x86}\ninetye & \ninetyb {\bf x64}\ninetye & \ninetyb {\bf Itanium}\ninetye & \ninetyb {\bf SPARC}\ninetye & \ninetyb {\bf SPARC64}\ninetye \\ \hline {\bf Windows family} & \marknotx & \markunkn & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \markcmpl & \markcmpl & \marknimp & \marknotx & \marknotx \\ {\bf Linux} & \marknimp & \markcmpl & \markcmpl & \markunkn & \markunkn & \marknotx & \markcmpl & \markcmpl & \marknotx & \marknotx & \markcmpl & \markcmpl & \marknotx & \markimpl & \markimpl \\ {\bf Mac OS X / iOS / Darwin} & \marknotx & \markcmpl & \markcmpl & \marknotx & \marknotx & \marknotx & \markcmpl & \markunkn & \marknotx & \marknotx & \markcmpl & \markcmpl & \marknotx & \marknotx & \marknotx \\ {\bf FreeBSD} & \marknimp & \markcmpl & \markcmpl & \markunkn & \markunkn & \marknimp & \markimpl & \markcmpl & \marknotx & \marknotx & \markcmpl & \markcmpl & \marknimp & \markunkn & \markunkn \\ {\bf NetBSD} & \marknimp & \markcmpl & \marknotx & \markimpl & \markunkn & \marknimp & \markimpl & \marknotx & \marknimp & \marknimp & \markcmpl & \markcmpl & \marknimp & \markimpl & \markunkn \\ {\bf OpenBSD} & \marknimp & \markcmpl & \marknotx & \markunkn & \markimpl & \marknimp & \markunkn & \marknotx & \marknimp & \marknimp & \markcmpl & \markcmpl & \marknimp & \markimpl & \markimpl \\ {\bf DragonFlyBSD} & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \markcmpl & \markcmpl & \marknotx & \marknotx & \marknotx \\ {\bf Solaris} & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \markcmpl & \markcmpl & \marknotx & \markimpl & \markimpl \\ {\bf Plan 9 / 9front} & \marknimp & \marknimp & \marknotx & \marknimp & \marknotx & \marknotx & \marknimp & \marknotx & \marknotx & \marknotx & \markcmpl & \marknimp & \marknotx & \marknimp & \marknotx \\ {\bf Haiku / BeOS} & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \markcmpl & \marknotx & \marknotx & \marknotx & \marknotx \\ {\bf Minix} & \marknotx & \markunkn & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \markcmpl & \marknotx & \marknotx & \marknotx & \marknotx \\ {\bf Playstation Portable} & \marknotx & \marknotx & \marknotx & \markcmpl & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx \\ {\bf Nintendo DS} & \marknotx & \markcmpl & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx & \marknotx \\ \end{tabular} \caption{Supported platforms}% \end{table}