Skip to content

Commit

Permalink
Auto merge of #2525 - qwandor:mlock2, r=Amanieu
Browse files Browse the repository at this point in the history
Add mlock2 on Android and Linux.

Unfortunately the type of the flags parameter is different between Bionic and glibc for some reason.
  • Loading branch information
bors committed Dec 9, 2021
2 parents 6fe1ff9 + ab1013b commit fb3dec2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,9 @@ fn test_android(target: &str) {
"reallocarray" => true,
"__system_property_wait" => true,

// Added in API level 30, but tests use level 28.
"mlock2" => true,

_ => false,
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,9 @@ pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
pub const ALG_OP_DECRYPT: ::c_int = 0;
pub const ALG_OP_ENCRYPT: ::c_int = 1;

// sys/mman.h
pub const MLOCK_ONFAULT: ::c_int = 0x01;

// uapi/linux/vm_sockets.h
pub const VMADDR_CID_ANY: ::c_uint = 0xFFFFFFFF;
pub const VMADDR_CID_HYPERVISOR: ::c_uint = 0;
Expand Down Expand Up @@ -2582,6 +2585,7 @@ extern "C" {
pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int;

pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int;
pub fn mlock2(addr: *const ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int;
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,7 @@ pub const MAP_SHARED_VALIDATE: ::c_int = 0x3;

// include/uapi/asm-generic/mman-common.h
pub const MAP_FIXED_NOREPLACE: ::c_int = 0x100000;
pub const MLOCK_ONFAULT: ::c_uint = 0x01;

// uapi/linux/vm_sockets.h
pub const VMADDR_CID_ANY: ::c_uint = 0xFFFFFFFF;
Expand Down Expand Up @@ -3533,6 +3534,7 @@ extern "C" {
pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long);

pub fn telldir(dirp: *mut ::DIR) -> ::c_long;
pub fn mlock2(addr: *const ::c_void, len: ::size_t, flags: ::c_uint) -> ::c_int;
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int;

pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
Expand Down

0 comments on commit fb3dec2

Please sign in to comment.