summaryrefslogtreecommitdiff
path: root/preload/wrappers_c.tmpl
blob: 024a46807378e59bf5b57f48e1a48ef0d3154b78 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Automatically generated file. Do not edit. */
## ^^^(Not this one, but the one this emits) ^^^

\#include "libsb2.h"
\#include "exported.h"


#def map_defs(key): char *mapped__$key = NULL;
#def map_pre(key): SBOX_MAP_PATH($key, mapped__$key);
#def map_post(key): if(mapped__$key) free(mapped__$key);
#def mapat_pre(f): SBOX_MAP_PATH_AT($f.mapfd,$f.mapkey, mapped__$f.mapkey);


#def optarg_defs(): int mode = 0;
#def optarg_pre(f)
    if($f.optarg_cond) {
      va_list arg;
      va_start (arg, $f.optarg_prev);
      mode = va_arg (arg, int);
      va_end (arg);
    }
#end def


#def HEADER(f,domap)
	#set global $f = $f
	#for $ext in f.extra
	#if domap or 'nomap' in $ext: #include source=$ext.defs

	#end for
	#for $ext in f.extra
        #if domap or 'nomap' in $ext: #include source=$ext.pre

	#end for

#end def

#def FOOTER(f,domap)
	#for $ext in f.extra
	#if domap or 'nomap' in $ext: #include source=$ext.post
	#end for
#end def


############################# WRAPS

#for $f in $funcs:
#set $fnext = $f.name+'_next__'
/*WRAP: $f.ret $(f.name)($f.args): $f.extra
 * 
*/
static $f.ret (*$fnext)($f.args);

$f.ret $f.name ($f.args)
{
	$f.ret ret;

  $HEADER($f,True)
	
        if($fnext == NULL) {
                $fnext = sbox_find_next_symbol(1, "$f.name");
        }
        ret = (*$fnext)(${', '.join(f.argnames)});
	$FOOTER($f,True)

        return(ret);

}

#if f.emit_nomap:
$f.ret ${f.name}_nomap($f.args)
{
	$f.ret ret;

  $HEADER($f,False)

        if($fnext == NULL) {
                $fnext = sbox_find_next_symbol(1, "$f.name");
        }
        ret = (*$fnext)(${', '.join(f.argnames_orig)});
  $FOOTER($f,False)

        return(ret);

}
#end if

#if f.emit_nomap_nolog:
$f.ret ${f.name}_nomap_nolog($f.args)
{
	$f.ret ret;

  $HEADER($f,False)

        if($fnext == NULL) {
                $fnext = sbox_find_next_symbol(0, "$f.name");
        }
        ret = (*$fnext)(${', '.join(f.argnames_orig)});
  $FOOTER($f,False)

        return(ret);

}
#end if

#end for

############################# GATES

#def vaskip_defs(): va_list ap;
#def vaskip_pre(f): va_start(ap,$f.optarg_prev);
#def vaskip_post(): va_end ap;


#for $f in $gates:
#set $fnext = $f.name+'_next__'
/*GATE: $f.ret $(f.name)($f.args): $f.extra
 * 
*/
static $f.ret (*$fnext)($f.args);

$f.ret $f.name ($f.args)
{
	$f.ret ret;
  $HEADER($f,True)

        if($fnext == NULL) {
                $fnext = sbox_find_next_symbol(1, "$f.name");
        }
  ret = ${f.name}_gate(${', '.join([$fnext,'__func__']+f.argnames)});

  $FOOTER($f,True)
        return(ret);
}

#end for