Skip to content

Commit fb3dec2

Browse files
committed
Auto merge of #2525 - qwandor:mlock2, r=Amanieu
Add mlock2 on Android and Linux. Unfortunately the type of the flags parameter is different between Bionic and glibc for some reason.
2 parents 6fe1ff9 + ab1013b commit fb3dec2

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,9 @@ fn test_android(target: &str) {
17021702
"reallocarray" => true,
17031703
"__system_property_wait" => true,
17041704

1705+
// Added in API level 30, but tests use level 28.
1706+
"mlock2" => true,
1707+
17051708
_ => false,
17061709
}
17071710
});

src/unix/linux_like/android/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,9 @@ pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
23282328
pub const ALG_OP_DECRYPT: ::c_int = 0;
23292329
pub const ALG_OP_ENCRYPT: ::c_int = 1;
23302330

2331+
// sys/mman.h
2332+
pub const MLOCK_ONFAULT: ::c_int = 0x01;
2333+
23312334
// uapi/linux/vm_sockets.h
23322335
pub const VMADDR_CID_ANY: ::c_uint = 0xFFFFFFFF;
23332336
pub const VMADDR_CID_HYPERVISOR: ::c_uint = 0;
@@ -2582,6 +2585,7 @@ extern "C" {
25822585
pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int;
25832586

25842587
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int;
2588+
pub fn mlock2(addr: *const ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
25852589
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int;
25862590
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
25872591
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;

src/unix/linux_like/linux/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,7 @@ pub const MAP_SHARED_VALIDATE: ::c_int = 0x3;
25832583

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

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

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

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

0 commit comments

Comments
 (0)