Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
77f34295
Commit
77f34295
authored
May 17, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codegen: Move remaining BPF function calls into IRBuilderBPF
parent
69216fe4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
31 deletions
+51
-31
src/codegen_llvm.cpp
src/codegen_llvm.cpp
+7
-30
src/irbuilderbpf.cpp
src/irbuilderbpf.cpp
+40
-0
src/irbuilderbpf.h
src/irbuilderbpf.h
+4
-1
No files found.
src/codegen_llvm.cpp
View file @
77f34295
...
...
@@ -20,53 +20,30 @@ void CodegenLLVM::visit(Builtin &builtin)
{
if
(
builtin
.
ident
==
"nsecs"
)
{
// u64 ktime_get_ns()
FunctionType
*
gettime_func_type
=
FunctionType
::
get
(
b_
.
getInt64Ty
(),
false
);
PointerType
*
gettime_func_ptr_type
=
PointerType
::
get
(
gettime_func_type
,
0
);
Constant
*
gettime_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
b_
.
getInt64
(
BPF_FUNC_ktime_get_ns
),
gettime_func_ptr_type
);
expr_
=
b_
.
CreateCall
(
gettime_func
);
expr_
=
b_
.
CreateGetNs
();
}
else
if
(
builtin
.
ident
==
"pid"
||
builtin
.
ident
==
"tid"
)
{
// u64 bpf_get_current_pid_tgid(void)
// Return: current->tgid << 32 | current->pid
FunctionType
*
getpidtgid_func_type
=
FunctionType
::
get
(
b_
.
getInt64Ty
(),
false
);
PointerType
*
getpidtgid_func_ptr_type
=
PointerType
::
get
(
getpidtgid_func_type
,
0
);
Constant
*
getpidtgid_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
b_
.
getInt64
(
BPF_FUNC_get_current_pid_tgid
),
getpidtgid_func_ptr_type
);
CallInst
*
call
=
b_
.
CreateCall
(
getpidtgid_func
);
Value
*
pidtgid
=
b_
.
CreateGetPidTgid
();
if
(
builtin
.
ident
==
"pid"
)
{
expr_
=
b_
.
CreateLShr
(
call
,
32
);
expr_
=
b_
.
CreateLShr
(
pidtgid
,
32
);
}
else
if
(
builtin
.
ident
==
"tid"
)
{
expr_
=
b_
.
CreateAnd
(
call
,
0xffffffff
);
expr_
=
b_
.
CreateAnd
(
pidtgid
,
0xffffffff
);
}
}
else
if
(
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
)
{
// u64 bpf_get_current_uid_gid(void)
// Return: current_gid << 32 | current_uid
FunctionType
*
getuidgid_func_type
=
FunctionType
::
get
(
b_
.
getInt64Ty
(),
false
);
PointerType
*
getuidgid_func_ptr_type
=
PointerType
::
get
(
getuidgid_func_type
,
0
);
Constant
*
getuidgid_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
b_
.
getInt64
(
BPF_FUNC_get_current_uid_gid
),
getuidgid_func_ptr_type
);
CallInst
*
call
=
b_
.
CreateCall
(
getuidgid_func
);
Value
*
uidgid
=
b_
.
CreateGetUidGid
();
if
(
builtin
.
ident
==
"uid"
)
{
expr_
=
b_
.
CreateAnd
(
call
,
0xffffffff
);
expr_
=
b_
.
CreateAnd
(
uidgid
,
0xffffffff
);
}
else
if
(
builtin
.
ident
==
"gid"
)
{
expr_
=
b_
.
CreateLShr
(
call
,
32
);
expr_
=
b_
.
CreateLShr
(
uidgid
,
32
);
}
}
else
...
...
src/irbuilderbpf.cpp
View file @
77f34295
...
...
@@ -106,6 +106,46 @@ void IRBuilderBPF::CreateMapUpdateElem(Map &map, Value *key, Value *val)
CallInst
*
call
=
CreateCall
(
update_func
,
{
map_ptr
,
key
,
val
,
flags
});
}
Value
*
IRBuilderBPF
::
CreateGetNs
()
{
// u64 ktime_get_ns()
// Return: current ktime
FunctionType
*
gettime_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
false
);
PointerType
*
gettime_func_ptr_type
=
PointerType
::
get
(
gettime_func_type
,
0
);
Constant
*
gettime_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_ktime_get_ns
),
gettime_func_ptr_type
);
return
CreateCall
(
gettime_func
);
}
Value
*
IRBuilderBPF
::
CreateGetPidTgid
()
{
// u64 bpf_get_current_pid_tgid(void)
// Return: current->tgid << 32 | current->pid
FunctionType
*
getpidtgid_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
false
);
PointerType
*
getpidtgid_func_ptr_type
=
PointerType
::
get
(
getpidtgid_func_type
,
0
);
Constant
*
getpidtgid_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_pid_tgid
),
getpidtgid_func_ptr_type
);
return
CreateCall
(
getpidtgid_func
);
}
Value
*
IRBuilderBPF
::
CreateGetUidGid
()
{
// u64 bpf_get_current_uid_gid(void)
// Return: current_gid << 32 | current_uid
FunctionType
*
getuidgid_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
false
);
PointerType
*
getuidgid_func_ptr_type
=
PointerType
::
get
(
getuidgid_func_type
,
0
);
Constant
*
getuidgid_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_uid_gid
),
getuidgid_func_ptr_type
);
return
CreateCall
(
getuidgid_func
);
}
}
// namespace ast
}
// namespace bpftrace
}
// namespace ebpf
src/irbuilderbpf.h
View file @
77f34295
...
...
@@ -21,7 +21,10 @@ public:
AllocaInst
*
CreateAllocaBPF
(
llvm
::
Type
*
ty
,
const
std
::
string
&
name
=
""
)
const
;
Value
*
CreateBpfPseudoCall
(
Map
&
map
);
Value
*
CreateMapLookupElem
(
Map
&
map
,
Value
*
key
);
void
CreateMapUpdateElem
(
Map
&
map
,
Value
*
key
,
Value
*
val
);
void
CreateMapUpdateElem
(
Map
&
map
,
Value
*
key
,
Value
*
val
);
Value
*
CreateGetNs
();
Value
*
CreateGetPidTgid
();
Value
*
CreateGetUidGid
();
private:
Module
&
module_
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment