Skip to content

Commit 33b2257

Browse files
authored
define-syscall: Add bpf target (#387)
* Add target_arch bpf * Add unstable feature * Add comment
1 parent 2d7f8e8 commit 33b2257

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

define-syscall/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ edition = { workspace = true }
1212
[package.metadata.docs.rs]
1313
targets = ["x86_64-unknown-linux-gnu"]
1414

15+
[features]
16+
# static syscalls for eBPF are experimental and
17+
# not guaranteed to work
18+
unstable-static-syscalls = []
19+
1520
[lints.rust]
1621
unexpected_cfgs = { level = "warn", check-cfg = [
1722
'cfg(target_feature, values("static-syscalls"))',

define-syscall/src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
pub mod definitions;
55

6-
#[cfg(target_feature = "static-syscalls")]
6+
#[cfg(any(
7+
target_feature = "static-syscalls",
8+
all(target_arch = "bpf", feature = "unstable-static-syscalls")
9+
))]
710
#[macro_export]
811
macro_rules! define_syscall {
912
($(#[$attr:meta])* fn $name:ident($($arg:ident: $typ:ty),*) -> $ret:ty) => {
@@ -26,7 +29,10 @@ macro_rules! define_syscall {
2629
}
2730
}
2831

29-
#[cfg(not(target_feature = "static-syscalls"))]
32+
#[cfg(not(any(
33+
target_feature = "static-syscalls",
34+
all(target_arch = "bpf", feature = "unstable-static-syscalls")
35+
)))]
3036
#[macro_export]
3137
macro_rules! define_syscall {
3238
($(#[$attr:meta])* fn $name:ident($($arg:ident: $typ:ty),*) -> $ret:ty) => {
@@ -40,12 +46,18 @@ macro_rules! define_syscall {
4046
}
4147
}
4248

43-
#[cfg(target_feature = "static-syscalls")]
49+
#[cfg(any(
50+
target_feature = "static-syscalls",
51+
all(target_arch = "bpf", feature = "unstable-static-syscalls")
52+
))]
4453
pub const fn sys_hash(name: &str) -> usize {
4554
murmur3_32(name.as_bytes(), 0) as usize
4655
}
4756

48-
#[cfg(target_feature = "static-syscalls")]
57+
#[cfg(any(
58+
target_feature = "static-syscalls",
59+
all(target_arch = "bpf", feature = "unstable-static-syscalls")
60+
))]
4961
const fn murmur3_32(buf: &[u8], seed: u32) -> u32 {
5062
const fn pre_mix(buf: [u8; 4]) -> u32 {
5163
u32::from_le_bytes(buf)

0 commit comments

Comments
 (0)