Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 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 | { |
Russ Cox | 15b76ad | 2014-09-09 13:39:57 -0400 | [diff] [blame] | 24 | uintptr stacklo; |
| 25 | uintptr stackhi; |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /* |
Russ Cox | f8d49b5 | 2013-02-28 16:24:38 -0500 | [diff] [blame] | 29 | * Arguments to the _cgo_thread_start call. |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 30 | * Also known to ../pkg/runtime/runtime.h. |
| 31 | */ |
| 32 | typedef struct ThreadStart ThreadStart; |
| 33 | struct ThreadStart |
| 34 | { |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 35 | G *g; |
Dmitriy Vyukov | 8a3c587 | 2014-01-22 10:30:10 +0400 | [diff] [blame] | 36 | uintptr *tls; |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 37 | void (*fn)(void); |
| 38 | }; |
| 39 | |
| 40 | /* |
| 41 | * Called by 5c/6c/8c world. |
| 42 | * Makes a local copy of the ThreadStart and |
Russ Cox | f8d49b5 | 2013-02-28 16:24:38 -0500 | [diff] [blame] | 43 | * calls _cgo_sys_thread_start(ts). |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 44 | */ |
Russ Cox | f8d49b5 | 2013-02-28 16:24:38 -0500 | [diff] [blame] | 45 | extern void (*_cgo_thread_start)(ThreadStart *ts); |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Creates the new operating system thread (OS, arch dependent). |
| 49 | */ |
Russ Cox | f8d49b5 | 2013-02-28 16:24:38 -0500 | [diff] [blame] | 50 | void _cgo_sys_thread_start(ThreadStart *ts); |
Russ Cox | b07b04d | 2010-12-08 14:10:00 -0500 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Call fn in the 6c world. |
| 54 | */ |
| 55 | void crosscall_amd64(void (*fn)(void)); |
| 56 | |
| 57 | /* |
| 58 | * Call fn in the 8c world. |
| 59 | */ |
| 60 | void crosscall_386(void (*fn)(void)); |
David Crawshaw | 72faffb | 2014-07-03 21:04:48 -0400 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Prints error then calls abort. For linux and android. |
| 64 | */ |
| 65 | void fatalf(const char* format, ...); |
David Crawshaw | 1b49a86 | 2015-03-08 11:37:02 -0400 | [diff] [blame^] | 66 | |
| 67 | /* |
| 68 | * Registers the current mach thread port for EXC_BAD_ACCESS processing. |
| 69 | */ |
| 70 | void darwin_arm_init_thread_exception_port(void); |
| 71 | |
| 72 | /* |
| 73 | * Starts a mach message server processing EXC_BAD_ACCESS. |
| 74 | */ |
| 75 | void darwin_arm_init_mach_exception_handler(void); |