github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/stubs.go (about)

     1  // Copyright 2014 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 runtime
     6  
     7  import "unsafe"
     8  
     9  // Declarations for runtime services implemented in C or assembly.
    10  
    11  const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
    12  const regSize = 4 << (^uintreg(0) >> 63) // unsafe.Sizeof(uintreg(0)) but an ideal const
    13  
    14  // Should be a built-in for unsafe.Pointer?
    15  //go:nosplit
    16  func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
    17  	return unsafe.Pointer(uintptr(p) + x)
    18  }
    19  
    20  // n must be a power of 2
    21  func roundup(p unsafe.Pointer, n uintptr) unsafe.Pointer {
    22  	delta := -uintptr(p) & (n - 1)
    23  	return unsafe.Pointer(uintptr(p) + delta)
    24  }
    25  
    26  // in runtime.c
    27  func getg() *g
    28  func acquirem() *m
    29  func releasem(mp *m)
    30  func gomcache() *mcache
    31  func readgstatus(*g) uint32 // proc.c
    32  
    33  // mcall switches from the g to the g0 stack and invokes fn(g),
    34  // where g is the goroutine that made the call.
    35  // mcall saves g's current PC/SP in g->sched so that it can be restored later.
    36  // It is up to fn to arrange for that later execution, typically by recording
    37  // g in a data structure, causing something to call ready(g) later.
    38  // mcall returns to the original goroutine g later, when g has been rescheduled.
    39  // fn must not return at all; typically it ends by calling schedule, to let the m
    40  // run other goroutines.
    41  //
    42  // mcall can only be called from g stacks (not g0, not gsignal).
    43  //go:noescape
    44  func mcall(fn func(*g))
    45  
    46  // onM switches from the g to the g0 stack and invokes fn().
    47  // When fn returns, onM switches back to the g and returns,
    48  // continuing execution on the g stack.
    49  // If arguments must be passed to fn, they can be written to
    50  // g->m->ptrarg (pointers) and g->m->scalararg (non-pointers)
    51  // before the call and then consulted during fn.
    52  // Similarly, fn can pass return values back in those locations.
    53  // If fn is written in Go, it can be a closure, which avoids the need for
    54  // ptrarg and scalararg entirely.
    55  // After reading values out of ptrarg and scalararg it is conventional
    56  // to zero them to avoid (memory or information) leaks.
    57  //
    58  // If onM is called from a g0 stack, it invokes fn and returns,
    59  // without any stack switches.
    60  //
    61  // If onM is called from a gsignal stack, it crashes the program.
    62  // The implication is that functions used in signal handlers must
    63  // not use onM.
    64  //
    65  // NOTE(rsc): We could introduce a separate onMsignal that is
    66  // like onM but if called from a gsignal stack would just run fn on
    67  // that stack. The caller of onMsignal would be required to save the
    68  // old values of ptrarg/scalararg and restore them when the call
    69  // was finished, in case the signal interrupted an onM sequence
    70  // in progress on the g or g0 stacks. Until there is a clear need for this,
    71  // we just reject onM in signal handling contexts entirely.
    72  //
    73  //go:noescape
    74  func onM(fn func())
    75  
    76  // onMsignal is like onM but is allowed to be used in code that
    77  // might run on the gsignal stack. Code running on a signal stack
    78  // may be interrupting an onM sequence on the main stack, so
    79  // if the onMsignal calling sequence writes to ptrarg/scalararg,
    80  // it must first save the old values and then restore them when
    81  // finished. As an exception to the rule, it is fine not to save and
    82  // restore the values if the program is trying to crash rather than
    83  // return from the signal handler.
    84  // Once all the runtime is written in Go, there will be no ptrarg/scalararg
    85  // and the distinction between onM and onMsignal (and perhaps mcall)
    86  // can go away.
    87  //
    88  // If onMsignal is called from a gsignal stack, it invokes fn directly,
    89  // without a stack switch. Otherwise onMsignal behaves like onM.
    90  //
    91  //go:noescape
    92  func onM_signalok(fn func())
    93  
    94  func badonm() {
    95  	gothrow("onM called from signal goroutine")
    96  }
    97  
    98  // C functions that run on the M stack.
    99  // Call using mcall.
   100  func gosched_m(*g)
   101  func park_m(*g)
   102  func recovery_m(*g)
   103  
   104  // More C functions that run on the M stack.
   105  // Call using onM.
   106  func mcacheRefill_m()
   107  func largeAlloc_m()
   108  func gc_m()
   109  func scavenge_m()
   110  func setFinalizer_m()
   111  func removeFinalizer_m()
   112  func markallocated_m()
   113  func unrollgcprog_m()
   114  func unrollgcproginplace_m()
   115  func setgcpercent_m()
   116  func setmaxthreads_m()
   117  func ready_m()
   118  func deferproc_m()
   119  func goexit_m()
   120  func startpanic_m()
   121  func dopanic_m()
   122  func readmemstats_m()
   123  func writeheapdump_m()
   124  
   125  // memclr clears n bytes starting at ptr.
   126  // in memclr_*.s
   127  //go:noescape
   128  func memclr(ptr unsafe.Pointer, n uintptr)
   129  
   130  // memmove copies n bytes from "from" to "to".
   131  // in memmove_*.s
   132  //go:noescape
   133  func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)
   134  
   135  func starttheworld()
   136  func stoptheworld()
   137  func newextram()
   138  func lockOSThread()
   139  func unlockOSThread()
   140  
   141  // exported value for testing
   142  var hashLoad = loadFactor
   143  
   144  // in asm_*.s
   145  func fastrand1() uint32
   146  
   147  // in asm_*.s
   148  //go:noescape
   149  func memeq(a, b unsafe.Pointer, size uintptr) bool
   150  
   151  // noescape hides a pointer from escape analysis.  noescape is
   152  // the identity function but escape analysis doesn't think the
   153  // output depends on the input.  noescape is inlined and currently
   154  // compiles down to a single xor instruction.
   155  // USE CAREFULLY!
   156  //go:nosplit
   157  func noescape(p unsafe.Pointer) unsafe.Pointer {
   158  	x := uintptr(p)
   159  	return unsafe.Pointer(x ^ 0)
   160  }
   161  
   162  func entersyscall()
   163  func reentersyscall(pc uintptr, sp unsafe.Pointer)
   164  func entersyscallblock()
   165  func exitsyscall()
   166  
   167  func cgocallback(fn, frame unsafe.Pointer, framesize uintptr)
   168  func gogo(buf *gobuf)
   169  func gosave(buf *gobuf)
   170  func read(fd int32, p unsafe.Pointer, n int32) int32
   171  func close(fd int32) int32
   172  func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
   173  
   174  //go:noescape
   175  func jmpdefer(fv *funcval, argp uintptr)
   176  func exit1(code int32)
   177  func asminit()
   178  func setg(gg *g)
   179  func exit(code int32)
   180  func breakpoint()
   181  func nanotime() int64
   182  func usleep(usec uint32)
   183  
   184  // careful: cputicks is not guaranteed to be monotonic!  In particular, we have
   185  // noticed drift between cpus on certain os/arch combinations.  See issue 8976.
   186  func cputicks() int64
   187  
   188  func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer
   189  func munmap(addr unsafe.Pointer, n uintptr)
   190  func madvise(addr unsafe.Pointer, n uintptr, flags int32)
   191  func reflectcall(fn, arg unsafe.Pointer, n uint32, retoffset uint32)
   192  func osyield()
   193  func procyield(cycles uint32)
   194  func cgocallback_gofunc(fv *funcval, frame unsafe.Pointer, framesize uintptr)
   195  func readgogc() int32
   196  func purgecachedstats(c *mcache)
   197  func gostringnocopy(b *byte) string
   198  func goexit()
   199  
   200  //go:noescape
   201  func write(fd uintptr, p unsafe.Pointer, n int32) int32
   202  
   203  //go:noescape
   204  func cas(ptr *uint32, old, new uint32) bool
   205  
   206  //go:noescape
   207  func casp(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool
   208  
   209  //go:noescape
   210  func casuintptr(ptr *uintptr, old, new uintptr) bool
   211  
   212  //go:noescape
   213  func atomicstoreuintptr(ptr *uintptr, new uintptr)
   214  
   215  //go:noescape
   216  func atomicloaduintptr(ptr *uintptr) uintptr
   217  
   218  //go:noescape
   219  func atomicloaduint(ptr *uint) uint
   220  
   221  //go:noescape
   222  func setcallerpc(argp unsafe.Pointer, pc uintptr)
   223  
   224  //go:noescape
   225  func getcallerpc(argp unsafe.Pointer) uintptr
   226  
   227  //go:noescape
   228  func getcallersp(argp unsafe.Pointer) uintptr
   229  
   230  //go:noescape
   231  func asmcgocall(fn, arg unsafe.Pointer)
   232  
   233  //go:noescape
   234  func asmcgocall_errno(fn, arg unsafe.Pointer) int32
   235  
   236  //go:noescape
   237  func open(name *byte, mode, perm int32) int32
   238  
   239  //go:noescape
   240  func gotraceback(*bool) int32
   241  
   242  const _NoArgs = ^uintptr(0)
   243  
   244  func newstack()
   245  func newproc()
   246  func morestack()
   247  func mstart()
   248  func rt0_go()
   249  
   250  // return0 is a stub used to return 0 from deferproc.
   251  // It is called at the very end of deferproc to signal
   252  // the calling Go function that it should not jump
   253  // to deferreturn.
   254  // in asm_*.s
   255  func return0()
   256  
   257  // thunk to call time.now.
   258  func timenow() (sec int64, nsec int32)
   259  
   260  // in asm_*.s
   261  // not called directly; definitions here supply type information for traceback.
   262  func call16(fn, arg unsafe.Pointer, n, retoffset uint32)
   263  func call32(fn, arg unsafe.Pointer, n, retoffset uint32)
   264  func call64(fn, arg unsafe.Pointer, n, retoffset uint32)
   265  func call128(fn, arg unsafe.Pointer, n, retoffset uint32)
   266  func call256(fn, arg unsafe.Pointer, n, retoffset uint32)
   267  func call512(fn, arg unsafe.Pointer, n, retoffset uint32)
   268  func call1024(fn, arg unsafe.Pointer, n, retoffset uint32)
   269  func call2048(fn, arg unsafe.Pointer, n, retoffset uint32)
   270  func call4096(fn, arg unsafe.Pointer, n, retoffset uint32)
   271  func call8192(fn, arg unsafe.Pointer, n, retoffset uint32)
   272  func call16384(fn, arg unsafe.Pointer, n, retoffset uint32)
   273  func call32768(fn, arg unsafe.Pointer, n, retoffset uint32)
   274  func call65536(fn, arg unsafe.Pointer, n, retoffset uint32)
   275  func call131072(fn, arg unsafe.Pointer, n, retoffset uint32)
   276  func call262144(fn, arg unsafe.Pointer, n, retoffset uint32)
   277  func call524288(fn, arg unsafe.Pointer, n, retoffset uint32)
   278  func call1048576(fn, arg unsafe.Pointer, n, retoffset uint32)
   279  func call2097152(fn, arg unsafe.Pointer, n, retoffset uint32)
   280  func call4194304(fn, arg unsafe.Pointer, n, retoffset uint32)
   281  func call8388608(fn, arg unsafe.Pointer, n, retoffset uint32)
   282  func call16777216(fn, arg unsafe.Pointer, n, retoffset uint32)
   283  func call33554432(fn, arg unsafe.Pointer, n, retoffset uint32)
   284  func call67108864(fn, arg unsafe.Pointer, n, retoffset uint32)
   285  func call134217728(fn, arg unsafe.Pointer, n, retoffset uint32)
   286  func call268435456(fn, arg unsafe.Pointer, n, retoffset uint32)
   287  func call536870912(fn, arg unsafe.Pointer, n, retoffset uint32)
   288  func call1073741824(fn, arg unsafe.Pointer, n, retoffset uint32)