#include "config.h"
#include "go-assert.h"
-#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#include <ucontext.h>
typedef uint8 bool;
typedef uint8 byte;
+typedef struct Func Func;
typedef struct G G;
typedef union Lock Lock;
typedef struct M M;
typedef struct __go_func_type FuncType;
typedef struct __go_map_type MapType;
+typedef struct Traceback Traceback;
+
/*
* per-cpu declaration.
*/
void* gcnext_segment;
void* gcnext_sp;
void* gcinitial_sp;
- jmp_buf gcregs;
+ ucontext_t gcregs;
byte* entry; // initial function
G* alllink; // on allg
void* param; // passed parameter on wakeup
M* m; // for debuggers, but offset not hard-coded
M* lockedm;
M* idlem;
- // int32 sig;
- // uintptr sigcode0;
- // uintptr sigcode1;
+ int32 sig;
+ int32 writenbuf;
+ byte* writebuf;
+ uintptr sigcode0;
+ uintptr sigcode1;
// uintptr sigpc;
uintptr gopc; // pc of go statement that created this goroutine
+ Traceback* traceback;
+
ucontext_t context;
void* stack_context[10];
};
MCache *mcache;
G* lockedg;
G* idleg;
+ uintptr createstack[32]; // Stack that created this thread.
M* nextwaitm; // next M waiting for lock
uintptr waitsema; // semaphore for parking on locks
uint32 waitsemacount;
};
enum
{
- SigCatch = 1<<0,
- SigIgnore = 1<<1,
- SigRestart = 1<<2,
- SigQueue = 1<<3,
- SigPanic = 1<<4,
+ SigNotify = 1<<0, // let signal.Notify have signal, even if from kernel
+ 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
+ SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
+};
+
+#ifndef NSIG
+#define NSIG 32
+#endif
+
+// 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
};
/* Macros. */
* common functions and data
*/
int32 runtime_findnull(const byte*);
+void runtime_dump(byte*, int32);
/*
* very low level c-called
void runtime_goenvs_unix(void);
void runtime_throw(const char*) __attribute__ ((noreturn));
void runtime_panicstring(const char*) __attribute__ ((noreturn));
+void runtime_prints(const char*);
+void runtime_printf(const char*, ...);
void* runtime_mal(uintptr);
void runtime_schedinit(void);
-void runtime_initsig(int32);
+void runtime_initsig(void);
+void runtime_sigenable(uint32 sig);
+int32 runtime_gotraceback(void);
+void runtime_goroutineheader(G*);
+void runtime_goroutinetrailer(G*);
+void runtime_traceback();
+void runtime_tracebackothers(G*);
+void runtime_printtrace(uintptr*, int32);
String runtime_gostringnocopy(const byte*);
void* runtime_mstart(void*);
G* runtime_malg(int32, byte**, size_t*);
void runtime_tsleep(int64);
M* runtime_newm(void);
void runtime_goexit(void);
-void runtime_entersyscall(void) __asm__("libgo_syscall.syscall.entersyscall");
-void runtime_exitsyscall(void) __asm__("libgo_syscall.syscall.exitsyscall");
+void runtime_entersyscall(void) __asm__("syscall.Entersyscall");
+void runtime_exitsyscall(void) __asm__("syscall.Exitsyscall");
void siginit(void);
bool __go_sigsend(int32 sig);
+int32 runtime_callers(int32, uintptr*, int32);
int64 runtime_nanotime(void);
int64 runtime_cputicks(void);
void runtime_stoptheworld(void);
void runtime_starttheworld(bool);
+extern uint32 runtime_worldsema;
G* __go_go(void (*pfn)(void*), void*);
/*
void runtime_futexwakeup(uint32*, uint32);
/*
+ * 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))
+#define runtime_getcallerpc(p) __builtin_return_address(0)
+
+#ifdef __rtems__
+void __wrap_rtems_task_variable_add(void **);
+#endif
+
+/*
+ * 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
+
+/*
* runtime go-called
*/
-void runtime_panic(Eface);
+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);
+
+struct __go_func_type;
+void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
+ void **, void **)
+ asm ("reflect.call");
/* Functions. */
#define runtime_panic __go_panic
-#define runtime_printf printf
+#define runtime_write(d, v, n) write((d), (v), (n))
#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_exit(s) exit(s)
MCache* runtime_allocmcache(void);
void free(void *v);
-struct __go_func_type;
-bool runtime_addfinalizer(void*, void(*fn)(void*), const struct __go_func_type *);
#define runtime_cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
#define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
#define runtime_xadd(p, v) __sync_add_and_fetch (p, v)
#define runtime_atomicloadp(p) __atomic_load_n (p, __ATOMIC_SEQ_CST)
#define runtime_atomicstorep(p, v) __atomic_store_n (p, v, __ATOMIC_SEQ_CST)
+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);
void runtime_dopanic(int32) __attribute__ ((noreturn));
void runtime_startpanic(void);
void runtime_ready(G*);
void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
void runtime_usleep(uint32);
+/*
+ * runtime c-called (but written in Go)
+ */
+void runtime_printany(Eface)
+ __asm__("runtime.Printany");
+void runtime_newTypeAssertionError(const String*, const String*, const String*, const String*, Eface*)
+ __asm__("runtime.NewTypeAssertionError");
+void runtime_newErrorString(String, Eface*)
+ __asm__("runtime.NewErrorString");
+
+/*
+ * wrapped for go users
+ */
+bool runtime_isInf(float64 f, int32 sign);
+#define runtime_isNaN(f) __builtin_isnan(f)
void runtime_semacquire(uint32 volatile *);
void runtime_semrelease(uint32 volatile *);
int32 runtime_gomaxprocsfunc(int32 n);
void runtime_procyield(uint32);
void runtime_osyield(void);
-void runtime_LockOSThread(void) __asm__("libgo_runtime.runtime.LockOSThread");
-void runtime_UnlockOSThread(void) __asm__("libgo_runtime.runtime.UnlockOSThread");
+void runtime_LockOSThread(void) __asm__("runtime.LockOSThread");
+void runtime_UnlockOSThread(void) __asm__("runtime.UnlockOSThread");
-/*
- * 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))
+bool runtime_showframe(const unsigned char*);
-struct __go_func_type;
-void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
- void **, void **)
- asm ("libgo_reflect.reflect.call");
+uintptr runtime_memlimit(void);
-#ifdef __rtems__
-void __wrap_rtems_task_variable_add(void **);
-#endif
+// 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);
void runtime_time_scan(void (*)(byte*, int64));
+void runtime_trampoline_scan(void (*)(byte *, int64));
+
+void runtime_setsig(int32, bool, bool);
+#define runtime_setitimer setitimer
+
+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*);
+
+// 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;
+
+extern _Bool __go_file_line (uintptr, String*, String*, int *);