1#define	JEMALLOC_WITNESS_C_
2#include "jemalloc/internal/jemalloc_internal.h"
3
4void
5witness_init(witness_t *witness, const char *name, witness_rank_t rank,
6    witness_comp_t *comp)
7{
8
9	witness->name = name;
10	witness->rank = rank;
11	witness->comp = comp;
12}
13
14#ifdef JEMALLOC_JET
15#undef witness_lock_error
16#define	witness_lock_error JEMALLOC_N(n_witness_lock_error)
17#endif
18void
19witness_lock_error(const witness_list_t *witnesses, const witness_t *witness)
20{
21	witness_t *w;
22
23	malloc_printf("<jemalloc>: Lock rank order reversal:");
24	ql_foreach(w, witnesses, link) {
25		malloc_printf(" %s(%u)", w->name, w->rank);
26	}
27	malloc_printf(" %s(%u)\n", witness->name, witness->rank);
28	abort();
29}
30#ifdef JEMALLOC_JET
31#undef witness_lock_error
32#define	witness_lock_error JEMALLOC_N(witness_lock_error)
33witness_lock_error_t *witness_lock_error = JEMALLOC_N(n_witness_lock_error);
34#endif
35
36#ifdef JEMALLOC_JET
37#undef witness_owner_error
38#define	witness_owner_error JEMALLOC_N(n_witness_owner_error)
39#endif
40void
41witness_owner_error(const witness_t *witness)
42{
43
44	malloc_printf("<jemalloc>: Should own %s(%u)\n", witness->name,
45	    witness->rank);
46	abort();
47}
48#ifdef JEMALLOC_JET
49#undef witness_owner_error
50#define	witness_owner_error JEMALLOC_N(witness_owner_error)
51witness_owner_error_t *witness_owner_error = JEMALLOC_N(n_witness_owner_error);
52#endif
53
54#ifdef JEMALLOC_JET
55#undef witness_not_owner_error
56#define	witness_not_owner_error JEMALLOC_N(n_witness_not_owner_error)
57#endif
58void
59witness_not_owner_error(const witness_t *witness)
60{
61
62	malloc_printf("<jemalloc>: Should not own %s(%u)\n", witness->name,
63	    witness->rank);
64	abort();
65}
66#ifdef JEMALLOC_JET
67#undef witness_not_owner_error
68#define	witness_not_owner_error JEMALLOC_N(witness_not_owner_error)
69witness_not_owner_error_t *witness_not_owner_error =
70    JEMALLOC_N(n_witness_not_owner_error);
71#endif
72
73#ifdef JEMALLOC_JET
74#undef witness_lockless_error
75#define	witness_lockless_error JEMALLOC_N(n_witness_lockless_error)
76#endif
77void
78witness_lockless_error(const witness_list_t *witnesses)
79{
80	witness_t *w;
81
82	malloc_printf("<jemalloc>: Should not own any locks:");
83	ql_foreach(w, witnesses, link) {
84		malloc_printf(" %s(%u)", w->name, w->rank);
85	}
86	malloc_printf("\n");
87	abort();
88}
89#ifdef JEMALLOC_JET
90#undef witness_lockless_error
91#define	witness_lockless_error JEMALLOC_N(witness_lockless_error)
92witness_lockless_error_t *witness_lockless_error =
93    JEMALLOC_N(n_witness_lockless_error);
94#endif
95
96void
97witnesses_cleanup(tsd_t *tsd)
98{
99
100	witness_assert_lockless(tsd_tsdn(tsd));
101
102	/* Do nothing. */
103}
104
105void
106witness_fork_cleanup(tsd_t *tsd)
107{
108
109	/* Do nothing. */
110}
111
112void
113witness_prefork(tsd_t *tsd)
114{
115
116	tsd_witness_fork_set(tsd, true);
117}
118
119void
120witness_postfork_parent(tsd_t *tsd)
121{
122
123	tsd_witness_fork_set(tsd, false);
124}
125
126void
127witness_postfork_child(tsd_t *tsd)
128{
129#ifndef JEMALLOC_MUTEX_INIT_CB
130	witness_list_t *witnesses;
131
132	witnesses = tsd_witnessesp_get(tsd);
133	ql_new(witnesses);
134#endif
135	tsd_witness_fork_set(tsd, false);
136}
137