aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/os/linux')
-rw-r--r--lib/std/os/linux/bpf.zig17
-rw-r--r--lib/std/os/linux/bpf/btf.zig6
-rw-r--r--lib/std/os/linux/bpf/helpers.zig2
-rw-r--r--lib/std/os/linux/io_uring.zig4
-rw-r--r--lib/std/os/linux/seccomp.zig2
-rw-r--r--lib/std/os/linux/tls.zig8
-rw-r--r--lib/std/os/linux/x86.zig2
7 files changed, 27 insertions, 14 deletions
diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig
index 63b669acd5..9f9e253547 100644
--- a/lib/std/os/linux/bpf.zig
+++ b/lib/std/os/linux/bpf.zig
@@ -167,6 +167,13 @@ pub const F_ANY_ALIGNMENT = 0x2;
/// will regress tests to expose bugs.
pub const F_TEST_RND_HI32 = 0x4;
+/// If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
+/// restrict map and helper usage for such programs. Sleepable BPF programs can
+/// only be attached to hooks where kernel execution context allows sleeping.
+/// Such programs are allowed to use helpers that may sleep like
+/// bpf_copy_from_user().
+pub const F_SLEEPABLE = 0x10;
+
/// When BPF ldimm64's insn[0].src_reg != 0 then this can have two extensions:
/// insn[0].src_reg: BPF_PSEUDO_MAP_FD BPF_PSEUDO_MAP_VALUE
/// insn[0].imm: map fd map fd
@@ -1134,6 +1141,10 @@ pub const ProgType = enum(u32) {
/// context type: bpf_sk_lookup
sk_lookup,
+
+ /// context type: void *
+ syscall,
+
_,
};
@@ -1649,6 +1660,7 @@ pub fn prog_load(
log: ?*Log,
license: []const u8,
kern_version: u32,
+ flags: u32,
) !fd_t {
var attr = Attr{
.prog_load = std.mem.zeroes(ProgLoadAttr),
@@ -1659,6 +1671,7 @@ pub fn prog_load(
attr.prog_load.insn_cnt = @intCast(u32, insns.len);
attr.prog_load.license = @ptrToInt(license.ptr);
attr.prog_load.kern_version = kern_version;
+ attr.prog_load.prog_flags = flags;
if (log) |l| {
attr.prog_load.log_buf = @ptrToInt(l.buf.ptr);
@@ -1688,8 +1701,8 @@ test "prog_load" {
Insn.exit(),
};
- const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
+ const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0, 0);
defer std.os.close(prog);
- try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
+ try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0, 0));
}
diff --git a/lib/std/os/linux/bpf/btf.zig b/lib/std/os/linux/bpf/btf.zig
index 7b85a618b3..39d25014da 100644
--- a/lib/std/os/linux/bpf/btf.zig
+++ b/lib/std/os/linux/bpf/btf.zig
@@ -109,7 +109,7 @@ pub const Enum64 = extern struct {
val_hi32: i32,
};
-/// array kind is followd by this struct
+/// array kind is followed by this struct
pub const Array = extern struct {
typ: u32,
index_type: u32,
@@ -149,13 +149,13 @@ pub const FuncLinkage = enum {
external,
};
-/// var kind is followd by a single Var struct to describe additional
+/// var kind is followed by a single Var struct to describe additional
/// information related to the variable such as its linkage
pub const Var = extern struct {
linkage: u32,
};
-/// datasec kind is followed by multible VarSecInfo to describe all Var kind
+/// datasec kind is followed by multiple VarSecInfo to describe all Var kind
/// types it contains along with it's in-section offset as well as size.
pub const VarSecInfo = extern struct {
typ: u32,
diff --git a/lib/std/os/linux/bpf/helpers.zig b/lib/std/os/linux/bpf/helpers.zig
index dafd4de69f..6084b01e6c 100644
--- a/lib/std/os/linux/bpf/helpers.zig
+++ b/lib/std/os/linux/bpf/helpers.zig
@@ -143,7 +143,7 @@ pub const seq_printf = @intToPtr(*const fn (m: *kern.SeqFile, fmt: ?*const u8, f
pub const seq_write = @intToPtr(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, 127);
pub const sk_cgroup_id = @intToPtr(*const fn (sk: *kern.BpfSock) u64, 128);
pub const sk_ancestor_cgroup_id = @intToPtr(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, 129);
-pub const ringbuf_output = @intToPtr(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, 130);
+pub const ringbuf_output = @intToPtr(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, 130);
pub const ringbuf_reserve = @intToPtr(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, 131);
pub const ringbuf_submit = @intToPtr(*const fn (data: ?*anyopaque, flags: u64) void, 132);
pub const ringbuf_discard = @intToPtr(*const fn (data: ?*anyopaque, flags: u64) void, 133);
diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig
index b7467d765f..0610b214d5 100644
--- a/lib/std/os/linux/io_uring.zig
+++ b/lib/std/os/linux/io_uring.zig
@@ -277,7 +277,7 @@ pub const IO_Uring = struct {
fn copy_cqes_ready(self: *IO_Uring, cqes: []linux.io_uring_cqe, wait_nr: u32) u32 {
_ = wait_nr;
const ready = self.cq_ready();
- const count = std.math.min(cqes.len, ready);
+ const count = @min(cqes.len, ready);
var head = self.cq.head.*;
var tail = head +% count;
// TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop.
@@ -1093,7 +1093,7 @@ pub const SubmissionQueue = struct {
pub fn init(fd: os.fd_t, p: linux.io_uring_params) !SubmissionQueue {
assert(fd >= 0);
assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0);
- const size = std.math.max(
+ const size = @max(
p.sq_off.array + p.sq_entries * @sizeOf(u32),
p.cq_off.cqes + p.cq_entries * @sizeOf(linux.io_uring_cqe),
);
diff --git a/lib/std/os/linux/seccomp.zig b/lib/std/os/linux/seccomp.zig
index 23dbb6ee38..f10cb84aa0 100644
--- a/lib/std/os/linux/seccomp.zig
+++ b/lib/std/os/linux/seccomp.zig
@@ -65,7 +65,7 @@
//!
//! Unfortunately, there is no easy solution for issue 5. The most reliable
//! strategy is to keep testing; test newer Zig versions, different libcs,
-//! different distros, and design your filter to accomidate all of them.
+//! different distros, and design your filter to accommodate all of them.
//! Alternatively, you could inject a filter at runtime. Since filters are
//! preserved across execve(2), a filter could be setup before executing your
//! program, without your program having any knowledge of this happening. This
diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig
index 311e5609e8..d765e403c8 100644
--- a/lib/std/os/linux/tls.zig
+++ b/lib/std/os/linux/tls.zig
@@ -233,7 +233,7 @@ fn initTLS(phdrs: []elf.Phdr) void {
l += tls_align_factor - delta;
l += @sizeOf(CustomData);
tcb_offset = l;
- l += mem.alignForward(tls_tcb_size, tls_align_factor);
+ l += mem.alignForward(usize, tls_tcb_size, tls_align_factor);
data_offset = l;
l += tls_data_alloc_size;
break :blk l;
@@ -241,14 +241,14 @@ fn initTLS(phdrs: []elf.Phdr) void {
.VariantII => blk: {
var l: usize = 0;
data_offset = l;
- l += mem.alignForward(tls_data_alloc_size, tls_align_factor);
+ l += mem.alignForward(usize, tls_data_alloc_size, tls_align_factor);
// The thread pointer is aligned to p_align
tcb_offset = l;
l += tls_tcb_size;
// The CustomData structure is right after the TCB with no padding
// in between so it can be easily found
l += @sizeOf(CustomData);
- l = mem.alignForward(l, @alignOf(DTV));
+ l = mem.alignForward(usize, l, @alignOf(DTV));
dtv_offset = l;
l += @sizeOf(DTV);
break :blk l;
@@ -329,7 +329,7 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void {
// Make sure the slice is correctly aligned.
const begin_addr = @ptrToInt(alloc_tls_area.ptr);
- const begin_aligned_addr = mem.alignForward(begin_addr, tls_image.alloc_align);
+ const begin_aligned_addr = mem.alignForward(usize, begin_addr, tls_image.alloc_align);
const start = begin_aligned_addr - begin_addr;
break :blk alloc_tls_area[start .. start + tls_image.alloc_size];
};
diff --git a/lib/std/os/linux/x86.zig b/lib/std/os/linux/x86.zig
index 2e67fa6b5b..c9274e11ee 100644
--- a/lib/std/os/linux/x86.zig
+++ b/lib/std/os/linux/x86.zig
@@ -108,7 +108,7 @@ pub fn syscall6(
);
}
-pub fn socketcall(call: usize, args: [*]usize) usize {
+pub fn socketcall(call: usize, args: [*]const usize) usize {
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize),
: [number] "{eax}" (@enumToInt(SYS.socketcall)),