2013-03-19 11:40:29 -06:00
|
|
|
// 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.
|
2009-11-17 09:20:58 -07:00
|
|
|
|
|
|
|
#include "runtime.h"
|
2011-12-16 13:33:58 -07:00
|
|
|
#include "defs_GOOS_GOARCH.h"
|
|
|
|
#include "os_GOOS.h"
|
2013-03-14 12:35:13 -06:00
|
|
|
#include "signal_unix.h"
|
runtime: fix signal stack bug
In CL 4188061 I changed malg to allocate the requested
number of bytes n, not n+StackGuard, so that the
allocations would use rounder numbers.
The allocation of the signal stack asks for 32k and
then used g->stackguard as the base, but g->stackguard
is StackGuard bytes above the base. Previously, asking
for 32k meant getting 32k+StackGuard bytes, so using
g->stackguard as the base was safe. Now, the actual base
must be computed, so that the signal handler does not
run StackGuard bytes past the top of the stack.
Was causing flakiness mainly in programs that use the
network, because they sometimes write to closed network
connections, causing SIGPIPEs. Was also causing problems
in the doc/progs test.
Also fix Makefile so that changes to stack.h trigger rebuild.
R=bradfitzgo, r, r2
CC=golang-dev
https://golang.org/cl/4230044
2011-02-24 14:46:44 -07:00
|
|
|
#include "stack.h"
|
2009-11-17 09:20:58 -07:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
extern SigTab runtime·sigtab[];
|
|
|
|
extern int32 runtime·sys_umtx_op(uint32*, int32, uint32, void*, void*);
|
2010-04-08 19:15:30 -06:00
|
|
|
|
2012-01-09 23:39:17 -07:00
|
|
|
// From FreeBSD's <sys/sysctl.h>
|
|
|
|
#define CTL_HW 6
|
|
|
|
#define HW_NCPU 3
|
|
|
|
|
2013-02-15 10:18:33 -07:00
|
|
|
static Sigset sigset_none;
|
2012-02-21 21:44:09 -07:00
|
|
|
static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, };
|
|
|
|
|
2012-01-09 23:39:17 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-17 09:20:58 -07:00
|
|
|
// FreeBSD's umtx_op syscall is effectively the same as Linux's futex, and
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
// thus the code is largely similar. See linux/thread.c and lock_futex.c for comments.
|
2009-11-17 09:20:58 -07:00
|
|
|
|
2013-07-29 12:22:34 -06:00
|
|
|
#pragma textflag 7
|
2011-11-02 07:42:01 -06:00
|
|
|
void
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
runtime·futexsleep(uint32 *addr, uint32 val, int64 ns)
|
2009-11-17 09:20:58 -07:00
|
|
|
{
|
|
|
|
int32 ret;
|
2013-07-29 12:22:34 -06:00
|
|
|
Timespec ts;
|
2009-11-17 09:20:58 -07:00
|
|
|
|
2013-07-29 12:22:34 -06:00
|
|
|
if(ns < 0) {
|
|
|
|
ret = runtime·sys_umtx_op(addr, UMTX_OP_WAIT_UINT, val, nil, nil);
|
|
|
|
if(ret >= 0 || ret == -EINTR)
|
|
|
|
return;
|
|
|
|
goto fail;
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
}
|
2013-07-29 12:22:34 -06:00
|
|
|
ts.tv_nsec = 0;
|
|
|
|
ts.tv_sec = runtime·timediv(ns, 1000000000, (int32*)&ts.tv_nsec);
|
|
|
|
ret = runtime·sys_umtx_op(addr, UMTX_OP_WAIT_UINT, val, nil, &ts);
|
2009-11-17 09:20:58 -07:00
|
|
|
if(ret >= 0 || ret == -EINTR)
|
|
|
|
return;
|
|
|
|
|
2013-07-29 12:22:34 -06:00
|
|
|
fail:
|
2013-07-29 12:58:26 -06:00
|
|
|
runtime·prints("umtx_wait addr=");
|
|
|
|
runtime·printpointer(addr);
|
|
|
|
runtime·prints(" val=");
|
|
|
|
runtime·printint(val);
|
|
|
|
runtime·prints(" ret=");
|
|
|
|
runtime·printint(ret);
|
|
|
|
runtime·prints("\n");
|
2009-11-17 09:20:58 -07:00
|
|
|
*(int32*)0x1005 = 0x1005;
|
|
|
|
}
|
|
|
|
|
2011-11-02 07:42:01 -06:00
|
|
|
void
|
|
|
|
runtime·futexwakeup(uint32 *addr, uint32 cnt)
|
2009-11-17 09:20:58 -07:00
|
|
|
{
|
|
|
|
int32 ret;
|
|
|
|
|
2011-11-02 07:42:01 -06:00
|
|
|
ret = runtime·sys_umtx_op(addr, UMTX_OP_WAKE, cnt, nil, nil);
|
2009-11-17 09:20:58 -07:00
|
|
|
if(ret >= 0)
|
|
|
|
return;
|
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("umtx_wake addr=%p ret=%d\n", addr, ret);
|
2009-11-17 09:20:58 -07:00
|
|
|
*(int32*)0x1006 = 0x1006;
|
|
|
|
}
|
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
void runtime·thr_start(void*);
|
2009-11-17 09:20:58 -07:00
|
|
|
|
|
|
|
void
|
2013-03-01 09:44:43 -07:00
|
|
|
runtime·newosproc(M *mp, void *stk)
|
2009-11-17 09:20:58 -07:00
|
|
|
{
|
2009-11-18 00:58:51 -07:00
|
|
|
ThrParam param;
|
2012-02-21 21:44:09 -07:00
|
|
|
Sigset oset;
|
2009-11-17 09:20:58 -07:00
|
|
|
|
|
|
|
if(0){
|
2013-03-01 09:44:43 -07:00
|
|
|
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);
|
2009-11-17 09:20:58 -07:00
|
|
|
}
|
|
|
|
|
2012-02-21 21:44:09 -07:00
|
|
|
runtime·sigprocmask(&sigset_all, &oset);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·memclr((byte*)¶m, sizeof param);
|
2009-11-17 09:20:58 -07:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
param.start_func = runtime·thr_start;
|
2012-12-18 09:30:29 -07:00
|
|
|
param.arg = (byte*)mp;
|
2013-03-01 09:44:43 -07:00
|
|
|
|
|
|
|
// NOTE(rsc): This code is confused. stackbase is the top of the stack
|
|
|
|
// and is equal to stk. However, it's working, so I'm not changing it.
|
|
|
|
param.stack_base = (void*)mp->g0->stackbase;
|
|
|
|
param.stack_size = (byte*)stk - (byte*)mp->g0->stackbase;
|
|
|
|
|
2012-12-18 09:30:29 -07:00
|
|
|
param.child_tid = (intptr*)&mp->procid;
|
2009-11-17 09:20:58 -07:00
|
|
|
param.parent_tid = nil;
|
2012-12-18 09:30:29 -07:00
|
|
|
param.tls_base = (void*)&mp->tls[0];
|
|
|
|
param.tls_size = sizeof mp->tls;
|
2009-11-18 00:58:51 -07:00
|
|
|
|
2012-12-18 09:30:29 -07:00
|
|
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
2009-11-17 09:20:58 -07:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·thr_new(¶m, sizeof param);
|
2012-02-21 21:44:09 -07:00
|
|
|
runtime·sigprocmask(&oset, nil);
|
2009-11-17 09:20:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·osinit(void)
|
2009-11-17 09:20:58 -07:00
|
|
|
{
|
2012-01-09 23:39:17 -07:00
|
|
|
runtime·ncpu = getncpu();
|
2009-11-17 09:20:58 -07:00
|
|
|
}
|
|
|
|
|
2013-03-12 11:47:44 -06:00
|
|
|
void
|
|
|
|
runtime·get_random_data(byte **rnd, int32 *rnd_len)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-01-11 17:48:15 -07:00
|
|
|
void
|
|
|
|
runtime·goenvs(void)
|
|
|
|
{
|
|
|
|
runtime·goenvs_unix();
|
|
|
|
}
|
|
|
|
|
2009-11-17 09:20:58 -07:00
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
2013-02-21 05:24:38 -07:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
|
|
|
// Called on the new thread, can not allocate memory.
|
2009-11-17 09:20:58 -07:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·minit(void)
|
2009-11-17 09:20:58 -07:00
|
|
|
{
|
|
|
|
// Initialize signal handling
|
2012-05-30 11:07:52 -06:00
|
|
|
runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
|
2013-02-15 10:18:33 -07:00
|
|
|
runtime·sigprocmask(&sigset_none, nil);
|
2009-11-17 09:20:58 -07:00
|
|
|
}
|
2010-04-08 19:15:30 -06:00
|
|
|
|
2013-02-20 15:48:23 -07:00
|
|
|
// Called from dropm to undo the effect of an minit.
|
|
|
|
void
|
|
|
|
runtime·unminit(void)
|
|
|
|
{
|
|
|
|
runtime·signalstack(nil, 0);
|
|
|
|
}
|
|
|
|
|
2010-04-08 19:15:30 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·sigpanic(void)
|
2010-04-08 19:15:30 -06:00
|
|
|
{
|
|
|
|
switch(g->sig) {
|
|
|
|
case SIGBUS:
|
2012-01-10 12:46:57 -07:00
|
|
|
if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000) {
|
|
|
|
if(g->sigpc == 0)
|
|
|
|
runtime·panicstring("call of nil func value");
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("invalid memory address or nil pointer dereference");
|
2012-01-10 12:46:57 -07:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("unexpected fault address %p\n", g->sigcode1);
|
|
|
|
runtime·throw("fault");
|
2010-04-08 19:15:30 -06:00
|
|
|
case SIGSEGV:
|
2012-01-10 12:46:57 -07:00
|
|
|
if((g->sigcode0 == 0 || g->sigcode0 == SEGV_MAPERR || g->sigcode0 == SEGV_ACCERR) && g->sigcode1 < 0x1000) {
|
|
|
|
if(g->sigpc == 0)
|
|
|
|
runtime·panicstring("call of nil func value");
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("invalid memory address or nil pointer dereference");
|
2012-01-10 12:46:57 -07:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("unexpected fault address %p\n", g->sigcode1);
|
|
|
|
runtime·throw("fault");
|
2010-04-08 19:15:30 -06:00
|
|
|
case SIGFPE:
|
|
|
|
switch(g->sigcode0) {
|
|
|
|
case FPE_INTDIV:
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("integer divide by zero");
|
2010-04-08 19:15:30 -06:00
|
|
|
case FPE_INTOVF:
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("integer overflow");
|
2010-04-08 19:15:30 -06:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring("floating point error");
|
2010-04-08 19:15:30 -06:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·panicstring(runtime·sigtab[g->sig].name);
|
2010-04-08 19:15:30 -06:00
|
|
|
}
|
2012-02-24 13:28:51 -07:00
|
|
|
|
|
|
|
uintptr
|
|
|
|
runtime·memlimit(void)
|
|
|
|
{
|
|
|
|
Rlimit rl;
|
|
|
|
extern byte text[], 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 = end - 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;
|
|
|
|
}
|
2012-02-28 14:18:24 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
runtime·setprof(bool on)
|
|
|
|
{
|
|
|
|
USED(on);
|
|
|
|
}
|
2012-03-08 10:12:40 -07:00
|
|
|
|
2013-03-14 12:35:13 -06:00
|
|
|
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 */
|
|
|
|
} Sigaction;
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·setsig(int32 i, GoSighandler *fn, bool restart)
|
|
|
|
{
|
|
|
|
Sigaction 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)
|
|
|
|
{
|
|
|
|
Sigaction 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);
|
|
|
|
}
|