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
92
pkg/tcpip/link/fdbased/mmap_unsafe.go
Normal file
92
pkg/tcpip/link/fdbased/mmap_unsafe.go
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
// Copyright 2019 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.
|
||||
|
||||
//go:build (linux && amd64) || (linux && arm64)
|
||||
// +build linux,amd64 linux,arm64
|
||||
|
||||
package fdbased
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/sagernet/gvisor/pkg/atomicbitops"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip/link/stopfd"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// tPacketHdrlen is the TPACKET_HDRLEN variable defined in <linux/if_packet.h>.
|
||||
var tPacketHdrlen = tPacketAlign(unsafe.Sizeof(tPacketHdr{}) + unsafe.Sizeof(unix.RawSockaddrLinklayer{}))
|
||||
|
||||
// tpStatus returns the frame status field.
|
||||
// The status is concurrently updated by the kernel as a result we must
|
||||
// use atomic operations to prevent races.
|
||||
func (t tPacketHdr) tpStatus() uint32 {
|
||||
hdr := unsafe.Pointer(&t[0])
|
||||
statusPtr := unsafe.Pointer(uintptr(hdr) + uintptr(tpStatusOffset))
|
||||
return (*atomicbitops.Uint32)(statusPtr).Load()
|
||||
}
|
||||
|
||||
// setTPStatus set's the frame status to the provided status.
|
||||
// The status is concurrently updated by the kernel as a result we must
|
||||
// use atomic operations to prevent races.
|
||||
func (t tPacketHdr) setTPStatus(status uint32) {
|
||||
hdr := unsafe.Pointer(&t[0])
|
||||
statusPtr := unsafe.Pointer(uintptr(hdr) + uintptr(tpStatusOffset))
|
||||
(*atomicbitops.Uint32)(statusPtr).Store(status)
|
||||
}
|
||||
|
||||
func newPacketMMapDispatcher(fd int, e *endpoint, opts *Options) (linkDispatcher, error) {
|
||||
stopFD, err := stopfd.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d := &packetMMapDispatcher{
|
||||
StopFD: stopFD,
|
||||
fd: fd,
|
||||
e: e,
|
||||
}
|
||||
pageSize := unix.Getpagesize()
|
||||
if tpBlockSize%pageSize != 0 {
|
||||
return nil, fmt.Errorf("tpBlockSize: %d is not page aligned, pagesize: %d", tpBlockSize, pageSize)
|
||||
}
|
||||
tReq := tPacketReq{
|
||||
tpBlockSize: uint32(tpBlockSize),
|
||||
tpBlockNR: uint32(tpBlockNR),
|
||||
tpFrameSize: uint32(tpFrameSize),
|
||||
tpFrameNR: uint32(tpFrameNR),
|
||||
}
|
||||
// Setup PACKET_RX_RING.
|
||||
if err := setsockopt(d.fd, unix.SOL_PACKET, unix.PACKET_RX_RING, unsafe.Pointer(&tReq), unsafe.Sizeof(tReq)); err != nil {
|
||||
return nil, fmt.Errorf("failed to enable PACKET_RX_RING: %v", err)
|
||||
}
|
||||
// Let's mmap the blocks.
|
||||
sz := tpBlockSize * tpBlockNR
|
||||
buf, err := unix.Mmap(d.fd, 0, sz, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unix.Mmap(...,0, %v, ...) failed = %v", sz, err)
|
||||
}
|
||||
d.mgr = newProcessorManager(opts, e)
|
||||
d.mgr.start()
|
||||
d.ringBuffer = buf
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func setsockopt(fd, level, name int, val unsafe.Pointer, vallen uintptr) error {
|
||||
if _, _, errno := unix.Syscall6(unix.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(val), vallen, 0); errno != 0 {
|
||||
return error(errno)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue