2010-12-03 05:34:57 +01:00
|
|
|
/* runtime.h -- runtime support for Go.
|
|
|
|
|
|
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "go-assert.h"
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-01-29 08:16:20 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2012-05-24 22:44:34 +02:00
|
|
|
#include <unistd.h>
|
2010-12-03 05:34:57 +01:00
|
|
|
#include <pthread.h>
|
2010-12-17 07:42:06 +01:00
|
|
|
#include <semaphore.h>
|
2011-11-28 06:45:49 +01:00
|
|
|
#include <ucontext.h>
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-14 23:26:45 +01:00
|
|
|
#include "array.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
#include "go-alloc.h"
|
|
|
|
#include "go-panic.h"
|
|
|
|
#include "go-string.h"
|
|
|
|
|
|
|
|
/* This file supports C files copied from the 6g runtime library.
|
|
|
|
This is a version of the 6g runtime.h rewritten for gccgo's version
|
|
|
|
of the code. */
|
|
|
|
|
|
|
|
typedef signed int int8 __attribute__ ((mode (QI)));
|
|
|
|
typedef unsigned int uint8 __attribute__ ((mode (QI)));
|
|
|
|
typedef signed int int16 __attribute__ ((mode (HI)));
|
|
|
|
typedef unsigned int uint16 __attribute__ ((mode (HI)));
|
|
|
|
typedef signed int int32 __attribute__ ((mode (SI)));
|
|
|
|
typedef unsigned int uint32 __attribute__ ((mode (SI)));
|
|
|
|
typedef signed int int64 __attribute__ ((mode (DI)));
|
|
|
|
typedef unsigned int uint64 __attribute__ ((mode (DI)));
|
|
|
|
typedef float float32 __attribute__ ((mode (SF)));
|
|
|
|
typedef double float64 __attribute__ ((mode (DF)));
|
|
|
|
typedef unsigned int uintptr __attribute__ ((mode (pointer)));
|
|
|
|
|
|
|
|
/* Defined types. */
|
|
|
|
|
|
|
|
typedef uint8 bool;
|
|
|
|
typedef uint8 byte;
|
2012-03-07 02:16:20 +01:00
|
|
|
typedef struct Func Func;
|
2011-11-11 22:02:48 +01:00
|
|
|
typedef struct G G;
|
2011-11-22 21:24:44 +01:00
|
|
|
typedef union Lock Lock;
|
2010-12-03 05:34:57 +01:00
|
|
|
typedef struct M M;
|
2011-11-22 21:24:44 +01:00
|
|
|
typedef union Note Note;
|
2011-12-21 23:24:47 +01:00
|
|
|
typedef struct SigTab SigTab;
|
2010-12-03 05:34:57 +01:00
|
|
|
typedef struct MCache MCache;
|
2011-09-16 17:47:21 +02:00
|
|
|
typedef struct FixAlloc FixAlloc;
|
2011-12-01 09:06:16 +01:00
|
|
|
typedef struct Hchan Hchan;
|
2011-12-13 00:40:51 +01:00
|
|
|
typedef struct Timers Timers;
|
|
|
|
typedef struct Timer Timer;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-01 09:06:16 +01:00
|
|
|
typedef struct __go_open_array Slice;
|
|
|
|
typedef struct __go_string String;
|
2011-11-30 01:21:52 +01:00
|
|
|
typedef struct __go_interface Iface;
|
|
|
|
typedef struct __go_empty_interface Eface;
|
|
|
|
typedef struct __go_type_descriptor Type;
|
2011-12-01 09:06:16 +01:00
|
|
|
typedef struct __go_defer_stack Defer;
|
2011-11-11 22:02:48 +01:00
|
|
|
typedef struct __go_panic_stack Panic;
|
|
|
|
|
2011-11-30 01:21:52 +01:00
|
|
|
typedef struct __go_func_type FuncType;
|
|
|
|
typedef struct __go_map_type MapType;
|
|
|
|
|
2011-11-28 06:45:49 +01:00
|
|
|
/*
|
|
|
|
* per-cpu declaration.
|
|
|
|
*/
|
|
|
|
extern M* runtime_m(void);
|
|
|
|
extern G* runtime_g(void);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-11-11 22:02:48 +01:00
|
|
|
extern M runtime_m0;
|
|
|
|
extern G runtime_g0;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-11-28 06:45:49 +01:00
|
|
|
/*
|
|
|
|
* defined constants
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// G status
|
|
|
|
//
|
|
|
|
// If you add to this list, add to the list
|
|
|
|
// of "okay during garbage collection" status
|
|
|
|
// in mgc0.c too.
|
|
|
|
Gidle,
|
|
|
|
Grunnable,
|
|
|
|
Grunning,
|
|
|
|
Gsyscall,
|
|
|
|
Gwaiting,
|
|
|
|
Gmoribund,
|
|
|
|
Gdead,
|
|
|
|
};
|
2010-12-03 05:34:57 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
true = 1,
|
|
|
|
false = 0,
|
|
|
|
};
|
|
|
|
|
2011-11-22 21:24:44 +01:00
|
|
|
/*
|
|
|
|
* structures
|
|
|
|
*/
|
|
|
|
union Lock
|
|
|
|
{
|
|
|
|
uint32 key; // futex-based impl
|
|
|
|
M* waitm; // linked list of waiting M's (sema-based impl)
|
|
|
|
};
|
|
|
|
union Note
|
|
|
|
{
|
|
|
|
uint32 key; // futex-based impl
|
|
|
|
M* waitm; // waiting M (sema-based impl)
|
|
|
|
};
|
2011-11-11 22:02:48 +01:00
|
|
|
struct G
|
|
|
|
{
|
|
|
|
Defer* defer;
|
|
|
|
Panic* panic;
|
|
|
|
void* exception; // current exception being thrown
|
|
|
|
bool is_foreign; // whether current exception from other language
|
2011-11-28 06:45:49 +01:00
|
|
|
void *gcstack; // if status==Gsyscall, gcstack = stackbase to use during gc
|
|
|
|
uintptr gcstack_size;
|
|
|
|
void* gcnext_segment;
|
|
|
|
void* gcnext_sp;
|
|
|
|
void* gcinitial_sp;
|
2012-05-22 18:57:23 +02:00
|
|
|
ucontext_t gcregs;
|
2011-11-11 22:02:48 +01:00
|
|
|
byte* entry; // initial function
|
|
|
|
G* alllink; // on allg
|
|
|
|
void* param; // passed parameter on wakeup
|
2011-11-28 06:45:49 +01:00
|
|
|
bool fromgogo; // reached from gogo
|
2011-11-11 22:02:48 +01:00
|
|
|
int16 status;
|
|
|
|
int32 goid;
|
2011-12-01 09:06:16 +01:00
|
|
|
uint32 selgen; // valid sudog pointer
|
2011-11-28 06:45:49 +01:00
|
|
|
const char* waitreason; // if status==Gwaiting
|
2011-11-11 22:02:48 +01:00
|
|
|
G* schedlink;
|
|
|
|
bool readyonstop;
|
|
|
|
bool ispanic;
|
|
|
|
M* m; // for debuggers, but offset not hard-coded
|
|
|
|
M* lockedm;
|
|
|
|
M* idlem;
|
2012-05-17 07:30:25 +02:00
|
|
|
int32 sig;
|
2012-03-02 21:01:37 +01:00
|
|
|
int32 writenbuf;
|
|
|
|
byte* writebuf;
|
2012-05-17 07:30:25 +02:00
|
|
|
uintptr sigcode0;
|
|
|
|
uintptr sigcode1;
|
2011-11-11 22:02:48 +01:00
|
|
|
// uintptr sigpc;
|
2011-11-28 06:45:49 +01:00
|
|
|
uintptr gopc; // pc of go statement that created this goroutine
|
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
G* dotraceback;
|
|
|
|
|
2011-11-28 06:45:49 +01:00
|
|
|
ucontext_t context;
|
|
|
|
void* stack_context[10];
|
2011-11-11 22:02:48 +01:00
|
|
|
};
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
struct M
|
|
|
|
{
|
2011-11-28 06:45:49 +01:00
|
|
|
G* g0; // goroutine with scheduling stack
|
|
|
|
G* gsignal; // signal-handling G
|
2011-11-11 22:02:48 +01:00
|
|
|
G* curg; // current running goroutine
|
2011-09-16 17:47:21 +02:00
|
|
|
int32 id;
|
2010-12-03 05:34:57 +01:00
|
|
|
int32 mallocing;
|
|
|
|
int32 gcing;
|
|
|
|
int32 locks;
|
|
|
|
int32 nomemprof;
|
2011-11-28 06:45:49 +01:00
|
|
|
int32 waitnextg;
|
2011-11-14 23:26:45 +01:00
|
|
|
int32 dying;
|
2011-03-27 21:14:55 +02:00
|
|
|
int32 profilehz;
|
2011-11-28 06:45:49 +01:00
|
|
|
int32 helpgc;
|
2011-09-16 17:47:21 +02:00
|
|
|
uint32 fastrand;
|
2011-11-28 06:45:49 +01:00
|
|
|
Note havenextg;
|
|
|
|
G* nextg;
|
|
|
|
M* alllink; // on allm
|
|
|
|
M* schedlink;
|
2010-12-03 05:34:57 +01:00
|
|
|
MCache *mcache;
|
2011-11-28 06:45:49 +01:00
|
|
|
G* lockedg;
|
|
|
|
G* idleg;
|
2012-03-02 17:38:43 +01:00
|
|
|
uintptr createstack[32]; // Stack that created this thread.
|
2011-11-22 21:24:44 +01:00
|
|
|
M* nextwaitm; // next M waiting for lock
|
|
|
|
uintptr waitsema; // semaphore for parking on locks
|
|
|
|
uint32 waitsemacount;
|
|
|
|
uint32 waitsemalock;
|
2010-12-03 05:34:57 +01:00
|
|
|
};
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
struct SigTab
|
|
|
|
{
|
|
|
|
int32 sig;
|
|
|
|
int32 flags;
|
|
|
|
};
|
|
|
|
enum
|
|
|
|
{
|
2012-03-02 17:38:43 +01:00
|
|
|
SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel
|
2012-03-02 21:01:37 +01:00
|
|
|
SigKill = 1<<1, // if signal.Notify doesn't take it, exit quietly
|
|
|
|
SigThrow = 1<<2, // if signal.Notify doesn't take it, exit loudly
|
|
|
|
SigPanic = 1<<3, // if the signal is from the kernel, panic
|
2012-03-02 17:38:43 +01:00
|
|
|
SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
|
2011-12-21 23:24:47 +01:00
|
|
|
};
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
#ifndef NSIG
|
|
|
|
#define NSIG 32
|
|
|
|
#endif
|
|
|
|
|
2012-03-07 02:16:20 +01:00
|
|
|
// NOTE(rsc): keep in sync with extern.go:/type.Func.
|
|
|
|
// Eventually, the loaded symbol table should be closer to this form.
|
|
|
|
struct Func
|
|
|
|
{
|
|
|
|
String name;
|
|
|
|
uintptr entry; // entry pc
|
|
|
|
};
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
/* Macros. */
|
2011-11-14 23:26:45 +01:00
|
|
|
|
2012-01-13 06:11:45 +01:00
|
|
|
#ifdef GOOS_windows
|
2011-11-14 23:26:45 +01:00
|
|
|
enum {
|
|
|
|
Windows = 1
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
enum {
|
|
|
|
Windows = 0
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-12-13 00:40:51 +01:00
|
|
|
struct Timers
|
|
|
|
{
|
|
|
|
Lock;
|
|
|
|
G *timerproc;
|
|
|
|
bool sleeping;
|
|
|
|
bool rescheduling;
|
|
|
|
Note waitnote;
|
|
|
|
Timer **t;
|
|
|
|
int32 len;
|
|
|
|
int32 cap;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Package time knows the layout of this structure.
|
|
|
|
// If this struct changes, adjust ../time/sleep.go:/runtimeTimer.
|
|
|
|
struct Timer
|
|
|
|
{
|
|
|
|
int32 i; // heap index
|
|
|
|
|
|
|
|
// Timer wakes up at when, and then at when+period, ... (period > 0 only)
|
|
|
|
// each time calling f(now, arg) in the timer goroutine, so f must be
|
|
|
|
// a well-behaved function and not block.
|
|
|
|
int64 when;
|
|
|
|
int64 period;
|
|
|
|
void (*f)(int64, Eface);
|
|
|
|
Eface arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* defined macros
|
|
|
|
* you need super-gopher-guru privilege
|
|
|
|
* to add this list.
|
|
|
|
*/
|
2010-12-03 05:34:57 +01:00
|
|
|
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
#define nil ((void*)0)
|
|
|
|
#define USED(v) ((void) v)
|
|
|
|
|
2011-11-14 23:26:45 +01:00
|
|
|
/*
|
|
|
|
* external data
|
|
|
|
*/
|
2011-11-28 06:45:49 +01:00
|
|
|
G* runtime_allg;
|
|
|
|
G* runtime_lastg;
|
|
|
|
M* runtime_allm;
|
|
|
|
extern int32 runtime_gomaxprocs;
|
|
|
|
extern bool runtime_singleproc;
|
2011-11-14 23:26:45 +01:00
|
|
|
extern uint32 runtime_panicking;
|
2011-11-28 06:45:49 +01:00
|
|
|
extern int32 runtime_gcwaiting; // gc is waiting to run
|
2011-11-22 21:24:44 +01:00
|
|
|
int32 runtime_ncpu;
|
2011-11-14 23:26:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* common functions and data
|
|
|
|
*/
|
|
|
|
int32 runtime_findnull(const byte*);
|
2012-05-24 22:44:34 +02:00
|
|
|
void runtime_dump(byte*, int32);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-11-14 23:26:45 +01:00
|
|
|
/*
|
|
|
|
* very low level c-called
|
|
|
|
*/
|
|
|
|
void runtime_args(int32, byte**);
|
2011-11-22 21:24:44 +01:00
|
|
|
void runtime_osinit();
|
2011-11-14 23:26:45 +01:00
|
|
|
void runtime_goargs(void);
|
|
|
|
void runtime_goenvs(void);
|
2012-01-25 21:56:26 +01:00
|
|
|
void runtime_goenvs_unix(void);
|
2011-12-21 23:24:47 +01:00
|
|
|
void runtime_throw(const char*) __attribute__ ((noreturn));
|
2011-11-30 01:21:52 +01:00
|
|
|
void runtime_panicstring(const char*) __attribute__ ((noreturn));
|
2012-05-24 22:44:34 +02:00
|
|
|
void runtime_prints(const char*);
|
|
|
|
void runtime_printf(const char*, ...);
|
2010-12-03 05:34:57 +01:00
|
|
|
void* runtime_mal(uintptr);
|
2011-11-28 06:45:49 +01:00
|
|
|
void runtime_schedinit(void);
|
2012-03-02 17:38:43 +01:00
|
|
|
void runtime_initsig(void);
|
2012-03-02 21:01:37 +01:00
|
|
|
void runtime_sigenable(uint32 sig);
|
2012-05-17 07:30:25 +02:00
|
|
|
int32 runtime_gotraceback(void);
|
|
|
|
void runtime_goroutineheader(G*);
|
|
|
|
void runtime_goroutinetrailer(G*);
|
|
|
|
void runtime_traceback();
|
|
|
|
void runtime_tracebackothers(G*);
|
2011-11-30 01:21:52 +01:00
|
|
|
String runtime_gostringnocopy(const byte*);
|
2011-11-28 06:45:49 +01:00
|
|
|
void* runtime_mstart(void*);
|
|
|
|
G* runtime_malg(int32, byte**, size_t*);
|
|
|
|
void runtime_minit(void);
|
2010-12-03 05:34:57 +01:00
|
|
|
void runtime_mallocinit(void);
|
2011-11-28 06:45:49 +01:00
|
|
|
void runtime_gosched(void);
|
2011-12-13 00:40:51 +01:00
|
|
|
void runtime_tsleep(int64);
|
|
|
|
M* runtime_newm(void);
|
2011-11-28 06:45:49 +01:00
|
|
|
void runtime_goexit(void);
|
2012-05-15 00:08:42 +02:00
|
|
|
void runtime_entersyscall(void) __asm__("syscall.Entersyscall");
|
|
|
|
void runtime_exitsyscall(void) __asm__("syscall.Exitsyscall");
|
2010-12-03 05:34:57 +01:00
|
|
|
void siginit(void);
|
|
|
|
bool __go_sigsend(int32 sig);
|
2012-03-02 17:38:43 +01:00
|
|
|
int32 runtime_callers(int32, uintptr*, int32);
|
2010-12-03 05:34:57 +01:00
|
|
|
int64 runtime_nanotime(void);
|
2012-02-09 09:19:58 +01:00
|
|
|
int64 runtime_cputicks(void);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
void runtime_stoptheworld(void);
|
2011-10-27 01:57:58 +02:00
|
|
|
void runtime_starttheworld(bool);
|
2012-03-02 21:01:37 +01:00
|
|
|
extern uint32 runtime_worldsema;
|
2011-11-28 06:45:49 +01:00
|
|
|
G* __go_go(void (*pfn)(void*), void*);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mutual exclusion locks. in the uncontended case,
|
|
|
|
* as fast as spin locks (just a few user-level instructions),
|
|
|
|
* but on the contention path they sleep in the kernel.
|
2011-11-22 21:24:44 +01:00
|
|
|
* a zeroed Lock is unlocked (no need to initialize each lock).
|
2010-12-03 05:34:57 +01:00
|
|
|
*/
|
|
|
|
void runtime_lock(Lock*);
|
|
|
|
void runtime_unlock(Lock*);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sleep and wakeup on one-time events.
|
|
|
|
* before any calls to notesleep or notewakeup,
|
|
|
|
* must call noteclear to initialize the Note.
|
2011-11-22 21:24:44 +01:00
|
|
|
* then, exactly one thread can call notesleep
|
2010-12-03 05:34:57 +01:00
|
|
|
* and exactly one thread can call notewakeup (once).
|
2011-11-22 21:24:44 +01:00
|
|
|
* once notewakeup has been called, the notesleep
|
|
|
|
* will return. future notesleep will return immediately.
|
|
|
|
* subsequent noteclear must be called only after
|
|
|
|
* previous notesleep has returned, e.g. it's disallowed
|
|
|
|
* to call noteclear straight after notewakeup.
|
|
|
|
*
|
|
|
|
* notetsleep is like notesleep but wakes up after
|
|
|
|
* a given number of nanoseconds even if the event
|
|
|
|
* has not yet happened. if a goroutine uses notetsleep to
|
|
|
|
* wake up early, it must wait to call noteclear until it
|
|
|
|
* can be sure that no other goroutine is calling
|
|
|
|
* notewakeup.
|
2010-12-03 05:34:57 +01:00
|
|
|
*/
|
2011-03-27 21:14:55 +02:00
|
|
|
void runtime_noteclear(Note*);
|
|
|
|
void runtime_notesleep(Note*);
|
|
|
|
void runtime_notewakeup(Note*);
|
2011-11-22 21:24:44 +01:00
|
|
|
void runtime_notetsleep(Note*, int64);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* low-level synchronization for implementing the above
|
|
|
|
*/
|
|
|
|
uintptr runtime_semacreate(void);
|
|
|
|
int32 runtime_semasleep(int64);
|
|
|
|
void runtime_semawakeup(M*);
|
|
|
|
// or
|
|
|
|
void runtime_futexsleep(uint32*, uint32, int64);
|
|
|
|
void runtime_futexwakeup(uint32*, uint32);
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
/*
|
|
|
|
* low level C-called
|
|
|
|
*/
|
|
|
|
#define runtime_mmap mmap
|
|
|
|
#define runtime_munmap munmap
|
|
|
|
#define runtime_madvise madvise
|
|
|
|
#define runtime_memclr(buf, size) __builtin_memset((buf), 0, (size))
|
2012-03-02 21:01:37 +01:00
|
|
|
#define runtime_getcallerpc(p) __builtin_return_address(0)
|
2012-03-02 17:38:43 +01:00
|
|
|
|
|
|
|
#ifdef __rtems__
|
|
|
|
void __wrap_rtems_task_variable_add(void **);
|
|
|
|
#endif
|
|
|
|
|
2012-05-24 22:44:34 +02:00
|
|
|
/*
|
|
|
|
* Names generated by gccgo.
|
|
|
|
*/
|
|
|
|
#define runtime_printbool __go_print_bool
|
|
|
|
#define runtime_printfloat __go_print_double
|
|
|
|
#define runtime_printint __go_print_int64
|
|
|
|
#define runtime_printiface __go_print_interface
|
|
|
|
#define runtime_printeface __go_print_empty_interface
|
|
|
|
#define runtime_printstring __go_print_string
|
|
|
|
#define runtime_printpointer __go_print_pointer
|
|
|
|
#define runtime_printuint __go_print_uint64
|
|
|
|
#define runtime_printslice __go_print_slice
|
|
|
|
#define runtime_printcomplex __go_print_complex
|
|
|
|
|
2011-11-30 01:21:52 +01:00
|
|
|
/*
|
|
|
|
* runtime go-called
|
|
|
|
*/
|
2012-05-24 22:44:34 +02:00
|
|
|
void runtime_printbool(_Bool);
|
|
|
|
void runtime_printfloat(double);
|
|
|
|
void runtime_printint(int64);
|
|
|
|
void runtime_printiface(Iface);
|
|
|
|
void runtime_printeface(Eface);
|
|
|
|
void runtime_printstring(String);
|
|
|
|
void runtime_printpc(void*);
|
|
|
|
void runtime_printpointer(void*);
|
|
|
|
void runtime_printuint(uint64);
|
|
|
|
void runtime_printhex(uint64);
|
|
|
|
void runtime_printslice(Slice);
|
|
|
|
void runtime_printcomplex(__complex double);
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
struct __go_func_type;
|
|
|
|
void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
|
|
|
|
void **, void **)
|
2012-05-15 00:08:42 +02:00
|
|
|
asm ("reflect.call");
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
/* Functions. */
|
2011-11-30 01:21:52 +01:00
|
|
|
#define runtime_panic __go_panic
|
2012-05-24 22:44:34 +02:00
|
|
|
#define runtime_write(d, v, n) write((d), (v), (n))
|
2010-12-03 05:34:57 +01:00
|
|
|
#define runtime_malloc(s) __go_alloc(s)
|
|
|
|
#define runtime_free(p) __go_free(p)
|
|
|
|
#define runtime_strcmp(s1, s2) __builtin_strcmp((s1), (s2))
|
|
|
|
#define runtime_mcmp(a, b, s) __builtin_memcmp((a), (b), (s))
|
|
|
|
#define runtime_memmove(a, b, s) __builtin_memmove((a), (b), (s))
|
2012-02-28 21:57:15 +01:00
|
|
|
#define runtime_exit(s) exit(s)
|
2010-12-03 05:34:57 +01:00
|
|
|
MCache* runtime_allocmcache(void);
|
|
|
|
void free(void *v);
|
2010-12-17 07:42:06 +01:00
|
|
|
#define runtime_cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
|
2011-03-17 00:05:44 +01:00
|
|
|
#define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
|
2011-10-27 01:57:58 +02:00
|
|
|
#define runtime_xadd(p, v) __sync_add_and_fetch (p, v)
|
2011-11-22 21:24:44 +01:00
|
|
|
#define runtime_xchg(p, v) __atomic_exchange_n (p, v, __ATOMIC_SEQ_CST)
|
|
|
|
#define runtime_atomicload(p) __atomic_load_n (p, __ATOMIC_SEQ_CST)
|
|
|
|
#define runtime_atomicstore(p, v) __atomic_store_n (p, v, __ATOMIC_SEQ_CST)
|
|
|
|
#define runtime_atomicloadp(p) __atomic_load_n (p, __ATOMIC_SEQ_CST)
|
|
|
|
#define runtime_atomicstorep(p, v) __atomic_store_n (p, v, __ATOMIC_SEQ_CST)
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-03-02 21:01:37 +01:00
|
|
|
struct __go_func_type;
|
|
|
|
bool runtime_addfinalizer(void*, void(*fn)(void*), const struct __go_func_type *);
|
|
|
|
#define runtime_getcallersp(p) __builtin_frame_address(1)
|
|
|
|
int32 runtime_mcount(void);
|
|
|
|
int32 runtime_gcount(void);
|
2011-11-14 23:26:45 +01:00
|
|
|
void runtime_dopanic(int32) __attribute__ ((noreturn));
|
|
|
|
void runtime_startpanic(void);
|
2011-11-28 06:45:49 +01:00
|
|
|
void runtime_ready(G*);
|
2011-11-14 23:26:45 +01:00
|
|
|
const byte* runtime_getenv(const char*);
|
|
|
|
int32 runtime_atoi(const byte*);
|
2011-12-02 20:34:41 +01:00
|
|
|
uint32 runtime_fastrand1(void);
|
|
|
|
|
2011-11-28 06:45:49 +01:00
|
|
|
void runtime_sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
|
2011-03-27 21:14:55 +02:00
|
|
|
void runtime_resetcpuprofiler(int32);
|
|
|
|
void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
|
2011-12-02 20:34:41 +01:00
|
|
|
void runtime_usleep(uint32);
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
/*
|
|
|
|
* runtime c-called (but written in Go)
|
|
|
|
*/
|
|
|
|
void runtime_printany(Eface)
|
2012-05-15 00:08:42 +02:00
|
|
|
__asm__("runtime.Printany");
|
2012-03-02 17:38:43 +01:00
|
|
|
void runtime_newTypeAssertionError(const String*, const String*, const String*, const String*, Eface*)
|
2012-05-15 00:08:42 +02:00
|
|
|
__asm__("runtime.NewTypeAssertionError");
|
2012-03-02 17:38:43 +01:00
|
|
|
void runtime_newErrorString(String, Eface*)
|
2012-05-15 00:08:42 +02:00
|
|
|
__asm__("runtime.NewErrorString");
|
2012-03-02 17:38:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* wrapped for go users
|
|
|
|
*/
|
2012-05-24 22:44:34 +02:00
|
|
|
bool runtime_isInf(float64 f, int32 sign);
|
|
|
|
#define runtime_isNaN(f) __builtin_isnan(f)
|
2011-11-28 06:45:49 +01:00
|
|
|
void runtime_semacquire(uint32 volatile *);
|
|
|
|
void runtime_semrelease(uint32 volatile *);
|
|
|
|
int32 runtime_gomaxprocsfunc(int32 n);
|
2011-10-27 01:57:58 +02:00
|
|
|
void runtime_procyield(uint32);
|
|
|
|
void runtime_osyield(void);
|
2012-05-15 00:08:42 +02:00
|
|
|
void runtime_LockOSThread(void) __asm__("runtime.LockOSThread");
|
|
|
|
void runtime_UnlockOSThread(void) __asm__("runtime.UnlockOSThread");
|
2011-03-27 21:14:55 +02:00
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
bool runtime_showframe(const unsigned char*);
|
|
|
|
|
2012-03-06 18:57:23 +01:00
|
|
|
uintptr runtime_memlimit(void);
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
// If appropriate, ask the operating system to control whether this
|
|
|
|
// thread should receive profiling signals. This is only necessary on OS X.
|
|
|
|
// An operating system should not deliver a profiling signal to a
|
|
|
|
// thread that is not actually executing (what good is that?), but that's
|
|
|
|
// what OS X prefers to do. When profiling is turned on, we mask
|
|
|
|
// away the profiling signal when threads go to sleep, so that OS X
|
|
|
|
// is forced to deliver the signal to a thread that's actually running.
|
|
|
|
// This is a no-op on other systems.
|
|
|
|
void runtime_setprof(bool);
|
2011-12-13 00:40:51 +01:00
|
|
|
|
|
|
|
void runtime_time_scan(void (*)(byte*, int64));
|
2012-03-02 17:38:43 +01:00
|
|
|
|
|
|
|
void runtime_setsig(int32, bool, bool);
|
|
|
|
#define runtime_setitimer setitimer
|
2012-03-06 18:57:23 +01:00
|
|
|
|
|
|
|
void runtime_check(void);
|
|
|
|
|
|
|
|
// A list of global variables that the garbage collector must scan.
|
|
|
|
struct root_list {
|
|
|
|
struct root_list *next;
|
|
|
|
struct root {
|
|
|
|
void *decl;
|
|
|
|
size_t size;
|
|
|
|
} roots[];
|
|
|
|
};
|
|
|
|
|
|
|
|
void __go_register_gc_roots(struct root_list*);
|
2012-04-20 06:58:26 +02:00
|
|
|
|
|
|
|
// Size of stack space allocated using Go's allocator.
|
|
|
|
// This will be 0 when using split stacks, as in that case
|
|
|
|
// the stacks are allocated by the splitstack library.
|
|
|
|
extern uintptr runtime_stacks_sys;
|
2012-05-17 07:30:25 +02:00
|
|
|
|
|
|
|
extern _Bool __go_file_line (uintptr, String*, String*, int *);
|