]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] runtime: convert dragonfly/amd64 port to Go
authorJoel Sing <jsing@google.com>
Fri, 14 Nov 2014 17:47:20 +0000 (04:47 +1100)
committerJoel Sing <jsing@google.com>
Fri, 14 Nov 2014 17:47:20 +0000 (04:47 +1100)
LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/176750043

src/runtime/defs_dragonfly_amd64.go
src/runtime/os1_dragonfly.go [new file with mode: 0644]
src/runtime/os2_dragonfly.go [new file with mode: 0644]
src/runtime/os_dragonfly.c [deleted file]
src/runtime/os_dragonfly.go
src/runtime/os_dragonfly.h [deleted file]
src/runtime/signal_dragonfly.go [new file with mode: 0644]
src/runtime/signal_dragonfly_amd64.go [new file with mode: 0644]
src/runtime/signal_dragonfly_amd64.h [deleted file]
src/runtime/signals_dragonfly.h [deleted file]

index 0081f7aa67c49755fdf34bdd3389c76fa4aed15e..7e95977054b6120c154d77bcdea42ba97c313e66 100644 (file)
@@ -92,16 +92,16 @@ type rtprio struct {
 }
 
 type lwpparams struct {
-       _type unsafe.Pointer
-       arg   *byte
-       stack *byte
-       tid1  *int32
-       tid2  *int32
+       start_func uintptr
+       arg        unsafe.Pointer
+       stack      uintptr
+       tid1       unsafe.Pointer // *int32
+       tid2       unsafe.Pointer // *int32
 }
 
 type sigaltstackt struct {
-       ss_sp     *int8
-       ss_size   uint64
+       ss_sp     uintptr
+       ss_size   uintptr
        ss_flags  int32
        pad_cgo_0 [4]byte
 }
@@ -111,8 +111,8 @@ type sigset struct {
 }
 
 type stackt struct {
-       ss_sp     *int8
-       ss_size   uint64
+       ss_sp     uintptr
+       ss_size   uintptr
        ss_flags  int32
        pad_cgo_0 [4]byte
 }
@@ -124,7 +124,7 @@ type siginfo struct {
        si_pid    int32
        si_uid    uint32
        si_status int32
-       si_addr   *byte
+       si_addr   uint64
        si_value  [8]byte
        si_band   int64
        __spare__ [7]int32
@@ -132,32 +132,32 @@ type siginfo struct {
 }
 
 type mcontext struct {
-       mc_onstack  int64
-       mc_rdi      int64
-       mc_rsi      int64
-       mc_rdx      int64
-       mc_rcx      int64
-       mc_r8       int64
-       mc_r9       int64
-       mc_rax      int64
-       mc_rbx      int64
-       mc_rbp      int64
-       mc_r10      int64
-       mc_r11      int64
-       mc_r12      int64
-       mc_r13      int64
-       mc_r14      int64
-       mc_r15      int64
-       mc_xflags   int64
-       mc_trapno   int64
-       mc_addr     int64
-       mc_flags    int64
-       mc_err      int64
-       mc_rip      int64
-       mc_cs       int64
-       mc_rflags   int64
-       mc_rsp      int64
-       mc_ss       int64
+       mc_onstack  uint64
+       mc_rdi      uint64
+       mc_rsi      uint64
+       mc_rdx      uint64
+       mc_rcx      uint64
+       mc_r8       uint64
+       mc_r9       uint64
+       mc_rax      uint64
+       mc_rbx      uint64
+       mc_rbp      uint64
+       mc_r10      uint64
+       mc_r11      uint64
+       mc_r12      uint64
+       mc_r13      uint64
+       mc_r14      uint64
+       mc_r15      uint64
+       mc_xflags   uint64
+       mc_trapno   uint64
+       mc_addr     uint64
+       mc_flags    uint64
+       mc_err      uint64
+       mc_rip      uint64
+       mc_cs       uint64
+       mc_rflags   uint64
+       mc_rsp      uint64
+       mc_ss       uint64
        mc_len      uint32
        mc_fpformat uint32
        mc_ownedfp  uint32
@@ -180,11 +180,19 @@ type timespec struct {
        tv_nsec int64
 }
 
+func (ts *timespec) set_sec(x int32) {
+       ts.tv_sec = int64(x)
+}
+
 type timeval struct {
        tv_sec  int64
        tv_usec int64
 }
 
+func (tv *timeval) set_usec(x int32) {
+       tv.tv_usec = int64(x)
+}
+
 type itimerval struct {
        it_interval timeval
        it_value    timeval
diff --git a/src/runtime/os1_dragonfly.go b/src/runtime/os1_dragonfly.go
new file mode 100644 (file)
index 0000000..82bb45b
--- /dev/null
@@ -0,0 +1,220 @@
+// Copyright 2011 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.
+
+package runtime
+
+import "unsafe"
+
+// From DragonFly's <sys/sysctl.h>
+const (
+       _CTL_HW  = 6
+       _HW_NCPU = 3
+)
+
+var sigset_none = sigset{}
+var sigset_all = sigset{[4]uint32{^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0)}}
+
+func getncpu() int32 {
+       mib := [2]uint32{_CTL_HW, _HW_NCPU}
+       out := uint32(0)
+       nout := unsafe.Sizeof(out)
+       ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
+       if ret >= 0 {
+               return int32(out)
+       }
+       return 1
+}
+
+//go:nosplit
+func futexsleep(addr *uint32, val uint32, ns int64) {
+       systemstack(func() {
+               futexsleep1(addr, val, ns)
+       })
+}
+
+func futexsleep1(addr *uint32, val uint32, ns int64) {
+       var timeout int32
+       if ns >= 0 {
+               // The timeout is specified in microseconds - ensure that we
+               // do not end up dividing to zero, which would put us to sleep
+               // indefinitely...
+               timeout = timediv(ns, 1000, nil)
+               if timeout == 0 {
+                       timeout = 1
+               }
+       }
+
+       // sys_umtx_sleep will return EWOULDBLOCK (EAGAIN) when the timeout
+       // expires or EBUSY if the mutex value does not match.
+       ret := sys_umtx_sleep(addr, int32(val), timeout)
+       if ret >= 0 || ret == -_EINTR || ret == -_EAGAIN || ret == -_EBUSY {
+               return
+       }
+
+       print("umtx_sleep addr=", addr, " val=", val, " ret=", ret, "\n")
+       *(*int32)(unsafe.Pointer(uintptr(0x1005))) = 0x1005
+}
+
+//go:nosplit
+func futexwakeup(addr *uint32, cnt uint32) {
+       ret := sys_umtx_wakeup(addr, int32(cnt))
+       if ret >= 0 {
+               return
+       }
+
+       systemstack(func() {
+               print("umtx_wake_addr=", addr, " ret=", ret, "\n")
+               *(*int32)(unsafe.Pointer(uintptr(0x1006))) = 0x1006
+       })
+}
+
+func lwp_start(uintptr)
+
+func newosproc(mp *m, stk unsafe.Pointer) {
+       if false {
+               print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " lwp_start=", funcPC(lwp_start), " id=", mp.id, "/", mp.tls[0], " ostk=", &mp, "\n")
+       }
+
+       var oset sigset
+       sigprocmask(&sigset_all, &oset)
+
+       params := lwpparams{
+               start_func: funcPC(lwp_start),
+               arg:        unsafe.Pointer(mp),
+               stack:      uintptr(stk),
+               tid1:       unsafe.Pointer(&mp.procid),
+               tid2:       nil,
+       }
+
+       mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
+
+       lwp_create(&params)
+       sigprocmask(&oset, nil)
+}
+
+func osinit() {
+       ncpu = getncpu()
+}
+
+var urandom_data [_HashRandomBytes]byte
+var urandom_dev = []byte("/dev/urandom\x00")
+
+//go:nosplit
+func get_random_data(rnd *unsafe.Pointer, rnd_len *int32) {
+       fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0)
+       if read(fd, unsafe.Pointer(&urandom_data), _HashRandomBytes) == _HashRandomBytes {
+               *rnd = unsafe.Pointer(&urandom_data[0])
+               *rnd_len = _HashRandomBytes
+       } else {
+               *rnd = nil
+               *rnd_len = 0
+       }
+       close(fd)
+}
+
+func goenvs() {
+       goenvs_unix()
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+func mpreinit(mp *m) {
+       mp.gsignal = malg(32 * 1024)
+       mp.gsignal.m = mp
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
+func minit() {
+       _g_ := getg()
+
+       // m.procid is a uint64, but lwp_start writes an int32. Fix it up.
+       _g_.m.procid = uint64(*(*int32)(unsafe.Pointer(&_g_.m.procid)))
+
+       // Initialize signal handling
+       signalstack((*byte)(unsafe.Pointer(_g_.m.gsignal.stack.lo)), 32*1024)
+       sigprocmask(&sigset_none, nil)
+}
+
+// Called from dropm to undo the effect of an minit.
+func unminit() {
+       signalstack(nil, 0)
+}
+
+func memlimit() uintptr {
+       /*
+                               TODO: Convert to Go when something actually uses the result.
+
+                               Rlimit rl;
+                               extern byte runtime·text[], runtime·end[];
+                               uintptr used;
+
+                               if(runtime·getrlimit(RLIMIT_AS, &rl) != 0)
+                                       return 0;
+                               if(rl.rlim_cur >= 0x7fffffff)
+                                       return 0;
+
+                               // Estimate our VM footprint excluding the heap.
+                               // Not an exact science: use size of binary plus
+                               // some room for thread stacks.
+                               used = runtime·end - runtime·text + (64<<20);
+                               if(used >= rl.rlim_cur)
+                                       return 0;
+
+                               // If there's not at least 16 MB left, we're probably
+                               // not going to be able to do much.  Treat as no limit.
+                               rl.rlim_cur -= used;
+                               if(rl.rlim_cur < (16<<20))
+                                       return 0;
+
+                               return rl.rlim_cur - used;
+       */
+       return 0
+}
+
+func sigtramp()
+
+type sigactiont struct {
+       sa_sigaction uintptr
+       sa_flags     int32
+       sa_mask      sigset
+}
+
+func setsig(i int32, fn uintptr, restart bool) {
+       var sa sigactiont
+       sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK
+       if restart {
+               sa.sa_flags |= _SA_RESTART
+       }
+       sa.sa_mask = sigset_all
+       if fn == funcPC(sighandler) {
+               fn = funcPC(sigtramp)
+       }
+       sa.sa_sigaction = fn
+       sigaction(i, &sa, nil)
+}
+
+func getsig(i int32) uintptr {
+       var sa sigactiont
+       sigaction(i, nil, &sa)
+       if sa.sa_sigaction == funcPC(sigtramp) {
+               return funcPC(sighandler)
+       }
+       return sa.sa_sigaction
+}
+
+func signalstack(p *byte, n int32) {
+       var st sigaltstackt
+       st.ss_sp = uintptr(unsafe.Pointer(p))
+       st.ss_size = uintptr(n)
+       st.ss_flags = 0
+       if p == nil {
+               st.ss_flags = _SS_DISABLE
+       }
+       sigaltstack(&st, nil)
+}
+
+func unblocksignals() {
+       sigprocmask(&sigset_none, nil)
+}
diff --git a/src/runtime/os2_dragonfly.go b/src/runtime/os2_dragonfly.go
new file mode 100644 (file)
index 0000000..0a20ed4
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2011 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.
+
+package runtime
+
+const (
+       _NSIG       = 33
+       _SI_USER    = 0x10001
+       _SS_DISABLE = 4
+       _RLIMIT_AS  = 10
+)
diff --git a/src/runtime/os_dragonfly.c b/src/runtime/os_dragonfly.c
deleted file mode 100644 (file)
index 75c43b0..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-// Copyright 2011 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 "runtime.h"
-#include "defs_GOOS_GOARCH.h"
-#include "os_GOOS.h"
-#include "signal_unix.h"
-#include "stack.h"
-#include "textflag.h"
-
-extern SigTabT runtime·sigtab[];
-extern int32 runtime·sys_umtx_sleep(uint32*, int32, int32);
-extern int32 runtime·sys_umtx_wakeup(uint32*, int32);
-
-// From DragonFly's <sys/sysctl.h>
-#define        CTL_HW  6
-#define        HW_NCPU 3
-
-static Sigset sigset_none;
-static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, };
-
-static int32
-getncpu(void)
-{
-       uint32 mib[2];
-       uint32 out;
-       int32 ret;
-       uintptr nout;
-
-       // Fetch hw.ncpu via sysctl.
-       mib[0] = CTL_HW;
-       mib[1] = HW_NCPU;
-       nout = sizeof out;
-       out = 0;
-       ret = runtime·sysctl(mib, 2, (byte*)&out, &nout, nil, 0);
-       if(ret >= 0)
-               return out;
-       else
-               return 1;
-}
-
-static void futexsleep(void);
-
-#pragma textflag NOSPLIT
-void
-runtime·futexsleep(uint32 *addr, uint32 val, int64 ns)
-{
-       void (*fn)(void);
-
-       g->m->ptrarg[0] = addr;
-       g->m->scalararg[0] = val;
-       g->m->ptrarg[1] = &ns;
-
-       fn = futexsleep;
-       runtime·onM(&fn);
-}
-
-static void
-futexsleep(void)
-{
-       uint32 *addr;
-       uint32 val;
-       int64 ns;
-       int32 timeout = 0;
-       int32 ret;
-
-       addr = g->m->ptrarg[0];
-       val = g->m->scalararg[0];
-       ns = *(int64*)g->m->ptrarg[1];
-       g->m->ptrarg[0] = nil;
-       g->m->scalararg[0] = 0;
-       g->m->ptrarg[1] = nil;
-
-       if(ns >= 0) {
-               // The timeout is specified in microseconds - ensure that we
-               // do not end up dividing to zero, which would put us to sleep
-               // indefinitely...
-               timeout = runtime·timediv(ns, 1000, nil);
-               if(timeout == 0)
-                       timeout = 1;
-       }
-
-       // sys_umtx_sleep will return EWOULDBLOCK (EAGAIN) when the timeout
-       // expires or EBUSY if the mutex value does not match. 
-       ret = runtime·sys_umtx_sleep(addr, val, timeout);
-       if(ret >= 0 || ret == -EINTR || ret == -EAGAIN || ret == -EBUSY)
-               return;
-
-       runtime·prints("umtx_wait addr=");
-       runtime·printpointer(addr);
-       runtime·prints(" val=");
-       runtime·printint(val);
-       runtime·prints(" ret=");
-       runtime·printint(ret);
-       runtime·prints("\n");
-       *(int32*)0x1005 = 0x1005;
-}
-
-static void badfutexwakeup(void);
-
-#pragma textflag NOSPLIT
-void
-runtime·futexwakeup(uint32 *addr, uint32 cnt)
-{
-       int32 ret;
-       void (*fn)(void);
-
-       ret = runtime·sys_umtx_wakeup(addr, cnt);
-       if(ret >= 0)
-               return;
-
-       g->m->ptrarg[0] = addr;
-       g->m->scalararg[0] = ret;
-       fn = badfutexwakeup;
-       if(g == g->m->gsignal)
-               fn();
-       else
-               runtime·onM(&fn);
-       *(int32*)0x1006 = 0x1006;
-}
-
-static void
-badfutexwakeup(void)
-{
-       void *addr;
-       int32 ret;
-       
-       addr = g->m->ptrarg[0];
-       ret = g->m->scalararg[0];
-       runtime·printf("umtx_wake addr=%p ret=%d\n", addr, ret);
-}
-
-void runtime·lwp_start(void*);
-
-void
-runtime·newosproc(M *mp, void *stk)
-{
-       Lwpparams params;
-       Sigset oset;
-
-       if(0){
-               runtime·printf("newosproc stk=%p m=%p g=%p id=%d/%d ostk=%p\n",
-                       stk, mp, mp->g0, mp->id, (int32)mp->tls[0], &mp);
-       }
-
-       runtime·sigprocmask(&sigset_all, &oset);
-       runtime·memclr((byte*)&params, sizeof params);
-
-       params.func = runtime·lwp_start;
-       params.arg = (byte*)mp;
-       params.stack = (byte*)stk;
-       params.tid1 = (int32*)&mp->procid;
-       params.tid2 = nil;
-
-       mp->tls[0] = mp->id;    // so 386 asm can find it
-
-       runtime·lwp_create(&params);
-       runtime·sigprocmask(&oset, nil);
-}
-
-void
-runtime·osinit(void)
-{
-       runtime·ncpu = getncpu();
-}
-
-#pragma textflag NOSPLIT
-void
-runtime·get_random_data(byte **rnd, int32 *rnd_len)
-{
-       #pragma dataflag NOPTR
-       static byte urandom_data[HashRandomBytes];
-       int32 fd;
-       fd = runtime·open("/dev/urandom", 0 /* O_RDONLY */, 0);
-       if(runtime·read(fd, urandom_data, HashRandomBytes) == HashRandomBytes) {
-               *rnd = urandom_data;
-               *rnd_len = HashRandomBytes;
-       } else {
-               *rnd = nil;
-               *rnd_len = 0;
-       }
-       runtime·close(fd);
-}
-
-void
-runtime·goenvs(void)
-{
-       runtime·goenvs_unix();
-}
-
-// Called to initialize a new m (including the bootstrap m).
-// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
-void
-runtime·mpreinit(M *mp)
-{
-       mp->gsignal = runtime·malg(32*1024);
-       mp->gsignal->m = mp;
-}
-
-// Called to initialize a new m (including the bootstrap m).
-// Called on the new thread, can not allocate memory.
-void
-runtime·minit(void)
-{
-       // Initialize signal handling
-       runtime·signalstack((byte*)g->m->gsignal->stack.lo, 32*1024);
-       runtime·sigprocmask(&sigset_none, nil);
-}
-
-// Called from dropm to undo the effect of an minit.
-void
-runtime·unminit(void)
-{
-       runtime·signalstack(nil, 0);
-}
-
-uintptr
-runtime·memlimit(void)
-{
-       Rlimit rl;
-       extern byte runtime·text[], runtime·end[];
-       uintptr used;
-       
-       if(runtime·getrlimit(RLIMIT_AS, &rl) != 0)
-               return 0;
-       if(rl.rlim_cur >= 0x7fffffff)
-               return 0;
-
-       // Estimate our VM footprint excluding the heap.
-       // Not an exact science: use size of binary plus
-       // some room for thread stacks.
-       used = runtime·end - runtime·text + (64<<20);
-       if(used >= rl.rlim_cur)
-               return 0;
-
-       // If there's not at least 16 MB left, we're probably
-       // not going to be able to do much.  Treat as no limit.
-       rl.rlim_cur -= used;
-       if(rl.rlim_cur < (16<<20))
-               return 0;
-
-       return rl.rlim_cur - used;
-}
-
-extern void runtime·sigtramp(void);
-
-typedef struct sigaction {
-       union {
-               void    (*__sa_handler)(int32);
-               void    (*__sa_sigaction)(int32, Siginfo*, void *);
-       } __sigaction_u;                /* signal handler */
-       int32   sa_flags;               /* see signal options below */
-       Sigset  sa_mask;                /* signal mask to apply */
-} SigactionT;
-
-void
-runtime·setsig(int32 i, GoSighandler *fn, bool restart)
-{
-       SigactionT sa;
-
-       runtime·memclr((byte*)&sa, sizeof sa);
-       sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
-       if(restart)
-               sa.sa_flags |= SA_RESTART;
-       sa.sa_mask.__bits[0] = ~(uint32)0;
-       sa.sa_mask.__bits[1] = ~(uint32)0;
-       sa.sa_mask.__bits[2] = ~(uint32)0;
-       sa.sa_mask.__bits[3] = ~(uint32)0;
-       if(fn == runtime·sighandler)
-               fn = (void*)runtime·sigtramp;
-       sa.__sigaction_u.__sa_sigaction = (void*)fn;
-       runtime·sigaction(i, &sa, nil);
-}
-
-GoSighandler*
-runtime·getsig(int32 i)
-{
-       SigactionT sa;
-
-       runtime·memclr((byte*)&sa, sizeof sa);
-       runtime·sigaction(i, nil, &sa);
-       if((void*)sa.__sigaction_u.__sa_sigaction == runtime·sigtramp)
-               return runtime·sighandler;
-       return (void*)sa.__sigaction_u.__sa_sigaction;
-}
-
-void
-runtime·signalstack(byte *p, int32 n)
-{
-       StackT st;
-
-       st.ss_sp = (void*)p;
-       st.ss_size = n;
-       st.ss_flags = 0;
-       if(p == nil)
-               st.ss_flags = SS_DISABLE;
-       runtime·sigaltstack(&st, nil);
-}
-
-void
-runtime·unblocksignals(void)
-{
-       runtime·sigprocmask(&sigset_none, nil);
-}
-
-#pragma textflag NOSPLIT
-int8*
-runtime·signame(int32 sig)
-{
-       return runtime·sigtab[sig].name;
-}
index cdaa06986ee6e85dfb4ba40abe90a3c6fe671bea..0e00f874fb272fc6d912b86e47cca58bf1232008 100644 (file)
@@ -6,15 +6,35 @@ package runtime
 
 import "unsafe"
 
-func lwp_create(param unsafe.Pointer) int32
-func sigaltstack(new, old unsafe.Pointer)
-func sigaction(sig int32, new, old unsafe.Pointer)
-func sigprocmask(new, old unsafe.Pointer)
-func setitimer(mode int32, new, old unsafe.Pointer)
+//go:noescape
+func lwp_create(param *lwpparams) int32
+
+//go:noescape
+func sigaltstack(new, old *sigaltstackt)
+
+//go:noescape
+func sigaction(sig int32, new, old *sigactiont)
+
+//go:noescape
+func sigprocmask(new, old *sigset)
+
+//go:noescape
+func setitimer(mode int32, new, old *itimerval)
+
+//go:noescape
 func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
+
+//go:noescape
 func getrlimit(kind int32, limit unsafe.Pointer) int32
+
 func raise(sig int32)
-func sys_umtx_sleep(addr unsafe.Pointer, val, timeout int32) int32
-func sys_umtx_wakeup(addr unsafe.Pointer, val int32) int32
+
+//go:noescape
+func sys_umtx_sleep(addr *uint32, val, timeout int32) int32
+
+//go:noescape
+func sys_umtx_wakeup(addr *uint32, val int32) int32
+
+func osyield()
 
 const stackSystem = 0
diff --git a/src/runtime/os_dragonfly.h b/src/runtime/os_dragonfly.h
deleted file mode 100644 (file)
index 389736a..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2011 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.
-
-
-typedef byte* kevent_udata;
-
-int32  runtime·lwp_create(Lwpparams*);
-void   runtime·sigpanic(void);
-void   runtime·sigaltstack(SigaltstackT*, SigaltstackT*);
-struct sigaction;
-void   runtime·sigaction(int32, struct sigaction*, struct sigaction*);
-void   runtime·sigprocmask(Sigset *, Sigset *);
-void   runtime·unblocksignals(void);
-void   runtime·setitimer(int32, Itimerval*, Itimerval*);
-int32  runtime·sysctl(uint32*, uint32, byte*, uintptr*, byte*, uintptr);
-
-enum {
-       NSIG = 33,
-       SI_USER = 0x10001,
-       SS_DISABLE = 4,
-       RLIMIT_AS = 10,
-};
-
-typedef struct Rlimit Rlimit;
-struct Rlimit {
-       int64   rlim_cur;
-       int64   rlim_max;
-};
-int32  runtime·getrlimit(int32, Rlimit*);
diff --git a/src/runtime/signal_dragonfly.go b/src/runtime/signal_dragonfly.go
new file mode 100644 (file)
index 0000000..d37e11a
--- /dev/null
@@ -0,0 +1,46 @@
+// 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.
+
+package runtime
+
+type sigTabT struct {
+       flags int32
+       name  string
+}
+
+var sigtable = [...]sigTabT{
+       /* 0 */ {0, "SIGNONE: no trap"},
+       /* 1 */ {_SigNotify + _SigKill, "SIGHUP: terminal line hangup"},
+       /* 2 */ {_SigNotify + _SigKill, "SIGINT: interrupt"},
+       /* 3 */ {_SigNotify + _SigThrow, "SIGQUIT: quit"},
+       /* 4 */ {_SigThrow, "SIGILL: illegal instruction"},
+       /* 5 */ {_SigThrow, "SIGTRAP: trace trap"},
+       /* 6 */ {_SigNotify + _SigThrow, "SIGABRT: abort"},
+       /* 7 */ {_SigThrow, "SIGEMT: emulate instruction executed"},
+       /* 8 */ {_SigPanic, "SIGFPE: floating-point exception"},
+       /* 9 */ {0, "SIGKILL: kill"},
+       /* 10 */ {_SigPanic, "SIGBUS: bus error"},
+       /* 11 */ {_SigPanic, "SIGSEGV: segmentation violation"},
+       /* 12 */ {_SigThrow, "SIGSYS: bad system call"},
+       /* 13 */ {_SigNotify, "SIGPIPE: write to broken pipe"},
+       /* 14 */ {_SigNotify, "SIGALRM: alarm clock"},
+       /* 15 */ {_SigNotify + _SigKill, "SIGTERM: termination"},
+       /* 16 */ {_SigNotify, "SIGURG: urgent condition on socket"},
+       /* 17 */ {0, "SIGSTOP: stop"},
+       /* 18 */ {_SigNotify + _SigDefault, "SIGTSTP: keyboard stop"},
+       /* 19 */ {0, "SIGCONT: continue after stop"},
+       /* 20 */ {_SigNotify, "SIGCHLD: child status has changed"},
+       /* 21 */ {_SigNotify + _SigDefault, "SIGTTIN: background read from tty"},
+       /* 22 */ {_SigNotify + _SigDefault, "SIGTTOU: background write to tty"},
+       /* 23 */ {_SigNotify, "SIGIO: i/o now possible"},
+       /* 24 */ {_SigNotify, "SIGXCPU: cpu limit exceeded"},
+       /* 25 */ {_SigNotify, "SIGXFSZ: file size limit exceeded"},
+       /* 26 */ {_SigNotify, "SIGVTALRM: virtual alarm clock"},
+       /* 27 */ {_SigNotify, "SIGPROF: profiling alarm clock"},
+       /* 28 */ {_SigNotify, "SIGWINCH: window size change"},
+       /* 29 */ {_SigNotify, "SIGINFO: status request from keyboard"},
+       /* 30 */ {_SigNotify, "SIGUSR1: user-defined signal 1"},
+       /* 31 */ {_SigNotify, "SIGUSR2: user-defined signal 2"},
+       /* 32 */ {_SigNotify, "SIGTHR: reserved"},
+}
diff --git a/src/runtime/signal_dragonfly_amd64.go b/src/runtime/signal_dragonfly_amd64.go
new file mode 100644 (file)
index 0000000..740959c
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright 2013 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.
+
+package runtime
+
+import "unsafe"
+
+type sigctxt struct {
+       info *siginfo
+       ctxt unsafe.Pointer
+}
+
+func (c *sigctxt) regs() *mcontext {
+       return (*mcontext)(unsafe.Pointer(&(*ucontext)(c.ctxt).uc_mcontext))
+}
+func (c *sigctxt) rax() uint64     { return c.regs().mc_rax }
+func (c *sigctxt) rbx() uint64     { return c.regs().mc_rbx }
+func (c *sigctxt) rcx() uint64     { return c.regs().mc_rcx }
+func (c *sigctxt) rdx() uint64     { return c.regs().mc_rdx }
+func (c *sigctxt) rdi() uint64     { return c.regs().mc_rdi }
+func (c *sigctxt) rsi() uint64     { return c.regs().mc_rsi }
+func (c *sigctxt) rbp() uint64     { return c.regs().mc_rbp }
+func (c *sigctxt) rsp() uint64     { return c.regs().mc_rsp }
+func (c *sigctxt) r8() uint64      { return c.regs().mc_r8 }
+func (c *sigctxt) r9() uint64      { return c.regs().mc_r9 }
+func (c *sigctxt) r10() uint64     { return c.regs().mc_r10 }
+func (c *sigctxt) r11() uint64     { return c.regs().mc_r11 }
+func (c *sigctxt) r12() uint64     { return c.regs().mc_r12 }
+func (c *sigctxt) r13() uint64     { return c.regs().mc_r13 }
+func (c *sigctxt) r14() uint64     { return c.regs().mc_r14 }
+func (c *sigctxt) r15() uint64     { return c.regs().mc_r15 }
+func (c *sigctxt) rip() uint64     { return c.regs().mc_rip }
+func (c *sigctxt) rflags() uint64  { return c.regs().mc_rflags }
+func (c *sigctxt) cs() uint64      { return uint64(c.regs().mc_cs) }
+func (c *sigctxt) fs() uint64      { return uint64(c.regs().mc_ss) }
+func (c *sigctxt) gs() uint64      { return uint64(c.regs().mc_ss) }
+func (c *sigctxt) sigcode() uint64 { return uint64(c.info.si_code) }
+func (c *sigctxt) sigaddr() uint64 { return uint64(c.info.si_addr) }
+
+func (c *sigctxt) set_rip(x uint64)     { c.regs().mc_rip = x }
+func (c *sigctxt) set_rsp(x uint64)     { c.regs().mc_rsp = x }
+func (c *sigctxt) set_sigcode(x uint64) { c.info.si_code = int32(x) }
+func (c *sigctxt) set_sigaddr(x uint64) { c.info.si_addr = x }
diff --git a/src/runtime/signal_dragonfly_amd64.h b/src/runtime/signal_dragonfly_amd64.h
deleted file mode 100644 (file)
index 5b4f977..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2013 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.
-
-#define SIG_REGS(ctxt) (((Ucontext*)(ctxt))->uc_mcontext)
-
-#define SIG_RAX(info, ctxt) (SIG_REGS(ctxt).mc_rax)
-#define SIG_RBX(info, ctxt) (SIG_REGS(ctxt).mc_rbx)
-#define SIG_RCX(info, ctxt) (SIG_REGS(ctxt).mc_rcx)
-#define SIG_RDX(info, ctxt) (SIG_REGS(ctxt).mc_rdx)
-#define SIG_RDI(info, ctxt) (SIG_REGS(ctxt).mc_rdi)
-#define SIG_RSI(info, ctxt) (SIG_REGS(ctxt).mc_rsi)
-#define SIG_RBP(info, ctxt) (SIG_REGS(ctxt).mc_rbp)
-#define SIG_RSP(info, ctxt) (SIG_REGS(ctxt).mc_rsp)
-#define SIG_R8(info, ctxt) (SIG_REGS(ctxt).mc_r8)
-#define SIG_R9(info, ctxt) (SIG_REGS(ctxt).mc_r9)
-#define SIG_R10(info, ctxt) (SIG_REGS(ctxt).mc_r10)
-#define SIG_R11(info, ctxt) (SIG_REGS(ctxt).mc_r11)
-#define SIG_R12(info, ctxt) (SIG_REGS(ctxt).mc_r12)
-#define SIG_R13(info, ctxt) (SIG_REGS(ctxt).mc_r13)
-#define SIG_R14(info, ctxt) (SIG_REGS(ctxt).mc_r14)
-#define SIG_R15(info, ctxt) (SIG_REGS(ctxt).mc_r15)
-#define SIG_RIP(info, ctxt) (SIG_REGS(ctxt).mc_rip)
-#define SIG_RFLAGS(info, ctxt) (SIG_REGS(ctxt).mc_rflags)
-
-#define SIG_CS(info, ctxt) (SIG_REGS(ctxt).mc_cs)
-#define SIG_FS(info, ctxt) (SIG_REGS(ctxt).mc_ss)
-#define SIG_GS(info, ctxt) (SIG_REGS(ctxt).mc_ss)
-
-#define SIG_CODE0(info, ctxt) ((info)->si_code)
-#define SIG_CODE1(info, ctxt) ((uintptr)(info)->si_addr)
diff --git a/src/runtime/signals_dragonfly.h b/src/runtime/signals_dragonfly.h
deleted file mode 100644 (file)
index 07343a7..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-// 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 "textflag.h"
-
-#define N SigNotify
-#define K SigKill
-#define T SigThrow
-#define P SigPanic
-#define D SigDefault
-
-#pragma dataflag NOPTR
-SigTab runtime·sigtab[] = {
-       /* 0 */ 0, "SIGNONE: no trap",
-       /* 1 */ N+K, "SIGHUP: terminal line hangup",
-       /* 2 */ N+K, "SIGINT: interrupt",
-       /* 3 */ N+T, "SIGQUIT: quit",
-       /* 4 */ T, "SIGILL: illegal instruction",
-       /* 5 */ T, "SIGTRAP: trace trap",
-       /* 6 */ N+T, "SIGABRT: abort",
-       /* 7 */ T, "SIGEMT: emulate instruction executed",
-       /* 8 */ P, "SIGFPE: floating-point exception",
-       /* 9 */ 0, "SIGKILL: kill",
-       /* 10 */        P, "SIGBUS: bus error",
-       /* 11 */        P, "SIGSEGV: segmentation violation",
-       /* 12 */        T, "SIGSYS: bad system call",
-       /* 13 */        N, "SIGPIPE: write to broken pipe",
-       /* 14 */        N, "SIGALRM: alarm clock",
-       /* 15 */        N+K, "SIGTERM: termination",
-       /* 16 */        N, "SIGURG: urgent condition on socket",
-       /* 17 */        0, "SIGSTOP: stop",
-       /* 18 */        N+D, "SIGTSTP: keyboard stop",
-       /* 19 */        0, "SIGCONT: continue after stop",
-       /* 20 */        N, "SIGCHLD: child status has changed",
-       /* 21 */        N+D, "SIGTTIN: background read from tty",
-       /* 22 */        N+D, "SIGTTOU: background write to tty",
-       /* 23 */        N, "SIGIO: i/o now possible",
-       /* 24 */        N, "SIGXCPU: cpu limit exceeded",
-       /* 25 */        N, "SIGXFSZ: file size limit exceeded",
-       /* 26 */        N, "SIGVTALRM: virtual alarm clock",
-       /* 27 */        N, "SIGPROF: profiling alarm clock",
-       /* 28 */        N, "SIGWINCH: window size change",
-       /* 29 */        N, "SIGINFO: status request from keyboard",
-       /* 30 */        N, "SIGUSR1: user-defined signal 1",
-       /* 31 */        N, "SIGUSR2: user-defined signal 2",
-       /* 32 */        N, "SIGTHR: reserved",
-};
-
-#undef N
-#undef K
-#undef T
-#undef P
-#undef D