File: trampoline.man

package info (click to toggle)
ffcall 2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,024 kB
  • sloc: asm: 100,607; ansic: 50,932; sh: 5,630; makefile: 1,588; cpp: 2
file content (75 lines) | stat: -rw-r--r-- 3,013 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
TRAMPOLINE(3)              Library Functions Manual              TRAMPOLINE(3)



NAME
       trampoline - closures as first-class C functions

SYNOPSIS
       #include <trampoline.h>

       function = alloc_trampoline(address, variable, data);

       free_trampoline(function);

       is_trampoline(function)
       trampoline_address(function)
       trampoline_variable(function)
       trampoline_data(function)

DESCRIPTION
       These  functions implement closures as first-class C functions.  A clo‐
       sure consists of a regular C function and a piece of  data  which  gets
       passed to the C function when the closure is called.

       Closures as first-class C functions means that they fit into a function
       pointer and can be called exactly like any other C function.   function
       =  alloc_trampoline(address,  variable, data) allocates a closure. When
       function gets called, it stores data in the variable variable and calls
       the  C function at address.  The function at address is responsible for
       fetching data out of variable  immediately,  before  execution  of  any
       other function call.

       This  is  much  like gcc's local functions, except that the GNU C local
       functions have dynamic extent (i.e. are deallocated when  the  creating
       function  returns), while trampoline provides functions with indefinite
       extent: function is only deallocated when free_trampoline(function)  is
       called.

       is_trampoline(function) checks whether the C function function was pro‐
       duced by a call to alloc_trampoline.  If this returns true,  the  argu‐
       ments given to alloc_trampoline can be retrieved:

           trampoline_address(function) returns address,

           trampoline_variable(function) returns variable,

           trampoline_data(function) returns data.


SEE ALSO
       gcc(1), stdarg(3), callback(3)


BUGS
       Passing the data through a global variable is not reentrant. Don't call
       trampoline functions from within signal handlers. This is fixed in  the
       callback(3) package.


PORTING
       The way gcc builds local functions is described in the gcc source, file
       gcc-2.6.3/config/cpu/cpu.h.


AUTHOR
       Bruno Haible <bruno@clisp.org>


ACKNOWLEDGEMENTS
       Many ideas were cribbed from the gcc source.




                                1 January 2017                   TRAMPOLINE(3)