2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl service runtime closure.
36 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_NACL_CLOSURE_H_
37 #define NATIVE_CLIENT_SERVICE_RUNTIME_NACL_CLOSURE_H_
39 #include "native_client/service_runtime/nacl_sync.h"
42 * This file contains declarations for simple closures. They
43 * self-delete when run. The ctors are factory fns, rather than
44 * placement-new style ctors. If there is no memory, we immediately
45 * abort. The dtor frees.
47 * There are currently subclasses to handle at most 10 arguments.
48 * Beyond that, wrap the args in a struct and pass a pointer to it!
50 * This should be machine-generated code to allow more args.
52 * Primary deficiency: we use void * as the generic argument type, and
53 * while it suffices for much, it is neither type-safe nor complete
54 * (viz, 64-bit types such as int64_t, double, etc won't work).
61 struct NaClClosureVtbl
{
62 void (*Dtor
)(struct NaClClosure
*);
63 void (*Run
)(struct NaClClosure
*);
67 struct NaClClosureVtbl
const *vtbl
;
68 struct NaClClosureResult
*res
;
72 struct NaClClosure base
;
76 struct NaClClosure0
*NaClClosure0Ctor(void (*fn
)(void));
77 void NaClClosure0Dtor(struct NaClClosure
*vself
);
78 void NaClClosure0Run(struct NaClClosure
*vself
);
81 struct NaClClosure base
;
86 struct NaClClosure1
*NaClClosure1Ctor(void (*fn
)(void *arg1
),
88 void NaClClosure1Dtor(struct NaClClosure
*vself
);
89 void NaClClosure1Run(struct NaClClosure
*vself
);
92 struct NaClClosure base
;
93 void (*fn
)(void *, void *);
98 struct NaClClosure2
*NaClClosure2Ctor(void (*fn
)(void *arg1
,
102 void NaClClosure2Dtor(struct NaClClosure
*self
);
103 void NaClClosure2Run(struct NaClClosure
*vself
);
105 struct NaClClosure3
{
106 struct NaClClosure base
;
107 void (*fn
)(void *, void *, void *);
113 struct NaClClosure3
*NaClClosure3Ctor(void (*fn
)(void *arg1
,
119 void NaClClosure3Dtor(struct NaClClosure
*self
);
120 void NaClClosure3Run(struct NaClClosure
*vself
);
122 struct NaClClosure4
{
123 struct NaClClosure base
;
124 void (*fn
)(void *, void *, void *, void *);
131 struct NaClClosure4
*NaClClosure4Ctor(void (*fn
)(void *arg1
,
139 void NaClClosure4Dtor(struct NaClClosure
*self
);
140 void NaClClosure4Run(struct NaClClosure
*vself
);
142 struct NaClClosure5
{
143 struct NaClClosure base
;
144 void (*fn
)(void *, void *, void *, void *,
146 void *arg1
, *arg2
, *arg3
, *arg4
;
150 struct NaClClosure5
*NaClClosure5Ctor(void (*fn
)(void *arg1
,
160 void NaClClosure5Dtor(struct NaClClosure
*self
);
161 void NaClClosure5Run(struct NaClClosure
*vself
);
163 struct NaClClosure6
{
164 struct NaClClosure base
;
165 void (*fn
)(void *, void *, void *, void *,
175 struct NaClClosure6
*NaClClosure6Ctor(void (*fn
)(void *arg1
,
187 void NaClClosure6Dtor(struct NaClClosure
*self
);
188 void NaClClosure6Run(struct NaClClosure
*vself
);
190 struct NaClClosure7
{
191 struct NaClClosure base
;
192 void (*fn
)(void *, void *, void *, void *,
193 void *, void *, void *);
203 struct NaClClosure7
*NaClClosure7Ctor(void (*fn
)(void *arg1
,
217 void NaClClosure7Dtor(struct NaClClosure
*self
);
218 void NaClClosure7Run(struct NaClClosure
*vself
);
220 struct NaClClosure8
{
221 struct NaClClosure base
;
222 void (*fn
)(void *, void *, void *, void *,
223 void *, void *, void *, void *);
234 struct NaClClosure8
*NaClClosure8Ctor(void (*fn
)(void *arg1
,
250 void NaClClosure8Dtor(struct NaClClosure
*self
);
251 void NaClClosure8Run(struct NaClClosure
*vself
);
253 struct NaClClosure9
{
254 struct NaClClosure base
;
255 void (*fn
)(void *, void *, void *, void *,
256 void *, void *, void *, void *,
269 struct NaClClosure9
*NaClClosure9Ctor(void (*fn
)(void *arg1
,
287 void NaClClosure9Dtor(struct NaClClosure
*self
);
288 void NaClClosure9Run(struct NaClClosure
*vself
);
290 struct NaClClosure10
{
291 struct NaClClosure base
;
292 void (*fn
)(void *, void *, void *, void *,
293 void *, void *, void *, void *,
307 struct NaClClosure10
*NaClClosure10Ctor(void (*fn
)(void *arg1
,
327 void NaClClosure10Dtor(struct NaClClosure
*self
);
328 void NaClClosure10Run(struct NaClClosure
*vself
);