Home | History | Annotate | Download | only in cgo
      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 <stdint.h>
      6 #include <stdlib.h>
      7 #include <stdio.h>
      8 
      9 #define nil ((void*)0)
     10 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
     11 
     12 typedef uint32_t uint32;
     13 typedef uint64_t uint64;
     14 typedef uintptr_t uintptr;
     15 
     16 /*
     17  * The beginning of the per-goroutine structure,
     18  * as defined in ../pkg/runtime/runtime.h.
     19  * Just enough to edit these two fields.
     20  */
     21 typedef struct G G;
     22 struct G
     23 {
     24 	uintptr stacklo;
     25 	uintptr stackhi;
     26 };
     27 
     28 /*
     29  * Arguments to the _cgo_thread_start call.
     30  * Also known to ../pkg/runtime/runtime.h.
     31  */
     32 typedef struct ThreadStart ThreadStart;
     33 struct ThreadStart
     34 {
     35 	G *g;
     36 	uintptr *tls;
     37 	void (*fn)(void);
     38 };
     39 
     40 /*
     41  * Called by 5c/6c/8c world.
     42  * Makes a local copy of the ThreadStart and
     43  * calls _cgo_sys_thread_start(ts).
     44  */
     45 extern void (*_cgo_thread_start)(ThreadStart *ts);
     46 
     47 /*
     48  * Creates a new operating system thread without updating any Go state
     49  * (OS dependent).
     50  */
     51 extern void (*_cgo_sys_thread_create)(void* (*func)(void*), void* arg);
     52 
     53 /*
     54  * Creates the new operating system thread (OS, arch dependent).
     55  */
     56 void _cgo_sys_thread_start(ThreadStart *ts);
     57 
     58 /*
     59  * Waits for the Go runtime to be initialized (OS dependent).
     60  */
     61 void _cgo_wait_runtime_init_done();
     62 
     63 /*
     64  * Call fn in the 6c world.
     65  */
     66 void crosscall_amd64(void (*fn)(void));
     67 
     68 /*
     69  * Call fn in the 8c world.
     70  */
     71 void crosscall_386(void (*fn)(void));
     72 
     73 /*
     74  * Prints error then calls abort. For linux and android.
     75  */
     76 void fatalf(const char* format, ...);
     77 
     78 /*
     79  * Registers the current mach thread port for EXC_BAD_ACCESS processing.
     80  */
     81 void darwin_arm_init_thread_exception_port(void);
     82 
     83 /*
     84  * Starts a mach message server processing EXC_BAD_ACCESS.
     85  */
     86 void darwin_arm_init_mach_exception_handler(void);
     87