gcc/libgo/go/runtime
Ian Lance Taylor f1857c6369 runtime: complete defer handling in CgocallBackDone
When C code calls a Go function, it actually calls a function
    generated by cgo. That function is written in Go, and, among other
    things, it calls the real Go function like this:
            CgocallBack()
            defer CgocallBackDone()
            RealGoFunction()
    The deferred CgocallBackDone function enters syscall mode as we return
    to C. Typically the C function will then eventually return to Go.
    
    However, in the case where the C function is running on a thread
    created in C, it will not return to Go. For that case we will have
    allocated an m struct, with an associated g struct, for the duration
    of the Go code, and when the Go is complete we will return the m and g
    to a free list.
    
    That all works, but we are running in a deferred function, which means
    that we have been invoked by deferreturn, and deferreturn expects to
    do a bit of cleanup to record that the defer has been completed. Doing
    that cleanup while using an m and g that have already been returned to
    the free list is clearly a bad idea. It was kind of working because
    deferreturn was holding the g pointer in a local variable, but there
    were races with some other thread picking up and using the newly freed g.
    It was also kind of working because of a special check in freedefer;
    that check is no longer necessary.
    
    This patch changes the special case of releasing the m and g to do the
    defer cleanup in CgocallBackDone itself.
    
    This patch also checks for the special case of a panic through
    CgocallBackDone. In that special case, we don't want to release the m
    and g. Since we are returning to C code that was not called by Go
    code, we know that the panic is not going to be caught and we are
    going to exit the program. So for that special case we keep the m and
    g structs so that the rest of the panic code can use them.
    
    Reviewed-on: https://go-review.googlesource.com/46530

From-SVN: r249611
2017-06-23 20:19:40 +00:00
..
debug libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
internal libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
msan libgo: Update to go1.6rc1. 2016-02-03 21:58:02 +00:00
pprof Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
testdata runtime: don't assume that _ = *s will panic if s is nil 2017-06-22 14:46:12 +00:00
trace libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
alg.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
append_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
callers_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
cgo_gccgo.go runtime: complete defer handling in CgocallBackDone 2017-06-23 20:19:40 +00:00
cgocall.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
cgocheck.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
chan_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
chan.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
chanbarrier_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
closure_test.go
compiler.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
complex_test.go
cpuprof.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
cputicks.go runtime: copy runtime.go and runtime1.go from Go 1.7 2016-09-29 00:56:44 +00:00
crash_cgo_test.go runtime: adjust tests for gofrontend 2017-06-22 14:28:57 +00:00
crash_nonunix_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
crash_test.go runtime: adjust tests for gofrontend 2017-06-22 14:28:57 +00:00
crash_unix_test.go runtime: adjust tests for gofrontend 2017-06-22 14:28:57 +00:00
debug.go runtime: make NumGoroutine wait for system goroutines to register 2017-06-22 15:46:47 +00:00
env_posix.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
env_test.go runtime: Remove now unnecessary pad field from ParFor. 2015-10-31 00:59:47 +00:00
error.go runtime: rewrite panic/defer code from C to Go 2016-11-22 17:58:04 +00:00
export_arm_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
export_linux_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
export_mmap_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
export_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
export_windows_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
extern.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
fastlog2_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
fastlog2.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
fastlog2table.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
ffi.go runtime, reflect: rewrite Go to FFI type conversion in Go 2016-11-18 00:15:38 +00:00
gc_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
gcinfo_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
hash32.go libgo: remove old MIPS architecture names 2017-06-21 22:11:04 +00:00
hash64.go libgo: remove old MIPS architecture names 2017-06-21 22:11:04 +00:00
hash_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
hashmap_fast.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
hashmap.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
heapdump.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
iface_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
iface.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
lfstack_32bit.go libgo: remove old MIPS architecture names 2017-06-21 22:11:04 +00:00
lfstack_64bit.go libgo: remove old MIPS architecture names 2017-06-21 22:11:04 +00:00
lfstack_test.go runtime: Remove now unnecessary pad field from ParFor. 2015-10-31 00:59:47 +00:00
lfstack.go runtime: copy lfstack code from Go 1.7 runtime 2016-10-21 20:07:06 +00:00
lock_futex.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
lock_sema.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
malloc_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
malloc.go libgo: update to 1.8.3 release 2017-06-08 19:02:12 +00:00
map_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
mapspeed_test.go runtime: Remove now unnecessary pad field from ParFor. 2015-10-31 00:59:47 +00:00
mbarrier.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mbitmap.go libgo: update to 1.8.3 release 2017-06-08 19:02:12 +00:00
mcache.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mcentral.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mem_gccgo.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
memmove_linux_amd64_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
memmove_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mfinal_test.go runtime: Remove now unnecessary pad field from ParFor. 2015-10-31 00:59:47 +00:00
mfinal.go runtime: make NumGoroutine wait for system goroutines to register 2017-06-22 15:46:47 +00:00
mfixalloc.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mgc_gccgo.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mgc.go runtime: uncomment check for gchelper on g0 stack 2017-06-22 22:12:50 +00:00
mgcmark.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mgcsweep.go runtime: fix isSystemGoroutine for gccgo 2017-05-11 20:55:41 +00:00
mgcsweepbuf.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mgcwork.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mheap.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mkfastlog2table.go libgo: Update to go1.6rc1. 2016-02-03 21:58:02 +00:00
mksizeclasses.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
mprof.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
msan0.go compiler, runtime: replace hashmap code with Go 1.7 hashmap 2016-09-21 20:58:51 +00:00
msize.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mstats.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
mstkbar.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
net_plan9.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
netpoll_aix.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
netpoll_epoll.go runtime, syscall: force EPOLLET to be positive 2016-10-19 16:53:13 +00:00
netpoll_kqueue.go runtime: copy netpoll code from Go 1.7 runtime 2016-10-18 14:38:29 +00:00
netpoll_nacl.go runtime: copy netpoll code from Go 1.7 runtime 2016-10-18 14:38:29 +00:00
netpoll_solaris.go runtime: copy netpoll code from Go 1.7 runtime 2016-10-18 14:38:29 +00:00
netpoll_stub.go runtime: copy netpoll code from Go 1.7 runtime 2016-10-18 14:38:29 +00:00
netpoll_windows.go runtime: copy netpoll code from Go 1.7 runtime 2016-10-18 14:38:29 +00:00
netpoll.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
norace_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
os_aix.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
os_darwin.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
os_dragonfly.go runtime: copy internal locking code from Go 1.7 runtime 2016-09-30 13:45:08 +00:00
os_freebsd.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
os_gccgo.go runtime: mark dropm and callees nowritebarrierrec 2017-06-22 22:11:01 +00:00
os_linux_ppc64x.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
os_linux.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
os_netbsd.go runtime: copy internal locking code from Go 1.7 runtime 2016-09-30 13:45:08 +00:00
os_openbsd.go runtime: copy internal locking code from Go 1.7 runtime 2016-09-30 13:45:08 +00:00
os_solaris.go runtime: copy internal locking code from Go 1.7 runtime 2016-09-30 13:45:08 +00:00
panic.go runtime: complete defer handling in CgocallBackDone 2017-06-23 20:19:40 +00:00
print.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
proc_runtime_test.go libgo: update to go1.7rc3 2016-07-22 18:15:38 +00:00
proc_test.go runtime: copy more of scheduler from Go 1.7 runtime 2017-01-09 19:37:19 +00:00
proc.go runtime: don't crash if no p in kickoff 2017-06-23 16:05:44 +00:00
race0.go compiler, runtime: replace hashmap code with Go 1.7 hashmap 2016-09-21 20:58:51 +00:00
rdebug.go runtime: copy rdebug code from Go 1.7 runtime 2016-10-17 16:54:25 +00:00
runtime1.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
runtime2.go runtime: improve handling of panic during deferred function 2017-06-23 13:45:36 +00:00
runtime_mmap_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
runtime_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
runtime_unix_test.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
runtime-lldb_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
runtime.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
select.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
sema.go libgo: update to Go 1.8.1 release 2017-04-17 22:10:58 +00:00
signal_gccgo.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
signal_sighandler.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
signal_unix.go runtime: mark dropm and callees nowritebarrierrec 2017-06-22 22:11:01 +00:00
sigqueue.go runtime: copy signal code from Go 1.7 runtime 2016-11-10 22:53:23 +00:00
sizeclasses.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
slice.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
stack.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
string_test.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
string.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
stubs2.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
stubs.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
symtab_test.go runtime: Remove now unnecessary pad field from ParFor. 2015-10-31 00:59:47 +00:00
symtab.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
time.go runtime: make NumGoroutine wait for system goroutines to register 2017-06-22 15:46:47 +00:00
trace.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
traceback_gccgo.go runtime: in traceback, print panic rather than runtime.gopanic 2017-06-22 04:16:23 +00:00
type.go Big merge of changes to gofrontend repo that were postponed due to the 2017-05-10 17:26:09 +00:00
typekind.go compiler, runtime: replace hashmap code with Go 1.7 hashmap 2016-09-21 20:58:51 +00:00
unaligned1.go runtime: copy memory hash code from Go 1.7 2016-12-08 16:37:54 +00:00
unaligned2.go libgo: remove old MIPS architecture names 2017-06-21 22:11:04 +00:00
utf8.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
vdso_none.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
write_err_android.go libgo: update to Go 1.8 release candidate 1 2017-01-14 00:05:42 +00:00
write_err.go Accidentally failed to commit these earlier, as part of: 2016-10-11 00:08:35 +00:00