Commit 75eef2c1 authored by 4ast's avatar 4ast Committed by GitHub

Merge pull request #656 from iovisor/non-static-functions

Disable non-static function calls
parents cee60569 3f28e7bc
...@@ -462,6 +462,15 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) { ...@@ -462,6 +462,15 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
rewriter_.ReplaceText(expansionRange(Call->getSourceRange()), text); rewriter_.ReplaceText(expansionRange(Call->getSourceRange()), text);
} }
} }
} else if (FunctionDecl *F = dyn_cast<FunctionDecl>(Decl)) {
if (F->isExternallyVisible() && !F->getBuiltinID()) {
auto start_loc = rewriter_.getSourceMgr().getFileLoc(Decl->getLocStart());
if (rewriter_.getSourceMgr().getFileID(start_loc)
== rewriter_.getSourceMgr().getMainFileID()) {
error(Call->getLocStart(), "cannot call non-static helper function");
return false;
}
}
} }
} }
return true; return true;
......
...@@ -522,7 +522,17 @@ int do_next(struct pt_regs *ctx) { ...@@ -522,7 +522,17 @@ int do_next(struct pt_regs *ctx) {
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
b1["dummy"][c_key] b1["dummy"][c_key]
def test_invalid_noninline_call(self):
text = """
int bar(void) {
return 0;
}
int foo(struct pt_regs *ctx) {
return bar();
}
"""
with self.assertRaises(Exception):
b = BPF(text=text)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -28,7 +28,7 @@ enum stat_types { ...@@ -28,7 +28,7 @@ enum stat_types {
BPF_ARRAY(stats, u64, S_MAXSTAT + 1); BPF_ARRAY(stats, u64, S_MAXSTAT + 1);
void stats_increment(int key) { static void stats_increment(int key) {
u64 *leaf = stats.lookup(&key); u64 *leaf = stats.lookup(&key);
if (leaf) (*leaf)++; if (leaf) (*leaf)++;
} }
......
...@@ -51,7 +51,7 @@ enum stat_types { ...@@ -51,7 +51,7 @@ enum stat_types {
BPF_ARRAY(stats, u64, S_MAXSTAT + 1); BPF_ARRAY(stats, u64, S_MAXSTAT + 1);
void stats_increment(int key) { static void stats_increment(int key) {
u64 *leaf = stats.lookup(&key); u64 *leaf = stats.lookup(&key);
if (leaf) (*leaf)++; if (leaf) (*leaf)++;
} }
......
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