1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2019, Matthew Macy <mmacy@freebsd.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#ifndef _SYS_GCOV_H_
30#define _SYS_GCOV_H_
31
32MALLOC_DECLARE(M_GCOV);
33
34/*
35 * Profiling data types used for gcc 3.4 and above - these are defined by
36 * gcc and need to be kept as close to the original definition as possible to
37 * remain compatible.
38 */
39#define GCOV_DATA_MAGIC		((unsigned int) 0x67636461)
40#define GCOV_TAG_FUNCTION	((unsigned int) 0x01000000)
41#define GCOV_TAG_COUNTER_BASE	((unsigned int) 0x01a10000)
42#define GCOV_TAG_FOR_COUNTER(count)					\
43	(GCOV_TAG_COUNTER_BASE + ((unsigned int) (count) << 17))
44
45typedef uint64_t gcov_type;
46
47/* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so
48 * we cannot use full definition here and they need to be placed in gcc specific
49 * implementation of gcov. This also means no direct access to the members in
50 * generic code and usage of the interface below.*/
51struct gcov_info;
52
53/* Interface to access gcov_info data  */
54const char *gcov_info_filename(struct gcov_info *info);
55unsigned int gcov_info_version(struct gcov_info *info);
56struct gcov_info *gcov_info_next(struct gcov_info *info);
57void gcov_info_link(struct gcov_info *info);
58void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
59
60/* Base interface. */
61enum gcov_action {
62	GCOV_ADD,
63	GCOV_REMOVE,
64};
65
66/* Iterator control. */
67struct gcov_iterator;
68
69struct gcov_iterator *gcov_iter_new(struct gcov_info *info);
70void gcov_iter_free(struct gcov_iterator *iter);
71void gcov_iter_start(struct gcov_iterator *iter);
72int gcov_iter_next(struct gcov_iterator *iter);
73int gcov_iter_write(struct gcov_iterator *iter, struct sbuf *sbuf);
74struct gcov_info *gcov_iter_get_info(struct gcov_iterator *iter);
75
76/* gcov_info control. */
77void gcov_info_reset(struct gcov_info *info);
78int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2);
79void gcov_info_add(struct gcov_info *dest, struct gcov_info *source);
80struct gcov_info *gcov_info_dup(struct gcov_info *info);
81void gcov_info_free(struct gcov_info *info);
82void gcov_stats_reset(void);
83void gcov_enable_events(void);
84void gcov_module_unload(void *, module_t);
85void gcov_fs_init(void);
86
87int within_module(vm_offset_t addr, module_t mod);
88
89struct gcov_link {
90	enum {
91		OBJ_TREE,
92		SRC_TREE,
93	} dir;
94	const char *ext;
95};
96extern const struct gcov_link gcov_link[];
97#endif
98