github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/runtime/cgo/gcc_util.c (about)

     1  // Copyright 2009 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "libcgo.h"
     6  
     7  /* Stub for calling malloc from Go */
     8  void
     9  x_cgo_malloc(void *p)
    10  {
    11  	struct a {
    12  		long long n;
    13  		void *ret;
    14  	} *a = p;
    15  
    16  	a->ret = malloc(a->n);
    17  }
    18  
    19  /* Stub for calling free from Go */
    20  void
    21  x_cgo_free(void *p)
    22  {
    23  	struct a {
    24  		void *arg;
    25  	} *a = p;
    26  
    27  	free(a->arg);
    28  }
    29  
    30  /* Stub for creating a new thread */
    31  void
    32  x_cgo_thread_start(ThreadStart *arg)
    33  {
    34  	ThreadStart *ts;
    35  
    36  	/* Make our own copy that can persist after we return. */
    37  	ts = malloc(sizeof *ts);
    38  	if(ts == nil) {
    39  		fprintf(stderr, "runtime/cgo: out of memory in thread_start\n");
    40  		abort();
    41  	}
    42  	*ts = *arg;
    43  
    44  	_cgo_sys_thread_start(ts);	/* OS-dependent half */
    45  }