Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: add type safe Pointer wrapper #1670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion btf/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func probeBTF(typ Type) error {
}

fd, err := sys.BtfLoad(&sys.BtfLoadAttr{
Btf: sys.NewSlicePointer(buf),
Btf: sys.SlicePointer(buf),
BtfSize: uint32(len(buf)),
})

Expand Down
10 changes: 6 additions & 4 deletions btf/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewHandleFromRawBTF(btf []byte) (*Handle, error) {
}

attr := &sys.BtfLoadAttr{
Btf: sys.NewSlicePointer(btf),
Btf: sys.SlicePointer(btf),
BtfSize: uint32(len(btf)),
}

Expand Down Expand Up @@ -91,7 +91,7 @@ func NewHandleFromRawBTF(btf []byte) (*Handle, error) {

logBuf = make([]byte, logSize)
attr.BtfLogSize = logSize
attr.BtfLogBuf = sys.NewSlicePointer(logBuf)
attr.BtfLogBuf = sys.SlicePointer(logBuf)
attr.BtfLogLevel = 1
}

Expand Down Expand Up @@ -133,7 +133,8 @@ func NewHandleFromID(id ID) (*Handle, error) {
func (h *Handle) Spec(base *Spec) (*Spec, error) {
var btfInfo sys.BtfInfo
btfBuffer := make([]byte, h.size)
btfInfo.Btf, btfInfo.BtfSize = sys.NewSlicePointerLen(btfBuffer)
btfInfo.Btf = sys.SlicePointer(btfBuffer)
btfInfo.BtfSize = uint32(len(btfBuffer))

if err := sys.ObjInfo(h.fd, &btfInfo); err != nil {
return nil, err
Expand Down Expand Up @@ -204,7 +205,8 @@ func newHandleInfoFromFD(fd *sys.FD) (*HandleInfo, error) {
btfInfo.BtfSize = 0

nameBuffer := make([]byte, btfInfo.NameLen)
btfInfo.Name, btfInfo.NameLen = sys.NewSlicePointerLen(nameBuffer)
btfInfo.Name = sys.SlicePointer(nameBuffer)
btfInfo.NameLen = uint32(len(nameBuffer))
if err := sys.ObjInfo(fd, &btfInfo); err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func newProgramInfoFromFd(fd *sys.FD) (*ProgramInfo, error) {
if info.NrMapIds > 0 {
pi.maps = make([]MapID, info.NrMapIds)
info2.NrMapIds = info.NrMapIds
info2.MapIds = sys.NewSlicePointer(pi.maps)
info2.MapIds = sys.SlicePointer(pi.maps)
makeSecondCall = true
} else if haveProgramInfoMapIDs() == nil {
// This program really has no associated maps.
Expand All @@ -294,13 +294,13 @@ func newProgramInfoFromFd(fd *sys.FD) (*ProgramInfo, error) {
if info.XlatedProgLen > 0 {
pi.insns = make([]byte, info.XlatedProgLen)
info2.XlatedProgLen = info.XlatedProgLen
info2.XlatedProgInsns = sys.NewSlicePointer(pi.insns)
info2.XlatedProgInsns = sys.SlicePointer(pi.insns)
makeSecondCall = true
}

if info.NrLineInfo > 0 {
pi.lineInfos = make([]byte, btf.LineInfoSize*info.NrLineInfo)
info2.LineInfo = sys.NewSlicePointer(pi.lineInfos)
info2.LineInfo = sys.SlicePointer(pi.lineInfos)
info2.LineInfoRecSize = btf.LineInfoSize
info2.NrLineInfo = info.NrLineInfo
pi.numLineInfos = info.NrLineInfo
Expand All @@ -309,7 +309,7 @@ func newProgramInfoFromFd(fd *sys.FD) (*ProgramInfo, error) {

if info.NrFuncInfo > 0 {
pi.funcInfos = make([]byte, btf.FuncInfoSize*info.NrFuncInfo)
info2.FuncInfo = sys.NewSlicePointer(pi.funcInfos)
info2.FuncInfo = sys.SlicePointer(pi.funcInfos)
info2.FuncInfoRecSize = btf.FuncInfoSize
info2.NrFuncInfo = info.NrFuncInfo
pi.numFuncInfos = info.NrFuncInfo
Expand All @@ -321,31 +321,31 @@ func newProgramInfoFromFd(fd *sys.FD) (*ProgramInfo, error) {
pi.jitedInfo.numInsns = info.JitedProgLen
pi.jitedInfo.insns = make([]byte, info.JitedProgLen)
info2.JitedProgLen = info.JitedProgLen
info2.JitedProgInsns = sys.NewSlicePointer(pi.jitedInfo.insns)
info2.JitedProgInsns = sys.SlicePointer(pi.jitedInfo.insns)
makeSecondCall = true
}

if info.NrJitedFuncLens > 0 {
pi.jitedInfo.numFuncLens = info.NrJitedFuncLens
pi.jitedInfo.funcLens = make([]uint32, info.NrJitedFuncLens)
info2.NrJitedFuncLens = info.NrJitedFuncLens
info2.JitedFuncLens = sys.NewSlicePointer(pi.jitedInfo.funcLens)
info2.JitedFuncLens = sys.SlicePointer(pi.jitedInfo.funcLens)
makeSecondCall = true
}

if info.NrJitedLineInfo > 0 {
pi.jitedInfo.numLineInfos = info.NrJitedLineInfo
pi.jitedInfo.lineInfos = make([]uint64, info.NrJitedLineInfo)
info2.NrJitedLineInfo = info.NrJitedLineInfo
info2.JitedLineInfo = sys.NewSlicePointer(pi.jitedInfo.lineInfos)
info2.JitedLineInfo = sys.SlicePointer(pi.jitedInfo.lineInfos)
info2.JitedLineInfoRecSize = info.JitedLineInfoRecSize
makeSecondCall = true
}

if info.NrJitedKsyms > 0 {
pi.jitedInfo.numKsyms = info.NrJitedKsyms
pi.jitedInfo.ksyms = make([]uint64, info.NrJitedKsyms)
info2.JitedKsyms = sys.NewSlicePointer(pi.jitedInfo.ksyms)
info2.JitedKsyms = sys.SlicePointer(pi.jitedInfo.ksyms)
info2.NrJitedKsyms = info.NrJitedKsyms
makeSecondCall = true
}
Expand Down
Loading
Loading