mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-24 19:08:10 +00:00
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:
@ -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",
|
||||
|
||||
@ -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(),
|
||||
|
||||
7
internal/plugin/proc/testdata/stageplugin.go
vendored
7
internal/plugin/proc/testdata/stageplugin.go
vendored
@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user