Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
When a cgo program calls setuid, setgid, etc., the GNU/Linux
pthread library sends signal SIGSETXID to each thread to tell
it to update its UID info. If Go is permitted to intercept
the default SIGSETXID signal handler, the program will hang.
This patch tells the runtime package to not try to intercept
SIGSETXID on GNU/Linux. This will be odd if a Go program
wants to try to use that signal, but it means that cgo
programs that call setuid, etc., won't hang.
Fixes#3871.
R=rsc, r, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/6455050
Move panic/defer/recover-related stuff from proc.c/runtime.c to a new file panic.c.
No semantic changes.
proc.c is 1800+ LOC and is a bit difficult to work with.
R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/6343071
1. Rename 'g' and 'm' local vars to 'gp' and 'mp' (convention already used in some functions)
'g' and 'm' are global vars that mean current goroutine and current machine,
when they are shadowed by local vars, it's confusing, no ability to debug log both, etc.
2. White-space shuffling.
No semantic changes.
In preparation to bigger changes.
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/6355061
There may be further savings if convT2I can avoid the function call
if the cache is good and T is uintptr-shaped, a la convT2E, but that
will be a follow-up CL.
src/pkg/runtime:
benchmark old ns/op new ns/op delta
BenchmarkConvT2ISmall 43 15 -64.01%
BenchmarkConvT2IUintptr 45 14 -67.48%
BenchmarkConvT2ILarge 130 101 -22.31%
test/bench/go1:
benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 8588997000 8499058000 -1.05%
BenchmarkFannkuch11 5300392000 5358093000 +1.09%
BenchmarkGobDecode 30295580 31040190 +2.46%
BenchmarkGobEncode 18102070 17675650 -2.36%
BenchmarkGzip 774191400 771591400 -0.34%
BenchmarkGunzip 245915100 247464100 +0.63%
BenchmarkJSONEncode 123577000 121423050 -1.74%
BenchmarkJSONDecode 451969800 596256200 +31.92%
BenchmarkMandelbrot200 10060050 10072880 +0.13%
BenchmarkParse 10989840 11037710 +0.44%
BenchmarkRevcomp 1782666000 1716864000 -3.69%
BenchmarkTemplate 798286600 723234400 -9.40%
R=rsc, bradfitz, go.peter.90, daniel.morsing, dave, uriel
CC=golang-dev
https://golang.org/cl/6337058
The issue seems to not be triggered right now,
but I've seen the deadlock after some other legal
modifications to runtime.
So I think we are safer this way.
R=rsc, r
CC=golang-dev
https://golang.org/cl/6339051
This can only happen if the hash function we're using is getting
far more than it's fair share of collisions, but that has happened
to us repeatedly as we've expanded the allowed use cases for
hash tables (issue 1544, issue 2609, issue 2630, issue 2883, issue 3695).
Maybe this will help the next time we try something new.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6306083
if we were to use sizeof(sa.sa_mask) instead of 8 as the last argument
to rt_sigaction, we would have already fixed this bug, so also updated
Linux/386 and Linux/amd64 files to use that; also test the return value
of rt_sigaction.
R=dave, rsc
CC=golang-dev
https://golang.org/cl/6297087
On netbsd/386, tv_sec is a 64-bit integer for both timeval and timespec.
Fix the time handling code so that it works correctly.
R=golang-dev, rsc, m4dh4tt3r
CC=golang-dev
https://golang.org/cl/6256056
Thanks to Dave Cheney for the magic words "comm page".
benchmark old ns/op new ns/op delta
BenchmarkNow 197 33 -83.05%
This should make profiling a little better on OS X.
The raw time saved is unlikely to matter: what likely matters
more is that it seems like OS X sends profiling signals on the
way out of system calls more often than it should; avoiding
the system call should increase the accuracy of cpu profiles.
The 386 version would be similar but needs to do different
math for CPU speeds less than 1 GHz. (Apparently Apple has
never shipped a 64-bit CPU with such a slow clock.)
R=golang-dev, bradfitz, dave, minux.ma, r
CC=golang-dev
https://golang.org/cl/6275056
amd64 was done in CL 6275056.
We don't attempt to handle machines with clock speeds
less than 1 GHz. Those will fall back to the system call.
benchmark old ns/op new ns/op delta
BenchmarkNow 364 38 -89.53%
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6307045
Using an int64 for a block size doesn't make
sense on 32bit platforms but extracts a performance
penalty dealing with double word quantities on Arm.
linux/arm
benchmark old ns/op new ns/op delta
BenchmarkGobDecode 155401600 144589300 -6.96%
BenchmarkGobEncode 72772220 62460940 -14.17%
BenchmarkGzip 5822632 2604797 -55.26%
BenchmarkGunzip 326321 151721 -53.51%
benchmark old MB/s new MB/s speedup
BenchmarkGobDecode 4.94 5.31 1.07x
BenchmarkGobEncode 10.55 12.29 1.16x
R=golang-dev, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6272047
The previous code was preparing arrays of entries that would be
filled if there was one entry every 128 bytes. Moving to a 4096
byte interval reduces the overhead per megabyte of address space
to 2kB from 64kB (on 64-bit systems).
The performance impact will be negative for very small MemProfileRate.
test/bench/garbage/tree2 -heapsize 800000000 (default memprofilerate)
Before: mprof 65993056 bytes (1664 bucketmem + 65991392 addrmem)
After: mprof 1989984 bytes (1680 bucketmem + 1988304 addrmem)
R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6257069
The previous heap profile format did not include buckets with
zero used bytes. Also add several missing MemStats fields in
debug mode.
R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6249068
The correct procid is needed for unparking LWPs on NetBSD - always
initialise procid in minit() so that cgo works correctly. The non-cgo
case already works correctly since procid is initialised via
lwp_create().
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6257071
A block with finalizer might also be profiled. The special bit
is needed to unregister the block from the profile. It will be
unset only when the block is freed.
Fixes#3668.
R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6249066
It's sad to introduce a new macro, but rnd shows up consistently
in profiles, and the function call overwhelms the two arithmetic
instructions it performs.
R=r
CC=golang-dev
https://golang.org/cl/6260051
This is from CL 5451105 but was dropped from that CL.
See also CL 6137051.
The only change compared to 5451105 is to check for
h != nil in reflect·mapiterinit; allowing use of nil maps
must have happened after that original CL.
Fixes#3573.
R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/6215078
The previous attempt to explain this got it backwards (all the more reason to be
sad we couldn't make the two functions behave the same).
Fixes#3669.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6249051
This fixes occasional 64-bit failures.
Maybe it will fix the 32-bit failures too,
so re-enable on 32-bit for now.
R=golang-dev, bradfitz, r, dvyukov
CC=golang-dev
https://golang.org/cl/6218050
With the timed semacquire patch
(kernel-tsemacquire) for Plan 9,
we can now properly do a timed
wait for the semaphore, in
semasleep.
R=golang-dev, rsc, rminnich, ality, r
CC=0intro, golang-dev, john, mirtchovski
https://golang.org/cl/6197046
Implement getcontext and sigprocmask for NetBSD - these will soon be
used by the thread handling code.
Also fix netbsd/386 signal handling - there is no sigreturn, just
return so that we hit the trampoline.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6215049
Update/correct NetBSD signal handling - most of this is needed due to
the correctly generated runtime definitions.
R=golang-dev, m4dh4tt3r, rsc
CC=golang-dev
https://golang.org/cl/6195079
Fix and regenerate runtime defs for NetBSD.
Whilst the mcontext struct can be handled across architectures,
the registers are provided as defines that index an array, rather
than as members of the struct. Since these are architecture
dependent, include them via a defs_netbsd_<arch>.go file.
R=golang-dev, m4dh4tt3r, rsc
CC=golang-dev
https://golang.org/cl/6190070
Parallel GC needs to know in advance how many helper threads will be there.
Hopefully it's the last patch before I can tackle parallel sweep phase.
The benchmarks are unaffected.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6200064
Set the TLS base using the _lwp_setprivate() syscall, instead of via
sysarch(). NetBSD tracks the pointer passed to _lwp_setprivate() and
restores this value when restoring mcontext. If sysarch() is used
directly, restoring an mcontext trashes the FS/GS value, resulting
in a segfault when we next try to access the TLS.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6206062
we can't add the division result to n during iteration, because it might
turn n into NaN or Inf.
R=golang-dev, rsc, iant, iant
CC=golang-dev
https://golang.org/cl/6197045
Use correct syscall numbers and arguments for NetBSD.
Provide a trampoline for signal returns (using signal API 3).
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6209048
Decode AT_RANDOM, AT_HWCAP, and AT_PLATFORM.
This CL only make use of AT_RANDOM, but future CLs will make use of the others.
R=dave, rsc
CC=golang-dev
https://golang.org/cl/5978051
1. In CL 5989057, I made a mistake in the last minute change.
"MOVW.W R4, -4(SP)" should really be "MOVW.W R4, -4(R13)",
as 5l will rewrite offset for SP.
2. misc/cgo/test/issue1560.go tests for parallel sleep of 1s,
but on ARM, the deadline is frequently missed, so change sleep
time to 2s on ARM.
R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6202043
This adds proper note handling for Plan 9,
and fixes the issue of properly killing go procs.
Without this change, the first go proc that dies
(using runtime·exit()) would kill all the running
go procs. Proper signal handling is needed.
R=golang-dev, ality, rminnich, rsc
CC=golang-dev, john, mirtchovski
https://golang.org/cl/5617048
This makes it possible to inline the prefetch of upcoming
memory addresses during garbage collection, instead of
needing to flush registers, make a function call, and
reload registers. On garbage collection-heavy workloads,
this results in a 5% speedup.
Fixes#3493.
R=dvyukov, ken, r, dave
CC=golang-dev
https://golang.org/cl/5990066
Switch from using the rfork() syscall on OpenBSD, to the __tfork()
syscall. The __tfork() syscall is the preferred way of creating
system threads and the rfork() syscall has recently been removed.
Note: this will break compatibility with OpenBSD releases prior to 5.1.
R=golang-dev, bradfitz, devon.odell, rsc
CC=golang-dev
https://golang.org/cl/6037048
This lets the test pass on PPC64 GNU/Linux, which uses a much
larger page size and thus uses more memory to hold blocks
allocated for memory profiling.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6048054
Update runtime defs for openbsd. Add struct __tfork, which will be
needed by an upcoming change.
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/6007050
Update the threxit and thrsleep syscalls to match the ABI of the
OpenBSD 5.1 kernel. These changes are backwards compatible with
older kernels.
Fixes#3311.
R=golang-dev, rsc, devon.odell
CC=golang-dev
https://golang.org/cl/5777079
This leads to ~30kB improvement on code size for ARM machines with VFP/NEON.
Example: go test -c math
GOARM=5 GOARM=6
Old: 1884200 1839144
New: 1884165 1805245
-: 35 33899
R=rsc, bradfitz, dave, kai.backman
CC=golang-dev
https://golang.org/cl/5975060
Change 5660047 moved an FLDCW instruction
that disables invalid operand traps into
runtime·asminit, which is called from
runtime·mstart. Thus, runtime·check is being
called prior to setting the appropriate control bits,
which on any QNaN comparison will cause Plan 9
to take an invalid operand trap. This change loads
the control bits (for Plan 9) prior to runtime·check.
Ideally, this should be done before the QNaN checks
on any system, but possibly other kernels simply
don't ever trap on invalid operands.
R=golang-dev, rminnich
CC=golang-dev, john, rsc
https://golang.org/cl/5939045
Block signals during thread creation, otherwise the new thread can
receive a signal prior to initialisation completing.
Fixes#3102.
R=golang-dev, rsc, devon.odell, minux.ma
CC=golang-dev
https://golang.org/cl/5757064
It is a bug that Caller and Callers disagree about the offset of the skip
parameter. Document the bug.
R=rsc, dsymonds, r, iant
CC=golang-dev
https://golang.org/cl/5976064
Not a complete fix for issue 3342, but fixes the trivial case.
There may still be a race in the instants before and after
a scavenger-induced garbage collection.
Intended to be "obviously safe": a call to runtime·gosched
before main.main is no different than a call to runtime.Gosched
at the beginning of main.main, and it is (or had better be)
safe to call runtime.Gosched at any point during main.
Update #3342.
R=iant
CC=golang-dev
https://golang.org/cl/5919052
Breaks closure test when GOMAXPROCS=2 or more.
««« original CL description
runtime: restore deadlock detection in the simplest case.
Fixes#3342.
R=iant, r, dave, rsc
CC=golang-dev, remy
https://golang.org/cl/5844051
»»»
R=rsc
CC=golang-dev
https://golang.org/cl/5924045
There was a small window during program initialization
where a signal could come in before the handling mechanisms
were set up to handle it. Delay the signal-handler installation
until we're ready for the signals.
Fixes#3314.
R=golang-dev, dsymonds, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/5833049
This function uses 48-byte of precious non-split stack for every callback
function, and without this CL, it can easily overflow the non-split stack.
I encountered this when trying to enable misc/cgo/test on windows/amd64.
R=rsc
CC=golang-dev
https://golang.org/cl/5784075
It's the best we can do before Go 1.
For issue 3250; not a fix but at least less mysterious.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5797068
It may have to switch stacks, since we are calling
a DLL instead of a system call.
badcallback says where it is, because it is being called
on a Windows stack already.
R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/5782060
Implement runtime·write, like on the other systems,
and also runtime·badcallback, in assembly to reduce
stack footprint.
TBR=golang-dev
CC=golang-dev
https://golang.org/cl/5785055
When a very low-level system call that should never fail
does fail, we call notok, which crashes the program.
Often, we are then left with only the program counter as
information about the crash, and it is in notok.
Instead, inline calls to notok (it is just one instruction
on most systems) so that the program counter will
tell us which system call is unhappy.
R=golang-dev, gri, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/5792048
Before:
$ go run x.go
signal 11 (core dumped)
$
After:
$ go run x.go
runtime: cgo callback on thread not created by Go.
signal 11 (core dumped)
$
For issue 3068.
Not a fix, but as much of a fix as we can do before Go 1.
R=golang-dev, rogpeppe, gri
CC=golang-dev
https://golang.org/cl/5781047
If it didn't reach the limit, we can try extending the arena
before resorting to random memory mappings and praying for the
kernel to be kind.
Fixes#3173.
R=rsc, rsc
CC=golang-dev
https://golang.org/cl/5725045
Don't try to print obviously corrupt slices or interfaces.
Doesn't actually solve 3047 or 2818, but seems a good idea anyway.
R=rsc, bsiegert
CC=golang-dev
https://golang.org/cl/5708061
Work around profiling kernel bug with signal masks.
Still broken on 64-bit Snow Leopard kernel,
but I think we can ignore that one and let people
upgrade to Lion.
Add new trivial tools addr2line and objdump to take
the place of the GNU tools of the same name, since
those are not installed on OS X.
Adapt pprof to invoke 'go tool addr2line' and
'go tool objdump' if the system tools do not exist.
Clean up disassembly of base register on amd64.
Fixes#2008.
R=golang-dev, bradfitz, mikioh.mikioh, r, iant
CC=golang-dev
https://golang.org/cl/5697066
Makes it possible for client code to maintain its own profiles,
and also reduces the API surface by giving us a type that
models built-in profiles.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5684056
Ignore signals while we are spawning a new thread. Previously, a
signal arriving just before runtime.minit setting up the signal
handler triggers a "double fault" in signal trampolining.
Fixes#3017.
R=rsc, mikioh.mikioh, minux.ma, adg
CC=golang-dev
https://golang.org/cl/5684060
cc: add #pragma textflag to set it
runtime: mark mheap to go into noptr-bss.
remove special case in garbage collector
Remove the ARM from.flag field created by CL 5687044.
The DUPOK flag was already in p->reg, so keep using that.
Otherwise test/nilptr.go creates a very large binary.
Should fix the arm build.
Diagnosed by minux.ma; replacement for CL 5690044.
R=golang-dev, minux.ma, r
CC=golang-dev
https://golang.org/cl/5686060
A fault during malloc might lead to the program's
first call to findfunc, which would in turn call malloc.
Don't do that.
Fixes#1777.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5689047
morebuf holds a pc/sp from the last stack split or
reflect.call or panic/recover. If the pc is a closure,
the reference will keep it from being collected.
moreargp holds a pointer to the arguments from the
last stack split or reflect.call or panic/recover.
Normally it is a stack pointer and thus not of interest,
but in the case of reflect.call it is an allocated argument
list and holds up the arguments to the call.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5674109
The m->cret word holds the C return value when returning
across a stack split boundary. It was not being cleared after
use, which means that the return value (if a C function)
or else the value of AX/R0 at the time of the last stack unsplit
was being kept alive longer than necessary. Clear it.
I think the effect here should be very small, but worth fixing
anyway.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5677092
Periodically browse MHeap's freelists for long unused spans and release them if any.
Current hardcoded settings:
- GC is forced if none occured over the last 2 minutes.
- spans are handed back after 5 minutes of uselessness.
SysUnused (for Unix) is a wrapper on madvise MADV_DONTNEED on Linux and MADV_FREE on BSDs.
R=rsc, dvyukov, remyoudompheng
CC=golang-dev
https://golang.org/cl/5451057