diff --git a/src/bpf/args.zig b/src/bpf/args.zig index 5d25dfa..a155966 100644 --- a/src/bpf/args.zig +++ b/src/bpf/args.zig @@ -29,7 +29,7 @@ pub fn Ctx(comptime func_name: []const u8) type { const f = @typeInfo(@TypeOf(@field(vmlinux, "_zig_" ++ func_name))); comptime var fields: []const StructField = &.{}; - for (0.., f.Fn.params) |i, arg| { + for (0.., f.@"fn".params) |i, arg| { fields = fields ++ [_]StructField{ .{ .name = std.fmt.comptimePrint("arg{}", .{i}), @@ -44,7 +44,7 @@ pub fn Ctx(comptime func_name: []const u8) type { fields = fields ++ [_]StructField{ .{ .name = "ret", - .type = f.Fn.return_type.?, + .type = f.@"fn".return_type.?, .default_value = null, .is_comptime = false, .alignment = @sizeOf(u64), @@ -52,7 +52,7 @@ pub fn Ctx(comptime func_name: []const u8) type { }; return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .@"extern", .is_tuple = false, .fields = fields, @@ -140,15 +140,15 @@ pub const REGS = extern struct { /// Check if the type is ?*T or *T. pub inline fn is_pointer(comptime typ: type) bool { const ti = @typeInfo(typ); - return ti == .Pointer or (ti == .Optional and @typeInfo(ti.Optional.child) == .Pointer); + return ti == .pointer or (ti == .optional and @typeInfo(ti.optional.child) == .pointer); } /// Get the pointee type pub inline fn deref_pointer(comptime typ: type) type { const ti = @typeInfo(typ); return switch (ti) { - inline .Pointer => |info| return info.child, - inline .Optional => |info| return @typeInfo(info.child).Pointer.child, + inline .pointer => |info| return info.child, + inline .optional => |info| return @typeInfo(info.child).pointer.child, else => @compileLog(ti), }; } @@ -158,8 +158,8 @@ pub fn cast(comptime T: type, rc: c_ulong) T { if (is_pointer(T)) return @ptrFromInt(rc); const ti = @typeInfo(T); - if (ti == .Int) { - if (ti.Int.signedness == .signed) { + if (ti == .int) { + if (ti.int.signedness == .signed) { return @truncate(@as(c_long, @bitCast(rc))); } return @truncate(rc); @@ -184,8 +184,8 @@ pub fn PT_REGS(comptime func_name: []const u8, comptime for_syscall: bool) type return @alignCast(@ptrCast(self)); } - pub usingnamespace if (f.Fn.params.len < 1) struct {} else struct { - const RET = f.Fn.params[0].type.?; + pub usingnamespace if (f.@"fn".params.len < 1) struct {} else struct { + const RET = f.@"fn".params[0].type.?; pub fn arg0(self: *Self) RET { if (!in_bpf_program) { @@ -199,8 +199,8 @@ pub fn PT_REGS(comptime func_name: []const u8, comptime for_syscall: bool) type } }; - pub usingnamespace if (f.Fn.params.len < 2) struct {} else struct { - const RET = f.Fn.params[1].type.?; + pub usingnamespace if (f.@"fn".params.len < 2) struct {} else struct { + const RET = f.@"fn".params[1].type.?; pub fn arg1(self: *Self) RET { if (!in_bpf_program) { @@ -214,8 +214,8 @@ pub fn PT_REGS(comptime func_name: []const u8, comptime for_syscall: bool) type } }; - pub usingnamespace if (f.Fn.params.len < 3) struct {} else struct { - const RET = f.Fn.params[2].type.?; + pub usingnamespace if (f.@"fn".params.len < 3) struct {} else struct { + const RET = f.@"fn".params[2].type.?; pub fn arg2(self: *Self) RET { if (!in_bpf_program) { @@ -229,8 +229,8 @@ pub fn PT_REGS(comptime func_name: []const u8, comptime for_syscall: bool) type } }; - pub usingnamespace if (f.Fn.params.len < 4) struct {} else struct { - const RET = f.Fn.params[3].type.?; + pub usingnamespace if (f.@"fn".params.len < 4) struct {} else struct { + const RET = f.@"fn".params[3].type.?; pub fn arg3(self: *Self) RET { if (!in_bpf_program) { @@ -244,8 +244,8 @@ pub fn PT_REGS(comptime func_name: []const u8, comptime for_syscall: bool) type } }; - pub usingnamespace if (f.Fn.params.len < 5) struct {} else struct { - const RET = f.Fn.params[4].type.?; + pub usingnamespace if (f.@"fn".params.len < 5) struct {} else struct { + const RET = f.@"fn".params[4].type.?; pub fn arg4(self: *Self) RET { if (!in_bpf_program) { @@ -259,8 +259,8 @@ pub fn PT_REGS(comptime func_name: []const u8, comptime for_syscall: bool) type } }; - pub usingnamespace if (f.Fn.return_type.? == void) struct {} else struct { - const RET = f.Fn.return_type.?; + pub usingnamespace if (f.@"fn".return_type.? == void) struct {} else struct { + const RET = f.@"fn".return_type.?; pub fn ret(self: *Self) RET { if (!in_bpf_program) { @@ -297,48 +297,48 @@ pub fn SYSCALL(comptime name: []const u8) type { @ptrCast(self); } - pub usingnamespace if (f.Fn.params.len < 1) struct {} else struct { - const RET = f.Fn.params[0].type.?; + pub usingnamespace if (f.@"fn".params.len < 1) struct {} else struct { + const RET = f.@"fn".params[0].type.?; pub fn arg0(self: *Self) RET { return self.get_arg_ctx().arg0(); } }; - pub usingnamespace if (f.Fn.params.len < 2) struct {} else struct { - const RET = f.Fn.params[1].type.?; + pub usingnamespace if (f.@"fn".params.len < 2) struct {} else struct { + const RET = f.@"fn".params[1].type.?; pub fn arg1(self: *Self) RET { return self.get_arg_ctx().arg1(); } }; - pub usingnamespace if (f.Fn.params.len < 3) struct {} else struct { - const RET = f.Fn.params[2].type.?; + pub usingnamespace if (f.@"fn".params.len < 3) struct {} else struct { + const RET = f.@"fn".params[2].type.?; pub fn arg2(self: *Self) RET { return self.get_arg_ctx().arg2(); } }; - pub usingnamespace if (f.Fn.params.len < 4) struct {} else struct { - const RET = f.Fn.params[3].type.?; + pub usingnamespace if (f.@"fn".params.len < 4) struct {} else struct { + const RET = f.@"fn".params[3].type.?; pub fn arg3(self: *Self) RET { return self.get_arg_ctx().arg3(); } }; - pub usingnamespace if (f.Fn.params.len < 5) struct {} else struct { - const RET = f.Fn.params[4].type.?; + pub usingnamespace if (f.@"fn".params.len < 5) struct {} else struct { + const RET = f.@"fn".params[4].type.?; pub fn arg4(self: *Self) RET { return self.get_arg_ctx().arg4(); } }; - pub usingnamespace if (f.Fn.return_type.? == void) struct {} else struct { - const RET = f.Fn.return_type.?; + pub usingnamespace if (f.@"fn".return_type.? == void) struct {} else struct { + const RET = f.@"fn".return_type.?; pub fn ret(self: *Self) RET { return @as(*T, @ptrCast(self)).ret(); diff --git a/src/bpf/map.zig b/src/bpf/map.zig index 47964d3..1df8295 100644 --- a/src/bpf/map.zig +++ b/src/bpf/map.zig @@ -63,20 +63,22 @@ fn Map( }} else [_]StructField{}); const Def = @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .@"extern", .is_tuple = false, .fields = &fields, .decls = &[_]Declaration{}, }, }); + return struct { var def: Def = undefined; + const p: *Def = &def; const Self = @This(); comptime { - @export(Self.def, .{ .name = name, .section = ".maps" }); + @export(p, .{ .name = name, .section = ".maps" }); } /// Perform a lookup in *map* for an entry associated to *key*. diff --git a/src/btf_sanitizer/main.zig b/src/btf_sanitizer/main.zig index 074141d..f7e2e99 100644 --- a/src/btf_sanitizer/main.zig +++ b/src/btf_sanitizer/main.zig @@ -18,7 +18,7 @@ fn dbg_print(comptime fmt: []const u8, args: anytype) void { } } -fn libbpf_dbg_printf(level: c.libbpf_print_level, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(c.libbpf_print_fn_t).Optional.child).Pointer.child).Fn.params[2].type.?) callconv(.C) c_int { +fn libbpf_dbg_printf(level: c.libbpf_print_level, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(c.libbpf_print_fn_t).optional.child).pointer.child).@"fn".params[2].type.?) callconv(.C) c_int { if (!debug and level == c.LIBBPF_DEBUG) return 0; return c.vdprintf(std.io.getStdErr().handle, fmt, args); diff --git a/src/tests/root.zig b/src/tests/root.zig index 0209ff3..4800344 100644 --- a/src/tests/root.zig +++ b/src/tests/root.zig @@ -7,7 +7,7 @@ pub const libbpf = @cImport({ }); const build_options = @import("@build_options"); -pub fn dbg_printf(level: libbpf.libbpf_print_level, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(libbpf.libbpf_print_fn_t).Optional.child).Pointer.child).Fn.params[2].type.?) callconv(.C) c_int { +pub fn dbg_printf(level: libbpf.libbpf_print_level, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(libbpf.libbpf_print_fn_t).optional.child).pointer.child).@"fn".params[2].type.?) callconv(.C) c_int { if (!build_options.debug and level == libbpf.LIBBPF_DEBUG) return 0; return libbpf.vdprintf(std.io.getStdErr().handle, fmt, args); diff --git a/src/tools/trace/comm.zig b/src/tools/trace/comm.zig index 91c92ff..facaafe 100644 --- a/src/tools/trace/comm.zig +++ b/src/tools/trace/comm.zig @@ -59,8 +59,8 @@ pub fn Arg(comptime name: []const u8, comptime is_syscall: bool) type { var ti = @typeInfo(FT); inline while (comptime it.next()) |field_name| : (ti = @typeInfo(FT)) { - if (ti == .Optional) { - FT = ti.Optional.child; + if (ti == .optional) { + FT = ti.optional.child; ti = @typeInfo(FT); } @@ -81,8 +81,8 @@ pub fn Arg(comptime name: []const u8, comptime is_syscall: bool) type { if (is_string(FT)) return String; } return switch (ti) { - .Pointer => |info| info.child, - .Optional => |info| info.child, + .pointer => |info| info.child, + .optional => |info| info.child, else => FT, }; } @@ -115,14 +115,14 @@ pub fn Arg(comptime name: []const u8, comptime is_syscall: bool) type { } comptime var ti = @typeInfo(FT); - var src: usize = if (ti == .Pointer) @intFromPtr(arg) else @intFromPtr(&arg); + var src: usize = if (ti == .pointer) @intFromPtr(arg) else @intFromPtr(&arg); inline while (comptime it.next()) |field_name| { - if (ti == .Optional) { - FT = ti.Optional.child; + if (ti == .pptional) { + FT = ti.optional.child; ti = @typeInfo(FT); } - if (ti == .Pointer) { + if (ti == .pointer) { FT = ti.Pointer.child; ti = @typeInfo(FT); } diff --git a/src/tools/trace/trace.bpf.zig b/src/tools/trace/trace.bpf.zig index b2fe073..3a13410 100644 --- a/src/tools/trace/trace.bpf.zig +++ b/src/tools/trace/trace.bpf.zig @@ -60,7 +60,7 @@ fn generate(comptime name: []const u8, comptime id: u32, comptime with_stack: bo } comptime { - @export(_entry, .{ .name = name ++ if (is_syscall) "_syscall_entry" else "_kprobe_entry" }); + @export(&_entry, .{ .name = name ++ if (is_syscall) "_syscall_entry" else "_kprobe_entry" }); } fn _exit(ctx: *F.Ctx()) linksection(F.exit_section()) callconv(.C) c_long { @@ -95,7 +95,7 @@ fn generate(comptime name: []const u8, comptime id: u32, comptime with_stack: bo } } if (want_ret) { - @export(_exit, .{ .name = name ++ if (is_syscall) "_syscall_exit" else "_kprobe_exit" }); + @export(&_exit, .{ .name = name ++ if (is_syscall) "_syscall_exit" else "_kprobe_exit" }); } } }; diff --git a/src/tools/trace/trace.zig b/src/tools/trace/trace.zig index a672db3..9203253 100644 --- a/src/tools/trace/trace.zig +++ b/src/tools/trace/trace.zig @@ -21,7 +21,7 @@ const TF = @TypeOf(tracing_funcs[0]); var exiting = false; var debug = false; -fn dbg_printf(level: libbpf.libbpf_print_level, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(libbpf.libbpf_print_fn_t).Optional.child).Pointer.child).Fn.params[2].type.?) callconv(.C) c_int { +fn dbg_printf(level: libbpf.libbpf_print_level, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(libbpf.libbpf_print_fn_t).optional.child).pointer.child).@"fn".params[2].type.?) callconv(.C) c_int { if (!debug and level == libbpf.LIBBPF_DEBUG) return 0; return libbpf.vdprintf(std.io.getStdErr().handle, fmt, args); diff --git a/src/vmlinux_dumper/main.zig b/src/vmlinux_dumper/main.zig index 2f9348f..78332bc 100644 --- a/src/vmlinux_dumper/main.zig +++ b/src/vmlinux_dumper/main.zig @@ -16,7 +16,7 @@ fn dbg_print(comptime fmt: []const u8, args: anytype) void { } } -fn btf_dump_printf(ctx: ?*anyopaque, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(libbpf.btf_dump_printf_fn_t).Optional.child).Pointer.child).Fn.params[2].type.?) callconv(.C) void { +fn btf_dump_printf(ctx: ?*anyopaque, fmt: [*c]const u8, args: @typeInfo(@typeInfo(@typeInfo(libbpf.btf_dump_printf_fn_t).optional.child).pointer.child).@"fn".params[2].type.?) callconv(.C) void { const fd = @intFromPtr(ctx); _ = libbpf.vdprintf(@intCast(fd), fmt, args); } @@ -49,7 +49,7 @@ pub fn main() !void { } const output = try std.fs.createFileAbsolute(output_arg.?, .{}); defer output.close(); - if (debug) print("vmlinux_dumper: dump vmlinux.h to {s}\n", .{output_arg.?}); + dbg_print("dump vmlinux.zig to {s}\n", .{output_arg.?}); const d = libbpf.btf_dump__new(btf, btf_dump_printf, @ptrFromInt(@as(usize, @intCast(output.handle))), null); if (d == null) {