summaryrefslogtreecommitdiff
path: root/src/runtime
Commit message (Collapse)AuthorAgeFilesLines
* [dev.cc] all: merge default (8d42099cdc23) into dev.ccdev.ccRuss Cox2014-12-052-7/+24
|\ | | | | | | | | | | TBR=austin CC=golang-codereviews https://codereview.appspot.com/178700044
| * runtime: fix hang in GC due to shrinkstack vs netpoll raceRuss Cox2014-12-013-6/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During garbage collection, after scanning a stack, we think about shrinking it to reclaim some memory. The shrinking code (called while the world is stopped) checked that the status was Gwaiting or Grunnable and then changed the state to Gcopystack, to essentially lock the stack so that no other GC thread is scanning it. The same locking happens for stack growth (and is more necessary there). oldstatus = runtime?readgstatus(gp); oldstatus &= ~Gscan; if(oldstatus == Gwaiting || oldstatus == Grunnable) runtime?casgstatus(gp, oldstatus, Gcopystack); // oldstatus is Gwaiting or Grunnable else runtime?throw("copystack: bad status, not Gwaiting or Grunnable"); Unfortunately, "stop the world" doesn't stop everything. It stops all normal goroutine execution, but the network polling thread is still blocked in epoll and may wake up. If it does, and it chooses a goroutine to mark runnable, and that goroutine is the one whose stack is shrinking, then it can happen that between readgstatus and casgstatus, the status changes from Gwaiting to Grunnable. casgstatus assumes that if the status is not what is expected, it is a transient change (like from Gwaiting to Gscanwaiting and back, or like from Gwaiting to Gcopystack and back), and it loops until the status has been restored to the expected value. In this case, the status has changed semi-permanently from Gwaiting to Grunnable - it won't change again until the GC is done and the world can continue, but the GC is waiting for the status to change back. This wedges the program. To fix, call a special variant of casgstatus that accepts either Gwaiting or Grunnable as valid statuses. Without the fix bug with the extra check+throw in casgstatus, the program below dies in a few seconds (2-10) with GOMAXPROCS=8 on a 2012 Retina MacBook Pro. With the fix, it runs for minutes and minutes. package main import ( "io" "log" "net" "runtime" ) func main() { const N = 100 for i := 0; i < N; i++ { l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { log.Fatal(err) } ch := make(chan net.Conn, 1) go func() { var err error c1, err := net.Dial("tcp", l.Addr().String()) if err != nil { log.Fatal(err) } ch <- c1 }() c2, err := l.Accept() if err != nil { log.Fatal(err) } c1 := <-ch l.Close() go netguy(c1, c2) go netguy(c2, c1) c1.Write(make([]byte, 100)) } for { runtime.GC() } } func netguy(r, w net.Conn) { buf := make([]byte, 100) for { bigstack(1000) _, err := io.ReadFull(r, buf) if err != nil { log.Fatal(err) } w.Write(buf) } } var g int func bigstack(n int) { var buf [100]byte if n > 0 { bigstack(n - 1) } g = int(buf[0]) + int(buf[99]) } Fixes issue 9186. LGTM=rlh R=austin, rlh CC=dvyukov, golang-codereviews, iant, khr, r https://codereview.appspot.com/179680043
* | [dev.cc] runtime: convert dragonfly/386 port to GoJoel Sing2014-11-253-59/+78
| | | | | | | | | | | | | | LGTM=rsc R=rsc, bradfitz CC=golang-codereviews https://codereview.appspot.com/178210043
* | [dev.cc] runtime: convert netbsd/386 port to GoJoel Sing2014-11-225-45/+71
| | | | | | | | | | | | | | LGTM=minux R=rsc, minux CC=golang-codereviews https://codereview.appspot.com/177170043
* | [dev.cc] runtime: convert netbsd/amd64 port to GoJoel Sing2014-11-2212-511/+436
| | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/169620043
* | [dev.cc] runtime: migrate Android/ARM port to Go.Shenghou Ma2014-11-215-10/+5
| | | | | | | | | | | | | | | | | | I tested building Go itself, but not any of go.mobile tests. LGTM=crawshaw R=crawshaw, rsc CC=golang-codereviews https://codereview.appspot.com/179110043
* | [dev.cc] runtime: explicitly exclude android in zgoos_linux.goShenghou Ma2014-11-2112-22/+4
| | | | | | | | | | | | | | | | | | | | Otherwise both zgoos_linux.go and zgoos_android.go will be compiled for GOOS=android. LGTM=crawshaw, rsc R=rsc, crawshaw CC=golang-codereviews https://codereview.appspot.com/178110043
* | [dev.cc] runtime: convert Plan 9 port to GoDavid du Colombier2014-11-2118-923/+756
| | | | | | | | | | | | | | | | | | | | Thanks to Aram H?v?rneanu, Nick Owens and Russ Cox for the early reviews. LGTM=aram, rsc R=rsc, lucio.dere, aram, ality CC=golang-codereviews, mischief https://codereview.appspot.com/175370043
* | [dev.cc] runtime: convert nacl support to GoRuss Cox2014-11-2120-767/+562
| | | | | | | | | | | | | | LGTM=dave R=minux, dave CC=golang-codereviews https://codereview.appspot.com/181030043
* | [dev.cc] runtime: windows does not use _cgo_setenv and _cgo_unsetenvAlex Brainman2014-11-211-5/+7
| | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/175480043
* | [dev.cc] runtime: fix windows goenvs conversion mistakeAlex Brainman2014-11-211-2/+2
| | | | | | | | | | | | | | | | | | uint16 occupies 2 bytes, not 1 LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/178100043
* | [dev.cc] all: merge default (e4ab8f908aac) into dev.ccRuss Cox2014-11-20358-26658/+25075
|\ \ | |/ |/| | | | | | | TBR=austin CC=golang-codereviews https://codereview.appspot.com/179040044
| * [dev.cc] runtime: convert remaining windows C code to GoAlex Brainman2014-11-2012-984/+853
| | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/177090043
| * [dev.cc] runtime: add explicit siginfo.si_addr fieldAustin Clements2014-11-199-27/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | struct siginfo_t's si_addr field is part of a union. Previously, we represented this union in Go using an opaque byte array and accessed the si_addr field using unsafe (and wrong on 386 and arm!) pointer arithmetic. Since si_addr is the only field we use from this union, this replaces the opaque byte array with an explicit declaration of the si_addr field and accesses it directly. LGTM=minux, rsc R=rsc, minux CC=golang-codereviews https://codereview.appspot.com/179970044
| * [dev.cc] runtime: decode power64 branch instructions the way the CPU doesAustin Clements2014-11-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, this used the top 8 bits of an instruction as a sort-of opcode and ignored the top two bits of the relative PC. This worked because these jumps are always negative and never big enough for the top two bits of the relative PC (also the bottom 2 bits of the sort-of opcode) to be anything other than 0b11, but the code is confusing because it doesn't match the actual structure of the instruction. Instead, use the real 6 bit opcode and use all 24 bits of relative PC. LGTM=rsc R=rsc, dave CC=golang-codereviews https://codereview.appspot.com/179960043
| * [dev.cc] runtime: allow more address bits in lfstack on Power64Austin Clements2014-11-192-7/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, lfstack assumed Linux limited user space addresses to 43 bits on Power64 based on a paper from 2001. It turns out the limit is now 46 bits, so lfstack was truncating pointers. Raise the limit to 48 bits (for some future proofing and to make it match amd64) and add a self-test that will fail in a useful way if ever unpack(pack(x)) != x. With this change, dev.cc passes all.bash on power64le. LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/174430043
| * [dev.cc] runtime: update sys_windows_386.s and sys_windows_amd64.s for Go ↵Alex Brainman2014-11-192-15/+15
| | | | | | | | | | | | | | | | | | conversion LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/176970043
| * [dev.cc] runtime: merge power64 onM/onM_signalok into systemstackAustin Clements2014-11-181-33/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | This is the power64 component of CL 174950043. With this, dev.cc compiles on power64 and power64le and passes most tests if GOGC=off (but crashes in go_bootstrap if GC is on). LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/175290043
| * [dev.cc] runtime: catch defs_linux_power64*.go up to other archsAustin Clements2014-11-182-4/+28
| | | | | | | | | | | | | | | | | | | | | | Fix a constant conversion error. Add set_{sec,nsec} for timespec and set_usec for timeval. Fix type of sigaltstackt.ss_size. LGTM=rsc R=rsc, bradfitz CC=golang-codereviews https://codereview.appspot.com/180840043
| * [dev.cc] runtime: convert power64-specific .c and .h files to GoAustin Clements2014-11-187-66/+136
| | | | | | | | | | | | | | | | | | The power64 equivalent of CL 174860043 LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/179890043
| * [dev.cc] runtime: convert power64 assembly files for C to Go transitionAustin Clements2014-11-182-5/+11
| | | | | | | | | | | | | | | | | | The power64 equivalent of CL 168510043 LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/178940043
| * [dev.cc] runtime: convert power64 signal handlers from C to GoAustin Clements2014-11-185-235/+215
| | | | | | | | | | | | | | | | | | The power64 equivalent of CL 168500044 LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/175280043
| * [dev.cc] runtime: generate GOOS- and GOARCH-specific files with go generateRuss Cox2014-11-1825-15/+376
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Eventually I'd like almost everything cmd/dist generates to be done with 'go generate' and checked in, to simplify the bootstrap process. The only thing cmd/dist really needs to do is write things like the current experiment info and the current version. This is a first step toward that. It replaces the _NaCl etc constants with generated ones goos_nacl, goos_darwin, goarch_386, and so on. LGTM=dave, austin R=austin, dave, bradfitz CC=golang-codereviews, iant, r https://codereview.appspot.com/174290043
| * [dev.cc] runtime: convert defs_linux_power64*.h to goRuss Cox2014-11-184-408/+372
| | | | | | | | | | | | | | LGTM=austin R=austin CC=golang-codereviews https://codereview.appspot.com/176990043
| * [dev.cc] runtime: two missed references to "M stack"Austin Clements2014-11-182-2/+2
| | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/177940043
| * [dev.cc] runtime: replace deleted netpollfd functionAlex Brainman2014-11-171-1/+1
| | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/169710043
| * [dev.cc] runtime: fix _sfloat thunkDave Cheney2014-11-151-2/+3
| | | | | | | | | | | | | | | | | | | | * _sfloat dispatches to runtime._sfloat2 with the Go calling convention, so the seecond argument is a [15]uint32, not a *[15]uint32. * adjust _sfloat2 to return the new pc in 68(R13) as expected. LGTM=rsc R=minux, austin, rsc CC=golang-codereviews https://codereview.appspot.com/174160043
| * [dev.cc] runtime: fix bus error accessing auxv random data on arm5Dave Cheney2014-11-151-2/+5
| | | | | | | | | | | | | | | | | | | | | | It's rather unsporting of the kernel to give us a pointer to unaligned memory. This fixes one crash, the next crash occurs in the soft float emulation. LGTM=minux, rsc, austin R=minux, rsc, austin CC=golang-codereviews https://codereview.appspot.com/177730043
| * [dev.cc] runtime: change set_sec to take int64Russ Cox2014-11-1412-22/+22
| | | | | | | | | | | | | | | | | | Fixes build. Tested that all these systems can make.bash. TBR=austin CC=golang-codereviews https://codereview.appspot.com/177770043
| * [dev.cc] runtime: fix lfstack for amd64 addresses in top half of addr spaceRuss Cox2014-11-144-25/+60
| | | | | | | | | | | | | | | | | | While we are here, add the linux/power64 version. LGTM=austin R=austin CC=aram, dvyukov, golang-codereviews https://codereview.appspot.com/177750043
| * [dev.cc] runtime: fix linux buildRuss Cox2014-11-144-2/+14
| | | | | | | | | | | | TBR=austin CC=golang-codereviews https://codereview.appspot.com/176760044
| * [dev.cc] runtime: convert dragonfly/amd64 port to GoJoel Sing2014-11-1510-470/+393
| | | | | | | | | | | | | | LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://codereview.appspot.com/176750043
| * [dev.cc] all: merge dev.power64 (7667e41f3ced) into dev.ccRuss Cox2014-11-14300-25050/+20980
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to reduce the delta between dev.cc and dev.garbage to just garbage collector changes. These are the files that had merge conflicts and have been edited by hand: malloc.go mem_linux.go mgc.go os1_linux.go proc1.go panic1.go runtime1.go LGTM=austin R=austin CC=golang-codereviews https://codereview.appspot.com/174180043
| | * [dev.cc] runtime: convert openbsd/386 port to GoJoel Sing2014-11-155-52/+82
| | | | | | | | | | | | | | | | | | | | | LGTM=rsc R=golang-codereviews, bradfitz, rsc CC=golang-codereviews https://codereview.appspot.com/173200044
| | * [dev.cc] runtime: fix nil pointer crash handler bug on SolarisAram H?v?rneanu2014-11-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | This change fixes the Solaris port. LGTM=dave, rsc R=rsc, dave CC=brad, golang-codereviews https://codereview.appspot.com/168600045
| | * [dev.cc] runtime: convert netpoll_windows.c to GoAlex Brainman2014-11-143-167/+156
| | | | | | | | | | | | | | | | | | | | | LGTM=rsc R=rsc CC=dvyukov, golang-codereviews https://codereview.appspot.com/172530043
| | * [dev.cc] runtime: convert openbsd/amd64 port to GoJoel Sing2014-11-1410-457/+409
| | | | | | | | | | | | | | | | | | | | | LGTM=rsc R=rsc, bradfitz CC=golang-codereviews https://codereview.appspot.com/171660043
| | * [dev.cc] runtime: make SIGSYS notifiable on freebsd (again)Joel Sing2014-11-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was originally done to the C port in rev 17d3b45534b5 and seemingly got lost during the conversion. LGTM=bradfitz R=rsc, bradfitz CC=golang-codereviews https://codereview.appspot.com/167700043
| | * [dev.cc] runtime: convert Solaris port to GoAram H?v?rneanu2014-11-1321-1228/+912
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Memory management was consolitated with the BSD ports, since it was almost identical. Assembly thunks are gone, being replaced by the new //go:linkname feature. This change supersedes CL 138390043 (runtime: convert solaris netpoll to Go), which was previously reviewed and tested. This change is only the first step, the port now builds, but doesn't run. Binaries fail to exec: ld.so.1: 6.out: fatal: 6.out: TLS requirement failure : TLS support is unavailable Killed This seems to happen because binaries don't link with libc.so anymore. We will have to solve that in a different CL. Also this change is just a rough translation of the original C code, cleanup will come in a different CL. [This CL is part of the removal of C code from package runtime. See golang.org/s/dev.cc for an overview.] LGTM=rsc R=rsc, dave CC=golang-codereviews, iant, khr, minux, r, rlh https://codereview.appspot.com/174960043
| | * [dev.cc] runtime: convert mem_windows.c to GoAlex Brainman2014-11-132-132/+119
| | | | | | | | | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/175000043
| | * [dev.cc] runtime: add missing cb_max constAlex Brainman2014-11-131-0/+8
| | | | | | | | | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/169490043
| | * [dev.cc] [dev.cc] runtime: fix freebsd cgo __progname exportJoel Sing2014-11-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/174050043 Committer: Russ Cox <rsc@golang.org>
| | * [dev.cc] runtime: delete scalararg, ptrarg; rename onM to systemstackRuss Cox2014-11-1236-422/+259
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Scalararg and ptrarg are not "signal safe". Go code filling them out can be interrupted by a signal, and then the signal handler runs, and if it also ends up in Go code that uses scalararg or ptrarg, now the old values have been smashed. For the pieces of code that do need to run in a signal handler, we introduced onM_signalok, which is really just onM except that the _signalok is meant to convey that the caller asserts that scalarg and ptrarg will be restored to their old values after the call (instead of the usual behavior, zeroing them). Scalararg and ptrarg are also untyped and therefore error-prone. Go code can always pass a closure instead of using scalararg and ptrarg; they were only really necessary for C code. And there's no more C code. For all these reasons, delete scalararg and ptrarg, converting the few remaining references to use closures. Once those are gone, there is no need for a distinction between onM and onM_signalok, so replace both with a single function equivalent to the current onM_signalok (that is, it can be called on any of the curg, g0, and gsignal stacks). The name onM and the phrase 'm stack' are misnomers, because on most system an M has two system stacks: the main thread stack and the signal handling stack. Correct the misnomer by naming the replacement function systemstack. Fix a few references to "M stack" in code. The main motivation for this change is to eliminate scalararg/ptrarg. Rick and I have already seen them cause problems because the calling sequence m.ptrarg[0] = p is a heap pointer assignment, so it gets a write barrier. The write barrier also uses onM, so it has all the same problems as if it were being invoked by a signal handler. We worked around this by saving and restoring the old values and by calling onM_signalok, but there's no point in keeping this nice home for bugs around any longer. This CL also changes funcline to return the file name as a result instead of filling in a passed-in *string. (The *string signature is left over from when the code was written in and called from C.) That's arguably an unrelated change, except that once I had done the ptrarg/scalararg/onM cleanup I started getting false positives about the *string argument escaping (not allowed in package runtime). The compiler is wrong, but the easiest fix is to write the code like Go code instead of like C code. I am a bit worried that the compiler is wrong because of some use of uninitialized memory in the escape analysis. If that's the reason, it will go away when we convert the compiler to Go. (And if not, we'll debug it the next time.) LGTM=khr R=r, khr CC=austin, golang-codereviews, iant, rlh https://codereview.appspot.com/174950043
| | * [dev.cc] runtime/cgo: add comment about import _ "unsafe"Russ Cox2014-11-126-6/+6
| | | | | | | | | | | | | | | | | | | | | LGTM=bradfitz, r R=r, bradfitz CC=golang-codereviews https://codereview.appspot.com/167650043
| | * [dev.cc] runtime/cgo: fix freebsd build?Russ Cox2014-11-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | Last try and then someone with a FreeBSD has to do it. TBR=r CC=golang-codereviews https://codereview.appspot.com/171590043
| | * [dev.cc] runtime: fix arm5 buildRuss Cox2014-11-111-1/+1
| | | | | | | | | | | | | | | | | | TBR=r CC=golang-codereviews https://codereview.appspot.com/168600043
| | * [dev.cc] runtime/cgo: add missing import _ "unsafe" for //go:linknameRuss Cox2014-11-113-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Will prod freebsd build along. Not claiming it will fix it. TBR=r CC=golang-codereviews https://codereview.appspot.com/171580044
| | * [dev.cc] runtime: convert freebsd to GoRuss Cox2014-11-1125-1008/+639
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It builds. Don't know if it works, but it's a lot closer than having everything in C. LGTM=r R=r CC=golang-codereviews https://codereview.appspot.com/168590043
| | * [dev.cc] runtime: convert softfloat_arm.c to Go + build fixesRuss Cox2014-11-116-707/+662
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also include onM_signalok fix from issue 8995. Fixes linux/arm build. Fixes issue 8995. LGTM=r R=r, dave CC=golang-codereviews https://codereview.appspot.com/168580043
| | * [dev.cc] runtime: bring back mgc0.hRuss Cox2014-11-111-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | This was recorded as an hg mv instead of an hg cp. For now a C version is needed for the Go compiler. TBR=r CC=golang-codereviews https://codereview.appspot.com/174020043