feat(shm): 统一共享内存区域(§13.1) — 子进程侧模板适配

- proc_shm_unix.go.tmpl: fd 3 = 统一区域,fd 4 = eventfd
- proc_main.go.tmpl: 握手解析 SuperBlock,从 ctxOff/evtOff 定位两段
- 新增 unified region 常量(magic/version/offset) + StageContext 内部布局常量
This commit is contained in:
JianFeeeee
2026-09-10 11:46:12 +08:00
parent a66739e59b
commit fc236120e3
2 changed files with 104 additions and 46 deletions

View File

@ -10,31 +10,23 @@ import (
// Unix 侧共享段挂载:内核经 ExtraFiles 传入继承的 fd。
//
// fd 布局(与内核 internal/plugin/proc/plugin.go 的 ExtraFiles 顺序一致):
// 统一共享内存区域布局(§13.1):
//
// fd 3 = StageContext 段(memfd / 已 unlink 的临时文件)
// fd 4 = 事件环段
// fd 5 = 事件通知(Linux eventfd / macOS pipe 读端)
// fd 3 = 统一区域(SuperBlock + StageContext + EvtRing)
// fd 4 = 事件通知(Linux eventfd / macOS pipe 读端)
//
// 继承的 fd 无需文件名,也不残留——这是选 memfd 而非 /dev/shm 的原因。
const (
fdStageShm = 3
fdEvtRingShm = 4
fdEvtNotifier = 5
fdUnifiedShm = 3
fdEvtNotifier = 4
)
// attachStageShm 挂载 StageContext 共享段。
// attachUnifiedShm 挂载统一共享内存区域。
//
// 各进程 mmap 到不同虚拟地址,段内一律用相对偏移而非指针,故仍能正确解引用
// (实验 2 已验证父子 mmap 基址不同时偏移解引用正确)。
func attachStageShm(size int) ([]byte, error) {
return syscall.Mmap(fdStageShm, 0, size,
syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
}
// attachEvtRingShm 挂载事件环段。
func attachEvtRingShm(size int) ([]byte, error) {
return syscall.Mmap(fdEvtRingShm, 0, size,
func attachUnifiedShm(size int) ([]byte, error) {
return syscall.Mmap(fdUnifiedShm, 0, size,
syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
}