xref: /freebsd/contrib/processor-trace/libipt/internal/include/pt_last_ip.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /*
2  * Copyright (c) 2013-2019, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *  * Redistributions of source code must retain the above copyright notice,
8  *    this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright notice,
10  *    this list of conditions and the following disclaimer in the documentation
11  *    and/or other materials provided with the distribution.
12  *  * Neither the name of Intel Corporation nor the names of its contributors
13  *    may be used to endorse or promote products derived from this software
14  *    without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef PT_LAST_IP_H
30 #define PT_LAST_IP_H
31 
32 #include <stdint.h>
33 
34 struct pt_packet_ip;
35 struct pt_config;
36 
37 
38 /* Keeping track of the last-ip in Intel PT packets. */
39 struct pt_last_ip {
40 	/* The last IP. */
41 	uint64_t ip;
42 
43 	/* Flags governing the handling of IP updates and queries:
44 	 *
45 	 * - we have seen an IP update.
46 	 */
47 	uint32_t have_ip:1;
48 	/* - the IP has been suppressed in the last update. */
49 	uint32_t suppressed:1;
50 };
51 
52 
53 /* Initialize (or reset) the last-ip. */
54 extern void pt_last_ip_init(struct pt_last_ip *last_ip);
55 
56 /* Query the last-ip.
57  *
58  * If @ip is not NULL, provides the last-ip in @ip on success.
59  *
60  * Returns zero on success.
61  * Returns -pte_internal if @last_ip is NULL.
62  * Returns -pte_noip if there is no last-ip.
63  * Returns -pte_ip_suppressed if the last-ip has been suppressed.
64  */
65 extern int pt_last_ip_query(uint64_t *ip, const struct pt_last_ip *last_ip);
66 
67 /* Update last-ip.
68  *
69  * Updates @last_ip based on @packet and, if non-null, @config.
70  *
71  * Returns zero on success.
72  * Returns -pte_internal if @last_ip or @packet is NULL.
73  * Returns -pte_bad_packet if @packet appears to be corrupted.
74  */
75 extern int pt_last_ip_update_ip(struct pt_last_ip *last_ip,
76 				const struct pt_packet_ip *packet,
77 				const struct pt_config *config);
78 
79 #endif /* PT_LAST_IP_H */
80