Skip to content

Commit 99e491e

Browse files
committed
feat: make TranslatedSize not reliant on instructions being available
Signed-off-by: Max Altgelt <[email protected]>
1 parent 0d74bd6 commit 99e491e

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

info.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ type ProgramInfo struct {
305305

306306
maps []MapID
307307
insns []byte
308+
numInsns uint32
308309
jitedSize uint32
309310
verifiedInstructions uint32
310311

@@ -372,6 +373,7 @@ func newProgramInfoFromFd(fd *sys.FD) (*ProgramInfo, error) {
372373
jitedSize: info.JitedProgLen,
373374
loadTime: time.Duration(info.LoadTime),
374375
verifiedInstructions: info.VerifiedInsns,
376+
numInsns: info.XlatedProgLen,
375377
}
376378

377379
// Supplement OBJ_INFO with data from /proc/self/fdinfo. It contains fields
@@ -758,20 +760,12 @@ func (pi *ProgramInfo) JitedSize() (uint32, error) {
758760
// TranslatedSize returns the size of the program's translated instructions in
759761
// bytes, after it has been verified and rewritten by the kernel.
760762
//
761-
// Returns an error wrapping [ErrRestrictedKernel] if translated instructions
762-
// are restricted by sysctls.
763-
//
764763
// Available from 4.13. Reading this metadata requires CAP_BPF or equivalent.
765764
func (pi *ProgramInfo) TranslatedSize() (int, error) {
766-
if pi.restricted {
767-
return 0, fmt.Errorf("xlated size: %w", ErrRestrictedKernel)
768-
}
769-
770-
insns := len(pi.insns)
771-
if insns == 0 {
765+
if pi.numInsns == 0 {
772766
return 0, fmt.Errorf("insufficient permissions or unsupported kernel: %w", ErrNotSupported)
773767
}
774-
return insns, nil
768+
return int(pi.numInsns), nil
775769
}
776770

777771
// MapIDs returns the maps related to the program.

0 commit comments

Comments
 (0)