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 5package runtime 6 7import ( 8 "runtime/internal/atomic" 9 _ "unsafe" // for go:linkname 10) 11 12//go:generate go run wincallback.go 13//go:generate go run mkduff.go 14//go:generate go run mkfastlog2table.go 15 16// For gccgo, while we still have C runtime code, use go:linkname to 17// export some functions. 18// 19//go:linkname tickspersecond 20 21var ticksLock mutex 22var ticksVal uint64 23 24// Note: Called by runtime/pprof in addition to runtime code. 25func tickspersecond() int64 { 26 r := int64(atomic.Load64(&ticksVal)) 27 if r != 0 { 28 return r 29 } 30 lock(&ticksLock) 31 r = int64(ticksVal) 32 if r == 0 { 33 t0 := nanotime() 34 c0 := cputicks() 35 usleep(100 * 1000) 36 t1 := nanotime() 37 c1 := cputicks() 38 if t1 == t0 { 39 t1++ 40 } 41 r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0) 42 if r == 0 { 43 r++ 44 } 45 atomic.Store64(&ticksVal, uint64(r)) 46 } 47 unlock(&ticksLock) 48 return r 49} 50 51var envs []string 52var argslice []string 53 54//go:linkname syscall_runtime_envs syscall.runtime_envs 55func syscall_runtime_envs() []string { return append([]string{}, envs...) } 56 57//go:linkname syscall_Getpagesize syscall.Getpagesize 58func syscall_Getpagesize() int { return int(physPageSize) } 59 60//go:linkname os_runtime_args os.runtime_args 61func os_runtime_args() []string { return append([]string{}, argslice...) } 62 63//go:linkname syscall_Exit syscall.Exit 64//go:nosplit 65func syscall_Exit(code int) { 66 exit(int32(code)) 67} 68 69// Temporary, for the gccgo runtime code written in C. 70//go:linkname get_envs runtime_get_envs 71func get_envs() []string { return envs } 72 73//go:linkname get_args runtime_get_args 74func get_args() []string { return argslice } 75