aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_freebsd_amd64.s
AgeCommit message (Collapse)Author
2021-04-15runtime: unify C->Go ABI transitionsAustin Clements
The previous CL introduced macros for transitions from the Windows ABI to the Go ABI. This CL does the same for SysV and uses them in almost all places where we transition from the C ABI to the Go ABI. Compared to Windows, this transition is much simpler and I didn't find any places that were getting it wrong. But this does let us unify a lot of code nicely and introduces some degree of abstraction around these ABI transitions. Change-Id: Ib6bdecafce587ce18fca4c8300fcf401284a2bcd Reviewed-on: https://go-review.googlesource.com/c/go/+/309930 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2020-12-22runtime: correct error handling in several FreeBSD syscall wrappersNikhil Benesch
The FreeBSD syscall convention uses the carry flag to indicate whether an error has occured. The sys_umtx_op, thr_new, and pipe2 syscall wrappers were failing to account for this convention and silently suppressing errors as a result. This commit corrects these wrappers by copying the pattern used by the other fallible syscall wrappers. Note that futexsleep1 must now explicitly ignore the ETIMEDOUT error from sys_umtx_op. Previously ETIMEDOUT was implicitly ignored because sys_umtx_op never returned an error. Fixes #43106. Change-Id: I9c422b87cf4c6d308003bf42c3b419f785578b5d Reviewed-on: https://go-review.googlesource.com/c/go/+/276892 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Than McIntosh <thanm@google.com>
2019-10-26runtime: M-targeted signals for BSDsAustin Clements
For these, we split up the existing runtime.raise assembly implementation into its constituent "get thread ID" and "signal thread" parts. This lets us implement signalM and reimplement raise in pure Go. (NetBSD conveniently already had lwp_self.) We also change minit to store the procid directly, rather than depending on newosproc to do so. This is because newosproc isn't called for the bootstrap M, but we need a procid for every M. This is also simpler overall. For #10958, #24543. Change-Id: Ie5f1fcada6a33046375066bcbe054d1f784d39c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/201402 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-10-21runtime: change read and write to return negative errno valueIan Lance Taylor
The internal read and write functions used to return -1 on error; change them to return a negative errno value instead. This will be used by later CLs in this series. For most targets this is a simplification, although for ones that call into libc it is a complication. Updates #27707 Change-Id: Id02bf9487f03e7e88e4f2b85e899e986738697ad Reviewed-on: https://go-review.googlesource.com/c/go/+/171823 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2019-10-20runtime: define nonblockingPipeIan Lance Taylor
This requires defining pipe, pipe2, and setNonblock for various platforms. The new function is currently only used on AIX. It will be used by later CLs in this series. Updates #27707 Change-Id: Id2f987b66b4c66a3ef40c22484ff1d14f58e9b31 Reviewed-on: https://go-review.googlesource.com/c/go/+/171822 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-04runtime: wrap nanotime, walltime, and writeAustin Clements
In preparation for general faketime support, this renames the existing nanotime, walltime, and write functions to nanotime1, walltime1, and write1 and wraps them with trivial Go functions. This will let us inject different implementations on all platforms when faketime is enabled. Updates #30439. Change-Id: Ice5ccc513a32a6d89ea051638676d3ee05b00418 Reviewed-on: https://go-review.googlesource.com/c/go/+/192738 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-09-18runtime: use MADV_FREE on Linux if availableTobias Klauser
On Linux, sysUnused currently uses madvise(MADV_DONTNEED) to signal the kernel that a range of allocated memory contains unneeded data. After a successful call, the range (but not the data it contained before the call to madvise) is still available but the first access to that range will unconditionally incur a page fault (needed to 0-fill the range). A faster alternative is MADV_FREE, available since Linux 4.5. The mechanism is very similar, but the page fault will only be incurred if the kernel, between the call to madvise and the first access, decides to reuse that memory for something else. In sysUnused, test whether MADV_FREE is supported and fall back to MADV_DONTNEED in case it isn't. This requires making the return value of the madvise syscall available to the caller, so change runtime.madvise to return it. Fixes #23687 Change-Id: I962c3429000dd9f4a00846461ad128b71201bb04 Reviewed-on: https://go-review.googlesource.com/135395 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-18runtime: fast clock_gettime call on FreeBSDYuval Pavel Zholkover
Use AT_TIMEKEEP ELF aux entry to access a kernel mapped ring of timehands structs. The timehands are updated by the kernel periodically, but for accurate measure the timecounter still needs to be queried. Currently the fast path is used only when kern.timecounter.hardware==TSC-low or kern.timecounter.hardware=='ARM MPCore Timecounter', other timecounters revert back to regular system call. TODO: add support for HPET timecounter on 386/amd64. Change-Id: I321ca4e92be63ba21a2574b758ef5c1e729086ad Reviewed-on: https://go-review.googlesource.com/93156 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-03-21all: enable c-shared/c-archive support for freebsd/amd64Tim Wright
Fixes #14327 Much of the code is based on the linux/amd64 code that implements these build modes, and code is shared where possible. Change-Id: Ia510f2023768c0edbc863aebc585929ec593b332 Reviewed-on: https://go-review.googlesource.com/93875 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-17runtime: remove unused getrlimit functionTobias Klauser
Follow CL 93655 which removed the (commented-out) usage of this function. Also remove unused constant _RLIMIT_AS and type rlimit. Change-Id: Ifb6e6b2104f4c2555269f8ced72bfcae24f5d5e9 Reviewed-on: https://go-review.googlesource.com/94775 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2017-10-18runtime: separate error result for mmapAustin Clements
Currently mmap returns an unsafe.Pointer that encodes OS errors as values less than 4096. In practice this is okay, but it borders on being really unsafe: for example, the value has to be checked immediately after return and if stack copying were ever to observe such a value, it would panic. It's also not remotely idiomatic. Fix this by making mmap return a separate pointer value and error, like a normal Go function. Updates #22218. Change-Id: Iefd965095ffc82cc91118872753a5d39d785c3a6 Reviewed-on: https://go-review.googlesource.com/71270 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-11runtime: make it possible to exit Go-created threadsAustin Clements
Currently, threads created by the runtime exist until the whole program exits. For #14592 and #20395, we want to be able to exit and clean up threads created by the runtime. This commit implements that mechanism. The main difficulty is how to clean up the g0 stack. In cgo mode and on Solaris and Windows where the OS manages thread stacks, we simply arrange to return from mstart and let the system clean up the thread. If the runtime allocated the g0 stack, then we use a new exitThread syscall wrapper that arranges to clear a flag in the M once the stack can safely be reaped and call the thread termination syscall. exitThread is based on the existing exit1 wrapper, which was always meant to terminate the calling thread. However, exit1 has never been used since it was introduced 9 years ago, so it was broken on several platforms. exitThread also has the additional complication of having to flag that the stack is unused, which requires some tricks on platforms that use the stack for syscalls. This still leaves the problem of how to reap the unused g0 stacks. For this, we move the M from allm to a new freem list as part of the M exiting. Later, allocm scans the freem list, finds Ms that are marked as done with their stack, removes these from the list and frees their g0 stacks. This also allows these Ms to be garbage collected. This CL does not yet use any of this functionality. Follow-up CLs will. Likewise, there are no new tests in this CL because we'll need follow-up functionality to test it. Change-Id: Ic851ee74227b6d39c6fc1219fc71b45d3004bc63 Reviewed-on: https://go-review.googlesource.com/46037 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2017-03-10runtime: use cpuset_getaffinity for runtime.NumCPU() on FreeBSDDavid NewHamlet
In FreeBSD when run Go proc under a given sub-list of processors(e.g. 'cpuset -l 0 ./a.out' in multi-core system), runtime.NumCPU() still return all physical CPUs from sysctl hw.ncpu instead of account from sub-list. Fix by use syscall cpuset_getaffinity to account the number of sub-list. Fixes #15206 Change-Id: If87c4b620e870486efa100685db5debbf1210a5b Reviewed-on: https://go-review.googlesource.com/29341 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2017-02-03time: record monotonic clock reading in time.Now, for more accurate comparisonsRuss Cox
See https://golang.org/design/12914-monotonic for details. Fixes #12914. Change-Id: I80edc2e6c012b4ace7161c84cf067d444381a009 Reviewed-on: https://go-review.googlesource.com/36255 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Caleb Spare <cespare@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-12-15runtime: preserve callee-saved C registers in sigtrampBryan C. Mills
This fixes Linux and the *BSD platforms on 386/amd64. A few OS/arch combinations were already saving registers and/or doing something that doesn't clearly resemble the SysV C ABI; those have been left alone. Fixes #18328. Change-Id: I6398f6c71020de108fc8b26ca5946f0ba0258667 Reviewed-on: https://go-review.googlesource.com/34501 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-11-01runtime: align stack pointer in sigfwdBryan C. Mills
sigfwd calls an arbitrary C signal handler function. The System V ABI for x86_64 (and the most recent revision of the ABI for i386) requires the stack to be 16-byte aligned. Fixes: #17641 Change-Id: I77f53d4a8c29c1b0fe8cfbcc8d5381c4e6f75a6b Reviewed-on: https://go-review.googlesource.com/32107 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-27runtime: use clock_gettime(CLOCK_REALTIME) for nanosecond-precision time.now ↵Russ Cox
on arm64, mips64x Assembly copied from the clock_gettime(CLOCK_MONOTONIC) call in runtime.nanotime in these files and then modified to use CLOCK_REALTIME. Also comment system call numbers in a few other files. Fixes #11222. Change-Id: Ie132086de7386f865908183aac2713f90fc73e0d Reviewed-on: https://go-review.googlesource.com/32177 Reviewed-by: Cherry Zhang <cherryyz@google.com>
2016-10-01runtime: sleep on CLOCK_MONOTONIC in futexsleep1 on freebsdMike Appleby
In FreeBSD 10.0, the _umtx_op syscall was changed to allow sleeping on any supported clock, but the default clock was switched from a monotonic clock to CLOCK_REALTIME. Prior to 10.0, the __umtx_op_wait* functions ignored the fourth argument to _umtx_op (uaddr1), expected the fifth argument (uaddr2) to be a struct timespec pointer, and used a monotonic clock (nanouptime(9)) for timeout calculations. Since 10.0, if callers want a clock other than CLOCK_REALTIME, they must call _umtx_op with uaddr1 set to a value greater than sizeof(struct timespec), and with uaddr2 as pointer to a struct _umtx_time, rather than a timespec. Callers can set the _clockid field of the struct _umtx_time to request the clock they want. The relevant FreeBSD commit: https://svnweb.freebsd.org/base?view=revision&revision=232144 Fixes #17168 Change-Id: I3dd7b32b683622b8d7b4a6a8f9eb56401bed6bdf Reviewed-on: https://go-review.googlesource.com/30154 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-30runtime, syscall: use FP instead of SP for parametersMatthew Dempsky
Consistently access function parameters using the FP pseudo-register instead of SP (e.g., x+0(FP) instead of x+4(SP) or x+8(SP), depending on register size). Two reasons: 1) doc/asm says the SP pseudo-register should use negative offsets in the range [-framesize, 0), and 2) cmd/vet only validates parameter offsets when indexed from the FP pseudo-register. No binary changes to the compiled object files for any of the affected package/OS/arch combinations. Change-Id: I0efc6079bc7519fcea588c114ec6a39b245d68b0 Reviewed-on: https://go-review.googlesource.com/30085 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-25all: fix assembly vet issuesJosh Bleecher Snyder
Add missing function prototypes. Fix function prototypes. Use FP references instead of SP references. Fix variable names. Update comments. Clean up whitespace. (Not for vet.) All fairly minor fixes to make vet happy. Updates #11041 Change-Id: Ifab2cdf235ff61cdc226ab1d84b8467b5ac9446c Reviewed-on: https://go-review.googlesource.com/27713 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-24runtime: adjust gsignal stack to current signal stackIan Lance Taylor
If non-Go code calls sigaltstack before a signal is received, use sigaltstack to determine the current signal stack and set the gsignal stack to use it. This makes the Go runtime more robust in the face of non-Go code. We still can't handle a disabled signal stack or a signal triggered with SA_ONSTACK clear, but we now give clear errors for those cases. Fixes #7227. Update #9896. Change-Id: Icb1607e01fd6461019b6d77d940e59b3aed4d258 Reviewed-on: https://go-review.googlesource.com/18102 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2015-07-27runtime: log all thread stack traces during GODEBUG=crash on UnixIan Lance Taylor
This extends https://golang.org/cl/2811, which only applied to Darwin and GNU/Linux, to all Unix systems. Fixes #9591. Change-Id: Iec3fb438564ba2924b15b447c0480f87c0bfd009 Reviewed-on: https://go-review.googlesource.com/12661 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-22runtime: if we don't handle a signal on a non-Go thread, raise itIan Lance Taylor
In the past badsignal would crash the program. In https://golang.org/cl/10757044 badsignal was changed to call sigsend, to fix issue #3250. The effect of this was that when a non-Go thread received a signal, and os/signal.Notify was not being used to check for occurrences of the signal, the signal was ignored. This changes the code so that if os/signal.Notify is not being used, then the signal handler is reset to what it was, and the signal is raised again. This lets non-Go threads handle the signal as they wish. In particular, it means that a segmentation violation in a non-Go thread will ordinarily crash the process, as it should. Fixes #10139. Update #11794. Change-Id: I2109444aaada9d963ad03b1d071ec667760515e5 Reviewed-on: https://go-review.googlesource.com/12503 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2015-04-14runtime: rename close to closefdDavid Crawshaw
Avoids shadowing the builtin channel close function. Change-Id: I7a729b0937c8248fe27222be61318a88db995eee Reviewed-on: https://go-review.googlesource.com/8898 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: David Crawshaw <crawshaw@golang.org>
2015-03-05cmd/internal/ld, runtime: halve tlsoffset on ELF/intelMichael Hudson-Doyle
For OSes that use elf on intel, 2*Ptrsize bytes are reserved for TLS. But only one pointer (g) has been stored in the TLS for a while now. So we can set it to just Ptrsize, which happily matches what happens when externally linking. Fixes #9913 Change-Id: Ic816369d3a55a8cdcc23be349b1a1791d53f5f81 Reviewed-on: https://go-review.googlesource.com/6584 Run-TryBot: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-03runtime: Update open/close/read/write to return -1 on error.Keith Randall
Error detection code copied from syscall, where presumably we actually do it right. Note that we throw the errno away. The runtime doesn't use it. Fixes #10052 Change-Id: I8de77dda6bf287276b137646c26b84fa61554ec8 Reviewed-on: https://go-review.googlesource.com/6571 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-02runtime: eliminate uses of BP on amd64Austin Clements
Any place that clobbers BP in the runtime can potentially interfere with frame pointer unwinding with GOEXPERIMENT=framepointer. This change eliminates uses of BP in the runtime to address this problem. We have spare registers everywhere this occurs, so there's no downside to eliminating BP. Where possible, this uses the same new register as the amd64p32 runtime, which doesn't use BP due to restrictions placed on it by NaCL. One nice side effect of this is that it will let perf/VTune unwind the call stack even through a call to systemstack, which will let us get really good call graphs from the garbage collector. Change-Id: I0ffa14cb4dd2b613a7049b8ec59df37c52286212 Reviewed-on: https://go-review.googlesource.com/3390 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-18runtime, syscall: use SYSCALL instruction on FreeBSD.Bill Thiede
This manually reverts 555da73 from #6372 which implies a minimum FreeBSD version of 8-STABLE. Updates docs to mention new minimum requirement. Fixes #9627 Change-Id: I40ae64be3682d79dd55024e32581e3e5e2be8aa7 Reviewed-on: https://go-review.googlesource.com/3020 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-11-11[dev.cc] runtime: convert assembly files for C to Go transitionRuss Cox
The main change is that #include "zasm_GOOS_GOARCH.h" is now #include "go_asm.h" and/or #include "go_tls.h". Also, because C StackGuard is now Go _StackGuard, the assembly name changes from const_StackGuard to const__StackGuard. In asm_$GOARCH.s, add new function getg, formerly implemented in C. The renamed atomics now have Go wrappers, to get escape analysis annotations right. Those wrappers are in CL 174860043. LGTM=r, aram R=r, aram CC=austin, dvyukov, golang-codereviews, iant, khr https://golang.org/cl/168510043
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.