feat(shm): 统一共享内存区域(§13.1) — 单 memfd 容纳 SuperBlock+StageContext+EvtRing

- unified.go: SuperBlock 布局 + SharedRef 类型
- NewHost(): 两段 memfd 合并为单一 memfd,fd 3 = 统一区域,fd 4 = eventfd
- 子进程侧: testdata 插件从 SuperBlock 解析 ctxOff/evtOff
- streaming 测试: EvtConsumer 协程在 host.Close 前 Stop+Wait 防 SIGSEGV
This commit is contained in:
JianFeeeee
2026-09-10 11:42:22 +08:00
parent 7a328679da
commit ad016e4410
7 changed files with 291 additions and 60 deletions

View File

@ -181,7 +181,10 @@ func main() {
send(response{ID: req.ID, Error: fmt.Sprintf("mmap: %v", err)})
continue
}
shm = m
// 统一区域:前 64B 是 SuperBlock,StageContext 段在其后
ctxOff := binary.LittleEndian.Uint32(m[20:])
ctxSize := binary.LittleEndian.Uint32(m[24:])
shm = m[ctxOff : ctxOff+ctxSize]
}
send(response{ID: req.ID, Result: map[string]interface{}{
"protocol": 1, "sdk_version": "test",

View File

@ -133,7 +133,10 @@ func main() {
send(response{ID: req.ID, Error: fmt.Sprintf("mmap: %v", err)})
continue
}
shm = m
// 统一区域:前 64B 是 SuperBlock,StageContext 段在其后
ctxOff := binary.LittleEndian.Uint32(m[20:])
ctxSize := binary.LittleEndian.Uint32(m[24:])
shm = m[ctxOff : ctxOff+ctxSize]
}
send(response{ID: req.ID, Result: map[string]interface{}{
"protocol": 1, "sdk_version": "test", "plugin_name": "readonly", "pid": os.Getpid(),

View File

@ -223,14 +223,17 @@ func main() {
json.Unmarshal(req.Params, &hp)
shmSize = hp.ShmSize
if shmSize > 0 {
// fd 3 = 内核传入的共享段 memfd
// fd 3 = 内核传入的统一共享内存区域
m, err := syscall.Mmap(3, 0, shmSize,
syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
if err != nil {
send(response{ID: req.ID, Error: fmt.Sprintf("mmap 共享段失败: %v", err)})
continue
}
shm = m
// 统一区域:前 64B 是 SuperBlock,StageContext 段在其后
ctxOff := binary.LittleEndian.Uint32(m[20:])
ctxSize := binary.LittleEndian.Uint32(m[24:])
shm = m[ctxOff : ctxOff+ctxSize]
}
send(response{ID: req.ID, Result: map[string]interface{}{
"protocol": 1, "sdk_version": "test", "plugin_name": "stage", "pid": os.Getpid(),