Skip to content
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

uapi: Use libc for syscall constants #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ readme = "README.md"

[dependencies]
enumflags2 = "0.7"
libc = "0.2"
libc = "0.2.133"
thiserror = "1.0"

[dev-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions src/uapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,23 @@ pub use self::landlock::{
LANDLOCK_CREATE_RULESET_VERSION,
};

use libc::{__u32, c_int, c_void, size_t, syscall};

#[cfg(target_arch = "x86_64")]
const __NR_LANDLOCK_CREATE_RULESET: u32 = 444;
#[cfg(target_arch = "x86_64")]
const __NR_LANDLOCK_ADD_RULE: u32 = 445;
#[cfg(target_arch = "x86_64")]
const __NR_LANDLOCK_RESTRICT_SELF: u32 = 446;
use libc::{
__u32, c_int, c_void, size_t, syscall, SYS_landlock_add_rule, SYS_landlock_create_ruleset,
SYS_landlock_restrict_self,
};

#[rustfmt::skip]
pub unsafe fn landlock_create_ruleset(attr: *const landlock_ruleset_attr, size: size_t,
flags: __u32) -> c_int {
syscall(__NR_LANDLOCK_CREATE_RULESET as i64, attr, size, flags) as c_int
syscall(SYS_landlock_create_ruleset, attr, size, flags) as c_int
}

#[rustfmt::skip]
pub unsafe fn landlock_add_rule(ruleset_fd: c_int, rule_type: landlock_rule_type,
rule_attr: *const c_void, flags: __u32) -> c_int {
syscall(__NR_LANDLOCK_ADD_RULE as i64, ruleset_fd, rule_type, rule_attr, flags) as c_int
syscall(SYS_landlock_add_rule, ruleset_fd, rule_type, rule_attr, flags) as c_int
}

pub unsafe fn landlock_restrict_self(ruleset_fd: c_int, flags: __u32) -> c_int {
syscall(__NR_LANDLOCK_RESTRICT_SELF as i64, ruleset_fd, flags) as c_int
syscall(SYS_landlock_restrict_self, ruleset_fd, flags) as c_int
}