Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
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
bcc
Commits
f3d3c94b
Commit
f3d3c94b
authored
Feb 22, 2018
by
4ast
Committed by
GitHub
Feb 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1602 from iovisor/yhs_dev2
add a BPFModule API to disable rw_engine sscanf/snprintf functions
parents
40fd6692
db7b8eb0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
11 deletions
+25
-11
src/cc/api/BPF.h
src/cc/api/BPF.h
+3
-2
src/cc/bpf_module.cc
src/cc/bpf_module.cc
+18
-7
src/cc/bpf_module.h
src/cc/bpf_module.h
+2
-1
tests/cc/test_array_table.cc
tests/cc/test_array_table.cc
+2
-1
No files found.
src/cc/api/BPF.h
View file @
f3d3c94b
...
...
@@ -45,8 +45,9 @@ class BPF {
public:
static
const
int
BPF_MAX_STACK_DEPTH
=
127
;
explicit
BPF
(
unsigned
int
flag
=
0
,
TableStorage
*
ts
=
nullptr
)
:
flag_
(
flag
),
bpf_module_
(
new
BPFModule
(
flag
,
ts
))
{}
explicit
BPF
(
unsigned
int
flag
=
0
,
TableStorage
*
ts
=
nullptr
,
bool
rw_engine_enabled
=
true
)
:
flag_
(
flag
),
bpf_module_
(
new
BPFModule
(
flag
,
ts
,
rw_engine_enabled
))
{}
StatusTuple
init
(
const
std
::
string
&
bpf_program
,
const
std
::
vector
<
std
::
string
>&
cflags
=
{},
const
std
::
vector
<
USDT
>&
usdt
=
{});
...
...
src/cc/bpf_module.cc
View file @
f3d3c94b
...
...
@@ -99,8 +99,9 @@ class MyMemoryManager : public SectionMemoryManager {
map
<
string
,
tuple
<
uint8_t
*
,
uintptr_t
>>
*
sections_
;
};
BPFModule
::
BPFModule
(
unsigned
flags
,
TableStorage
*
ts
)
BPFModule
::
BPFModule
(
unsigned
flags
,
TableStorage
*
ts
,
bool
rw_engine_enabled
)
:
flags_
(
flags
),
rw_engine_enabled_
(
rw_engine_enabled
),
used_b_loader_
(
false
),
ctx_
(
new
LLVMContext
),
id_
(
std
::
to_string
((
uintptr_t
)
this
)),
...
...
@@ -530,6 +531,8 @@ int BPFModule::annotate() {
}
StatusTuple
BPFModule
::
sscanf
(
string
fn_name
,
const
char
*
str
,
void
*
val
)
{
if
(
!
rw_engine_enabled_
)
return
StatusTuple
(
-
1
,
"rw_engine not enabled"
);
auto
fn
=
(
int
(
*
)(
const
char
*
,
void
*
))
rw_engine_
->
getFunctionAddress
(
fn_name
);
if
(
!
fn
)
...
...
@@ -542,6 +545,8 @@ StatusTuple BPFModule::sscanf(string fn_name, const char *str, void *val) {
StatusTuple
BPFModule
::
snprintf
(
string
fn_name
,
char
*
str
,
size_t
sz
,
const
void
*
val
)
{
if
(
!
rw_engine_enabled_
)
return
StatusTuple
(
-
1
,
"rw_engine not enabled"
);
auto
fn
=
(
int
(
*
)(
char
*
,
size_t
,
const
void
*
))
rw_engine_
->
getFunctionAddress
(
fn_name
);
if
(
!
fn
)
...
...
@@ -937,8 +942,10 @@ int BPFModule::load_b(const string &filename, const string &proto_filename) {
used_b_loader_
=
true
;
if
(
int
rc
=
b_loader
.
parse
(
&*
mod_
,
filename
,
proto_filename
,
*
ts_
,
id_
))
return
rc
;
if
(
int
rc
=
annotate
())
return
rc
;
if
(
rw_engine_enabled_
)
{
if
(
int
rc
=
annotate
())
return
rc
;
}
if
(
int
rc
=
finalize
())
return
rc
;
return
0
;
...
...
@@ -956,8 +963,10 @@ int BPFModule::load_c(const string &filename, const char *cflags[], int ncflags)
}
if
(
int
rc
=
load_cfile
(
filename
,
false
,
cflags
,
ncflags
))
return
rc
;
if
(
int
rc
=
annotate
())
return
rc
;
if
(
rw_engine_enabled_
)
{
if
(
int
rc
=
annotate
())
return
rc
;
}
if
(
int
rc
=
finalize
())
return
rc
;
return
0
;
...
...
@@ -971,8 +980,10 @@ int BPFModule::load_string(const string &text, const char *cflags[], int ncflags
}
if
(
int
rc
=
load_cfile
(
text
,
true
,
cflags
,
ncflags
))
return
rc
;
if
(
int
rc
=
annotate
())
return
rc
;
if
(
rw_engine_enabled_
)
{
if
(
int
rc
=
annotate
())
return
rc
;
}
if
(
int
rc
=
finalize
())
return
rc
;
...
...
src/cc/bpf_module.h
View file @
f3d3c94b
...
...
@@ -75,7 +75,7 @@ class BPFModule {
const
void
*
val
);
public:
BPFModule
(
unsigned
flags
,
TableStorage
*
ts
=
nullptr
);
BPFModule
(
unsigned
flags
,
TableStorage
*
ts
=
nullptr
,
bool
rw_engine_enabled
=
true
);
~
BPFModule
();
int
load_b
(
const
std
::
string
&
filename
,
const
std
::
string
&
proto_filename
);
int
load_c
(
const
std
::
string
&
filename
,
const
char
*
cflags
[],
int
ncflags
);
...
...
@@ -120,6 +120,7 @@ class BPFModule {
private:
unsigned
flags_
;
// 0x1 for printing
bool
rw_engine_enabled_
;
bool
used_b_loader_
;
std
::
string
filename_
;
std
::
string
proto_filename_
;
...
...
tests/cc/test_array_table.cc
View file @
f3d3c94b
...
...
@@ -27,7 +27,8 @@ TEST_CASE("test array table", "[array_table]") {
BPF_TABLE("array", int, int, myarray, 128);
)"
;
ebpf
::
BPF
bpf
;
// turn off the rw_engine
ebpf
::
BPF
bpf
(
0
,
nullptr
,
false
);
ebpf
::
StatusTuple
res
(
0
);
res
=
bpf
.
init
(
BPF_PROGRAM
);
REQUIRE
(
res
.
code
()
==
0
);
...
...
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