46
50
typedef struct Func Func;
47
51
typedef struct G G;
48
52
typedef struct Gobuf Gobuf;
49
typedef union Lock Lock;
53
typedef struct Lock Lock;
50
54
typedef struct M M;
51
56
typedef struct Mem Mem;
52
typedef union Note Note;
57
typedef struct Note Note;
53
58
typedef struct Slice Slice;
54
59
typedef struct Stktop Stktop;
55
60
typedef struct String String;
61
typedef struct FuncVal FuncVal;
56
62
typedef struct SigTab SigTab;
57
63
typedef struct MCache MCache;
58
64
typedef struct FixAlloc FixAlloc;
59
65
typedef struct Iface Iface;
60
66
typedef struct Itab Itab;
67
typedef struct InterfaceType InterfaceType;
61
68
typedef struct Eface Eface;
62
69
typedef struct Type Type;
63
70
typedef struct ChanType ChanType;
64
71
typedef struct MapType MapType;
65
72
typedef struct Defer Defer;
73
typedef struct DeferChunk DeferChunk;
66
74
typedef struct Panic Panic;
67
75
typedef struct Hmap Hmap;
68
76
typedef struct Hchan Hchan;
69
77
typedef struct Complex64 Complex64;
70
78
typedef struct Complex128 Complex128;
71
79
typedef struct WinCall WinCall;
80
typedef struct SEH SEH;
72
81
typedef struct Timers Timers;
73
82
typedef struct Timer Timer;
83
typedef struct GCStats GCStats;
84
typedef struct LFNode LFNode;
85
typedef struct ParFor ParFor;
86
typedef struct ParForThread ParForThread;
87
typedef struct CgoMal CgoMal;
88
typedef struct PollDesc PollDesc;
76
* per-cpu declaration.
91
* Per-CPU declaration.
77
93
* "extern register" is a special storage class implemented by 6c, 8c, etc.
78
* on machines with lots of registers, it allocates a register that will not be
79
* used in generated code. on the x86, it allocates a slot indexed by a
82
* amd64: allocated downwards from R15
83
* x86: allocated upwards from 0(GS)
84
* arm: allocated downwards from R10
86
* every C file linked into a Go program must include runtime.h
87
* so that the C compiler knows to avoid other uses of these registers.
88
* the Go compilers know to avoid them.
94
* On the ARM, it is an actual register; elsewhere it is a slot in thread-
95
* local storage indexed by a segment register. See zasmhdr in
96
* src/cmd/dist/buildruntime.c for details, and be aware that the linker may
97
* make further OS-specific changes to the compiler's output. For example,
98
* 6l/linux rewrites 0(GS) as -16(FS).
100
* Every C file linked into a Go program must include runtime.h so that the
101
* C compiler (6c, 8c, etc.) knows to avoid other uses of these dedicated
102
* registers. The Go compiler (6g, 8g, etc.) knows to avoid them.
90
104
extern register G* g;
91
105
extern register M* m;
122
Gmoribund_unused, // currently unused, but hardcoded in gdb scripts
141
PtrSize = sizeof(void*),
145
// Per-M stack segment cache size.
147
// Global <-> per-M stack segment cache transfer batch size.
148
StackCacheBatch = 16,
152
// This value is generated by the linker and should be kept in
153
// sync with cmd/ld/lib.h
154
ArgsSizeUnknown = 0x80000000,
122
uint32 key; // futex-based impl
123
M* waitm; // linked list of waiting M's (sema-based impl)
161
// Futex-based impl treats it as uint32 key,
162
// while sema-based impl as M* waitm.
163
// Used to be a union, but unions break precise GC.
127
uint32 key; // futex-based impl
128
M* waitm; // waiting M (sema-based impl)
168
// Futex-based impl treats it as uint32 key,
169
// while sema-based impl as M* waitm.
170
// Used to be a union, but unions break precise GC.
181
// variable-size, fn-specific data here
157
205
{ // must not move anything
158
206
byte* array; // actual data
159
uint32 len; // number of elements
160
uint32 cap; // allocated number of elements
207
uintgo len; // number of elements
208
uintgo cap; // allocated number of elements
164
212
// The offsets of these fields are known to (hard-coded in) libmach.
219
// the struct must consist of only uint64's,
220
// because it is casted to uint64[].
171
byte* stackguard; // cannot move - also known to linker, libmach, runtime/cgo
172
byte* stackbase; // cannot move - also known to libmach, runtime/cgo
229
uintptr stackguard; // cannot move - also known to linker, libmach, runtime/cgo
230
uintptr stackbase; // cannot move - also known to libmach, runtime/cgo
176
byte* gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
177
byte* gcsp; // if status==Gsyscall, gcsp = sched.sp to use during gc
178
byte* gcguard; // if status==Gsyscall, gcguard = stackguard to use during gc
180
byte* entry; // initial function
234
uintptr gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
235
uintptr gcsp; // if status==Gsyscall, gcsp = sched.sp to use during gc
236
byte* gcpc; // if status==Gsyscall, gcpc = sched.pc to use during gc
237
uintptr gcguard; // if status==Gsyscall, gcguard = stackguard to use during gc
239
FuncVal* fnstart; // initial function
181
240
G* alllink; // on allg
182
241
void* param; // passed parameter on wakeup
185
244
uint32 selgen; // valid sudog pointer
186
245
int8* waitreason; // if status==Gwaiting
248
bool issystem; // do not output in stack dump
249
bool isbackground; // ignore in deadlock detector
250
bool blockingsyscall; // hint that the next syscall will block
251
int8 raceignore; // ignore race detection events
190
252
M* m; // for debuggers, but offset not hard-coded
258
DeferChunk *dchunknext;
196
259
uintptr sigcode0;
197
260
uintptr sigcode1;
199
262
uintptr gopc; // pc of go statement that created this goroutine
213
277
uintptr cret; // return value from C
214
278
uint64 procid; // for debuggers, but offset not hard-coded
215
279
G* gsignal; // signal-handling G
216
uint32 tls[8]; // thread-local storage (for 386 extern register)
280
uintptr tls[4]; // thread-local storage (for x86 extern register)
281
void (*mstartfn)(void);
217
282
G* curg; // current running goroutine
283
P* p; // attached P for executing Go code (nil if not executing Go code)
294
bool blockingsyscall;
297
uint64 ncgocall; // number of cgo calls in total
298
int32 ncgo; // number of cgo calls currently in progress
231
301
M* alllink; // on allm
233
303
uint32 machport; // Return address for Mach IPC (OS X)
235
FixAlloc *stackalloc;
306
uint32 stackcachepos;
307
uint32 stackcachecnt;
308
void* stackcache[StackCacheSize];
238
310
uintptr createstack[32]; // Stack that created this thread.
239
311
uint32 freglo[16]; // D[i] lsb and F[i]
240
312
uint32 freghi[16]; // D[i] msb and F[i+16]
241
313
uint32 fflag; // floating point compare flags
314
uint32 locked; // tracking for LockOSThread
242
315
M* nextwaitm; // next M waiting for lock
243
316
uintptr waitsema; // semaphore for parking on locks
244
317
uint32 waitsemacount;
245
318
uint32 waitsemalock;
323
void (*waitunlockf)(Lock*);
325
uint32 moreframesize_minalloc;
327
uintptr settype_buf[1024];
328
uintptr settype_bufsize;
247
330
#ifdef GOOS_windows
248
331
void* thread; // thread handle
345
uint32 status; // one of Pidle/Prunning/...
347
uint32 tick; // incremented on every scheduler or system call
348
M* m; // back-link to associated M (nil if idle)
351
// Queue of runnable goroutines.
357
// Available G's (status == Gdead)
364
// The m->locked word holds a single bit saying whether
365
// external calls to LockOSThread are in effect, and then a counter
366
// of the internal nesting depth of lockOSThread / unlockOSThread.
255
375
// The offsets of these fields are known to (hard-coded in) libmach.
335
473
// a well-behaved function and not block.
338
void (*f)(int64, Eface);
480
// Lock-free stack node.
487
// Parallel for descriptor.
490
void (*body)(ParFor*, uint32); // executed for each element
491
uint32 done; // number of idle threads
492
uint32 nthr; // total number of threads
493
uint32 nthrmax; // maximum number of threads
494
uint32 thrseq; // thread id sequencer
495
uint32 cnt; // iteration space [0, cnt)
496
void *ctx; // arbitrary user context
497
bool wait; // if true, wait while all threads finish processing,
498
// otherwise parfor may return while other threads are still working
499
ParForThread *thr; // array of thread descriptors
500
uint32 pad; // to align ParForThread.pos for 64-bit atomic operations
509
// Track memory allocated by code not written in Go during a cgo call,
510
// so that the garbage collector can see them.
344
519
* you need super-gopher-guru privilege
396
572
extern Alg runtime·algarray[Amax];
574
byte* runtime·startup_random_data;
575
uint32 runtime·startup_random_data_len;
576
void runtime·get_random_data(byte**, int32*);
579
// hashinit wants this many random bytes
582
void runtime·hashinit(void);
398
584
void runtime·memhash(uintptr*, uintptr, void*);
399
585
void runtime·nohash(uintptr*, uintptr, void*);
400
586
void runtime·strhash(uintptr*, uintptr, void*);
401
587
void runtime·interhash(uintptr*, uintptr, void*);
402
588
void runtime·nilinterhash(uintptr*, uintptr, void*);
589
void runtime·aeshash(uintptr*, uintptr, void*);
590
void runtime·aeshash32(uintptr*, uintptr, void*);
591
void runtime·aeshash64(uintptr*, uintptr, void*);
592
void runtime·aeshashstr(uintptr*, uintptr, void*);
404
594
void runtime·memequal(bool*, uintptr, void*, void*);
405
595
void runtime·noequal(bool*, uintptr, void*, void*);
490
696
void* runtime·getu(void);
491
697
void runtime·throw(int8*);
492
698
void runtime·panicstring(int8*);
493
uint32 runtime·rnd(uint32, uint32);
494
699
void runtime·prints(int8*);
495
700
void runtime·printf(int8*, ...);
496
701
byte* runtime·mchr(byte*, byte, byte*);
497
int32 runtime·mcmp(byte*, byte*, uint32);
498
void runtime·memmove(void*, void*, uint32);
702
int32 runtime·mcmp(byte*, byte*, uintptr);
703
void runtime·memmove(void*, void*, uintptr);
499
704
void* runtime·mal(uintptr);
500
705
String runtime·catstring(String, String);
501
706
String runtime·gostring(byte*);
502
String runtime·gostringn(byte*, int32);
503
Slice runtime·gobytes(byte*, int32);
707
String runtime·gostringn(byte*, intgo);
708
Slice runtime·gobytes(byte*, intgo);
504
709
String runtime·gostringnocopy(byte*);
505
710
String runtime·gostringw(uint16*);
506
711
void runtime·initsig(void);
507
712
void runtime·sigenable(uint32 sig);
508
int32 runtime·gotraceback(void);
713
void runtime·sigdisable(uint32 sig);
714
int32 runtime·gotraceback(bool *crash);
509
715
void runtime·goroutineheader(G*);
510
716
void runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp);
511
717
void runtime·tracebackothers(G*);
718
int32 runtime·open(int8*, int32, int32);
719
int32 runtime·read(int32, void*, int32);
512
720
int32 runtime·write(int32, void*, int32);
721
int32 runtime·close(int32);
513
722
int32 runtime·mincore(void*, uintptr, byte*);
514
723
bool runtime·cas(uint32*, uint32, uint32);
724
bool runtime·cas64(uint64*, uint64*, uint64);
515
725
bool runtime·casp(void**, void*, void*);
516
726
// Don't confuse with XADD x86 instruction,
517
727
// this one is actually 'addx', that is, add-and-fetch.
518
728
uint32 runtime·xadd(uint32 volatile*, int32);
729
uint64 runtime·xadd64(uint64 volatile*, int64);
519
730
uint32 runtime·xchg(uint32 volatile*, uint32);
731
uint64 runtime·xchg64(uint64 volatile*, uint64);
520
732
uint32 runtime·atomicload(uint32 volatile*);
521
733
void runtime·atomicstore(uint32 volatile*, uint32);
734
void runtime·atomicstore64(uint64 volatile*, uint64);
735
uint64 runtime·atomicload64(uint64 volatile*);
522
736
void* runtime·atomicloadp(void* volatile*);
523
737
void runtime·atomicstorep(void* volatile*, void*);
524
void runtime·jmpdefer(byte*, void*);
738
void runtime·jmpdefer(FuncVal*, void*);
525
739
void runtime·exit1(int32);
526
740
void runtime·ready(G*);
527
741
byte* runtime·getenv(int8*);
528
742
int32 runtime·atoi(byte*);
529
void runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void));
530
void runtime·signalstack(byte*, int32);
743
void runtime·newosproc(M *mp, void *stk);
744
void runtime·mstart(void);
531
745
G* runtime·malg(int32);
532
746
void runtime·asminit(void);
747
void runtime·mpreinit(M*);
533
748
void runtime·minit(void);
749
void runtime·unminit(void);
750
void runtime·signalstack(byte*, int32);
534
751
Func* runtime·findfunc(uintptr);
535
752
int32 runtime·funcline(Func*, uintptr);
536
753
void* runtime·stackalloc(uint32);
537
754
void runtime·stackfree(void*, uintptr);
538
755
MCache* runtime·allocmcache(void);
756
void runtime·freemcache(MCache*);
539
757
void runtime·mallocinit(void);
758
void runtime·mprofinit(void);
540
759
bool runtime·ifaceeq_c(Iface, Iface);
541
760
bool runtime·efaceeq_c(Eface, Eface);
542
uintptr runtime·ifacehash(Iface);
543
uintptr runtime·efacehash(Eface);
761
uintptr runtime·ifacehash(Iface, uintptr);
762
uintptr runtime·efacehash(Eface, uintptr);
544
763
void* runtime·malloc(uintptr size);
545
764
void runtime·free(void *v);
546
bool runtime·addfinalizer(void*, void(*fn)(void*), int32);
765
bool runtime·addfinalizer(void*, FuncVal *fn, uintptr);
547
766
void runtime·runpanic(Panic*);
548
767
void* runtime·getcallersp(void*);
549
768
int32 runtime·mcount(void);
551
770
void runtime·mcall(void(*)(G*));
552
771
uint32 runtime·fastrand1(void);
773
void runtime·setmg(M*, G*);
774
void runtime·newextram(void);
554
775
void runtime·exit(int32);
555
776
void runtime·breakpoint(void);
556
777
void runtime·gosched(void);
557
void runtime·tsleep(int64);
778
void runtime·park(void(*)(Lock*), Lock*, int8*);
779
void runtime·tsleep(int64, int8*);
558
780
M* runtime·newm(void);
559
781
void runtime·goexit(void);
560
782
void runtime·asmcgocall(void (*fn)(void*), void*);
561
783
void runtime·entersyscall(void);
784
void runtime·entersyscallblock(void);
562
785
void runtime·exitsyscall(void);
563
G* runtime·newproc1(byte*, byte*, int32, int32, void*);
786
G* runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
564
787
bool runtime·sigsend(int32 sig);
565
788
int32 runtime·callers(int32, uintptr*, int32);
566
int32 runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32);
789
int32 runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32, void (*)(Func*, byte*, byte*, void*), void*);
567
790
int64 runtime·nanotime(void);
568
791
void runtime·dopanic(int32);
569
792
void runtime·startpanic(void);
793
void runtime·unwindstack(G*, byte*);
570
794
void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
571
795
void runtime·resetcpuprofiler(int32);
572
796
void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
573
797
void runtime·usleep(uint32);
574
798
int64 runtime·cputicks(void);
799
int64 runtime·tickspersecond(void);
800
void runtime·blockevent(int64, int32);
801
extern int64 runtime·blockprofilerate;
802
void runtime·addtimer(Timer*);
803
bool runtime·deltimer(Timer*);
804
G* runtime·netpoll(bool);
805
void runtime·netpollinit(void);
806
int32 runtime·netpollopen(int32, PollDesc*);
807
int32 runtime·netpollclose(int32);
808
void runtime·netpollready(G**, PollDesc*, int32);
809
void runtime·crash(void);
576
811
#pragma varargck argpos runtime·printf 1
577
812
#pragma varargck type "d" int32
636
871
void runtime·futexwakeup(uint32*, uint32);
875
* Initialize uint64 head to 0, compare with 0 to test for emptiness.
876
* The stack does not keep pointers to nodes,
877
* so they can be garbage collected if there are no other pointers to nodes.
879
void runtime·lfstackpush(uint64 *head, LFNode *node);
880
LFNode* runtime·lfstackpop(uint64 *head);
883
* Parallel for over [0, n).
884
* body() is executed for each iteration.
885
* nthr - total number of worker threads.
886
* ctx - arbitrary user context.
887
* if wait=true, threads return from parfor() when all work is done;
888
* otherwise, threads can return while other threads are still finishing processing.
890
ParFor* runtime·parforalloc(uint32 nthrmax);
891
void runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32));
892
void runtime·parfordo(ParFor *desc);
639
895
* This is consistent across Linux and BSD.
640
896
* If a new OS is added that is different, move this to
641
897
* $GOOS/$GOARCH/defs.h.
708
968
int32 runtime·gomaxprocsfunc(int32 n);
709
969
void runtime·procyield(uint32);
710
970
void runtime·osyield(void);
711
void runtime·LockOSThread(void);
712
void runtime·UnlockOSThread(void);
971
void runtime·lockOSThread(void);
972
void runtime·unlockOSThread(void);
714
974
void runtime·mapassign(MapType*, Hmap*, byte*, byte*);
715
975
void runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*);
716
976
void runtime·mapiternext(struct hash_iter*);
717
977
bool runtime·mapiterkey(struct hash_iter*, void*);
718
void runtime·mapiterkeyvalue(struct hash_iter*, void*, void*);
719
978
Hmap* runtime·makemap_c(MapType*, int64);
721
980
Hchan* runtime·makechan_c(ChanType*, int64);
722
void runtime·chansend(ChanType*, Hchan*, byte*, bool*);
981
void runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*);
723
982
void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
724
int32 runtime·chanlen(Hchan*);
725
int32 runtime·chancap(Hchan*);
726
bool runtime·showframe(Func*);
983
bool runtime·showframe(Func*, bool);
728
void runtime·ifaceE2I(struct InterfaceType*, Eface, Iface*);
985
void runtime·ifaceE2I(InterfaceType*, Eface, Iface*);
730
987
uintptr runtime·memlimit(void);