blob: 9d96521f53ffceaa42af0503e1e1bcb4fc8b7357 (
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
|
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "libcgo.h"
/* Stub for calling malloc from Go */
static void
x_cgo_malloc(void *p)
{
struct a {
long long n;
void *ret;
} *a = p;
a->ret = malloc(a->n);
}
void (*_cgo_malloc)(void*) = x_cgo_malloc;
/* Stub for calling from Go */
static void
x_cgo_free(void *p)
{
struct a {
void *arg;
} *a = p;
free(a->arg);
}
void (*_cgo_free)(void*) = x_cgo_free;
/* Stub for creating a new thread */
static void
xlibcgo_thread_start(ThreadStart *arg)
{
ThreadStart *ts;
/* Make our own copy that can persist after we return. */
ts = malloc(sizeof *ts);
if(ts == nil) {
fprintf(stderr, "runtime/cgo: out of memory in thread_start\n");
abort();
}
*ts = *arg;
libcgo_sys_thread_start(ts); /* OS-dependent half */
}
void (*libcgo_thread_start)(ThreadStart*) = xlibcgo_thread_start;
|