diff --git a/pkg/sync/BUILD b/pkg/sync/BUILD index ead9fc6ae..547f12c9f 100644 --- a/pkg/sync/BUILD +++ b/pkg/sync/BUILD @@ -28,6 +28,14 @@ arch_genrule( template = "runtime_spinning_impl_%s.s", ) +# Architecture-independent constants. +nogo_facts( + name = "runtime_constants_impl", + srcs = ["runtime.go"], + output = "runtime_constants_impl.go", + template = "runtime_constants.tmpl", +) + go_library( name = "sync", srcs = [ @@ -49,6 +57,7 @@ go_library( "rwmutex_unsafe.go", "seqcount.go", "sync.go", + ":runtime_constants_impl", ":runtime_spinning_impl_arch", ], marshal = False, diff --git a/pkg/sync/runtime_constants.tmpl b/pkg/sync/runtime_constants.tmpl new file mode 100644 index 000000000..f843d7fca --- /dev/null +++ b/pkg/sync/runtime_constants.tmpl @@ -0,0 +1,29 @@ +// Copyright 2023 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package sync + +// Values for the reason argument to gopark, from Go's src/runtime/runtime2.go. +const ( + WaitReasonSelect uint8 = {{ .import.runtime.Constants.waitReasonSelect }} + WaitReasonChanReceive uint8 = {{ .import.runtime.Constants.waitReasonChanReceive }} + WaitReasonSemacquire uint8 = {{ .import.runtime.Constants.waitReasonSemacquire }} +) + +// Values for the traceEv argument to gopark, from Go's src/runtime/trace.go. +const ( + TraceEvGoBlockRecv byte = {{ .import.runtime.Constants.traceEvGoBlockRecv }} + TraceEvGoBlockSelect byte = {{ .import.runtime.Constants.traceEvGoBlockSelect }} + TraceEvGoBlockSync byte = {{ .import.runtime.Constants.traceEvGoBlockSync }} +) diff --git a/pkg/sync/runtime_unsafe.go b/pkg/sync/runtime_unsafe.go index 05239282b..53ff41aca 100644 --- a/pkg/sync/runtime_unsafe.go +++ b/pkg/sync/runtime_unsafe.go @@ -78,20 +78,6 @@ func Goready(gp uintptr, traceskip int, wakep bool) { } } -// Values for the reason argument to gopark, from Go's src/runtime/runtime2.go. -const ( - WaitReasonSelect uint8 = 9 - WaitReasonChanReceive uint8 = 14 - WaitReasonSemacquire uint8 = 18 -) - -// Values for the traceEv argument to gopark, from Go's src/runtime/trace.go. -const ( - TraceEvGoBlockRecv byte = 23 - TraceEvGoBlockSelect byte = 24 - TraceEvGoBlockSync byte = 25 -) - // Rand32 returns a non-cryptographically-secure random uint32. func Rand32() uint32 { return fastrand()