return nil, fmt.Errorf("can't mmap data pages: %w", err)
}
- cons_pos := (*uint64)(unsafe.Pointer(&cons[0]))
- prod_pos := (*uint64)(unsafe.Pointer(&prod[0]))
+ cons_pos := (*uintptr)(unsafe.Pointer(&cons[0]))
+ prod_pos := (*uintptr)(unsafe.Pointer(&prod[0]))
ring := &ringbufEventRing{
prod: prod,
type ringReader struct {
// These point into mmap'ed memory and must be accessed atomically.
- prod_pos, cons_pos *uint64
- mask uint64
+ prod_pos, cons_pos *uintptr
+ mask uintptr
ring []byte
}
-func newRingReader(cons_ptr, prod_ptr *uint64, ring []byte) *ringReader {
+func newRingReader(cons_ptr, prod_ptr *uintptr, ring []byte) *ringReader {
return &ringReader{
prod_pos: prod_ptr,
cons_pos: cons_ptr,
// cap is always a power of two
- mask: uint64(cap(ring)/2 - 1),
+ mask: uintptr(cap(ring)/2 - 1),
ring: ring,
}
}
// The amount of data available to read in the ring buffer.
func (rr *ringReader) AvailableBytes() uint64 {
- prod := atomic.LoadUint64(rr.prod_pos)
- cons := atomic.LoadUint64(rr.cons_pos)
- return prod - cons
+ prod := atomic.LoadUintptr(rr.prod_pos)
+ cons := atomic.LoadUintptr(rr.cons_pos)
+ return uint64(prod - cons)
}
// Read a record from an event ring.
func (rr *ringReader) readRecord(rec *Record) error {
- prod := atomic.LoadUint64(rr.prod_pos)
- cons := atomic.LoadUint64(rr.cons_pos)
+ prod := atomic.LoadUintptr(rr.prod_pos)
+ cons := atomic.LoadUintptr(rr.cons_pos)
for {
if remaining := prod - cons; remaining == 0 {
cons += sys.BPF_RINGBUF_HDR_SZ
// Data is always padded to 8 byte alignment.
- dataLenAligned := uint64(internal.Align(header.dataLen(), 8))
+ dataLenAligned := uintptr(internal.Align(header.dataLen(), 8))
if remaining := prod - cons; remaining < dataLenAligned {
return fmt.Errorf("read sample data: %w", io.ErrUnexpectedEOF)
}
// when the record header indicates that the data should be
// discarded, we skip it by just updating the consumer position
// to the next record.
- atomic.StoreUint64(rr.cons_pos, cons)
+ atomic.StoreUintptr(rr.cons_pos, cons)
continue
}
copy(rec.RawSample, rr.ring[start:])
rec.Remaining = int(prod - cons)
- atomic.StoreUint64(rr.cons_pos, cons)
+ atomic.StoreUintptr(rr.cons_pos, cons)
return nil
}
}