@@ -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.
765764func (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