This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const bpf = @import("bpf"); | |
const mem = std.mem; | |
usingnamespace @import("common.zig"); | |
const os = std.os; | |
const assert = std.debug.assert; | |
const c = @cImport({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (self.progs.items) |*prog| { | |
const rel_name = try std.mem.join(self.allocator, "", &[_][]const u8{ ".rel", prog.name }); | |
defer self.allocator.free(rel_name); | |
const rel_section: *Elf.Section = for (self.elf.relos.items) |relo| { | |
if (mem.eql(u8, self.elf.get_section_name(relo), rel_name)) { | |
break relo; | |
} | |
} else continue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ llvm-objdump -d src/probe.o | |
src/probe.o: file format ELF64-BPF | |
Disassembly of section socket1: | |
0000000000000000 bpf_prog: | |
0: bf 16 00 00 00 00 00 00 r6 = r1 | |
1: 85 00 00 00 05 00 00 00 call 5 | |
2: 7b 0a f8 ff 00 00 00 00 *(u64 *)(r10 - 8) = r0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub const Insn = packed struct { | |
code: u8, | |
dst: u4, | |
src: u4, | |
off: i16, | |
imm: i32, | |
}; | |
pub const MapDef = extern struct { | |
type: u32, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Builder = std.build.Builder; | |
const builtin = @import("builtin"); | |
pub fn build(b: *Builder) void { | |
const target = b.standardTargetOptions(.{}); | |
const obj = b.addObject("probe", "src/probe.zig"); | |
obj.setTarget(std.zig.CrossTarget{ | |
.cpu_arch = switch ((target.cpu_arch orelse builtin.arch).endian()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ llvm-objdump --section-headers src/probe.o | |
src/probe.o: file format ELF64-BPF | |
Sections: | |
Idx Name Size VMA Type | |
0 00000000 0000000000000000 | |
1 .text 00000000 0000000000000000 TEXT | |
2 socket1 00000070 0000000000000000 TEXT | |
3 .relsocket1 00000010 0000000000000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const mem = std.mem | |
usingnamespace @import("bpf"); | |
export var events linksection("maps") = PerfEventArray.init(256, 0); | |
export fn bpf_prog(ctx: *SkBuff) linksection("socket1") c_int { | |
var time = ktime_get_ns(); | |
events.event_output(ctx, F_CURRENT_CPU, mem.asBytes(&time)) catch {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-2.0 | |
// Copyright (c) 2020 Matt Knight | |
// | |
// Base on the opensnoop probe as part of libbpf-tools | |
// Copyright (c) 2019 Facebook | |
// Copyright (c) 2020 Netflix | |
usingnamespace BPF.kern; | |
const std = @import("std"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const bpf = @import("bpf"); | |
const mem = std.mem; | |
usingnamespace @import("common.zig"); | |
const BPF = std.os.linux.BPF; | |
const os = std.os; | |
const assert = std.debug.assert; |