github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/runtime/runtime.h (about) 1 // 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 5 /* 6 * basic types 7 */ 8 typedef signed char int8; 9 typedef unsigned char uint8; 10 typedef signed short int16; 11 typedef unsigned short uint16; 12 typedef signed int int32; 13 typedef unsigned int uint32; 14 typedef signed long long int int64; 15 typedef unsigned long long int uint64; 16 typedef float float32; 17 typedef double float64; 18 19 #ifdef _64BIT 20 typedef uint64 uintptr; 21 typedef int64 intptr; 22 typedef int64 intgo; // Go's int 23 typedef uint64 uintgo; // Go's uint 24 #else 25 typedef uint32 uintptr; 26 typedef int32 intptr; 27 typedef int32 intgo; // Go's int 28 typedef uint32 uintgo; // Go's uint 29 #endif 30 31 /* 32 * get rid of C types 33 * the / / / forces a syntax error immediately, 34 * which will show "last name: XXunsigned". 35 */ 36 #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 / / / 44 45 /* 46 * defined types 47 */ 48 typedef uint8 bool; 49 typedef uint8 byte; 50 typedef struct Func Func; 51 typedef struct G G; 52 typedef struct Gobuf Gobuf; 53 typedef struct Lock Lock; 54 typedef struct M M; 55 typedef struct P P; 56 typedef struct Mem Mem; 57 typedef struct Note Note; 58 typedef struct Slice Slice; 59 typedef struct Stktop Stktop; 60 typedef struct String String; 61 typedef struct FuncVal FuncVal; 62 typedef struct SigTab SigTab; 63 typedef struct MCache MCache; 64 typedef struct FixAlloc FixAlloc; 65 typedef struct Iface Iface; 66 typedef struct Itab Itab; 67 typedef struct InterfaceType InterfaceType; 68 typedef struct Eface Eface; 69 typedef struct Type Type; 70 typedef struct ChanType ChanType; 71 typedef struct MapType MapType; 72 typedef struct Defer Defer; 73 typedef struct DeferChunk DeferChunk; 74 typedef struct Panic Panic; 75 typedef struct Hmap Hmap; 76 typedef struct Hchan Hchan; 77 typedef struct Complex64 Complex64; 78 typedef struct Complex128 Complex128; 79 typedef struct WinCall WinCall; 80 typedef struct SEH SEH; 81 typedef struct Timers Timers; 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; 89 90 /* 91 * Per-CPU declaration. 92 * 93 * "extern register" is a special storage class implemented by 6c, 8c, etc. 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). 99 * 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. 103 */ 104 extern register G* g; 105 extern register M* m; 106 107 /* 108 * defined constants 109 */ 110 enum 111 { 112 // G status 113 // 114 // If you add to this list, add to the list 115 // of "okay during garbage collection" status 116 // in mgc0.c too. 117 Gidle, 118 Grunnable, 119 Grunning, 120 Gsyscall, 121 Gwaiting, 122 Gmoribund_unused, // currently unused, but hardcoded in gdb scripts 123 Gdead, 124 }; 125 enum 126 { 127 // P status 128 Pidle, 129 Prunning, 130 Psyscall, 131 Pgcstop, 132 Pdead, 133 }; 134 enum 135 { 136 true = 1, 137 false = 0, 138 }; 139 enum 140 { 141 PtrSize = sizeof(void*), 142 }; 143 enum 144 { 145 // Per-M stack segment cache size. 146 StackCacheSize = 32, 147 // Global <-> per-M stack segment cache transfer batch size. 148 StackCacheBatch = 16, 149 }; 150 enum 151 { 152 // This value is generated by the linker and should be kept in 153 // sync with cmd/ld/lib.h 154 ArgsSizeUnknown = 0x80000000, 155 }; 156 /* 157 * structures 158 */ 159 struct Lock 160 { 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. 164 uintptr key; 165 }; 166 struct Note 167 { 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. 171 uintptr key; 172 }; 173 struct String 174 { 175 byte* str; 176 intgo len; 177 }; 178 struct FuncVal 179 { 180 void (*fn)(void); 181 // variable-size, fn-specific data here 182 }; 183 struct Iface 184 { 185 Itab* tab; 186 void* data; 187 }; 188 struct Eface 189 { 190 Type* type; 191 void* data; 192 }; 193 struct Complex64 194 { 195 float32 real; 196 float32 imag; 197 }; 198 struct Complex128 199 { 200 float64 real; 201 float64 imag; 202 }; 203 204 struct Slice 205 { // must not move anything 206 byte* array; // actual data 207 uintgo len; // number of elements 208 uintgo cap; // allocated number of elements 209 }; 210 struct Gobuf 211 { 212 // The offsets of these fields are known to (hard-coded in) libmach. 213 uintptr sp; 214 byte* pc; 215 G* g; 216 }; 217 struct GCStats 218 { 219 // the struct must consist of only uint64's, 220 // because it is casted to uint64[]. 221 uint64 nhandoff; 222 uint64 nhandoffcnt; 223 uint64 nprocyield; 224 uint64 nosyield; 225 uint64 nsleep; 226 }; 227 struct G 228 { 229 uintptr stackguard; // cannot move - also known to linker, libmach, runtime/cgo 230 uintptr stackbase; // cannot move - also known to libmach, runtime/cgo 231 Defer* defer; 232 Panic* panic; 233 Gobuf sched; 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 238 uintptr stack0; 239 FuncVal* fnstart; // initial function 240 G* alllink; // on allg 241 void* param; // passed parameter on wakeup 242 int16 status; 243 int64 goid; 244 uint32 selgen; // valid sudog pointer 245 int8* waitreason; // if status==Gwaiting 246 G* schedlink; 247 bool ispanic; 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 252 M* m; // for debuggers, but offset not hard-coded 253 M* lockedm; 254 int32 sig; 255 int32 writenbuf; 256 byte* writebuf; 257 DeferChunk *dchunk; 258 DeferChunk *dchunknext; 259 uintptr sigcode0; 260 uintptr sigcode1; 261 uintptr sigpc; 262 uintptr gopc; // pc of go statement that created this goroutine 263 uintptr racectx; 264 uintptr end[]; 265 }; 266 struct M 267 { 268 // The offsets of these fields are known to (hard-coded in) libmach. 269 G* g0; // goroutine with scheduling stack 270 void (*morepc)(void); 271 void* moreargp; // argument pointer for more stack 272 Gobuf morebuf; // gobuf arg to morestack 273 274 // Fields not known to debuggers. 275 uint32 moreframesize; // size arguments to morestack 276 uint32 moreargsize; 277 uintptr cret; // return value from C 278 uint64 procid; // for debuggers, but offset not hard-coded 279 G* gsignal; // signal-handling G 280 uintptr tls[4]; // thread-local storage (for x86 extern register) 281 void (*mstartfn)(void); 282 G* curg; // current running goroutine 283 P* p; // attached P for executing Go code (nil if not executing Go code) 284 P* nextp; 285 int32 id; 286 int32 mallocing; 287 int32 throwing; 288 int32 gcing; 289 int32 locks; 290 int32 nomemprof; 291 int32 dying; 292 int32 profilehz; 293 int32 helpgc; 294 bool blockingsyscall; 295 bool spinning; 296 uint32 fastrand; 297 uint64 ncgocall; // number of cgo calls in total 298 int32 ncgo; // number of cgo calls currently in progress 299 CgoMal* cgomal; 300 Note park; 301 M* alllink; // on allm 302 M* schedlink; 303 uint32 machport; // Return address for Mach IPC (OS X) 304 MCache *mcache; 305 int32 stackinuse; 306 uint32 stackcachepos; 307 uint32 stackcachecnt; 308 void* stackcache[StackCacheSize]; 309 G* lockedg; 310 uintptr createstack[32]; // Stack that created this thread. 311 uint32 freglo[16]; // D[i] lsb and F[i] 312 uint32 freghi[16]; // D[i] msb and F[i+16] 313 uint32 fflag; // floating point compare flags 314 uint32 locked; // tracking for LockOSThread 315 M* nextwaitm; // next M waiting for lock 316 uintptr waitsema; // semaphore for parking on locks 317 uint32 waitsemacount; 318 uint32 waitsemalock; 319 GCStats gcstats; 320 bool racecall; 321 bool needextram; 322 void* racepc; 323 void (*waitunlockf)(Lock*); 324 void* waitlock; 325 uint32 moreframesize_minalloc; 326 327 uintptr settype_buf[1024]; 328 uintptr settype_bufsize; 329 330 #ifdef GOOS_windows 331 void* thread; // thread handle 332 #endif 333 #ifdef GOOS_plan9 334 int8* notesig; 335 byte* errstr; 336 #endif 337 SEH* seh; 338 uintptr end[]; 339 }; 340 341 struct P 342 { 343 Lock; 344 345 uint32 status; // one of Pidle/Prunning/... 346 P* link; 347 uint32 tick; // incremented on every scheduler or system call 348 M* m; // back-link to associated M (nil if idle) 349 MCache* mcache; 350 351 // Queue of runnable goroutines. 352 G** runq; 353 int32 runqhead; 354 int32 runqtail; 355 int32 runqsize; 356 357 // Available G's (status == Gdead) 358 G* gfree; 359 int32 gfreecnt; 360 361 byte pad[64]; 362 }; 363 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. 367 enum 368 { 369 LockExternal = 1, 370 LockInternal = 2, 371 }; 372 373 struct Stktop 374 { 375 // The offsets of these fields are known to (hard-coded in) libmach. 376 uint8* stackguard; 377 uint8* stackbase; 378 Gobuf gobuf; 379 uint32 argsize; 380 381 uint8* argp; // pointer to arguments in old frame 382 uintptr free; // if free>0, call stackfree using free as size 383 bool panic; // is this frame the top of a panic? 384 }; 385 struct SigTab 386 { 387 int32 flags; 388 int8 *name; 389 }; 390 enum 391 { 392 SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel 393 SigKill = 1<<1, // if signal.Notify doesn't take it, exit quietly 394 SigThrow = 1<<2, // if signal.Notify doesn't take it, exit loudly 395 SigPanic = 1<<3, // if the signal is from the kernel, panic 396 SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it 397 SigHandling = 1<<5, // our signal handler is registered 398 SigIgnored = 1<<6, // the signal was ignored before we registered for it 399 }; 400 401 // NOTE(rsc): keep in sync with extern.go:/type.Func. 402 // Eventually, the loaded symbol table should be closer to this form. 403 struct Func 404 { 405 String name; 406 String type; // go type string 407 String src; // src file name 408 Slice pcln; // pc/ln tab for this func 409 uintptr entry; // entry pc 410 uintptr pc0; // starting pc, ln for table 411 int32 ln0; 412 int32 frame; // stack frame size 413 int32 args; // in/out args size 414 int32 locals; // locals size 415 }; 416 417 // layout of Itab known to compilers 418 struct Itab 419 { 420 InterfaceType* inter; 421 Type* type; 422 Itab* link; 423 int32 bad; 424 int32 unused; 425 void (*fun[])(void); 426 }; 427 428 struct WinCall 429 { 430 void (*fn)(void*); 431 uintptr n; // number of parameters 432 void* args; // parameters 433 uintptr r1; // return values 434 uintptr r2; 435 uintptr err; // error number 436 }; 437 struct SEH 438 { 439 void* prev; 440 void* handler; 441 }; 442 443 #ifdef GOOS_windows 444 enum { 445 Windows = 1 446 }; 447 #else 448 enum { 449 Windows = 0 450 }; 451 #endif 452 453 struct Timers 454 { 455 Lock; 456 G *timerproc; 457 bool sleeping; 458 bool rescheduling; 459 Note waitnote; 460 Timer **t; 461 int32 len; 462 int32 cap; 463 }; 464 465 // Package time knows the layout of this structure. 466 // If this struct changes, adjust ../time/sleep.go:/runtimeTimer. 467 struct Timer 468 { 469 int32 i; // heap index 470 471 // Timer wakes up at when, and then at when+period, ... (period > 0 only) 472 // each time calling f(now, arg) in the timer goroutine, so f must be 473 // a well-behaved function and not block. 474 int64 when; 475 int64 period; 476 FuncVal *fv; 477 Eface arg; 478 }; 479 480 // Lock-free stack node. 481 struct LFNode 482 { 483 LFNode *next; 484 uintptr pushcnt; 485 }; 486 487 // Parallel for descriptor. 488 struct ParFor 489 { 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 501 // stats 502 uint64 nsteal; 503 uint64 nstealcnt; 504 uint64 nprocyield; 505 uint64 nosyield; 506 uint64 nsleep; 507 }; 508 509 // Track memory allocated by code not written in Go during a cgo call, 510 // so that the garbage collector can see them. 511 struct CgoMal 512 { 513 CgoMal *next; 514 void *alloc; 515 }; 516 517 /* 518 * defined macros 519 * you need super-gopher-guru privilege 520 * to add this list. 521 */ 522 #define nelem(x) (sizeof(x)/sizeof((x)[0])) 523 #define nil ((void*)0) 524 #define offsetof(s,m) (uint32)(&(((s*)0)->m)) 525 #define ROUND(x, n) (((x)+(n)-1)&~((n)-1)) /* all-caps to mark as macro: it evaluates n twice */ 526 527 /* 528 * known to compiler 529 */ 530 enum { 531 Structrnd = sizeof(uintptr) 532 }; 533 534 /* 535 * type algorithms - known to compiler 536 */ 537 enum 538 { 539 AMEM, 540 AMEM0, 541 AMEM8, 542 AMEM16, 543 AMEM32, 544 AMEM64, 545 AMEM128, 546 ANOEQ, 547 ANOEQ0, 548 ANOEQ8, 549 ANOEQ16, 550 ANOEQ32, 551 ANOEQ64, 552 ANOEQ128, 553 ASTRING, 554 AINTER, 555 ANILINTER, 556 ASLICE, 557 AFLOAT32, 558 AFLOAT64, 559 ACPLX64, 560 ACPLX128, 561 Amax 562 }; 563 typedef struct Alg Alg; 564 struct Alg 565 { 566 void (*hash)(uintptr*, uintptr, void*); 567 void (*equal)(bool*, uintptr, void*, void*); 568 void (*print)(uintptr, void*); 569 void (*copy)(uintptr, void*, void*); 570 }; 571 572 extern Alg runtime·algarray[Amax]; 573 574 byte* runtime·startup_random_data; 575 uint32 runtime·startup_random_data_len; 576 void runtime·get_random_data(byte**, int32*); 577 578 enum { 579 // hashinit wants this many random bytes 580 HashRandomBytes = 32 581 }; 582 void runtime·hashinit(void); 583 584 void runtime·memhash(uintptr*, uintptr, void*); 585 void runtime·nohash(uintptr*, uintptr, void*); 586 void runtime·strhash(uintptr*, uintptr, void*); 587 void runtime·interhash(uintptr*, uintptr, void*); 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*); 593 594 void runtime·memequal(bool*, uintptr, void*, void*); 595 void runtime·noequal(bool*, uintptr, void*, void*); 596 void runtime·strequal(bool*, uintptr, void*, void*); 597 void runtime·interequal(bool*, uintptr, void*, void*); 598 void runtime·nilinterequal(bool*, uintptr, void*, void*); 599 600 bool runtime·memeq(void*, void*, uintptr); 601 602 void runtime·memprint(uintptr, void*); 603 void runtime·strprint(uintptr, void*); 604 void runtime·interprint(uintptr, void*); 605 void runtime·nilinterprint(uintptr, void*); 606 607 void runtime·memcopy(uintptr, void*, void*); 608 void runtime·memcopy8(uintptr, void*, void*); 609 void runtime·memcopy16(uintptr, void*, void*); 610 void runtime·memcopy32(uintptr, void*, void*); 611 void runtime·memcopy64(uintptr, void*, void*); 612 void runtime·memcopy128(uintptr, void*, void*); 613 void runtime·strcopy(uintptr, void*, void*); 614 void runtime·algslicecopy(uintptr, void*, void*); 615 void runtime·intercopy(uintptr, void*, void*); 616 void runtime·nilintercopy(uintptr, void*, void*); 617 618 /* 619 * deferred subroutine calls 620 */ 621 struct Defer 622 { 623 int32 siz; 624 bool special; // not part of defer frame 625 bool free; // if special, free when done 626 byte* argp; // where args were copied from 627 byte* pc; 628 FuncVal* fn; 629 Defer* link; 630 void* args[1]; // padded to actual size 631 }; 632 633 struct DeferChunk 634 { 635 DeferChunk *prev; 636 uintptr off; 637 }; 638 639 /* 640 * panics 641 */ 642 struct Panic 643 { 644 Eface arg; // argument to panic 645 byte* stackbase; // g->stackbase in panic 646 Panic* link; // link to earlier panic 647 bool recovered; // whether this panic is over 648 }; 649 650 /* 651 * external data 652 */ 653 extern String runtime·emptystring; 654 extern uintptr runtime·zerobase; 655 extern G* runtime·allg; 656 extern G* runtime·lastg; 657 extern M* runtime·allm; 658 extern P** runtime·allp; 659 extern int32 runtime·gomaxprocs; 660 extern bool runtime·singleproc; 661 extern uint32 runtime·panicking; 662 extern uint32 runtime·gcwaiting; // gc is waiting to run 663 extern int8* runtime·goos; 664 extern int32 runtime·ncpu; 665 extern bool runtime·iscgo; 666 extern void (*runtime·sysargs)(int32, uint8**); 667 extern uint32 runtime·maxstring; 668 extern uint32 runtime·Hchansize; 669 extern uint32 runtime·cpuid_ecx; 670 extern uint32 runtime·cpuid_edx; 671 672 /* 673 * common functions and data 674 */ 675 int32 runtime·strcmp(byte*, byte*); 676 byte* runtime·strstr(byte*, byte*); 677 int32 runtime·findnull(byte*); 678 int32 runtime·findnullw(uint16*); 679 void runtime·dump(byte*, int32); 680 int32 runtime·runetochar(byte*, int32); 681 int32 runtime·charntorune(int32*, uint8*, int32); 682 683 /* 684 * very low level c-called 685 */ 686 #define FLUSH(x) USED(x) 687 688 void runtime·gogo(Gobuf*, uintptr); 689 void runtime·gogocall(Gobuf*, void(*)(void), uintptr); 690 void runtime·gogocallfn(Gobuf*, FuncVal*); 691 void runtime·gosave(Gobuf*); 692 void runtime·lessstack(void); 693 void runtime·goargs(void); 694 void runtime·goenvs(void); 695 void runtime·goenvs_unix(void); 696 void* runtime·getu(void); 697 void runtime·throw(int8*); 698 void runtime·panicstring(int8*); 699 void runtime·prints(int8*); 700 void runtime·printf(int8*, ...); 701 byte* runtime·mchr(byte*, byte, byte*); 702 int32 runtime·mcmp(byte*, byte*, uintptr); 703 void runtime·memmove(void*, void*, uintptr); 704 void* runtime·mal(uintptr); 705 String runtime·catstring(String, String); 706 String runtime·gostring(byte*); 707 String runtime·gostringn(byte*, intgo); 708 Slice runtime·gobytes(byte*, intgo); 709 String runtime·gostringnocopy(byte*); 710 String runtime·gostringw(uint16*); 711 void runtime·initsig(void); 712 void runtime·sigenable(uint32 sig); 713 void runtime·sigdisable(uint32 sig); 714 int32 runtime·gotraceback(bool *crash); 715 void runtime·goroutineheader(G*); 716 void runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp); 717 void runtime·tracebackothers(G*); 718 int32 runtime·open(int8*, int32, int32); 719 int32 runtime·read(int32, void*, int32); 720 int32 runtime·write(int32, void*, int32); 721 int32 runtime·close(int32); 722 int32 runtime·mincore(void*, uintptr, byte*); 723 bool runtime·cas(uint32*, uint32, uint32); 724 bool runtime·cas64(uint64*, uint64*, uint64); 725 bool runtime·casp(void**, void*, void*); 726 // Don't confuse with XADD x86 instruction, 727 // this one is actually 'addx', that is, add-and-fetch. 728 uint32 runtime·xadd(uint32 volatile*, int32); 729 uint64 runtime·xadd64(uint64 volatile*, int64); 730 uint32 runtime·xchg(uint32 volatile*, uint32); 731 uint64 runtime·xchg64(uint64 volatile*, uint64); 732 uint32 runtime·atomicload(uint32 volatile*); 733 void runtime·atomicstore(uint32 volatile*, uint32); 734 void runtime·atomicstore64(uint64 volatile*, uint64); 735 uint64 runtime·atomicload64(uint64 volatile*); 736 void* runtime·atomicloadp(void* volatile*); 737 void runtime·atomicstorep(void* volatile*, void*); 738 void runtime·jmpdefer(FuncVal*, void*); 739 void runtime·exit1(int32); 740 void runtime·ready(G*); 741 byte* runtime·getenv(int8*); 742 int32 runtime·atoi(byte*); 743 void runtime·newosproc(M *mp, void *stk); 744 void runtime·mstart(void); 745 G* runtime·malg(int32); 746 void runtime·asminit(void); 747 void runtime·mpreinit(M*); 748 void runtime·minit(void); 749 void runtime·unminit(void); 750 void runtime·signalstack(byte*, int32); 751 Func* runtime·findfunc(uintptr); 752 int32 runtime·funcline(Func*, uintptr); 753 void* runtime·stackalloc(uint32); 754 void runtime·stackfree(void*, uintptr); 755 MCache* runtime·allocmcache(void); 756 void runtime·freemcache(MCache*); 757 void runtime·mallocinit(void); 758 void runtime·mprofinit(void); 759 bool runtime·ifaceeq_c(Iface, Iface); 760 bool runtime·efaceeq_c(Eface, Eface); 761 uintptr runtime·ifacehash(Iface, uintptr); 762 uintptr runtime·efacehash(Eface, uintptr); 763 void* runtime·malloc(uintptr size); 764 void runtime·free(void *v); 765 bool runtime·addfinalizer(void*, FuncVal *fn, uintptr); 766 void runtime·runpanic(Panic*); 767 void* runtime·getcallersp(void*); 768 int32 runtime·mcount(void); 769 int32 runtime·gcount(void); 770 void runtime·mcall(void(*)(G*)); 771 uint32 runtime·fastrand1(void); 772 773 void runtime·setmg(M*, G*); 774 void runtime·newextram(void); 775 void runtime·exit(int32); 776 void runtime·breakpoint(void); 777 void runtime·gosched(void); 778 void runtime·park(void(*)(Lock*), Lock*, int8*); 779 void runtime·tsleep(int64, int8*); 780 M* runtime·newm(void); 781 void runtime·goexit(void); 782 void runtime·asmcgocall(void (*fn)(void*), void*); 783 void runtime·entersyscall(void); 784 void runtime·entersyscallblock(void); 785 void runtime·exitsyscall(void); 786 G* runtime·newproc1(FuncVal*, byte*, int32, int32, void*); 787 bool runtime·sigsend(int32 sig); 788 int32 runtime·callers(int32, uintptr*, int32); 789 int32 runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32, void (*)(Func*, byte*, byte*, void*), void*); 790 int64 runtime·nanotime(void); 791 void runtime·dopanic(int32); 792 void runtime·startpanic(void); 793 void runtime·unwindstack(G*, byte*); 794 void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp); 795 void runtime·resetcpuprofiler(int32); 796 void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32); 797 void runtime·usleep(uint32); 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); 810 811 #pragma varargck argpos runtime·printf 1 812 #pragma varargck type "d" int32 813 #pragma varargck type "d" uint32 814 #pragma varargck type "D" int64 815 #pragma varargck type "D" uint64 816 #pragma varargck type "x" int32 817 #pragma varargck type "x" uint32 818 #pragma varargck type "X" int64 819 #pragma varargck type "X" uint64 820 #pragma varargck type "p" void* 821 #pragma varargck type "p" uintptr 822 #pragma varargck type "s" int8* 823 #pragma varargck type "s" uint8* 824 #pragma varargck type "S" String 825 826 void runtime·stoptheworld(void); 827 void runtime·starttheworld(void); 828 extern uint32 runtime·worldsema; 829 830 /* 831 * mutual exclusion locks. in the uncontended case, 832 * as fast as spin locks (just a few user-level instructions), 833 * but on the contention path they sleep in the kernel. 834 * a zeroed Lock is unlocked (no need to initialize each lock). 835 */ 836 void runtime·lock(Lock*); 837 void runtime·unlock(Lock*); 838 839 /* 840 * sleep and wakeup on one-time events. 841 * before any calls to notesleep or notewakeup, 842 * must call noteclear to initialize the Note. 843 * then, exactly one thread can call notesleep 844 * and exactly one thread can call notewakeup (once). 845 * once notewakeup has been called, the notesleep 846 * will return. future notesleep will return immediately. 847 * subsequent noteclear must be called only after 848 * previous notesleep has returned, e.g. it's disallowed 849 * to call noteclear straight after notewakeup. 850 * 851 * notetsleep is like notesleep but wakes up after 852 * a given number of nanoseconds even if the event 853 * has not yet happened. if a goroutine uses notetsleep to 854 * wake up early, it must wait to call noteclear until it 855 * can be sure that no other goroutine is calling 856 * notewakeup. 857 */ 858 void runtime·noteclear(Note*); 859 void runtime·notesleep(Note*); 860 void runtime·notewakeup(Note*); 861 void runtime·notetsleep(Note*, int64); 862 863 /* 864 * low-level synchronization for implementing the above 865 */ 866 uintptr runtime·semacreate(void); 867 int32 runtime·semasleep(int64); 868 void runtime·semawakeup(M*); 869 // or 870 void runtime·futexsleep(uint32*, uint32, int64); 871 void runtime·futexwakeup(uint32*, uint32); 872 873 /* 874 * Lock-free stack. 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. 878 */ 879 void runtime·lfstackpush(uint64 *head, LFNode *node); 880 LFNode* runtime·lfstackpop(uint64 *head); 881 882 /* 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. 889 */ 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); 893 894 /* 895 * This is consistent across Linux and BSD. 896 * If a new OS is added that is different, move this to 897 * $GOOS/$GOARCH/defs.h. 898 */ 899 #define EACCES 13 900 901 /* 902 * low level C-called 903 */ 904 // for mmap, we only pass the lower 32 bits of file offset to the 905 // assembly routine; the higher bits (if required), should be provided 906 // by the assembly routine as 0. 907 uint8* runtime·mmap(byte*, uintptr, int32, int32, int32, uint32); 908 void runtime·munmap(byte*, uintptr); 909 void runtime·madvise(byte*, uintptr, int32); 910 void runtime·memclr(byte*, uintptr); 911 void runtime·setcallerpc(void*, void*); 912 void* runtime·getcallerpc(void*); 913 914 /* 915 * runtime go-called 916 */ 917 void runtime·printbool(bool); 918 void runtime·printbyte(int8); 919 void runtime·printfloat(float64); 920 void runtime·printint(int64); 921 void runtime·printiface(Iface); 922 void runtime·printeface(Eface); 923 void runtime·printstring(String); 924 void runtime·printpc(void*); 925 void runtime·printpointer(void*); 926 void runtime·printuint(uint64); 927 void runtime·printhex(uint64); 928 void runtime·printslice(Slice); 929 void runtime·printcomplex(Complex128); 930 void reflect·call(FuncVal*, byte*, uint32); 931 void runtime·panic(Eface); 932 void runtime·panicindex(void); 933 void runtime·panicslice(void); 934 935 /* 936 * runtime c-called (but written in Go) 937 */ 938 void runtime·printany(Eface); 939 void runtime·newTypeAssertionError(String*, String*, String*, String*, Eface*); 940 void runtime·newErrorString(String, Eface*); 941 void runtime·fadd64c(uint64, uint64, uint64*); 942 void runtime·fsub64c(uint64, uint64, uint64*); 943 void runtime·fmul64c(uint64, uint64, uint64*); 944 void runtime·fdiv64c(uint64, uint64, uint64*); 945 void runtime·fneg64c(uint64, uint64*); 946 void runtime·f32to64c(uint32, uint64*); 947 void runtime·f64to32c(uint64, uint32*); 948 void runtime·fcmp64c(uint64, uint64, int32*, bool*); 949 void runtime·fintto64c(int64, uint64*); 950 void runtime·f64tointc(uint64, int64*, bool*); 951 952 /* 953 * wrapped for go users 954 */ 955 float64 runtime·Inf(int32 sign); 956 float64 runtime·NaN(void); 957 float32 runtime·float32frombits(uint32 i); 958 uint32 runtime·float32tobits(float32 f); 959 float64 runtime·float64frombits(uint64 i); 960 uint64 runtime·float64tobits(float64 f); 961 float64 runtime·frexp(float64 d, int32 *ep); 962 bool runtime·isInf(float64 f, int32 sign); 963 bool runtime·isNaN(float64 f); 964 float64 runtime·ldexp(float64 d, int32 e); 965 float64 runtime·modf(float64 d, float64 *ip); 966 void runtime·semacquire(uint32*); 967 void runtime·semrelease(uint32*); 968 int32 runtime·gomaxprocsfunc(int32 n); 969 void runtime·procyield(uint32); 970 void runtime·osyield(void); 971 void runtime·lockOSThread(void); 972 void runtime·unlockOSThread(void); 973 974 void runtime·mapassign(MapType*, Hmap*, byte*, byte*); 975 void runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*); 976 void runtime·mapiternext(struct hash_iter*); 977 bool runtime·mapiterkey(struct hash_iter*, void*); 978 Hmap* runtime·makemap_c(MapType*, int64); 979 980 Hchan* runtime·makechan_c(ChanType*, int64); 981 void runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*); 982 void runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*); 983 bool runtime·showframe(Func*, bool); 984 985 void runtime·ifaceE2I(InterfaceType*, Eface, Iface*); 986 987 uintptr runtime·memlimit(void); 988 989 // If appropriate, ask the operating system to control whether this 990 // thread should receive profiling signals. This is only necessary on OS X. 991 // An operating system should not deliver a profiling signal to a 992 // thread that is not actually executing (what good is that?), but that's 993 // what OS X prefers to do. When profiling is turned on, we mask 994 // away the profiling signal when threads go to sleep, so that OS X 995 // is forced to deliver the signal to a thread that's actually running. 996 // This is a no-op on other systems. 997 void runtime·setprof(bool); 998 999 // float.c 1000 extern float64 runtime·nan; 1001 extern float64 runtime·posinf; 1002 extern float64 runtime·neginf; 1003 extern uint64 ·nan; 1004 extern uint64 ·posinf; 1005 extern uint64 ·neginf; 1006 #define ISNAN(f) ((f) != (f)) 1007 1008 enum 1009 { 1010 UseSpanType = 1, 1011 };