OSDN Git Service

runtime: Ignore stack sizes when deciding when to GC.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / runtime.h
index e28bc82..d379f99 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "config.h"
 
-#define _GNU_SOURCE
 #include "go-assert.h"
 #include <setjmp.h>
 #include <signal.h>
@@ -49,13 +48,17 @@ typedef unsigned int uintptr __attribute__ ((mode (pointer)));
 
 typedef        uint8                   bool;
 typedef        uint8                   byte;
+typedef        struct  Func            Func;
 typedef        struct  G               G;
 typedef        union   Lock            Lock;
 typedef        struct  M               M;
 typedef        union   Note            Note;
+typedef        struct  SigTab          SigTab;
 typedef        struct  MCache          MCache;
 typedef struct FixAlloc        FixAlloc;
 typedef        struct  Hchan           Hchan;
+typedef        struct  Timers          Timers;
+typedef        struct  Timer           Timer;
 
 typedef        struct  __go_open_array         Slice;
 typedef        struct  __go_string             String;
@@ -141,6 +144,8 @@ struct      G
        M*      lockedm;
        M*      idlem;
        // int32        sig;
+       int32   writenbuf;
+       byte*   writebuf;
        // uintptr      sigcode0;
        // uintptr      sigcode1;
        // uintptr      sigpc;
@@ -172,15 +177,42 @@ struct    M
        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;
        uint32  waitsemalock;
 };
 
+struct SigTab
+{
+       int32   sig;
+       int32   flags;
+};
+enum
+{
+       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.  */
 
-#ifdef __WINDOWS__
+#ifdef GOOS_windows
 enum {
    Windows = 1
 };
@@ -190,6 +222,38 @@ enum {
 };
 #endif
 
+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.
+ */
 #define        nelem(x)        (sizeof(x)/sizeof((x)[0]))
 #define        nil             ((void*)0)
 #define USED(v)                ((void) v)
@@ -218,26 +282,33 @@ void      runtime_args(int32, byte**);
 void   runtime_osinit();
 void   runtime_goargs(void);
 void   runtime_goenvs(void);
-void   runtime_throw(const char*);
+void   runtime_goenvs_unix(void);
+void   runtime_throw(const char*) __attribute__ ((noreturn));
 void   runtime_panicstring(const char*) __attribute__ ((noreturn));
 void*  runtime_mal(uintptr);
 void   runtime_schedinit(void);
-void   runtime_initsig(int32);
+void   runtime_initsig(void);
+void   runtime_sigenable(uint32 sig);
 String runtime_gostringnocopy(const byte*);
 void*  runtime_mstart(void*);
 G*     runtime_malg(int32, byte**, size_t*);
 void   runtime_minit(void);
 void   runtime_mallocinit(void);
 void   runtime_gosched(void);
+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__("libgo_syscall.syscall.Entersyscall");
+void   runtime_exitsyscall(void) __asm__("libgo_syscall.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*);
 
 /*
@@ -284,26 +355,38 @@ void      runtime_futexsleep(uint32*, uint32, int64);
 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
+
+/*
  * runtime go-called
  */
 void   runtime_panic(Eface);
+struct __go_func_type;
+void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
+                 void **, void **)
+  asm ("libgo_reflect.reflect.call");
 
 /* Functions.  */
 #define runtime_panic __go_panic
 #define runtime_printf printf
 #define runtime_malloc(s) __go_alloc(s)
 #define runtime_free(p) __go_free(p)
-#define runtime_memclr(buf, size) __builtin_memset((buf), 0, (size))
 #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))
-#define runtime_exit(s) _exit(s)
+#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_mmap mmap
-#define runtime_munmap(p, s) munmap((p), (s))
 #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)
@@ -313,27 +396,75 @@ bool      runtime_addfinalizer(void*, void(*fn)(void*), const struct __go_func_type *
 #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*);
 const byte*    runtime_getenv(const char*);
 int32  runtime_atoi(const byte*);
+uint32 runtime_fastrand1(void);
+
 void   runtime_sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp);
 void   runtime_resetcpuprofiler(int32);
 void   runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
-uint32 runtime_fastrand1(void);
+void   runtime_usleep(uint32);
+
+/*
+ * runtime c-called (but written in Go)
+ */
+void   runtime_printany(Eface)
+     __asm__("libgo_runtime.runtime.Printany");
+void   runtime_newTypeAssertionError(const String*, const String*, const String*, const String*, Eface*)
+     __asm__("libgo_runtime.runtime.NewTypeAssertionError");
+void   runtime_newErrorString(String, Eface*)
+     __asm__("libgo_runtime.runtime.NewErrorString");
+
+/*
+ * wrapped for go users
+ */
 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_usleep(uint32);
+void   runtime_LockOSThread(void) __asm__("libgo_runtime.runtime.LockOSThread");
+void   runtime_UnlockOSThread(void) __asm__("libgo_runtime.runtime.UnlockOSThread");
+
+uintptr        runtime_memlimit(void);
+
+// 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_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[];
+};
 
-struct __go_func_type;
-void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
-                 void **, void **)
-  asm ("libgo_reflect.reflect.call");
+void   __go_register_gc_roots(struct root_list*);
 
-#ifdef __rtems__
-void __wrap_rtems_task_variable_add(void **);
-#endif
+// 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;