mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-23 10:42:12 +00:00
57dc742c76
Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.2.4 to 0.2.5. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.2.4...v0.2.5) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package link
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/cilium/ebpf"
|
|
"github.com/cilium/ebpf/internal/sys"
|
|
)
|
|
|
|
type RawTracepointOptions struct {
|
|
// Tracepoint name.
|
|
Name string
|
|
// Program must be of type RawTracepoint*
|
|
Program *ebpf.Program
|
|
}
|
|
|
|
// AttachRawTracepoint links a BPF program to a raw_tracepoint.
|
|
//
|
|
// Requires at least Linux 4.17.
|
|
func AttachRawTracepoint(opts RawTracepointOptions) (Link, error) {
|
|
if t := opts.Program.Type(); t != ebpf.RawTracepoint && t != ebpf.RawTracepointWritable {
|
|
return nil, fmt.Errorf("invalid program type %s, expected RawTracepoint(Writable)", t)
|
|
}
|
|
if opts.Program.FD() < 0 {
|
|
return nil, fmt.Errorf("invalid program: %w", sys.ErrClosedFd)
|
|
}
|
|
|
|
fd, err := sys.RawTracepointOpen(&sys.RawTracepointOpenAttr{
|
|
Name: sys.NewStringPointer(opts.Name),
|
|
ProgFd: uint32(opts.Program.FD()),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = haveBPFLink()
|
|
if errors.Is(err, ErrNotSupported) {
|
|
// Prior to commit 70ed506c3bbc ("bpf: Introduce pinnable bpf_link abstraction")
|
|
// raw_tracepoints are just a plain fd.
|
|
return &simpleRawTracepoint{fd}, nil
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &rawTracepoint{RawLink{fd: fd}}, nil
|
|
}
|
|
|
|
type simpleRawTracepoint struct {
|
|
fd *sys.FD
|
|
}
|
|
|
|
var _ Link = (*simpleRawTracepoint)(nil)
|
|
|
|
func (frt *simpleRawTracepoint) isLink() {}
|
|
|
|
func (frt *simpleRawTracepoint) Close() error {
|
|
return frt.fd.Close()
|
|
}
|
|
|
|
func (frt *simpleRawTracepoint) Update(_ *ebpf.Program) error {
|
|
return fmt.Errorf("update raw_tracepoint: %w", ErrNotSupported)
|
|
}
|
|
|
|
func (frt *simpleRawTracepoint) Pin(string) error {
|
|
return fmt.Errorf("pin raw_tracepoint: %w", ErrNotSupported)
|
|
}
|
|
|
|
func (frt *simpleRawTracepoint) Unpin() error {
|
|
return fmt.Errorf("unpin raw_tracepoint: %w", ErrNotSupported)
|
|
}
|
|
|
|
func (frt *simpleRawTracepoint) Info() (*Info, error) {
|
|
return nil, fmt.Errorf("can't get raw_tracepoint info: %w", ErrNotSupported)
|
|
}
|
|
|
|
type rawTracepoint struct {
|
|
RawLink
|
|
}
|
|
|
|
var _ Link = (*rawTracepoint)(nil)
|
|
|
|
func (rt *rawTracepoint) Update(_ *ebpf.Program) error {
|
|
return fmt.Errorf("update raw_tracepoint: %w", ErrNotSupported)
|
|
}
|