summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-06-10 16:32:35 +0000
committerbors <bors@rust-lang.org>2021-06-10 16:32:35 +0000
commitdac89a3159cd5b3c712ababc131bbaedf415e4b3 (patch)
tree2c6d529665576e3d56e53756bd92f480974e2f87
parentce5cee1f8d3ba3be9db4039dc5c486544998a495 (diff)
parent7f6ce32a3120974190d2ff03d84380549f767ced (diff)
downloadrust-libc-dac89a3159cd5b3c712ababc131bbaedf415e4b3.tar.gz
Auto merge of #2228 - jonas-schievink:mallinfo2, r=JohnTitor
Add `mallinfo2` support This function was added in glibc 2.33 and fixes a shortcoming of the mallinfo API: it was unable to handle memory usage of more than 2 GB due to its use of `int` as the field types. This was fixed by duplicating the API and changing them to `size_t`.
-rwxr-xr-xlibc-test/build.rs6
-rw-r--r--libc-test/semver/linux-gnu.txt1
-rw-r--r--src/unix/linux_like/linux/gnu/mod.rs14
3 files changed, 21 insertions, 0 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 276be49259..0f2eefaf1c 100755
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -2650,6 +2650,9 @@ fn test_linux(target: &str) {
// FIXME: CI's kernel header version is old.
"sockaddr_can" => true,
+ // Requires glibc 2.33 or newer.
+ "mallinfo2" => true,
+
_ => false,
}
});
@@ -2853,6 +2856,9 @@ fn test_linux(target: &str) {
// FIXME: This needs musl 1.2.2 or later.
"gettid" if musl => true,
+ // Needs glibc 2.33 or later.
+ "mallinfo2" => true,
+
_ => false,
}
});
diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt
index 58b2eb6c94..fb3256086c 100644
--- a/libc-test/semver/linux-gnu.txt
+++ b/libc-test/semver/linux-gnu.txt
@@ -546,6 +546,7 @@ glob_t
globfree
globfree64
mallinfo
+mallinfo2
malloc_usable_size
mallopt
nl_mmap_hdr
diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs
index cc7e414f69..ad0f88261d 100644
--- a/src/unix/linux_like/linux/gnu/mod.rs
+++ b/src/unix/linux_like/linux/gnu/mod.rs
@@ -128,6 +128,19 @@ s! {
pub keepcost: ::c_int,
}
+ pub struct mallinfo2 {
+ pub arena: ::size_t,
+ pub ordblks: ::size_t,
+ pub smblks: ::size_t,
+ pub hblks: ::size_t,
+ pub hblkhd: ::size_t,
+ pub usmblks: ::size_t,
+ pub fsmblks: ::size_t,
+ pub uordblks: ::size_t,
+ pub fordblks: ::size_t,
+ pub keepcost: ::size_t,
+ }
+
pub struct nlmsghdr {
pub nlmsg_len: u32,
pub nlmsg_type: u16,
@@ -1281,6 +1294,7 @@ extern "C" {
) -> ::c_int;
pub fn sched_getcpu() -> ::c_int;
pub fn mallinfo() -> ::mallinfo;
+ pub fn mallinfo2() -> ::mallinfo2;
pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
pub fn getpwent_r(
pwd: *mut ::passwd,