~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/pkg/runtime/runtime.h

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#ifdef _64BIT
20
20
typedef uint64          uintptr;
21
21
typedef int64           intptr;
 
22
typedef int64           intgo; // Go's int
 
23
typedef uint64          uintgo; // Go's uint
22
24
#else
23
25
typedef uint32          uintptr;
24
 
typedef int32           intptr;
 
26
typedef int32           intptr;
 
27
typedef int32           intgo; // Go's int
 
28
typedef uint32          uintgo; // Go's uint
25
29
#endif
26
30
 
27
31
/*
46
50
typedef struct  Func            Func;
47
51
typedef struct  G               G;
48
52
typedef struct  Gobuf           Gobuf;
49
 
typedef union   Lock            Lock;
 
53
typedef struct  Lock            Lock;
50
54
typedef struct  M               M;
 
55
typedef struct  P               P;
51
56
typedef struct  Mem             Mem;
52
 
typedef union   Note            Note;
 
57
typedef struct  Note            Note;
53
58
typedef struct  Slice           Slice;
54
59
typedef struct  Stktop          Stktop;
55
60
typedef struct  String          String;
 
61
typedef struct  FuncVal         FuncVal;
56
62
typedef struct  SigTab          SigTab;
57
63
typedef struct  MCache          MCache;
58
64
typedef struct  FixAlloc        FixAlloc;
59
65
typedef struct  Iface           Iface;
60
66
typedef struct  Itab            Itab;
 
67
typedef struct  InterfaceType   InterfaceType;
61
68
typedef struct  Eface           Eface;
62
69
typedef struct  Type            Type;
63
70
typedef struct  ChanType                ChanType;
64
71
typedef struct  MapType         MapType;
65
72
typedef struct  Defer           Defer;
 
73
typedef struct  DeferChunk      DeferChunk;
66
74
typedef struct  Panic           Panic;
67
75
typedef struct  Hmap            Hmap;
68
76
typedef struct  Hchan           Hchan;
69
77
typedef struct  Complex64       Complex64;
70
78
typedef struct  Complex128      Complex128;
71
79
typedef struct  WinCall         WinCall;
 
80
typedef struct  SEH             SEH;
72
81
typedef struct  Timers          Timers;
73
82
typedef struct  Timer           Timer;
 
83
typedef struct  GCStats         GCStats;
 
84
typedef struct  LFNode          LFNode;
 
85
typedef struct  ParFor          ParFor;
 
86
typedef struct  ParForThread    ParForThread;
 
87
typedef struct  CgoMal          CgoMal;
 
88
typedef struct  PollDesc        PollDesc;
74
89
 
75
90
/*
76
 
 * per-cpu declaration.
 
91
 * Per-CPU declaration.
 
92
 *
77
93
 * "extern register" is a special storage class implemented by 6c, 8c, etc.
78
 
 * on machines with lots of registers, it allocates a register that will not be
79
 
 * used in generated code.  on the x86, it allocates a slot indexed by a
80
 
 * segment register.
81
 
 *
82
 
 * amd64: allocated downwards from R15
83
 
 * x86: allocated upwards from 0(GS)
84
 
 * arm: allocated downwards from R10
85
 
 *
86
 
 * every C file linked into a Go program must include runtime.h
87
 
 * so that the C compiler knows to avoid other uses of these registers.
88
 
 * the Go compilers know to avoid them.
 
94
 * On the ARM, it is an actual register; elsewhere it is a slot in thread-
 
95
 * local storage indexed by a segment register. See zasmhdr in
 
96
 * src/cmd/dist/buildruntime.c for details, and be aware that the linker may
 
97
 * make further OS-specific changes to the compiler's output. For example,
 
98
 * 6l/linux rewrites 0(GS) as -16(FS).
 
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.
89
103
 */
90
104
extern  register        G*      g;
91
105
extern  register        M*      m;
105
119
        Grunning,
106
120
        Gsyscall,
107
121
        Gwaiting,
108
 
        Gmoribund,
 
122
        Gmoribund_unused,  // currently unused, but hardcoded in gdb scripts
109
123
        Gdead,
110
124
};
111
125
enum
112
126
{
 
127
        // P status
 
128
        Pidle,
 
129
        Prunning,
 
130
        Psyscall,
 
131
        Pgcstop,
 
132
        Pdead,
 
133
};
 
134
enum
 
135
{
113
136
        true    = 1,
114
137
        false   = 0,
115
138
};
116
 
 
 
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
};
117
156
/*
118
157
 * structures
119
158
 */
120
 
union   Lock
 
159
struct  Lock
121
160
{
122
 
        uint32  key;    // futex-based impl
123
 
        M*      waitm;  // linked list of waiting M's (sema-based impl)
 
161
        // Futex-based impl treats it as uint32 key,
 
162
        // while sema-based impl as M* waitm.
 
163
        // Used to be a union, but unions break precise GC.
 
164
        uintptr key;
124
165
};
125
 
union   Note
 
166
struct  Note
126
167
{
127
 
        uint32  key;    // futex-based impl
128
 
        M*      waitm;  // waiting M (sema-based impl)
 
168
        // Futex-based impl treats it as uint32 key,
 
169
        // while sema-based impl as M* waitm.
 
170
        // Used to be a union, but unions break precise GC.
 
171
        uintptr key;
129
172
};
130
173
struct String
131
174
{
132
175
        byte*   str;
133
 
        int32   len;
 
176
        intgo   len;
 
177
};
 
178
struct FuncVal
 
179
{
 
180
        void    (*fn)(void);
 
181
        // variable-size, fn-specific data here
134
182
};
135
183
struct Iface
136
184
{
156
204
struct  Slice
157
205
{                               // must not move anything
158
206
        byte*   array;          // actual data
159
 
        uint32  len;            // number of elements
160
 
        uint32  cap;            // allocated number of elements
 
207
        uintgo  len;            // number of elements
 
208
        uintgo  cap;            // allocated number of elements
161
209
};
162
210
struct  Gobuf
163
211
{
164
212
        // The offsets of these fields are known to (hard-coded in) libmach.
165
 
        byte*   sp;
 
213
        uintptr sp;
166
214
        byte*   pc;
167
215
        G*      g;
168
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
};
169
227
struct  G
170
228
{
171
 
        byte*   stackguard;     // cannot move - also known to linker, libmach, runtime/cgo
172
 
        byte*   stackbase;      // cannot move - also known to libmach, runtime/cgo
 
229
        uintptr stackguard;     // cannot move - also known to linker, libmach, runtime/cgo
 
230
        uintptr stackbase;      // cannot move - also known to libmach, runtime/cgo
173
231
        Defer*  defer;
174
232
        Panic*  panic;
175
233
        Gobuf   sched;
176
 
        byte*   gcstack;                // if status==Gsyscall, gcstack = stackbase to use during gc
177
 
        byte*   gcsp;           // if status==Gsyscall, gcsp = sched.sp to use during gc
178
 
        byte*   gcguard;                // if status==Gsyscall, gcguard = stackguard to use during gc
179
 
        byte*   stack0;
180
 
        byte*   entry;          // initial function
 
234
        uintptr gcstack;                // if status==Gsyscall, gcstack = stackbase to use during gc
 
235
        uintptr gcsp;           // if status==Gsyscall, gcsp = sched.sp to use during gc
 
236
        byte*   gcpc;           // if status==Gsyscall, gcpc = sched.pc to use during gc
 
237
        uintptr gcguard;                // if status==Gsyscall, gcguard = stackguard to use during gc
 
238
        uintptr stack0;
 
239
        FuncVal*        fnstart;                // initial function
181
240
        G*      alllink;        // on allg
182
241
        void*   param;          // passed parameter on wakeup
183
242
        int16   status;
184
 
        int32   goid;
 
243
        int64   goid;
185
244
        uint32  selgen;         // valid sudog pointer
186
245
        int8*   waitreason;     // if status==Gwaiting
187
246
        G*      schedlink;
188
 
        bool    readyonstop;
189
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
190
252
        M*      m;              // for debuggers, but offset not hard-coded
191
253
        M*      lockedm;
192
 
        M*      idlem;
193
254
        int32   sig;
194
255
        int32   writenbuf;
195
256
        byte*   writebuf;
 
257
        DeferChunk      *dchunk;
 
258
        DeferChunk      *dchunknext;
196
259
        uintptr sigcode0;
197
260
        uintptr sigcode1;
198
261
        uintptr sigpc;
199
262
        uintptr gopc;   // pc of go statement that created this goroutine
 
263
        uintptr racectx;
200
264
        uintptr end[];
201
265
};
202
266
struct  M
213
277
        uintptr cret;           // return value from C
214
278
        uint64  procid;         // for debuggers, but offset not hard-coded
215
279
        G*      gsignal;        // signal-handling G
216
 
        uint32  tls[8];         // thread-local storage (for 386 extern register)
 
280
        uintptr tls[4];         // thread-local storage (for x86 extern register)
 
281
        void    (*mstartfn)(void);
217
282
        G*      curg;           // current running goroutine
 
283
        P*      p;              // attached P for executing Go code (nil if not executing Go code)
 
284
        P*      nextp;
218
285
        int32   id;
219
286
        int32   mallocing;
 
287
        int32   throwing;
220
288
        int32   gcing;
221
289
        int32   locks;
222
290
        int32   nomemprof;
223
 
        int32   waitnextg;
224
291
        int32   dying;
225
292
        int32   profilehz;
226
293
        int32   helpgc;
 
294
        bool    blockingsyscall;
 
295
        bool    spinning;
227
296
        uint32  fastrand;
228
 
        uint64  ncgocall;
229
 
        Note    havenextg;
230
 
        G*      nextg;
 
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;
231
301
        M*      alllink;        // on allm
232
302
        M*      schedlink;
233
303
        uint32  machport;       // Return address for Mach IPC (OS X)
234
304
        MCache  *mcache;
235
 
        FixAlloc        *stackalloc;
 
305
        int32   stackinuse;
 
306
        uint32  stackcachepos;
 
307
        uint32  stackcachecnt;
 
308
        void*   stackcache[StackCacheSize];
236
309
        G*      lockedg;
237
 
        G*      idleg;
238
310
        uintptr createstack[32];        // Stack that created this thread.
239
311
        uint32  freglo[16];     // D[i] lsb and F[i]
240
312
        uint32  freghi[16];     // D[i] msb and F[i+16]
241
313
        uint32  fflag;          // floating point compare flags
 
314
        uint32  locked; // tracking for LockOSThread
242
315
        M*      nextwaitm;      // next M waiting for lock
243
316
        uintptr waitsema;       // semaphore for parking on locks
244
317
        uint32  waitsemacount;
245
318
        uint32  waitsemalock;
 
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;
246
329
 
247
330
#ifdef GOOS_windows
248
331
        void*   thread;         // thread handle
249
332
#endif
 
333
#ifdef GOOS_plan9
 
334
        int8*           notesig;
 
335
        byte*   errstr;
 
336
#endif
 
337
        SEH*    seh;
250
338
        uintptr end[];
251
339
};
252
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
 
253
373
struct  Stktop
254
374
{
255
375
        // The offsets of these fields are known to (hard-coded in) libmach.
274
394
        SigThrow = 1<<2,        // if signal.Notify doesn't take it, exit loudly
275
395
        SigPanic = 1<<3,        // if the signal is from the kernel, panic
276
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
277
399
};
278
400
 
279
401
// NOTE(rsc): keep in sync with extern.go:/type.Func.
288
410
        uintptr pc0;    // starting pc, ln for table
289
411
        int32   ln0;
290
412
        int32   frame;  // stack frame size
291
 
        int32   args;   // number of 32-bit in/out args
292
 
        int32   locals; // number of 32-bit locals
 
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);
293
426
};
294
427
 
295
428
struct  WinCall
301
434
        uintptr r2;
302
435
        uintptr err;    // error number
303
436
};
 
437
struct  SEH
 
438
{
 
439
        void*   prev;
 
440
        void*   handler;
 
441
};
304
442
 
305
443
#ifdef GOOS_windows
306
444
enum {
335
473
        // a well-behaved function and not block.
336
474
        int64   when;
337
475
        int64   period;
338
 
        void    (*f)(int64, Eface);
 
476
        FuncVal *fv;
339
477
        Eface   arg;
340
478
};
341
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
 
342
517
/*
343
518
 * defined macros
344
519
 *    you need super-gopher-guru privilege
347
522
#define nelem(x)        (sizeof(x)/sizeof((x)[0]))
348
523
#define nil             ((void*)0)
349
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 */
350
526
 
351
527
/*
352
528
 * known to compiler
395
571
 
396
572
extern  Alg     runtime·algarray[Amax];
397
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
 
398
584
void    runtime·memhash(uintptr*, uintptr, void*);
399
585
void    runtime·nohash(uintptr*, uintptr, void*);
400
586
void    runtime·strhash(uintptr*, uintptr, void*);
401
587
void    runtime·interhash(uintptr*, uintptr, void*);
402
588
void    runtime·nilinterhash(uintptr*, uintptr, void*);
 
589
void    runtime·aeshash(uintptr*, uintptr, void*);
 
590
void    runtime·aeshash32(uintptr*, uintptr, void*);
 
591
void    runtime·aeshash64(uintptr*, uintptr, void*);
 
592
void    runtime·aeshashstr(uintptr*, uintptr, void*);
403
593
 
404
594
void    runtime·memequal(bool*, uintptr, void*, void*);
405
595
void    runtime·noequal(bool*, uintptr, void*, void*);
407
597
void    runtime·interequal(bool*, uintptr, void*, void*);
408
598
void    runtime·nilinterequal(bool*, uintptr, void*, void*);
409
599
 
 
600
bool    runtime·memeq(void*, void*, uintptr);
 
601
 
410
602
void    runtime·memprint(uintptr, void*);
411
603
void    runtime·strprint(uintptr, void*);
412
604
void    runtime·interprint(uintptr, void*);
418
610
void    runtime·memcopy32(uintptr, void*, void*);
419
611
void    runtime·memcopy64(uintptr, void*, void*);
420
612
void    runtime·memcopy128(uintptr, void*, void*);
421
 
void    runtime·memcopy(uintptr, void*, void*);
422
613
void    runtime·strcopy(uintptr, void*, void*);
423
614
void    runtime·algslicecopy(uintptr, void*, void*);
424
615
void    runtime·intercopy(uintptr, void*, void*);
430
621
struct Defer
431
622
{
432
623
        int32   siz;
433
 
        bool    nofree;
 
624
        bool    special; // not part of defer frame
 
625
        bool    free; // if special, free when done
434
626
        byte*   argp;  // where args were copied from
435
627
        byte*   pc;
436
 
        byte*   fn;
 
628
        FuncVal*        fn;
437
629
        Defer*  link;
438
 
        byte    args[8];        // padded to actual size
 
630
        void*   args[1];        // padded to actual size
 
631
};
 
632
 
 
633
struct DeferChunk
 
634
{
 
635
        DeferChunk      *prev;
 
636
        uintptr off;
439
637
};
440
638
 
441
639
/*
453
651
 * external data
454
652
 */
455
653
extern  String  runtime·emptystring;
456
 
G*      runtime·allg;
457
 
G*      runtime·lastg;
458
 
M*      runtime·allm;
 
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;
459
659
extern  int32   runtime·gomaxprocs;
460
660
extern  bool    runtime·singleproc;
461
661
extern  uint32  runtime·panicking;
462
 
extern  int32   runtime·gcwaiting;              // gc is waiting to run
463
 
int8*   runtime·goos;
464
 
int32   runtime·ncpu;
 
662
extern  uint32  runtime·gcwaiting;              // gc is waiting to run
 
663
extern  int8*   runtime·goos;
 
664
extern  int32   runtime·ncpu;
465
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;
466
671
 
467
672
/*
468
673
 * common functions and data
481
686
#define FLUSH(x)        USED(x)
482
687
 
483
688
void    runtime·gogo(Gobuf*, uintptr);
484
 
void    runtime·gogocall(Gobuf*, void(*)(void));
 
689
void    runtime·gogocall(Gobuf*, void(*)(void), uintptr);
 
690
void    runtime·gogocallfn(Gobuf*, FuncVal*);
485
691
void    runtime·gosave(Gobuf*);
486
692
void    runtime·lessstack(void);
487
693
void    runtime·goargs(void);
490
696
void*   runtime·getu(void);
491
697
void    runtime·throw(int8*);
492
698
void    runtime·panicstring(int8*);
493
 
uint32  runtime·rnd(uint32, uint32);
494
699
void    runtime·prints(int8*);
495
700
void    runtime·printf(int8*, ...);
496
701
byte*   runtime·mchr(byte*, byte, byte*);
497
 
int32   runtime·mcmp(byte*, byte*, uint32);
498
 
void    runtime·memmove(void*, void*, uint32);
 
702
int32   runtime·mcmp(byte*, byte*, uintptr);
 
703
void    runtime·memmove(void*, void*, uintptr);
499
704
void*   runtime·mal(uintptr);
500
705
String  runtime·catstring(String, String);
501
706
String  runtime·gostring(byte*);
502
 
String  runtime·gostringn(byte*, int32);
503
 
Slice   runtime·gobytes(byte*, int32);
 
707
String  runtime·gostringn(byte*, intgo);
 
708
Slice   runtime·gobytes(byte*, intgo);
504
709
String  runtime·gostringnocopy(byte*);
505
710
String  runtime·gostringw(uint16*);
506
711
void    runtime·initsig(void);
507
712
void    runtime·sigenable(uint32 sig);
508
 
int32   runtime·gotraceback(void);
 
713
void    runtime·sigdisable(uint32 sig);
 
714
int32   runtime·gotraceback(bool *crash);
509
715
void    runtime·goroutineheader(G*);
510
716
void    runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp);
511
717
void    runtime·tracebackothers(G*);
 
718
int32   runtime·open(int8*, int32, int32);
 
719
int32   runtime·read(int32, void*, int32);
512
720
int32   runtime·write(int32, void*, int32);
 
721
int32   runtime·close(int32);
513
722
int32   runtime·mincore(void*, uintptr, byte*);
514
723
bool    runtime·cas(uint32*, uint32, uint32);
 
724
bool    runtime·cas64(uint64*, uint64*, uint64);
515
725
bool    runtime·casp(void**, void*, void*);
516
726
// Don't confuse with XADD x86 instruction,
517
727
// this one is actually 'addx', that is, add-and-fetch.
518
728
uint32  runtime·xadd(uint32 volatile*, int32);
 
729
uint64  runtime·xadd64(uint64 volatile*, int64);
519
730
uint32  runtime·xchg(uint32 volatile*, uint32);
 
731
uint64  runtime·xchg64(uint64 volatile*, uint64);
520
732
uint32  runtime·atomicload(uint32 volatile*);
521
733
void    runtime·atomicstore(uint32 volatile*, uint32);
 
734
void    runtime·atomicstore64(uint64 volatile*, uint64);
 
735
uint64  runtime·atomicload64(uint64 volatile*);
522
736
void*   runtime·atomicloadp(void* volatile*);
523
737
void    runtime·atomicstorep(void* volatile*, void*);
524
 
void    runtime·jmpdefer(byte*, void*);
 
738
void    runtime·jmpdefer(FuncVal*, void*);
525
739
void    runtime·exit1(int32);
526
740
void    runtime·ready(G*);
527
741
byte*   runtime·getenv(int8*);
528
742
int32   runtime·atoi(byte*);
529
 
void    runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void));
530
 
void    runtime·signalstack(byte*, int32);
 
743
void    runtime·newosproc(M *mp, void *stk);
 
744
void    runtime·mstart(void);
531
745
G*      runtime·malg(int32);
532
746
void    runtime·asminit(void);
 
747
void    runtime·mpreinit(M*);
533
748
void    runtime·minit(void);
 
749
void    runtime·unminit(void);
 
750
void    runtime·signalstack(byte*, int32);
534
751
Func*   runtime·findfunc(uintptr);
535
752
int32   runtime·funcline(Func*, uintptr);
536
753
void*   runtime·stackalloc(uint32);
537
754
void    runtime·stackfree(void*, uintptr);
538
755
MCache* runtime·allocmcache(void);
 
756
void    runtime·freemcache(MCache*);
539
757
void    runtime·mallocinit(void);
 
758
void    runtime·mprofinit(void);
540
759
bool    runtime·ifaceeq_c(Iface, Iface);
541
760
bool    runtime·efaceeq_c(Eface, Eface);
542
 
uintptr runtime·ifacehash(Iface);
543
 
uintptr runtime·efacehash(Eface);
 
761
uintptr runtime·ifacehash(Iface, uintptr);
 
762
uintptr runtime·efacehash(Eface, uintptr);
544
763
void*   runtime·malloc(uintptr size);
545
764
void    runtime·free(void *v);
546
 
bool    runtime·addfinalizer(void*, void(*fn)(void*), int32);
 
765
bool    runtime·addfinalizer(void*, FuncVal *fn, uintptr);
547
766
void    runtime·runpanic(Panic*);
548
767
void*   runtime·getcallersp(void*);
549
768
int32   runtime·mcount(void);
551
770
void    runtime·mcall(void(*)(G*));
552
771
uint32  runtime·fastrand1(void);
553
772
 
 
773
void runtime·setmg(M*, G*);
 
774
void runtime·newextram(void);
554
775
void    runtime·exit(int32);
555
776
void    runtime·breakpoint(void);
556
777
void    runtime·gosched(void);
557
 
void    runtime·tsleep(int64);
 
778
void    runtime·park(void(*)(Lock*), Lock*, int8*);
 
779
void    runtime·tsleep(int64, int8*);
558
780
M*      runtime·newm(void);
559
781
void    runtime·goexit(void);
560
782
void    runtime·asmcgocall(void (*fn)(void*), void*);
561
783
void    runtime·entersyscall(void);
 
784
void    runtime·entersyscallblock(void);
562
785
void    runtime·exitsyscall(void);
563
 
G*      runtime·newproc1(byte*, byte*, int32, int32, void*);
 
786
G*      runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
564
787
bool    runtime·sigsend(int32 sig);
565
788
int32   runtime·callers(int32, uintptr*, int32);
566
 
int32   runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32);
 
789
int32   runtime·gentraceback(byte*, byte*, byte*, G*, int32, uintptr*, int32, void (*)(Func*, byte*, byte*, void*), void*);
567
790
int64   runtime·nanotime(void);
568
791
void    runtime·dopanic(int32);
569
792
void    runtime·startpanic(void);
 
793
void    runtime·unwindstack(G*, byte*);
570
794
void    runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
571
795
void    runtime·resetcpuprofiler(int32);
572
796
void    runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
573
797
void    runtime·usleep(uint32);
574
798
int64   runtime·cputicks(void);
 
799
int64   runtime·tickspersecond(void);
 
800
void    runtime·blockevent(int64, int32);
 
801
extern int64 runtime·blockprofilerate;
 
802
void    runtime·addtimer(Timer*);
 
803
bool    runtime·deltimer(Timer*);
 
804
G*      runtime·netpoll(bool);
 
805
void    runtime·netpollinit(void);
 
806
int32   runtime·netpollopen(int32, PollDesc*);
 
807
int32   runtime·netpollclose(int32);
 
808
void    runtime·netpollready(G**, PollDesc*, int32);
 
809
void    runtime·crash(void);
575
810
 
576
811
#pragma varargck        argpos  runtime·printf  1
577
812
#pragma varargck        type    "d"     int32
589
824
#pragma varargck        type    "S"     String
590
825
 
591
826
void    runtime·stoptheworld(void);
592
 
void    runtime·starttheworld(bool);
 
827
void    runtime·starttheworld(void);
593
828
extern uint32 runtime·worldsema;
594
829
 
595
830
/*
636
871
void    runtime·futexwakeup(uint32*, uint32);
637
872
 
638
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
/*
639
895
 * This is consistent across Linux and BSD.
640
896
 * If a new OS is added that is different, move this to
641
897
 * $GOOS/$GOARCH/defs.h.
645
901
/*
646
902
 * low level C-called
647
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.
648
907
uint8*  runtime·mmap(byte*, uintptr, int32, int32, int32, uint32);
649
908
void    runtime·munmap(byte*, uintptr);
650
909
void    runtime·madvise(byte*, uintptr, int32);
656
915
 * runtime go-called
657
916
 */
658
917
void    runtime·printbool(bool);
 
918
void    runtime·printbyte(int8);
659
919
void    runtime·printfloat(float64);
660
920
void    runtime·printint(int64);
661
921
void    runtime·printiface(Iface);
667
927
void    runtime·printhex(uint64);
668
928
void    runtime·printslice(Slice);
669
929
void    runtime·printcomplex(Complex128);
670
 
void    reflect·call(byte*, byte*, uint32);
 
930
void    reflect·call(FuncVal*, byte*, uint32);
671
931
void    runtime·panic(Eface);
672
932
void    runtime·panicindex(void);
673
933
void    runtime·panicslice(void);
708
968
int32   runtime·gomaxprocsfunc(int32 n);
709
969
void    runtime·procyield(uint32);
710
970
void    runtime·osyield(void);
711
 
void    runtime·LockOSThread(void);
712
 
void    runtime·UnlockOSThread(void);
 
971
void    runtime·lockOSThread(void);
 
972
void    runtime·unlockOSThread(void);
713
973
 
714
974
void    runtime·mapassign(MapType*, Hmap*, byte*, byte*);
715
975
void    runtime·mapaccess(MapType*, Hmap*, byte*, byte*, bool*);
716
976
void    runtime·mapiternext(struct hash_iter*);
717
977
bool    runtime·mapiterkey(struct hash_iter*, void*);
718
 
void    runtime·mapiterkeyvalue(struct hash_iter*, void*, void*);
719
978
Hmap*   runtime·makemap_c(MapType*, int64);
720
979
 
721
980
Hchan*  runtime·makechan_c(ChanType*, int64);
722
 
void    runtime·chansend(ChanType*, Hchan*, byte*, bool*);
 
981
void    runtime·chansend(ChanType*, Hchan*, byte*, bool*, void*);
723
982
void    runtime·chanrecv(ChanType*, Hchan*, byte*, bool*, bool*);
724
 
int32   runtime·chanlen(Hchan*);
725
 
int32   runtime·chancap(Hchan*);
726
 
bool    runtime·showframe(Func*);
 
983
bool    runtime·showframe(Func*, bool);
727
984
 
728
 
void    runtime·ifaceE2I(struct InterfaceType*, Eface, Iface*);
 
985
void    runtime·ifaceE2I(InterfaceType*, Eface, Iface*);
729
986
 
730
987
uintptr runtime·memlimit(void);
731
988
 
738
995
// is forced to deliver the signal to a thread that's actually running.
739
996
// This is a no-op on other systems.
740
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
};