blob: 187a827a02e2e9e9b6e96fd1d958d323b607b27b [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 Cox10ea6512012-09-24 20:57:01 -040022typedef int64 intgo; // Go's int
23typedef uint64 uintgo; // Go's uint
Russ Cox0d3a0432009-03-30 00:01:07 -070024#else
25typedef uint32 uintptr;
Russ Cox0b08c942012-09-24 14:58:34 -040026typedef int32 intptr;
27typedef int32 intgo; // Go's int
28typedef uint32 uintgo; // Go's uint
Russ Cox0d3a0432009-03-30 00:01:07 -070029#endif
Ken Thompsonbbb20732008-06-05 19:38:39 -070030
31/*
32 * get rid of C types
Russ Cox3aa063d2008-11-23 17:08:55 -080033 * the / / / forces a syntax error immediately,
34 * which will show "last name: XXunsigned".
Ken Thompsonbbb20732008-06-05 19:38:39 -070035 */
Russ Cox3aa063d2008-11-23 17:08:55 -080036#define unsigned XXunsigned / / /
37#define signed XXsigned / / /
38#define char XXchar / / /
39#define short XXshort / / /
40#define int XXint / / /
41#define long XXlong / / /
42#define float XXfloat / / /
43#define double XXdouble / / /
Ken Thompsonbbb20732008-06-05 19:38:39 -070044
45/*
46 * defined types
47 */
48typedef uint8 bool;
49typedef uint8 byte;
Russ Cox3aa063d2008-11-23 17:08:55 -080050typedef struct Func Func;
51typedef struct G G;
52typedef struct Gobuf Gobuf;
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +030053typedef union Lock Lock;
Russ Cox3aa063d2008-11-23 17:08:55 -080054typedef struct M M;
Russ Coxd28acc42008-08-04 16:43:49 -070055typedef struct Mem Mem;
Russ Cox3aa063d2008-11-23 17:08:55 -080056typedef union Note Note;
Rob Pike87f22082009-08-25 15:54:25 -070057typedef struct Slice Slice;
Russ Cox3aa063d2008-11-23 17:08:55 -080058typedef struct Stktop Stktop;
Ken Thompson36570612009-04-09 18:16:21 -070059typedef struct String String;
Russ Coxc3077f72008-12-19 17:11:54 -080060typedef struct SigTab SigTab;
61typedef struct MCache MCache;
Russ Coxd324f212011-09-30 09:40:01 -040062typedef struct FixAlloc FixAlloc;
Russ Coxc3077f72008-12-19 17:11:54 -080063typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070064typedef struct Itab Itab;
Jan Ziak5c1422a2012-11-01 13:13:20 -040065typedef struct InterfaceType InterfaceType;
Ken Thompsonf59cb492010-02-19 20:42:50 -080066typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070067typedef struct Type Type;
Russ Cox3770b0e2011-08-17 15:54:17 -040068typedef struct ChanType ChanType;
Russ Cox65bde082011-08-17 14:56:27 -040069typedef struct MapType MapType;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080070typedef struct Defer Defer;
Russ Cox0de71612012-12-22 14:54:39 -050071typedef struct DeferChunk DeferChunk;
Russ Cox9b1507b2010-03-31 11:46:01 -070072typedef struct Panic Panic;
Luuk van Dijk7400be82011-01-31 12:27:28 +010073typedef struct Hmap Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070074typedef struct Hchan Hchan;
Ken Thompsonf59cb492010-02-19 20:42:50 -080075typedef struct Complex64 Complex64;
76typedef struct Complex128 Complex128;
Alex Brainman2a808822011-08-27 23:17:00 +100077typedef struct WinCall WinCall;
Alex Brainmanafe0e972012-05-30 15:10:54 +100078typedef struct SEH SEH;
Russ Cox3b860262011-11-09 15:17:05 -050079typedef struct Timers Timers;
80typedef struct Timer Timer;
Dmitriy Vyukovd839a802012-04-05 20:48:28 +040081typedef struct GCStats GCStats;
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +040082typedef struct LFNode LFNode;
Dmitriy Vyukov95643642012-05-11 10:50:03 +040083typedef struct ParFor ParFor;
84typedef struct ParForThread ParForThread;
Ian Lance Taylore9a30872012-11-10 11:19:06 -080085typedef struct CgoMal CgoMal;
Ken Thompson594175d2008-07-13 14:29:46 -070086
87/*
Nigel Tao90ad6a22012-10-19 11:02:32 +110088 * Per-CPU declaration.
89 *
Rob Piked08f0062009-08-11 13:30:35 -070090 * "extern register" is a special storage class implemented by 6c, 8c, etc.
Nigel Tao90ad6a22012-10-19 11:02:32 +110091 * On the ARM, it is an actual register; elsewhere it is a slot in thread-
92 * local storage indexed by a segment register. See zasmhdr in
93 * src/cmd/dist/buildruntime.c for details, and be aware that the linker may
94 * make further OS-specific changes to the compiler's output. For example,
95 * 6l/linux rewrites 0(GS) as -16(FS).
Rob Piked08f0062009-08-11 13:30:35 -070096 *
Nigel Tao90ad6a22012-10-19 11:02:32 +110097 * Every C file linked into a Go program must include runtime.h so that the
98 * C compiler (6c, 8c, etc.) knows to avoid other uses of these dedicated
99 * registers. The Go compiler (6g, 8g, etc.) knows to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -0700100 */
Rob Piked08f0062009-08-11 13:30:35 -0700101extern register G* g;
102extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -0700103
104/*
105 * defined constants
106 */
107enum
108{
109 // G status
Russ Cox72157c32010-04-08 13:24:53 -0700110 //
111 // If you add to this list, add to the list
112 // of "okay during garbage collection" status
113 // in mgc0.c too.
Ken Thompson594175d2008-07-13 14:29:46 -0700114 Gidle,
115 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -0700116 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -0800117 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -0700118 Gwaiting,
Russ Cox96824002008-08-05 14:18:47 -0700119 Gmoribund,
Ken Thompson594175d2008-07-13 14:29:46 -0700120 Gdead,
121};
122enum
123{
124 true = 1,
125 false = 0,
126};
Jan Ziak54193682012-09-17 17:18:21 -0400127enum
128{
129 PtrSize = sizeof(void*),
130};
Dmitriy Vyukovf82db7d2013-01-10 09:57:06 +0400131enum
132{
133 // Per-M stack segment cache size.
134 StackCacheSize = 32,
135 // Global <-> per-M stack segment cache transfer batch size.
136 StackCacheBatch = 16,
137};
Ken Thompson594175d2008-07-13 14:29:46 -0700138
139/*
140 * structures
141 */
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300142union Lock
Russ Coxd28acc42008-08-04 16:43:49 -0700143{
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300144 uint32 key; // futex-based impl
145 M* waitm; // linked list of waiting M's (sema-based impl)
Russ Cox5ff12f82008-09-24 10:25:28 -0700146};
Russ Cox376898c2008-09-09 11:50:14 -0700147union Note
Russ Coxd28acc42008-08-04 16:43:49 -0700148{
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300149 uint32 key; // futex-based impl
150 M* waitm; // waiting M (sema-based impl)
Russ Coxd28acc42008-08-04 16:43:49 -0700151};
Ken Thompson594175d2008-07-13 14:29:46 -0700152struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700153{
Ken Thompson36570612009-04-09 18:16:21 -0700154 byte* str;
Russ Cox0b08c942012-09-24 14:58:34 -0400155 intgo len;
Ken Thompson594175d2008-07-13 14:29:46 -0700156};
Russ Coxc3077f72008-12-19 17:11:54 -0800157struct Iface
158{
Russ Coxc7513ea2009-07-07 11:02:54 -0700159 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700160 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800161};
Russ Cox2da50222009-05-20 14:57:55 -0700162struct Eface
163{
Russ Coxc7513ea2009-07-07 11:02:54 -0700164 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700165 void* data;
166};
Ken Thompsonf59cb492010-02-19 20:42:50 -0800167struct Complex64
168{
169 float32 real;
170 float32 imag;
171};
172struct Complex128
173{
174 float64 real;
175 float64 imag;
176};
Ken Thompson66a603c2008-08-27 17:28:30 -0700177
Rob Pike87f22082009-08-25 15:54:25 -0700178struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700179{ // must not move anything
180 byte* array; // actual data
Russ Cox0b08c942012-09-24 14:58:34 -0400181 uintgo len; // number of elements
182 uintgo cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700183};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700184struct Gobuf
185{
Russ Cox38020092009-06-17 16:31:02 -0700186 // The offsets of these fields are known to (hard-coded in) libmach.
Jan Ziak334bf952012-05-30 13:07:52 -0400187 uintptr sp;
Russ Cox7343e032009-06-17 15:12:16 -0700188 byte* pc;
189 G* g;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700190};
Dmitriy Vyukovd839a802012-04-05 20:48:28 +0400191struct GCStats
192{
193 // the struct must consist of only uint64's,
194 // because it is casted to uint64[].
195 uint64 nhandoff;
196 uint64 nhandoffcnt;
197 uint64 nprocyield;
198 uint64 nosyield;
199 uint64 nsleep;
200};
Ken Thompson7b454bb2008-07-09 11:35:26 -0700201struct G
Ken Thompson45288542008-07-08 17:19:17 -0700202{
Jan Ziak334bf952012-05-30 13:07:52 -0400203 uintptr stackguard; // cannot move - also known to linker, libmach, runtime/cgo
204 uintptr stackbase; // cannot move - also known to libmach, runtime/cgo
Russ Cox7343e032009-06-17 15:12:16 -0700205 Defer* defer;
Russ Cox9b1507b2010-03-31 11:46:01 -0700206 Panic* panic;
207 Gobuf sched;
Jan Ziak334bf952012-05-30 13:07:52 -0400208 uintptr gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
209 uintptr gcsp; // if status==Gsyscall, gcsp = sched.sp to use during gc
210 uintptr gcguard; // if status==Gsyscall, gcguard = stackguard to use during gc
211 uintptr stack0;
Russ Cox7343e032009-06-17 15:12:16 -0700212 byte* entry; // initial function
Rob Pike3835e012008-07-28 11:29:41 -0700213 G* alllink; // on allg
Ken Thompsone963cba2008-07-25 15:55:12 -0700214 void* param; // passed parameter on wakeup
215 int16 status;
Dmitriy Vyukov320df442012-10-26 10:13:06 +0400216 int64 goid;
Adam Langley50d6c812009-12-18 12:25:53 -0800217 uint32 selgen; // valid sudog pointer
Russ Cox03e9ea52011-08-22 23:26:39 -0400218 int8* waitreason; // if status==Gwaiting
Russ Cox96824002008-08-05 14:18:47 -0700219 G* schedlink;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800220 bool readyonstop;
Russ Cox9b1507b2010-03-31 11:46:01 -0700221 bool ispanic;
Dmitriy Vyukov81221f52013-01-29 14:57:11 +0400222 bool issystem;
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400223 int8 raceignore; // ignore race detection events
Russ Cox7343e032009-06-17 15:12:16 -0700224 M* m; // for debuggers, but offset not hard-coded
Russ Cox218c3932009-07-13 17:28:39 -0700225 M* lockedm;
Russ Cox582fd172011-02-27 23:32:42 -0500226 M* idlem;
Russ Cox5963dba2010-04-08 18:15:30 -0700227 int32 sig;
Russ Coxe4b02bf2012-02-22 21:45:01 -0500228 int32 writenbuf;
229 byte* writebuf;
Russ Cox0de71612012-12-22 14:54:39 -0500230 DeferChunk *dchunk;
231 DeferChunk *dchunknext;
Russ Cox5963dba2010-04-08 18:15:30 -0700232 uintptr sigcode0;
233 uintptr sigcode1;
Russ Cox12307002011-01-18 14:15:11 -0500234 uintptr sigpc;
Russ Cox324cc3d02011-03-02 13:42:02 -0500235 uintptr gopc; // pc of go statement that created this goroutine
Hector Chu9fd26872011-09-17 17:57:59 +1000236 uintptr end[];
Russ Coxd28acc42008-08-04 16:43:49 -0700237};
Ken Thompson45288542008-07-08 17:19:17 -0700238struct M
239{
Russ Cox38020092009-06-17 16:31:02 -0700240 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700241 G* g0; // goroutine with scheduling stack
242 void (*morepc)(void);
Russ Cox141a4a12011-01-14 14:05:20 -0500243 void* moreargp; // argument pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700244 Gobuf morebuf; // gobuf arg to morestack
245
Russ Cox38020092009-06-17 16:31:02 -0700246 // Fields not known to debuggers.
Russ Cox141a4a12011-01-14 14:05:20 -0500247 uint32 moreframesize; // size arguments to morestack
248 uint32 moreargsize;
Russ Cox7343e032009-06-17 15:12:16 -0700249 uintptr cret; // return value from C
250 uint64 procid; // for debuggers, but offset not hard-coded
251 G* gsignal; // signal-handling G
252 uint32 tls[8]; // thread-local storage (for 386 extern register)
Russ Cox7343e032009-06-17 15:12:16 -0700253 G* curg; // current running goroutine
Russ Coxefc86a72008-11-25 16:48:10 -0800254 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800255 int32 mallocing;
Dmitriy Vyukov81221f52013-01-29 14:57:11 +0400256 int32 throwing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700257 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800258 int32 locks;
Russ Cox6eb251f2010-03-24 09:40:09 -0700259 int32 nomemprof;
Russ Cox218c3932009-07-13 17:28:39 -0700260 int32 waitnextg;
Russ Cox67793502011-02-16 13:21:13 -0500261 int32 dying;
Russ Coxc19b3732011-03-23 11:43:37 -0400262 int32 profilehz;
Russ Coxd324f212011-09-30 09:40:01 -0400263 int32 helpgc;
Dmitriy Vyukov909f3182011-07-12 01:23:58 -0400264 uint32 fastrand;
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800265 uint64 ncgocall; // number of cgo calls in total
266 int32 ncgo; // number of cgo calls currently in progress
267 CgoMal* cgomal;
Russ Cox96824002008-08-05 14:18:47 -0700268 Note havenextg;
269 G* nextg;
Russ Cox93689d82009-10-09 15:35:33 -0700270 M* alllink; // on allm
Russ Cox96824002008-08-05 14:18:47 -0700271 M* schedlink;
Russ Cox376898c2008-09-09 11:50:14 -0700272 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800273 MCache *mcache;
Dmitriy Vyukovf82db7d2013-01-10 09:57:06 +0400274 int32 stackinuse;
275 uint32 stackcachepos;
276 uint32 stackcachecnt;
277 void* stackcache[StackCacheSize];
Russ Cox218c3932009-07-13 17:28:39 -0700278 G* lockedg;
Russ Cox582fd172011-02-27 23:32:42 -0500279 G* idleg;
Russ Cox5b93fc92012-02-08 10:33:54 -0500280 uintptr createstack[32]; // Stack that created this thread.
Ken Thompsonae605262010-12-09 14:45:27 -0800281 uint32 freglo[16]; // D[i] lsb and F[i]
282 uint32 freghi[16]; // D[i] msb and F[i+16]
283 uint32 fflag; // floating point compare flags
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300284 M* nextwaitm; // next M waiting for lock
285 uintptr waitsema; // semaphore for parking on locks
286 uint32 waitsemacount;
287 uint32 waitsemalock;
Dmitriy Vyukovd839a802012-04-05 20:48:28 +0400288 GCStats gcstats;
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400289 bool racecall;
290 void* racepc;
Jan Ziak51b8edc2012-11-27 13:04:59 -0500291 uint32 moreframesize_minalloc;
Russ Cox3b860262011-11-09 15:17:05 -0500292
Jan Ziakf8c58372012-09-24 20:08:05 -0400293 uintptr settype_buf[1024];
294 uintptr settype_bufsize;
295
Russ Cox851f3012011-12-16 15:33:58 -0500296#ifdef GOOS_windows
Hector Chu9fd26872011-09-17 17:57:59 +1000297 void* thread; // thread handle
Hector Chu5c303252011-09-14 20:23:21 -0400298#endif
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800299#ifdef GOOS_plan9
300 int8* notesig;
301#endif
Alex Brainmanafe0e972012-05-30 15:10:54 +1000302 SEH* seh;
Hector Chu9fd26872011-09-17 17:57:59 +1000303 uintptr end[];
Ken Thompson751ce3a2008-07-11 19:16:39 -0700304};
Russ Cox370276a2011-04-27 23:21:12 -0400305
Ken Thompson52620032008-07-14 14:33:39 -0700306struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700307{
Russ Cox38020092009-06-17 16:31:02 -0700308 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700309 uint8* stackguard;
310 uint8* stackbase;
311 Gobuf gobuf;
Russ Cox141a4a12011-01-14 14:05:20 -0500312 uint32 argsize;
Russ Coxbba278a2009-07-08 18:16:09 -0700313
Russ Coxafc69282011-01-25 16:35:36 -0500314 uint8* argp; // pointer to arguments in old frame
315 uintptr free; // if free>0, call stackfree using free as size
Russ Cox9b1507b2010-03-31 11:46:01 -0700316 bool panic; // is this frame the top of a panic?
Ken Thompson45288542008-07-08 17:19:17 -0700317};
Ken Thompson594175d2008-07-13 14:29:46 -0700318struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700319{
Russ Coxdfa58932008-12-03 14:21:28 -0800320 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700321 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700322};
Russ Coxdfa58932008-12-03 14:21:28 -0800323enum
324{
Russ Cox35586f72012-02-13 13:52:37 -0500325 SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel
David Symonds3d8ebef2012-02-17 14:36:40 +1100326 SigKill = 1<<1, // if signal.Notify doesn't take it, exit quietly
327 SigThrow = 1<<2, // if signal.Notify doesn't take it, exit loudly
328 SigPanic = 1<<3, // if the signal is from the kernel, panic
329 SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
Russ Coxdfa58932008-12-03 14:21:28 -0800330};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700331
Russ Cox6eb251f2010-03-24 09:40:09 -0700332// NOTE(rsc): keep in sync with extern.go:/type.Func.
333// Eventually, the loaded symbol table should be closer to this form.
Russ Cox3aa063d2008-11-23 17:08:55 -0800334struct Func
335{
Ken Thompson36570612009-04-09 18:16:21 -0700336 String name;
337 String type; // go type string
338 String src; // src file name
Rob Pike87f22082009-08-25 15:54:25 -0700339 Slice pcln; // pc/ln tab for this func
Russ Cox6eb251f2010-03-24 09:40:09 -0700340 uintptr entry; // entry pc
341 uintptr pc0; // starting pc, ln for table
Russ Coxa5433362008-11-25 09:23:36 -0800342 int32 ln0;
Russ Cox6eb251f2010-03-24 09:40:09 -0700343 int32 frame; // stack frame size
Russ Coxefc86a72008-11-25 16:48:10 -0800344 int32 args; // number of 32-bit in/out args
345 int32 locals; // number of 32-bit locals
Russ Cox3aa063d2008-11-23 17:08:55 -0800346};
347
Jan Ziak5c1422a2012-11-01 13:13:20 -0400348// layout of Itab known to compilers
349struct Itab
350{
351 InterfaceType* inter;
352 Type* type;
353 Itab* link;
354 int32 bad;
355 int32 unused;
356 void (*fun[])(void);
357};
358
Alex Brainman2a808822011-08-27 23:17:00 +1000359struct WinCall
360{
361 void (*fn)(void*);
362 uintptr n; // number of parameters
363 void* args; // parameters
Alex Brainman74063792011-09-14 16:19:45 +1000364 uintptr r1; // return values
365 uintptr r2;
Alex Brainman2a808822011-08-27 23:17:00 +1000366 uintptr err; // error number
367};
Alex Brainmanafe0e972012-05-30 15:10:54 +1000368struct SEH
369{
370 void* prev;
371 void* handler;
372};
Alex Brainman2a808822011-08-27 23:17:00 +1000373
Russ Cox851f3012011-12-16 15:33:58 -0500374#ifdef GOOS_windows
Alex Brainmanf95a2f22010-09-12 11:45:16 +1000375enum {
376 Windows = 1
377};
378#else
379enum {
380 Windows = 0
381};
382#endif
383
Russ Cox3b860262011-11-09 15:17:05 -0500384struct Timers
385{
386 Lock;
387 G *timerproc;
388 bool sleeping;
389 bool rescheduling;
390 Note waitnote;
391 Timer **t;
392 int32 len;
393 int32 cap;
394};
395
396// Package time knows the layout of this structure.
397// If this struct changes, adjust ../time/sleep.go:/runtimeTimer.
398struct Timer
399{
400 int32 i; // heap index
401
402 // Timer wakes up at when, and then at when+period, ... (period > 0 only)
403 // each time calling f(now, arg) in the timer goroutine, so f must be
404 // a well-behaved function and not block.
405 int64 when;
406 int64 period;
407 void (*f)(int64, Eface);
408 Eface arg;
409};
410
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +0400411// Lock-free stack node.
412struct LFNode
413{
414 LFNode *next;
415 uintptr pushcnt;
416};
417
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400418// Parallel for descriptor.
419struct ParFor
420{
421 void (*body)(ParFor*, uint32); // executed for each element
422 uint32 done; // number of idle threads
423 uint32 nthr; // total number of threads
424 uint32 nthrmax; // maximum number of threads
425 uint32 thrseq; // thread id sequencer
426 uint32 cnt; // iteration space [0, cnt)
427 void *ctx; // arbitrary user context
428 bool wait; // if true, wait while all threads finish processing,
429 // otherwise parfor may return while other threads are still working
430 ParForThread *thr; // array of thread descriptors
431 // stats
432 uint64 nsteal;
433 uint64 nstealcnt;
434 uint64 nprocyield;
435 uint64 nosyield;
436 uint64 nsleep;
437};
438
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800439// Track memory allocated by code not written in Go during a cgo call,
440// so that the garbage collector can see them.
441struct CgoMal
442{
443 CgoMal *next;
444 byte *alloc;
445};
446
Ken Thompsonbbb20732008-06-05 19:38:39 -0700447/*
448 * defined macros
Robert Hencke3fbd4782011-05-30 18:02:59 +1000449 * you need super-gopher-guru privilege
Ken Thompsonbbb20732008-06-05 19:38:39 -0700450 * to add this list.
451 */
452#define nelem(x) (sizeof(x)/sizeof((x)[0]))
453#define nil ((void*)0)
Russ Coxdc9a3b22010-12-13 16:22:19 -0500454#define offsetof(s,m) (uint32)(&(((s*)0)->m))
Russ Cox6dbaa202012-05-29 14:02:29 -0400455#define ROUND(x, n) (((x)+(n)-1)&~((n)-1)) /* all-caps to mark as macro: it evaluates n twice */
Ken Thompsonbbb20732008-06-05 19:38:39 -0700456
457/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800458 * known to compiler
459 */
Russ Coxb9ccd072011-12-05 09:40:22 -0500460enum {
461 Structrnd = sizeof(uintptr)
462};
463
464/*
465 * type algorithms - known to compiler
466 */
Russ Coxeee50ae2008-12-19 12:05:22 -0800467enum
468{
Russ Coxa7f6d402009-01-26 09:56:42 -0800469 AMEM,
Dmitriy Vyukov1ff14052012-01-20 10:32:55 +0400470 AMEM0,
Dmitriy Vyukov54e94062011-08-08 09:35:32 -0400471 AMEM8,
472 AMEM16,
473 AMEM32,
474 AMEM64,
475 AMEM128,
Russ Cox196b6632011-12-12 22:22:09 -0500476 ANOEQ,
Dmitriy Vyukov1ff14052012-01-20 10:32:55 +0400477 ANOEQ0,
Dmitriy Vyukov54e94062011-08-08 09:35:32 -0400478 ANOEQ8,
479 ANOEQ16,
480 ANOEQ32,
481 ANOEQ64,
482 ANOEQ128,
Russ Cox196b6632011-12-12 22:22:09 -0500483 ASTRING,
484 AINTER,
485 ANILINTER,
486 ASLICE,
Russ Cox408f0b12012-01-26 16:25:07 -0500487 AFLOAT32,
488 AFLOAT64,
489 ACPLX64,
490 ACPLX128,
Russ Coxa7f6d402009-01-26 09:56:42 -0800491 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800492};
Russ Coxb9ccd072011-12-05 09:40:22 -0500493typedef struct Alg Alg;
494struct Alg
495{
496 void (*hash)(uintptr*, uintptr, void*);
497 void (*equal)(bool*, uintptr, void*, void*);
498 void (*print)(uintptr, void*);
499 void (*copy)(uintptr, void*, void*);
Russ Cox29aa3ff2009-07-02 21:25:46 -0700500};
501
Russ Coxb9ccd072011-12-05 09:40:22 -0500502extern Alg runtime·algarray[Amax];
503
504void runtime·memhash(uintptr*, uintptr, void*);
505void runtime·nohash(uintptr*, uintptr, void*);
506void runtime·strhash(uintptr*, uintptr, void*);
507void runtime·interhash(uintptr*, uintptr, void*);
508void runtime·nilinterhash(uintptr*, uintptr, void*);
509
510void runtime·memequal(bool*, uintptr, void*, void*);
511void runtime·noequal(bool*, uintptr, void*, void*);
512void runtime·strequal(bool*, uintptr, void*, void*);
513void runtime·interequal(bool*, uintptr, void*, void*);
514void runtime·nilinterequal(bool*, uintptr, void*, void*);
515
516void runtime·memprint(uintptr, void*);
517void runtime·strprint(uintptr, void*);
518void runtime·interprint(uintptr, void*);
519void runtime·nilinterprint(uintptr, void*);
520
521void runtime·memcopy(uintptr, void*, void*);
522void runtime·memcopy8(uintptr, void*, void*);
523void runtime·memcopy16(uintptr, void*, void*);
524void runtime·memcopy32(uintptr, void*, void*);
525void runtime·memcopy64(uintptr, void*, void*);
526void runtime·memcopy128(uintptr, void*, void*);
527void runtime·memcopy(uintptr, void*, void*);
528void runtime·strcopy(uintptr, void*, void*);
529void runtime·algslicecopy(uintptr, void*, void*);
530void runtime·intercopy(uintptr, void*, void*);
531void runtime·nilintercopy(uintptr, void*, void*);
532
Russ Coxeee50ae2008-12-19 12:05:22 -0800533/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800534 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800535 */
536struct Defer
537{
538 int32 siz;
Russ Cox0de71612012-12-22 14:54:39 -0500539 bool special; // not part of defer frame
540 bool free; // if special, free when done
Russ Cox141a4a12011-01-14 14:05:20 -0500541 byte* argp; // where args were copied from
Russ Cox9b1507b2010-03-31 11:46:01 -0700542 byte* pc;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800543 byte* fn;
544 Defer* link;
Jan Ziak334bf952012-05-30 13:07:52 -0400545 void* args[1]; // padded to actual size
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800546};
547
Russ Cox0de71612012-12-22 14:54:39 -0500548struct DeferChunk
549{
550 DeferChunk *prev;
551 uintptr off;
552};
553
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800554/*
Russ Cox9b1507b2010-03-31 11:46:01 -0700555 * panics
556 */
557struct Panic
558{
559 Eface arg; // argument to panic
560 byte* stackbase; // g->stackbase in panic
561 Panic* link; // link to earlier panic
562 bool recovered; // whether this panic is over
563};
564
565/*
Ken Thompson594175d2008-07-13 14:29:46 -0700566 * external data
567 */
Russ Cox68b42552010-11-04 14:00:19 -0400568extern String runtime·emptystring;
Jan Ziak4a191c22012-10-21 17:41:32 -0400569extern uintptr runtime·zerobase;
Shenghou Ma4019d0e2013-01-26 09:57:06 +0800570extern G* runtime·allg;
571extern G* runtime·lastg;
572extern M* runtime·allm;
Russ Cox68b42552010-11-04 14:00:19 -0400573extern int32 runtime·gomaxprocs;
Dmitriy Vyukova2677cf2011-08-16 16:53:02 -0400574extern bool runtime·singleproc;
Russ Cox67793502011-02-16 13:21:13 -0500575extern uint32 runtime·panicking;
Russ Cox68b42552010-11-04 14:00:19 -0400576extern int32 runtime·gcwaiting; // gc is waiting to run
Shenghou Ma4019d0e2013-01-26 09:57:06 +0800577extern int8* runtime·goos;
578extern int32 runtime·ncpu;
Russ Cox9042c2c2010-12-08 13:53:30 -0500579extern bool runtime·iscgo;
Russ Cox0b08c942012-09-24 14:58:34 -0400580extern void (*runtime·sysargs)(int32, uint8**);
581extern uint32 runtime·maxstring;
Ken Thompson594175d2008-07-13 14:29:46 -0700582
583/*
Rob Pike8e82a672008-06-30 11:50:36 -0700584 * common functions and data
585 */
Russ Cox68b42552010-11-04 14:00:19 -0400586int32 runtime·strcmp(byte*, byte*);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400587byte* runtime·strstr(byte*, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400588int32 runtime·findnull(byte*);
Alex Brainmana41d8542011-01-12 11:48:15 +1100589int32 runtime·findnullw(uint16*);
Russ Cox68b42552010-11-04 14:00:19 -0400590void runtime·dump(byte*, int32);
591int32 runtime·runetochar(byte*, int32);
592int32 runtime·charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700593
Rob Pike8e82a672008-06-30 11:50:36 -0700594/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700595 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700596 */
Russ Cox68b42552010-11-04 14:00:19 -0400597#define FLUSH(x) USED(x)
Russ Cox4e28cfe2010-03-26 14:15:30 -0700598
Russ Cox68b42552010-11-04 14:00:19 -0400599void runtime·gogo(Gobuf*, uintptr);
600void runtime·gogocall(Gobuf*, void(*)(void));
Russ Coxf9ca3b52011-03-07 10:37:42 -0500601void runtime·gosave(Gobuf*);
Russ Cox68b42552010-11-04 14:00:19 -0400602void runtime·lessstack(void);
603void runtime·goargs(void);
Alex Brainmana41d8542011-01-12 11:48:15 +1100604void runtime·goenvs(void);
605void runtime·goenvs_unix(void);
Russ Cox68b42552010-11-04 14:00:19 -0400606void* runtime·getu(void);
607void runtime·throw(int8*);
608void runtime·panicstring(int8*);
Russ Cox68b42552010-11-04 14:00:19 -0400609void runtime·prints(int8*);
610void runtime·printf(int8*, ...);
611byte* runtime·mchr(byte*, byte, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400612int32 runtime·mcmp(byte*, byte*, uint32);
613void runtime·memmove(void*, void*, uint32);
614void* runtime·mal(uintptr);
615String runtime·catstring(String, String);
616String runtime·gostring(byte*);
Russ Cox0b08c942012-09-24 14:58:34 -0400617String runtime·gostringn(byte*, intgo);
618Slice runtime·gobytes(byte*, intgo);
Russ Cox68b42552010-11-04 14:00:19 -0400619String runtime·gostringnocopy(byte*);
Alex Brainmana41d8542011-01-12 11:48:15 +1100620String runtime·gostringw(uint16*);
Russ Cox35586f72012-02-13 13:52:37 -0500621void runtime·initsig(void);
David Symonds3d8ebef2012-02-17 14:36:40 +1100622void runtime·sigenable(uint32 sig);
Russ Cox68b42552010-11-04 14:00:19 -0400623int32 runtime·gotraceback(void);
Russ Cox03e9ea52011-08-22 23:26:39 -0400624void runtime·goroutineheader(G*);
Russ Cox68b42552010-11-04 14:00:19 -0400625void runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp);
626void runtime·tracebackothers(G*);
627int32 runtime·write(int32, void*, int32);
Jonathan Markddde52a2011-06-07 21:50:10 -0700628int32 runtime·mincore(void*, uintptr, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400629bool runtime·cas(uint32*, uint32, uint32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400630bool runtime·cas64(uint64*, uint64*, uint64);
Russ Cox68b42552010-11-04 14:00:19 -0400631bool runtime·casp(void**, void*, void*);
Dmitriy Vyukov997c00f2011-06-28 15:09:53 -0400632// Don't confuse with XADD x86 instruction,
633// this one is actually 'addx', that is, add-and-fetch.
Russ Cox68b42552010-11-04 14:00:19 -0400634uint32 runtime·xadd(uint32 volatile*, int32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400635uint64 runtime·xadd64(uint64 volatile*, int64);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400636uint32 runtime·xchg(uint32 volatile*, uint32);
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700637uint32 runtime·atomicload(uint32 volatile*);
Dmitriy Vyukov91f0f182011-07-29 13:47:24 -0400638void runtime·atomicstore(uint32 volatile*, uint32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400639void runtime·atomicstore64(uint64 volatile*, uint64);
640uint64 runtime·atomicload64(uint64 volatile*);
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700641void* runtime·atomicloadp(void* volatile*);
642void runtime·atomicstorep(void* volatile*, void*);
Russ Cox68b42552010-11-04 14:00:19 -0400643void runtime·jmpdefer(byte*, void*);
644void runtime·exit1(int32);
645void runtime·ready(G*);
646byte* runtime·getenv(int8*);
647int32 runtime·atoi(byte*);
Jingcheng Zhang70e967b2012-12-19 00:30:29 +0800648void runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void));
Russ Cox68b42552010-11-04 14:00:19 -0400649void runtime·signalstack(byte*, int32);
650G* runtime·malg(int32);
Russ Cox1707a992012-02-14 01:23:15 -0500651void runtime·asminit(void);
Russ Cox68b42552010-11-04 14:00:19 -0400652void runtime·minit(void);
653Func* runtime·findfunc(uintptr);
Russ Coxb287d7c2011-02-02 16:44:20 -0500654int32 runtime·funcline(Func*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400655void* runtime·stackalloc(uint32);
Russ Coxafc69282011-01-25 16:35:36 -0500656void runtime·stackfree(void*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400657MCache* runtime·allocmcache(void);
Dmitriy Vyukoved516df2012-07-01 13:10:01 +0400658void runtime·freemcache(MCache*);
Russ Cox68b42552010-11-04 14:00:19 -0400659void runtime·mallocinit(void);
660bool runtime·ifaceeq_c(Iface, Iface);
661bool runtime·efaceeq_c(Eface, Eface);
Ian Lance Taylor63bee952013-01-04 07:53:42 -0800662uintptr runtime·ifacehash(Iface, uintptr);
663uintptr runtime·efacehash(Eface, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400664void* runtime·malloc(uintptr size);
665void runtime·free(void *v);
Russ Cox0b08c942012-09-24 14:58:34 -0400666bool runtime·addfinalizer(void*, void(*fn)(void*), uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400667void runtime·runpanic(Panic*);
668void* runtime·getcallersp(void*);
Russ Cox4608feb2011-01-28 15:03:26 -0500669int32 runtime·mcount(void);
Russ Coxe4b02bf2012-02-22 21:45:01 -0500670int32 runtime·gcount(void);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500671void runtime·mcall(void(*)(G*));
Dmitriy Vyukov909f3182011-07-12 01:23:58 -0400672uint32 runtime·fastrand1(void);
Russ Coxd28acc42008-08-04 16:43:49 -0700673
Russ Cox68b42552010-11-04 14:00:19 -0400674void runtime·exit(int32);
675void runtime·breakpoint(void);
676void runtime·gosched(void);
Dmitriy Vyukovf20fd872012-09-18 21:15:46 +0400677void runtime·park(void(*)(Lock*), Lock*, int8*);
678void runtime·tsleep(int64, int8*);
Russ Cox3b860262011-11-09 15:17:05 -0500679M* runtime·newm(void);
Russ Cox68b42552010-11-04 14:00:19 -0400680void runtime·goexit(void);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500681void runtime·asmcgocall(void (*fn)(void*), void*);
Russ Cox68b42552010-11-04 14:00:19 -0400682void runtime·entersyscall(void);
683void runtime·exitsyscall(void);
Russ Cox324cc3d02011-03-02 13:42:02 -0500684G* runtime·newproc1(byte*, byte*, int32, int32, void*);
Russ Cox68b42552010-11-04 14:00:19 -0400685bool runtime·sigsend(int32 sig);
Russ Cox68b42552010-11-04 14:00:19 -0400686int32 runtime·callers(int32, uintptr*, int32);
Russ Coxc19b3732011-03-23 11:43:37 -0400687int32 runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32);
Russ Cox68b42552010-11-04 14:00:19 -0400688int64 runtime·nanotime(void);
689void runtime·dopanic(int32);
Russ Cox67793502011-02-16 13:21:13 -0500690void runtime·startpanic(void);
Dmitriy Vyukova54f920b2012-07-04 14:52:51 +0400691void runtime·unwindstack(G*, byte*);
Russ Coxc19b3732011-03-23 11:43:37 -0400692void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
693void runtime·resetcpuprofiler(int32);
694void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
Russ Coxd324f212011-09-30 09:40:01 -0400695void runtime·usleep(uint32);
Damian Gryski8e765da2012-02-02 14:09:27 -0500696int64 runtime·cputicks(void);
Dmitriy Vyukov4cc7bf32012-10-06 12:56:04 +0400697int64 runtime·tickspersecond(void);
698void runtime·blockevent(int64, int32);
699extern int64 runtime·blockprofilerate;
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800700
Russ Cox68b42552010-11-04 14:00:19 -0400701#pragma varargck argpos runtime·printf 1
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800702#pragma varargck type "d" int32
703#pragma varargck type "d" uint32
704#pragma varargck type "D" int64
705#pragma varargck type "D" uint64
706#pragma varargck type "x" int32
707#pragma varargck type "x" uint32
708#pragma varargck type "X" int64
709#pragma varargck type "X" uint64
710#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700711#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800712#pragma varargck type "s" int8*
713#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700714#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800715
Russ Cox68b42552010-11-04 14:00:19 -0400716void runtime·stoptheworld(void);
Dmitriy Vyukov01826282012-05-15 19:10:16 +0400717void runtime·starttheworld(void);
Russ Coxe4b02bf2012-02-22 21:45:01 -0500718extern uint32 runtime·worldsema;
Russ Cox3f8aa662008-12-05 15:24:18 -0800719
Russ Coxd28acc42008-08-04 16:43:49 -0700720/*
721 * mutual exclusion locks. in the uncontended case,
722 * as fast as spin locks (just a few user-level instructions),
723 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700724 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700725 */
Russ Cox68b42552010-11-04 14:00:19 -0400726void runtime·lock(Lock*);
727void runtime·unlock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700728
729/*
Russ Coxa68592a2009-10-14 13:02:05 -0700730 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700731 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700732 * must call noteclear to initialize the Note.
Dmitriy Vyukova496c9e2011-08-03 15:51:55 -0400733 * then, exactly one thread can call notesleep
Russ Cox96824002008-08-05 14:18:47 -0700734 * and exactly one thread can call notewakeup (once).
Dmitriy Vyukova496c9e2011-08-03 15:51:55 -0400735 * once notewakeup has been called, the notesleep
736 * will return. future notesleep will return immediately.
737 * subsequent noteclear must be called only after
738 * previous notesleep has returned, e.g. it's disallowed
739 * to call noteclear straight after notewakeup.
Russ Cox3b860262011-11-09 15:17:05 -0500740 *
741 * notetsleep is like notesleep but wakes up after
742 * a given number of nanoseconds even if the event
743 * has not yet happened. if a goroutine uses notetsleep to
744 * wake up early, it must wait to call noteclear until it
745 * can be sure that no other goroutine is calling
746 * notewakeup.
Russ Coxd28acc42008-08-04 16:43:49 -0700747 */
Russ Cox68b42552010-11-04 14:00:19 -0400748void runtime·noteclear(Note*);
749void runtime·notesleep(Note*);
750void runtime·notewakeup(Note*);
Russ Cox3b860262011-11-09 15:17:05 -0500751void runtime·notetsleep(Note*, int64);
752
753/*
754 * low-level synchronization for implementing the above
755 */
756uintptr runtime·semacreate(void);
757int32 runtime·semasleep(int64);
758void runtime·semawakeup(M*);
759// or
760void runtime·futexsleep(uint32*, uint32, int64);
761void runtime·futexwakeup(uint32*, uint32);
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800762
763/*
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +0400764 * Lock-free stack.
765 * Initialize uint64 head to 0, compare with 0 to test for emptiness.
766 * The stack does not keep pointers to nodes,
767 * so they can be garbage collected if there are no other pointers to nodes.
768 */
769void runtime·lfstackpush(uint64 *head, LFNode *node);
770LFNode* runtime·lfstackpop(uint64 *head);
771
772/*
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400773 * Parallel for over [0, n).
774 * body() is executed for each iteration.
775 * nthr - total number of worker threads.
776 * ctx - arbitrary user context.
777 * if wait=true, threads return from parfor() when all work is done;
778 * otherwise, threads can return while other threads are still finishing processing.
779 */
780ParFor* runtime·parforalloc(uint32 nthrmax);
781void runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32));
782void runtime·parfordo(ParFor *desc);
783
784/*
Adam Langley3f7a3242009-11-13 10:08:51 -0800785 * This is consistent across Linux and BSD.
786 * If a new OS is added that is different, move this to
787 * $GOOS/$GOARCH/defs.h.
788 */
789#define EACCES 13
790
791/*
Russ Coxafc69282011-01-25 16:35:36 -0500792 * low level C-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700793 */
Shenghou Mab151af12012-09-21 13:50:02 +0800794// for mmap, we only pass the lower 32 bits of file offset to the
795// assembly routine; the higher bits (if required), should be provided
796// by the assembly routine as 0.
Russ Cox68b42552010-11-04 14:00:19 -0400797uint8* runtime·mmap(byte*, uintptr, int32, int32, int32, uint32);
Russ Coxe83cd7f2011-12-20 17:54:40 -0500798void runtime·munmap(byte*, uintptr);
799void runtime·madvise(byte*, uintptr, int32);
Russ Coxafc69282011-01-25 16:35:36 -0500800void runtime·memclr(byte*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400801void runtime·setcallerpc(void*, void*);
802void* runtime·getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700803
804/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700805 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700806 */
Russ Cox68b42552010-11-04 14:00:19 -0400807void runtime·printbool(bool);
808void runtime·printfloat(float64);
809void runtime·printint(int64);
810void runtime·printiface(Iface);
811void runtime·printeface(Eface);
812void runtime·printstring(String);
813void runtime·printpc(void*);
814void runtime·printpointer(void*);
815void runtime·printuint(uint64);
816void runtime·printhex(uint64);
817void runtime·printslice(Slice);
818void runtime·printcomplex(Complex128);
Russ Cox4e28cfe2010-03-26 14:15:30 -0700819void reflect·call(byte*, byte*, uint32);
Russ Cox68b42552010-11-04 14:00:19 -0400820void runtime·panic(Eface);
821void runtime·panicindex(void);
822void runtime·panicslice(void);
Russ Cox7c2b1592010-10-25 17:55:50 -0700823
Russ Cox63e878a2010-03-31 15:55:10 -0700824/*
825 * runtime c-called (but written in Go)
826 */
Russ Cox68b42552010-11-04 14:00:19 -0400827void runtime·printany(Eface);
Russ Cox6a75ece2012-02-12 23:26:20 -0500828void runtime·newTypeAssertionError(String*, String*, String*, String*, Eface*);
Russ Cox68b42552010-11-04 14:00:19 -0400829void runtime·newErrorString(String, Eface*);
830void runtime·fadd64c(uint64, uint64, uint64*);
831void runtime·fsub64c(uint64, uint64, uint64*);
832void runtime·fmul64c(uint64, uint64, uint64*);
833void runtime·fdiv64c(uint64, uint64, uint64*);
834void runtime·fneg64c(uint64, uint64*);
835void runtime·f32to64c(uint32, uint64*);
836void runtime·f64to32c(uint64, uint32*);
837void runtime·fcmp64c(uint64, uint64, int32*, bool*);
838void runtime·fintto64c(int64, uint64*);
839void runtime·f64tointc(uint64, int64*, bool*);
Rob Pike6db99de2008-07-08 10:36:43 -0700840
841/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800842 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -0700843 */
Russ Cox68b42552010-11-04 14:00:19 -0400844float64 runtime·Inf(int32 sign);
845float64 runtime·NaN(void);
846float32 runtime·float32frombits(uint32 i);
847uint32 runtime·float32tobits(float32 f);
848float64 runtime·float64frombits(uint64 i);
849uint64 runtime·float64tobits(float64 f);
850float64 runtime·frexp(float64 d, int32 *ep);
851bool runtime·isInf(float64 f, int32 sign);
852bool runtime·isNaN(float64 f);
853float64 runtime·ldexp(float64 d, int32 e);
854float64 runtime·modf(float64 d, float64 *ip);
855void runtime·semacquire(uint32*);
856void runtime·semrelease(uint32*);
Russ Cox68b42552010-11-04 14:00:19 -0400857int32 runtime·gomaxprocsfunc(int32 n);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400858void runtime·procyield(uint32);
859void runtime·osyield(void);
Russ Cox6808da02011-10-27 18:04:12 -0700860void runtime·LockOSThread(void);
861void runtime·UnlockOSThread(void);
David Symondsb5866492009-12-15 18:21:29 -0800862
Russ Cox65bde082011-08-17 14:56:27 -0400863void runtime·mapassign(MapType*, Hmap*, byte*, byte*);
864void runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*);
Russ Cox68b42552010-11-04 14:00:19 -0400865void runtime·mapiternext(struct hash_iter*);
866bool runtime·mapiterkey(struct hash_iter*, void*);
867void runtime·mapiterkeyvalue(struct hash_iter*, void*, void*);
Russ Cox65bde082011-08-17 14:56:27 -0400868Hmap* runtime·makemap_c(MapType*, int64);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700869
Russ Cox3770b0e2011-08-17 15:54:17 -0400870Hchan* runtime·makechan_c(ChanType*, int64);
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400871void runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*);
Russ Cox33e9d242011-08-23 13:13:27 -0400872void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
Dmitriy Vyukov81221f52013-01-29 14:57:11 +0400873bool runtime·showframe(Func*, bool);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700874
Jan Ziak5c1422a2012-11-01 13:13:20 -0400875void runtime·ifaceE2I(InterfaceType*, Eface, Iface*);
Russ Coxafc69282011-01-25 16:35:36 -0500876
Russ Cox102274a2012-02-24 15:28:51 -0500877uintptr runtime·memlimit(void);
Russ Cox6e2ae0a2012-02-28 16:18:24 -0500878
879// If appropriate, ask the operating system to control whether this
880// thread should receive profiling signals. This is only necessary on OS X.
881// An operating system should not deliver a profiling signal to a
882// thread that is not actually executing (what good is that?), but that's
883// what OS X prefers to do. When profiling is turned on, we mask
884// away the profiling signal when threads go to sleep, so that OS X
885// is forced to deliver the signal to a thread that's actually running.
886// This is a no-op on other systems.
887void runtime·setprof(bool);
Shenghou Ma0157c722012-08-07 23:45:50 +0800888
889// float.c
890extern float64 runtime·nan;
891extern float64 runtime·posinf;
892extern float64 runtime·neginf;
893extern uint64 ·nan;
894extern uint64 ·posinf;
895extern uint64 ·neginf;
896#define ISNAN(f) ((f) != (f))
Jan Ziakf8c58372012-09-24 20:08:05 -0400897
898enum
899{
900 UseSpanType = 1,
901};