Seal the heap: bounded library heaps and zero-allocation program tests

The programs point libuv, c-ares and Mbed TLS (MBEDTLS_PLATFORM_MEMORY in
the bundled build) at their own FixedHeap before anything runs, mark the
end of startup with heap_seal(), and in verbose mode report heap use and
any allocation after it at exit. The library build keeps the host's
allocator.

measure_alloc.py gains --udp, and the alloc_steady_programs_* tests now
fail on any malloc per relayed TCP connection (by name and by address)
or UDP association, for every cipher family.
This commit is contained in:
Max Lv
2026-10-15 00:34:30 +08:00
parent e0047c9cef
commit c69fb4c4d9
12 changed files with 304 additions and 12 deletions
+9
View File
@@ -58,6 +58,7 @@
#include "common.h"
#include "ss_windows.h"
#include "core/heap_guard.hpp"
#include "relay/tcp.hpp"
#include "relay/udp.hpp"
@@ -246,6 +247,10 @@ plugin_watcher_cb(SS_P_ ss_io *w, int revents)
int
main(int argc, char **argv)
{
// Bounded heaps for libuv, c-ares and Mbed TLS before any of them runs.
if (!ss::install_library_heaps())
FATAL("failed to reserve the library heaps");
int i, c;
int pid_flags = 0;
int mptcp = 0;
@@ -1051,6 +1056,7 @@ Same behavior as `-V`; see that option for details. Short alias: `-V`.
}
#endif
ss::heap_seal();
ss_run(loop, 0);
if (plugin != NULL) {
@@ -1071,5 +1077,8 @@ Same behavior as `-V`; see that option for details. Short alias: `-V`.
winsock_cleanup();
#endif
if (verbose)
ss::log_heap_report();
return ret_val;
}