Skip to content

Commit a358bfa

Browse files
authored
Implement virtual get_mallinfo, via rusage (#6221)
1 parent 2827d0d commit a358bfa

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

include/ccf/pal/mem.h

+25-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#if !defined(INSIDE_ENCLAVE) || defined(VIRTUAL_ENCLAVE)
88
# include <cstring>
99
# include <limits>
10+
# include <sys/resource.h>
1011
#else
1112
# include "ccf/pal/hardware_info.h"
1213

@@ -36,9 +37,30 @@ namespace ccf::pal
3637

3738
static inline bool get_mallinfo(MallocInfo& info)
3839
{
39-
info.max_total_heap_size = std::numeric_limits<size_t>::max();
40-
info.current_allocated_heap_size = 0;
41-
info.peak_allocated_heap_size = 0;
40+
{
41+
rusage ru;
42+
auto rc = getrusage(RUSAGE_SELF, &ru);
43+
if (rc != 0)
44+
{
45+
return false;
46+
}
47+
const auto heap_size = ru.ru_maxrss * 1024;
48+
49+
info.current_allocated_heap_size = heap_size;
50+
info.peak_allocated_heap_size = heap_size;
51+
}
52+
53+
{
54+
rlimit rl;
55+
auto rc = getrlimit(RLIMIT_AS, &rl);
56+
if (rc != 0)
57+
{
58+
return false;
59+
}
60+
61+
info.max_total_heap_size = rl.rlim_cur;
62+
}
63+
4264
return true;
4365
}
4466

0 commit comments

Comments
 (0)