-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add built-in function for formatting MAC addresses #1647
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "common.h" | ||
|
||
namespace bpftrace { | ||
namespace test { | ||
namespace codegen { | ||
|
||
TEST(codegen, call_macaddr) | ||
{ | ||
test("struct mac { unsigned char addr[6] } kprobe:f { @x = macaddr(((struct " | ||
"mac*)0)->addr); }", | ||
|
||
NAME); | ||
} | ||
|
||
} // namespace codegen | ||
} // namespace test | ||
} // namespace bpftrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
; ModuleID = 'bpftrace' | ||
source_filename = "bpftrace" | ||
target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128" | ||
target triple = "bpf-pc-linux" | ||
|
||
; Function Attrs: nounwind | ||
declare i64 @llvm.bpf.pseudo(i64, i64) #0 | ||
|
||
define i64 @"kprobe:f"(i8*) section "s_kprobe:f_1" { | ||
entry: | ||
%"@x_key" = alloca i64 | ||
%macaddr = alloca [6 x i8] | ||
%1 = bitcast [6 x i8]* %macaddr to i8* | ||
call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1) | ||
%2 = bitcast [6 x i8]* %macaddr to i8* | ||
call void @llvm.memset.p0i8.i64(i8* align 1 %2, i8 0, i64 6, i1 false) | ||
%3 = bitcast [6 x i8]* %macaddr to i8* | ||
call void @llvm.lifetime.start.p0i8(i64 -1, i8* %3) | ||
%probe_read_kernel = call i64 inttoptr (i64 113 to i64 ([6 x i8]*, i32, i64)*)([6 x i8]* %macaddr, i32 6, i64 0) | ||
%4 = bitcast i64* %"@x_key" to i8* | ||
call void @llvm.lifetime.start.p0i8(i64 -1, i8* %4) | ||
store i64 0, i64* %"@x_key" | ||
%pseudo = call i64 @llvm.bpf.pseudo(i64 1, i64 1) | ||
%update_elem = call i64 inttoptr (i64 2 to i64 (i64, i64*, [6 x i8]*, i64)*)(i64 %pseudo, i64* %"@x_key", [6 x i8]* %macaddr, i64 0) | ||
%5 = bitcast i64* %"@x_key" to i8* | ||
call void @llvm.lifetime.end.p0i8(i64 -1, i8* %5) | ||
%6 = bitcast [6 x i8]* %macaddr to i8* | ||
call void @llvm.lifetime.end.p0i8(i64 -1, i8* %6) | ||
ret i64 0 | ||
} | ||
|
||
; Function Attrs: argmemonly nounwind | ||
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1 | ||
|
||
; Function Attrs: argmemonly nounwind | ||
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1) #1 | ||
|
||
; Function Attrs: argmemonly nounwind | ||
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 | ||
|
||
attributes #0 = { nounwind } | ||
attributes #1 = { argmemonly nounwind } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC arrays can end up on stack already so this would probe read from the stack in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should I check for that case? I see that
shouldBeOnStackAlready
doesn't include arrays, so it wouldn't be enough to branch on that. But I'm thinking that we need to branch on something and then store (instead of probe read) if the arg is already on the stack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it would have to load/memcpy instead of probe reading.
I dont know the best way to check, arrays need some love. I'd be ok with this probe reading for now too, can always fix it in the future.