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
b6b9c6db
Commit
b6b9c6db
authored
May 04, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move FileDesc to common.h
parent
a09c4913
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
42 deletions
+84
-42
src/cc/bpf_module.cc
src/cc/bpf_module.cc
+4
-4
src/cc/common.cc
src/cc/common.cc
+34
-0
src/cc/common.h
src/cc/common.h
+23
-0
src/cc/frontends/b/codegen_llvm.cc
src/cc/frontends/b/codegen_llvm.cc
+2
-1
src/cc/table_desc.h
src/cc/table_desc.h
+21
-37
No files found.
src/cc/bpf_module.cc
View file @
b6b9c6db
...
...
@@ -329,7 +329,7 @@ unique_ptr<ExecutionEngine> BPFModule::finalize_rw(unique_ptr<Module> m) {
// load an entire c file as a module
int
BPFModule
::
load_cfile
(
const
string
&
file
,
bool
in_memory
,
const
char
*
cflags
[],
int
ncflags
)
{
clang_loader_
=
make_unique
<
ClangLoader
>
(
&*
ctx_
,
flags_
);
clang_loader_
=
ebpf
::
make_unique
<
ClangLoader
>
(
&*
ctx_
,
flags_
);
if
(
clang_loader_
->
parse
(
&
mod_
,
*
ts_
,
file
,
in_memory
,
cflags
,
ncflags
,
id_
))
return
-
1
;
return
0
;
...
...
@@ -341,7 +341,7 @@ int BPFModule::load_cfile(const string &file, bool in_memory, const char *cflags
// Load in a pre-built list of functions into the initial Module object, then
// build an ExecutionEngine.
int
BPFModule
::
load_includes
(
const
string
&
text
)
{
clang_loader_
=
make_unique
<
ClangLoader
>
(
&*
ctx_
,
flags_
);
clang_loader_
=
ebpf
::
make_unique
<
ClangLoader
>
(
&*
ctx_
,
flags_
);
if
(
clang_loader_
->
parse
(
&
mod_
,
*
ts_
,
text
,
true
,
nullptr
,
0
,
""
))
return
-
1
;
return
0
;
...
...
@@ -353,7 +353,7 @@ int BPFModule::annotate() {
fn
->
addFnAttr
(
Attribute
::
AlwaysInline
);
// separate module to hold the reader functions
auto
m
=
make_unique
<
Module
>
(
"sscanf"
,
*
ctx_
);
auto
m
=
ebpf
::
make_unique
<
Module
>
(
"sscanf"
,
*
ctx_
);
struct
llvmfnpointers
{
llvm
::
Function
*
key_sscanf
;
...
...
@@ -461,7 +461,7 @@ int BPFModule::finalize() {
string
err
;
EngineBuilder
builder
(
move
(
mod_
));
builder
.
setErrorStr
(
&
err
);
builder
.
setMCJITMemoryManager
(
make_unique
<
MyMemoryManager
>
(
&
sections_
));
builder
.
setMCJITMemoryManager
(
ebpf
::
make_unique
<
MyMemoryManager
>
(
&
sections_
));
builder
.
setMArch
(
"bpf"
);
builder
.
setUseOrcMCJITReplacement
(
true
);
engine_
=
unique_ptr
<
ExecutionEngine
>
(
builder
.
create
());
...
...
src/cc/common.cc
View file @
b6b9c6db
...
...
@@ -15,6 +15,8 @@
*/
#include <fstream>
#include <sstream>
#include <unistd.h>
#include "common.h"
namespace
ebpf
{
...
...
@@ -47,5 +49,37 @@ std::vector<int> get_possible_cpus() {
return
read_cpu_range
(
"/sys/devices/system/cpu/possible"
);
}
FileDesc
::
FileDesc
(
int
fd
)
:
fd_
(
fd
)
{}
FileDesc
::
FileDesc
(
FileDesc
&&
that
)
:
fd_
(
-
1
)
{
*
this
=
std
::
move
(
that
);
}
FileDesc
::~
FileDesc
()
{
if
(
fd_
>=
0
)
::
close
(
fd_
);
}
FileDesc
&
FileDesc
::
operator
=
(
int
fd
)
{
if
(
fd_
>=
0
)
::
close
(
fd_
);
fd_
=
fd
;
return
*
this
;
}
FileDesc
&
FileDesc
::
operator
=
(
FileDesc
&&
that
)
{
if
(
fd_
>=
0
)
::
close
(
fd_
);
fd_
=
that
.
fd_
;
that
.
fd_
=
-
1
;
return
*
this
;
}
FileDesc
FileDesc
::
dup
()
const
{
int
dup_fd
=
::
dup
(
fd_
);
return
FileDesc
(
dup_fd
);
}
FileDesc
::
operator
int
()
{
return
fd_
;
}
FileDesc
::
operator
int
()
const
{
return
fd_
;
}
}
// namespace ebpf
src/cc/common.h
View file @
b6b9c6db
...
...
@@ -33,4 +33,27 @@ std::vector<int> get_online_cpus();
std
::
vector
<
int
>
get_possible_cpus
();
/// FileDesc is a helper class for managing open file descriptors. Copy is
/// disallowed (call dup instead), and cleanup happens automatically.
class
FileDesc
{
public:
explicit
FileDesc
(
int
fd
=
-
1
);
FileDesc
(
FileDesc
&&
that
);
FileDesc
(
const
FileDesc
&
that
)
=
delete
;
~
FileDesc
();
FileDesc
&
operator
=
(
int
fd
);
FileDesc
&
operator
=
(
FileDesc
&&
that
);
FileDesc
&
operator
=
(
const
FileDesc
&
that
)
=
delete
;
operator
int
();
operator
int
()
const
;
FileDesc
dup
()
const
;
private:
int
fd_
;
};
}
// namespace ebpf
src/cc/frontends/b/codegen_llvm.cc
View file @
b6b9c6db
...
...
@@ -33,6 +33,7 @@
#include <llvm/IR/Module.h>
#include "bcc_exception.h"
#include "common.h"
#include "codegen_llvm.h"
#include "lexer.h"
#include "libbpf.h"
...
...
@@ -1244,7 +1245,7 @@ StatusTuple CodegenLLVM::visit(Node *root, TableStorage &ts, const string &id) {
map_type
=
BPF_MAP_TYPE_ARRAY
;
ts
.
Insert
(
Path
({
id
,
table
.
first
->
id_
->
name_
}),
{
table
.
first
->
id_
->
name_
,
table_fds_
[
table
.
first
]
,
map_type
,
table
.
first
->
id_
->
name_
,
FileDesc
(
table_fds_
[
table
.
first
])
,
map_type
,
table
.
first
->
key_type_
->
bit_width_
>>
3
,
table
.
first
->
leaf_type_
->
bit_width_
>>
3
,
table
.
first
->
size_
,
0
,
});
...
...
src/cc/table_desc.h
View file @
b6b9c6db
...
...
@@ -21,6 +21,8 @@
#include <memory>
#include <string>
#include "common.h"
namespace
llvm
{
class
Function
;
}
...
...
@@ -32,41 +34,6 @@ class QualType;
namespace
ebpf
{
class
TableDesc
;
/// FileDesc is a helper class for managing open file descriptors. Copy is
/// disallowed (call dup instead), and cleanup happens automatically.
class
FileDesc
{
friend
TableDesc
;
private:
FileDesc
&
operator
=
(
const
FileDesc
&
that
)
{
fd
=
::
dup
(
that
.
fd
);
return
*
this
;
}
FileDesc
(
const
FileDesc
&
that
)
{
*
this
=
that
;
}
public:
FileDesc
(
int
fd
=
-
1
)
:
fd
(
fd
)
{}
FileDesc
&
operator
=
(
FileDesc
&&
that
)
{
fd
=
that
.
fd
;
that
.
fd
=
-
1
;
return
*
this
;
}
FileDesc
(
FileDesc
&&
that
)
{
*
this
=
std
::
move
(
that
);
}
~
FileDesc
()
{
if
(
fd
>=
0
)
::
close
(
fd
);
}
FileDesc
dup
()
const
{
return
FileDesc
(
*
this
);
}
operator
int
()
{
return
fd
;
}
operator
int
()
const
{
return
fd
;
}
private:
int
fd
;
};
typedef
int
(
*
sscanf_fn
)(
const
char
*
,
void
*
);
typedef
int
(
*
snprintf_fn
)(
char
*
,
size_t
,
const
void
*
);
...
...
@@ -77,8 +44,22 @@ typedef int (*snprintf_fn)(char *, size_t, const void *);
/// so that objects of this class can reside in stl containers.
class
TableDesc
{
private:
TableDesc
(
const
TableDesc
&
)
=
default
;
TableDesc
&
operator
=
(
const
TableDesc
&
)
=
default
;
TableDesc
(
const
TableDesc
&
that
)
:
name
(
that
.
name
),
fd
(
that
.
fd
.
dup
()),
type
(
that
.
type
),
key_size
(
that
.
key_size
),
leaf_size
(
that
.
leaf_size
),
max_entries
(
that
.
max_entries
),
flags
(
that
.
flags
),
key_desc
(
that
.
key_desc
),
leaf_desc
(
that
.
leaf_desc
),
key_sscanf
(
that
.
key_sscanf
),
leaf_sscanf
(
that
.
leaf_sscanf
),
key_snprintf
(
that
.
key_snprintf
),
leaf_snprintf
(
that
.
leaf_snprintf
),
is_shared
(
that
.
is_shared
),
is_extern
(
that
.
is_extern
)
{}
public:
TableDesc
()
...
...
@@ -109,7 +90,10 @@ class TableDesc {
is_shared
(
false
),
is_extern
(
false
)
{}
TableDesc
(
TableDesc
&&
that
)
=
default
;
TableDesc
&
operator
=
(
TableDesc
&&
that
)
=
default
;
TableDesc
&
operator
=
(
const
TableDesc
&
that
)
=
delete
;
TableDesc
dup
()
const
{
return
TableDesc
(
*
this
);
}
std
::
string
name
;
...
...
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