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
@@ -64,6 +64,7 @@
#include "common.h"
#include "ss_windows.h"
#include "core/heap_guard.hpp"
#include "relay/tcp.hpp"
#include "relay/udp.hpp"
@@ -447,6 +448,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 mtu = 0;
@@ -1274,6 +1279,7 @@ Same behavior as `-S`; see that option for details. Short alias: `-S`.
#endif
// Enter the loop
ss::heap_seal();
ss_run(loop, 0);
if (verbose) {
@@ -1296,6 +1302,9 @@ Same behavior as `-S`; see that option for details. Short alias: `-S`.
winsock_cleanup();
#endif
if (verbose)
ss::log_heap_report();
return ret_val;
}