1// Copyright 2009 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5// Package syscall contains an interface to the low-level operating system 6// primitives. The details vary depending on the underlying system, and 7// by default, godoc will display the syscall documentation for the current 8// system. If you want godoc to display syscall documentation for another 9// system, set $GOOS and $GOARCH to the desired system. For example, if 10// you want to view documentation for freebsd/arm on linux/amd64, set $GOOS 11// to freebsd and $GOARCH to arm. 12// The primary use of syscall is inside other packages that provide a more 13// portable interface to the system, such as "os", "time" and "net". Use 14// those packages rather than this one if you can. 15// For details of the functions and data types in this package consult 16// the manuals for the appropriate operating system. 17// These calls return err == nil to indicate success; otherwise 18// err is an operating system error describing the failure. 19// On most systems, that error has type [Errno]. 20// 21// NOTE: Most of the functions, types, and constants defined in 22// this package are also available in the [golang.org/x/sys] package. 23// That package has more system call support than this one, 24// and most new code should prefer that package where possible. 25// See https://golang.org/s/go1.4-syscall for more information. 26package syscall 27 28import "internal/bytealg" 29 30//go:generate go run ./mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go 31 32// StringByteSlice converts a string to a NUL-terminated []byte, 33// If s contains a NUL byte this function panics instead of 34// returning an error. 35// 36// Deprecated: Use ByteSliceFromString instead. 37func StringByteSlice(s string) []byte { 38 a, err := ByteSliceFromString(s) 39 if err != nil { 40 panic("syscall: string with NUL passed to StringByteSlice") 41 } 42 return a 43} 44 45// ByteSliceFromString returns a NUL-terminated slice of bytes 46// containing the text of s. If s contains a NUL byte at any 47// location, it returns (nil, [EINVAL]). 48func ByteSliceFromString(s string) ([]byte, error) { 49 if bytealg.IndexByteString(s, 0) != -1 { 50 return nil, EINVAL 51 } 52 a := make([]byte, len(s)+1) 53 copy(a, s) 54 return a, nil 55} 56 57// StringBytePtr returns a pointer to a NUL-terminated array of bytes. 58// If s contains a NUL byte this function panics instead of returning 59// an error. 60// 61// Deprecated: Use [BytePtrFromString] instead. 62func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] } 63 64// BytePtrFromString returns a pointer to a NUL-terminated array of 65// bytes containing the text of s. If s contains a NUL byte at any 66// location, it returns (nil, [EINVAL]). 67func BytePtrFromString(s string) (*byte, error) { 68 a, err := ByteSliceFromString(s) 69 if err != nil { 70 return nil, err 71 } 72 return &a[0], nil 73} 74 75// Single-word zero for use when we need a valid pointer to 0 bytes. 76// See mksyscall.pl. 77var _zero uintptr 78 79// Unix returns the time stored in ts as seconds plus nanoseconds. 80func (ts *Timespec) Unix() (sec int64, nsec int64) { 81 return int64(ts.Sec), int64(ts.Nsec) 82} 83 84// Unix returns the time stored in tv as seconds plus nanoseconds. 85func (tv *Timeval) Unix() (sec int64, nsec int64) { 86 return int64(tv.Sec), int64(tv.Usec) * 1000 87} 88 89// Nano returns the time stored in ts as nanoseconds. 90func (ts *Timespec) Nano() int64 { 91 return int64(ts.Sec)*1e9 + int64(ts.Nsec) 92} 93 94// Nano returns the time stored in tv as nanoseconds. 95func (tv *Timeval) Nano() int64 { 96 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 97} 98 99// Getpagesize and Exit are provided by the runtime. 100 101func Getpagesize() int 102func Exit(code int) 103 104// runtimeSetenv and runtimeUnsetenv are provided by the runtime. 105func runtimeSetenv(k, v string) 106func runtimeUnsetenv(k string) 107