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 #include "native_client/service_runtime/nacl_closure.h"
38 #include "native_client/service_runtime/nacl_log.h"
41 * This file implements simple closures. See the header file for
44 * This should be machine-generated code to allow more args.
46 * Primary deficiency: we use void * as the generic argument type, and
47 * while it suffices for much, it is neither type-safe nor complete
48 * (viz, 64-bit types such as int64_t, double, etc won't work).
51 static struct NaClClosureVtbl
const kNaClClosure0Vtbl
= {
56 struct NaClClosure0
*NaClClosure0Ctor(void (*fn
)(void))
58 struct NaClClosure0
*self
= malloc(sizeof *self
);
60 NaClLog(LOG_FATAL
, "No memory in NaClClosure0 ctor\n");
62 self
->base
.vtbl
= &kNaClClosure0Vtbl
;
67 void NaClClosure0Dtor(struct NaClClosure
*vself
)
69 struct NaClClosure0
*self
= (struct NaClClosure0
*) vself
;
73 void NaClClosure0Run(struct NaClClosure
*vself
)
75 struct NaClClosure0
*self
= (struct NaClClosure0
*) vself
;
77 NaClClosure0Dtor(vself
);
80 static struct NaClClosureVtbl
const kNaClClosure1Vtbl
= {
85 struct NaClClosure1
*NaClClosure1Ctor(void (*fn
)(void *),
88 struct NaClClosure1
*self
= malloc(sizeof *self
);
90 NaClLog(LOG_FATAL
, "No memory in NaClClosure1 ctor\n");
92 self
->base
.vtbl
= &kNaClClosure1Vtbl
;
98 void NaClClosure1Dtor(struct NaClClosure
*vself
)
100 struct NaClClosure1
*self
= (struct NaClClosure1
*) vself
;
104 void NaClClosure1Run(struct NaClClosure
*vself
)
106 struct NaClClosure1
*self
= (struct NaClClosure1
*) vself
;
107 (*self
->fn
)(self
->arg1
);
108 NaClClosure1Dtor(vself
);
111 static struct NaClClosureVtbl
const kNaClClosure2Vtbl
= {
116 struct NaClClosure2
*NaClClosure2Ctor(void (*fn
)(void *, void *),
120 struct NaClClosure2
*self
= malloc(sizeof *self
);
122 NaClLog(LOG_FATAL
, "No memory in NaClClosure2 ctor\n");
124 self
->base
.vtbl
= &kNaClClosure2Vtbl
;
131 void NaClClosure2Dtor(struct NaClClosure
*vself
)
133 struct NaClClosure2
*self
= (struct NaClClosure2
*) vself
;
137 void NaClClosure2Run(struct NaClClosure
*vself
)
139 struct NaClClosure2
*self
= (struct NaClClosure2
*) vself
;
140 (*self
->fn
)(self
->arg1
, self
->arg2
);
141 NaClClosure2Dtor(vself
);
144 static struct NaClClosureVtbl
const kNaClClosure3Vtbl
= {
149 struct NaClClosure3
*NaClClosure3Ctor(void (*fn
)(void *, void *, void *),
154 struct NaClClosure3
*self
= malloc(sizeof *self
);
156 NaClLog(LOG_FATAL
, "No memory in NaClClosure3 ctor\n");
158 self
->base
.vtbl
= &kNaClClosure3Vtbl
;
166 void NaClClosure3Dtor(struct NaClClosure
*vself
)
168 struct NaClClosure3
*self
= (struct NaClClosure3
*) vself
;
172 void NaClClosure3Run(struct NaClClosure
*vself
)
174 struct NaClClosure3
*self
= (struct NaClClosure3
*) vself
;
175 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
);
176 NaClClosure3Dtor(vself
);
179 static struct NaClClosureVtbl
const kNaClClosure4Vtbl
= {
184 struct NaClClosure4
*NaClClosure4Ctor(void (*fn
)(void *, void *,
191 struct NaClClosure4
*self
= malloc(sizeof *self
);
193 NaClLog(LOG_FATAL
, "No memory in NaClClosure4 ctor\n");
195 self
->base
.vtbl
= &kNaClClosure4Vtbl
;
204 void NaClClosure4Dtor(struct NaClClosure
*vself
)
206 struct NaClClosure4
*self
= (struct NaClClosure4
*) vself
;
210 void NaClClosure4Run(struct NaClClosure
*vself
)
212 struct NaClClosure4
*self
= (struct NaClClosure4
*) vself
;
213 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
);
214 NaClClosure4Dtor(vself
);
217 static struct NaClClosureVtbl
const kNaClClosure5Vtbl
= {
222 struct NaClClosure5
*NaClClosure5Ctor(void (*fn
)(void *, void *,
231 struct NaClClosure5
*self
= malloc(sizeof *self
);
233 NaClLog(LOG_FATAL
, "No memory in NaClClosure5 ctor\n");
235 self
->base
.vtbl
= &kNaClClosure5Vtbl
;
245 void NaClClosure5Dtor(struct NaClClosure
*vself
)
247 struct NaClClosure5
*self
= (struct NaClClosure5
*) vself
;
251 void NaClClosure5Run(struct NaClClosure
*vself
)
253 struct NaClClosure5
*self
= (struct NaClClosure5
*) vself
;
254 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
,
256 NaClClosure5Dtor(vself
);
259 static struct NaClClosureVtbl
const kNaClClosure6Vtbl
= {
264 struct NaClClosure6
*NaClClosure6Ctor(void (*fn
)(void *, void *,
274 struct NaClClosure6
*self
= malloc(sizeof *self
);
276 NaClLog(LOG_FATAL
, "No memory in NaClClosure6 ctor\n");
278 self
->base
.vtbl
= &kNaClClosure6Vtbl
;
289 void NaClClosure6Dtor(struct NaClClosure
*vself
)
291 struct NaClClosure6
*self
= (struct NaClClosure6
*) vself
;
295 void NaClClosure6Run(struct NaClClosure
*vself
)
297 struct NaClClosure6
*self
= (struct NaClClosure6
*) vself
;
298 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
,
299 self
->arg5
, self
->arg6
);
300 NaClClosure6Dtor(vself
);
303 static struct NaClClosureVtbl
const kNaClClosure7Vtbl
= {
308 struct NaClClosure7
*NaClClosure7Ctor(void (*fn
)(void *, void *,
320 struct NaClClosure7
*self
= malloc(sizeof *self
);
322 NaClLog(LOG_FATAL
, "No memory in NaClClosure7 ctor\n");
324 self
->base
.vtbl
= &kNaClClosure7Vtbl
;
336 void NaClClosure7Dtor(struct NaClClosure
*vself
)
338 struct NaClClosure7
*self
= (struct NaClClosure7
*) vself
;
342 void NaClClosure7Run(struct NaClClosure
*vself
)
344 struct NaClClosure7
*self
= (struct NaClClosure7
*) vself
;
345 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
,
346 self
->arg5
, self
->arg6
, self
->arg7
);
347 NaClClosure7Dtor(vself
);
350 static struct NaClClosureVtbl
const kNaClClosure8Vtbl
= {
355 struct NaClClosure8
*NaClClosure8Ctor(void (*fn
)(void *, void *,
368 struct NaClClosure8
*self
= malloc(sizeof *self
);
370 NaClLog(LOG_FATAL
, "No memory in NaClClosure8 ctor\n");
372 self
->base
.vtbl
= &kNaClClosure8Vtbl
;
385 void NaClClosure8Dtor(struct NaClClosure
*vself
)
387 struct NaClClosure8
*self
= (struct NaClClosure8
*) vself
;
391 void NaClClosure8Run(struct NaClClosure
*vself
)
393 struct NaClClosure8
*self
= (struct NaClClosure8
*) vself
;
394 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
,
395 self
->arg5
, self
->arg6
, self
->arg7
, self
->arg8
);
396 NaClClosure8Dtor(vself
);
399 static struct NaClClosureVtbl
const kNaClClosure9Vtbl
= {
404 struct NaClClosure9
*NaClClosure9Ctor(void (*fn
)(void *, void *,
419 struct NaClClosure9
*self
= malloc(sizeof *self
);
421 NaClLog(LOG_FATAL
, "No memory in NaClClosure9 ctor\n");
423 self
->base
.vtbl
= &kNaClClosure9Vtbl
;
437 void NaClClosure9Dtor(struct NaClClosure
*vself
)
439 struct NaClClosure9
*self
= (struct NaClClosure9
*) vself
;
443 void NaClClosure9Run(struct NaClClosure
*vself
)
445 struct NaClClosure9
*self
= (struct NaClClosure9
*) vself
;
446 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
,
447 self
->arg5
, self
->arg6
, self
->arg7
, self
->arg8
,
449 NaClClosure9Dtor(vself
);
452 static struct NaClClosureVtbl
const kNaClClosure10Vtbl
= {
457 struct NaClClosure10
*NaClClosure10Ctor(void (*fn
)(void *, void *,
473 struct NaClClosure10
*self
= malloc(sizeof *self
);
475 NaClLog(LOG_FATAL
, "No memory in NaClClosure10 ctor\n");
477 self
->base
.vtbl
= &kNaClClosure10Vtbl
;
492 void NaClClosure10Dtor(struct NaClClosure
*vself
)
494 struct NaClClosure10
*self
= (struct NaClClosure10
*) vself
;
498 void NaClClosure10Run(struct NaClClosure
*vself
)
500 struct NaClClosure10
*self
= (struct NaClClosure10
*) vself
;
501 (*self
->fn
)(self
->arg1
, self
->arg2
, self
->arg3
, self
->arg4
,
502 self
->arg5
, self
->arg6
, self
->arg7
, self
->arg8
,
503 self
->arg9
, self
->arg10
);
504 NaClClosure10Dtor(vself
);