snapshot: sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1
Содержимое пина, зафиксированного в go.mod sing-box-lx, одним коммитом без истории. Полная история SagerNet/gvisor — 1.45 ГБ и клонируется в каждой CI-джобе; наша дельта — одна вставка в одну функцию, история для неё не нужна. Module path github.com/sagernet/gvisor сохранён намеренно: на него опирается replace-директива суперпроекта. Патч поверх — отдельным коммитом, чтобы дельта читалась одним git show и переносилась на новый пин копированием. SPECS/TASKS/048-GVISOR_HANDSHAKE_NIL_CRASH
This commit is contained in:
commit
2c4ae3b0a4
712 changed files with 185689 additions and 0 deletions
82
pkg/gomaxprocs/gomaxprocs.go
Normal file
82
pkg/gomaxprocs/gomaxprocs.go
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// Copyright 2025 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 gomaxprocs synchronizes adjustments to GOMAXPROCS. When this package
|
||||
// is active (i.e. after the first call to SetBase), it sets the value of
|
||||
// GOMAXPROCS to a "base" value (which should be set by a single goroutine,
|
||||
// without races) plus a non-negative "temporary" value (which may be
|
||||
// concurrently increased or decreased by multiple goroutines).
|
||||
//
|
||||
// Note that changing GOMAXPROCS stops the world, so callers should adjust
|
||||
// GOMAXPROCS infrequently.
|
||||
//
|
||||
// TODO: Add gomaxprocs.Get() and check that other gVisor packages don't call
|
||||
// runtime.GOMAXPROCS() at all.
|
||||
package gomaxprocs
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/sagernet/gvisor/pkg/log"
|
||||
)
|
||||
|
||||
var (
|
||||
mu gomaxprocsMutex
|
||||
// +checklocks:mu
|
||||
base int
|
||||
// +checklocks:mu
|
||||
temp int
|
||||
)
|
||||
|
||||
// SetBase sets base GOMAXPROCS.
|
||||
func SetBase(n int) {
|
||||
if n < 1 {
|
||||
log.Traceback("Invalid base GOMAXPROCS: %d", n)
|
||||
return
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
oldBase := base
|
||||
base = n
|
||||
updateRuntime(oldBase, temp)
|
||||
}
|
||||
|
||||
// Add adds n temporary GOMAXPROCS. n may be negative; callers should call Add
|
||||
// with negative n to remove temporary GOMAXPROCS when they are no longer
|
||||
// needed.
|
||||
func Add(n int) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
t := temp + n
|
||||
if t < 0 {
|
||||
log.Traceback("gomaxprocs.Add(%d) would cause temp to become %d", n, t)
|
||||
return
|
||||
}
|
||||
oldTemp := temp
|
||||
temp = t
|
||||
if base != 0 {
|
||||
updateRuntime(base, oldTemp)
|
||||
}
|
||||
}
|
||||
|
||||
// +checklocks:mu
|
||||
func updateRuntime(oldBase, oldTemp int) {
|
||||
n := base + temp
|
||||
log.Debugf("Setting GOMAXPROCS to %d", n)
|
||||
got := runtime.GOMAXPROCS(n)
|
||||
if want := oldBase + oldTemp; oldBase != 0 && got != want {
|
||||
// Something changed GOMAXPROCS outside of our control.
|
||||
log.Warningf("Previous GOMAXPROCS was %d, expected %d = %d + %d", got, want, oldBase, oldTemp)
|
||||
}
|
||||
}
|
||||
64
pkg/gomaxprocs/gomaxprocs_mutex.go
Normal file
64
pkg/gomaxprocs/gomaxprocs_mutex.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package gomaxprocs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/sagernet/gvisor/pkg/sync"
|
||||
"github.com/sagernet/gvisor/pkg/sync/locking"
|
||||
)
|
||||
|
||||
// Mutex is sync.Mutex with the correctness validator.
|
||||
type gomaxprocsMutex struct {
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
var gomaxprocsprefixIndex *locking.MutexClass
|
||||
|
||||
// lockNames is a list of user-friendly lock names.
|
||||
// Populated in init.
|
||||
var gomaxprocslockNames []string
|
||||
|
||||
// lockNameIndex is used as an index passed to NestedLock and NestedUnlock,
|
||||
// referring to an index within lockNames.
|
||||
// Values are specified using the "consts" field of go_template_instance.
|
||||
type gomaxprocslockNameIndex int
|
||||
|
||||
// DO NOT REMOVE: The following function automatically replaced with lock index constants.
|
||||
// LOCK_NAME_INDEX_CONSTANTS
|
||||
const ()
|
||||
|
||||
// Lock locks m.
|
||||
// +checklocksignore
|
||||
func (m *gomaxprocsMutex) Lock() {
|
||||
locking.AddGLock(gomaxprocsprefixIndex, -1)
|
||||
m.mu.Lock()
|
||||
}
|
||||
|
||||
// NestedLock locks m knowing that another lock of the same type is held.
|
||||
// +checklocksignore
|
||||
func (m *gomaxprocsMutex) NestedLock(i gomaxprocslockNameIndex) {
|
||||
locking.AddGLock(gomaxprocsprefixIndex, int(i))
|
||||
m.mu.Lock()
|
||||
}
|
||||
|
||||
// Unlock unlocks m.
|
||||
// +checklocksignore
|
||||
func (m *gomaxprocsMutex) Unlock() {
|
||||
locking.DelGLock(gomaxprocsprefixIndex, -1)
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
// NestedUnlock unlocks m knowing that another lock of the same type is held.
|
||||
// +checklocksignore
|
||||
func (m *gomaxprocsMutex) NestedUnlock(i gomaxprocslockNameIndex) {
|
||||
locking.DelGLock(gomaxprocsprefixIndex, int(i))
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
// DO NOT REMOVE: The following function is automatically replaced.
|
||||
func gomaxprocsinitLockNames() {}
|
||||
|
||||
func init() {
|
||||
gomaxprocsinitLockNames()
|
||||
gomaxprocsprefixIndex = locking.NewMutexClass(reflect.TypeOf(gomaxprocsMutex{}), gomaxprocslockNames)
|
||||
}
|
||||
3
pkg/gomaxprocs/gomaxprocs_state_autogen.go
Normal file
3
pkg/gomaxprocs/gomaxprocs_state_autogen.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// automatically generated by stateify.
|
||||
|
||||
package gomaxprocs
|
||||
Loading…
Add table
Add a link
Reference in a new issue