blob: b0276072fdb48be237838f7733d836f6c4ead0f5 [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 Coxc5f694a2013-03-01 08:30:11 -050055typedef struct P P;
Russ Coxd28acc42008-08-04 16:43:49 -070056typedef struct Mem Mem;
Russ Cox3aa063d2008-11-23 17:08:55 -080057typedef union Note Note;
Rob Pike87f22082009-08-25 15:54:25 -070058typedef struct Slice Slice;
Russ Cox3aa063d2008-11-23 17:08:55 -080059typedef struct Stktop Stktop;
Ken Thompson36570612009-04-09 18:16:21 -070060typedef struct String String;
Russ Cox1903ad72013-02-21 17:01:13 -050061typedef struct FuncVal FuncVal;
Russ Coxc3077f72008-12-19 17:11:54 -080062typedef struct SigTab SigTab;
63typedef struct MCache MCache;
Russ Coxd324f212011-09-30 09:40:01 -040064typedef struct FixAlloc FixAlloc;
Russ Coxc3077f72008-12-19 17:11:54 -080065typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070066typedef struct Itab Itab;
Jan Ziak5c1422a2012-11-01 13:13:20 -040067typedef struct InterfaceType InterfaceType;
Ken Thompsonf59cb492010-02-19 20:42:50 -080068typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070069typedef struct Type Type;
Russ Cox3770b0e2011-08-17 15:54:17 -040070typedef struct ChanType ChanType;
Russ Cox65bde082011-08-17 14:56:27 -040071typedef struct MapType MapType;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080072typedef struct Defer Defer;
Russ Cox0de71612012-12-22 14:54:39 -050073typedef struct DeferChunk DeferChunk;
Russ Cox9b1507b2010-03-31 11:46:01 -070074typedef struct Panic Panic;
Luuk van Dijk7400be82011-01-31 12:27:28 +010075typedef struct Hmap Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070076typedef struct Hchan Hchan;
Ken Thompsonf59cb492010-02-19 20:42:50 -080077typedef struct Complex64 Complex64;
78typedef struct Complex128 Complex128;
Alex Brainman2a808822011-08-27 23:17:00 +100079typedef struct WinCall WinCall;
Alex Brainmanafe0e972012-05-30 15:10:54 +100080typedef struct SEH SEH;
Russ Cox3b860262011-11-09 15:17:05 -050081typedef struct Timers Timers;
82typedef struct Timer Timer;
Russ Cox1903ad72013-02-21 17:01:13 -050083typedef struct GCStats GCStats;
84typedef struct LFNode LFNode;
85typedef struct ParFor ParFor;
86typedef struct ParForThread ParForThread;
87typedef struct CgoMal CgoMal;
Ken Thompson594175d2008-07-13 14:29:46 -070088
89/*
Nigel Tao90ad6a22012-10-19 11:02:32 +110090 * Per-CPU declaration.
91 *
Rob Piked08f0062009-08-11 13:30:35 -070092 * "extern register" is a special storage class implemented by 6c, 8c, etc.
Nigel Tao90ad6a22012-10-19 11:02:32 +110093 * On the ARM, it is an actual register; elsewhere it is a slot in thread-
94 * local storage indexed by a segment register. See zasmhdr in
95 * src/cmd/dist/buildruntime.c for details, and be aware that the linker may
96 * make further OS-specific changes to the compiler's output. For example,
97 * 6l/linux rewrites 0(GS) as -16(FS).
Rob Piked08f0062009-08-11 13:30:35 -070098 *
Nigel Tao90ad6a22012-10-19 11:02:32 +110099 * Every C file linked into a Go program must include runtime.h so that the
100 * C compiler (6c, 8c, etc.) knows to avoid other uses of these dedicated
101 * registers. The Go compiler (6g, 8g, etc.) knows to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -0700102 */
Rob Piked08f0062009-08-11 13:30:35 -0700103extern register G* g;
104extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -0700105
106/*
107 * defined constants
108 */
109enum
110{
111 // G status
Russ Cox72157c32010-04-08 13:24:53 -0700112 //
113 // If you add to this list, add to the list
114 // of "okay during garbage collection" status
115 // in mgc0.c too.
Ken Thompson594175d2008-07-13 14:29:46 -0700116 Gidle,
117 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -0700118 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -0800119 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -0700120 Gwaiting,
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200121 Gmoribund_unused, // currently unused, but hardcoded in gdb scripts
Ken Thompson594175d2008-07-13 14:29:46 -0700122 Gdead,
123};
124enum
125{
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200126 // P status
127 Pidle,
128 Prunning,
129 Psyscall,
130 Pgcstop,
131 Pdead,
132};
133enum
134{
Ken Thompson594175d2008-07-13 14:29:46 -0700135 true = 1,
136 false = 0,
137};
Jan Ziak54193682012-09-17 17:18:21 -0400138enum
139{
140 PtrSize = sizeof(void*),
141};
Dmitriy Vyukovf82db7d2013-01-10 09:57:06 +0400142enum
143{
144 // Per-M stack segment cache size.
145 StackCacheSize = 32,
146 // Global <-> per-M stack segment cache transfer batch size.
147 StackCacheBatch = 16,
148};
Ken Thompson594175d2008-07-13 14:29:46 -0700149
150/*
151 * structures
152 */
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300153union Lock
Russ Coxd28acc42008-08-04 16:43:49 -0700154{
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300155 uint32 key; // futex-based impl
156 M* waitm; // linked list of waiting M's (sema-based impl)
Russ Cox5ff12f82008-09-24 10:25:28 -0700157};
Russ Cox376898c2008-09-09 11:50:14 -0700158union Note
Russ Coxd28acc42008-08-04 16:43:49 -0700159{
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300160 uint32 key; // futex-based impl
161 M* waitm; // waiting M (sema-based impl)
Russ Coxd28acc42008-08-04 16:43:49 -0700162};
Ken Thompson594175d2008-07-13 14:29:46 -0700163struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700164{
Ken Thompson36570612009-04-09 18:16:21 -0700165 byte* str;
Russ Cox0b08c942012-09-24 14:58:34 -0400166 intgo len;
Ken Thompson594175d2008-07-13 14:29:46 -0700167};
Russ Cox1903ad72013-02-21 17:01:13 -0500168struct FuncVal
169{
170 void (*fn)(void);
171 // variable-size, fn-specific data here
172};
Russ Coxc3077f72008-12-19 17:11:54 -0800173struct Iface
174{
Russ Coxc7513ea2009-07-07 11:02:54 -0700175 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700176 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800177};
Russ Cox2da50222009-05-20 14:57:55 -0700178struct Eface
179{
Russ Coxc7513ea2009-07-07 11:02:54 -0700180 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700181 void* data;
182};
Ken Thompsonf59cb492010-02-19 20:42:50 -0800183struct Complex64
184{
185 float32 real;
186 float32 imag;
187};
188struct Complex128
189{
190 float64 real;
191 float64 imag;
192};
Ken Thompson66a603c2008-08-27 17:28:30 -0700193
Rob Pike87f22082009-08-25 15:54:25 -0700194struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700195{ // must not move anything
196 byte* array; // actual data
Russ Cox0b08c942012-09-24 14:58:34 -0400197 uintgo len; // number of elements
198 uintgo cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700199};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700200struct Gobuf
201{
Russ Cox38020092009-06-17 16:31:02 -0700202 // The offsets of these fields are known to (hard-coded in) libmach.
Jan Ziak334bf952012-05-30 13:07:52 -0400203 uintptr sp;
Russ Cox7343e032009-06-17 15:12:16 -0700204 byte* pc;
205 G* g;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700206};
Dmitriy Vyukovd839a802012-04-05 20:48:28 +0400207struct GCStats
208{
209 // the struct must consist of only uint64's,
210 // because it is casted to uint64[].
211 uint64 nhandoff;
212 uint64 nhandoffcnt;
213 uint64 nprocyield;
214 uint64 nosyield;
215 uint64 nsleep;
216};
Ken Thompson7b454bb2008-07-09 11:35:26 -0700217struct G
Ken Thompson45288542008-07-08 17:19:17 -0700218{
Jan Ziak334bf952012-05-30 13:07:52 -0400219 uintptr stackguard; // cannot move - also known to linker, libmach, runtime/cgo
220 uintptr stackbase; // cannot move - also known to libmach, runtime/cgo
Russ Cox7343e032009-06-17 15:12:16 -0700221 Defer* defer;
Russ Cox9b1507b2010-03-31 11:46:01 -0700222 Panic* panic;
223 Gobuf sched;
Jan Ziak334bf952012-05-30 13:07:52 -0400224 uintptr gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
225 uintptr gcsp; // if status==Gsyscall, gcsp = sched.sp to use during gc
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200226 byte* gcpc; // if status==Gsyscall, gcpc = sched.pc to use during gc
Jan Ziak334bf952012-05-30 13:07:52 -0400227 uintptr gcguard; // if status==Gsyscall, gcguard = stackguard to use during gc
228 uintptr stack0;
Russ Cox1903ad72013-02-21 17:01:13 -0500229 FuncVal* fnstart; // initial function
Rob Pike3835e012008-07-28 11:29:41 -0700230 G* alllink; // on allg
Ken Thompsone963cba2008-07-25 15:55:12 -0700231 void* param; // passed parameter on wakeup
232 int16 status;
Dmitriy Vyukov320df442012-10-26 10:13:06 +0400233 int64 goid;
Adam Langley50d6c812009-12-18 12:25:53 -0800234 uint32 selgen; // valid sudog pointer
Russ Cox03e9ea52011-08-22 23:26:39 -0400235 int8* waitreason; // if status==Gwaiting
Russ Cox96824002008-08-05 14:18:47 -0700236 G* schedlink;
Russ Cox9b1507b2010-03-31 11:46:01 -0700237 bool ispanic;
Dmitriy Vyukov6ee739d2013-03-12 17:21:44 +0400238 bool issystem; // do not output in stack dump
239 bool isbackground; // ignore in deadlock detector
240 int8 raceignore; // ignore race detection events
Russ Cox7343e032009-06-17 15:12:16 -0700241 M* m; // for debuggers, but offset not hard-coded
Russ Cox218c3932009-07-13 17:28:39 -0700242 M* lockedm;
Russ Cox5963dba2010-04-08 18:15:30 -0700243 int32 sig;
Russ Coxe4b02bf2012-02-22 21:45:01 -0500244 int32 writenbuf;
245 byte* writebuf;
Russ Cox0de71612012-12-22 14:54:39 -0500246 DeferChunk *dchunk;
247 DeferChunk *dchunknext;
Russ Cox5963dba2010-04-08 18:15:30 -0700248 uintptr sigcode0;
249 uintptr sigcode1;
Russ Cox12307002011-01-18 14:15:11 -0500250 uintptr sigpc;
Russ Cox324cc3d02011-03-02 13:42:02 -0500251 uintptr gopc; // pc of go statement that created this goroutine
Dmitriy Vyukov0a40cd22013-02-06 11:40:54 +0400252 uintptr racectx;
Hector Chu9fd26872011-09-17 17:57:59 +1000253 uintptr end[];
Russ Coxd28acc42008-08-04 16:43:49 -0700254};
Ken Thompson45288542008-07-08 17:19:17 -0700255struct M
256{
Russ Cox38020092009-06-17 16:31:02 -0700257 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700258 G* g0; // goroutine with scheduling stack
259 void (*morepc)(void);
Russ Cox141a4a12011-01-14 14:05:20 -0500260 void* moreargp; // argument pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700261 Gobuf morebuf; // gobuf arg to morestack
262
Russ Cox38020092009-06-17 16:31:02 -0700263 // Fields not known to debuggers.
Russ Cox141a4a12011-01-14 14:05:20 -0500264 uint32 moreframesize; // size arguments to morestack
265 uint32 moreargsize;
Russ Cox7343e032009-06-17 15:12:16 -0700266 uintptr cret; // return value from C
267 uint64 procid; // for debuggers, but offset not hard-coded
268 G* gsignal; // signal-handling G
Russ Coxd0d74162013-03-01 09:24:17 -0500269 uintptr tls[4]; // thread-local storage (for x86 extern register)
270 void (*mstartfn)(void);
Russ Cox7343e032009-06-17 15:12:16 -0700271 G* curg; // current running goroutine
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200272 P* p; // attached P for executing Go code (nil if not executing Go code)
273 P* nextp;
Russ Coxefc86a72008-11-25 16:48:10 -0800274 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800275 int32 mallocing;
Dmitriy Vyukov81221f52013-01-29 14:57:11 +0400276 int32 throwing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700277 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800278 int32 locks;
Russ Cox6eb251f2010-03-24 09:40:09 -0700279 int32 nomemprof;
Russ Cox67793502011-02-16 13:21:13 -0500280 int32 dying;
Russ Coxc19b3732011-03-23 11:43:37 -0400281 int32 profilehz;
Russ Coxd324f212011-09-30 09:40:01 -0400282 int32 helpgc;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200283 bool blockingsyscall;
284 bool spinning;
Dmitriy Vyukov909f3182011-07-12 01:23:58 -0400285 uint32 fastrand;
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800286 uint64 ncgocall; // number of cgo calls in total
287 int32 ncgo; // number of cgo calls currently in progress
288 CgoMal* cgomal;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200289 Note park;
Russ Cox93689d82009-10-09 15:35:33 -0700290 M* alllink; // on allm
Russ Cox96824002008-08-05 14:18:47 -0700291 M* schedlink;
Russ Cox376898c2008-09-09 11:50:14 -0700292 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800293 MCache *mcache;
Dmitriy Vyukovf82db7d2013-01-10 09:57:06 +0400294 int32 stackinuse;
295 uint32 stackcachepos;
296 uint32 stackcachecnt;
297 void* stackcache[StackCacheSize];
Russ Cox218c3932009-07-13 17:28:39 -0700298 G* lockedg;
Russ Cox5b93fc92012-02-08 10:33:54 -0500299 uintptr createstack[32]; // Stack that created this thread.
Ken Thompsonae605262010-12-09 14:45:27 -0800300 uint32 freglo[16]; // D[i] lsb and F[i]
301 uint32 freghi[16]; // D[i] msb and F[i+16]
302 uint32 fflag; // floating point compare flags
Russ Coxb0a29f32013-02-01 08:34:41 -0800303 uint32 locked; // tracking for LockOSThread
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300304 M* nextwaitm; // next M waiting for lock
305 uintptr waitsema; // semaphore for parking on locks
306 uint32 waitsemacount;
307 uint32 waitsemalock;
Dmitriy Vyukovd839a802012-04-05 20:48:28 +0400308 GCStats gcstats;
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400309 bool racecall;
Russ Cox6c976392013-02-20 17:48:23 -0500310 bool needextram;
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400311 void* racepc;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200312 void (*waitunlockf)(Lock*);
313 Lock* waitlock;
Jan Ziak51b8edc2012-11-27 13:04:59 -0500314 uint32 moreframesize_minalloc;
Russ Cox3b860262011-11-09 15:17:05 -0500315
Jan Ziakf8c58372012-09-24 20:08:05 -0400316 uintptr settype_buf[1024];
317 uintptr settype_bufsize;
318
Russ Cox851f3012011-12-16 15:33:58 -0500319#ifdef GOOS_windows
Hector Chu9fd26872011-09-17 17:57:59 +1000320 void* thread; // thread handle
Hector Chu5c303252011-09-14 20:23:21 -0400321#endif
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800322#ifdef GOOS_plan9
323 int8* notesig;
Akshat Kumara566dea2013-03-08 00:54:44 +0100324 byte* errstr;
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800325#endif
Alex Brainmanafe0e972012-05-30 15:10:54 +1000326 SEH* seh;
Hector Chu9fd26872011-09-17 17:57:59 +1000327 uintptr end[];
Ken Thompson751ce3a2008-07-11 19:16:39 -0700328};
Russ Cox370276a2011-04-27 23:21:12 -0400329
Dmitriy Vyukov353ce602013-02-23 08:48:02 +0400330struct P
331{
332 Lock;
333
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200334 uint32 status; // one of Pidle/Prunning/...
Dmitriy Vyukov6cdfb002013-02-27 21:17:53 +0200335 P* link;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200336 uint32 tick; // incremented on every scheduler or system call
337 M* m; // back-link to associated M (nil if idle)
338 MCache* mcache;
Dmitriy Vyukov6cdfb002013-02-27 21:17:53 +0200339
Dmitriy Vyukov353ce602013-02-23 08:48:02 +0400340 // Queue of runnable goroutines.
341 G** runq;
342 int32 runqhead;
343 int32 runqtail;
344 int32 runqsize;
Dmitriy Vyukov6cdfb002013-02-27 21:17:53 +0200345
346 // Available G's (status == Gdead)
347 G* gfree;
348 int32 gfreecnt;
349
350 byte pad[64];
Dmitriy Vyukov353ce602013-02-23 08:48:02 +0400351};
352
Russ Coxb0a29f32013-02-01 08:34:41 -0800353// The m->locked word holds a single bit saying whether
354// external calls to LockOSThread are in effect, and then a counter
355// of the internal nesting depth of lockOSThread / unlockOSThread.
356enum
357{
358 LockExternal = 1,
359 LockInternal = 2,
360};
361
Ken Thompson52620032008-07-14 14:33:39 -0700362struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700363{
Russ Cox38020092009-06-17 16:31:02 -0700364 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700365 uint8* stackguard;
366 uint8* stackbase;
367 Gobuf gobuf;
Russ Cox141a4a12011-01-14 14:05:20 -0500368 uint32 argsize;
Russ Coxbba278a2009-07-08 18:16:09 -0700369
Russ Coxafc69282011-01-25 16:35:36 -0500370 uint8* argp; // pointer to arguments in old frame
371 uintptr free; // if free>0, call stackfree using free as size
Russ Cox9b1507b2010-03-31 11:46:01 -0700372 bool panic; // is this frame the top of a panic?
Ken Thompson45288542008-07-08 17:19:17 -0700373};
Ken Thompson594175d2008-07-13 14:29:46 -0700374struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700375{
Russ Coxdfa58932008-12-03 14:21:28 -0800376 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700377 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700378};
Russ Coxdfa58932008-12-03 14:21:28 -0800379enum
380{
Russ Cox35586f72012-02-13 13:52:37 -0500381 SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel
David Symonds3d8ebef2012-02-17 14:36:40 +1100382 SigKill = 1<<1, // if signal.Notify doesn't take it, exit quietly
383 SigThrow = 1<<2, // if signal.Notify doesn't take it, exit loudly
384 SigPanic = 1<<3, // if the signal is from the kernel, panic
385 SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
Russ Coxdfa58932008-12-03 14:21:28 -0800386};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700387
Russ Cox6eb251f2010-03-24 09:40:09 -0700388// NOTE(rsc): keep in sync with extern.go:/type.Func.
389// Eventually, the loaded symbol table should be closer to this form.
Russ Cox3aa063d2008-11-23 17:08:55 -0800390struct Func
391{
Ken Thompson36570612009-04-09 18:16:21 -0700392 String name;
393 String type; // go type string
394 String src; // src file name
Rob Pike87f22082009-08-25 15:54:25 -0700395 Slice pcln; // pc/ln tab for this func
Russ Cox6eb251f2010-03-24 09:40:09 -0700396 uintptr entry; // entry pc
397 uintptr pc0; // starting pc, ln for table
Russ Coxa5433362008-11-25 09:23:36 -0800398 int32 ln0;
Russ Cox6eb251f2010-03-24 09:40:09 -0700399 int32 frame; // stack frame size
Carl Shapirof4666172013-02-21 12:52:26 -0800400 int32 args; // in/out args size
401 int32 locals; // locals size
Russ Cox3aa063d2008-11-23 17:08:55 -0800402};
403
Jan Ziak5c1422a2012-11-01 13:13:20 -0400404// layout of Itab known to compilers
405struct Itab
406{
407 InterfaceType* inter;
408 Type* type;
409 Itab* link;
410 int32 bad;
411 int32 unused;
412 void (*fun[])(void);
413};
414
Alex Brainman2a808822011-08-27 23:17:00 +1000415struct WinCall
416{
417 void (*fn)(void*);
418 uintptr n; // number of parameters
419 void* args; // parameters
Alex Brainman74063792011-09-14 16:19:45 +1000420 uintptr r1; // return values
421 uintptr r2;
Alex Brainman2a808822011-08-27 23:17:00 +1000422 uintptr err; // error number
423};
Alex Brainmanafe0e972012-05-30 15:10:54 +1000424struct SEH
425{
426 void* prev;
427 void* handler;
428};
Alex Brainman2a808822011-08-27 23:17:00 +1000429
Russ Cox851f3012011-12-16 15:33:58 -0500430#ifdef GOOS_windows
Alex Brainmanf95a2f22010-09-12 11:45:16 +1000431enum {
432 Windows = 1
433};
434#else
435enum {
436 Windows = 0
437};
438#endif
439
Russ Cox3b860262011-11-09 15:17:05 -0500440struct Timers
441{
442 Lock;
443 G *timerproc;
444 bool sleeping;
445 bool rescheduling;
446 Note waitnote;
447 Timer **t;
448 int32 len;
449 int32 cap;
450};
451
452// Package time knows the layout of this structure.
453// If this struct changes, adjust ../time/sleep.go:/runtimeTimer.
454struct Timer
455{
456 int32 i; // heap index
457
458 // Timer wakes up at when, and then at when+period, ... (period > 0 only)
459 // each time calling f(now, arg) in the timer goroutine, so f must be
460 // a well-behaved function and not block.
461 int64 when;
462 int64 period;
Russ Cox1903ad72013-02-21 17:01:13 -0500463 FuncVal *fv;
Russ Cox3b860262011-11-09 15:17:05 -0500464 Eface arg;
465};
466
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +0400467// Lock-free stack node.
468struct LFNode
469{
470 LFNode *next;
471 uintptr pushcnt;
472};
473
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400474// Parallel for descriptor.
475struct ParFor
476{
477 void (*body)(ParFor*, uint32); // executed for each element
478 uint32 done; // number of idle threads
479 uint32 nthr; // total number of threads
480 uint32 nthrmax; // maximum number of threads
481 uint32 thrseq; // thread id sequencer
482 uint32 cnt; // iteration space [0, cnt)
483 void *ctx; // arbitrary user context
484 bool wait; // if true, wait while all threads finish processing,
485 // otherwise parfor may return while other threads are still working
486 ParForThread *thr; // array of thread descriptors
Dmitriy Vyukov433824d2013-03-10 20:46:11 +0400487 uint32 pad; // to align ParForThread.pos for 64-bit atomic operations
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400488 // stats
489 uint64 nsteal;
490 uint64 nstealcnt;
491 uint64 nprocyield;
492 uint64 nosyield;
493 uint64 nsleep;
494};
495
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800496// Track memory allocated by code not written in Go during a cgo call,
497// so that the garbage collector can see them.
498struct CgoMal
499{
500 CgoMal *next;
501 byte *alloc;
502};
503
Ken Thompsonbbb20732008-06-05 19:38:39 -0700504/*
505 * defined macros
Robert Hencke3fbd4782011-05-30 18:02:59 +1000506 * you need super-gopher-guru privilege
Ken Thompsonbbb20732008-06-05 19:38:39 -0700507 * to add this list.
508 */
509#define nelem(x) (sizeof(x)/sizeof((x)[0]))
510#define nil ((void*)0)
Russ Coxdc9a3b22010-12-13 16:22:19 -0500511#define offsetof(s,m) (uint32)(&(((s*)0)->m))
Russ Cox6dbaa202012-05-29 14:02:29 -0400512#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 -0700513
514/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800515 * known to compiler
516 */
Russ Coxb9ccd072011-12-05 09:40:22 -0500517enum {
518 Structrnd = sizeof(uintptr)
519};
520
521/*
522 * type algorithms - known to compiler
523 */
Russ Coxeee50ae2008-12-19 12:05:22 -0800524enum
525{
Russ Coxa7f6d402009-01-26 09:56:42 -0800526 AMEM,
Dmitriy Vyukov1ff14052012-01-20 10:32:55 +0400527 AMEM0,
Dmitriy Vyukov54e94062011-08-08 09:35:32 -0400528 AMEM8,
529 AMEM16,
530 AMEM32,
531 AMEM64,
532 AMEM128,
Russ Cox196b6632011-12-12 22:22:09 -0500533 ANOEQ,
Dmitriy Vyukov1ff14052012-01-20 10:32:55 +0400534 ANOEQ0,
Dmitriy Vyukov54e94062011-08-08 09:35:32 -0400535 ANOEQ8,
536 ANOEQ16,
537 ANOEQ32,
538 ANOEQ64,
539 ANOEQ128,
Russ Cox196b6632011-12-12 22:22:09 -0500540 ASTRING,
541 AINTER,
542 ANILINTER,
543 ASLICE,
Russ Cox408f0b12012-01-26 16:25:07 -0500544 AFLOAT32,
545 AFLOAT64,
546 ACPLX64,
547 ACPLX128,
Russ Coxa7f6d402009-01-26 09:56:42 -0800548 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800549};
Russ Coxb9ccd072011-12-05 09:40:22 -0500550typedef struct Alg Alg;
551struct Alg
552{
553 void (*hash)(uintptr*, uintptr, void*);
554 void (*equal)(bool*, uintptr, void*, void*);
555 void (*print)(uintptr, void*);
556 void (*copy)(uintptr, void*, void*);
Russ Cox29aa3ff2009-07-02 21:25:46 -0700557};
558
Russ Coxb9ccd072011-12-05 09:40:22 -0500559extern Alg runtime·algarray[Amax];
560
561void runtime·memhash(uintptr*, uintptr, void*);
562void runtime·nohash(uintptr*, uintptr, void*);
563void runtime·strhash(uintptr*, uintptr, void*);
564void runtime·interhash(uintptr*, uintptr, void*);
565void runtime·nilinterhash(uintptr*, uintptr, void*);
566
567void runtime·memequal(bool*, uintptr, void*, void*);
568void runtime·noequal(bool*, uintptr, void*, void*);
569void runtime·strequal(bool*, uintptr, void*, void*);
570void runtime·interequal(bool*, uintptr, void*, void*);
571void runtime·nilinterequal(bool*, uintptr, void*, void*);
572
573void runtime·memprint(uintptr, void*);
574void runtime·strprint(uintptr, void*);
575void runtime·interprint(uintptr, void*);
576void runtime·nilinterprint(uintptr, void*);
577
578void runtime·memcopy(uintptr, void*, void*);
579void runtime·memcopy8(uintptr, void*, void*);
580void runtime·memcopy16(uintptr, void*, void*);
581void runtime·memcopy32(uintptr, void*, void*);
582void runtime·memcopy64(uintptr, void*, void*);
583void runtime·memcopy128(uintptr, void*, void*);
584void runtime·memcopy(uintptr, void*, void*);
585void runtime·strcopy(uintptr, void*, void*);
586void runtime·algslicecopy(uintptr, void*, void*);
587void runtime·intercopy(uintptr, void*, void*);
588void runtime·nilintercopy(uintptr, void*, void*);
589
Russ Coxeee50ae2008-12-19 12:05:22 -0800590/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800591 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800592 */
593struct Defer
594{
595 int32 siz;
Russ Cox0de71612012-12-22 14:54:39 -0500596 bool special; // not part of defer frame
597 bool free; // if special, free when done
Russ Cox141a4a12011-01-14 14:05:20 -0500598 byte* argp; // where args were copied from
Russ Cox9b1507b2010-03-31 11:46:01 -0700599 byte* pc;
Russ Cox1903ad72013-02-21 17:01:13 -0500600 FuncVal* fn;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800601 Defer* link;
Jan Ziak334bf952012-05-30 13:07:52 -0400602 void* args[1]; // padded to actual size
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800603};
604
Russ Cox0de71612012-12-22 14:54:39 -0500605struct DeferChunk
606{
607 DeferChunk *prev;
608 uintptr off;
609};
610
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800611/*
Russ Cox9b1507b2010-03-31 11:46:01 -0700612 * panics
613 */
614struct Panic
615{
616 Eface arg; // argument to panic
617 byte* stackbase; // g->stackbase in panic
618 Panic* link; // link to earlier panic
619 bool recovered; // whether this panic is over
620};
621
622/*
Ken Thompson594175d2008-07-13 14:29:46 -0700623 * external data
624 */
Russ Cox68b42552010-11-04 14:00:19 -0400625extern String runtime·emptystring;
Jan Ziak4a191c22012-10-21 17:41:32 -0400626extern uintptr runtime·zerobase;
Shenghou Ma4019d0e2013-01-26 09:57:06 +0800627extern G* runtime·allg;
628extern G* runtime·lastg;
629extern M* runtime·allm;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200630extern P** runtime·allp;
Russ Cox68b42552010-11-04 14:00:19 -0400631extern int32 runtime·gomaxprocs;
Dmitriy Vyukova2677cf2011-08-16 16:53:02 -0400632extern bool runtime·singleproc;
Russ Cox67793502011-02-16 13:21:13 -0500633extern uint32 runtime·panicking;
Russ Cox36115532013-03-01 14:57:05 -0500634extern uint32 runtime·gcwaiting; // gc is waiting to run
Shenghou Ma4019d0e2013-01-26 09:57:06 +0800635extern int8* runtime·goos;
636extern int32 runtime·ncpu;
Russ Cox9042c2c2010-12-08 13:53:30 -0500637extern bool runtime·iscgo;
Russ Cox0b08c942012-09-24 14:58:34 -0400638extern void (*runtime·sysargs)(int32, uint8**);
639extern uint32 runtime·maxstring;
Jan Ziaka656f822013-02-25 15:58:23 -0500640extern uint32 runtime·Hchansize;
Ken Thompson594175d2008-07-13 14:29:46 -0700641
642/*
Rob Pike8e82a672008-06-30 11:50:36 -0700643 * common functions and data
644 */
Russ Cox68b42552010-11-04 14:00:19 -0400645int32 runtime·strcmp(byte*, byte*);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400646byte* runtime·strstr(byte*, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400647int32 runtime·findnull(byte*);
Alex Brainmana41d8542011-01-12 11:48:15 +1100648int32 runtime·findnullw(uint16*);
Russ Cox68b42552010-11-04 14:00:19 -0400649void runtime·dump(byte*, int32);
650int32 runtime·runetochar(byte*, int32);
651int32 runtime·charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700652
Rob Pike8e82a672008-06-30 11:50:36 -0700653/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700654 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700655 */
Russ Cox68b42552010-11-04 14:00:19 -0400656#define FLUSH(x) USED(x)
Russ Cox4e28cfe2010-03-26 14:15:30 -0700657
Russ Cox68b42552010-11-04 14:00:19 -0400658void runtime·gogo(Gobuf*, uintptr);
Russ Cox6066fdc2013-02-22 10:47:54 -0500659void runtime·gogocall(Gobuf*, void(*)(void), uintptr);
Russ Cox1903ad72013-02-21 17:01:13 -0500660void runtime·gogocallfn(Gobuf*, FuncVal*);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500661void runtime·gosave(Gobuf*);
Russ Cox68b42552010-11-04 14:00:19 -0400662void runtime·lessstack(void);
663void runtime·goargs(void);
Alex Brainmana41d8542011-01-12 11:48:15 +1100664void runtime·goenvs(void);
665void runtime·goenvs_unix(void);
Russ Cox68b42552010-11-04 14:00:19 -0400666void* runtime·getu(void);
667void runtime·throw(int8*);
668void runtime·panicstring(int8*);
Russ Cox68b42552010-11-04 14:00:19 -0400669void runtime·prints(int8*);
670void runtime·printf(int8*, ...);
671byte* runtime·mchr(byte*, byte, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400672int32 runtime·mcmp(byte*, byte*, uint32);
Rémy Oudompheng1b8f51c2013-03-09 00:41:03 +0100673void runtime·memmove(void*, void*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400674void* runtime·mal(uintptr);
675String runtime·catstring(String, String);
676String runtime·gostring(byte*);
Russ Cox0b08c942012-09-24 14:58:34 -0400677String runtime·gostringn(byte*, intgo);
678Slice runtime·gobytes(byte*, intgo);
Russ Cox68b42552010-11-04 14:00:19 -0400679String runtime·gostringnocopy(byte*);
Alex Brainmana41d8542011-01-12 11:48:15 +1100680String runtime·gostringw(uint16*);
Russ Cox35586f72012-02-13 13:52:37 -0500681void runtime·initsig(void);
David Symonds3d8ebef2012-02-17 14:36:40 +1100682void runtime·sigenable(uint32 sig);
Russ Cox68b42552010-11-04 14:00:19 -0400683int32 runtime·gotraceback(void);
Russ Cox03e9ea52011-08-22 23:26:39 -0400684void runtime·goroutineheader(G*);
Russ Cox68b42552010-11-04 14:00:19 -0400685void runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp);
686void runtime·tracebackothers(G*);
687int32 runtime·write(int32, void*, int32);
Jonathan Markddde52a2011-06-07 21:50:10 -0700688int32 runtime·mincore(void*, uintptr, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400689bool runtime·cas(uint32*, uint32, uint32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400690bool runtime·cas64(uint64*, uint64*, uint64);
Russ Cox68b42552010-11-04 14:00:19 -0400691bool runtime·casp(void**, void*, void*);
Dmitriy Vyukov997c00f2011-06-28 15:09:53 -0400692// Don't confuse with XADD x86 instruction,
693// this one is actually 'addx', that is, add-and-fetch.
Russ Cox68b42552010-11-04 14:00:19 -0400694uint32 runtime·xadd(uint32 volatile*, int32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400695uint64 runtime·xadd64(uint64 volatile*, int64);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400696uint32 runtime·xchg(uint32 volatile*, uint32);
Dmitriy Vyukovadd33492013-03-05 09:46:52 +0200697uint64 runtime·xchg64(uint64 volatile*, uint64);
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700698uint32 runtime·atomicload(uint32 volatile*);
Dmitriy Vyukov91f0f182011-07-29 13:47:24 -0400699void runtime·atomicstore(uint32 volatile*, uint32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400700void runtime·atomicstore64(uint64 volatile*, uint64);
701uint64 runtime·atomicload64(uint64 volatile*);
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700702void* runtime·atomicloadp(void* volatile*);
703void runtime·atomicstorep(void* volatile*, void*);
Russ Cox1903ad72013-02-21 17:01:13 -0500704void runtime·jmpdefer(FuncVal*, void*);
Russ Cox68b42552010-11-04 14:00:19 -0400705void runtime·exit1(int32);
706void runtime·ready(G*);
707byte* runtime·getenv(int8*);
708int32 runtime·atoi(byte*);
Russ Coxe6a3e222013-03-01 11:44:43 -0500709void runtime·newosproc(M *mp, void *stk);
710void runtime·mstart(void);
Russ Cox68b42552010-11-04 14:00:19 -0400711G* runtime·malg(int32);
Russ Cox1707a992012-02-14 01:23:15 -0500712void runtime·asminit(void);
Dmitriy Vyukova0955a22013-02-21 16:24:38 +0400713void runtime·mpreinit(M*);
Russ Cox68b42552010-11-04 14:00:19 -0400714void runtime·minit(void);
Russ Cox6c976392013-02-20 17:48:23 -0500715void runtime·unminit(void);
716void runtime·signalstack(byte*, int32);
Russ Cox68b42552010-11-04 14:00:19 -0400717Func* runtime·findfunc(uintptr);
Russ Coxb287d7c2011-02-02 16:44:20 -0500718int32 runtime·funcline(Func*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400719void* runtime·stackalloc(uint32);
Russ Coxafc69282011-01-25 16:35:36 -0500720void runtime·stackfree(void*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400721MCache* runtime·allocmcache(void);
Dmitriy Vyukoved516df2012-07-01 13:10:01 +0400722void runtime·freemcache(MCache*);
Russ Cox68b42552010-11-04 14:00:19 -0400723void runtime·mallocinit(void);
Jan Ziak4da6b362013-01-30 09:01:31 -0800724void runtime·mprofinit(void);
Russ Cox68b42552010-11-04 14:00:19 -0400725bool runtime·ifaceeq_c(Iface, Iface);
726bool runtime·efaceeq_c(Eface, Eface);
Ian Lance Taylor63bee952013-01-04 07:53:42 -0800727uintptr runtime·ifacehash(Iface, uintptr);
728uintptr runtime·efacehash(Eface, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400729void* runtime·malloc(uintptr size);
730void runtime·free(void *v);
Russ Cox1903ad72013-02-21 17:01:13 -0500731bool runtime·addfinalizer(void*, FuncVal *fn, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400732void runtime·runpanic(Panic*);
733void* runtime·getcallersp(void*);
Russ Cox4608feb2011-01-28 15:03:26 -0500734int32 runtime·mcount(void);
Russ Coxe4b02bf2012-02-22 21:45:01 -0500735int32 runtime·gcount(void);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500736void runtime·mcall(void(*)(G*));
Dmitriy Vyukov909f3182011-07-12 01:23:58 -0400737uint32 runtime·fastrand1(void);
Russ Coxd28acc42008-08-04 16:43:49 -0700738
Russ Cox6c976392013-02-20 17:48:23 -0500739void runtime·setmg(M*, G*);
740void runtime·newextram(void);
Russ Cox68b42552010-11-04 14:00:19 -0400741void runtime·exit(int32);
742void runtime·breakpoint(void);
743void runtime·gosched(void);
Dmitriy Vyukovf20fd872012-09-18 21:15:46 +0400744void runtime·park(void(*)(Lock*), Lock*, int8*);
745void runtime·tsleep(int64, int8*);
Russ Cox3b860262011-11-09 15:17:05 -0500746M* runtime·newm(void);
Russ Cox68b42552010-11-04 14:00:19 -0400747void runtime·goexit(void);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500748void runtime·asmcgocall(void (*fn)(void*), void*);
Russ Cox68b42552010-11-04 14:00:19 -0400749void runtime·entersyscall(void);
Dmitriy Vyukove25f19a2013-02-20 20:21:45 +0400750void runtime·entersyscallblock(void);
Russ Cox68b42552010-11-04 14:00:19 -0400751void runtime·exitsyscall(void);
Russ Cox1903ad72013-02-21 17:01:13 -0500752G* runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
Russ Cox68b42552010-11-04 14:00:19 -0400753bool runtime·sigsend(int32 sig);
Russ Cox68b42552010-11-04 14:00:19 -0400754int32 runtime·callers(int32, uintptr*, int32);
Russ Coxe0deb2e2013-03-05 15:36:40 -0500755int32 runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32);
Russ Cox68b42552010-11-04 14:00:19 -0400756int64 runtime·nanotime(void);
757void runtime·dopanic(int32);
Russ Cox67793502011-02-16 13:21:13 -0500758void runtime·startpanic(void);
Dmitriy Vyukova54f920b2012-07-04 14:52:51 +0400759void runtime·unwindstack(G*, byte*);
Russ Coxc19b3732011-03-23 11:43:37 -0400760void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
761void runtime·resetcpuprofiler(int32);
762void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
Russ Coxd324f212011-09-30 09:40:01 -0400763void runtime·usleep(uint32);
Damian Gryski8e765da2012-02-02 14:09:27 -0500764int64 runtime·cputicks(void);
Dmitriy Vyukov4cc7bf32012-10-06 12:56:04 +0400765int64 runtime·tickspersecond(void);
766void runtime·blockevent(int64, int32);
767extern int64 runtime·blockprofilerate;
Dmitriy Vyukovd0c11d22013-03-05 09:38:15 +0200768void runtime·addtimer(Timer*);
769bool runtime·deltimer(Timer*);
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800770
Russ Cox68b42552010-11-04 14:00:19 -0400771#pragma varargck argpos runtime·printf 1
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800772#pragma varargck type "d" int32
773#pragma varargck type "d" uint32
774#pragma varargck type "D" int64
775#pragma varargck type "D" uint64
776#pragma varargck type "x" int32
777#pragma varargck type "x" uint32
778#pragma varargck type "X" int64
779#pragma varargck type "X" uint64
780#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700781#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800782#pragma varargck type "s" int8*
783#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700784#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800785
Russ Cox68b42552010-11-04 14:00:19 -0400786void runtime·stoptheworld(void);
Dmitriy Vyukov01826282012-05-15 19:10:16 +0400787void runtime·starttheworld(void);
Russ Coxe4b02bf2012-02-22 21:45:01 -0500788extern uint32 runtime·worldsema;
Russ Cox3f8aa662008-12-05 15:24:18 -0800789
Russ Coxd28acc42008-08-04 16:43:49 -0700790/*
791 * mutual exclusion locks. in the uncontended case,
792 * as fast as spin locks (just a few user-level instructions),
793 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700794 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700795 */
Russ Cox68b42552010-11-04 14:00:19 -0400796void runtime·lock(Lock*);
797void runtime·unlock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700798
799/*
Russ Coxa68592a2009-10-14 13:02:05 -0700800 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700801 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700802 * must call noteclear to initialize the Note.
Dmitriy Vyukova496c9e2011-08-03 15:51:55 -0400803 * then, exactly one thread can call notesleep
Russ Cox96824002008-08-05 14:18:47 -0700804 * and exactly one thread can call notewakeup (once).
Dmitriy Vyukova496c9e2011-08-03 15:51:55 -0400805 * once notewakeup has been called, the notesleep
806 * will return. future notesleep will return immediately.
807 * subsequent noteclear must be called only after
808 * previous notesleep has returned, e.g. it's disallowed
809 * to call noteclear straight after notewakeup.
Russ Cox3b860262011-11-09 15:17:05 -0500810 *
811 * notetsleep is like notesleep but wakes up after
812 * a given number of nanoseconds even if the event
813 * has not yet happened. if a goroutine uses notetsleep to
814 * wake up early, it must wait to call noteclear until it
815 * can be sure that no other goroutine is calling
816 * notewakeup.
Russ Coxd28acc42008-08-04 16:43:49 -0700817 */
Russ Cox68b42552010-11-04 14:00:19 -0400818void runtime·noteclear(Note*);
819void runtime·notesleep(Note*);
820void runtime·notewakeup(Note*);
Russ Cox3b860262011-11-09 15:17:05 -0500821void runtime·notetsleep(Note*, int64);
822
823/*
824 * low-level synchronization for implementing the above
825 */
826uintptr runtime·semacreate(void);
827int32 runtime·semasleep(int64);
828void runtime·semawakeup(M*);
829// or
830void runtime·futexsleep(uint32*, uint32, int64);
831void runtime·futexwakeup(uint32*, uint32);
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800832
833/*
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +0400834 * Lock-free stack.
835 * Initialize uint64 head to 0, compare with 0 to test for emptiness.
836 * The stack does not keep pointers to nodes,
837 * so they can be garbage collected if there are no other pointers to nodes.
838 */
839void runtime·lfstackpush(uint64 *head, LFNode *node);
840LFNode* runtime·lfstackpop(uint64 *head);
841
842/*
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400843 * Parallel for over [0, n).
844 * body() is executed for each iteration.
845 * nthr - total number of worker threads.
846 * ctx - arbitrary user context.
847 * if wait=true, threads return from parfor() when all work is done;
848 * otherwise, threads can return while other threads are still finishing processing.
849 */
850ParFor* runtime·parforalloc(uint32 nthrmax);
851void runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32));
852void runtime·parfordo(ParFor *desc);
853
854/*
Adam Langley3f7a3242009-11-13 10:08:51 -0800855 * This is consistent across Linux and BSD.
856 * If a new OS is added that is different, move this to
857 * $GOOS/$GOARCH/defs.h.
858 */
859#define EACCES 13
860
861/*
Russ Coxafc69282011-01-25 16:35:36 -0500862 * low level C-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700863 */
Shenghou Mab151af12012-09-21 13:50:02 +0800864// for mmap, we only pass the lower 32 bits of file offset to the
865// assembly routine; the higher bits (if required), should be provided
866// by the assembly routine as 0.
Russ Cox68b42552010-11-04 14:00:19 -0400867uint8* runtime·mmap(byte*, uintptr, int32, int32, int32, uint32);
Russ Coxe83cd7f2011-12-20 17:54:40 -0500868void runtime·munmap(byte*, uintptr);
869void runtime·madvise(byte*, uintptr, int32);
Russ Coxafc69282011-01-25 16:35:36 -0500870void runtime·memclr(byte*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400871void runtime·setcallerpc(void*, void*);
872void* runtime·getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700873
874/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700875 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700876 */
Russ Cox68b42552010-11-04 14:00:19 -0400877void runtime·printbool(bool);
Carl Shapiro7f9c02a2013-02-19 18:05:44 -0800878void runtime·printbyte(int8);
Russ Cox68b42552010-11-04 14:00:19 -0400879void runtime·printfloat(float64);
880void runtime·printint(int64);
881void runtime·printiface(Iface);
882void runtime·printeface(Eface);
883void runtime·printstring(String);
884void runtime·printpc(void*);
885void runtime·printpointer(void*);
886void runtime·printuint(uint64);
887void runtime·printhex(uint64);
888void runtime·printslice(Slice);
889void runtime·printcomplex(Complex128);
Russ Cox1903ad72013-02-21 17:01:13 -0500890void reflect·call(FuncVal*, byte*, uint32);
Russ Cox68b42552010-11-04 14:00:19 -0400891void runtime·panic(Eface);
892void runtime·panicindex(void);
893void runtime·panicslice(void);
Russ Cox7c2b1592010-10-25 17:55:50 -0700894
Russ Cox63e878a2010-03-31 15:55:10 -0700895/*
896 * runtime c-called (but written in Go)
897 */
Russ Cox68b42552010-11-04 14:00:19 -0400898void runtime·printany(Eface);
Russ Cox6a75ece2012-02-12 23:26:20 -0500899void runtime·newTypeAssertionError(String*, String*, String*, String*, Eface*);
Russ Cox68b42552010-11-04 14:00:19 -0400900void runtime·newErrorString(String, Eface*);
901void runtime·fadd64c(uint64, uint64, uint64*);
902void runtime·fsub64c(uint64, uint64, uint64*);
903void runtime·fmul64c(uint64, uint64, uint64*);
904void runtime·fdiv64c(uint64, uint64, uint64*);
905void runtime·fneg64c(uint64, uint64*);
906void runtime·f32to64c(uint32, uint64*);
907void runtime·f64to32c(uint64, uint32*);
908void runtime·fcmp64c(uint64, uint64, int32*, bool*);
909void runtime·fintto64c(int64, uint64*);
910void runtime·f64tointc(uint64, int64*, bool*);
Rob Pike6db99de2008-07-08 10:36:43 -0700911
912/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800913 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -0700914 */
Russ Cox68b42552010-11-04 14:00:19 -0400915float64 runtime·Inf(int32 sign);
916float64 runtime·NaN(void);
917float32 runtime·float32frombits(uint32 i);
918uint32 runtime·float32tobits(float32 f);
919float64 runtime·float64frombits(uint64 i);
920uint64 runtime·float64tobits(float64 f);
921float64 runtime·frexp(float64 d, int32 *ep);
922bool runtime·isInf(float64 f, int32 sign);
923bool runtime·isNaN(float64 f);
924float64 runtime·ldexp(float64 d, int32 e);
925float64 runtime·modf(float64 d, float64 *ip);
926void runtime·semacquire(uint32*);
927void runtime·semrelease(uint32*);
Russ Cox68b42552010-11-04 14:00:19 -0400928int32 runtime·gomaxprocsfunc(int32 n);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400929void runtime·procyield(uint32);
930void runtime·osyield(void);
Russ Coxb0a29f32013-02-01 08:34:41 -0800931void runtime·lockOSThread(void);
932void runtime·unlockOSThread(void);
David Symondsb5866492009-12-15 18:21:29 -0800933
Russ Cox65bde082011-08-17 14:56:27 -0400934void runtime·mapassign(MapType*, Hmap*, byte*, byte*);
935void runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*);
Russ Cox68b42552010-11-04 14:00:19 -0400936void runtime·mapiternext(struct hash_iter*);
937bool runtime·mapiterkey(struct hash_iter*, void*);
938void runtime·mapiterkeyvalue(struct hash_iter*, void*, void*);
Russ Cox65bde082011-08-17 14:56:27 -0400939Hmap* runtime·makemap_c(MapType*, int64);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700940
Russ Cox3770b0e2011-08-17 15:54:17 -0400941Hchan* runtime·makechan_c(ChanType*, int64);
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400942void runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*);
Russ Cox33e9d242011-08-23 13:13:27 -0400943void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
Dmitriy Vyukov81221f52013-01-29 14:57:11 +0400944bool runtime·showframe(Func*, bool);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700945
Jan Ziak5c1422a2012-11-01 13:13:20 -0400946void runtime·ifaceE2I(InterfaceType*, Eface, Iface*);
Russ Coxafc69282011-01-25 16:35:36 -0500947
Russ Cox102274a2012-02-24 15:28:51 -0500948uintptr runtime·memlimit(void);
Russ Cox6e2ae0a2012-02-28 16:18:24 -0500949
950// If appropriate, ask the operating system to control whether this
951// thread should receive profiling signals. This is only necessary on OS X.
952// An operating system should not deliver a profiling signal to a
953// thread that is not actually executing (what good is that?), but that's
954// what OS X prefers to do. When profiling is turned on, we mask
955// away the profiling signal when threads go to sleep, so that OS X
956// is forced to deliver the signal to a thread that's actually running.
957// This is a no-op on other systems.
958void runtime·setprof(bool);
Shenghou Ma0157c722012-08-07 23:45:50 +0800959
960// float.c
961extern float64 runtime·nan;
962extern float64 runtime·posinf;
963extern float64 runtime·neginf;
964extern uint64 ·nan;
965extern uint64 ·posinf;
966extern uint64 ·neginf;
967#define ISNAN(f) ((f) != (f))
Jan Ziakf8c58372012-09-24 20:08:05 -0400968
969enum
970{
971 UseSpanType = 1,
972};