Skip to content

Commit dac89a3

Browse files
committed
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`.
2 parents ce5cee1 + 7f6ce32 commit dac89a3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Diff for: libc-test/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,9 @@ fn test_linux(target: &str) {
26502650
// FIXME: CI's kernel header version is old.
26512651
"sockaddr_can" => true,
26522652

2653+
// Requires glibc 2.33 or newer.
2654+
"mallinfo2" => true,
2655+
26532656
_ => false,
26542657
}
26552658
});
@@ -2853,6 +2856,9 @@ fn test_linux(target: &str) {
28532856
// FIXME: This needs musl 1.2.2 or later.
28542857
"gettid" if musl => true,
28552858

2859+
// Needs glibc 2.33 or later.
2860+
"mallinfo2" => true,
2861+
28562862
_ => false,
28572863
}
28582864
});

Diff for: libc-test/semver/linux-gnu.txt

+1
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ glob_t
546546
globfree
547547
globfree64
548548
mallinfo
549+
mallinfo2
549550
malloc_usable_size
550551
mallopt
551552
nl_mmap_hdr

Diff for: src/unix/linux_like/linux/gnu/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ s! {
128128
pub keepcost: ::c_int,
129129
}
130130

131+
pub struct mallinfo2 {
132+
pub arena: ::size_t,
133+
pub ordblks: ::size_t,
134+
pub smblks: ::size_t,
135+
pub hblks: ::size_t,
136+
pub hblkhd: ::size_t,
137+
pub usmblks: ::size_t,
138+
pub fsmblks: ::size_t,
139+
pub uordblks: ::size_t,
140+
pub fordblks: ::size_t,
141+
pub keepcost: ::size_t,
142+
}
143+
131144
pub struct nlmsghdr {
132145
pub nlmsg_len: u32,
133146
pub nlmsg_type: u16,
@@ -1281,6 +1294,7 @@ extern "C" {
12811294
) -> ::c_int;
12821295
pub fn sched_getcpu() -> ::c_int;
12831296
pub fn mallinfo() -> ::mallinfo;
1297+
pub fn mallinfo2() -> ::mallinfo2;
12841298
pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
12851299
pub fn getpwent_r(
12861300
pwd: *mut ::passwd,

0 commit comments

Comments
 (0)