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
f0d3ae2c
Commit
f0d3ae2c
authored
Jul 22, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass sizes to IRBuilderBPF as size_t's instead of LLVM Int64's
parent
3f6a1c03
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
24 deletions
+24
-24
src/codegen_llvm.cpp
src/codegen_llvm.cpp
+8
-8
src/irbuilderbpf.cpp
src/irbuilderbpf.cpp
+11
-11
src/irbuilderbpf.h
src/irbuilderbpf.h
+5
-5
No files found.
src/codegen_llvm.cpp
View file @
f0d3ae2c
...
...
@@ -63,7 +63,7 @@ void CodegenLLVM::visit(Builtin &builtin)
else
if
(
builtin
.
ident
==
"comm"
)
{
AllocaInst
*
buf
=
b_
.
CreateAllocaBPF
(
builtin
.
type
,
"comm"
);
b_
.
CreateGetCurrentComm
(
buf
,
b
_
.
getInt64
(
builtin
.
type
.
size
)
);
b_
.
CreateGetCurrentComm
(
buf
,
b
uiltin
.
type
.
size
);
expr_
=
buf
;
}
else
if
(
!
builtin
.
ident
.
compare
(
0
,
3
,
"arg"
)
&&
builtin
.
ident
.
size
()
==
4
&&
...
...
@@ -74,7 +74,7 @@ void CodegenLLVM::visit(Builtin &builtin)
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
builtin
.
type
,
builtin
.
ident
);
int
offset
=
arch
::
arg_offset
(
arg_num
)
*
sizeof
(
uintptr_t
);
Value
*
src
=
b_
.
CreateGEP
(
ctx_
,
b_
.
getInt64
(
offset
));
b_
.
CreateProbeRead
(
dst
,
b_
.
getInt64
(
8
)
,
src
);
b_
.
CreateProbeRead
(
dst
,
8
,
src
);
expr_
=
b_
.
CreateLoad
(
dst
);
}
else
if
(
builtin
.
ident
==
"retval"
)
...
...
@@ -82,7 +82,7 @@ void CodegenLLVM::visit(Builtin &builtin)
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
builtin
.
type
,
builtin
.
ident
);
int
offset
=
arch
::
ret_offset
()
*
sizeof
(
uintptr_t
);
Value
*
src
=
b_
.
CreateGEP
(
ctx_
,
b_
.
getInt64
(
offset
));
b_
.
CreateProbeRead
(
dst
,
b_
.
getInt64
(
8
)
,
src
);
b_
.
CreateProbeRead
(
dst
,
8
,
src
);
expr_
=
b_
.
CreateLoad
(
dst
);
}
else
...
...
@@ -127,9 +127,9 @@ void CodegenLLVM::visit(Call &call)
else
if
(
call
.
func
==
"str"
)
{
AllocaInst
*
buf
=
b_
.
CreateAllocaBPF
(
call
.
type
,
"str"
);
b_
.
CreateMemset
(
buf
,
b_
.
getInt8
(
0
),
b_
.
getInt64
(
call
.
type
.
size
)
);
b_
.
CreateMemset
(
buf
,
b_
.
getInt8
(
0
),
call
.
type
.
size
);
call
.
vargs
->
front
()
->
accept
(
*
this
);
b_
.
CreateProbeReadStr
(
buf
,
b_
.
getInt64
(
call
.
type
.
size
)
,
expr_
);
b_
.
CreateProbeReadStr
(
buf
,
call
.
type
.
size
,
expr_
);
expr_
=
buf
;
}
else
...
...
@@ -202,7 +202,7 @@ void CodegenLLVM::visit(Unop &unop)
case
bpftrace
:
:
Parser
::
token
::
MUL
:
{
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
unop
.
expr
->
type
,
"deref"
);
b_
.
CreateProbeRead
(
dst
,
b_
.
getInt64
(
8
)
,
expr_
);
b_
.
CreateProbeRead
(
dst
,
8
,
expr_
);
expr_
=
b_
.
CreateLoad
(
dst
);
break
;
}
...
...
@@ -308,7 +308,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
expr
->
accept
(
*
this
);
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
if
(
expr
->
type
.
type
==
Type
::
string
)
b_
.
CreateMemcpy
(
offset_val
,
expr_
,
b_
.
getInt64
(
expr
->
type
.
size
)
);
b_
.
CreateMemcpy
(
offset_val
,
expr_
,
expr
->
type
.
size
);
else
b_
.
CreateStore
(
expr_
,
offset_val
);
offset
+=
expr
->
type
.
size
;
...
...
@@ -338,7 +338,7 @@ AllocaInst *CodegenLLVM::getQuantizeMapKey(Map &map, Value *log2)
expr
->
accept
(
*
this
);
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
if
(
expr
->
type
.
type
==
Type
::
string
)
b_
.
CreateMemcpy
(
offset_val
,
expr_
,
b_
.
getInt64
(
expr
->
type
.
size
)
);
b_
.
CreateMemcpy
(
offset_val
,
expr_
,
expr
->
type
.
size
);
else
b_
.
CreateStore
(
expr_
,
offset_val
);
offset
+=
expr
->
type
.
size
;
...
...
src/irbuilderbpf.cpp
View file @
f0d3ae2c
...
...
@@ -86,16 +86,16 @@ AllocaInst *IRBuilderBPF::CreateAllocaMapKey(int bytes, const std::string &name)
return
new
AllocaInst
(
ty
,
name
,
&
entry_block
.
front
());
}
void
IRBuilderBPF
::
CreateMemcpy
(
Value
*
dst
,
Value
*
src
,
Value
*
len
)
void
IRBuilderBPF
::
CreateMemcpy
(
Value
*
dst
,
Value
*
src
,
size_t
len
)
{
Function
*
memcpy_func
=
module_
.
getFunction
(
"llvm.memcpy.p0i8.p0i8.i64"
);
CreateCall
(
memcpy_func
,
{
dst
,
src
,
len
,
getInt32
(
1
),
getInt1
(
0
)},
"memcpy"
);
CreateCall
(
memcpy_func
,
{
dst
,
src
,
getInt64
(
len
)
,
getInt32
(
1
),
getInt1
(
0
)},
"memcpy"
);
}
void
IRBuilderBPF
::
CreateMemset
(
Value
*
dst
,
Value
*
val
,
Value
*
len
)
void
IRBuilderBPF
::
CreateMemset
(
Value
*
dst
,
Value
*
val
,
size_t
len
)
{
Function
*
memset_func
=
module_
.
getFunction
(
"llvm.memset.p0i8.i64"
);
CreateCall
(
memset_func
,
{
dst
,
val
,
len
,
getInt32
(
1
),
getInt1
(
0
)},
"memset"
);
CreateCall
(
memset_func
,
{
dst
,
val
,
getInt64
(
len
)
,
getInt32
(
1
),
getInt1
(
0
)},
"memset"
);
}
CallInst
*
IRBuilderBPF
::
CreateBpfPseudoCall
(
int
mapfd
)
...
...
@@ -188,7 +188,7 @@ void IRBuilderBPF::CreateMapDeleteElem(Map &map, AllocaInst *key)
CallInst
*
call
=
CreateCall
(
delete_func
,
{
map_ptr
,
key
},
"delete_elem"
);
}
void
IRBuilderBPF
::
CreateProbeRead
(
AllocaInst
*
dst
,
Value
*
size
,
Value
*
src
)
void
IRBuilderBPF
::
CreateProbeRead
(
AllocaInst
*
dst
,
size_t
size
,
Value
*
src
)
{
// int bpf_probe_read(void *dst, int size, void *src)
// Return: 0 on success or negative error
...
...
@@ -201,10 +201,10 @@ void IRBuilderBPF::CreateProbeRead(AllocaInst *dst, Value *size, Value *src)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_probe_read
),
proberead_func_ptr_type
);
CallInst
*
call
=
CreateCall
(
proberead_func
,
{
dst
,
size
,
src
},
"probe_read"
);
CallInst
*
call
=
CreateCall
(
proberead_func
,
{
dst
,
getInt64
(
size
)
,
src
},
"probe_read"
);
}
void
IRBuilderBPF
::
CreateProbeReadStr
(
AllocaInst
*
dst
,
Value
*
size
,
Value
*
src
)
void
IRBuilderBPF
::
CreateProbeReadStr
(
AllocaInst
*
dst
,
size_t
size
,
Value
*
src
)
{
// int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
FunctionType
*
probereadstr_func_type
=
FunctionType
::
get
(
...
...
@@ -216,7 +216,7 @@ void IRBuilderBPF::CreateProbeReadStr(AllocaInst *dst, Value *size, Value *src)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_probe_read_str
),
probereadstr_func_ptr_type
);
CallInst
*
call
=
CreateCall
(
probereadstr_func
,
{
dst
,
size
,
src
},
"probe_read_str"
);
CallInst
*
call
=
CreateCall
(
probereadstr_func
,
{
dst
,
getInt64
(
size
)
,
src
},
"probe_read_str"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetNs
()
...
...
@@ -271,7 +271,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx, bool ustack)
// Return: >= 0 stackid on success or negative error
FunctionType
*
getstackid_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
{
getInt8PtrTy
(),
getInt8PtrTy
(),
getInt
8Ptr
Ty
()},
{
getInt8PtrTy
(),
getInt8PtrTy
(),
getInt
64
Ty
()},
false
);
PointerType
*
getstackid_func_ptr_type
=
PointerType
::
get
(
getstackid_func_type
,
0
);
Constant
*
getstackid_func
=
ConstantExpr
::
getCast
(
...
...
@@ -281,7 +281,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx, bool ustack)
return
CreateCall
(
getstackid_func
,
{
ctx
,
map_ptr
,
flags_val
},
"get_stackid"
);
}
void
IRBuilderBPF
::
CreateGetCurrentComm
(
AllocaInst
*
buf
,
Value
*
size
)
void
IRBuilderBPF
::
CreateGetCurrentComm
(
AllocaInst
*
buf
,
size_t
size
)
{
// int bpf_get_current_comm(char *buf, int size_of_buf)
// Return: 0 on success or negative error
...
...
@@ -294,7 +294,7 @@ void IRBuilderBPF::CreateGetCurrentComm(AllocaInst *buf, Value *size)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_comm
),
getcomm_func_ptr_type
);
CreateCall
(
getcomm_func
,
{
buf
,
size
},
"get_comm"
);
CreateCall
(
getcomm_func
,
{
buf
,
getInt64
(
size
)
},
"get_comm"
);
}
}
// namespace ast
...
...
src/irbuilderbpf.h
View file @
f0d3ae2c
...
...
@@ -20,20 +20,20 @@ public:
AllocaInst
*
CreateAllocaBPF
(
const
SizedType
&
stype
,
const
std
::
string
&
name
=
""
);
AllocaInst
*
CreateAllocaMapKey
(
int
bytes
,
const
std
::
string
&
name
=
""
);
void
CreateMemcpy
(
Value
*
dst
,
Value
*
src
,
Value
*
len
);
void
CreateMemset
(
Value
*
dst
,
Value
*
val
,
Value
*
len
);
void
CreateMemcpy
(
Value
*
dst
,
Value
*
src
,
size_t
len
);
void
CreateMemset
(
Value
*
dst
,
Value
*
val
,
size_t
len
);
CallInst
*
CreateBpfPseudoCall
(
int
mapfd
);
CallInst
*
CreateBpfPseudoCall
(
Map
&
map
);
LoadInst
*
CreateMapLookupElem
(
Map
&
map
,
AllocaInst
*
key
);
void
CreateMapUpdateElem
(
Map
&
map
,
AllocaInst
*
key
,
Value
*
val
);
void
CreateMapDeleteElem
(
Map
&
map
,
AllocaInst
*
key
);
void
CreateProbeRead
(
AllocaInst
*
dst
,
Value
*
size
,
Value
*
src
);
void
CreateProbeReadStr
(
AllocaInst
*
dst
,
Value
*
size
,
Value
*
src
);
void
CreateProbeRead
(
AllocaInst
*
dst
,
size_t
size
,
Value
*
src
);
void
CreateProbeReadStr
(
AllocaInst
*
dst
,
size_t
size
,
Value
*
src
);
CallInst
*
CreateGetNs
();
CallInst
*
CreateGetPidTgid
();
CallInst
*
CreateGetUidGid
();
CallInst
*
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
);
void
CreateGetCurrentComm
(
AllocaInst
*
buf
,
Value
*
size
);
void
CreateGetCurrentComm
(
AllocaInst
*
buf
,
size_t
size
);
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