|
| 1 | +(* |
| 2 | + * Copyright 2026 Multikernel Technologies, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + *) |
| 16 | + |
| 17 | +(** Standard BPF helper functions. |
| 18 | +
|
| 19 | + These are the legacy BPF helpers invoked through a fixed helper ID. libbpf's |
| 20 | + [<bpf/bpf_helpers.h>] (via the auto-generated [bpf_helper_defs.h]) already |
| 21 | + declares every one of them as a function pointer, so the eBPF C backend must |
| 22 | + NOT emit its own [extern ... __ksym;] declaration for them - doing so clashes |
| 23 | + with the libbpf declaration ("redefinition as different kind of symbol"). |
| 24 | +
|
| 25 | + KernelScript uses the [extern] keyword for both kfuncs and helpers, so the |
| 26 | + backend consults this set to tell them apart: a name here is a helper (skip |
| 27 | + the __ksym declaration); anything else is a real kfunc (needs __ksym). |
| 28 | +
|
| 29 | + The list mirrors libbpf's [bpf_helper_defs.h], which is generated from the |
| 30 | + kernel's [__BPF_FUNC_MAPPER] and only ever grows. *) |
| 31 | + |
| 32 | +let helper_names = [ |
| 33 | + "bpf_bind"; |
| 34 | + "bpf_bprm_opts_set"; |
| 35 | + "bpf_btf_find_by_name_kind"; |
| 36 | + "bpf_cgrp_storage_delete"; |
| 37 | + "bpf_cgrp_storage_get"; |
| 38 | + "bpf_check_mtu"; |
| 39 | + "bpf_clone_redirect"; |
| 40 | + "bpf_copy_from_user"; |
| 41 | + "bpf_copy_from_user_task"; |
| 42 | + "bpf_csum_diff"; |
| 43 | + "bpf_csum_level"; |
| 44 | + "bpf_csum_update"; |
| 45 | + "bpf_current_task_under_cgroup"; |
| 46 | + "bpf_d_path"; |
| 47 | + "bpf_dynptr_data"; |
| 48 | + "bpf_dynptr_from_mem"; |
| 49 | + "bpf_dynptr_read"; |
| 50 | + "bpf_dynptr_write"; |
| 51 | + "bpf_fib_lookup"; |
| 52 | + "bpf_find_vma"; |
| 53 | + "bpf_for_each_map_elem"; |
| 54 | + "bpf_get_attach_cookie"; |
| 55 | + "bpf_get_branch_snapshot"; |
| 56 | + "bpf_get_cgroup_classid"; |
| 57 | + "bpf_get_current_ancestor_cgroup_id"; |
| 58 | + "bpf_get_current_cgroup_id"; |
| 59 | + "bpf_get_current_comm"; |
| 60 | + "bpf_get_current_pid_tgid"; |
| 61 | + "bpf_get_current_task"; |
| 62 | + "bpf_get_current_task_btf"; |
| 63 | + "bpf_get_current_uid_gid"; |
| 64 | + "bpf_get_func_arg"; |
| 65 | + "bpf_get_func_arg_cnt"; |
| 66 | + "bpf_get_func_ip"; |
| 67 | + "bpf_get_func_ret"; |
| 68 | + "bpf_get_hash_recalc"; |
| 69 | + "bpf_get_listener_sock"; |
| 70 | + "bpf_get_local_storage"; |
| 71 | + "bpf_get_netns_cookie"; |
| 72 | + "bpf_get_ns_current_pid_tgid"; |
| 73 | + "bpf_get_numa_node_id"; |
| 74 | + "bpf_get_prandom_u32"; |
| 75 | + "bpf_get_retval"; |
| 76 | + "bpf_get_route_realm"; |
| 77 | + "bpf_get_smp_processor_id"; |
| 78 | + "bpf_get_socket_cookie"; |
| 79 | + "bpf_get_socket_uid"; |
| 80 | + "bpf_getsockopt"; |
| 81 | + "bpf_get_stack"; |
| 82 | + "bpf_get_stackid"; |
| 83 | + "bpf_get_task_stack"; |
| 84 | + "bpf_ima_file_hash"; |
| 85 | + "bpf_ima_inode_hash"; |
| 86 | + "bpf_inode_storage_delete"; |
| 87 | + "bpf_inode_storage_get"; |
| 88 | + "bpf_jiffies64"; |
| 89 | + "bpf_kallsyms_lookup_name"; |
| 90 | + "bpf_kptr_xchg"; |
| 91 | + "bpf_ktime_get_boot_ns"; |
| 92 | + "bpf_ktime_get_coarse_ns"; |
| 93 | + "bpf_ktime_get_ns"; |
| 94 | + "bpf_ktime_get_tai_ns"; |
| 95 | + "bpf_l3_csum_replace"; |
| 96 | + "bpf_l4_csum_replace"; |
| 97 | + "bpf_load_hdr_opt"; |
| 98 | + "bpf_loop"; |
| 99 | + "bpf_lwt_push_encap"; |
| 100 | + "bpf_lwt_seg6_action"; |
| 101 | + "bpf_lwt_seg6_adjust_srh"; |
| 102 | + "bpf_lwt_seg6_store_bytes"; |
| 103 | + "bpf_map_delete_elem"; |
| 104 | + "bpf_map_lookup_elem"; |
| 105 | + "bpf_map_lookup_percpu_elem"; |
| 106 | + "bpf_map_peek_elem"; |
| 107 | + "bpf_map_pop_elem"; |
| 108 | + "bpf_map_push_elem"; |
| 109 | + "bpf_map_update_elem"; |
| 110 | + "bpf_msg_apply_bytes"; |
| 111 | + "bpf_msg_cork_bytes"; |
| 112 | + "bpf_msg_pop_data"; |
| 113 | + "bpf_msg_pull_data"; |
| 114 | + "bpf_msg_push_data"; |
| 115 | + "bpf_msg_redirect_hash"; |
| 116 | + "bpf_msg_redirect_map"; |
| 117 | + "bpf_override_return"; |
| 118 | + "bpf_per_cpu_ptr"; |
| 119 | + "bpf_perf_event_output"; |
| 120 | + "bpf_perf_event_read"; |
| 121 | + "bpf_perf_event_read_value"; |
| 122 | + "bpf_perf_prog_read_value"; |
| 123 | + "bpf_probe_read"; |
| 124 | + "bpf_probe_read_kernel"; |
| 125 | + "bpf_probe_read_kernel_str"; |
| 126 | + "bpf_probe_read_str"; |
| 127 | + "bpf_probe_read_user"; |
| 128 | + "bpf_probe_read_user_str"; |
| 129 | + "bpf_probe_write_user"; |
| 130 | + "bpf_rc_keydown"; |
| 131 | + "bpf_rc_pointer_rel"; |
| 132 | + "bpf_rc_repeat"; |
| 133 | + "bpf_read_branch_records"; |
| 134 | + "bpf_redirect"; |
| 135 | + "bpf_redirect_map"; |
| 136 | + "bpf_redirect_neigh"; |
| 137 | + "bpf_redirect_peer"; |
| 138 | + "bpf_reserve_hdr_opt"; |
| 139 | + "bpf_ringbuf_discard"; |
| 140 | + "bpf_ringbuf_discard_dynptr"; |
| 141 | + "bpf_ringbuf_output"; |
| 142 | + "bpf_ringbuf_query"; |
| 143 | + "bpf_ringbuf_reserve"; |
| 144 | + "bpf_ringbuf_reserve_dynptr"; |
| 145 | + "bpf_ringbuf_submit"; |
| 146 | + "bpf_ringbuf_submit_dynptr"; |
| 147 | + "bpf_send_signal"; |
| 148 | + "bpf_send_signal_thread"; |
| 149 | + "bpf_seq_printf"; |
| 150 | + "bpf_seq_printf_btf"; |
| 151 | + "bpf_seq_write"; |
| 152 | + "bpf_set_hash"; |
| 153 | + "bpf_set_hash_invalid"; |
| 154 | + "bpf_set_retval"; |
| 155 | + "bpf_setsockopt"; |
| 156 | + "bpf_sk_ancestor_cgroup_id"; |
| 157 | + "bpf_sk_assign"; |
| 158 | + "bpf_skb_adjust_room"; |
| 159 | + "bpf_skb_ancestor_cgroup_id"; |
| 160 | + "bpf_skb_cgroup_classid"; |
| 161 | + "bpf_skb_cgroup_id"; |
| 162 | + "bpf_skb_change_head"; |
| 163 | + "bpf_skb_change_proto"; |
| 164 | + "bpf_skb_change_tail"; |
| 165 | + "bpf_skb_change_type"; |
| 166 | + "bpf_skb_ecn_set_ce"; |
| 167 | + "bpf_skb_get_tunnel_key"; |
| 168 | + "bpf_skb_get_tunnel_opt"; |
| 169 | + "bpf_skb_get_xfrm_state"; |
| 170 | + "bpf_skb_load_bytes"; |
| 171 | + "bpf_skb_load_bytes_relative"; |
| 172 | + "bpf_skb_output"; |
| 173 | + "bpf_skb_pull_data"; |
| 174 | + "bpf_skb_set_tstamp"; |
| 175 | + "bpf_skb_set_tunnel_key"; |
| 176 | + "bpf_skb_set_tunnel_opt"; |
| 177 | + "bpf_skb_store_bytes"; |
| 178 | + "bpf_skb_under_cgroup"; |
| 179 | + "bpf_skb_vlan_pop"; |
| 180 | + "bpf_skb_vlan_push"; |
| 181 | + "bpf_sk_cgroup_id"; |
| 182 | + "bpf_skc_lookup_tcp"; |
| 183 | + "bpf_skc_to_mptcp_sock"; |
| 184 | + "bpf_skc_to_tcp6_sock"; |
| 185 | + "bpf_skc_to_tcp_request_sock"; |
| 186 | + "bpf_skc_to_tcp_sock"; |
| 187 | + "bpf_skc_to_tcp_timewait_sock"; |
| 188 | + "bpf_skc_to_udp6_sock"; |
| 189 | + "bpf_skc_to_unix_sock"; |
| 190 | + "bpf_sk_fullsock"; |
| 191 | + "bpf_sk_lookup_tcp"; |
| 192 | + "bpf_sk_lookup_udp"; |
| 193 | + "bpf_sk_redirect_hash"; |
| 194 | + "bpf_sk_redirect_map"; |
| 195 | + "bpf_sk_release"; |
| 196 | + "bpf_sk_select_reuseport"; |
| 197 | + "bpf_sk_storage_delete"; |
| 198 | + "bpf_sk_storage_get"; |
| 199 | + "bpf_snprintf"; |
| 200 | + "bpf_snprintf_btf"; |
| 201 | + "bpf_sock_from_file"; |
| 202 | + "bpf_sock_hash_update"; |
| 203 | + "bpf_sock_map_update"; |
| 204 | + "bpf_sock_ops_cb_flags_set"; |
| 205 | + "bpf_spin_lock"; |
| 206 | + "bpf_spin_unlock"; |
| 207 | + "bpf_store_hdr_opt"; |
| 208 | + "bpf_strncmp"; |
| 209 | + "bpf_strtol"; |
| 210 | + "bpf_strtoul"; |
| 211 | + "bpf_sys_bpf"; |
| 212 | + "bpf_sys_close"; |
| 213 | + "bpf_sysctl_get_current_value"; |
| 214 | + "bpf_sysctl_get_name"; |
| 215 | + "bpf_sysctl_get_new_value"; |
| 216 | + "bpf_sysctl_set_new_value"; |
| 217 | + "bpf_tail_call"; |
| 218 | + "bpf_task_pt_regs"; |
| 219 | + "bpf_task_storage_delete"; |
| 220 | + "bpf_task_storage_get"; |
| 221 | + "bpf_tcp_check_syncookie"; |
| 222 | + "bpf_tcp_gen_syncookie"; |
| 223 | + "bpf_tcp_raw_check_syncookie_ipv4"; |
| 224 | + "bpf_tcp_raw_check_syncookie_ipv6"; |
| 225 | + "bpf_tcp_raw_gen_syncookie_ipv4"; |
| 226 | + "bpf_tcp_raw_gen_syncookie_ipv6"; |
| 227 | + "bpf_tcp_send_ack"; |
| 228 | + "bpf_tcp_sock"; |
| 229 | + "bpf_this_cpu_ptr"; |
| 230 | + "bpf_timer_cancel"; |
| 231 | + "bpf_timer_init"; |
| 232 | + "bpf_timer_set_callback"; |
| 233 | + "bpf_timer_start"; |
| 234 | + "bpf_trace_printk"; |
| 235 | + "bpf_trace_vprintk"; |
| 236 | + "bpf_user_ringbuf_drain"; |
| 237 | + "bpf_xdp_adjust_head"; |
| 238 | + "bpf_xdp_adjust_meta"; |
| 239 | + "bpf_xdp_adjust_tail"; |
| 240 | + "bpf_xdp_get_buff_len"; |
| 241 | + "bpf_xdp_load_bytes"; |
| 242 | + "bpf_xdp_output"; |
| 243 | + "bpf_xdp_store_bytes"; |
| 244 | +] |
| 245 | + |
| 246 | +let helper_set = |
| 247 | + let tbl = Hashtbl.create 256 in |
| 248 | + List.iter (fun name -> Hashtbl.replace tbl name ()) helper_names; |
| 249 | + tbl |
| 250 | + |
| 251 | +(** [is_bpf_helper name] is true if [name] is a standard BPF helper already |
| 252 | + declared by libbpf's bpf_helpers.h, and therefore must not be re-declared |
| 253 | + as a [__ksym] extern by the eBPF C backend. *) |
| 254 | +let is_bpf_helper name = Hashtbl.mem helper_set name |
0 commit comments