Commit 7d7eb0c6 authored by Brendan Gregg's avatar Brendan Gregg

Merge branch 'master' into master

parents 4d57da10 2be91230
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "frontends/clang/b_frontend_action.h" #include "frontends/clang/b_frontend_action.h"
#include "bpf_module.h" #include "bpf_module.h"
#include "kbuild_helper.h" #include "kbuild_helper.h"
#include "shared_table.h"
#include "libbpf.h" #include "libbpf.h"
namespace ebpf { namespace ebpf {
...@@ -113,6 +114,10 @@ BPFModule::~BPFModule() { ...@@ -113,6 +114,10 @@ BPFModule::~BPFModule() {
engine_.reset(); engine_.reset();
rw_engine_.reset(); rw_engine_.reset();
ctx_.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) { static void debug_printf(Module *mod, IRBuilder<> &B, const string &fmt, vector<Value *> args) {
......
...@@ -599,6 +599,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) { ...@@ -599,6 +599,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
C.getDiagnostics().Report(Decl->getLocStart(), diag_id) << table.name << "already in use"; C.getDiagnostics().Report(Decl->getLocStart(), diag_id) << table.name << "already in use";
return false; return false;
} }
table_it->is_shared = true;
return true; return true;
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include <unistd.h>
#include "shared_table.h" #include "shared_table.h"
namespace ebpf { namespace ebpf {
...@@ -43,4 +45,13 @@ bool SharedTables::insert_fd(const string &name, int fd) { ...@@ -43,4 +45,13 @@ bool SharedTables::insert_fd(const string &name, int fd) {
return true; 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;
}
} }
...@@ -30,6 +30,8 @@ class SharedTables { ...@@ -30,6 +30,8 @@ class SharedTables {
bool insert_fd(const std::string &name, int fd); bool insert_fd(const std::string &name, int fd);
// lookup an fd in the shared table, or -1 if not found // lookup an fd in the shared table, or -1 if not found
int lookup_fd(const std::string &name) const; 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: private:
static SharedTables *instance_; static SharedTables *instance_;
std::map<std::string, int> tables_; std::map<std::string, int> tables_;
......
...@@ -38,6 +38,7 @@ struct TableDesc { ...@@ -38,6 +38,7 @@ struct TableDesc {
llvm::Function *leaf_sscanf; llvm::Function *leaf_sscanf;
llvm::Function *key_snprintf; llvm::Function *key_snprintf;
llvm::Function *leaf_snprintf; llvm::Function *leaf_snprintf;
bool is_shared;
}; };
} // namespace ebpf } // namespace ebpf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment