aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall.go
AgeCommit message (Collapse)Author
2022-10-18internal/godebug: remove dependency on osRuss Cox
The immediate reason is that we want to use godebug from math/rand, and math/rand importing godebug importing os causes an import cycle in package testing. More generally, the new approach to backward compatibility outlined in discussion #55090 will require using this package from other similarly sensitive places, perhaps even package os itself. Best to remove all dependencies. Preparation for #54880. Change-Id: Ia01657a2d90e707a8121a336c9db3b7247c0198f Reviewed-on: https://go-review.googlesource.com/c/go/+/439418 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-28syscall: optimize Byte{Ptr,Slice}FromStringKir Kolyshkin
Use bytealg.IndexByteString(str, 0) instead of looping through the string to check for a zero byte. A quick and dirty benchmark shows 10x performance improvement (on amd64 machine, using go 1.17.3). BytePtrFromString is used by many functions with string arguments. This change should make many functions in os package, such as those accepting a filename (os.Open, os.Stat, etc.), a tad faster. PS I am aware that syscall package is deprecated and frozen, but this change is mainly for the os package and the likes. The alternative would be for os to switch to x/sys, which is a much bigger change. Change-Id: I18fdd50f9fbfe0a23a4a71bc4bd0a5f5b0eaa475 Reviewed-on: https://go-review.googlesource.com/c/go/+/368457 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2020-12-10syscall: drop references to Unix epoch in Timeval/Timespec docsIan Lance Taylor
The various conversion functions just change the format of time values. They don't use the Unix epoch. Although in practice the values are often times since the Unix epoch, they aren't always, so referring to the epoch can be confusing. Fixes #43010 Change-Id: I640d665f0d2017f0974db05d70858037c7c91eda Reviewed-on: https://go-review.googlesource.com/c/go/+/277073 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-02syscall: switch go:generate directives back to mksyscall_windows.goBryan C. Mills
Adjust mksyscall_windows.go to activate module mode and set -mod=readonly, and to suppress its own deprecation warning when run from within GOROOT/src. We can't vendor the mkwinsyscall tool in to the std module directly, because std-vendored dependencies (unlike the dependencies of all other modules) turn into actual, distinct packages in 'std' when viewed from outside the 'std' module. We don't want to introduce a binary in the 'std' meta-pattern, but we also don't particularly want to add more special-cases to the 'go' command right now when we have an existing wrapper program that can do the job. I also regenerated the affected packages to ensure that they are consistent with the current version of mksyscall, which produced some declaration-order changes in internal/syscall/windows/zsyscall_windows.go. Fixes #41916 Updates #25922 Change-Id: If6e6f8ba3dd372a7ecd6820ee6c0ca38d55f0f35 Reviewed-on: https://go-review.googlesource.com/c/go/+/261499 Trust: Bryan C. Mills <bcmills@google.com> Trust: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-10-05syscall, internal/syscall/windows, internal/syscall/windows/registry: make ↵Alex Brainman
go generate use new golang.org/x/sys/windows/mkwinsyscall Updates #34388 Change-Id: I327a1c1557c47fa6c113c7a1a507a8e7355f9d1a Reviewed-on: https://go-review.googlesource.com/c/go/+/199277 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2018-08-02syscall: use deprecation convention in package comment, simplifyBrad Fitzpatrick
Change-Id: I612041d31c01d49135947796fe2a09db3e6894d4 Reviewed-on: https://go-review.googlesource.com/127657 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-27syscall: document Time{spec,val} methodsTobias Klauser
Add godoc comments for Time{spec,val} methods Unix and Nano. Change-Id: I285bbd236af588b30140db7182b05f8b202b5b0b Reviewed-on: https://go-review.googlesource.com/73271 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-27syscall: make Exit call runtime.exitAlex Brainman
syscall.Exit and runtime.exit do the same thing. Why duplicate code? CL 45115 fixed bug where windows runtime.exit was correct, but syscall.Exit was broken. So CL 45115 fixed windows syscall.Exit by calling runtime.exit. Austin suggested that all OSes should do the same, and this CL implements his idea. While making changes, I discovered that nacl syscall.Exit returned error func Exit(code int) (err error) and I changed it into func Exit(code int) like all other OSes. I assumed it was a mistake and it is OK to do because cmd/api does not complain about it. Also I changed plan9 runtime.exit to accept int32 just like all other OSes do. Change-Id: I12f6022ad81406566cf9befcc6edc382eebd413b Reviewed-on: https://go-review.googlesource.com/66170 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David du Colombier <0intro@gmail.com>
2017-04-05syscall: update comments for x/sys migrationLynn Boger
The comments in this package state that users should be migrating code that uses the syscall package to its corresponding package in x/sys. However, the syscall.Signal and syscall.Errno types and the syscall.SysProcAttr struct is not defined in the x/sys package and still need to be referenced from within syscall. This adds a change to the comments to clarify that the migration will need to continue to use some references to syscall for now. Fixes #19560 Change-Id: I8abb96b93bea90070ce461da16dc7bcf7b4b29c1 Reviewed-on: https://go-review.googlesource.com/39450 Reviewed-by: Rob Pike <r@golang.org>
2017-02-13syscall: delete the "use" function and calls in non-generated files.Sameer Ajmani
Delete use stub from asm.s, leaving only a dummy file. Deleting the file causes Windows build to fail. Fixes #16607 Change-Id: Ic5a55e042e588f1e1bc6605a3d309d1eabdeb288 Reviewed-on: https://go-review.googlesource.com/36716 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-09-06syscall: make Getpagesize return page size from runtimeAustin Clements
syscall.Getpagesize currently returns hard-coded page sizes on all architectures (some of which are probably always wrong, and some of which are definitely not always right). The runtime now has this information, queried from the OS during runtime init, so make syscall.Getpagesize return the page size that the runtime knows. Updates #10180. Change-Id: I4daa6fbc61a2193eb8fa9e7878960971205ac346 Reviewed-on: https://go-review.googlesource.com/25051 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-24syscall, internal/syscall/windows, internal/syscall/windows/registry: make ↵Alex Brainman
go generate work on every os Fixes #16368 Change-Id: I2ef7a2deb5798e11cc1d3f8ca29a6e1655155422 Reviewed-on: https://go-review.googlesource.com/27411 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-14cmd/compile: recognize Syscall-like functions for liveness analysisRuss Cox
Consider this code: func f(*int) func g() { p := new(int) f(p) } where f is an assembly function. In general liveness analysis assumes that during the call to f, p is dead in this frame. If f has retained p, p will be found alive in f's frame and keep the new(int) from being garbage collected. This is all correct and works. We use the Go func declaration for f to give the assembly function liveness information (the arguments are assumed live for the entire call). Now consider this code: func h1() { p := new(int) syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p))) } Here syscall.Syscall is taking the place of f, but because its arguments are uintptr, the liveness analysis and the garbage collector ignore them. Since p is no longer live in h once the call starts, if the garbage collector scans the stack while the system call is blocked, it will find no reference to the new(int) and reclaim it. If the kernel is going to write to *p once the call finishes, reclaiming the memory is a mistake. We can't change the arguments or the liveness information for syscall.Syscall itself, both for compatibility and because sometimes the arguments really are integers, and the garbage collector will get quite upset if it finds an integer where it expects a pointer. The problem is that these arguments are fundamentally untyped. The solution we have taken in the syscall package's wrappers in past releases is to insert a call to a dummy function named "use", to make it look like the argument is live during the call to syscall.Syscall: func h2() { p := new(int) syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p))) use(unsafe.Pointer(p)) } Keeping p alive during the call means that if the garbage collector scans the stack during the system call now, it will find the reference to p. Unfortunately, this approach is not available to users outside syscall, because 'use' is unexported, and people also have to realize they need to use it and do so. There is much existing code using syscall.Syscall without a 'use'-like function. That code will fail very occasionally in mysterious ways (see #13372). This CL fixes all that existing code by making the compiler do the right thing automatically, without any code modifications. That is, it takes h1 above, which is incorrect code today, and makes it correct code. Specifically, if the compiler sees a foreign func definition (one without a body) that has uintptr arguments, it marks those arguments as "unsafe uintptrs". If it later sees the function being called with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x as having escaped, and it makes sure to hold x in a live temporary variable until the call returns, so that the garbage collector cannot reclaim whatever heap memory x points to. For now I am leaving the explicit calls to use in package syscall, but they can be removed early in a future cycle (likely Go 1.7). The rule has no effect on escape analysis, only on liveness analysis. Fixes #13372. Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500 Reviewed-on: https://go-review.googlesource.com/18584 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-18all: switch to the new deprecation conventionShenghou Ma
While we're at it, move some misplaced comment blocks around. Change-Id: I1847d7f1ca1dbb8e5de737203c4ed6c66e112508 Reviewed-on: https://go-review.googlesource.com/10188 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-22syscall: update go.sys doc reference to golang.org/x/sysJoe Shaw
Change-Id: Ie5a36dbcd809fc165f4198d47641d5a95878460c Reviewed-on: https://go-review.googlesource.com/2000 Reviewed-by: Russ Cox <rsc@golang.org>
2014-09-08syscall: keep allocated C string live across call to SyscallRuss Cox
Given: p := alloc() fn_taking_ptr(p) p is NOT recorded as live at the call to fn_taking_ptr: it's not needed by the code following the call. p was passed to fn_taking_ptr, and fn_taking_ptr must keep it alive as long as it needs it. In practice, fn_taking_ptr will keep its own arguments live for as long as the function is executing. But if instead you have: p := alloc() i := uintptr(unsafe.Pointer(p)) fn_taking_int(i) p is STILL NOT recorded as live at the call to fn_taking_int: it's not needed by the code following the call. fn_taking_int is responsible for keeping its own arguments live, but fn_taking_int is written to take an integer, so even though fn_taking_int does keep its argument live, that argument does not keep the allocated memory live, because the garbage collector does not dereference integers. The shorter form: p := alloc() fn_taking_int(uintptr(unsafe.Pointer(p))) and the even shorter form: fn_taking_int(uintptr(unsafe.Pointer(alloc()))) are both the same as the 3-line form above. syscall.Syscall is like fn_taking_int: it is written to take a list of integers, and yet those integers are sometimes pointers. If there is no other copy of those pointers being kept live, the memory they point at may be garbage collected during the call to syscall.Syscall. This is happening on Solaris: for whatever reason, the timing is such that the garbage collector manages to free the string argument to the open(2) system call before the system call has been invoked. Change the system call wrappers to insert explicit references that will keep the allocations alive in the original frame (and therefore preserve the memory) until after syscall.Syscall has returned. Should fix Solaris flakiness. This is not a problem for cgo, because cgo wrappers have correctly typed arguments. LGTM=iant, khr, aram, rlh R=iant, khr, bradfitz, aram, rlh CC=dvyukov, golang-codereviews, r https://golang.org/cl/139360044
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.
2008-09-26move src/syscall to src/lib/syscall.Russ Cox
enforce rule: all kernel data structures and constants go in syscall module. move things that should be in syscall out of net. make net a single package. R=r OCL=15985 CL=15994
2008-09-17time & date.Russ Cox
rename AddrToInt, StatToInt, etc -> BytePtr, StatPtr, ... R=r OCL=15450 CL=15456
2008-09-16preliminary network - just Dial for nowRuss Cox
R=r,presotto OCL=15393 CL=15399
2008-09-11make syscall use strings for file namesRob Pike
tweak os to adjust move StringToBytes into syscall, at least for now this program still works: package main import os "os" func main() { os.Stdout.WriteString("hello, world\n"); a, b := os.NewFD(77).WriteString("no way"); os.Stdout.WriteString(b.String() + "\n"); } R=rsc DELTA=263 (59 added, 176 deleted, 28 changed) OCL=15153 CL=15153
2008-08-04- switched most of existing Go code to new export syntaxRobert Griesemer
- adjusted lang doc R=r DELTA=192 (26 added, 65 deleted, 101 changed) OCL=13844 CL=13848
2008-07-29fix a commentRob Pike
fix a register name R=gri OCL=13548 CL=13548
2008-07-29rewrite system call interface to use less assembler.Rob Pike
R=gri OCL=13546 CL=13546
2008-07-28add lstatRob Pike
clean up some code fix comments add paramter names to interface R=ken OCL=13521 CL=13521
2008-07-26add fstat, statRob Pike
R=ken OCL=13497 CL=13497
2008-07-26beginnings of a low-level syscall libraryRob Pike
R=ken OCL=13483 CL=13496