net/http/cgi: Correctly pass down the REMOTE_PORT value for CGI requests.

Currently when we get a CGI or FCGI request, the remote port of the client
is hard coded to zero, despite nearly every webserver passing down the
REMOTE_PORT variable.

This was likely originally excluded because the CGI RFC (rfc3875) does not
mention anything about the remote port of the client. However every webserver
tested does pass REMOTE_PORT down. This includes Apache 2.2, Apache 2.4,
nginx and lighttpd.

Fixes #8351

Change-Id: I4c6366cb39f0ccc05e038bd31d85f93b76e8d0c8
Reviewed-on: https://go-review.googlesource.com/1750
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
runtime: run libc SIGSETXID and SIGCANCEL handlers on signal stack

These signals are used by glibc to broadcast setuid/setgid to all
threads and to send pthread cancellations.  Unlike other signals, the
Go runtime does not intercept these because they must invoke the libc
handlers (see issues #3871 and #6997).  However, because 1) these
signals may be issued asynchronously by a thread running C code to
another thread running Go code and 2) glibc does not set SA_ONSTACK
for its handlers, glibc's signal handler may be run on a Go stack.
Signal frames range from 1.5K on amd64 to many kilobytes on ppc64, so
this may overflow the Go stack and corrupt heap (or other stack) data.

Fix this by ensuring that these signal handlers have the SA_ONSTACK
flag (but not otherwise taking over the handler).

This has been a problem since Go 1.1, but it's likely that people
haven't encountered it because it only affects setuid/setgid and
pthread_cancel.

Fixes #9600.

Change-Id: I6cf5f5c2d3aa48998d632f61f1ddc2778dcfd300
Reviewed-on: https://go-review.googlesource.com/1887
Reviewed-by: Ian Lance Taylor <iant@golang.org>
runtime: correct ptrSize test in Linux version of sysReserve

Change-Id: I90a8ca51269528a307e0d6f52436fc7913cd7900
Reviewed-on: https://go-review.googlesource.com/1541
Reviewed-by: Russ Cox <rsc@golang.org>
misc/cgo: fix issue 9400 test on 386

issue9400_linux.go did not build on 386 because it used a constant
that was larger than a 32-bit int in a ... argument.  Fix this by
casting the constant to uint64 (to match how the constant is being
used).

Change-Id: Ie8cb64c3910382a41c7852be7734a62f0b2d5a21
Reviewed-on: https://go-review.googlesource.com/2060
Reviewed-by: Ian Lance Taylor <iant@golang.org>
runtime: remove thunk.s

Replace with uses of //go:linkname in Go files, direct use of name in .s files.
The only one that really truly needs a jump is reflect.call; the jump is now
next to the runtime.reflectcall assembly implementations.

Change-Id: Ie7ff3020a8f60a8e4c8645fe236e7883a3f23f46
Reviewed-on: https://go-review.googlesource.com/1962
Reviewed-by: Austin Clements <austin@google.com>
reflect: add kindNoPointers if a function layout has no pointers.

malloc checks kindNoPointers and if it is not set and the object
is one pointer in size, it assumes it contains a pointer.  So we
must set kindNoPointers correctly; it isn't just a hint.

Fixes #9425

Change-Id: Ia43da23cc3298d6e3d6dbdf66d32e9678f0aedcf
Reviewed-on: https://go-review.googlesource.com/2055
Reviewed-by: Russ Cox <rsc@golang.org>
runtime: import unsafe in os_windows.go (fixes windows build)

Change-Id: I55419cb580e6d18cf1c17c3e7bb8777ed6d794e7
Reviewed-on: https://go-review.googlesource.com/1995
Reviewed-by: Ian Lance Taylor <iant@golang.org>
build: give freebsd longer to run tests

The freebsd-386 and freebsd-amd64 builders are timing out sometimes.
This will give them some more breathing room.

Change-Id: Ib65bd172cca046a52861759a4232d7b4b6514fa8
Reviewed-on: https://go-review.googlesource.com/1994
Reviewed-by: Ian Lance Taylor <iant@golang.org>
runtime: fix build for arm and ppc64/ppc64le

Change-Id: I17ddcb541dfac8b1e48e01ee005563031b6ade2a
Reviewed-on: https://go-review.googlesource.com/2062
Reviewed-by: Ian Lance Taylor <iant@golang.org>
cmd/api: work around Windows rename issue on the builders

More cmd/api/run.go hell.

Fixes #9407

Change-Id: If8fb446a2471d6372beb0534c9ab6824029b404c
Reviewed-on: https://go-review.googlesource.com/2054
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Minux Ma <minux@golang.org>
runtime: add comments for blank import of "unsafe"

Change-Id: Iaad548ea90d3b70341a723450d5e4d4c2b88856f
Reviewed-on: https://go-review.googlesource.com/2063
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
runtime: remove thunk_windows.s

Change-Id: I171298e7942093e9cc82e3a0c4fcbb5b10298816
Reviewed-on: https://go-review.googlesource.com/1998
Reviewed-by: Minux Ma <minux@golang.org>
cmd/dist: fatal shouldn't print errstr on Plan 9

During change 1864 discussion, Russ Cox pointed out
the fatal function shouldn't print errstr.

Change-Id: Icd71ec04be9c944bc235b8b198158465172e4fde
Reviewed-on: https://go-review.googlesource.com/2030
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
test: disable bug248 and bug345 tests on Plan 9

These tests were enabled as part of change 1774.
They depend on the errchk tool, which is a Perl
script. However, Perl is not available on Plan 9.

Change-Id: I82707aae16013acc9a3800d39b0084588b852b53
Reviewed-on: https://go-review.googlesource.com/2031
Reviewed-by: Minux Ma <minux@golang.org>
math/rand: fix example_test to show with the correct method

Originally it used r.Int63() to show "Uint32", and now we use the correct r.Uint32() method.

Fixes #9429

Change-Id: I8a1228f1ca1af93b0e3104676fc99000257c456f
Reviewed-on: https://go-review.googlesource.com/2069
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
runtime: fix exit on Plan 9

Add a nil byte at the end of the itoa buffer,
before calling gostringnocopy. This prevents
gostringnocopy to read past the buffer size.

Change-Id: I87494a8dd6ea45263882536bf6c0f294eda6866d
Reviewed-on: https://go-review.googlesource.com/2033
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
mime/multipart: moved some code to mime/internal/quotedprintable

The code concerning quoted-printable encoding (RFC 2045) and its
variant for MIME headers (RFC 2047) is currently spread in
mime/multipart and net/mail. It is also not exported.

This commit is the first step to fix that issue. It moves the
quoted-printable decoding code from mime/multipart to
mime/internal/quotedprintable. The exposed API is unchanged.

Concerns #4943.

Change-Id: I11352afbb2edb4d6ef62870b9bc5c87c639eff12
Reviewed-on: https://go-review.googlesource.com/1810
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
reflect: more function layout tests

Test more stuff:
1) flagNoPointers, an incorrect value was the cause of #9425
2) Total function layout size
3) gc program

Change-Id: I73f65fe740215938fa930d2f096febd9db0a0021
Reviewed-on: https://go-review.googlesource.com/2090
Reviewed-by: Ian Lance Taylor <iant@golang.org>
go/build: add variable expansion to cgo lines

When go parses #cgo lines, expand ${SRCDIR} into the path to the
source directory. This allows options to be passed to the
compiler and linker that involve file paths relative to the
source code directory. Without the expansion the paths would be
invalid when the current working directory changes.

Fixes #7891
Fixes #5428

Change-Id: I343a145a9771a5ccbaa958e4a1ecd1716fcae52d
Reviewed-on: https://go-review.googlesource.com/1756
Reviewed-by: Ian Lance Taylor <iant@golang.org>