blob: 244b54848946e0af8df3ac2903775c5bb58efb32 [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 Vyukovd6174542013-04-06 20:07:07 -070053typedef struct Lock Lock;
Russ Cox3aa063d2008-11-23 17:08:55 -080054typedef struct M M;
Russ Coxc5f694a2013-03-01 08:30:11 -050055typedef struct P P;
Dmitriy Vyukov58030c52013-04-06 20:09:02 -070056typedef struct 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 Cox1903ad72013-02-21 17:01:13 -050060typedef struct FuncVal FuncVal;
Russ Coxc3077f72008-12-19 17:11:54 -080061typedef struct SigTab SigTab;
62typedef struct MCache MCache;
Russ Coxd324f212011-09-30 09:40:01 -040063typedef struct FixAlloc FixAlloc;
Russ Coxc3077f72008-12-19 17:11:54 -080064typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070065typedef struct Itab Itab;
Jan Ziak5c1422a2012-11-01 13:13:20 -040066typedef struct InterfaceType InterfaceType;
Ken Thompsonf59cb492010-02-19 20:42:50 -080067typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070068typedef struct Type Type;
Russ Cox3770b0e2011-08-17 15:54:17 -040069typedef struct ChanType ChanType;
Russ Cox65bde082011-08-17 14:56:27 -040070typedef struct MapType MapType;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080071typedef struct Defer Defer;
Russ Cox0de71612012-12-22 14:54:39 -050072typedef struct DeferChunk DeferChunk;
Russ Cox9b1507b2010-03-31 11:46:01 -070073typedef struct Panic Panic;
Luuk van Dijk7400be82011-01-31 12:27:28 +010074typedef struct Hmap Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070075typedef struct Hchan Hchan;
Ken Thompsonf59cb492010-02-19 20:42:50 -080076typedef struct Complex64 Complex64;
77typedef struct Complex128 Complex128;
Alex Brainman2a808822011-08-27 23:17:00 +100078typedef struct WinCall WinCall;
Alex Brainmanafe0e972012-05-30 15:10:54 +100079typedef struct SEH SEH;
Alex Brainman05a5de32013-06-24 17:17:45 +100080typedef struct WinCallbackContext WinCallbackContext;
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;
Dmitriy Vyukov0bee99a2013-03-14 10:38:37 +040088typedef struct PollDesc PollDesc;
Dmitriy Vyukov4b536a52013-06-28 18:37:06 +040089typedef struct DebugVars DebugVars;
Ken Thompson594175d2008-07-13 14:29:46 -070090
91/*
Nigel Tao90ad6a22012-10-19 11:02:32 +110092 * Per-CPU declaration.
93 *
Rob Piked08f0062009-08-11 13:30:35 -070094 * "extern register" is a special storage class implemented by 6c, 8c, etc.
Nigel Tao90ad6a22012-10-19 11:02:32 +110095 * On the ARM, it is an actual register; elsewhere it is a slot in thread-
96 * local storage indexed by a segment register. See zasmhdr in
97 * src/cmd/dist/buildruntime.c for details, and be aware that the linker may
98 * make further OS-specific changes to the compiler's output. For example,
99 * 6l/linux rewrites 0(GS) as -16(FS).
Rob Piked08f0062009-08-11 13:30:35 -0700100 *
Nigel Tao90ad6a22012-10-19 11:02:32 +1100101 * Every C file linked into a Go program must include runtime.h so that the
102 * C compiler (6c, 8c, etc.) knows to avoid other uses of these dedicated
103 * registers. The Go compiler (6g, 8g, etc.) knows to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -0700104 */
Rob Piked08f0062009-08-11 13:30:35 -0700105extern register G* g;
106extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -0700107
108/*
109 * defined constants
110 */
111enum
112{
113 // G status
Russ Cox72157c32010-04-08 13:24:53 -0700114 //
115 // If you add to this list, add to the list
116 // of "okay during garbage collection" status
117 // in mgc0.c too.
Ken Thompson594175d2008-07-13 14:29:46 -0700118 Gidle,
119 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -0700120 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -0800121 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -0700122 Gwaiting,
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200123 Gmoribund_unused, // currently unused, but hardcoded in gdb scripts
Ken Thompson594175d2008-07-13 14:29:46 -0700124 Gdead,
125};
126enum
127{
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200128 // P status
129 Pidle,
130 Prunning,
131 Psyscall,
132 Pgcstop,
133 Pdead,
134};
135enum
136{
Ken Thompson594175d2008-07-13 14:29:46 -0700137 true = 1,
138 false = 0,
139};
Jan Ziak54193682012-09-17 17:18:21 -0400140enum
141{
142 PtrSize = sizeof(void*),
143};
Dmitriy Vyukovf82db7d2013-01-10 09:57:06 +0400144enum
145{
146 // Per-M stack segment cache size.
147 StackCacheSize = 32,
148 // Global <-> per-M stack segment cache transfer batch size.
149 StackCacheBatch = 16,
150};
Ken Thompson594175d2008-07-13 14:29:46 -0700151/*
152 * structures
153 */
Dmitriy Vyukovd6174542013-04-06 20:07:07 -0700154struct Lock
Russ Coxd28acc42008-08-04 16:43:49 -0700155{
Dmitriy Vyukovd6174542013-04-06 20:07:07 -0700156 // Futex-based impl treats it as uint32 key,
157 // while sema-based impl as M* waitm.
158 // Used to be a union, but unions break precise GC.
159 uintptr key;
Russ Cox5ff12f82008-09-24 10:25:28 -0700160};
Dmitriy Vyukov58030c52013-04-06 20:09:02 -0700161struct Note
Russ Coxd28acc42008-08-04 16:43:49 -0700162{
Dmitriy Vyukov58030c52013-04-06 20:09:02 -0700163 // Futex-based impl treats it as uint32 key,
164 // while sema-based impl as M* waitm.
165 // Used to be a union, but unions break precise GC.
166 uintptr key;
Russ Coxd28acc42008-08-04 16:43:49 -0700167};
Ken Thompson594175d2008-07-13 14:29:46 -0700168struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700169{
Ken Thompson36570612009-04-09 18:16:21 -0700170 byte* str;
Russ Cox0b08c942012-09-24 14:58:34 -0400171 intgo len;
Ken Thompson594175d2008-07-13 14:29:46 -0700172};
Russ Cox1903ad72013-02-21 17:01:13 -0500173struct FuncVal
174{
175 void (*fn)(void);
176 // variable-size, fn-specific data here
177};
Russ Coxc3077f72008-12-19 17:11:54 -0800178struct Iface
179{
Russ Coxc7513ea2009-07-07 11:02:54 -0700180 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700181 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800182};
Russ Cox2da50222009-05-20 14:57:55 -0700183struct Eface
184{
Russ Coxc7513ea2009-07-07 11:02:54 -0700185 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700186 void* data;
187};
Ken Thompsonf59cb492010-02-19 20:42:50 -0800188struct Complex64
189{
190 float32 real;
191 float32 imag;
192};
193struct Complex128
194{
195 float64 real;
196 float64 imag;
197};
Ken Thompson66a603c2008-08-27 17:28:30 -0700198
Rob Pike87f22082009-08-25 15:54:25 -0700199struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700200{ // must not move anything
201 byte* array; // actual data
Russ Cox0b08c942012-09-24 14:58:34 -0400202 uintgo len; // number of elements
203 uintgo cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700204};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700205struct Gobuf
206{
Russ Coxd67e7e32013-06-12 15:22:26 -0400207 // The offsets of sp, pc, and g are known to (hard-coded in) libmach.
Jan Ziak334bf952012-05-30 13:07:52 -0400208 uintptr sp;
Russ Coxe58f7982013-06-12 08:49:38 -0400209 uintptr pc;
Russ Cox7343e032009-06-17 15:12:16 -0700210 G* g;
Russ Coxd67e7e32013-06-12 15:22:26 -0400211 uintptr ret;
212 void* ctxt;
213 uintptr lr;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700214};
Dmitriy Vyukovd839a802012-04-05 20:48:28 +0400215struct GCStats
216{
217 // the struct must consist of only uint64's,
218 // because it is casted to uint64[].
219 uint64 nhandoff;
220 uint64 nhandoffcnt;
221 uint64 nprocyield;
222 uint64 nosyield;
223 uint64 nsleep;
224};
Ken Thompson7b454bb2008-07-09 11:35:26 -0700225struct G
Ken Thompson45288542008-07-08 17:19:17 -0700226{
Dmitriy Vyukovf5becf42013-06-03 12:28:24 +0400227 // stackguard0 can be set to StackPreempt as opposed to stackguard
228 uintptr stackguard0; // cannot move - also known to linker, libmach, runtime/cgo
Jan Ziak334bf952012-05-30 13:07:52 -0400229 uintptr stackbase; // cannot move - also known to libmach, runtime/cgo
Russ Cox7343e032009-06-17 15:12:16 -0700230 Defer* defer;
Russ Cox9b1507b2010-03-31 11:46:01 -0700231 Panic* panic;
232 Gobuf sched;
Jan Ziak334bf952012-05-30 13:07:52 -0400233 uintptr gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
234 uintptr gcsp; // if status==Gsyscall, gcsp = sched.sp to use during gc
Russ Coxe58f7982013-06-12 08:49:38 -0400235 uintptr gcpc; // if status==Gsyscall, gcpc = sched.pc to use during gc
Jan Ziak334bf952012-05-30 13:07:52 -0400236 uintptr gcguard; // if status==Gsyscall, gcguard = stackguard to use during gc
Dmitriy Vyukovf5becf42013-06-03 12:28:24 +0400237 uintptr stackguard; // same as stackguard0, but not set to StackPreempt
Jan Ziak334bf952012-05-30 13:07:52 -0400238 uintptr stack0;
Rob Pike3835e012008-07-28 11:29:41 -0700239 G* alllink; // on allg
Ken Thompsone963cba2008-07-25 15:55:12 -0700240 void* param; // passed parameter on wakeup
241 int16 status;
Dmitriy Vyukov320df442012-10-26 10:13:06 +0400242 int64 goid;
Adam Langley50d6c812009-12-18 12:25:53 -0800243 uint32 selgen; // valid sudog pointer
Russ Cox03e9ea52011-08-22 23:26:39 -0400244 int8* waitreason; // if status==Gwaiting
Russ Cox96824002008-08-05 14:18:47 -0700245 G* schedlink;
Russ Cox9b1507b2010-03-31 11:46:01 -0700246 bool ispanic;
Dmitriy Vyukov6ee739d2013-03-12 17:21:44 +0400247 bool issystem; // do not output in stack dump
248 bool isbackground; // ignore in deadlock detector
Dmitriy Vyukovea151042013-03-25 20:57:36 +0400249 bool blockingsyscall; // hint that the next syscall will block
Dmitriy Vyukov5887f142013-07-17 12:52:37 -0400250 bool preempt; // preemption signal, duplicates stackguard0 = StackPreempt
Dmitriy Vyukov6ee739d2013-03-12 17:21:44 +0400251 int8 raceignore; // ignore race detection events
Russ Cox7343e032009-06-17 15:12:16 -0700252 M* m; // for debuggers, but offset not hard-coded
Russ Cox218c3932009-07-13 17:28:39 -0700253 M* lockedm;
Russ Cox5963dba2010-04-08 18:15:30 -0700254 int32 sig;
Russ Coxe4b02bf2012-02-22 21:45:01 -0500255 int32 writenbuf;
256 byte* writebuf;
Russ Cox0de71612012-12-22 14:54:39 -0500257 DeferChunk *dchunk;
258 DeferChunk *dchunknext;
Russ Cox5963dba2010-04-08 18:15:30 -0700259 uintptr sigcode0;
260 uintptr sigcode1;
Russ Cox12307002011-01-18 14:15:11 -0500261 uintptr sigpc;
Russ Cox324cc3d02011-03-02 13:42:02 -0500262 uintptr gopc; // pc of go statement that created this goroutine
Dmitriy Vyukov0a40cd22013-02-06 11:40:54 +0400263 uintptr racectx;
Hector Chu9fd26872011-09-17 17:57:59 +1000264 uintptr end[];
Russ Coxd28acc42008-08-04 16:43:49 -0700265};
Ken Thompson45288542008-07-08 17:19:17 -0700266struct M
267{
Russ Cox7343e032009-06-17 15:12:16 -0700268 G* g0; // goroutine with scheduling stack
Russ Cox141a4a12011-01-14 14:05:20 -0500269 void* moreargp; // argument pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700270 Gobuf morebuf; // gobuf arg to morestack
271
Russ Cox38020092009-06-17 16:31:02 -0700272 // Fields not known to debuggers.
Russ Cox141a4a12011-01-14 14:05:20 -0500273 uint32 moreframesize; // size arguments to morestack
274 uint32 moreargsize;
Russ Cox7343e032009-06-17 15:12:16 -0700275 uintptr cret; // return value from C
276 uint64 procid; // for debuggers, but offset not hard-coded
277 G* gsignal; // signal-handling G
Russ Coxd0d74162013-03-01 09:24:17 -0500278 uintptr tls[4]; // thread-local storage (for x86 extern register)
279 void (*mstartfn)(void);
Russ Cox7343e032009-06-17 15:12:16 -0700280 G* curg; // current running goroutine
Russ Cox6fa3c892013-06-27 11:32:01 -0400281 G* caughtsig; // goroutine running during fatal signal
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200282 P* p; // attached P for executing Go code (nil if not executing Go code)
283 P* nextp;
Russ Coxefc86a72008-11-25 16:48:10 -0800284 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800285 int32 mallocing;
Dmitriy Vyukov81221f52013-01-29 14:57:11 +0400286 int32 throwing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700287 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800288 int32 locks;
Russ Cox6eb251f2010-03-24 09:40:09 -0700289 int32 nomemprof;
Russ Cox67793502011-02-16 13:21:13 -0500290 int32 dying;
Russ Coxc19b3732011-03-23 11:43:37 -0400291 int32 profilehz;
Russ Coxd324f212011-09-30 09:40:01 -0400292 int32 helpgc;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200293 bool blockingsyscall;
294 bool spinning;
Dmitriy Vyukov909f3182011-07-12 01:23:58 -0400295 uint32 fastrand;
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800296 uint64 ncgocall; // number of cgo calls in total
297 int32 ncgo; // number of cgo calls currently in progress
298 CgoMal* cgomal;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200299 Note park;
Russ Cox93689d82009-10-09 15:35:33 -0700300 M* alllink; // on allm
Russ Cox96824002008-08-05 14:18:47 -0700301 M* schedlink;
Russ Cox376898c2008-09-09 11:50:14 -0700302 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800303 MCache *mcache;
Dmitriy Vyukovf82db7d2013-01-10 09:57:06 +0400304 int32 stackinuse;
305 uint32 stackcachepos;
306 uint32 stackcachecnt;
307 void* stackcache[StackCacheSize];
Russ Cox218c3932009-07-13 17:28:39 -0700308 G* lockedg;
Russ Cox5b93fc92012-02-08 10:33:54 -0500309 uintptr createstack[32]; // Stack that created this thread.
Ken Thompsonae605262010-12-09 14:45:27 -0800310 uint32 freglo[16]; // D[i] lsb and F[i]
311 uint32 freghi[16]; // D[i] msb and F[i+16]
312 uint32 fflag; // floating point compare flags
Russ Coxb0a29f32013-02-01 08:34:41 -0800313 uint32 locked; // tracking for LockOSThread
Dmitriy Vyukovee24bfc2011-11-02 16:42:01 +0300314 M* nextwaitm; // next M waiting for lock
315 uintptr waitsema; // semaphore for parking on locks
316 uint32 waitsemacount;
317 uint32 waitsemalock;
Dmitriy Vyukovd839a802012-04-05 20:48:28 +0400318 GCStats gcstats;
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400319 bool racecall;
Russ Cox6c976392013-02-20 17:48:23 -0500320 bool needextram;
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +0400321 void* racepc;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200322 void (*waitunlockf)(Lock*);
Dmitriy Vyukov54340bf2013-04-06 20:01:28 -0700323 void* waitlock;
Russ Cox3b860262011-11-09 15:17:05 -0500324
Jan Ziakf8c58372012-09-24 20:08:05 -0400325 uintptr settype_buf[1024];
326 uintptr settype_bufsize;
327
Russ Cox851f3012011-12-16 15:33:58 -0500328#ifdef GOOS_windows
Hector Chu9fd26872011-09-17 17:57:59 +1000329 void* thread; // thread handle
Hector Chu5c303252011-09-14 20:23:21 -0400330#endif
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800331#ifdef GOOS_plan9
332 int8* notesig;
Akshat Kumara566dea2013-03-08 00:54:44 +0100333 byte* errstr;
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800334#endif
Alex Brainmanafe0e972012-05-30 15:10:54 +1000335 SEH* seh;
Hector Chu9fd26872011-09-17 17:57:59 +1000336 uintptr end[];
Ken Thompson751ce3a2008-07-11 19:16:39 -0700337};
Russ Cox370276a2011-04-27 23:21:12 -0400338
Dmitriy Vyukov353ce602013-02-23 08:48:02 +0400339struct P
340{
341 Lock;
342
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200343 uint32 status; // one of Pidle/Prunning/...
Dmitriy Vyukov6cdfb002013-02-27 21:17:53 +0200344 P* link;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200345 uint32 tick; // incremented on every scheduler or system call
346 M* m; // back-link to associated M (nil if idle)
347 MCache* mcache;
Dmitriy Vyukov6cdfb002013-02-27 21:17:53 +0200348
Dmitriy Vyukov353ce602013-02-23 08:48:02 +0400349 // Queue of runnable goroutines.
350 G** runq;
351 int32 runqhead;
352 int32 runqtail;
353 int32 runqsize;
Dmitriy Vyukov6cdfb002013-02-27 21:17:53 +0200354
355 // Available G's (status == Gdead)
356 G* gfree;
357 int32 gfreecnt;
358
359 byte pad[64];
Dmitriy Vyukov353ce602013-02-23 08:48:02 +0400360};
361
Dmitriy Vyukov27134562013-07-22 16:37:31 +0400362// The m->locked word holds two pieces of state counting active calls to LockOSThread/lockOSThread.
363// The low bit (LockExternal) is a boolean reporting whether any LockOSThread call is active.
364// External locks are not recursive; a second lock is silently ignored.
365// The upper bits of m->lockedcount record the nesting depth of calls to lockOSThread
366// (counting up by LockInternal), popped by unlockOSThread (counting down by LockInternal).
367// Internal locks can be recursive. For instance, a lock for cgo can occur while the main
368// goroutine is holding the lock during the initialization phase.
Russ Coxb0a29f32013-02-01 08:34:41 -0800369enum
370{
371 LockExternal = 1,
372 LockInternal = 2,
373};
374
Ken Thompson52620032008-07-14 14:33:39 -0700375struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700376{
Russ Cox38020092009-06-17 16:31:02 -0700377 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Coxe58f7982013-06-12 08:49:38 -0400378 uintptr stackguard;
379 uintptr stackbase;
Russ Cox7343e032009-06-17 15:12:16 -0700380 Gobuf gobuf;
Russ Cox141a4a12011-01-14 14:05:20 -0500381 uint32 argsize;
Russ Coxbba278a2009-07-08 18:16:09 -0700382
Russ Coxafc69282011-01-25 16:35:36 -0500383 uint8* argp; // pointer to arguments in old frame
384 uintptr free; // if free>0, call stackfree using free as size
Russ Cox9b1507b2010-03-31 11:46:01 -0700385 bool panic; // is this frame the top of a panic?
Ken Thompson45288542008-07-08 17:19:17 -0700386};
Ken Thompson594175d2008-07-13 14:29:46 -0700387struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700388{
Russ Coxdfa58932008-12-03 14:21:28 -0800389 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700390 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700391};
Russ Coxdfa58932008-12-03 14:21:28 -0800392enum
393{
Russ Cox35586f72012-02-13 13:52:37 -0500394 SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel
David Symonds3d8ebef2012-02-17 14:36:40 +1100395 SigKill = 1<<1, // if signal.Notify doesn't take it, exit quietly
396 SigThrow = 1<<2, // if signal.Notify doesn't take it, exit loudly
397 SigPanic = 1<<3, // if the signal is from the kernel, panic
398 SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
Russ Coxcb4428e2013-03-15 00:00:02 -0400399 SigHandling = 1<<5, // our signal handler is registered
400 SigIgnored = 1<<6, // the signal was ignored before we registered for it
Russ Coxdfa58932008-12-03 14:21:28 -0800401};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700402
Russ Coxc3de91b2013-07-18 10:43:22 -0400403// Layout of in-memory per-function information prepared by linker
Russ Cox5d363c62013-07-16 09:41:38 -0400404// See http://golang.org/s/go12symtab.
Russ Coxc3de91b2013-07-18 10:43:22 -0400405// Keep in sync with linker and with ../../libmach/sym.c
406// and with package debug/gosym.
Russ Cox3aa063d2008-11-23 17:08:55 -0800407struct Func
408{
Russ Cox5d363c62013-07-16 09:41:38 -0400409 uintptr entry; // start pc
Russ Coxc3de91b2013-07-18 10:43:22 -0400410 int32 nameoff; // function name
Russ Cox5d363c62013-07-16 09:41:38 -0400411
Russ Coxc7588412013-07-19 18:52:35 -0400412 // TODO: Perhaps remove these fields.
Carl Shapirof4666172013-02-21 12:52:26 -0800413 int32 args; // in/out args size
Russ Cox5d363c62013-07-16 09:41:38 -0400414 int32 frame; // legacy frame size; use pcsp if possible
Russ Cox5d363c62013-07-16 09:41:38 -0400415
416 int32 pcsp;
417 int32 pcfile;
418 int32 pcln;
419 int32 npcdata;
420 int32 nfuncdata;
Russ Cox3aa063d2008-11-23 17:08:55 -0800421};
422
Jan Ziak5c1422a2012-11-01 13:13:20 -0400423// layout of Itab known to compilers
Dmitriy Vyukovb36f2db2013-06-09 21:58:35 +0400424// allocated in non-garbage-collected memory
Jan Ziak5c1422a2012-11-01 13:13:20 -0400425struct Itab
426{
427 InterfaceType* inter;
428 Type* type;
429 Itab* link;
430 int32 bad;
431 int32 unused;
432 void (*fun[])(void);
433};
434
Alex Brainman2a808822011-08-27 23:17:00 +1000435struct WinCall
436{
437 void (*fn)(void*);
438 uintptr n; // number of parameters
439 void* args; // parameters
Alex Brainman74063792011-09-14 16:19:45 +1000440 uintptr r1; // return values
441 uintptr r2;
Alex Brainman2a808822011-08-27 23:17:00 +1000442 uintptr err; // error number
443};
Alex Brainmanafe0e972012-05-30 15:10:54 +1000444struct SEH
445{
446 void* prev;
447 void* handler;
448};
Alex Brainman05a5de32013-06-24 17:17:45 +1000449// describes how to handle callback
450struct WinCallbackContext
451{
452 void* gobody; // Go function to call
453 uintptr argsize; // callback arguments size (in bytes)
454 uintptr restorestack; // adjust stack on return by (in bytes) (386 only)
455};
Alex Brainman2a808822011-08-27 23:17:00 +1000456
Russ Cox851f3012011-12-16 15:33:58 -0500457#ifdef GOOS_windows
Alex Brainmanf95a2f22010-09-12 11:45:16 +1000458enum {
459 Windows = 1
460};
461#else
462enum {
463 Windows = 0
464};
465#endif
466
Russ Cox3b860262011-11-09 15:17:05 -0500467struct Timers
468{
469 Lock;
470 G *timerproc;
471 bool sleeping;
472 bool rescheduling;
473 Note waitnote;
474 Timer **t;
475 int32 len;
476 int32 cap;
477};
478
479// Package time knows the layout of this structure.
480// If this struct changes, adjust ../time/sleep.go:/runtimeTimer.
481struct Timer
482{
483 int32 i; // heap index
484
485 // Timer wakes up at when, and then at when+period, ... (period > 0 only)
486 // each time calling f(now, arg) in the timer goroutine, so f must be
487 // a well-behaved function and not block.
488 int64 when;
489 int64 period;
Russ Cox1903ad72013-02-21 17:01:13 -0500490 FuncVal *fv;
Russ Cox3b860262011-11-09 15:17:05 -0500491 Eface arg;
492};
493
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +0400494// Lock-free stack node.
495struct LFNode
496{
497 LFNode *next;
498 uintptr pushcnt;
499};
500
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400501// Parallel for descriptor.
502struct ParFor
503{
504 void (*body)(ParFor*, uint32); // executed for each element
505 uint32 done; // number of idle threads
506 uint32 nthr; // total number of threads
507 uint32 nthrmax; // maximum number of threads
508 uint32 thrseq; // thread id sequencer
509 uint32 cnt; // iteration space [0, cnt)
510 void *ctx; // arbitrary user context
511 bool wait; // if true, wait while all threads finish processing,
512 // otherwise parfor may return while other threads are still working
513 ParForThread *thr; // array of thread descriptors
Dmitriy Vyukov433824d2013-03-10 20:46:11 +0400514 uint32 pad; // to align ParForThread.pos for 64-bit atomic operations
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400515 // stats
516 uint64 nsteal;
517 uint64 nstealcnt;
518 uint64 nprocyield;
519 uint64 nosyield;
520 uint64 nsleep;
521};
522
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800523// Track memory allocated by code not written in Go during a cgo call,
524// so that the garbage collector can see them.
525struct CgoMal
526{
527 CgoMal *next;
Ian Lance Taylor6732ad92013-04-06 20:18:15 -0700528 void *alloc;
Ian Lance Taylore9a30872012-11-10 11:19:06 -0800529};
530
Dmitriy Vyukov4b536a52013-06-28 18:37:06 +0400531// Holds variables parsed from GODEBUG env var.
532struct DebugVars
533{
534 int32 gctrace;
535};
536
Ken Thompsonbbb20732008-06-05 19:38:39 -0700537/*
538 * defined macros
Robert Hencke3fbd4782011-05-30 18:02:59 +1000539 * you need super-gopher-guru privilege
Ken Thompsonbbb20732008-06-05 19:38:39 -0700540 * to add this list.
541 */
542#define nelem(x) (sizeof(x)/sizeof((x)[0]))
543#define nil ((void*)0)
Russ Coxdc9a3b22010-12-13 16:22:19 -0500544#define offsetof(s,m) (uint32)(&(((s*)0)->m))
Russ Cox6dbaa202012-05-29 14:02:29 -0400545#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 -0700546
547/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800548 * known to compiler
549 */
Russ Coxb9ccd072011-12-05 09:40:22 -0500550enum {
551 Structrnd = sizeof(uintptr)
552};
553
554/*
555 * type algorithms - known to compiler
556 */
Russ Coxeee50ae2008-12-19 12:05:22 -0800557enum
558{
Russ Coxa7f6d402009-01-26 09:56:42 -0800559 AMEM,
Dmitriy Vyukov1ff14052012-01-20 10:32:55 +0400560 AMEM0,
Dmitriy Vyukov54e94062011-08-08 09:35:32 -0400561 AMEM8,
562 AMEM16,
563 AMEM32,
564 AMEM64,
565 AMEM128,
Russ Cox196b6632011-12-12 22:22:09 -0500566 ANOEQ,
Dmitriy Vyukov1ff14052012-01-20 10:32:55 +0400567 ANOEQ0,
Dmitriy Vyukov54e94062011-08-08 09:35:32 -0400568 ANOEQ8,
569 ANOEQ16,
570 ANOEQ32,
571 ANOEQ64,
572 ANOEQ128,
Russ Cox196b6632011-12-12 22:22:09 -0500573 ASTRING,
574 AINTER,
575 ANILINTER,
576 ASLICE,
Russ Cox408f0b12012-01-26 16:25:07 -0500577 AFLOAT32,
578 AFLOAT64,
579 ACPLX64,
580 ACPLX128,
Russ Coxa7f6d402009-01-26 09:56:42 -0800581 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800582};
Russ Coxb9ccd072011-12-05 09:40:22 -0500583typedef struct Alg Alg;
584struct Alg
585{
586 void (*hash)(uintptr*, uintptr, void*);
587 void (*equal)(bool*, uintptr, void*, void*);
588 void (*print)(uintptr, void*);
589 void (*copy)(uintptr, void*, void*);
Russ Cox29aa3ff2009-07-02 21:25:46 -0700590};
591
Russ Coxb9ccd072011-12-05 09:40:22 -0500592extern Alg runtime·algarray[Amax];
593
Keith Randalla5d40242013-03-12 10:47:44 -0700594byte* runtime·startup_random_data;
595uint32 runtime·startup_random_data_len;
596void runtime·get_random_data(byte**, int32*);
597
598enum {
599 // hashinit wants this many random bytes
600 HashRandomBytes = 32
601};
602void runtime·hashinit(void);
603
Russ Coxb9ccd072011-12-05 09:40:22 -0500604void runtime·memhash(uintptr*, uintptr, void*);
605void runtime·nohash(uintptr*, uintptr, void*);
606void runtime·strhash(uintptr*, uintptr, void*);
607void runtime·interhash(uintptr*, uintptr, void*);
608void runtime·nilinterhash(uintptr*, uintptr, void*);
Keith Randalla5d40242013-03-12 10:47:44 -0700609void runtime·aeshash(uintptr*, uintptr, void*);
610void runtime·aeshash32(uintptr*, uintptr, void*);
611void runtime·aeshash64(uintptr*, uintptr, void*);
612void runtime·aeshashstr(uintptr*, uintptr, void*);
Russ Coxb9ccd072011-12-05 09:40:22 -0500613
614void runtime·memequal(bool*, uintptr, void*, void*);
615void runtime·noequal(bool*, uintptr, void*, void*);
616void runtime·strequal(bool*, uintptr, void*, void*);
617void runtime·interequal(bool*, uintptr, void*, void*);
618void runtime·nilinterequal(bool*, uintptr, void*, void*);
619
Keith Randall3d5daa22013-04-02 16:26:15 -0700620bool runtime·memeq(void*, void*, uintptr);
621
Russ Coxb9ccd072011-12-05 09:40:22 -0500622void runtime·memprint(uintptr, void*);
623void runtime·strprint(uintptr, void*);
624void runtime·interprint(uintptr, void*);
625void runtime·nilinterprint(uintptr, void*);
626
627void runtime·memcopy(uintptr, void*, void*);
628void runtime·memcopy8(uintptr, void*, void*);
629void runtime·memcopy16(uintptr, void*, void*);
630void runtime·memcopy32(uintptr, void*, void*);
631void runtime·memcopy64(uintptr, void*, void*);
632void runtime·memcopy128(uintptr, void*, void*);
Russ Coxb9ccd072011-12-05 09:40:22 -0500633void runtime·strcopy(uintptr, void*, void*);
634void runtime·algslicecopy(uintptr, void*, void*);
635void runtime·intercopy(uintptr, void*, void*);
636void runtime·nilintercopy(uintptr, void*, void*);
637
Russ Coxeee50ae2008-12-19 12:05:22 -0800638/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800639 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800640 */
641struct Defer
642{
643 int32 siz;
Russ Cox0de71612012-12-22 14:54:39 -0500644 bool special; // not part of defer frame
645 bool free; // if special, free when done
Russ Cox141a4a12011-01-14 14:05:20 -0500646 byte* argp; // where args were copied from
Russ Cox9b1507b2010-03-31 11:46:01 -0700647 byte* pc;
Russ Cox1903ad72013-02-21 17:01:13 -0500648 FuncVal* fn;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800649 Defer* link;
Jan Ziak334bf952012-05-30 13:07:52 -0400650 void* args[1]; // padded to actual size
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800651};
652
Russ Cox0de71612012-12-22 14:54:39 -0500653struct DeferChunk
654{
655 DeferChunk *prev;
656 uintptr off;
657};
658
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800659/*
Russ Cox9b1507b2010-03-31 11:46:01 -0700660 * panics
661 */
662struct Panic
663{
664 Eface arg; // argument to panic
Russ Coxe58f7982013-06-12 08:49:38 -0400665 uintptr stackbase; // g->stackbase in panic
Russ Cox9b1507b2010-03-31 11:46:01 -0700666 Panic* link; // link to earlier panic
667 bool recovered; // whether this panic is over
668};
669
670/*
Russ Coxe58f7982013-06-12 08:49:38 -0400671 * stack traces
672 */
673typedef struct Stkframe Stkframe;
674struct Stkframe
675{
676 Func* fn; // function being run
677 uintptr pc; // program counter within fn
678 uintptr lr; // program counter at caller aka link register
679 uintptr sp; // stack pointer at pc
680 uintptr fp; // stack pointer at caller aka frame pointer
Russ Cox48769bf2013-07-19 16:04:09 -0400681 byte* varp; // top of local variables
Russ Coxe58f7982013-06-12 08:49:38 -0400682 byte* argp; // pointer to function arguments
683 uintptr arglen; // number of bytes at argp
Russ Coxe58f7982013-06-12 08:49:38 -0400684};
685
Russ Cox6fa3c892013-06-27 11:32:01 -0400686int32 runtime·gentraceback(uintptr, uintptr, uintptr, G*, int32, uintptr*, int32, void(*)(Stkframe*, void*), void*, bool);
Russ Coxe58f7982013-06-12 08:49:38 -0400687void runtime·traceback(uintptr pc, uintptr sp, uintptr lr, G* gp);
688void runtime·tracebackothers(G*);
Russ Coxd67e7e32013-06-12 15:22:26 -0400689bool runtime·haszeroargs(uintptr pc);
Russ Coxa8374852013-07-17 12:47:18 -0400690bool runtime·topofstack(Func*);
Russ Coxe58f7982013-06-12 08:49:38 -0400691
692/*
Ken Thompson594175d2008-07-13 14:29:46 -0700693 * external data
694 */
Russ Cox68b42552010-11-04 14:00:19 -0400695extern String runtime·emptystring;
Jan Ziak4a191c22012-10-21 17:41:32 -0400696extern uintptr runtime·zerobase;
Shenghou Ma4019d0e2013-01-26 09:57:06 +0800697extern G* runtime·allg;
698extern G* runtime·lastg;
699extern M* runtime·allm;
Dmitriy Vyukov779c45a2013-03-01 13:49:16 +0200700extern P** runtime·allp;
Russ Cox68b42552010-11-04 14:00:19 -0400701extern int32 runtime·gomaxprocs;
Dmitriy Vyukov34c67eb2013-05-22 22:57:47 +0400702extern uint32 runtime·needextram;
Dmitriy Vyukova2677cf2011-08-16 16:53:02 -0400703extern bool runtime·singleproc;
Russ Cox67793502011-02-16 13:21:13 -0500704extern uint32 runtime·panicking;
Russ Cox36115532013-03-01 14:57:05 -0500705extern uint32 runtime·gcwaiting; // gc is waiting to run
Shenghou Ma4019d0e2013-01-26 09:57:06 +0800706extern int8* runtime·goos;
707extern int32 runtime·ncpu;
Russ Cox9042c2c2010-12-08 13:53:30 -0500708extern bool runtime·iscgo;
Russ Cox0b08c942012-09-24 14:58:34 -0400709extern void (*runtime·sysargs)(int32, uint8**);
710extern uint32 runtime·maxstring;
Jan Ziaka656f822013-02-25 15:58:23 -0500711extern uint32 runtime·Hchansize;
Keith Randalla5d40242013-03-12 10:47:44 -0700712extern uint32 runtime·cpuid_ecx;
713extern uint32 runtime·cpuid_edx;
Dmitriy Vyukov4b536a52013-06-28 18:37:06 +0400714extern DebugVars runtime·debug;
Ken Thompson594175d2008-07-13 14:29:46 -0700715
716/*
Rob Pike8e82a672008-06-30 11:50:36 -0700717 * common functions and data
718 */
Russ Cox68b42552010-11-04 14:00:19 -0400719int32 runtime·strcmp(byte*, byte*);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400720byte* runtime·strstr(byte*, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400721int32 runtime·findnull(byte*);
Alex Brainmana41d8542011-01-12 11:48:15 +1100722int32 runtime·findnullw(uint16*);
Russ Cox68b42552010-11-04 14:00:19 -0400723void runtime·dump(byte*, int32);
724int32 runtime·runetochar(byte*, int32);
725int32 runtime·charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700726
Rob Pike8e82a672008-06-30 11:50:36 -0700727/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700728 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700729 */
Russ Cox68b42552010-11-04 14:00:19 -0400730#define FLUSH(x) USED(x)
Russ Cox4e28cfe2010-03-26 14:15:30 -0700731
Russ Coxd67e7e32013-06-12 15:22:26 -0400732void runtime·gogo(Gobuf*);
733void runtime·gostartcall(Gobuf*, void(*)(void), void*);
734void runtime·gostartcallfn(Gobuf*, FuncVal*);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500735void runtime·gosave(Gobuf*);
Russ Cox68b42552010-11-04 14:00:19 -0400736void runtime·lessstack(void);
737void runtime·goargs(void);
Alex Brainmana41d8542011-01-12 11:48:15 +1100738void runtime·goenvs(void);
739void runtime·goenvs_unix(void);
Russ Cox68b42552010-11-04 14:00:19 -0400740void* runtime·getu(void);
741void runtime·throw(int8*);
742void runtime·panicstring(int8*);
Russ Cox68b42552010-11-04 14:00:19 -0400743void runtime·prints(int8*);
744void runtime·printf(int8*, ...);
745byte* runtime·mchr(byte*, byte, byte*);
Keith Randall00224a32013-03-20 13:51:29 -0700746int32 runtime·mcmp(byte*, byte*, uintptr);
Rémy Oudompheng1b8f51c2013-03-09 00:41:03 +0100747void runtime·memmove(void*, void*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400748void* runtime·mal(uintptr);
749String runtime·catstring(String, String);
750String runtime·gostring(byte*);
Russ Cox0b08c942012-09-24 14:58:34 -0400751String runtime·gostringn(byte*, intgo);
752Slice runtime·gobytes(byte*, intgo);
Russ Cox68b42552010-11-04 14:00:19 -0400753String runtime·gostringnocopy(byte*);
Alex Brainmana41d8542011-01-12 11:48:15 +1100754String runtime·gostringw(uint16*);
Russ Cox35586f72012-02-13 13:52:37 -0500755void runtime·initsig(void);
David Symonds3d8ebef2012-02-17 14:36:40 +1100756void runtime·sigenable(uint32 sig);
Russ Coxcb4428e2013-03-15 00:00:02 -0400757void runtime·sigdisable(uint32 sig);
Russ Cox5146a932013-03-15 01:11:03 -0400758int32 runtime·gotraceback(bool *crash);
Russ Cox03e9ea52011-08-22 23:26:39 -0400759void runtime·goroutineheader(G*);
Keith Randalla5d40242013-03-12 10:47:44 -0700760int32 runtime·open(int8*, int32, int32);
761int32 runtime·read(int32, void*, int32);
Russ Cox68b42552010-11-04 14:00:19 -0400762int32 runtime·write(int32, void*, int32);
Keith Randalla5d40242013-03-12 10:47:44 -0700763int32 runtime·close(int32);
Jonathan Markddde52a2011-06-07 21:50:10 -0700764int32 runtime·mincore(void*, uintptr, byte*);
Russ Cox68b42552010-11-04 14:00:19 -0400765bool runtime·cas(uint32*, uint32, uint32);
Russ Coxfb63e4f2013-07-12 00:03:32 -0400766bool runtime·cas64(uint64*, uint64, uint64);
Russ Cox68b42552010-11-04 14:00:19 -0400767bool runtime·casp(void**, void*, void*);
Dmitriy Vyukov997c00f2011-06-28 15:09:53 -0400768// Don't confuse with XADD x86 instruction,
769// this one is actually 'addx', that is, add-and-fetch.
Russ Cox68b42552010-11-04 14:00:19 -0400770uint32 runtime·xadd(uint32 volatile*, int32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400771uint64 runtime·xadd64(uint64 volatile*, int64);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -0400772uint32 runtime·xchg(uint32 volatile*, uint32);
Dmitriy Vyukovadd33492013-03-05 09:46:52 +0200773uint64 runtime·xchg64(uint64 volatile*, uint64);
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700774uint32 runtime·atomicload(uint32 volatile*);
Dmitriy Vyukov91f0f182011-07-29 13:47:24 -0400775void runtime·atomicstore(uint32 volatile*, uint32);
Dmitriy Vyukov46675712012-04-05 18:47:43 +0400776void runtime·atomicstore64(uint64 volatile*, uint64);
777uint64 runtime·atomicload64(uint64 volatile*);
Dmitriy Vyukov86a659c2011-07-13 11:22:41 -0700778void* runtime·atomicloadp(void* volatile*);
779void runtime·atomicstorep(void* volatile*, void*);
Russ Cox1903ad72013-02-21 17:01:13 -0500780void runtime·jmpdefer(FuncVal*, void*);
Russ Cox68b42552010-11-04 14:00:19 -0400781void runtime·exit1(int32);
782void runtime·ready(G*);
783byte* runtime·getenv(int8*);
784int32 runtime·atoi(byte*);
Russ Coxe6a3e222013-03-01 11:44:43 -0500785void runtime·newosproc(M *mp, void *stk);
786void runtime·mstart(void);
Russ Cox68b42552010-11-04 14:00:19 -0400787G* runtime·malg(int32);
Russ Cox1707a992012-02-14 01:23:15 -0500788void runtime·asminit(void);
Dmitriy Vyukova0955a22013-02-21 16:24:38 +0400789void runtime·mpreinit(M*);
Russ Cox68b42552010-11-04 14:00:19 -0400790void runtime·minit(void);
Russ Cox6c976392013-02-20 17:48:23 -0500791void runtime·unminit(void);
792void runtime·signalstack(byte*, int32);
Dmitriy Vyukov081129e2013-05-28 21:10:10 +0400793void runtime·symtabinit(void);
Russ Cox68b42552010-11-04 14:00:19 -0400794Func* runtime·findfunc(uintptr);
Russ Cox5d363c62013-07-16 09:41:38 -0400795int32 runtime·funcline(Func*, uintptr, String*);
796int32 runtime·funcarglen(Func*, uintptr);
797int32 runtime·funcspdelta(Func*, uintptr);
Russ Coxc3de91b2013-07-18 10:43:22 -0400798int8* runtime·funcname(Func*);
Russ Cox68b42552010-11-04 14:00:19 -0400799void* runtime·stackalloc(uint32);
Russ Coxafc69282011-01-25 16:35:36 -0500800void runtime·stackfree(void*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400801MCache* runtime·allocmcache(void);
Dmitriy Vyukoved516df2012-07-01 13:10:01 +0400802void runtime·freemcache(MCache*);
Russ Cox68b42552010-11-04 14:00:19 -0400803void runtime·mallocinit(void);
Jan Ziak4da6b362013-01-30 09:01:31 -0800804void runtime·mprofinit(void);
Russ Cox68b42552010-11-04 14:00:19 -0400805bool runtime·ifaceeq_c(Iface, Iface);
806bool runtime·efaceeq_c(Eface, Eface);
Ian Lance Taylor63bee952013-01-04 07:53:42 -0800807uintptr runtime·ifacehash(Iface, uintptr);
808uintptr runtime·efacehash(Eface, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400809void* runtime·malloc(uintptr size);
810void runtime·free(void *v);
Russ Cox1903ad72013-02-21 17:01:13 -0500811bool runtime·addfinalizer(void*, FuncVal *fn, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400812void runtime·runpanic(Panic*);
Russ Coxe58f7982013-06-12 08:49:38 -0400813uintptr runtime·getcallersp(void*);
Russ Cox4608feb2011-01-28 15:03:26 -0500814int32 runtime·mcount(void);
Russ Coxe4b02bf2012-02-22 21:45:01 -0500815int32 runtime·gcount(void);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500816void runtime·mcall(void(*)(G*));
Dmitriy Vyukov909f3182011-07-12 01:23:58 -0400817uint32 runtime·fastrand1(void);
Russ Cox6fa3c892013-06-27 11:32:01 -0400818void runtime·rewindmorestack(Gobuf*);
Russ Coxd28acc42008-08-04 16:43:49 -0700819
Russ Cox6c976392013-02-20 17:48:23 -0500820void runtime·setmg(M*, G*);
821void runtime·newextram(void);
Russ Cox68b42552010-11-04 14:00:19 -0400822void runtime·exit(int32);
823void runtime·breakpoint(void);
824void runtime·gosched(void);
Dmitriy Vyukov1e112cd2013-06-28 17:52:17 +0400825void runtime·gosched0(G*);
Dmitriy Vyukovf20fd872012-09-18 21:15:46 +0400826void runtime·park(void(*)(Lock*), Lock*, int8*);
827void runtime·tsleep(int64, int8*);
Russ Cox3b860262011-11-09 15:17:05 -0500828M* runtime·newm(void);
Russ Cox68b42552010-11-04 14:00:19 -0400829void runtime·goexit(void);
Russ Coxf9ca3b52011-03-07 10:37:42 -0500830void runtime·asmcgocall(void (*fn)(void*), void*);
Russ Cox68b42552010-11-04 14:00:19 -0400831void runtime·entersyscall(void);
Dmitriy Vyukove25f19a2013-02-20 20:21:45 +0400832void runtime·entersyscallblock(void);
Russ Cox68b42552010-11-04 14:00:19 -0400833void runtime·exitsyscall(void);
Russ Cox1903ad72013-02-21 17:01:13 -0500834G* runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
Russ Cox68b42552010-11-04 14:00:19 -0400835bool runtime·sigsend(int32 sig);
Russ Cox68b42552010-11-04 14:00:19 -0400836int32 runtime·callers(int32, uintptr*, int32);
837int64 runtime·nanotime(void);
838void runtime·dopanic(int32);
Russ Cox67793502011-02-16 13:21:13 -0500839void runtime·startpanic(void);
Dmitriy Vyukova54f920b2012-07-04 14:52:51 +0400840void runtime·unwindstack(G*, byte*);
Russ Coxc19b3732011-03-23 11:43:37 -0400841void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
842void runtime·resetcpuprofiler(int32);
843void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
Russ Coxd324f212011-09-30 09:40:01 -0400844void runtime·usleep(uint32);
Damian Gryski8e765da2012-02-02 14:09:27 -0500845int64 runtime·cputicks(void);
Dmitriy Vyukov4cc7bf32012-10-06 12:56:04 +0400846int64 runtime·tickspersecond(void);
847void runtime·blockevent(int64, int32);
848extern int64 runtime·blockprofilerate;
Dmitriy Vyukovd0c11d22013-03-05 09:38:15 +0200849void runtime·addtimer(Timer*);
850bool runtime·deltimer(Timer*);
Dmitriy Vyukovc2118842013-03-12 21:14:26 +0400851G* runtime·netpoll(bool);
Dmitriy Vyukov0bee99a2013-03-14 10:38:37 +0400852void runtime·netpollinit(void);
Alex Brainman38abb092013-05-20 12:55:50 +1000853int32 runtime·netpollopen(uintptr, PollDesc*);
854int32 runtime·netpollclose(uintptr);
Dmitriy Vyukov0bee99a2013-03-14 10:38:37 +0400855void runtime·netpollready(G**, PollDesc*, int32);
Russ Cox5146a932013-03-15 01:11:03 -0400856void runtime·crash(void);
Dmitriy Vyukov4b536a52013-06-28 18:37:06 +0400857void runtime·parsedebugvars(void);
Russ Coxe58f7982013-06-12 08:49:38 -0400858void _rt0_go(void);
Russ Cox48769bf2013-07-19 16:04:09 -0400859void* runtime·funcdata(Func*, int32);
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800860
Russ Cox68b42552010-11-04 14:00:19 -0400861#pragma varargck argpos runtime·printf 1
Carl Shapiro4e0a51c2013-05-28 17:59:10 -0700862#pragma varargck type "c" int32
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800863#pragma varargck type "d" int32
864#pragma varargck type "d" uint32
865#pragma varargck type "D" int64
866#pragma varargck type "D" uint64
867#pragma varargck type "x" int32
868#pragma varargck type "x" uint32
869#pragma varargck type "X" int64
870#pragma varargck type "X" uint64
871#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700872#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800873#pragma varargck type "s" int8*
874#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700875#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800876
Russ Cox68b42552010-11-04 14:00:19 -0400877void runtime·stoptheworld(void);
Dmitriy Vyukov01826282012-05-15 19:10:16 +0400878void runtime·starttheworld(void);
Russ Coxe4b02bf2012-02-22 21:45:01 -0500879extern uint32 runtime·worldsema;
Russ Cox3f8aa662008-12-05 15:24:18 -0800880
Russ Coxd28acc42008-08-04 16:43:49 -0700881/*
882 * mutual exclusion locks. in the uncontended case,
883 * as fast as spin locks (just a few user-level instructions),
884 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700885 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700886 */
Russ Cox68b42552010-11-04 14:00:19 -0400887void runtime·lock(Lock*);
888void runtime·unlock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700889
890/*
Russ Coxa68592a2009-10-14 13:02:05 -0700891 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700892 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700893 * must call noteclear to initialize the Note.
Dmitriy Vyukova496c9e2011-08-03 15:51:55 -0400894 * then, exactly one thread can call notesleep
Russ Cox96824002008-08-05 14:18:47 -0700895 * and exactly one thread can call notewakeup (once).
Dmitriy Vyukova496c9e2011-08-03 15:51:55 -0400896 * once notewakeup has been called, the notesleep
897 * will return. future notesleep will return immediately.
898 * subsequent noteclear must be called only after
899 * previous notesleep has returned, e.g. it's disallowed
900 * to call noteclear straight after notewakeup.
Russ Cox3b860262011-11-09 15:17:05 -0500901 *
902 * notetsleep is like notesleep but wakes up after
903 * a given number of nanoseconds even if the event
904 * has not yet happened. if a goroutine uses notetsleep to
905 * wake up early, it must wait to call noteclear until it
906 * can be sure that no other goroutine is calling
907 * notewakeup.
Dmitriy Vyukove97d6772013-07-22 23:02:27 +0400908 *
909 * notesleep/notetsleep are generally called on g0,
910 * notetsleepg is similar to notetsleep but is called on user g.
Russ Coxd28acc42008-08-04 16:43:49 -0700911 */
Russ Cox68b42552010-11-04 14:00:19 -0400912void runtime·noteclear(Note*);
913void runtime·notesleep(Note*);
914void runtime·notewakeup(Note*);
Dmitriy Vyukove932c202013-05-29 11:49:45 +0400915bool runtime·notetsleep(Note*, int64); // false - timeout
Dmitriy Vyukove97d6772013-07-22 23:02:27 +0400916bool runtime·notetsleepg(Note*, int64); // false - timeout
Russ Cox3b860262011-11-09 15:17:05 -0500917
918/*
919 * low-level synchronization for implementing the above
920 */
921uintptr runtime·semacreate(void);
922int32 runtime·semasleep(int64);
923void runtime·semawakeup(M*);
924// or
925void runtime·futexsleep(uint32*, uint32, int64);
926void runtime·futexwakeup(uint32*, uint32);
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800927
928/*
Dmitriy Vyukova5dc7792012-04-12 11:49:25 +0400929 * Lock-free stack.
930 * Initialize uint64 head to 0, compare with 0 to test for emptiness.
931 * The stack does not keep pointers to nodes,
932 * so they can be garbage collected if there are no other pointers to nodes.
933 */
934void runtime·lfstackpush(uint64 *head, LFNode *node);
935LFNode* runtime·lfstackpop(uint64 *head);
936
937/*
Dmitriy Vyukov95643642012-05-11 10:50:03 +0400938 * Parallel for over [0, n).
939 * body() is executed for each iteration.
940 * nthr - total number of worker threads.
941 * ctx - arbitrary user context.
942 * if wait=true, threads return from parfor() when all work is done;
943 * otherwise, threads can return while other threads are still finishing processing.
944 */
945ParFor* runtime·parforalloc(uint32 nthrmax);
946void runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32));
947void runtime·parfordo(ParFor *desc);
948
949/*
Adam Langley3f7a3242009-11-13 10:08:51 -0800950 * This is consistent across Linux and BSD.
951 * If a new OS is added that is different, move this to
952 * $GOOS/$GOARCH/defs.h.
953 */
954#define EACCES 13
955
956/*
Russ Coxafc69282011-01-25 16:35:36 -0500957 * low level C-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700958 */
Shenghou Mab151af12012-09-21 13:50:02 +0800959// for mmap, we only pass the lower 32 bits of file offset to the
960// assembly routine; the higher bits (if required), should be provided
961// by the assembly routine as 0.
Russ Cox68b42552010-11-04 14:00:19 -0400962uint8* runtime·mmap(byte*, uintptr, int32, int32, int32, uint32);
Russ Coxe83cd7f2011-12-20 17:54:40 -0500963void runtime·munmap(byte*, uintptr);
964void runtime·madvise(byte*, uintptr, int32);
Russ Coxafc69282011-01-25 16:35:36 -0500965void runtime·memclr(byte*, uintptr);
Russ Cox68b42552010-11-04 14:00:19 -0400966void runtime·setcallerpc(void*, void*);
967void* runtime·getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700968
969/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700970 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700971 */
Russ Cox68b42552010-11-04 14:00:19 -0400972void runtime·printbool(bool);
Carl Shapiro7f9c02a2013-02-19 18:05:44 -0800973void runtime·printbyte(int8);
Russ Cox68b42552010-11-04 14:00:19 -0400974void runtime·printfloat(float64);
975void runtime·printint(int64);
976void runtime·printiface(Iface);
977void runtime·printeface(Eface);
978void runtime·printstring(String);
979void runtime·printpc(void*);
980void runtime·printpointer(void*);
981void runtime·printuint(uint64);
982void runtime·printhex(uint64);
983void runtime·printslice(Slice);
984void runtime·printcomplex(Complex128);
Russ Cox1903ad72013-02-21 17:01:13 -0500985void reflect·call(FuncVal*, byte*, uint32);
Russ Cox68b42552010-11-04 14:00:19 -0400986void runtime·panic(Eface);
987void runtime·panicindex(void);
988void runtime·panicslice(void);
Russ Cox7c2b1592010-10-25 17:55:50 -0700989
Russ Cox63e878a2010-03-31 15:55:10 -0700990/*
991 * runtime c-called (but written in Go)
992 */
Russ Cox68b42552010-11-04 14:00:19 -0400993void runtime·printany(Eface);
Russ Cox6a75ece2012-02-12 23:26:20 -0500994void runtime·newTypeAssertionError(String*, String*, String*, String*, Eface*);
Russ Cox68b42552010-11-04 14:00:19 -0400995void runtime·newErrorString(String, Eface*);
996void runtime·fadd64c(uint64, uint64, uint64*);
997void runtime·fsub64c(uint64, uint64, uint64*);
998void runtime·fmul64c(uint64, uint64, uint64*);
999void runtime·fdiv64c(uint64, uint64, uint64*);
1000void runtime·fneg64c(uint64, uint64*);
1001void runtime·f32to64c(uint32, uint64*);
1002void runtime·f64to32c(uint64, uint32*);
1003void runtime·fcmp64c(uint64, uint64, int32*, bool*);
1004void runtime·fintto64c(int64, uint64*);
1005void runtime·f64tointc(uint64, int64*, bool*);
Rob Pike6db99de2008-07-08 10:36:43 -07001006
1007/*
Russ Cox1f8a40d2009-01-22 16:23:44 -08001008 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -07001009 */
Russ Cox68b42552010-11-04 14:00:19 -04001010float64 runtime·Inf(int32 sign);
1011float64 runtime·NaN(void);
1012float32 runtime·float32frombits(uint32 i);
1013uint32 runtime·float32tobits(float32 f);
1014float64 runtime·float64frombits(uint64 i);
1015uint64 runtime·float64tobits(float64 f);
1016float64 runtime·frexp(float64 d, int32 *ep);
1017bool runtime·isInf(float64 f, int32 sign);
1018bool runtime·isNaN(float64 f);
1019float64 runtime·ldexp(float64 d, int32 e);
1020float64 runtime·modf(float64 d, float64 *ip);
1021void runtime·semacquire(uint32*);
1022void runtime·semrelease(uint32*);
Russ Cox68b42552010-11-04 14:00:19 -04001023int32 runtime·gomaxprocsfunc(int32 n);
Dmitriy Vyukov4e5086b2011-07-29 12:44:06 -04001024void runtime·procyield(uint32);
1025void runtime·osyield(void);
Russ Coxb0a29f32013-02-01 08:34:41 -08001026void runtime·lockOSThread(void);
1027void runtime·unlockOSThread(void);
David Symondsb5866492009-12-15 18:21:29 -08001028
Russ Cox65bde082011-08-17 14:56:27 -04001029void runtime·mapassign(MapType*, Hmap*, byte*, byte*);
1030void runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*);
Russ Cox68b42552010-11-04 14:00:19 -04001031void runtime·mapiternext(struct hash_iter*);
1032bool runtime·mapiterkey(struct hash_iter*, void*);
Russ Cox65bde082011-08-17 14:56:27 -04001033Hmap* runtime·makemap_c(MapType*, int64);
Russ Cox5ddaf9a2009-07-08 15:00:54 -07001034
Russ Cox3770b0e2011-08-17 15:54:17 -04001035Hchan* runtime·makechan_c(ChanType*, int64);
Dmitriy Vyukov2f6cbc72012-10-07 22:05:32 +04001036void runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*);
Russ Cox33e9d242011-08-23 13:13:27 -04001037void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
Russ Cox6fa3c892013-06-27 11:32:01 -04001038bool runtime·showframe(Func*, G*);
Russ Cox5ddaf9a2009-07-08 15:00:54 -07001039
Jan Ziak5c1422a2012-11-01 13:13:20 -04001040void runtime·ifaceE2I(InterfaceType*, Eface, Iface*);
Russ Coxafc69282011-01-25 16:35:36 -05001041
Russ Cox102274a2012-02-24 15:28:51 -05001042uintptr runtime·memlimit(void);
Russ Cox6e2ae0a2012-02-28 16:18:24 -05001043
1044// If appropriate, ask the operating system to control whether this
1045// thread should receive profiling signals. This is only necessary on OS X.
1046// An operating system should not deliver a profiling signal to a
1047// thread that is not actually executing (what good is that?), but that's
1048// what OS X prefers to do. When profiling is turned on, we mask
1049// away the profiling signal when threads go to sleep, so that OS X
1050// is forced to deliver the signal to a thread that's actually running.
1051// This is a no-op on other systems.
1052void runtime·setprof(bool);
Shenghou Ma0157c722012-08-07 23:45:50 +08001053
1054// float.c
1055extern float64 runtime·nan;
1056extern float64 runtime·posinf;
1057extern float64 runtime·neginf;
1058extern uint64 ·nan;
1059extern uint64 ·posinf;
1060extern uint64 ·neginf;
1061#define ISNAN(f) ((f) != (f))
Jan Ziakf8c58372012-09-24 20:08:05 -04001062
1063enum
1064{
Dmitriy Vyukov5b79aa82013-03-14 13:48:19 +04001065 UseSpanType = 1,
Jan Ziakf8c58372012-09-24 20:08:05 -04001066};