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