// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package runtime

import (
	
	
)

//go:generate go run wincallback.go
//go:generate go run mkduff.go
//go:generate go run mkfastlog2table.go
//go:generate go run mklockrank.go -o lockrank.go

var ticks ticksType

type ticksType struct {
	lock mutex
	val  atomic.Int64
}

// Note: Called by runtime/pprof in addition to runtime code.
func () int64 {
	 := ticks.val.Load()
	if  != 0 {
		return 
	}
	lock(&ticks.lock)
	 = ticks.val.Load()
	if  == 0 {
		 := nanotime()
		 := cputicks()
		usleep(100 * 1000)
		 := nanotime()
		 := cputicks()
		if  ==  {
			++
		}
		 = ( - ) * 1000 * 1000 * 1000 / ( - )
		if  == 0 {
			++
		}
		ticks.val.Store()
	}
	unlock(&ticks.lock)
	return 
}

var envs []string
var argslice []string

//go:linkname syscall_runtime_envs syscall.runtime_envs
func () []string { return append([]string{}, envs...) }

//go:linkname syscall_Getpagesize syscall.Getpagesize
func () int { return int(physPageSize) }

//go:linkname os_runtime_args os.runtime_args
func () []string { return append([]string{}, argslice...) }

//go:linkname syscall_Exit syscall.Exit
//go:nosplit
func ( int) {
	exit(int32())
}

var godebugDefault string
var godebugUpdate atomic.Pointer[func(string, string)]
var godebugEnv atomic.Pointer[string] // set by parsedebugvars
var godebugNewIncNonDefault atomic.Pointer[func(string) func()]

//go:linkname godebug_setUpdate internal/godebug.setUpdate
func ( func(string, string)) {
	 := new(func(string, string))
	* = 
	godebugUpdate.Store()
	godebugNotify(false)
}

//go:linkname godebug_setNewIncNonDefault internal/godebug.setNewIncNonDefault
func ( func(string) func()) {
	 := new(func(string) func())
	* = 
	godebugNewIncNonDefault.Store()
}

// A godebugInc provides access to internal/godebug's IncNonDefault function
// for a given GODEBUG setting.
// Calls before internal/godebug registers itself are dropped on the floor.
type godebugInc struct {
	name string
	inc  atomic.Pointer[func()]
}

func ( *godebugInc) () {
	 := .inc.Load()
	if  == nil {
		 := godebugNewIncNonDefault.Load()
		if  == nil {
			return
		}
		// If other goroutines are racing here, no big deal. One will win,
		// and all the inc functions will be using the same underlying
		// *godebug.Setting.
		 = new(func())
		* = (*)(.name)
		.inc.Store()
	}
	(*)()
}

func ( bool) {
	 := godebugUpdate.Load()
	var  string
	if  := godebugEnv.Load();  != nil {
		 = *
	}
	if  {
		reparsedebugvars()
	}
	if  != nil {
		(*)(godebugDefault, )
	}
}

//go:linkname syscall_runtimeSetenv syscall.runtimeSetenv
func (,  string) {
	setenv_c(, )
	if  == "GODEBUG" {
		 := new(string)
		* = 
		godebugEnv.Store()
		godebugNotify(true)
	}
}

//go:linkname syscall_runtimeUnsetenv syscall.runtimeUnsetenv
func ( string) {
	unsetenv_c()
	if  == "GODEBUG" {
		godebugEnv.Store(nil)
		godebugNotify(true)
	}
}

// writeErrStr writes a string to descriptor 2.
//
//go:nosplit
func ( string) {
	write(2, unsafe.Pointer(unsafe.StringData()), int32(len()))
}

// auxv is populated on relevant platforms but defined here for all platforms
// so x/sys/cpu can assume the getAuxv symbol exists without keeping its list
// of auxv-using GOOS build tags in sync.
//
// It contains an even number of elements, (tag, value) pairs.
var auxv []uintptr

func () []uintptr { return auxv } // accessed from x/sys/cpu; see issue 57336