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.
6 The runtime package contains operations that interact with Go's runtime system,
7 such as functions to control goroutines. It also includes the low-level type information
8 used by the reflect package; see reflect's documentation for the programmable
9 interface to the run-time type system.
13 // Gosched yields the processor, allowing other goroutines to run. It does not
14 // suspend the current goroutine, so execution resumes automatically.
17 // Goexit terminates the goroutine that calls it. No other goroutine is affected.
18 // Goexit runs all deferred calls before terminating the goroutine.
21 // Caller reports file and line number information about function invocations on
22 // the calling goroutine's stack. The argument skip is the number of stack frames to
23 // ascend, with 0 identifying the the caller of Caller. The return values report the
24 // program counter, file name, and line number within the file of the corresponding
25 // call. The boolean ok is false if it was not possible to recover the information.
26 func Caller(skip int) (pc uintptr, file string, line int, ok bool)
28 // Callers fills the slice pc with the program counters of function invocations
29 // on the calling goroutine's stack. The argument skip is the number of stack frames
30 // to skip before recording in pc, with 0 starting at the caller of Caller.
31 // It returns the number of entries written to pc.
32 func Callers(skip int, pc []uintptr) int
34 // FuncForPC returns a *Func describing the function that contains the
35 // given program counter address, or else nil.
36 func FuncForPC(pc uintptr) *Func
38 // NOTE(rsc): Func must match struct Func in runtime.h
40 // Func records information about a function in the program,
41 // in particular the mapping from program counters to source
42 // line numbers within that function.
56 // Name returns the name of the function.
57 func (f *Func) Name() string { return f.name }
59 // Entry returns the entry address of the function.
60 func (f *Func) Entry() uintptr { return f.entry }
62 // FileLine returns the file name and line number of the
63 // source code corresponding to the program counter pc.
64 // The result will not be accurate if pc is not a program
66 func (f *Func) FileLine(pc uintptr) (file string, line int) {
67 // NOTE(rsc): If you edit this function, also edit
68 // symtab.c:/^funcline.
69 var pcQuant uintptr = 1
79 for i := 0; i < len(p) && pc <= targetpc; i++ {
82 line += int(p[i+1]<<24) | int(p[i+2]<<16) | int(p[i+3]<<8) | int(p[i+4])
87 line -= int(p[i] - 64)
89 pc += pcQuant * uintptr(p[i]-129)
96 // mid returns the current os thread (m) id.
99 // Semacquire waits until *s > 0 and then atomically decrements it.
100 // It is intended as a simple sleep primitive for use by the synchronization
101 // library and should not be used directly.
102 func Semacquire(s *uint32)
104 // Semrelease atomically increments *s and notifies a waiting goroutine
105 // if one is blocked in Semacquire.
106 // It is intended as a simple wakeup primitive for use by the synchronization
107 // library and should not be used directly.
108 func Semrelease(s *uint32)
110 // SetFinalizer sets the finalizer associated with x to f.
111 // When the garbage collector finds an unreachable block
112 // with an associated finalizer, it clears the association and runs
113 // f(x) in a separate goroutine. This makes x reachable again, but
114 // now without an associated finalizer. Assuming that SetFinalizer
115 // is not called again, the next time the garbage collector sees
116 // that x is unreachable, it will free x.
118 // SetFinalizer(x, nil) clears any finalizer associated with x.
120 // The argument x must be a pointer to an object allocated by
121 // calling new or by taking the address of a composite literal.
122 // The argument f must be a function that takes a single argument
123 // of x's type and returns no arguments. If either of these is not
124 // true, SetFinalizer aborts the program.
126 // Finalizers are run in dependency order: if A points at B, both have
127 // finalizers, and they are otherwise unreachable, only the finalizer
128 // for A runs; once A is freed, the finalizer for B can run.
129 // If a cyclic structure includes a block with a finalizer, that
130 // cycle is not guaranteed to be garbage collected and the finalizer
131 // is not guaranteed to run, because there is no ordering that
132 // respects the dependencies.
134 // The finalizer for x is scheduled to run at some arbitrary time after
135 // x becomes unreachable.
136 // There is no guarantee that finalizers will run before a program exits,
137 // so typically they are useful only for releasing non-memory resources
138 // associated with an object during a long-running program.
139 // For example, an os.File object could use a finalizer to close the
140 // associated operating system file descriptor when a program discards
141 // an os.File without calling Close, but it would be a mistake
142 // to depend on a finalizer to flush an in-memory I/O buffer such as a
143 // bufio.Writer, because the buffer would not be flushed at program exit.
145 // A single goroutine runs all finalizers for a program, sequentially.
146 // If a finalizer must run for a long time, it should do so by starting
149 // TODO(rsc): allow f to have (ignored) return values
151 func SetFinalizer(x, f interface{})
153 func getgoroot() string
155 // GOROOT returns the root of the Go tree.
156 // It uses the GOROOT environment variable, if set,
157 // or else the root used during the Go build.
158 func GOROOT() string {
166 // Version returns the Go tree's version string.
167 // It is either a sequence number or, when possible,
168 // a release tag like "release.2010-03-04".
169 // A trailing + indicates that the tree had local modifications
170 // at the time of the build.
171 func Version() string {
175 // GOOS is the Go tree's operating system target:
176 // one of darwin, freebsd, linux, and so on.
177 const GOOS string = theGoos
179 // GOARCH is the Go tree's architecture target:
180 // 386, amd64, or arm.
181 const GOARCH string = theGoarch