Skip to content

Commit 5b7769d

Browse files
committed
Implement bpf_get_current_uid_gid_emitter
1 parent b7c1e92 commit 5b7769d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,33 @@ def bpf_get_smp_processor_id_emitter(
539539
return result, ir.IntType(32)
540540

541541

542+
@HelperHandlerRegistry.register("uid")
543+
def bpf_get_current_uid_gid_emitter(
544+
call,
545+
map_ptr,
546+
module,
547+
builder,
548+
func,
549+
local_sym_tab=None,
550+
struct_sym_tab=None,
551+
map_sym_tab=None,
552+
):
553+
"""
554+
Emit LLVM IR for bpf_get_current_uid_gid helper function call.
555+
"""
556+
helper_id = ir.Constant(ir.IntType(64), BPFHelperID.BPF_GET_CURRENT_UID_GID.value)
557+
fn_type = ir.FunctionType(ir.IntType(64), [], var_arg=False)
558+
fn_ptr_type = ir.PointerType(fn_type)
559+
fn_ptr = builder.inttoptr(helper_id, fn_ptr_type)
560+
result = builder.call(fn_ptr, [], tail=False)
561+
562+
# Extract the lower 32 bits (UID) using bitwise AND with 0xFFFFFFFF
563+
# TODO: return both UID and GID if we end up needing GID somewhere
564+
mask = ir.Constant(ir.IntType(64), 0xFFFFFFFF)
565+
pid = builder.and_(result, mask)
566+
return pid, ir.IntType(64)
567+
568+
542569
def handle_helper_call(
543570
call,
544571
module,

0 commit comments

Comments
 (0)