blob: 6d4f23e29b2ee7b49de918e5de11a14fcc5a6142 [file] [log] [blame]
Russ Coxb07b04d2010-12-08 14:10:00 -05001// 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
12typedef uint32_t uint32;
13typedef uint64_t uint64;
14typedef 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 */
21typedef struct G G;
22struct G
23{
Russ Cox15b76ad2014-09-09 13:39:57 -040024 uintptr stacklo;
25 uintptr stackhi;
Russ Coxb07b04d2010-12-08 14:10:00 -050026};
27
28/*
Russ Coxf8d49b52013-02-28 16:24:38 -050029 * Arguments to the _cgo_thread_start call.
Russ Coxb07b04d2010-12-08 14:10:00 -050030 * Also known to ../pkg/runtime/runtime.h.
31 */
32typedef struct ThreadStart ThreadStart;
33struct ThreadStart
34{
Russ Coxb07b04d2010-12-08 14:10:00 -050035 G *g;
Dmitriy Vyukov8a3c5872014-01-22 10:30:10 +040036 uintptr *tls;
Russ Coxb07b04d2010-12-08 14:10:00 -050037 void (*fn)(void);
38};
39
40/*
41 * Called by 5c/6c/8c world.
42 * Makes a local copy of the ThreadStart and
Russ Coxf8d49b52013-02-28 16:24:38 -050043 * calls _cgo_sys_thread_start(ts).
Russ Coxb07b04d2010-12-08 14:10:00 -050044 */
Russ Coxf8d49b52013-02-28 16:24:38 -050045extern void (*_cgo_thread_start)(ThreadStart *ts);
Russ Coxb07b04d2010-12-08 14:10:00 -050046
47/*
48 * Creates the new operating system thread (OS, arch dependent).
49 */
Russ Coxf8d49b52013-02-28 16:24:38 -050050void _cgo_sys_thread_start(ThreadStart *ts);
Russ Coxb07b04d2010-12-08 14:10:00 -050051
52/*
53 * Call fn in the 6c world.
54 */
55void crosscall_amd64(void (*fn)(void));
56
57/*
58 * Call fn in the 8c world.
59 */
60void crosscall_386(void (*fn)(void));
David Crawshaw72faffb2014-07-03 21:04:48 -040061
62/*
63 * Prints error then calls abort. For linux and android.
64 */
65void fatalf(const char* format, ...);
David Crawshaw1b49a862015-03-08 11:37:02 -040066
67/*
68 * Registers the current mach thread port for EXC_BAD_ACCESS processing.
69 */
70void darwin_arm_init_thread_exception_port(void);
71
72/*
73 * Starts a mach message server processing EXC_BAD_ACCESS.
74 */
75void darwin_arm_init_mach_exception_handler(void);