Commit 278ab258 authored by Alastair Robertson's avatar Alastair Robertson

Add comm builtin

parent a28012be
...@@ -60,6 +60,12 @@ void CodegenLLVM::visit(Builtin &builtin) ...@@ -60,6 +60,12 @@ void CodegenLLVM::visit(Builtin &builtin)
expr_ = b_.CreateLShr(uidgid, 32); expr_ = b_.CreateLShr(uidgid, 32);
} }
} }
else if (builtin.ident == "comm")
{
AllocaInst *buf = b_.CreateAllocaBPF(builtin.type, "comm");
b_.CreateGetCurrentComm(buf, b_.getInt64(builtin.type.size));
expr_ = buf;
}
else if (!builtin.ident.compare(0, 3, "arg") && builtin.ident.size() == 4 && else if (!builtin.ident.compare(0, 3, "arg") && builtin.ident.size() == 4 &&
builtin.ident.at(3) >= '0' && builtin.ident.at(3) <= '9') builtin.ident.at(3) >= '0' && builtin.ident.at(3) <= '9')
{ {
......
...@@ -250,5 +250,21 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx, bool ustack) ...@@ -250,5 +250,21 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx, bool ustack)
return CreateCall(getstackid_func, {ctx, map_ptr, flags_val}, "get_stackid"); return CreateCall(getstackid_func, {ctx, map_ptr, flags_val}, "get_stackid");
} }
void IRBuilderBPF::CreateGetCurrentComm(AllocaInst *buf, Value *size)
{
// int bpf_get_current_comm(char *buf, int size_of_buf)
// Return: 0 on success or negative error
FunctionType *getcomm_func_type = FunctionType::get(
getInt64Ty(),
{getInt8PtrTy(), getInt64Ty()},
false);
PointerType *getcomm_func_ptr_type = PointerType::get(getcomm_func_type, 0);
Constant *getcomm_func = ConstantExpr::getCast(
Instruction::IntToPtr,
getInt64(BPF_FUNC_get_current_comm),
getcomm_func_ptr_type);
CreateCall(getcomm_func, {buf, size}, "get_comm");
}
} // namespace ast } // namespace ast
} // namespace bpftrace } // namespace bpftrace
...@@ -31,6 +31,7 @@ public: ...@@ -31,6 +31,7 @@ public:
CallInst *CreateGetPidTgid(); CallInst *CreateGetPidTgid();
CallInst *CreateGetUidGid(); CallInst *CreateGetUidGid();
CallInst *CreateGetStackId(Value *ctx, bool ustack); CallInst *CreateGetStackId(Value *ctx, bool ustack);
void CreateGetCurrentComm(AllocaInst *buf, Value *size);
private: private:
Module &module_; Module &module_;
......
...@@ -39,6 +39,9 @@ void SemanticAnalyser::visit(Builtin &builtin) ...@@ -39,6 +39,9 @@ void SemanticAnalyser::visit(Builtin &builtin)
builtin.type = SizedType(Type::ustack, 8); builtin.type = SizedType(Type::ustack, 8);
needs_stackid_map_ = true; needs_stackid_map_ = true;
} }
else if (builtin.ident == "comm") {
builtin.type = SizedType(Type::string, STRING_SIZE);
}
else if (!builtin.ident.compare(0, 3, "arg") && builtin.ident.size() == 4 && else if (!builtin.ident.compare(0, 3, "arg") && builtin.ident.size() == 4 &&
builtin.ident.at(3) >= '0' && builtin.ident.at(3) <= '9') { builtin.ident.at(3) >= '0' && builtin.ident.at(3) <= '9') {
int arg_num = atoi(builtin.ident.substr(3).c_str()); int arg_num = atoi(builtin.ident.substr(3).c_str());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment