2014-07-11 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / runtime / runtime.h
blob6bd53a852b40709d58cca59fbd94cb72b7a326ae
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.
5 #include "config.h"
7 #include "go-assert.h"
8 #include <complex.h>
9 #include <signal.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <pthread.h>
18 #include <semaphore.h>
19 #include <ucontext.h>
21 #ifdef HAVE_SYS_MMAN_H
22 #include <sys/mman.h>
23 #endif
25 #include "interface.h"
26 #include "go-alloc.h"
28 #define _STRINGIFY2_(x) #x
29 #define _STRINGIFY_(x) _STRINGIFY2_(x)
30 #define GOSYM_PREFIX _STRINGIFY_(__USER_LABEL_PREFIX__)
32 /* This file supports C files copied from the 6g runtime library.
33 This is a version of the 6g runtime.h rewritten for gccgo's version
34 of the code. */
36 typedef signed int int8 __attribute__ ((mode (QI)));
37 typedef unsigned int uint8 __attribute__ ((mode (QI)));
38 typedef signed int int16 __attribute__ ((mode (HI)));
39 typedef unsigned int uint16 __attribute__ ((mode (HI)));
40 typedef signed int int32 __attribute__ ((mode (SI)));
41 typedef unsigned int uint32 __attribute__ ((mode (SI)));
42 typedef signed int int64 __attribute__ ((mode (DI)));
43 typedef unsigned int uint64 __attribute__ ((mode (DI)));
44 typedef float float32 __attribute__ ((mode (SF)));
45 typedef double float64 __attribute__ ((mode (DF)));
46 typedef signed int intptr __attribute__ ((mode (pointer)));
47 typedef unsigned int uintptr __attribute__ ((mode (pointer)));
49 typedef intptr intgo; // Go's int
50 typedef uintptr uintgo; // Go's uint
52 /* Defined types. */
54 typedef uint8 bool;
55 typedef uint8 byte;
56 typedef struct Func Func;
57 typedef struct G G;
58 typedef struct Lock Lock;
59 typedef struct M M;
60 typedef struct P P;
61 typedef struct Note Note;
62 typedef struct String String;
63 typedef struct FuncVal FuncVal;
64 typedef struct SigTab SigTab;
65 typedef struct MCache MCache;
66 typedef struct FixAlloc FixAlloc;
67 typedef struct Hchan Hchan;
68 typedef struct Timers Timers;
69 typedef struct Timer Timer;
70 typedef struct GCStats GCStats;
71 typedef struct LFNode LFNode;
72 typedef struct ParFor ParFor;
73 typedef struct ParForThread ParForThread;
74 typedef struct CgoMal CgoMal;
75 typedef struct PollDesc PollDesc;
76 typedef struct DebugVars DebugVars;
78 typedef struct __go_open_array Slice;
79 typedef struct __go_interface Iface;
80 typedef struct __go_empty_interface Eface;
81 typedef struct __go_type_descriptor Type;
82 typedef struct __go_defer_stack Defer;
83 typedef struct __go_panic_stack Panic;
85 typedef struct __go_ptr_type PtrType;
86 typedef struct __go_func_type FuncType;
87 typedef struct __go_interface_type InterfaceType;
88 typedef struct __go_map_type MapType;
89 typedef struct __go_channel_type ChanType;
91 typedef struct Traceback Traceback;
93 typedef struct Location Location;
96 * Per-CPU declaration.
98 extern M* runtime_m(void);
99 extern G* runtime_g(void);
101 extern M runtime_m0;
102 extern G runtime_g0;
105 * defined constants
107 enum
109 // G status
111 // If you add to this list, add to the list
112 // of "okay during garbage collection" status
113 // in mgc0.c too.
114 Gidle,
115 Grunnable,
116 Grunning,
117 Gsyscall,
118 Gwaiting,
119 Gmoribund_unused, // currently unused, but hardcoded in gdb scripts
120 Gdead,
122 enum
124 // P status
125 Pidle,
126 Prunning,
127 Psyscall,
128 Pgcstop,
129 Pdead,
131 enum
133 true = 1,
134 false = 0,
136 enum
138 PtrSize = sizeof(void*),
140 enum
142 // Per-M stack segment cache size.
143 StackCacheSize = 32,
144 // Global <-> per-M stack segment cache transfer batch size.
145 StackCacheBatch = 16,
148 * structures
150 struct Lock
152 // Futex-based impl treats it as uint32 key,
153 // while sema-based impl as M* waitm.
154 // Used to be a union, but unions break precise GC.
155 uintptr key;
157 struct Note
159 // Futex-based impl treats it as uint32 key,
160 // while sema-based impl as M* waitm.
161 // Used to be a union, but unions break precise GC.
162 uintptr key;
164 struct String
166 const byte* str;
167 intgo len;
169 struct FuncVal
171 void (*fn)(void);
172 // variable-size, fn-specific data here
174 struct GCStats
176 // the struct must consist of only uint64's,
177 // because it is casted to uint64[].
178 uint64 nhandoff;
179 uint64 nhandoffcnt;
180 uint64 nprocyield;
181 uint64 nosyield;
182 uint64 nsleep;
185 // A location in the program, used for backtraces.
186 struct Location
188 uintptr pc;
189 String filename;
190 String function;
191 intgo lineno;
194 struct G
196 void* closure; // Closure value.
197 Defer* defer;
198 Panic* panic;
199 void* exception; // current exception being thrown
200 bool is_foreign; // whether current exception from other language
201 void *gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
202 uintptr gcstack_size;
203 void* gcnext_segment;
204 void* gcnext_sp;
205 void* gcinitial_sp;
206 ucontext_t gcregs;
207 byte* entry; // initial function
208 void* param; // passed parameter on wakeup
209 bool fromgogo; // reached from gogo
210 int16 status;
211 uint32 selgen; // valid sudog pointer
212 int64 goid;
213 int64 waitsince; // approx time when the G become blocked
214 const char* waitreason; // if status==Gwaiting
215 G* schedlink;
216 bool ispanic;
217 bool issystem; // do not output in stack dump
218 bool isbackground; // ignore in deadlock detector
219 M* m; // for debuggers, but offset not hard-coded
220 M* lockedm;
221 int32 sig;
222 int32 writenbuf;
223 byte* writebuf;
224 uintptr sigcode0;
225 uintptr sigcode1;
226 // uintptr sigpc;
227 uintptr gopc; // pc of go statement that created this goroutine
229 int32 ncgo;
230 CgoMal* cgomal;
232 Traceback* traceback;
234 ucontext_t context;
235 void* stack_context[10];
238 struct M
240 G* g0; // goroutine with scheduling stack
241 G* gsignal; // signal-handling G
242 byte* gsignalstack;
243 size_t gsignalstacksize;
244 void (*mstartfn)(void);
245 G* curg; // current running goroutine
246 G* caughtsig; // goroutine running during fatal signal
247 P* p; // attached P for executing Go code (nil if not executing Go code)
248 P* nextp;
249 int32 id;
250 int32 mallocing;
251 int32 throwing;
252 int32 gcing;
253 int32 locks;
254 int32 dying;
255 int32 profilehz;
256 int32 helpgc;
257 bool spinning; // M is out of work and is actively looking for work
258 bool blocked; // M is blocked on a Note
259 uint32 fastrand;
260 uint64 ncgocall; // number of cgo calls in total
261 int32 ncgo; // number of cgo calls currently in progress
262 CgoMal* cgomal;
263 Note park;
264 M* alllink; // on allm
265 M* schedlink;
266 MCache *mcache;
267 G* lockedg;
268 Location createstack[32]; // Stack that created this thread.
269 uint32 locked; // tracking for LockOSThread
270 M* nextwaitm; // next M waiting for lock
271 uintptr waitsema; // semaphore for parking on locks
272 uint32 waitsemacount;
273 uint32 waitsemalock;
274 GCStats gcstats;
275 bool racecall;
276 bool needextram;
277 bool dropextram; // for gccgo: drop after call is done.
278 bool (*waitunlockf)(G*, void*);
279 void* waitlock;
281 uintptr settype_buf[1024];
282 uintptr settype_bufsize;
284 uintptr end[];
287 struct P
289 Lock;
291 int32 id;
292 uint32 status; // one of Pidle/Prunning/...
293 P* link;
294 uint32 schedtick; // incremented on every scheduler call
295 uint32 syscalltick; // incremented on every system call
296 M* m; // back-link to associated M (nil if idle)
297 MCache* mcache;
298 Defer* deferpool; // pool of available Defer structs (see panic.c)
300 // Cache of goroutine ids, amortizes accesses to runtime_sched.goidgen.
301 uint64 goidcache;
302 uint64 goidcacheend;
304 // Queue of runnable goroutines.
305 uint32 runqhead;
306 uint32 runqtail;
307 G* runq[256];
309 // Available G's (status == Gdead)
310 G* gfree;
311 int32 gfreecnt;
313 byte pad[64];
316 // The m->locked word holds two pieces of state counting active calls to LockOSThread/lockOSThread.
317 // The low bit (LockExternal) is a boolean reporting whether any LockOSThread call is active.
318 // External locks are not recursive; a second lock is silently ignored.
319 // The upper bits of m->lockedcount record the nesting depth of calls to lockOSThread
320 // (counting up by LockInternal), popped by unlockOSThread (counting down by LockInternal).
321 // Internal locks can be recursive. For instance, a lock for cgo can occur while the main
322 // goroutine is holding the lock during the initialization phase.
323 enum
325 LockExternal = 1,
326 LockInternal = 2,
329 struct SigTab
331 int32 sig;
332 int32 flags;
334 enum
336 SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel
337 SigKill = 1<<1, // if signal.Notify doesn't take it, exit quietly
338 SigThrow = 1<<2, // if signal.Notify doesn't take it, exit loudly
339 SigPanic = 1<<3, // if the signal is from the kernel, panic
340 SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
341 SigHandling = 1<<5, // our signal handler is registered
342 SigIgnored = 1<<6, // the signal was ignored before we registered for it
345 // Layout of in-memory per-function information prepared by linker
346 // See http://golang.org/s/go12symtab.
347 // Keep in sync with linker and with ../../libmach/sym.c
348 // and with package debug/gosym.
349 struct Func
351 String name;
352 uintptr entry; // entry pc
355 #ifdef GOOS_windows
356 enum {
357 Windows = 1
359 #else
360 enum {
361 Windows = 0
363 #endif
364 #ifdef GOOS_solaris
365 enum {
366 Solaris = 1
368 #else
369 enum {
370 Solaris = 0
372 #endif
374 struct Timers
376 Lock;
377 G *timerproc;
378 bool sleeping;
379 bool rescheduling;
380 Note waitnote;
381 Timer **t;
382 int32 len;
383 int32 cap;
386 // Package time knows the layout of this structure.
387 // If this struct changes, adjust ../time/sleep.go:/runtimeTimer.
388 struct Timer
390 int32 i; // heap index
392 // Timer wakes up at when, and then at when+period, ... (period > 0 only)
393 // each time calling f(now, arg) in the timer goroutine, so f must be
394 // a well-behaved function and not block.
395 int64 when;
396 int64 period;
397 FuncVal *fv;
398 Eface arg;
401 // Lock-free stack node.
402 struct LFNode
404 LFNode *next;
405 uintptr pushcnt;
408 // Parallel for descriptor.
409 struct ParFor
411 void (*body)(ParFor*, uint32); // executed for each element
412 uint32 done; // number of idle threads
413 uint32 nthr; // total number of threads
414 uint32 nthrmax; // maximum number of threads
415 uint32 thrseq; // thread id sequencer
416 uint32 cnt; // iteration space [0, cnt)
417 void *ctx; // arbitrary user context
418 bool wait; // if true, wait while all threads finish processing,
419 // otherwise parfor may return while other threads are still working
420 ParForThread *thr; // array of thread descriptors
421 uint32 pad; // to align ParForThread.pos for 64-bit atomic operations
422 // stats
423 uint64 nsteal;
424 uint64 nstealcnt;
425 uint64 nprocyield;
426 uint64 nosyield;
427 uint64 nsleep;
430 // Track memory allocated by code not written in Go during a cgo call,
431 // so that the garbage collector can see them.
432 struct CgoMal
434 CgoMal *next;
435 void *alloc;
438 // Holds variables parsed from GODEBUG env var.
439 struct DebugVars
441 int32 allocfreetrace;
442 int32 efence;
443 int32 gctrace;
444 int32 scheddetail;
445 int32 schedtrace;
448 extern bool runtime_precisestack;
451 * defined macros
452 * you need super-gopher-guru privilege
453 * to add this list.
455 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
456 #define nil ((void*)0)
457 #define USED(v) ((void) v)
458 #define ROUND(x, n) (((x)+(n)-1)&~(uintptr)((n)-1)) /* all-caps to mark as macro: it evaluates n twice */
460 byte* runtime_startup_random_data;
461 uint32 runtime_startup_random_data_len;
462 void runtime_get_random_data(byte**, int32*);
464 enum {
465 // hashinit wants this many random bytes
466 HashRandomBytes = 32
468 void runtime_hashinit(void);
470 void runtime_traceback(void);
471 void runtime_tracebackothers(G*);
472 enum
474 // The maximum number of frames we print for a traceback
475 TracebackMaxFrames = 100,
479 * external data
481 extern uintptr runtime_zerobase;
482 extern G** runtime_allg;
483 extern uintptr runtime_allglen;
484 extern G* runtime_lastg;
485 extern M* runtime_allm;
486 extern P** runtime_allp;
487 extern int32 runtime_gomaxprocs;
488 extern uint32 runtime_needextram;
489 extern uint32 runtime_panicking;
490 extern int8* runtime_goos;
491 extern int32 runtime_ncpu;
492 extern void (*runtime_sysargs)(int32, uint8**);
493 extern DebugVars runtime_debug;
494 extern uintptr runtime_maxstacksize;
497 * common functions and data
499 #define runtime_strcmp(s1, s2) __builtin_strcmp((s1), (s2))
500 #define runtime_strstr(s1, s2) __builtin_strstr((s1), (s2))
501 intgo runtime_findnull(const byte*);
502 intgo runtime_findnullw(const uint16*);
503 void runtime_dump(byte*, int32);
505 void runtime_gogo(G*);
506 struct __go_func_type;
507 void runtime_args(int32, byte**);
508 void runtime_osinit();
509 void runtime_goargs(void);
510 void runtime_goenvs(void);
511 void runtime_goenvs_unix(void);
512 void runtime_throw(const char*) __attribute__ ((noreturn));
513 void runtime_panicstring(const char*) __attribute__ ((noreturn));
514 void runtime_prints(const char*);
515 void runtime_printf(const char*, ...);
516 #define runtime_mcmp(a, b, s) __builtin_memcmp((a), (b), (s))
517 #define runtime_memmove(a, b, s) __builtin_memmove((a), (b), (s))
518 void* runtime_mal(uintptr);
519 String runtime_gostring(const byte*);
520 String runtime_gostringnocopy(const byte*);
521 void runtime_schedinit(void);
522 void runtime_initsig(void);
523 void runtime_sigenable(uint32 sig);
524 void runtime_sigdisable(uint32 sig);
525 int32 runtime_gotraceback(bool *crash);
526 void runtime_goroutineheader(G*);
527 void runtime_printtrace(Location*, int32, bool);
528 #define runtime_open(p, f, m) open((p), (f), (m))
529 #define runtime_read(d, v, n) read((d), (v), (n))
530 #define runtime_write(d, v, n) write((d), (v), (n))
531 #define runtime_close(d) close(d)
532 void runtime_ready(G*);
533 const byte* runtime_getenv(const char*);
534 int32 runtime_atoi(const byte*);
535 void* runtime_mstart(void*);
536 G* runtime_malg(int32, byte**, size_t*);
537 void runtime_mpreinit(M*);
538 void runtime_minit(void);
539 void runtime_unminit(void);
540 void runtime_needm(void);
541 void runtime_dropm(void);
542 void runtime_signalstack(byte*, int32);
543 MCache* runtime_allocmcache(void);
544 void runtime_freemcache(MCache*);
545 void runtime_mallocinit(void);
546 void runtime_mprofinit(void);
547 #define runtime_malloc(s) __go_alloc(s)
548 #define runtime_free(p) __go_free(p)
549 #define runtime_getcallersp(p) __builtin_frame_address(1)
550 int32 runtime_mcount(void);
551 int32 runtime_gcount(void);
552 void runtime_mcall(void(*)(G*));
553 uint32 runtime_fastrand1(void);
554 int32 runtime_timediv(int64, int32, int32*);
556 // atomic operations
557 #define runtime_cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
558 #define runtime_cas64(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
559 #define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
560 // Don't confuse with XADD x86 instruction,
561 // this one is actually 'addx', that is, add-and-fetch.
562 #define runtime_xadd(p, v) __sync_add_and_fetch (p, v)
563 #define runtime_xadd64(p, v) __sync_add_and_fetch (p, v)
564 #define runtime_xchg(p, v) __atomic_exchange_n (p, v, __ATOMIC_SEQ_CST)
565 #define runtime_xchg64(p, v) __atomic_exchange_n (p, v, __ATOMIC_SEQ_CST)
566 #define runtime_xchgp(p, v) __atomic_exchange_n (p, v, __ATOMIC_SEQ_CST)
567 #define runtime_atomicload(p) __atomic_load_n (p, __ATOMIC_SEQ_CST)
568 #define runtime_atomicstore(p, v) __atomic_store_n (p, v, __ATOMIC_SEQ_CST)
569 #define runtime_atomicstore64(p, v) __atomic_store_n (p, v, __ATOMIC_SEQ_CST)
570 #define runtime_atomicload64(p) __atomic_load_n (p, __ATOMIC_SEQ_CST)
571 #define runtime_atomicloadp(p) __atomic_load_n (p, __ATOMIC_SEQ_CST)
572 #define runtime_atomicstorep(p, v) __atomic_store_n (p, v, __ATOMIC_SEQ_CST)
574 void runtime_setmg(M*, G*);
575 void runtime_newextram(void);
576 #define runtime_exit(s) exit(s)
577 #define runtime_breakpoint() __builtin_trap()
578 void runtime_gosched(void);
579 void runtime_gosched0(G*);
580 void runtime_schedtrace(bool);
581 void runtime_park(bool(*)(G*, void*), void*, const char*);
582 void runtime_parkunlock(Lock*, const char*);
583 void runtime_tsleep(int64, const char*);
584 M* runtime_newm(void);
585 void runtime_goexit(void);
586 void runtime_entersyscall(void) __asm__ (GOSYM_PREFIX "syscall.Entersyscall");
587 void runtime_entersyscallblock(void);
588 void runtime_exitsyscall(void) __asm__ (GOSYM_PREFIX "syscall.Exitsyscall");
589 G* __go_go(void (*pfn)(void*), void*);
590 void siginit(void);
591 bool __go_sigsend(int32 sig);
592 int32 runtime_callers(int32, Location*, int32);
593 int64 runtime_nanotime(void);
594 void runtime_dopanic(int32) __attribute__ ((noreturn));
595 void runtime_startpanic(void);
596 void runtime_freezetheworld(void);
597 void runtime_unwindstack(G*, byte*);
598 void runtime_sigprof();
599 void runtime_resetcpuprofiler(int32);
600 void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
601 void runtime_usleep(uint32);
602 int64 runtime_cputicks(void);
603 int64 runtime_tickspersecond(void);
604 void runtime_blockevent(int64, int32);
605 extern int64 runtime_blockprofilerate;
606 void runtime_addtimer(Timer*);
607 bool runtime_deltimer(Timer*);
608 G* runtime_netpoll(bool);
609 void runtime_netpollinit(void);
610 int32 runtime_netpollopen(uintptr, PollDesc*);
611 int32 runtime_netpollclose(uintptr);
612 void runtime_netpollready(G**, PollDesc*, int32);
613 uintptr runtime_netpollfd(PollDesc*);
614 void runtime_netpollarm(uintptr, int32);
615 void runtime_crash(void);
616 void runtime_parsedebugvars(void);
617 void _rt0_go(void);
618 void* runtime_funcdata(Func*, int32);
619 int32 runtime_setmaxthreads(int32);
621 void runtime_stoptheworld(void);
622 void runtime_starttheworld(void);
623 extern uint32 runtime_worldsema;
626 * mutual exclusion locks. in the uncontended case,
627 * as fast as spin locks (just a few user-level instructions),
628 * but on the contention path they sleep in the kernel.
629 * a zeroed Lock is unlocked (no need to initialize each lock).
631 void runtime_lock(Lock*);
632 void runtime_unlock(Lock*);
635 * sleep and wakeup on one-time events.
636 * before any calls to notesleep or notewakeup,
637 * must call noteclear to initialize the Note.
638 * then, exactly one thread can call notesleep
639 * and exactly one thread can call notewakeup (once).
640 * once notewakeup has been called, the notesleep
641 * will return. future notesleep will return immediately.
642 * subsequent noteclear must be called only after
643 * previous notesleep has returned, e.g. it's disallowed
644 * to call noteclear straight after notewakeup.
646 * notetsleep is like notesleep but wakes up after
647 * a given number of nanoseconds even if the event
648 * has not yet happened. if a goroutine uses notetsleep to
649 * wake up early, it must wait to call noteclear until it
650 * can be sure that no other goroutine is calling
651 * notewakeup.
653 * notesleep/notetsleep are generally called on g0,
654 * notetsleepg is similar to notetsleep but is called on user g.
656 void runtime_noteclear(Note*);
657 void runtime_notesleep(Note*);
658 void runtime_notewakeup(Note*);
659 bool runtime_notetsleep(Note*, int64); // false - timeout
660 bool runtime_notetsleepg(Note*, int64); // false - timeout
663 * low-level synchronization for implementing the above
665 uintptr runtime_semacreate(void);
666 int32 runtime_semasleep(int64);
667 void runtime_semawakeup(M*);
668 // or
669 void runtime_futexsleep(uint32*, uint32, int64);
670 void runtime_futexwakeup(uint32*, uint32);
673 * Lock-free stack.
674 * Initialize uint64 head to 0, compare with 0 to test for emptiness.
675 * The stack does not keep pointers to nodes,
676 * so they can be garbage collected if there are no other pointers to nodes.
678 void runtime_lfstackpush(uint64 *head, LFNode *node)
679 __asm__ (GOSYM_PREFIX "runtime.lfstackpush");
680 LFNode* runtime_lfstackpop(uint64 *head);
683 * Parallel for over [0, n).
684 * body() is executed for each iteration.
685 * nthr - total number of worker threads.
686 * ctx - arbitrary user context.
687 * if wait=true, threads return from parfor() when all work is done;
688 * otherwise, threads can return while other threads are still finishing processing.
690 ParFor* runtime_parforalloc(uint32 nthrmax);
691 void runtime_parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32));
692 void runtime_parfordo(ParFor *desc);
693 void runtime_parforiters(ParFor*, uintptr, uintptr*, uintptr*);
696 * low level C-called
698 #define runtime_mmap mmap
699 #define runtime_munmap munmap
700 #define runtime_madvise madvise
701 #define runtime_memclr(buf, size) __builtin_memset((buf), 0, (size))
702 #define runtime_getcallerpc(p) __builtin_return_address(0)
704 #ifdef __rtems__
705 void __wrap_rtems_task_variable_add(void **);
706 #endif
709 * Names generated by gccgo.
711 #define runtime_printbool __go_print_bool
712 #define runtime_printfloat __go_print_double
713 #define runtime_printint __go_print_int64
714 #define runtime_printiface __go_print_interface
715 #define runtime_printeface __go_print_empty_interface
716 #define runtime_printstring __go_print_string
717 #define runtime_printpointer __go_print_pointer
718 #define runtime_printuint __go_print_uint64
719 #define runtime_printslice __go_print_slice
720 #define runtime_printcomplex __go_print_complex
723 * runtime go-called
725 void runtime_printbool(_Bool);
726 void runtime_printbyte(int8);
727 void runtime_printfloat(double);
728 void runtime_printint(int64);
729 void runtime_printiface(Iface);
730 void runtime_printeface(Eface);
731 void runtime_printstring(String);
732 void runtime_printpc(void*);
733 void runtime_printpointer(void*);
734 void runtime_printuint(uint64);
735 void runtime_printhex(uint64);
736 void runtime_printslice(Slice);
737 void runtime_printcomplex(complex double);
738 void reflect_call(const struct __go_func_type *, FuncVal *, _Bool, _Bool,
739 void **, void **)
740 __asm__ (GOSYM_PREFIX "reflect.call");
741 #define runtime_panic __go_panic
744 * runtime c-called (but written in Go)
746 void runtime_printany(Eface)
747 __asm__ (GOSYM_PREFIX "runtime.Printany");
748 void runtime_newTypeAssertionError(const String*, const String*, const String*, const String*, Eface*)
749 __asm__ (GOSYM_PREFIX "runtime.NewTypeAssertionError");
750 void runtime_newErrorString(String, Eface*)
751 __asm__ (GOSYM_PREFIX "runtime.NewErrorString");
752 void runtime_newErrorCString(const char*, Eface*)
753 __asm__ (GOSYM_PREFIX "runtime.NewErrorCString");
756 * wrapped for go users
758 void runtime_semacquire(uint32 volatile *, bool);
759 void runtime_semrelease(uint32 volatile *);
760 int32 runtime_gomaxprocsfunc(int32 n);
761 void runtime_procyield(uint32);
762 void runtime_osyield(void);
763 void runtime_lockOSThread(void);
764 void runtime_unlockOSThread(void);
765 bool runtime_lockedOSThread(void);
767 bool runtime_showframe(String, bool);
768 void runtime_printcreatedby(G*);
770 uintptr runtime_memlimit(void);
772 #define ISNAN(f) __builtin_isnan(f)
774 enum
776 UseSpanType = 0,
779 #define runtime_setitimer setitimer
781 void runtime_check(void);
783 // A list of global variables that the garbage collector must scan.
784 struct root_list {
785 struct root_list *next;
786 struct root {
787 void *decl;
788 size_t size;
789 } roots[];
792 void __go_register_gc_roots(struct root_list*);
794 // Size of stack space allocated using Go's allocator.
795 // This will be 0 when using split stacks, as in that case
796 // the stacks are allocated by the splitstack library.
797 extern uintptr runtime_stacks_sys;
799 struct backtrace_state;
800 extern struct backtrace_state *__go_get_backtrace_state(void);
801 extern _Bool __go_file_line(uintptr, String*, String*, intgo *);
802 extern byte* runtime_progname();
803 extern void runtime_main(void*);
804 extern uint32 runtime_in_callers;
806 int32 getproccount(void);
808 #define PREFETCH(p) __builtin_prefetch(p)
810 void __go_set_closure(void*);
811 void* __go_get_closure(void);
813 bool runtime_gcwaiting(void);
814 void runtime_badsignal(int);
815 Defer* runtime_newdefer(void);
816 void runtime_freedefer(Defer*);