Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/BPFnative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ end
include("utils.jl")
include("common.jl")
include("libbpf.jl")
include("libcap.jl")
if Sys.islinux()
include("network.jl")
end
Expand Down
17 changes: 17 additions & 0 deletions src/libcap.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const libcap = "/usr/lib/libcap.so"

const CAP_PERFMON = Cint(39)
const CAP_BPF = Cint(39)
const CAP_EFFECTIVE = Cint(0)
const CAP_SET = Cint(1)

function add_cap_bpf!()
caps = ccall((:cap_get_proc, libcap), Ptr{Cvoid}, ())
cap_list = [CAP_BPF,CAP_PERFMON]
@assert ccall((:cap_set_flag, libcap), Cint,
(Ptr{Cvoid}, Cint, Cint, Ptr{Cvoid}, Cint),
caps, CAP_EFFECTIVE, length(cap_list), cap_list, CAP_SET) != 1
@assert ccall((:cap_set_proc, libcap), Cint, (Ptr{Cvoid},), caps) != -1
@assert ccall((:cap_free, libcap), Cint, (Ptr{Cvoid},), caps) != -1
return
end