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
2be91230
Commit
2be91230
authored
Jan 18, 2016
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #314 from iovisor/map_unshare
Close fd and unshare when public map is destructed
parents
120bfad7
d83192d0
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
0 deletions
+20
-0
src/cc/bpf_module.cc
src/cc/bpf_module.cc
+5
-0
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+1
-0
src/cc/shared_table.cc
src/cc/shared_table.cc
+11
-0
src/cc/shared_table.h
src/cc/shared_table.h
+2
-0
src/cc/table_desc.h
src/cc/table_desc.h
+1
-0
No files found.
src/cc/bpf_module.cc
View file @
2be91230
...
...
@@ -49,6 +49,7 @@
#include "frontends/clang/b_frontend_action.h"
#include "bpf_module.h"
#include "kbuild_helper.h"
#include "shared_table.h"
#include "libbpf.h"
namespace
ebpf
{
...
...
@@ -113,6 +114,10 @@ BPFModule::~BPFModule() {
engine_
.
reset
();
rw_engine_
.
reset
();
ctx_
.
reset
();
for
(
auto
table
:
*
tables_
)
{
if
(
table
.
is_shared
)
SharedTables
::
instance
()
->
remove_fd
(
table
.
name
);
}
}
static
void
debug_printf
(
Module
*
mod
,
IRBuilder
<>
&
B
,
const
string
&
fmt
,
vector
<
Value
*>
args
)
{
...
...
src/cc/frontends/clang/b_frontend_action.cc
View file @
2be91230
...
...
@@ -599,6 +599,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
C
.
getDiagnostics
().
Report
(
Decl
->
getLocStart
(),
diag_id
)
<<
table
.
name
<<
"already in use"
;
return
false
;
}
table_it
->
is_shared
=
true
;
return
true
;
}
...
...
src/cc/shared_table.cc
View file @
2be91230
...
...
@@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <unistd.h>
#include "shared_table.h"
namespace
ebpf
{
...
...
@@ -43,4 +45,13 @@ bool SharedTables::insert_fd(const string &name, int fd) {
return
true
;
}
bool
SharedTables
::
remove_fd
(
const
string
&
name
)
{
auto
table
=
tables_
.
find
(
name
);
if
(
table
==
tables_
.
end
())
return
false
;
close
(
table
->
second
);
tables_
.
erase
(
table
);
return
true
;
}
}
src/cc/shared_table.h
View file @
2be91230
...
...
@@ -30,6 +30,8 @@ class SharedTables {
bool
insert_fd
(
const
std
::
string
&
name
,
int
fd
);
// lookup an fd in the shared table, or -1 if not found
int
lookup_fd
(
const
std
::
string
&
name
)
const
;
// close and remove a shared fd. return true if the value was found
bool
remove_fd
(
const
std
::
string
&
name
);
private:
static
SharedTables
*
instance_
;
std
::
map
<
std
::
string
,
int
>
tables_
;
...
...
src/cc/table_desc.h
View file @
2be91230
...
...
@@ -38,6 +38,7 @@ struct TableDesc {
llvm
::
Function
*
leaf_sscanf
;
llvm
::
Function
*
key_snprintf
;
llvm
::
Function
*
leaf_snprintf
;
bool
is_shared
;
};
}
// namespace ebpf
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