// 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 tickspersecond() 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 syscall_runtime_envs() []string { return append([]string{}, envs...) }

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

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

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

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

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

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

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

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

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