github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/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	Note		Note;
    57  typedef	struct	Slice		Slice;
    58  typedef	struct	Stktop		Stktop;
    59  typedef	struct	String		String;
    60  typedef	struct	FuncVal		FuncVal;
    61  typedef	struct	SigTab		SigTab;
    62  typedef	struct	MCache		MCache;
    63  typedef	struct	FixAlloc	FixAlloc;
    64  typedef	struct	Iface		Iface;
    65  typedef	struct	Itab		Itab;
    66  typedef	struct	InterfaceType	InterfaceType;
    67  typedef	struct	Eface		Eface;
    68  typedef	struct	Type		Type;
    69  typedef	struct	ChanType		ChanType;
    70  typedef	struct	MapType		MapType;
    71  typedef	struct	Defer		Defer;
    72  typedef	struct	DeferChunk	DeferChunk;
    73  typedef	struct	Panic		Panic;
    74  typedef	struct	Hmap		Hmap;
    75  typedef	struct	Hchan		Hchan;
    76  typedef	struct	Complex64	Complex64;
    77  typedef	struct	Complex128	Complex128;
    78  typedef	struct	WinCall		WinCall;
    79  typedef	struct	SEH		SEH;
    80  typedef	struct	WinCallbackContext	WinCallbackContext;
    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  typedef	struct	DebugVars	DebugVars;
    90  
    91  /*
    92   * Per-CPU declaration.
    93   *
    94   * "extern register" is a special storage class implemented by 6c, 8c, etc.
    95   * 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).
   100   *
   101   * 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.
   104   */
   105  extern	register	G*	g;
   106  extern	register	M*	m;
   107  
   108  /*
   109   * defined constants
   110   */
   111  enum
   112  {
   113  	// G status
   114  	//
   115  	// If you add to this list, add to the list
   116  	// of "okay during garbage collection" status
   117  	// in mgc0.c too.
   118  	Gidle,
   119  	Grunnable,
   120  	Grunning,
   121  	Gsyscall,
   122  	Gwaiting,
   123  	Gmoribund_unused,  // currently unused, but hardcoded in gdb scripts
   124  	Gdead,
   125  };
   126  enum
   127  {
   128  	// P status
   129  	Pidle,
   130  	Prunning,
   131  	Psyscall,
   132  	Pgcstop,
   133  	Pdead,
   134  };
   135  enum
   136  {
   137  	true	= 1,
   138  	false	= 0,
   139  };
   140  enum
   141  {
   142  	PtrSize = sizeof(void*),
   143  };
   144  enum
   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  };
   151  /*
   152   * structures
   153   */
   154  struct	Lock
   155  {
   156  	// 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;
   160  };
   161  struct	Note
   162  {
   163  	// 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;
   167  };
   168  struct String
   169  {
   170  	byte*	str;
   171  	intgo	len;
   172  };
   173  struct FuncVal
   174  {
   175  	void	(*fn)(void);
   176  	// variable-size, fn-specific data here
   177  };
   178  struct Iface
   179  {
   180  	Itab*	tab;
   181  	void*	data;
   182  };
   183  struct Eface
   184  {
   185  	Type*	type;
   186  	void*	data;
   187  };
   188  struct Complex64
   189  {
   190  	float32	real;
   191  	float32	imag;
   192  };
   193  struct Complex128
   194  {
   195  	float64	real;
   196  	float64	imag;
   197  };
   198  
   199  struct	Slice
   200  {				// must not move anything
   201  	byte*	array;		// actual data
   202  	uintgo	len;		// number of elements
   203  	uintgo	cap;		// allocated number of elements
   204  };
   205  struct	Gobuf
   206  {
   207  	// The offsets of sp, pc, and g are known to (hard-coded in) libmach.
   208  	uintptr	sp;
   209  	uintptr	pc;
   210  	G*	g;
   211  	uintptr	ret;
   212  	void*	ctxt;
   213  	uintptr	lr;
   214  };
   215  struct	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  };
   225  
   226  struct	WinCall
   227  {
   228  	void	(*fn)(void*);
   229  	uintptr	n;	// number of parameters
   230  	void*	args;	// parameters
   231  	uintptr	r1;	// return values
   232  	uintptr	r2;
   233  	uintptr	err;	// error number
   234  };
   235  struct	SEH
   236  {
   237  	void*	prev;
   238  	void*	handler;
   239  };
   240  // describes how to handle callback
   241  struct	WinCallbackContext
   242  {
   243  	void*	gobody;		// Go function to call
   244  	uintptr	argsize;	// callback arguments size (in bytes)
   245  	uintptr	restorestack;	// adjust stack on return by (in bytes) (386 only)
   246  };
   247  
   248  struct	G
   249  {
   250  	// stackguard0 can be set to StackPreempt as opposed to stackguard
   251  	uintptr	stackguard0;	// cannot move - also known to linker, libmach, runtime/cgo
   252  	uintptr	stackbase;	// cannot move - also known to libmach, runtime/cgo
   253  	uint32	panicwrap;	// cannot move - also known to linker
   254  	uint32	selgen;		// valid sudog pointer
   255  	Defer*	defer;
   256  	Panic*	panic;
   257  	Gobuf	sched;
   258  	uintptr	syscallstack;	// if status==Gsyscall, syscallstack = stackbase to use during gc
   259  	uintptr	syscallsp;	// if status==Gsyscall, syscallsp = sched.sp to use during gc
   260  	uintptr	syscallpc;	// if status==Gsyscall, syscallpc = sched.pc to use during gc
   261  	uintptr	syscallguard;	// if status==Gsyscall, syscallguard = stackguard to use during gc
   262  	uintptr	stackguard;	// same as stackguard0, but not set to StackPreempt
   263  	uintptr	stack0;
   264  	uintptr	stacksize;
   265  	G*	alllink;	// on allg
   266  	void*	param;		// passed parameter on wakeup
   267  	int16	status;
   268  	int64	goid;
   269  	int8*	waitreason;	// if status==Gwaiting
   270  	G*	schedlink;
   271  	bool	ispanic;
   272  	bool	issystem;	// do not output in stack dump
   273  	bool	isbackground;	// ignore in deadlock detector
   274  	bool	preempt;	// preemption signal, duplicates stackguard0 = StackPreempt
   275  	int8	raceignore;	// ignore race detection events
   276  	M*	m;		// for debuggers, but offset not hard-coded
   277  	M*	lockedm;
   278  	int32	sig;
   279  	int32	writenbuf;
   280  	byte*	writebuf;
   281  	DeferChunk*	dchunk;
   282  	DeferChunk*	dchunknext;
   283  	uintptr	sigcode0;
   284  	uintptr	sigcode1;
   285  	uintptr	sigpc;
   286  	uintptr	gopc;		// pc of go statement that created this goroutine
   287  	uintptr	racectx;
   288  	uintptr	end[];
   289  };
   290  struct	M
   291  {
   292  	G*	g0;		// goroutine with scheduling stack
   293  	void*	moreargp;	// argument pointer for more stack
   294  	Gobuf	morebuf;	// gobuf arg to morestack
   295  
   296  	// Fields not known to debuggers.
   297  	uint32	moreframesize;	// size arguments to morestack
   298  	uint32	moreargsize;
   299  	uintptr	cret;		// return value from C
   300  	uint64	procid;		// for debuggers, but offset not hard-coded
   301  	G*	gsignal;	// signal-handling G
   302  	uintptr	tls[4];		// thread-local storage (for x86 extern register)
   303  	void	(*mstartfn)(void);
   304  	G*	curg;		// current running goroutine
   305  	G*	caughtsig;	// goroutine running during fatal signal
   306  	P*	p;		// attached P for executing Go code (nil if not executing Go code)
   307  	P*	nextp;
   308  	int32	id;
   309  	int32	mallocing;
   310  	int32	throwing;
   311  	int32	gcing;
   312  	int32	locks;
   313  	int32	dying;
   314  	int32	profilehz;
   315  	int32	helpgc;
   316  	bool	spinning;
   317  	uint32	fastrand;
   318  	uint64	ncgocall;	// number of cgo calls in total
   319  	int32	ncgo;		// number of cgo calls currently in progress
   320  	CgoMal*	cgomal;
   321  	Note	park;
   322  	M*	alllink;	// on allm
   323  	M*	schedlink;
   324  	uint32	machport;	// Return address for Mach IPC (OS X)
   325  	MCache*	mcache;
   326  	int32	stackinuse;
   327  	uint32	stackcachepos;
   328  	uint32	stackcachecnt;
   329  	void*	stackcache[StackCacheSize];
   330  	G*	lockedg;
   331  	uintptr	createstack[32];// Stack that created this thread.
   332  	uint32	freglo[16];	// D[i] lsb and F[i]
   333  	uint32	freghi[16];	// D[i] msb and F[i+16]
   334  	uint32	fflag;		// floating point compare flags
   335  	uint32	locked;		// tracking for LockOSThread
   336  	M*	nextwaitm;	// next M waiting for lock
   337  	uintptr	waitsema;	// semaphore for parking on locks
   338  	uint32	waitsemacount;
   339  	uint32	waitsemalock;
   340  	GCStats	gcstats;
   341  	bool	racecall;
   342  	bool	needextram;
   343  	void	(*waitunlockf)(Lock*);
   344  	void*	waitlock;
   345  
   346  	uintptr	settype_buf[1024];
   347  	uintptr	settype_bufsize;
   348  
   349  #ifdef GOOS_windows
   350  	void*	thread;		// thread handle
   351  	WinCall	wincall;
   352  #endif
   353  #ifdef GOOS_plan9
   354  	int8*	notesig;
   355  	byte*	errstr;
   356  #endif
   357  	SEH*	seh;
   358  	uintptr	end[];
   359  };
   360  
   361  struct P
   362  {
   363  	Lock;
   364  
   365  	int32	id;
   366  	uint32	status;		// one of Pidle/Prunning/...
   367  	P*	link;
   368  	uint32	schedtick;	// incremented on every scheduler call
   369  	uint32	syscalltick;	// incremented on every system call
   370  	M*	m;		// back-link to associated M (nil if idle)
   371  	MCache*	mcache;
   372  
   373  	// Queue of runnable goroutines.
   374  	G**	runq;
   375  	int32	runqhead;
   376  	int32	runqtail;
   377  	int32	runqsize;
   378  
   379  	// Available G's (status == Gdead)
   380  	G*	gfree;
   381  	int32	gfreecnt;
   382  
   383  	byte	pad[64];
   384  };
   385  
   386  // The m->locked word holds two pieces of state counting active calls to LockOSThread/lockOSThread.
   387  // The low bit (LockExternal) is a boolean reporting whether any LockOSThread call is active.
   388  // External locks are not recursive; a second lock is silently ignored.
   389  // The upper bits of m->lockedcount record the nesting depth of calls to lockOSThread
   390  // (counting up by LockInternal), popped by unlockOSThread (counting down by LockInternal).
   391  // Internal locks can be recursive. For instance, a lock for cgo can occur while the main
   392  // goroutine is holding the lock during the initialization phase.
   393  enum
   394  {
   395  	LockExternal = 1,
   396  	LockInternal = 2,
   397  };
   398  
   399  struct	Stktop
   400  {
   401  	// The offsets of these fields are known to (hard-coded in) libmach.
   402  	uintptr	stackguard;
   403  	uintptr	stackbase;
   404  	Gobuf	gobuf;
   405  	uint32	argsize;
   406  	uint32	panicwrap;
   407  
   408  	uint8*	argp;	// pointer to arguments in old frame
   409  	uintptr	free;	// if free>0, call stackfree using free as size
   410  	bool	panic;	// is this frame the top of a panic?
   411  };
   412  struct	SigTab
   413  {
   414  	int32	flags;
   415  	int8	*name;
   416  };
   417  enum
   418  {
   419  	SigNotify = 1<<0,	// let signal.Notify have signal, even if from kernel
   420  	SigKill = 1<<1,		// if signal.Notify doesn't take it, exit quietly
   421  	SigThrow = 1<<2,	// if signal.Notify doesn't take it, exit loudly
   422  	SigPanic = 1<<3,	// if the signal is from the kernel, panic
   423  	SigDefault = 1<<4,	// if the signal isn't explicitly requested, don't monitor it
   424  	SigHandling = 1<<5,	// our signal handler is registered
   425  	SigIgnored = 1<<6,	// the signal was ignored before we registered for it
   426  };
   427  
   428  // Layout of in-memory per-function information prepared by linker
   429  // See http://golang.org/s/go12symtab.
   430  // Keep in sync with linker and with ../../libmach/sym.c
   431  // and with package debug/gosym.
   432  struct	Func
   433  {
   434  	uintptr	entry;	// start pc
   435  	int32	nameoff;// function name
   436  	
   437  	int32	args;	// in/out args size
   438  	int32	frame;	// legacy frame size; use pcsp if possible
   439  
   440  	int32	pcsp;
   441  	int32	pcfile;
   442  	int32	pcln;
   443  	int32	npcdata;
   444  	int32	nfuncdata;
   445  };
   446  
   447  // layout of Itab known to compilers
   448  // allocated in non-garbage-collected memory
   449  struct	Itab
   450  {
   451  	InterfaceType*	inter;
   452  	Type*	type;
   453  	Itab*	link;
   454  	int32	bad;
   455  	int32	unused;
   456  	void	(*fun[])(void);
   457  };
   458  
   459  #ifdef GOOS_windows
   460  enum {
   461     Windows = 1
   462  };
   463  #else
   464  enum {
   465     Windows = 0
   466  };
   467  #endif
   468  
   469  struct	Timers
   470  {
   471  	Lock;
   472  	G	*timerproc;
   473  	bool		sleeping;
   474  	bool		rescheduling;
   475  	Note	waitnote;
   476  	Timer	**t;
   477  	int32	len;
   478  	int32	cap;
   479  };
   480  
   481  // Package time knows the layout of this structure.
   482  // If this struct changes, adjust ../time/sleep.go:/runtimeTimer.
   483  struct	Timer
   484  {
   485  	int32	i;	// heap index
   486  
   487  	// Timer wakes up at when, and then at when+period, ... (period > 0 only)
   488  	// each time calling f(now, arg) in the timer goroutine, so f must be
   489  	// a well-behaved function and not block.
   490  	int64	when;
   491  	int64	period;
   492  	FuncVal	*fv;
   493  	Eface	arg;
   494  };
   495  
   496  // Lock-free stack node.
   497  struct LFNode
   498  {
   499  	LFNode	*next;
   500  	uintptr	pushcnt;
   501  };
   502  
   503  // Parallel for descriptor.
   504  struct ParFor
   505  {
   506  	void (*body)(ParFor*, uint32);	// executed for each element
   507  	uint32 done;			// number of idle threads
   508  	uint32 nthr;			// total number of threads
   509  	uint32 nthrmax;			// maximum number of threads
   510  	uint32 thrseq;			// thread id sequencer
   511  	uint32 cnt;			// iteration space [0, cnt)
   512  	void *ctx;			// arbitrary user context
   513  	bool wait;			// if true, wait while all threads finish processing,
   514  					// otherwise parfor may return while other threads are still working
   515  	ParForThread *thr;		// array of thread descriptors
   516  	uint32 pad;			// to align ParForThread.pos for 64-bit atomic operations
   517  	// stats
   518  	uint64 nsteal;
   519  	uint64 nstealcnt;
   520  	uint64 nprocyield;
   521  	uint64 nosyield;
   522  	uint64 nsleep;
   523  };
   524  
   525  // Track memory allocated by code not written in Go during a cgo call,
   526  // so that the garbage collector can see them.
   527  struct CgoMal
   528  {
   529  	CgoMal	*next;
   530  	void	*alloc;
   531  };
   532  
   533  // Holds variables parsed from GODEBUG env var.
   534  struct DebugVars
   535  {
   536  	int32	gctrace;
   537  	int32	schedtrace;
   538  	int32	scheddetail;
   539  };
   540  
   541  extern bool runtime·precisestack;
   542  
   543  /*
   544   * defined macros
   545   *    you need super-gopher-guru privilege
   546   *    to add this list.
   547   */
   548  #define	nelem(x)	(sizeof(x)/sizeof((x)[0]))
   549  #define	nil		((void*)0)
   550  #define	offsetof(s,m)	(uint32)(&(((s*)0)->m))
   551  #define	ROUND(x, n)	(((x)+(n)-1)&~((n)-1)) /* all-caps to mark as macro: it evaluates n twice */
   552  
   553  /*
   554   * known to compiler
   555   */
   556  enum {
   557  	Structrnd = sizeof(uintptr)
   558  };
   559  
   560  /*
   561   * type algorithms - known to compiler
   562   */
   563  enum
   564  {
   565  	AMEM,
   566  	AMEM0,
   567  	AMEM8,
   568  	AMEM16,
   569  	AMEM32,
   570  	AMEM64,
   571  	AMEM128,
   572  	ANOEQ,
   573  	ANOEQ0,
   574  	ANOEQ8,
   575  	ANOEQ16,
   576  	ANOEQ32,
   577  	ANOEQ64,
   578  	ANOEQ128,
   579  	ASTRING,
   580  	AINTER,
   581  	ANILINTER,
   582  	ASLICE,
   583  	AFLOAT32,
   584  	AFLOAT64,
   585  	ACPLX64,
   586  	ACPLX128,
   587  	Amax
   588  };
   589  typedef	struct	Alg		Alg;
   590  struct	Alg
   591  {
   592  	void	(*hash)(uintptr*, uintptr, void*);
   593  	void	(*equal)(bool*, uintptr, void*, void*);
   594  	void	(*print)(uintptr, void*);
   595  	void	(*copy)(uintptr, void*, void*);
   596  };
   597  
   598  extern	Alg	runtime·algarray[Amax];
   599  
   600  byte*	runtime·startup_random_data;
   601  uint32	runtime·startup_random_data_len;
   602  void	runtime·get_random_data(byte**, int32*);
   603  
   604  enum {
   605  	// hashinit wants this many random bytes
   606  	HashRandomBytes = 32
   607  };
   608  void	runtime·hashinit(void);
   609  
   610  void	runtime·memhash(uintptr*, uintptr, void*);
   611  void	runtime·nohash(uintptr*, uintptr, void*);
   612  void	runtime·strhash(uintptr*, uintptr, void*);
   613  void	runtime·interhash(uintptr*, uintptr, void*);
   614  void	runtime·nilinterhash(uintptr*, uintptr, void*);
   615  void	runtime·aeshash(uintptr*, uintptr, void*);
   616  void	runtime·aeshash32(uintptr*, uintptr, void*);
   617  void	runtime·aeshash64(uintptr*, uintptr, void*);
   618  void	runtime·aeshashstr(uintptr*, uintptr, void*);
   619  
   620  void	runtime·memequal(bool*, uintptr, void*, void*);
   621  void	runtime·noequal(bool*, uintptr, void*, void*);
   622  void	runtime·strequal(bool*, uintptr, void*, void*);
   623  void	runtime·interequal(bool*, uintptr, void*, void*);
   624  void	runtime·nilinterequal(bool*, uintptr, void*, void*);
   625  
   626  bool	runtime·memeq(void*, void*, uintptr);
   627  
   628  void	runtime·memprint(uintptr, void*);
   629  void	runtime·strprint(uintptr, void*);
   630  void	runtime·interprint(uintptr, void*);
   631  void	runtime·nilinterprint(uintptr, void*);
   632  
   633  void	runtime·memcopy(uintptr, void*, void*);
   634  void	runtime·memcopy8(uintptr, void*, void*);
   635  void	runtime·memcopy16(uintptr, void*, void*);
   636  void	runtime·memcopy32(uintptr, void*, void*);
   637  void	runtime·memcopy64(uintptr, void*, void*);
   638  void	runtime·memcopy128(uintptr, void*, void*);
   639  void	runtime·strcopy(uintptr, void*, void*);
   640  void	runtime·algslicecopy(uintptr, void*, void*);
   641  void	runtime·intercopy(uintptr, void*, void*);
   642  void	runtime·nilintercopy(uintptr, void*, void*);
   643  
   644  /*
   645   * deferred subroutine calls
   646   */
   647  struct Defer
   648  {
   649  	int32	siz;
   650  	bool	special;	// not part of defer frame
   651  	bool	free;		// if special, free when done
   652  	byte*	argp;		// where args were copied from
   653  	byte*	pc;
   654  	FuncVal*	fn;
   655  	Defer*	link;
   656  	void*	args[1];	// padded to actual size
   657  };
   658  
   659  struct DeferChunk
   660  {
   661  	DeferChunk	*prev;
   662  	uintptr	off;
   663  };
   664  
   665  /*
   666   * panics
   667   */
   668  struct Panic
   669  {
   670  	Eface	arg;		// argument to panic
   671  	uintptr	stackbase;	// g->stackbase in panic
   672  	Panic*	link;		// link to earlier panic
   673  	bool	recovered;	// whether this panic is over
   674  };
   675  
   676  /*
   677   * stack traces
   678   */
   679  typedef struct Stkframe Stkframe;
   680  struct Stkframe
   681  {
   682  	Func*	fn;	// function being run
   683  	uintptr	pc;	// program counter within fn
   684  	uintptr	lr;	// program counter at caller aka link register
   685  	uintptr	sp;	// stack pointer at pc
   686  	uintptr	fp;	// stack pointer at caller aka frame pointer
   687  	byte*	varp;	// top of local variables
   688  	byte*	argp;	// pointer to function arguments
   689  	uintptr	arglen;	// number of bytes at argp
   690  };
   691  
   692  int32	runtime·gentraceback(uintptr, uintptr, uintptr, G*, int32, uintptr*, int32, void(*)(Stkframe*, void*), void*, bool);
   693  void	runtime·traceback(uintptr pc, uintptr sp, uintptr lr, G* gp);
   694  void	runtime·tracebackothers(G*);
   695  bool	runtime·haszeroargs(uintptr pc);
   696  bool	runtime·topofstack(Func*);
   697  
   698  /*
   699   * external data
   700   */
   701  extern	String	runtime·emptystring;
   702  extern	uintptr runtime·zerobase;
   703  extern	G*	runtime·allg;
   704  extern	G*	runtime·lastg;
   705  extern	M*	runtime·allm;
   706  extern	P**	runtime·allp;
   707  extern	int32	runtime·gomaxprocs;
   708  extern	uint32	runtime·needextram;
   709  extern	uint32	runtime·panicking;
   710  extern	int8*	runtime·goos;
   711  extern	int32	runtime·ncpu;
   712  extern	bool	runtime·iscgo;
   713  extern 	void	(*runtime·sysargs)(int32, uint8**);
   714  extern	uintptr	runtime·maxstring;
   715  extern	uint32	runtime·Hchansize;
   716  extern	uint32	runtime·cpuid_ecx;
   717  extern	uint32	runtime·cpuid_edx;
   718  extern	DebugVars	runtime·debug;
   719  extern	uintptr	runtime·maxstacksize;
   720  
   721  /*
   722   * common functions and data
   723   */
   724  int32	runtime·strcmp(byte*, byte*);
   725  byte*	runtime·strstr(byte*, byte*);
   726  intgo	runtime·findnull(byte*);
   727  intgo	runtime·findnullw(uint16*);
   728  void	runtime·dump(byte*, int32);
   729  int32	runtime·runetochar(byte*, int32);
   730  int32	runtime·charntorune(int32*, uint8*, int32);
   731  
   732  /*
   733   * very low level c-called
   734   */
   735  #define FLUSH(x)	USED(x)
   736  
   737  void	runtime·gogo(Gobuf*);
   738  void	runtime·gostartcall(Gobuf*, void(*)(void), void*);
   739  void	runtime·gostartcallfn(Gobuf*, FuncVal*);
   740  void	runtime·gosave(Gobuf*);
   741  void	runtime·lessstack(void);
   742  void	runtime·goargs(void);
   743  void	runtime·goenvs(void);
   744  void	runtime·goenvs_unix(void);
   745  void*	runtime·getu(void);
   746  void	runtime·throw(int8*);
   747  void	runtime·panicstring(int8*);
   748  void	runtime·prints(int8*);
   749  void	runtime·printf(int8*, ...);
   750  byte*	runtime·mchr(byte*, byte, byte*);
   751  int32	runtime·mcmp(byte*, byte*, uintptr);
   752  void	runtime·memmove(void*, void*, uintptr);
   753  void*	runtime·mal(uintptr);
   754  String	runtime·catstring(String, String);
   755  String	runtime·gostring(byte*);
   756  String  runtime·gostringn(byte*, intgo);
   757  Slice	runtime·gobytes(byte*, intgo);
   758  String	runtime·gostringnocopy(byte*);
   759  String	runtime·gostringw(uint16*);
   760  void	runtime·initsig(void);
   761  void	runtime·sigenable(uint32 sig);
   762  void	runtime·sigdisable(uint32 sig);
   763  int32	runtime·gotraceback(bool *crash);
   764  void	runtime·goroutineheader(G*);
   765  int32	runtime·open(int8*, int32, int32);
   766  int32	runtime·read(int32, void*, int32);
   767  int32	runtime·write(int32, void*, int32);
   768  int32	runtime·close(int32);
   769  int32	runtime·mincore(void*, uintptr, byte*);
   770  bool	runtime·cas(uint32*, uint32, uint32);
   771  bool	runtime·cas64(uint64*, uint64, uint64);
   772  bool	runtime·casp(void**, void*, void*);
   773  // Don't confuse with XADD x86 instruction,
   774  // this one is actually 'addx', that is, add-and-fetch.
   775  uint32	runtime·xadd(uint32 volatile*, int32);
   776  uint64	runtime·xadd64(uint64 volatile*, int64);
   777  uint32	runtime·xchg(uint32 volatile*, uint32);
   778  uint64	runtime·xchg64(uint64 volatile*, uint64);
   779  uint32	runtime·atomicload(uint32 volatile*);
   780  void	runtime·atomicstore(uint32 volatile*, uint32);
   781  void	runtime·atomicstore64(uint64 volatile*, uint64);
   782  uint64	runtime·atomicload64(uint64 volatile*);
   783  void*	runtime·atomicloadp(void* volatile*);
   784  void	runtime·atomicstorep(void* volatile*, void*);
   785  void	runtime·jmpdefer(FuncVal*, void*);
   786  void	runtime·exit1(int32);
   787  void	runtime·ready(G*);
   788  byte*	runtime·getenv(int8*);
   789  int32	runtime·atoi(byte*);
   790  void	runtime·newosproc(M *mp, void *stk);
   791  void	runtime·mstart(void);
   792  G*	runtime·malg(int32);
   793  void	runtime·asminit(void);
   794  void	runtime·mpreinit(M*);
   795  void	runtime·minit(void);
   796  void	runtime·unminit(void);
   797  void	runtime·signalstack(byte*, int32);
   798  void	runtime·symtabinit(void);
   799  Func*	runtime·findfunc(uintptr);
   800  int32	runtime·funcline(Func*, uintptr, String*);
   801  int32	runtime·funcarglen(Func*, uintptr);
   802  int32	runtime·funcspdelta(Func*, uintptr);
   803  int8*	runtime·funcname(Func*);
   804  int32	runtime·pcdatavalue(Func*, int32, uintptr);
   805  void*	runtime·stackalloc(uint32);
   806  void	runtime·stackfree(void*, uintptr);
   807  MCache*	runtime·allocmcache(void);
   808  void	runtime·freemcache(MCache*);
   809  void	runtime·mallocinit(void);
   810  void	runtime·mprofinit(void);
   811  bool	runtime·ifaceeq_c(Iface, Iface);
   812  bool	runtime·efaceeq_c(Eface, Eface);
   813  uintptr	runtime·ifacehash(Iface, uintptr);
   814  uintptr	runtime·efacehash(Eface, uintptr);
   815  void*	runtime·malloc(uintptr size);
   816  void	runtime·free(void *v);
   817  void	runtime·runpanic(Panic*);
   818  uintptr	runtime·getcallersp(void*);
   819  int32	runtime·mcount(void);
   820  int32	runtime·gcount(void);
   821  void	runtime·mcall(void(*)(G*));
   822  uint32	runtime·fastrand1(void);
   823  void	runtime·rewindmorestack(Gobuf*);
   824  int32	runtime·timediv(int64, int32, int32*);
   825  
   826  void runtime·setmg(M*, G*);
   827  void runtime·newextram(void);
   828  void	runtime·exit(int32);
   829  void	runtime·breakpoint(void);
   830  void	runtime·gosched(void);
   831  void	runtime·gosched0(G*);
   832  void	runtime·schedtrace(bool);
   833  void	runtime·park(void(*)(Lock*), Lock*, int8*);
   834  void	runtime·tsleep(int64, int8*);
   835  M*	runtime·newm(void);
   836  void	runtime·goexit(void);
   837  void	runtime·asmcgocall(void (*fn)(void*), void*);
   838  void	runtime·entersyscall(void);
   839  void	runtime·entersyscallblock(void);
   840  void	runtime·exitsyscall(void);
   841  G*	runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
   842  bool	runtime·sigsend(int32 sig);
   843  int32	runtime·callers(int32, uintptr*, int32);
   844  int64	runtime·nanotime(void);
   845  void	runtime·dopanic(int32);
   846  void	runtime·startpanic(void);
   847  void	runtime·freezetheworld(void);
   848  void	runtime·unwindstack(G*, byte*);
   849  void	runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
   850  void	runtime·resetcpuprofiler(int32);
   851  void	runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
   852  void	runtime·usleep(uint32);
   853  int64	runtime·cputicks(void);
   854  int64	runtime·tickspersecond(void);
   855  void	runtime·blockevent(int64, int32);
   856  extern int64 runtime·blockprofilerate;
   857  void	runtime·addtimer(Timer*);
   858  bool	runtime·deltimer(Timer*);
   859  G*	runtime·netpoll(bool);
   860  void	runtime·netpollinit(void);
   861  int32	runtime·netpollopen(uintptr, PollDesc*);
   862  int32   runtime·netpollclose(uintptr);
   863  void	runtime·netpollready(G**, PollDesc*, int32);
   864  uintptr	runtime·netpollfd(PollDesc*);
   865  void	runtime·crash(void);
   866  void	runtime·parsedebugvars(void);
   867  void	_rt0_go(void);
   868  void*	runtime·funcdata(Func*, int32);
   869  
   870  #pragma	varargck	argpos	runtime·printf	1
   871  #pragma	varargck	type	"c"	int32
   872  #pragma	varargck	type	"d"	int32
   873  #pragma	varargck	type	"d"	uint32
   874  #pragma	varargck	type	"D"	int64
   875  #pragma	varargck	type	"D"	uint64
   876  #pragma	varargck	type	"x"	int32
   877  #pragma	varargck	type	"x"	uint32
   878  #pragma	varargck	type	"X"	int64
   879  #pragma	varargck	type	"X"	uint64
   880  #pragma	varargck	type	"p"	void*
   881  #pragma	varargck	type	"p"	uintptr
   882  #pragma	varargck	type	"s"	int8*
   883  #pragma	varargck	type	"s"	uint8*
   884  #pragma	varargck	type	"S"	String
   885  
   886  void	runtime·stoptheworld(void);
   887  void	runtime·starttheworld(void);
   888  extern uint32 runtime·worldsema;
   889  
   890  /*
   891   * mutual exclusion locks.  in the uncontended case,
   892   * as fast as spin locks (just a few user-level instructions),
   893   * but on the contention path they sleep in the kernel.
   894   * a zeroed Lock is unlocked (no need to initialize each lock).
   895   */
   896  void	runtime·lock(Lock*);
   897  void	runtime·unlock(Lock*);
   898  
   899  /*
   900   * sleep and wakeup on one-time events.
   901   * before any calls to notesleep or notewakeup,
   902   * must call noteclear to initialize the Note.
   903   * then, exactly one thread can call notesleep
   904   * and exactly one thread can call notewakeup (once).
   905   * once notewakeup has been called, the notesleep
   906   * will return.  future notesleep will return immediately.
   907   * subsequent noteclear must be called only after
   908   * previous notesleep has returned, e.g. it's disallowed
   909   * to call noteclear straight after notewakeup.
   910   *
   911   * notetsleep is like notesleep but wakes up after
   912   * a given number of nanoseconds even if the event
   913   * has not yet happened.  if a goroutine uses notetsleep to
   914   * wake up early, it must wait to call noteclear until it
   915   * can be sure that no other goroutine is calling
   916   * notewakeup.
   917   *
   918   * notesleep/notetsleep are generally called on g0,
   919   * notetsleepg is similar to notetsleep but is called on user g.
   920   */
   921  void	runtime·noteclear(Note*);
   922  void	runtime·notesleep(Note*);
   923  void	runtime·notewakeup(Note*);
   924  bool	runtime·notetsleep(Note*, int64);  // false - timeout
   925  bool	runtime·notetsleepg(Note*, int64);  // false - timeout
   926  
   927  /*
   928   * low-level synchronization for implementing the above
   929   */
   930  uintptr	runtime·semacreate(void);
   931  int32	runtime·semasleep(int64);
   932  void	runtime·semawakeup(M*);
   933  // or
   934  void	runtime·futexsleep(uint32*, uint32, int64);
   935  void	runtime·futexwakeup(uint32*, uint32);
   936  
   937  /*
   938   * Lock-free stack.
   939   * Initialize uint64 head to 0, compare with 0 to test for emptiness.
   940   * The stack does not keep pointers to nodes,
   941   * so they can be garbage collected if there are no other pointers to nodes.
   942   */
   943  void	runtime·lfstackpush(uint64 *head, LFNode *node);
   944  LFNode*	runtime·lfstackpop(uint64 *head);
   945  
   946  /*
   947   * Parallel for over [0, n).
   948   * body() is executed for each iteration.
   949   * nthr - total number of worker threads.
   950   * ctx - arbitrary user context.
   951   * if wait=true, threads return from parfor() when all work is done;
   952   * otherwise, threads can return while other threads are still finishing processing.
   953   */
   954  ParFor*	runtime·parforalloc(uint32 nthrmax);
   955  void	runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32));
   956  void	runtime·parfordo(ParFor *desc);
   957  
   958  /*
   959   * This is consistent across Linux and BSD.
   960   * If a new OS is added that is different, move this to
   961   * $GOOS/$GOARCH/defs.h.
   962   */
   963  #define EACCES		13
   964  
   965  /*
   966   * low level C-called
   967   */
   968  // for mmap, we only pass the lower 32 bits of file offset to the 
   969  // assembly routine; the higher bits (if required), should be provided
   970  // by the assembly routine as 0.
   971  uint8*	runtime·mmap(byte*, uintptr, int32, int32, int32, uint32);
   972  void	runtime·munmap(byte*, uintptr);
   973  void	runtime·madvise(byte*, uintptr, int32);
   974  void	runtime·memclr(byte*, uintptr);
   975  void	runtime·setcallerpc(void*, void*);
   976  void*	runtime·getcallerpc(void*);
   977  
   978  /*
   979   * runtime go-called
   980   */
   981  void	runtime·printbool(bool);
   982  void	runtime·printbyte(int8);
   983  void	runtime·printfloat(float64);
   984  void	runtime·printint(int64);
   985  void	runtime·printiface(Iface);
   986  void	runtime·printeface(Eface);
   987  void	runtime·printstring(String);
   988  void	runtime·printpc(void*);
   989  void	runtime·printpointer(void*);
   990  void	runtime·printuint(uint64);
   991  void	runtime·printhex(uint64);
   992  void	runtime·printslice(Slice);
   993  void	runtime·printcomplex(Complex128);
   994  void	runtime·newstackcall(FuncVal*, byte*, uint32);
   995  void	reflect·call(FuncVal*, byte*, uint32);
   996  void	runtime·panic(Eface);
   997  void	runtime·panicindex(void);
   998  void	runtime·panicslice(void);
   999  
  1000  /*
  1001   * runtime c-called (but written in Go)
  1002   */
  1003  void	runtime·printany(Eface);
  1004  void	runtime·newTypeAssertionError(String*, String*, String*, String*, Eface*);
  1005  void	runtime·newErrorString(String, Eface*);
  1006  void	runtime·newErrorCString(int8*, Eface*);
  1007  void	runtime·fadd64c(uint64, uint64, uint64*);
  1008  void	runtime·fsub64c(uint64, uint64, uint64*);
  1009  void	runtime·fmul64c(uint64, uint64, uint64*);
  1010  void	runtime·fdiv64c(uint64, uint64, uint64*);
  1011  void	runtime·fneg64c(uint64, uint64*);
  1012  void	runtime·f32to64c(uint32, uint64*);
  1013  void	runtime·f64to32c(uint64, uint32*);
  1014  void	runtime·fcmp64c(uint64, uint64, int32*, bool*);
  1015  void	runtime·fintto64c(int64, uint64*);
  1016  void	runtime·f64tointc(uint64, int64*, bool*);
  1017  
  1018  /*
  1019   * wrapped for go users
  1020   */
  1021  float64	runtime·Inf(int32 sign);
  1022  float64	runtime·NaN(void);
  1023  float32	runtime·float32frombits(uint32 i);
  1024  uint32	runtime·float32tobits(float32 f);
  1025  float64	runtime·float64frombits(uint64 i);
  1026  uint64	runtime·float64tobits(float64 f);
  1027  float64	runtime·frexp(float64 d, int32 *ep);
  1028  bool	runtime·isInf(float64 f, int32 sign);
  1029  bool	runtime·isNaN(float64 f);
  1030  float64	runtime·ldexp(float64 d, int32 e);
  1031  float64	runtime·modf(float64 d, float64 *ip);
  1032  void	runtime·semacquire(uint32*, bool);
  1033  void	runtime·semrelease(uint32*);
  1034  int32	runtime·gomaxprocsfunc(int32 n);
  1035  void	runtime·procyield(uint32);
  1036  void	runtime·osyield(void);
  1037  void	runtime·lockOSThread(void);
  1038  void	runtime·unlockOSThread(void);
  1039  
  1040  void	runtime·mapassign(MapType*, Hmap*, byte*, byte*);
  1041  void	runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*);
  1042  void	runtime·mapiternext(struct hash_iter*);
  1043  bool	runtime·mapiterkey(struct hash_iter*, void*);
  1044  Hmap*	runtime·makemap_c(MapType*, int64);
  1045  
  1046  Hchan*	runtime·makechan_c(ChanType*, int64);
  1047  void	runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*);
  1048  void	runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
  1049  bool	runtime·showframe(Func*, G*);
  1050  void	runtime·printcreatedby(G*);
  1051  
  1052  void	runtime·ifaceE2I(InterfaceType*, Eface, Iface*);
  1053  bool	runtime·ifaceE2I2(InterfaceType*, Eface, Iface*);
  1054  uintptr	runtime·memlimit(void);
  1055  
  1056  // float.c
  1057  extern float64 runtime·nan;
  1058  extern float64 runtime·posinf;
  1059  extern float64 runtime·neginf;
  1060  extern uint64 ·nan;
  1061  extern uint64 ·posinf;
  1062  extern uint64 ·neginf;
  1063  #define ISNAN(f) ((f) != (f))
  1064  
  1065  enum
  1066  {
  1067  	UseSpanType = 1,
  1068  };