libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_alloc_audit.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * Use of this source code is governed by the ISC License.
4 *
5 * src/inc/xtc_alloc_audit.h
6 * Debug allocation auditor. When enabled it wraps the allocator
7 * vtable, recording every live allocation together with the
8 * process (xtc_self) that made it, so a test can assert that a
9 * process freed everything it allocated before it died -- per-proc
10 * leak detection. Off by default; it serializes alloc/free on a
11 * global mutex, so it is a debug/test tool, not for production.
12 */
13
14#ifndef XTC_ALLOC_AUDIT_H
15#define XTC_ALLOC_AUDIT_H
16
17#include "xtc_export.h"
18
19#include <stddef.h>
20#include <stdint.h>
21
22#include "xtc_proc.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/*
29 * PUBLIC: int xtc_alloc_audit_enable __P((int));
30 * PUBLIC: void xtc_alloc_audit_stats __P((size_t *, size_t *));
31 * PUBLIC: void xtc_alloc_audit_proc_leaks __P((xtc_pid_t, size_t *, size_t *));
32 */
33
34/* Enable (on != 0) or disable the auditor. Enabling wraps the
35 * current allocator hook; disabling restores it. Returns XTC_OK, or
36 * XTC_E_NOMEM if the tracking table could not be allocated. */
37XTC_API int xtc_alloc_audit_enable(int on);
38
39/* Total live (unfreed) allocations and their byte sum across all
40 * owners. Either pointer may be NULL. */
41XTC_API void xtc_alloc_audit_stats(size_t *out_count, size_t *out_bytes);
42
43/* Live allocations still attributed to process `pid` (allocations
44 * made off a process are attributed to the none pid). Either output
45 * pointer may be NULL. This is the per-proc leak check: call it from
46 * the process's xtc_proc_at_exit hook or after it is reaped. */
47XTC_API void xtc_alloc_audit_proc_leaks(xtc_pid_t pid, size_t *out_count,
48 size_t *out_bytes);
49
50#ifdef __cplusplus
51}
52#endif
53
54#endif /* XTC_ALLOC_AUDIT_H */