github.com/primecitizens/pcz/std@v0.2.1/runtime/public.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package runtime 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/arch" 8 "github.com/primecitizens/pcz/std/core/os" 9 ) 10 11 const ( 12 // GOOS is the running program's operating system target: 13 // one of darwin, freebsd, linux, and so on. 14 // To view possible combinations of GOOS and GOARCH, run "go tool dist list". 15 GOOS string = os.GOOS 16 17 // GOARCH is the running program's architecture target: 18 // one of 386, amd64, arm, s390x, and so on. 19 GOARCH string = arch.GOARCH 20 ) 21 22 // Version returns the Go tree's version string. 23 // It is either the commit hash and date at the time of the build or, 24 // when possible, a release tag like "go1.3". 25 // 26 // If any GOEXPERIMENTs are set to non-default values, it will include 27 // "X:<GOEXPERIMENT>". 28 func Version() string { 29 return buildVersion 30 } 31 32 // GOROOT returns the root used during the Go build. 33 func GOROOT() string { 34 return defaultGOROOT 35 } 36 37 // GOARM returns the GOARM environ used to build this application. 38 func GOARM() uint8 { 39 return goarm 40 } 41 42 // GOMAXPROCS returns 1. 43 func GOMAXPROCS(int) int { 44 return 1 45 } 46 47 // Mark KeepAlive as noinline so that it is easily detectable as an intrinsic. 48 // 49 //go:noinline 50 51 // KeepAlive marks its argument as currently reachable. 52 // This ensures that the object is not freed, and its finalizer is not run, 53 // before the point in the program where KeepAlive is called. 54 // 55 // A very simplified example showing where KeepAlive is required: 56 // 57 // type File struct { d int } 58 // d, err := syscall.Open("/file/path", syscall.O_RDONLY, 0) 59 // // ... do something if err != nil ... 60 // p := &File{d} 61 // runtime.SetFinalizer(p, func(p *File) { syscall.Close(p.d) }) 62 // var buf [10]byte 63 // n, err := syscall.Read(p.d, buf[:]) 64 // // Ensure p is not finalized until Read returns. 65 // runtime.KeepAlive(p) 66 // // No more uses of p after this point. 67 // 68 // Without the KeepAlive call, the finalizer could run at the start of 69 // syscall.Read, closing the file descriptor before syscall.Read makes 70 // the actual system call. 71 // 72 // Note: KeepAlive should only be used to prevent finalizers from 73 // running prematurely. In particular, when used with unsafe.Pointer, 74 // the rules for valid uses of unsafe.Pointer still apply. 75 func KeepAlive(x any) { 76 // TODO 77 }