| 96 | }; |
| 97 | |
| 98 | static int modify_return(ebpf::BPF &bpf) { |
| 99 | int prog_fd; |
| 100 | auto res = bpf.load_func("kmod_ret____x64_sys_openat", |
| 101 | BPF_PROG_TYPE_TRACING, prog_fd, BPF_F_SLEEPABLE); |
| 102 | if (!res.ok()) { |
| 103 | std::cerr << res.msg() << std::endl; |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | int attach_fd = bpf_attach_kfunc(prog_fd); |
| 108 | if (attach_fd < 0) { |
| 109 | std::cerr << "bpf_attach_kfunc failed: " << attach_fd << std::endl; |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | int ret = open("/bin/true", O_RDONLY); |
| 114 | if (ret >= 0 || errno != EINVAL) { |
| 115 | close(attach_fd); |
| 116 | std::cerr << "incorrect open result" << std::endl; |
| 117 | return 1; |
| 118 | } |
| 119 | |
| 120 | auto fname_table = bpf.get_array_table<struct fname_buf>("fname_table"); |
| 121 | uint32_t key = 0; |
| 122 | struct fname_buf val; |
| 123 | res = fname_table.get_value(key, val); |
| 124 | if (!res.ok()) { |
| 125 | close(attach_fd); |
| 126 | std::cerr << res.msg() << std::endl; |
| 127 | return 1; |
| 128 | } |
| 129 | std::cout << "opened file: " << val.buf << std::endl; |
| 130 | |
| 131 | // detach the kfunc. |
| 132 | close(attach_fd); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static int not_modify_return(ebpf::BPF &bpf) { |
| 137 | int prog_fd; |
no test coverage detected