gcc/libgo/runtime
Ian Lance Taylor 9c48398f49 runtime: Fix GC bug caused by Entersyscall modifying reg.
This patch fixes a rare but serious bug.  The Go garbage
collector only examines Go stacks.  When Go code calls a
function that is not written in Go, it first calls
syscall.Entersyscall.  Entersyscall records the position of
the Go stack pointer and saves a copy of all the registers.
If the garbage collector runs while the thread is executing
the non-Go code, the garbage collector fetches the stack
pointer and registers from the saved location.

Entersyscall saves the registers using the getcontext
function.  Unfortunately I didn't consider the possibility
that Entersyscall might itself change a register before
calling getcontext.  This only matters for callee-saved
registers, as caller-saved registers would be visible on the
saved stack.  And it only matters if Entersyscall is compiled
to save and modify a callee-saved register before it calls
getcontext.  And it only matters if a garbage collection
occurs while the non-Go code is executing.  And it only
matters if the only copy of a valid Go pointer happens to be
in the callee-saved register when Entersyscall is called.
When all those conditions are true, the Go pointer might get
collected incorrectly, leading to memory corruption.

This patch tries to avoid the problem by splitting
Entersyscall into two functions.  The first is a simple
function that just calls getcontext and then calls the rest of
Entersyscall.  This should fix the problem, provided the
simple Entersyscall function does not itself modify any
callee-saved registers before calling getcontext.  That seems
to be true on the systems I checked.  But since the argument
to getcontext is an offset from a TLS variable, it won't be
true on a system which needs to save callee-saved registers in
order to get the address of a TLS variable.  I don't know why
any system would work that way, but I don't know how to rule
it out.  I think that on any such system this will have to be
implemented in assembler.  I can't put the ucontext_t
structure on the stack, because this function can not split
stacks, and the ucontext_t structure is large enough that it
could cause a stack overflow.

From-SVN: r208390
2014-03-07 05:04:37 +00:00
..
arch.h
array.h compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
chan.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
cpuprof.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
defs.h
env_posix.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
getncpu-bsd.c runtime: support NumCPU() on more platforms Added support for Solaris, Irix, *BSD (including Darwin). 2012-08-07 04:42:49 +00:00
getncpu-irix.c runtime: support NumCPU() on more platforms Added support for Solaris, Irix, *BSD (including Darwin). 2012-08-07 04:42:49 +00:00
getncpu-linux.c runtime: use sched_getaffinity for runtime.NumCPU() on Linux 2012-08-10 06:08:11 +00:00
getncpu-none.c runtime: support NumCPU() on more platforms Added support for Solaris, Irix, *BSD (including Darwin). 2012-08-07 04:42:49 +00:00
getncpu-solaris.c runtime: support NumCPU() on more platforms Added support for Solaris, Irix, *BSD (including Darwin). 2012-08-07 04:42:49 +00:00
go-alloc.h
go-append.c runtime: Fix append of slice with elements of zero size. 2013-10-02 23:49:39 +00:00
go-assert-interface.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-assert.c
go-assert.h
go-breakpoint.c re PR go/46986 (Go is not supported on Darwin) 2013-01-24 19:44:23 +00:00
go-byte-array-to-string.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-caller.c runtime: Update for change to libbacktrace library. 2013-11-19 15:02:27 +00:00
go-callers.c libgo: Avoid some cases of getting callers recursively. 2013-12-01 01:40:16 +00:00
go-can-convert-interface.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-cdiv.c compiler, runtime: Fix complex division of NaN / 0. 2013-10-09 22:31:15 +00:00
go-cgo.c runtime: Support cgo callbacks from threads started by C. 2013-07-23 20:26:09 +00:00
go-check-interface.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-construct-map.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-convert-interface.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-copy.c
go-defer.c runtime: Fix defer of unlock thread at program startup. 2013-12-12 20:13:58 +00:00
go-defer.h runtime: Fix defer of unlock thread at program startup. 2013-12-12 20:13:58 +00:00
go-deferred-recover.c
go-eface-compare.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-eface-val-compare.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-fieldtrack.c re PR go/46986 (Go is not supported on Darwin) 2013-01-24 19:44:23 +00:00
go-getgoroot.c re PR go/46986 (Go is not supported on Darwin) 2013-01-24 19:44:23 +00:00
go-int-array-to-string.c runtime: Fix handling of surrogate pairs in string([]rune). 2013-11-26 23:27:29 +00:00
go-int-to-string.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-interface-compare.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-interface-eface-compare.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-interface-val-compare.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-main.c libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
go-make-slice.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-map-delete.c runtime: Delete from a nil map is now a no-op. 2012-12-12 23:29:10 +00:00
go-map-index.c libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
go-map-len.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-map-range.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-matherr.c
go-memcmp.c compiler, runtime: Memcmp routine returns intgo. 2012-11-06 18:12:45 +00:00
go-nanotime.c
go-new-map.c compiler, libgo: Fixes to prepare for 64-bit int. 2012-11-06 18:28:21 +00:00
go-new.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-nosys.c runtime: Fix typo in dup3 fallback implementation. 2013-10-18 13:26:40 +00:00
go-now.c re PR go/46986 (Go is not supported on Darwin) 2013-01-24 19:44:23 +00:00
go-panic.c runtime: Fix defer of unlock thread at program startup. 2013-12-12 20:13:58 +00:00
go-panic.h compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-print.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-recover.c compiler, reflect, runtime: Implement method values in reflect. 2013-12-12 01:08:52 +00:00
go-reflect-call.c reflect: Handle calls to functions that take or return empty structs 2013-11-19 02:30:03 +00:00
go-reflect-map.c libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
go-rune.c compiler, libgo: Fixes to prepare for 64-bit int. 2012-11-06 18:28:21 +00:00
go-runtime-error.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-setenv.c libgo: Update Go library to master revision 15489/921e53d4863c. 2013-01-29 20:52:43 +00:00
go-signal.c runtime: Use pthread_sigmask instead of sigprocmask. 2013-12-04 01:35:53 +00:00
go-strcmp.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-string-to-byte-array.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-string-to-int-array.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-string.h compiler, libgo: Fixes to prepare for 64-bit int. 2012-11-06 18:28:21 +00:00
go-strplus.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
go-strslice.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-traceback.c runtime: In backtraces, get inline functions, skip split-stack fns. 2013-01-30 22:24:40 +00:00
go-trampoline.c libgo: Update to revision 15193:6fdc1974457c of master library. 2012-12-22 01:15:33 +00:00
go-type-complex.c runtime: Return random number of hash of NaN. 2012-09-22 06:06:31 +00:00
go-type-eface.c
go-type-error.c
go-type-float.c runtime: Return random number of hash of NaN. 2012-09-22 06:06:31 +00:00
go-type-identity.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-type-interface.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-type-string.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-type.h compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-typedesc-equal.c compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
go-typestring.c re PR go/46986 (Go is not supported on Darwin) 2013-01-24 19:44:23 +00:00
go-unsafe-new.c libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
go-unsafe-newarray.c libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
go-unsafe-pointer.c re PR go/46986 (Go is not supported on Darwin) 2013-01-24 19:44:23 +00:00
go-unwind.c runtime: Fix defer of unlock thread at program startup. 2013-12-12 20:13:58 +00:00
go-varargs.c syscall: Only call varargs libc functions from C code. 2013-11-24 02:38:28 +00:00
goc2c.c runtime: Change main in goc2c to return int. 2013-02-07 22:24:34 +00:00
iface.goc
interface.h compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
lfstack.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
lock_futex.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
lock_sema.c re PR go/59408 (Many Go tests FAIL with notesleep not on g0) 2013-12-06 18:26:27 +00:00
malloc.goc runtime: Use a better heap location on arm64 systems. 2014-02-21 03:24:03 +00:00
malloc.h runtime: Add netpoll code that uses select. 2013-11-14 20:15:04 +00:00
map.goc
map.h
mcache.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
mcentral.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
mem_posix_memalign.c
mem.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
mfinal.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
mfixalloc.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
mgc0.c libgo: Update to Go 1.2.1 release. 2014-03-03 20:14:52 +00:00
mgc0.h libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
mheap.c runtime: fix 32-bit malloc for pointers >= 0x80000000 2014-01-09 23:16:56 +00:00
mprof.goc libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
msize.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
netpoll_epoll.c runtime: Add netpoll code that uses select. 2013-11-14 20:15:04 +00:00
netpoll_kqueue.c runtime: Add netpoll code that uses select. 2013-11-14 20:15:04 +00:00
netpoll_select.c re PR go/59433 (Many 64-bit Go tests SEGV on Solaris) 2014-01-08 00:42:45 +00:00
netpoll_stub.c runtime: Add netpoll code that uses select. 2013-11-14 20:15:04 +00:00
netpoll.goc libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
panic.c runtime: Fix defer of unlock thread at program startup. 2013-12-12 20:13:58 +00:00
parfor.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
print.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
proc.c runtime: Fix GC bug caused by Entersyscall modifying reg. 2014-03-07 05:04:37 +00:00
race.h libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
reflect.goc compiler, runtime: More steps toward separating int and intgo. 2012-11-01 03:02:13 +00:00
rtems-task-variable-add.c
runtime1.goc libgo: Update to current sources. 2012-10-23 04:31:11 +00:00
runtime.c runtime: Remove unused runtime_cpuid variables. 2014-01-06 03:01:58 +00:00
runtime.h runtime: Fix prototype and one use of runtime_traceback. 2013-12-03 14:51:07 +00:00
sema.goc libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
signal_unix.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
signal_unix.h libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
sigqueue.goc libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
string.goc libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
thread-linux.c libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
thread-sema.c runtime: support NumCPU() on more platforms Added support for Solaris, Irix, *BSD (including Darwin). 2012-08-07 04:42:49 +00:00
thread.c libgo: Update to Go 1.1.1. 2013-07-16 06:54:42 +00:00
time.goc libgo: Update to October 24 version of master library. 2013-11-06 19:49:01 +00:00
yield.c