Skip to content

Commit

Permalink
rust: use bindgen --size_t-is-usize option
Browse files Browse the repository at this point in the history
This will give us identical bindings for all platforms regardless of
what underlying C type they use to define size_t.

For some reason, this isn't the default:
rust-lang/rust-bindgen#1901

Previously, we generated different things on different platforms:

x86-64:     pub type size_t = ::std::os::raw::c_ulong;
32-bit arm: pub type size_t = ::std::os::raw::c_uint;

It also lets us eliminate a couple of size_t casts in the Rust wrapper
code.

Bug: None
Test: (cd rust/minijail; cargo test)
Change-Id: Ic37fc7fb2cf2ad173b4bc184a499011d299c8917
  • Loading branch information
danielverkamp committed Jul 14, 2022
1 parent 22388b9 commit bedb1b1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions rust/minijail-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn bindings_generation() -> io::Result<()> {
.args(&["--blacklist-type", "__uint64_t"])
.args(&["--whitelist-function", "^minijail_.*"])
.args(&["--whitelist-var", "^MINIJAIL_.*"])
.arg("--size_t-is-usize")
.arg("--no-layout-tests")
.arg("--disable-header-comment")
.args(&["--output", gen_file.to_str().unwrap()])
Expand Down
5 changes: 2 additions & 3 deletions rust/minijail-sys/libminijail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub type rlim_t = __rlim64_t;
pub type gid_t = __gid_t;
pub type uid_t = __uid_t;
pub type pid_t = __pid_t;
pub type size_t = ::std::os::raw::c_ulong;
#[repr(C)]
pub struct sock_filter {
pub code: __u16,
Expand Down Expand Up @@ -68,7 +67,7 @@ extern "C" {
pub fn minijail_change_gid(j: *mut minijail, gid: gid_t);
}
extern "C" {
pub fn minijail_set_supplementary_gids(j: *mut minijail, size: size_t, list: *const gid_t);
pub fn minijail_set_supplementary_gids(j: *mut minijail, size: usize, list: *const gid_t);
}
extern "C" {
pub fn minijail_keep_supplementary_gids(j: *mut minijail);
Expand Down Expand Up @@ -256,7 +255,7 @@ extern "C" {
pub fn minijail_mount_tmp(j: *mut minijail);
}
extern "C" {
pub fn minijail_mount_tmp_size(j: *mut minijail, size: size_t);
pub fn minijail_mount_tmp_size(j: *mut minijail, size: usize);
}
extern "C" {
pub fn minijail_mount_dev(j: *mut minijail);
Expand Down
4 changes: 2 additions & 2 deletions rust/minijail/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl Minijail {
}
pub fn set_supplementary_gids(&mut self, ids: &[libc::gid_t]) {
unsafe {
minijail_set_supplementary_gids(self.jail, ids.len() as size_t, ids.as_ptr());
minijail_set_supplementary_gids(self.jail, ids.len(), ids.as_ptr());
}
}
pub fn keep_supplementary_gids(&mut self) {
Expand Down Expand Up @@ -767,7 +767,7 @@ impl Minijail {
}
pub fn mount_tmp_size(&mut self, size: usize) {
unsafe {
minijail_mount_tmp_size(self.jail, size as size_t);
minijail_mount_tmp_size(self.jail, size);
}
}
pub fn mount_bind<P1: AsRef<Path>, P2: AsRef<Path>>(
Expand Down

0 comments on commit bedb1b1

Please sign in to comment.