2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2011-05-02 11:55:51 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
runtime: scheduler, cgo reorganization
* Change use of m->g0 stack (aka scheduler stack).
* Provide runtime.mcall(f) to invoke f() on m->g0 stack.
* Replace scheduler loop entry with runtime.mcall(schedule).
Runtime.mcall eliminates the need for fake scheduler states that
exist just to run a bit of code on the m->g0 stack
(Grecovery, Gstackalloc).
The elimination of the scheduler as a loop that stops and
starts using gosave and gogo fixes a bad interaction with the
way cgo uses the m->g0 stack. Cgo runs external (gcc-compiled)
C functions on that stack, and then when calling back into Go,
it sets m->g0->sched.sp below the added call frames, so that
other uses of m->g0's stack will not interfere with those frames.
Unfortunately, gogo (longjmp) back to the scheduler loop at
this point would end up running scheduler with the lower
sp, which no longer points at a valid stack frame for
a call to scheduler. If scheduler then wrote any function call
arguments or local variables to where it expected the stack
frame to be, it would overwrite other data on the stack.
I realized this possibility while debugging a problem with
calling complex Go code in a Go -> C -> Go cgo callback.
This wasn't the bug I was looking for, it turns out, but I believe
it is a real bug nonetheless. Switching to runtime.mcall, which
only adds new frames to the stack and never jumps into
functions running in existing ones, fixes this bug.
* Move cgo-related code out of proc.c into cgocall.c.
* Add very large comment describing cgo call sequences.
* Simpilify, regularize cgo function implementations and names.
* Add test suite as misc/cgo/test.
Now the Go -> C path calls cgocall, which calls asmcgocall,
and the C -> Go path calls cgocallback, which calls cgocallbackg.
The shuffling, which affects mainly the callback case, moves
most of the callback implementation to cgocallback running
on the m->curg stack (not the m->g0 scheduler stack) and
only while accounted for with $GOMAXPROCS (between calls
to exitsyscall and entersyscall).
The previous callback code did not block in startcgocallback's
approximation to exitsyscall, so if, say, the garbage collector
were running, it would still barge in and start doing things
like call malloc. Similarly endcgocallback's approximation of
entersyscall did not call matchmg to kick off new OS threads
when necessary, which caused the bug in issue 1560.
Fixes #1560.
R=iant
CC=golang-dev
https://golang.org/cl/4253054
2011-03-07 08:37:42 -07:00
|
|
|
package cgotest
|
|
|
|
|
2011-05-02 11:55:51 -06:00
|
|
|
import "testing"
|
|
|
|
|
2012-10-30 14:38:01 -06:00
|
|
|
// The actual test functions are in non-_test.go files
|
2011-05-02 11:55:51 -06:00
|
|
|
// so that they can use cgo (import "C").
|
|
|
|
// These wrappers are here for gotest to find.
|
|
|
|
|
2014-09-25 08:59:01 -06:00
|
|
|
func TestAlign(t *testing.T) { testAlign(t) }
|
|
|
|
func TestConst(t *testing.T) { testConst(t) }
|
|
|
|
func TestEnum(t *testing.T) { testEnum(t) }
|
|
|
|
func TestAtol(t *testing.T) { testAtol(t) }
|
|
|
|
func TestErrno(t *testing.T) { testErrno(t) }
|
|
|
|
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
|
|
|
|
func TestUnsignedInt(t *testing.T) { testUnsignedInt(t) }
|
|
|
|
func TestCallback(t *testing.T) { testCallback(t) }
|
|
|
|
func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
|
|
|
|
func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
|
|
|
|
func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
|
|
|
|
func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
|
|
|
|
func TestPanicFromC(t *testing.T) { testPanicFromC(t) }
|
|
|
|
func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
|
|
|
|
func TestBlocking(t *testing.T) { testBlocking(t) }
|
|
|
|
func Test1328(t *testing.T) { test1328(t) }
|
|
|
|
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
|
|
|
|
func TestSetEnv(t *testing.T) { testSetEnv(t) }
|
|
|
|
func TestHelpers(t *testing.T) { testHelpers(t) }
|
|
|
|
func TestLibgcc(t *testing.T) { testLibgcc(t) }
|
|
|
|
func Test1635(t *testing.T) { test1635(t) }
|
|
|
|
func TestPrintf(t *testing.T) { testPrintf(t) }
|
|
|
|
func Test4029(t *testing.T) { test4029(t) }
|
|
|
|
func TestBoolAlign(t *testing.T) { testBoolAlign(t) }
|
|
|
|
func Test3729(t *testing.T) { test3729(t) }
|
|
|
|
func Test3775(t *testing.T) { test3775(t) }
|
|
|
|
func TestCthread(t *testing.T) { testCthread(t) }
|
|
|
|
func TestCallbackCallers(t *testing.T) { testCallbackCallers(t) }
|
|
|
|
func Test5227(t *testing.T) { test5227(t) }
|
|
|
|
func TestCflags(t *testing.T) { testCflags(t) }
|
|
|
|
func Test5337(t *testing.T) { test5337(t) }
|
|
|
|
func Test5548(t *testing.T) { test5548(t) }
|
|
|
|
func Test5603(t *testing.T) { test5603(t) }
|
|
|
|
func Test6833(t *testing.T) { test6833(t) }
|
|
|
|
func Test3250(t *testing.T) { test3250(t) }
|
|
|
|
func TestCallbackStack(t *testing.T) { testCallbackStack(t) }
|
|
|
|
func TestFpVar(t *testing.T) { testFpVar(t) }
|
|
|
|
func Test4339(t *testing.T) { test4339(t) }
|
|
|
|
func Test6390(t *testing.T) { test6390(t) }
|
|
|
|
func Test5986(t *testing.T) { test5986(t) }
|
|
|
|
func Test7665(t *testing.T) { test7665(t) }
|
|
|
|
func TestNaming(t *testing.T) { testNaming(t) }
|
|
|
|
func Test7560(t *testing.T) { test7560(t) }
|
|
|
|
func Test5242(t *testing.T) { test5242(t) }
|
|
|
|
func Test8092(t *testing.T) { test8092(t) }
|
|
|
|
func Test7978(t *testing.T) { test7978(t) }
|
|
|
|
func Test8694(t *testing.T) { test8694(t) }
|
2014-10-08 23:10:51 -06:00
|
|
|
func Test8517(t *testing.T) { test8517(t) }
|
cmd/ld: do not assume that only pe section names start with '.'
Our current pe object reader assumes that every symbol starting with
'.' is section. It appeared to be true, until now gcc 4.9.1 generates
some symbols with '.' at the front. Change that logic to check other
symbol fields in addition to checking for '.'. I am not an expert
here, but it seems reasonable to me.
Added test, but it is only good, if tested with gcc 4.9.1. Otherwise
the test PASSes regardless.
Fixes #8811.
Fixes #8856.
LGTM=jfrederich, iant, stephen.gutekanst
R=golang-codereviews, jfrederich, stephen.gutekanst, iant
CC=alex.brainman, golang-codereviews
https://golang.org/cl/152410043
2014-10-11 05:01:04 -06:00
|
|
|
func Test8811(t *testing.T) { test8811(t) }
|
2014-09-25 08:59:01 -06:00
|
|
|
func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) }
|
|
|
|
func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) }
|
2014-10-30 12:01:14 -06:00
|
|
|
func Test9026(t *testing.T) { test9026(t) }
|
2015-11-04 12:14:19 -07:00
|
|
|
func Test9510(t *testing.T) { test9510(t) }
|
2015-01-11 22:12:59 -07:00
|
|
|
func Test9557(t *testing.T) { test9557(t) }
|
2015-06-07 20:14:04 -06:00
|
|
|
func Test10303(t *testing.T) { test10303(t, 10) }
|
2015-07-29 23:04:09 -06:00
|
|
|
func Test11925(t *testing.T) { test11925(t) }
|
2015-09-10 00:32:12 -06:00
|
|
|
func Test12030(t *testing.T) { test12030(t) }
|
2015-11-10 12:25:15 -07:00
|
|
|
func TestGCC68255(t *testing.T) { testGCC68255(t) }
|
2015-11-19 18:03:01 -07:00
|
|
|
func TestCallGoWithString(t *testing.T) { testCallGoWithString(t) }
|
2016-03-16 11:53:53 -06:00
|
|
|
func Test14838(t *testing.T) { test14838(t) }
|
2016-08-09 19:06:46 -06:00
|
|
|
func Test8756(t *testing.T) { test8756(t) }
|
2016-09-11 13:34:58 -06:00
|
|
|
func Test17065(t *testing.T) { test17065(t) }
|
2016-01-23 23:22:54 -07:00
|
|
|
func TestThreadLock(t *testing.T) { testThreadLockFunc(t) }
|
2016-10-21 08:54:46 -06:00
|
|
|
func TestCheckConst(t *testing.T) { testCheckConst(t) }
|
2016-11-10 15:34:32 -07:00
|
|
|
func Test17537(t *testing.T) { test17537(t) }
|
2016-11-30 16:46:37 -07:00
|
|
|
func Test18126(t *testing.T) { test18126(t) }
|
2017-05-16 06:52:41 -06:00
|
|
|
func Test20369(t *testing.T) { test20369(t) }
|
2017-04-21 04:18:36 -06:00
|
|
|
func Test18720(t *testing.T) { test18720(t) }
|
2017-05-25 23:20:27 -06:00
|
|
|
func Test20266(t *testing.T) { test20266(t) }
|
2017-06-03 21:11:19 -06:00
|
|
|
func Test20129(t *testing.T) { test20129(t) }
|
2017-07-17 10:14:23 -06:00
|
|
|
func Test20910(t *testing.T) { test20910(t) }
|
2017-08-30 22:49:43 -06:00
|
|
|
func Test21708(t *testing.T) { test21708(t) }
|
2017-09-09 22:38:51 -06:00
|
|
|
func Test21809(t *testing.T) { test21809(t) }
|
2017-10-13 19:26:10 -06:00
|
|
|
func Test6907(t *testing.T) { test6907(t) }
|
|
|
|
func Test6907Go(t *testing.T) { test6907Go(t) }
|
2017-09-26 16:14:50 -06:00
|
|
|
func Test21897(t *testing.T) { test21897(t) }
|
2017-12-04 22:29:38 -07:00
|
|
|
func Test22906(t *testing.T) { test22906(t) }
|
2018-03-01 15:52:27 -07:00
|
|
|
func Test24206(t *testing.T) { test24206(t) }
|
2011-08-18 10:17:09 -06:00
|
|
|
|
2018-03-01 15:52:27 -07:00
|
|
|
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
|
|
|
func BenchmarkGoString(b *testing.B) { benchGoString(b) }
|