blob: c04693899fd7f9f32bba61b7d1725772c7d44733 [file] [log] [blame]
Ken Thompsonbbb20732008-06-05 19:38:39 -07001// 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
Ken Thompsonbbb20732008-06-05 19:38:39 -07005/*
6 * basic types
7 */
8typedef signed char int8;
9typedef unsigned char uint8;
10typedef signed short int16;
11typedef unsigned short uint16;
12typedef signed int int32;
13typedef unsigned int uint32;
14typedef signed long long int int64;
15typedef unsigned long long int uint64;
16typedef float float32;
17typedef double float64;
Russ Cox0d3a0432009-03-30 00:01:07 -070018
19#ifdef _64BIT
Russ Cox75647d22008-11-17 12:32:35 -080020typedef uint64 uintptr;
Devon H. O'Dell659780b2009-11-18 09:11:39 -080021typedef int64 intptr;
Russ Cox0d3a0432009-03-30 00:01:07 -070022#else
23typedef uint32 uintptr;
Devon H. O'Dell659780b2009-11-18 09:11:39 -080024typedef int32 intptr;
Russ Cox0d3a0432009-03-30 00:01:07 -070025#endif
Ken Thompsonbbb20732008-06-05 19:38:39 -070026
27/*
28 * get rid of C types
Russ Cox3aa063d2008-11-23 17:08:55 -080029 * the / / / forces a syntax error immediately,
30 * which will show "last name: XXunsigned".
Ken Thompsonbbb20732008-06-05 19:38:39 -070031 */
Russ Cox3aa063d2008-11-23 17:08:55 -080032#define unsigned XXunsigned / / /
33#define signed XXsigned / / /
34#define char XXchar / / /
35#define short XXshort / / /
36#define int XXint / / /
37#define long XXlong / / /
38#define float XXfloat / / /
39#define double XXdouble / / /
Ken Thompsonbbb20732008-06-05 19:38:39 -070040
41/*
42 * defined types
43 */
44typedef uint8 bool;
45typedef uint8 byte;
Ken Thompson594175d2008-07-13 14:29:46 -070046typedef struct Alg Alg;
Russ Cox3aa063d2008-11-23 17:08:55 -080047typedef struct Func Func;
48typedef struct G G;
49typedef struct Gobuf Gobuf;
Russ Coxd28acc42008-08-04 16:43:49 -070050typedef struct Lock Lock;
Russ Cox3aa063d2008-11-23 17:08:55 -080051typedef struct M M;
Russ Coxd28acc42008-08-04 16:43:49 -070052typedef struct Mem Mem;
Russ Cox3aa063d2008-11-23 17:08:55 -080053typedef union Note Note;
Rob Pike87f22082009-08-25 15:54:25 -070054typedef struct Slice Slice;
Russ Cox3aa063d2008-11-23 17:08:55 -080055typedef struct Stktop Stktop;
Ken Thompson36570612009-04-09 18:16:21 -070056typedef struct String String;
Russ Cox3aa063d2008-11-23 17:08:55 -080057typedef struct Usema Usema;
Russ Coxc3077f72008-12-19 17:11:54 -080058typedef struct SigTab SigTab;
59typedef struct MCache MCache;
60typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070061typedef struct Itab Itab;
Ken Thompsonf59cb492010-02-19 20:42:50 -080062typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070063typedef struct Type Type;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080064typedef struct Defer Defer;
Russ Cox764b6ec2009-07-08 13:55:57 -070065typedef struct hash Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070066typedef struct Hchan Hchan;
Ken Thompsonf59cb492010-02-19 20:42:50 -080067typedef struct Complex64 Complex64;
68typedef struct Complex128 Complex128;
Ken Thompson594175d2008-07-13 14:29:46 -070069
70/*
Rob Piked08f0062009-08-11 13:30:35 -070071 * per-cpu declaration.
72 * "extern register" is a special storage class implemented by 6c, 8c, etc.
73 * on machines with lots of registers, it allocates a register that will not be
74 * used in generated code. on the x86, it allocates a slot indexed by a
75 * segment register.
76 *
77 * amd64: allocated downwards from R15
78 * x86: allocated upwards from 0(FS)
Kai Backmanebf32c52010-02-06 21:59:46 -080079 * arm: allocated downwards from R10
Russ Cox653cef12009-08-26 10:47:18 -070080 *
Rob Piked08f0062009-08-11 13:30:35 -070081 * every C file linked into a Go program must include runtime.h
82 * so that the C compiler knows to avoid other uses of these registers.
83 * the Go compilers know to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -070084 */
Rob Piked08f0062009-08-11 13:30:35 -070085extern register G* g;
86extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -070087
88/*
89 * defined constants
90 */
91enum
92{
93 // G status
94 Gidle,
95 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -070096 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -080097 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -070098 Gwaiting,
Russ Cox96824002008-08-05 14:18:47 -070099 Gmoribund,
Ken Thompson594175d2008-07-13 14:29:46 -0700100 Gdead,
101};
102enum
103{
104 true = 1,
105 false = 0,
106};
107
108/*
109 * structures
110 */
Russ Coxd28acc42008-08-04 16:43:49 -0700111struct Lock
112{
113 uint32 key;
Hector Chu6bfe5f52010-01-06 17:58:55 -0800114#ifdef __MINGW__
115 void* event;
116#else
Russ Cox376898c2008-09-09 11:50:14 -0700117 uint32 sema; // for OS X
Hector Chu6bfe5f52010-01-06 17:58:55 -0800118#endif
Russ Coxd28acc42008-08-04 16:43:49 -0700119};
Russ Cox5ff12f82008-09-24 10:25:28 -0700120struct Usema
121{
122 uint32 u;
123 uint32 k;
124};
Russ Cox376898c2008-09-09 11:50:14 -0700125union Note
Russ Coxd28acc42008-08-04 16:43:49 -0700126{
Russ Cox376898c2008-09-09 11:50:14 -0700127 struct { // Linux
128 Lock lock;
129 };
130 struct { // OS X
131 int32 wakeup;
Russ Cox5ff12f82008-09-24 10:25:28 -0700132 Usema sema;
Russ Cox376898c2008-09-09 11:50:14 -0700133 };
Russ Coxd28acc42008-08-04 16:43:49 -0700134};
Ken Thompson594175d2008-07-13 14:29:46 -0700135struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700136{
Ken Thompson36570612009-04-09 18:16:21 -0700137 byte* str;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700138 int32 len;
Ken Thompson594175d2008-07-13 14:29:46 -0700139};
Russ Coxc3077f72008-12-19 17:11:54 -0800140struct Iface
141{
Russ Coxc7513ea2009-07-07 11:02:54 -0700142 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700143 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800144};
Russ Cox2da50222009-05-20 14:57:55 -0700145struct Eface
146{
Russ Coxc7513ea2009-07-07 11:02:54 -0700147 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700148 void* data;
149};
Ken Thompsonf59cb492010-02-19 20:42:50 -0800150struct Complex64
151{
152 float32 real;
153 float32 imag;
154};
155struct Complex128
156{
157 float64 real;
158 float64 imag;
159};
Ken Thompson66a603c2008-08-27 17:28:30 -0700160
Rob Pike87f22082009-08-25 15:54:25 -0700161struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700162{ // must not move anything
163 byte* array; // actual data
Rob Pike87f22082009-08-25 15:54:25 -0700164 uint32 len; // number of elements
Russ Cox75647d22008-11-17 12:32:35 -0800165 uint32 cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700166};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700167struct Gobuf
168{
Russ Cox38020092009-06-17 16:31:02 -0700169 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700170 byte* sp;
171 byte* pc;
172 G* g;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700173};
Ken Thompson7b454bb2008-07-09 11:35:26 -0700174struct G
Ken Thompson45288542008-07-08 17:19:17 -0700175{
Russ Cox133a1582009-10-03 10:37:12 -0700176 byte* stackguard; // cannot move - also known to linker, libmach, libcgo
177 byte* stackbase; // cannot move - also known to libmach, libcgo
Russ Cox7343e032009-06-17 15:12:16 -0700178 Defer* defer;
Russ Cox38020092009-06-17 16:31:02 -0700179 Gobuf sched; // cannot move - also known to libmach
Russ Cox133a1582009-10-03 10:37:12 -0700180 byte* stack0;
Russ Cox7343e032009-06-17 15:12:16 -0700181 byte* entry; // initial function
Rob Pike3835e012008-07-28 11:29:41 -0700182 G* alllink; // on allg
Ken Thompsone963cba2008-07-25 15:55:12 -0700183 void* param; // passed parameter on wakeup
184 int16 status;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700185 int32 goid;
Adam Langley50d6c812009-12-18 12:25:53 -0800186 uint32 selgen; // valid sudog pointer
Russ Cox96824002008-08-05 14:18:47 -0700187 G* schedlink;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800188 bool readyonstop;
Russ Cox7343e032009-06-17 15:12:16 -0700189 M* m; // for debuggers, but offset not hard-coded
Russ Cox218c3932009-07-13 17:28:39 -0700190 M* lockedm;
Russ Cox133a1582009-10-03 10:37:12 -0700191 void (*cgofn)(void*); // for cgo/ffi
192 void *cgoarg;
Russ Coxd28acc42008-08-04 16:43:49 -0700193};
Ken Thompson45288542008-07-08 17:19:17 -0700194struct M
195{
Russ Cox38020092009-06-17 16:31:02 -0700196 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700197 G* g0; // goroutine with scheduling stack
198 void (*morepc)(void);
Russ Coxbba278a2009-07-08 18:16:09 -0700199 void* morefp; // frame pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700200 Gobuf morebuf; // gobuf arg to morestack
201
Russ Cox38020092009-06-17 16:31:02 -0700202 // Fields not known to debuggers.
Russ Cox7343e032009-06-17 15:12:16 -0700203 uint32 moreframe; // size arguments to morestack
204 uint32 moreargs;
205 uintptr cret; // return value from C
206 uint64 procid; // for debuggers, but offset not hard-coded
207 G* gsignal; // signal-handling G
208 uint32 tls[8]; // thread-local storage (for 386 extern register)
209 Gobuf sched; // scheduling stack
210 G* curg; // current running goroutine
Russ Coxefc86a72008-11-25 16:48:10 -0800211 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800212 int32 mallocing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700213 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800214 int32 locks;
Russ Cox218c3932009-07-13 17:28:39 -0700215 int32 waitnextg;
Russ Cox96824002008-08-05 14:18:47 -0700216 Note havenextg;
217 G* nextg;
Russ Cox93689d82009-10-09 15:35:33 -0700218 M* alllink; // on allm
Russ Cox96824002008-08-05 14:18:47 -0700219 M* schedlink;
Russ Cox376898c2008-09-09 11:50:14 -0700220 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800221 MCache *mcache;
Russ Cox218c3932009-07-13 17:28:39 -0700222 G* lockedg;
Hector Chu6bfe5f52010-01-06 17:58:55 -0800223#ifdef __MINGW__
224 void* return_address; // saved return address and stack
225 void* stack_pointer; // pointer for Windows stdcall
226 void* os_stack_pointer;
227#endif
Ken Thompson751ce3a2008-07-11 19:16:39 -0700228};
Ken Thompson52620032008-07-14 14:33:39 -0700229struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700230{
Russ Cox38020092009-06-17 16:31:02 -0700231 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700232 uint8* stackguard;
233 uint8* stackbase;
234 Gobuf gobuf;
235 uint32 args;
Russ Coxbba278a2009-07-08 18:16:09 -0700236
237 // Frame pointer: where args start in old frame.
238 // fp == gobuf.sp except in the case of a reflected
239 // function call, which uses an off-stack argument frame.
240 uint8* fp;
Ken Thompson45288542008-07-08 17:19:17 -0700241};
Ken Thompson594175d2008-07-13 14:29:46 -0700242struct Alg
Ken Thompson751ce3a2008-07-11 19:16:39 -0700243{
Russ Coxa52fb812009-06-04 21:09:06 -0700244 uintptr (*hash)(uint32, void*);
Ken Thompson594175d2008-07-13 14:29:46 -0700245 uint32 (*equal)(uint32, void*, void*);
246 void (*print)(uint32, void*);
247 void (*copy)(uint32, void*, void*);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700248};
Ken Thompson594175d2008-07-13 14:29:46 -0700249struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700250{
Russ Coxdfa58932008-12-03 14:21:28 -0800251 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700252 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700253};
Russ Coxdfa58932008-12-03 14:21:28 -0800254enum
255{
256 SigCatch = 1<<0,
257 SigIgnore = 1<<1,
258 SigRestart = 1<<2,
David Symondsb5866492009-12-15 18:21:29 -0800259 SigQueue = 1<<3,
Russ Coxdfa58932008-12-03 14:21:28 -0800260};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700261
Russ Cox3aa063d2008-11-23 17:08:55 -0800262// (will be) shared with go; edit ../cmd/6g/sys.go too.
263// should move out of sys.go eventually.
264// also eventually, the loaded symbol table should
265// be closer to this form.
266struct Func
267{
Ken Thompson36570612009-04-09 18:16:21 -0700268 String name;
269 String type; // go type string
270 String src; // src file name
Russ Coxa5433362008-11-25 09:23:36 -0800271 uint64 entry; // entry pc
272 int64 frame; // stack frame size
Rob Pike87f22082009-08-25 15:54:25 -0700273 Slice pcln; // pc/ln tab for this func
Russ Coxa5433362008-11-25 09:23:36 -0800274 int64 pc0; // starting pc, ln for table
275 int32 ln0;
Russ Coxefc86a72008-11-25 16:48:10 -0800276 int32 args; // number of 32-bit in/out args
277 int32 locals; // number of 32-bit locals
Russ Cox3aa063d2008-11-23 17:08:55 -0800278};
279
Ken Thompsonbbb20732008-06-05 19:38:39 -0700280/*
281 * defined macros
282 * you need super-goru privilege
283 * to add this list.
284 */
285#define nelem(x) (sizeof(x)/sizeof((x)[0]))
286#define nil ((void*)0)
287
288/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800289 * known to compiler
290 */
291enum
292{
Russ Coxa7f6d402009-01-26 09:56:42 -0800293 AMEM,
294 ANOEQ,
Russ Coxeee50ae2008-12-19 12:05:22 -0800295 ASTRING,
Russ Coxeee50ae2008-12-19 12:05:22 -0800296 AINTER,
Russ Cox2da50222009-05-20 14:57:55 -0700297 ANILINTER,
Russ Cox9b6d3852009-01-26 12:36:21 -0800298 AFAKE,
Russ Coxa7f6d402009-01-26 09:56:42 -0800299 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800300};
301
Russ Cox29aa3ff2009-07-02 21:25:46 -0700302
303enum {
304 Structrnd = sizeof(uintptr)
305};
306
Russ Coxeee50ae2008-12-19 12:05:22 -0800307/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800308 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800309 */
310struct Defer
311{
312 int32 siz;
313 byte* sp;
314 byte* fn;
315 Defer* link;
316 byte args[8]; // padded to actual size
317};
318
319/*
Ken Thompson594175d2008-07-13 14:29:46 -0700320 * external data
321 */
Russ Coxa7f6d402009-01-26 09:56:42 -0800322extern Alg algarray[Amax];
Ken Thompson36570612009-04-09 18:16:21 -0700323extern String emptystring;
Ken Thompson594175d2008-07-13 14:29:46 -0700324G* allg;
Russ Cox93689d82009-10-09 15:35:33 -0700325M* allm;
Ken Thompson594175d2008-07-13 14:29:46 -0700326int32 goidgen;
Russ Coxd28acc42008-08-04 16:43:49 -0700327extern int32 gomaxprocs;
Rob Pike6e8dbc22008-09-12 09:44:41 -0700328extern int32 panicking;
Ken Thompson79fbbe32008-11-05 21:50:28 -0800329extern int32 maxround;
Rob Pikef6d67c92009-10-13 22:48:03 -0700330extern int32 fd; // usually 1; set to 2 when panicking
Russ Cox5328df62010-01-09 09:47:45 -0800331extern int32 gcwaiting; // gc is waiting to run
Russ Cox1b14bdb2009-09-22 16:28:32 -0700332int8* goos;
Ken Thompson594175d2008-07-13 14:29:46 -0700333
334/*
Rob Pike8e82a672008-06-30 11:50:36 -0700335 * common functions and data
336 */
Ken Thompson751ce3a2008-07-11 19:16:39 -0700337int32 strcmp(byte*, byte*);
Russ Cox3aa063d2008-11-23 17:08:55 -0800338int32 findnull(byte*);
Hector Chu6bfe5f52010-01-06 17:58:55 -0800339int32 findnullw(uint16*);
Rob Pike8e82a672008-06-30 11:50:36 -0700340void dump(byte*, int32);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700341int32 runetochar(byte*, int32);
Rob Pike54ec7192009-04-12 17:01:17 -0700342int32 charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700343
Rob Pike8e82a672008-06-30 11:50:36 -0700344/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700345 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700346 */
Russ Cox7343e032009-06-17 15:12:16 -0700347void gogo(Gobuf*, uintptr);
348void gogocall(Gobuf*, void(*)(void));
349uintptr gosave(Gobuf*);
Russ Cox718be322010-01-25 18:52:55 -0800350void ·lessstack(void);
Russ Cox36096242009-01-16 14:58:14 -0800351void goargs(void);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700352void FLUSH(void*);
Rob Piked3204ef2008-06-30 14:39:47 -0700353void* getu(void);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700354void throw(int8*);
Ken Thompson594175d2008-07-13 14:29:46 -0700355uint32 rnd(uint32, uint32);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700356void prints(int8*);
Russ Coxefc86a72008-11-25 16:48:10 -0800357void printf(int8*, ...);
Russ Cox3aa063d2008-11-23 17:08:55 -0800358byte* mchr(byte*, byte, byte*);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700359void mcpy(byte*, byte*, uint32);
Russ Cox9b6d3852009-01-26 12:36:21 -0800360int32 mcmp(byte*, byte*, uint32);
Russ Cox652f5562009-11-20 09:11:46 -0800361void memmove(void*, void*, uint32);
Russ Cox596c16e2010-03-23 20:48:23 -0700362void* mal(uintptr);
363void* malx(uintptr size, int32 skip_delta);
Ken Thompson36570612009-04-09 18:16:21 -0700364uint32 cmpstring(String, String);
365String gostring(byte*);
Hector Chu6bfe5f52010-01-06 17:58:55 -0800366String gostringw(uint16*);
Rob Pikeaeb43982008-06-21 15:36:23 -0700367void initsig(void);
Russ Coxfb40f882008-09-22 13:47:53 -0700368int32 gotraceback(void);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700369void traceback(uint8 *pc, uint8 *sp, G* gp);
Rob Pike3835e012008-07-28 11:29:41 -0700370void tracebackothers(G*);
Rob Pikec870ac22008-07-14 20:54:55 -0700371int32 open(byte*, int32, ...);
Rob Pikec870ac22008-07-14 20:54:55 -0700372int32 write(int32, void*, int32);
Russ Coxd28acc42008-08-04 16:43:49 -0700373bool cas(uint32*, uint32, uint32);
Hector Chu6bfe5f52010-01-06 17:58:55 -0800374bool casp(void**, void*, void*);
375uint32 xadd(uint32 volatile*, int32);
Russ Coxaa3222d82009-06-02 23:02:12 -0700376void jmpdefer(byte*, void*);
Russ Coxd28acc42008-08-04 16:43:49 -0700377void exit1(int32);
378void ready(G*);
379byte* getenv(int8*);
380int32 atoi(byte*);
Russ Cox96824002008-08-05 14:18:47 -0700381void newosproc(M *m, G *g, void *stk, void (*fn)(void));
Russ Coxa67258f2008-09-18 15:56:46 -0700382void signalstack(byte*, int32);
383G* malg(int32);
384void minit(void);
Russ Cox0d3a0432009-03-30 00:01:07 -0700385Func* findfunc(uintptr);
Russ Coxa5433362008-11-25 09:23:36 -0800386int32 funcline(Func*, uint64);
Russ Cox79e1db22008-12-04 08:30:54 -0800387void* stackalloc(uint32);
388void stackfree(void*);
Russ Coxe29ce172008-12-18 15:42:28 -0800389MCache* allocmcache(void);
390void mallocinit(void);
Russ Coxa7f6d402009-01-26 09:56:42 -0800391bool ifaceeq(Iface, Iface);
Russ Cox2da50222009-05-20 14:57:55 -0700392bool efaceeq(Eface, Eface);
Russ Coxa52fb812009-06-04 21:09:06 -0700393uintptr ifacehash(Iface);
394uintptr efacehash(Eface);
395uintptr nohash(uint32, void*);
Russ Coxa7f6d402009-01-26 09:56:42 -0800396uint32 noequal(uint32, void*, void*);
Russ Cox1ce17912009-01-26 17:37:05 -0800397void* malloc(uintptr size);
Russ Cox1ce17912009-01-26 17:37:05 -0800398void free(void *v);
Russ Cox62d627f2010-02-08 21:41:54 -0800399void addfinalizer(void*, void(*fn)(void*), int32);
Russ Cox918afd942009-05-08 15:21:41 -0700400void exit(int32);
401void breakpoint(void);
402void gosched(void);
403void goexit(void);
Russ Cox133a1582009-10-03 10:37:12 -0700404void runcgo(void (*fn)(void*), void*);
Russ Cox718be322010-01-25 18:52:55 -0800405void ·entersyscall(void);
406void ·exitsyscall(void);
Russ Cox62d627f2010-02-08 21:41:54 -0800407void newproc1(byte*, byte*, int32, int32);
David Symondsb5866492009-12-15 18:21:29 -0800408void siginit(void);
Russ Cox08579c22009-12-16 20:20:50 -0800409bool sigsend(int32 sig);
Russ Coxe4f06812010-02-08 14:32:22 -0800410void gettime(int64*, int32*);
Russ Cox2b7d1472010-03-23 17:01:17 -0700411int32 callers(int32, uintptr*, int32);
Russ Coxe4f06812010-02-08 14:32:22 -0800412int64 nanotime(void);
Russ Coxd28acc42008-08-04 16:43:49 -0700413
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800414#pragma varargck argpos printf 1
415
416#pragma varargck type "d" int32
417#pragma varargck type "d" uint32
418#pragma varargck type "D" int64
419#pragma varargck type "D" uint64
420#pragma varargck type "x" int32
421#pragma varargck type "x" uint32
422#pragma varargck type "X" int64
423#pragma varargck type "X" uint64
424#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700425#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800426#pragma varargck type "s" int8*
427#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700428#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800429
Russ Cox3f8aa662008-12-05 15:24:18 -0800430// TODO(rsc): Remove. These are only temporary,
431// for the mark and sweep collector.
432void stoptheworld(void);
433void starttheworld(void);
434
Russ Coxd28acc42008-08-04 16:43:49 -0700435/*
436 * mutual exclusion locks. in the uncontended case,
437 * as fast as spin locks (just a few user-level instructions),
438 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700439 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700440 */
441void lock(Lock*);
442void unlock(Lock*);
Russ Cox62d627f2010-02-08 21:41:54 -0800443void destroylock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700444
445/*
Russ Coxa68592a2009-10-14 13:02:05 -0700446 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700447 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700448 * must call noteclear to initialize the Note.
449 * then, any number of threads can call notesleep
450 * and exactly one thread can call notewakeup (once).
451 * once notewakeup has been called, all the notesleeps
452 * will return. future notesleeps will return immediately.
Russ Coxd28acc42008-08-04 16:43:49 -0700453 */
Russ Cox96824002008-08-05 14:18:47 -0700454void noteclear(Note*);
455void notesleep(Note*);
456void notewakeup(Note*);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700457
458/*
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800459 * Redefine methods for the benefit of gcc, which does not support
460 * UTF-8 characters in identifiers.
461 */
462#ifndef __GNUC__
Russ Cox718be322010-01-25 18:52:55 -0800463#define runtime_memclr ·memclr
464#define runtime_getcallerpc ·getcallerpc
465#define runtime_mmap ·mmap
466#define runtime_printslice ·printslice
467#define runtime_printbool ·printbool
468#define runtime_printfloat ·printfloat
469#define runtime_printhex ·printhex
470#define runtime_printint ·printint
471#define runtime_printiface ·printiface
472#define runtime_printeface ·printeface
473#define runtime_printpc ·printpc
474#define runtime_printpointer ·printpointer
475#define runtime_printstring ·printstring
476#define runtime_printuint ·printuint
Ken Thompsonf59cb492010-02-19 20:42:50 -0800477#define runtime_printcomplex ·printcomplex
Russ Cox718be322010-01-25 18:52:55 -0800478#define runtime_setcallerpc ·setcallerpc
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800479#endif
480
481/*
Adam Langley3f7a3242009-11-13 10:08:51 -0800482 * This is consistent across Linux and BSD.
483 * If a new OS is added that is different, move this to
484 * $GOOS/$GOARCH/defs.h.
485 */
486#define EACCES 13
487
488/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800489 * low level go-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700490 */
Russ Cox22a5c782009-10-15 23:10:49 -0700491uint8* runtime_mmap(byte*, uint32, int32, int32, int32, uint32);
492void runtime_memclr(byte*, uint32);
493void runtime_setcallerpc(void*, void*);
494void* runtime_getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700495
496/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700497 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700498 */
Russ Cox22a5c782009-10-15 23:10:49 -0700499void runtime_printbool(bool);
500void runtime_printfloat(float64);
501void runtime_printint(int64);
502void runtime_printiface(Iface);
503void runtime_printeface(Eface);
504void runtime_printstring(String);
505void runtime_printpc(void*);
506void runtime_printpointer(void*);
507void runtime_printuint(uint64);
508void runtime_printhex(uint64);
509void runtime_printslice(Slice);
Ken Thompsonf59cb492010-02-19 20:42:50 -0800510void runtime_printcomplex(Complex128);
Russ Coxa186b772010-01-27 15:37:08 -0800511void ·panicl(int32);
Rob Pike6db99de2008-07-08 10:36:43 -0700512
513/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800514 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -0700515 */
Russ Cox1f8a40d2009-01-22 16:23:44 -0800516float64 Inf(int32 sign);
517float64 NaN(void);
518float32 float32frombits(uint32 i);
519uint32 float32tobits(float32 f);
520float64 float64frombits(uint64 i);
521uint64 float64tobits(float64 f);
522float64 frexp(float64 d, int32 *ep);
523bool isInf(float64 f, int32 sign);
524bool isNaN(float64 f);
525float64 ldexp(float64 d, int32 e);
526float64 modf(float64 d, float64 *ip);
527void semacquire(uint32*);
528void semrelease(uint32*);
David Symondsb5866492009-12-15 18:21:29 -0800529String signame(int32 sig);
530
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700531
Russ Cox764b6ec2009-07-08 13:55:57 -0700532void mapassign(Hmap*, byte*, byte*);
533void mapaccess(Hmap*, byte*, byte*, bool*);
534struct hash_iter* mapiterinit(Hmap*);
535void mapiternext(struct hash_iter*);
536bool mapiterkey(struct hash_iter*, void*);
537void mapiterkeyvalue(struct hash_iter*, void*, void*);
Russ Cox7a0f4ca2009-09-08 13:46:54 -0700538Hmap* makemap(Type*, Type*, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700539
Russ Cox7a0f4ca2009-09-08 13:46:54 -0700540Hchan* makechan(Type*, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700541void chansend(Hchan*, void*, bool*);
542void chanrecv(Hchan*, void*, bool*);
Russ Cox653cef12009-08-26 10:47:18 -0700543void chanclose(Hchan*);
544bool chanclosed(Hchan*);
Russ Coxde7920e2009-08-26 12:42:22 -0700545int32 chanlen(Hchan*);
546int32 chancap(Hchan*);
Russ Cox92e92572009-07-10 16:32:26 -0700547
548void ifaceE2I(struct InterfaceType*, Eface, Iface*);