2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
cmd/cc, runtime: convert C compilers to use Go calling convention
To date, the C compilers and Go compilers differed only in how
values were returned from functions. This made it difficult to call
Go from C or C from Go if return values were involved. It also made
assembly called from Go and assembly called from C different.
This CL changes the C compiler to use the Go conventions, passing
results on the stack, after the arguments.
[Exception: this does not apply to C ... functions, because you can't
know where on the stack the arguments end.]
By doing this, the CL makes it possible to rewrite C functions into Go
one at a time, without worrying about which languages call that
function or which languages it calls.
This CL also updates all the assembly files in package runtime to use
the new conventions. Argument references of the form 40(SP) have
been rewritten to the form name+10(FP) instead, and there are now
Go func prototypes for every assembly function called from C or Go.
This means that 'go vet runtime' checks effectively every assembly
function, and go vet's output was used to automate the bulk of the
conversion.
Some functions, like seek and nsec on Plan 9, needed to be rewritten.
Many assembly routines called from C were reading arguments
incorrectly, using MOVL instead of MOVQ or vice versa, especially on
the less used systems like openbsd.
These were found by go vet and have been corrected too.
If we're lucky, this may reduce flakiness on those systems.
Tested on:
darwin/386
darwin/amd64
linux/arm
linux/386
linux/amd64
If this breaks another system, the bug is almost certainly in the
sys_$GOOS_$GOARCH.s file, since the rest of the CL is tested
by the combination of the above systems.
LGTM=dvyukov, iant
R=golang-codereviews, 0intro, dave, alex.brainman, dvyukov, iant
CC=golang-codereviews, josharian, r
https://golang.org/cl/135830043
2014-08-27 09:32:17 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
2015-10-21 19:36:05 -06:00
|
|
|
type mOS struct {
|
|
|
|
waitsema int32 // semaphore for parking on locks
|
|
|
|
waitsemacount int32
|
|
|
|
waitsemalock int32
|
|
|
|
}
|
2015-10-21 13:48:53 -06:00
|
|
|
|
2014-11-21 08:22:18 -07:00
|
|
|
func nacl_exception_stack(p uintptr, size int32) int32
|
|
|
|
func nacl_exception_handler(fn uintptr, arg unsafe.Pointer) int32
|
cmd/cc, runtime: convert C compilers to use Go calling convention
To date, the C compilers and Go compilers differed only in how
values were returned from functions. This made it difficult to call
Go from C or C from Go if return values were involved. It also made
assembly called from Go and assembly called from C different.
This CL changes the C compiler to use the Go conventions, passing
results on the stack, after the arguments.
[Exception: this does not apply to C ... functions, because you can't
know where on the stack the arguments end.]
By doing this, the CL makes it possible to rewrite C functions into Go
one at a time, without worrying about which languages call that
function or which languages it calls.
This CL also updates all the assembly files in package runtime to use
the new conventions. Argument references of the form 40(SP) have
been rewritten to the form name+10(FP) instead, and there are now
Go func prototypes for every assembly function called from C or Go.
This means that 'go vet runtime' checks effectively every assembly
function, and go vet's output was used to automate the bulk of the
conversion.
Some functions, like seek and nsec on Plan 9, needed to be rewritten.
Many assembly routines called from C were reading arguments
incorrectly, using MOVL instead of MOVQ or vice versa, especially on
the less used systems like openbsd.
These were found by go vet and have been corrected too.
If we're lucky, this may reduce flakiness on those systems.
Tested on:
darwin/386
darwin/amd64
linux/arm
linux/386
linux/amd64
If this breaks another system, the bug is almost certainly in the
sys_$GOOS_$GOARCH.s file, since the rest of the CL is tested
by the combination of the above systems.
LGTM=dvyukov, iant
R=golang-codereviews, 0intro, dave, alex.brainman, dvyukov, iant
CC=golang-codereviews, josharian, r
https://golang.org/cl/135830043
2014-08-27 09:32:17 -06:00
|
|
|
func nacl_sem_create(flag int32) int32
|
|
|
|
func nacl_sem_wait(sem int32) int32
|
|
|
|
func nacl_sem_post(sem int32) int32
|
|
|
|
func nacl_mutex_create(flag int32) int32
|
|
|
|
func nacl_mutex_lock(mutex int32) int32
|
|
|
|
func nacl_mutex_trylock(mutex int32) int32
|
|
|
|
func nacl_mutex_unlock(mutex int32) int32
|
|
|
|
func nacl_cond_create(flag int32) int32
|
|
|
|
func nacl_cond_wait(cond, n int32) int32
|
|
|
|
func nacl_cond_signal(cond int32) int32
|
|
|
|
func nacl_cond_broadcast(cond int32) int32
|
2014-11-21 08:22:18 -07:00
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func nacl_cond_timed_wait_abs(cond, lock int32, ts *timespec) int32
|
|
|
|
func nacl_thread_create(fn uintptr, stk, tls, xx unsafe.Pointer) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func nacl_nanosleep(ts, extra *timespec) int32
|
|
|
|
func nanotime() int64
|
|
|
|
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer
|
|
|
|
func exit(code int32)
|
|
|
|
func osyield()
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func write(fd uintptr, p unsafe.Pointer, n int32) int32
|
2014-08-29 14:20:48 -06:00
|
|
|
|
2014-12-22 11:27:53 -07:00
|
|
|
//go:linkname os_sigpipe os.sigpipe
|
2014-09-03 22:54:06 -06:00
|
|
|
func os_sigpipe() {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("too many writes on closed pipe")
|
2014-09-03 22:54:06 -06:00
|
|
|
}
|
liblink, runtime: diagnose and fix C code running on Go stack
This CL contains compiler+runtime changes that detect C code
running on Go (not g0, not gsignal) stacks, and it contains
corrections for what it detected.
The detection works by changing the C prologue to use a different
stack guard word in the G than Go prologue does. On the g0 and
gsignal stacks, that stack guard word is set to the usual
stack guard value. But on ordinary Go stacks, that stack
guard word is set to ^0, which will make any stack split
check fail. The C prologue then calls morestackc instead
of morestack, and morestackc aborts the program with
a message about running C code on a Go stack.
This check catches all C code running on the Go stack
except NOSPLIT code. The NOSPLIT code is allowed,
so the check is complete. Since it is a dynamic check,
the code must execute to be caught. But unlike the static
checks we've been using in cmd/ld, the dynamic check
works with function pointers and other indirect calls.
For example it caught sigpanic being pushed onto Go
stacks in the signal handlers.
Fixes #8667.
LGTM=khr, iant
R=golang-codereviews, khr, iant
CC=golang-codereviews, r
https://golang.org/cl/133700043
2014-09-08 12:05:23 -06:00
|
|
|
|
2016-01-01 16:44:12 -07:00
|
|
|
func dieFromSignal(sig int32) {
|
|
|
|
exit(2)
|
|
|
|
}
|
|
|
|
|
liblink, runtime: diagnose and fix C code running on Go stack
This CL contains compiler+runtime changes that detect C code
running on Go (not g0, not gsignal) stacks, and it contains
corrections for what it detected.
The detection works by changing the C prologue to use a different
stack guard word in the G than Go prologue does. On the g0 and
gsignal stacks, that stack guard word is set to the usual
stack guard value. But on ordinary Go stacks, that stack
guard word is set to ^0, which will make any stack split
check fail. The C prologue then calls morestackc instead
of morestack, and morestackc aborts the program with
a message about running C code on a Go stack.
This check catches all C code running on the Go stack
except NOSPLIT code. The NOSPLIT code is allowed,
so the check is complete. Since it is a dynamic check,
the code must execute to be caught. But unlike the static
checks we've been using in cmd/ld, the dynamic check
works with function pointers and other indirect calls.
For example it caught sigpanic being pushed onto Go
stacks in the signal handlers.
Fixes #8667.
LGTM=khr, iant
R=golang-codereviews, khr, iant
CC=golang-codereviews, r
https://golang.org/cl/133700043
2014-09-08 12:05:23 -06:00
|
|
|
func sigpanic() {
|
|
|
|
g := getg()
|
|
|
|
if !canpanic(g) {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("unexpected signal during runtime execution")
|
liblink, runtime: diagnose and fix C code running on Go stack
This CL contains compiler+runtime changes that detect C code
running on Go (not g0, not gsignal) stacks, and it contains
corrections for what it detected.
The detection works by changing the C prologue to use a different
stack guard word in the G than Go prologue does. On the g0 and
gsignal stacks, that stack guard word is set to the usual
stack guard value. But on ordinary Go stacks, that stack
guard word is set to ^0, which will make any stack split
check fail. The C prologue then calls morestackc instead
of morestack, and morestackc aborts the program with
a message about running C code on a Go stack.
This check catches all C code running on the Go stack
except NOSPLIT code. The NOSPLIT code is allowed,
so the check is complete. Since it is a dynamic check,
the code must execute to be caught. But unlike the static
checks we've been using in cmd/ld, the dynamic check
works with function pointers and other indirect calls.
For example it caught sigpanic being pushed onto Go
stacks in the signal handlers.
Fixes #8667.
LGTM=khr, iant
R=golang-codereviews, khr, iant
CC=golang-codereviews, r
https://golang.org/cl/133700043
2014-09-08 12:05:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Native Client only invokes the exception handler for memory faults.
|
|
|
|
g.sig = _SIGSEGV
|
|
|
|
panicmem()
|
|
|
|
}
|
2015-01-14 09:18:24 -07:00
|
|
|
|
|
|
|
func raiseproc(sig int32) {
|
|
|
|
}
|
2015-03-02 21:16:48 -07:00
|
|
|
|
2016-03-01 16:21:55 -07:00
|
|
|
// Stubs so tests can link correctly. These should never be called.
|
2015-03-02 21:16:48 -07:00
|
|
|
func open(name *byte, mode, perm int32) int32
|
2015-04-13 17:37:04 -06:00
|
|
|
func closefd(fd int32) int32
|
2015-03-02 21:16:48 -07:00
|
|
|
func read(fd int32, p unsafe.Pointer, n int32) int32
|