Skip to content

Commit

Permalink
Auto merge of #2228 - jonas-schievink:mallinfo2, r=JohnTitor
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bors committed Jun 10, 2021
2 parents ce5cee1 + 7f6ce32 commit dac89a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
});
Expand Down Expand Up @@ -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,
}
});
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/linux-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ glob_t
globfree
globfree64
mallinfo
mallinfo2
malloc_usable_size
mallopt
nl_mmap_hdr
Expand Down
14 changes: 14 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dac89a3

Please sign in to comment.