Skip to content

Commit f87d8e6

Browse files
authored
ringbuf: Use uintptr for positions for 32-bit compatibility (#1843)
Signed-off-by: Joshua McBeth <[email protected]>
1 parent 5e20f81 commit f87d8e6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

ringbuf/ring.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func newRingBufEventRing(mapFD, size int) (*ringbufEventRing, error) {
3333
return nil, fmt.Errorf("can't mmap data pages: %w", err)
3434
}
3535

36-
cons_pos := (*uint64)(unsafe.Pointer(&cons[0]))
37-
prod_pos := (*uint64)(unsafe.Pointer(&prod[0]))
36+
cons_pos := (*uintptr)(unsafe.Pointer(&cons[0]))
37+
prod_pos := (*uintptr)(unsafe.Pointer(&prod[0]))
3838

3939
ring := &ringbufEventRing{
4040
prod: prod,
@@ -58,17 +58,17 @@ func (ring *ringbufEventRing) Close() {
5858

5959
type ringReader struct {
6060
// These point into mmap'ed memory and must be accessed atomically.
61-
prod_pos, cons_pos *uint64
62-
mask uint64
61+
prod_pos, cons_pos *uintptr
62+
mask uintptr
6363
ring []byte
6464
}
6565

66-
func newRingReader(cons_ptr, prod_ptr *uint64, ring []byte) *ringReader {
66+
func newRingReader(cons_ptr, prod_ptr *uintptr, ring []byte) *ringReader {
6767
return &ringReader{
6868
prod_pos: prod_ptr,
6969
cons_pos: cons_ptr,
7070
// cap is always a power of two
71-
mask: uint64(cap(ring)/2 - 1),
71+
mask: uintptr(cap(ring)/2 - 1),
7272
ring: ring,
7373
}
7474
}
@@ -82,15 +82,15 @@ func (rr *ringReader) size() int {
8282

8383
// The amount of data available to read in the ring buffer.
8484
func (rr *ringReader) AvailableBytes() uint64 {
85-
prod := atomic.LoadUint64(rr.prod_pos)
86-
cons := atomic.LoadUint64(rr.cons_pos)
87-
return prod - cons
85+
prod := atomic.LoadUintptr(rr.prod_pos)
86+
cons := atomic.LoadUintptr(rr.cons_pos)
87+
return uint64(prod - cons)
8888
}
8989

9090
// Read a record from an event ring.
9191
func (rr *ringReader) readRecord(rec *Record) error {
92-
prod := atomic.LoadUint64(rr.prod_pos)
93-
cons := atomic.LoadUint64(rr.cons_pos)
92+
prod := atomic.LoadUintptr(rr.prod_pos)
93+
cons := atomic.LoadUintptr(rr.cons_pos)
9494

9595
for {
9696
if remaining := prod - cons; remaining == 0 {
@@ -117,7 +117,7 @@ func (rr *ringReader) readRecord(rec *Record) error {
117117
cons += sys.BPF_RINGBUF_HDR_SZ
118118

119119
// Data is always padded to 8 byte alignment.
120-
dataLenAligned := uint64(internal.Align(header.dataLen(), 8))
120+
dataLenAligned := uintptr(internal.Align(header.dataLen(), 8))
121121
if remaining := prod - cons; remaining < dataLenAligned {
122122
return fmt.Errorf("read sample data: %w", io.ErrUnexpectedEOF)
123123
}
@@ -129,7 +129,7 @@ func (rr *ringReader) readRecord(rec *Record) error {
129129
// when the record header indicates that the data should be
130130
// discarded, we skip it by just updating the consumer position
131131
// to the next record.
132-
atomic.StoreUint64(rr.cons_pos, cons)
132+
atomic.StoreUintptr(rr.cons_pos, cons)
133133
continue
134134
}
135135

@@ -141,7 +141,7 @@ func (rr *ringReader) readRecord(rec *Record) error {
141141

142142
copy(rec.RawSample, rr.ring[start:])
143143
rec.Remaining = int(prod - cons)
144-
atomic.StoreUint64(rr.cons_pos, cons)
144+
atomic.StoreUintptr(rr.cons_pos, cons)
145145
return nil
146146
}
147147
}

0 commit comments

Comments
 (0)