authorgravatar for bjorn.linse@gmail.combfredl <bjorn.linse@gmail.com> 2023-06-05 15:56:25+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-13 10:57:51-07:00
log4f914c8414c5220de145b141103ea71e01b23bda
tree72c5ff5a6649e18f779cea7ccc54dc6c67bd89d6
parent28eed1f7b3a8654b941960232d7c707d88649d8d

bpf: expose "syscall" program type and F_SLEEPABLE flag


1 files changed, 15 insertions(+), 2 deletions(-)

lib/std/os/linux/bpf.zig+15-2
...@@ -167,6 +167,13 @@ pub const F_ANY_ALIGNMENT = 0x2;...@@ -167,6 +167,13 @@ pub const F_ANY_ALIGNMENT = 0x2;
167/// will regress tests to expose bugs.167/// will regress tests to expose bugs.
168pub const F_TEST_RND_HI32 = 0x4;168pub const F_TEST_RND_HI32 = 0x4;
169169
170/// If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
171/// restrict map and helper usage for such programs. Sleepable BPF programs can
172/// only be attached to hooks where kernel execution context allows sleeping.
173/// Such programs are allowed to use helpers that may sleep like
174/// bpf_copy_from_user().
175pub const F_SLEEPABLE = 0x10;
176
170/// When BPF ldimm64's insn[0].src_reg != 0 then this can have two extensions:177/// When BPF ldimm64's insn[0].src_reg != 0 then this can have two extensions:
171/// insn[0].src_reg: BPF_PSEUDO_MAP_FD BPF_PSEUDO_MAP_VALUE178/// insn[0].src_reg: BPF_PSEUDO_MAP_FD BPF_PSEUDO_MAP_VALUE
172/// insn[0].imm: map fd map fd179/// insn[0].imm: map fd map fd
...@@ -1134,6 +1141,10 @@ pub const ProgType = enum(u32) {...@@ -1134,6 +1141,10 @@ pub const ProgType = enum(u32) {
11341141
1135 /// context type: bpf_sk_lookup1142 /// context type: bpf_sk_lookup
1136 sk_lookup,1143 sk_lookup,
1144
1145 /// context type: void *
1146 syscall,
1147
1137 _,1148 _,
1138};1149};
11391150
...@@ -1649,6 +1660,7 @@ pub fn prog_load(...@@ -1649,6 +1660,7 @@ pub fn prog_load(
1649 log: ?*Log,1660 log: ?*Log,
1650 license: []const u8,1661 license: []const u8,
1651 kern_version: u32,1662 kern_version: u32,
1663 flags: u32,
1652) !fd_t {1664) !fd_t {
1653 var attr = Attr{1665 var attr = Attr{
1654 .prog_load = std.mem.zeroes(ProgLoadAttr),1666 .prog_load = std.mem.zeroes(ProgLoadAttr),
...@@ -1659,6 +1671,7 @@ pub fn prog_load(...@@ -1659,6 +1671,7 @@ pub fn prog_load(
1659 attr.prog_load.insn_cnt = @intCast(u32, insns.len);1671 attr.prog_load.insn_cnt = @intCast(u32, insns.len);
1660 attr.prog_load.license = @ptrToInt(license.ptr);1672 attr.prog_load.license = @ptrToInt(license.ptr);
1661 attr.prog_load.kern_version = kern_version;1673 attr.prog_load.kern_version = kern_version;
1674 attr.prog_load.prog_flags = flags;
16621675
1663 if (log) |l| {1676 if (log) |l| {
1664 attr.prog_load.log_buf = @ptrToInt(l.buf.ptr);1677 attr.prog_load.log_buf = @ptrToInt(l.buf.ptr);
...@@ -1688,8 +1701,8 @@ test "prog_load" {...@@ -1688,8 +1701,8 @@ test "prog_load" {
1688 Insn.exit(),1701 Insn.exit(),
1689 };1702 };
16901703
1691 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);1704 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0, 0);
1692 defer std.os.close(prog);1705 defer std.os.close(prog);
16931706
1694 try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));1707 try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0, 0));
1695}1708}