Skip to content

Commit 60768e6

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
feat: implement binder read loop and BC_REPLY for server-side transactions
Add receiver registry (RegisterReceiver/UnregisterReceiver) on the Driver struct, a background read loop goroutine that processes incoming BR_TRANSACTION events and dispatches them to registered TransactionReceiver handlers, and a Reply method that sends BC_REPLY back to the transaction originator. The read loop also handles BR_INCREFS/BR_ACQUIRE acknowledgments and graceful shutdown via context cancellation.
1 parent ff02172 commit 60768e6

2 files changed

Lines changed: 440 additions & 4 deletions

File tree

kernelbinder/driver.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"runtime"
1111
"sync"
12+
"sync/atomic"
1213
"unsafe"
1314

1415
"github.com/facebookincubator/go-belt/tool/logger"
@@ -35,6 +36,13 @@ type Driver struct {
3536
mapSize uint32
3637
mu sync.Mutex
3738
acquiredHandles map[uint32]bool // tracks handles acquired via BC_INCREFS + BC_ACQUIRE
39+
40+
receivers map[uintptr]binder.TransactionReceiver
41+
receiversMu sync.RWMutex
42+
nextCookie atomic.Uintptr
43+
44+
readLoopOnce sync.Once
45+
readLoopDone chan struct{} // closed when the read loop exits
3846
}
3947

4048
// Compile-time interface check.
@@ -110,6 +118,8 @@ func Open(
110118
mapped: mapped,
111119
mapSize: mapSize,
112120
acquiredHandles: make(map[uint32]bool),
121+
receivers: make(map[uintptr]binder.TransactionReceiver),
122+
readLoopDone: make(chan struct{}),
113123
}
114124

115125
return d, nil

0 commit comments

Comments
 (0)