aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/env_posix.go12
-rw-r--r--src/runtime/runtime.go28
-rw-r--r--src/runtime/runtime1.go6
3 files changed, 35 insertions, 11 deletions
diff --git a/src/runtime/env_posix.go b/src/runtime/env_posix.go
index 94a19d80d8..0eb4f0d7a3 100644
--- a/src/runtime/env_posix.go
+++ b/src/runtime/env_posix.go
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build unix || (js && wasm) || windows || plan9
-
package runtime
import "unsafe"
@@ -48,10 +46,7 @@ var _cgo_setenv unsafe.Pointer // pointer to C function
var _cgo_unsetenv unsafe.Pointer // pointer to C function
// Update the C environment if cgo is loaded.
-// Called from syscall.Setenv.
-//
-//go:linkname syscall_setenv_c syscall.setenv_c
-func syscall_setenv_c(k string, v string) {
+func setenv_c(k string, v string) {
if _cgo_setenv == nil {
return
}
@@ -60,10 +55,7 @@ func syscall_setenv_c(k string, v string) {
}
// Update the C environment if cgo is loaded.
-// Called from syscall.unsetenv.
-//
-//go:linkname syscall_unsetenv_c syscall.unsetenv_c
-func syscall_unsetenv_c(k string) {
+func unsetenv_c(k string) {
if _cgo_unsetenv == nil {
return
}
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go
index 50f68a327c..25b714de4e 100644
--- a/src/runtime/runtime.go
+++ b/src/runtime/runtime.go
@@ -65,3 +65,31 @@ func os_runtime_args() []string { return append([]string{}, argslice...) }
func syscall_Exit(code int) {
exit(int32(code))
}
+
+var godebugenv atomic.Pointer[string] // set by parsedebugvars
+
+//go:linkname godebug_getGODEBUG internal/godebug.getGODEBUG
+func godebug_getGODEBUG() string {
+ if p := godebugenv.Load(); p != nil {
+ return *p
+ }
+ return ""
+}
+
+//go:linkname syscall_runtimeSetenv syscall.runtimeSetenv
+func syscall_runtimeSetenv(key, value string) {
+ setenv_c(key, value)
+ if key == "GODEBUG" {
+ p := new(string)
+ *p = value
+ godebugenv.Store(p)
+ }
+}
+
+//go:linkname syscall_runtimeUnsetenv syscall.runtimeUnsetenv
+func syscall_runtimeUnsetenv(key string) {
+ unsetenv_c(key)
+ if key == "GODEBUG" {
+ godebugenv.Store(nil)
+ }
+}
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index b0a458d187..a29608329c 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -355,6 +355,8 @@ var dbgvars = []dbgVar{
{"adaptivestackstart", &debug.adaptivestackstart},
}
+var globalGODEBUG string
+
func parsedebugvars() {
// defaults
debug.cgocheck = 1
@@ -372,7 +374,9 @@ func parsedebugvars() {
debug.madvdontneed = 1
}
- for p := gogetenv("GODEBUG"); p != ""; {
+ globalGODEBUG = gogetenv("GODEBUG")
+ godebugenv.StoreNoWB(&globalGODEBUG)
+ for p := globalGODEBUG; p != ""; {
field := ""
i := bytealg.IndexByteString(p, ',')
if i < 0 {