xref: /freebsd/contrib/processor-trace/libipt/internal/include/pt_packet.h (revision 18054d0220cfc8df9c9568c437bd6fbb59d53c3c)
1 /*
2  * Copyright (c) 2014-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_PACKET_H
30 #define PT_PACKET_H
31 
32 #include <stdint.h>
33 
34 struct pt_config;
35 struct pt_packet;
36 struct pt_packet_ip;
37 struct pt_packet_tnt;
38 struct pt_packet_pip;
39 struct pt_packet_mode;
40 struct pt_packet_tsc;
41 struct pt_packet_cbr;
42 struct pt_packet_tma;
43 struct pt_packet_mtc;
44 struct pt_packet_cyc;
45 struct pt_packet_vmcs;
46 struct pt_packet_mnt;
47 struct pt_packet_exstop;
48 struct pt_packet_mwait;
49 struct pt_packet_pwre;
50 struct pt_packet_pwrx;
51 struct pt_packet_ptw;
52 
53 
54 /* Read the payload of an Intel PT packet.
55  *
56  * Reads the payload of the packet starting at @pos into @packet.
57  *
58  * For pt_pkt_read_psb(), the @packet parameter is omitted; the function
59  * validates that the payload matches the expected PSB pattern.
60  *
61  * Decoding an unknown packet uses @config's decode callback.  If the callback
62  * is NULL, pt_pkt_read_unknown() returns -pte_bad_opc.
63  *
64  * Beware that the packet opcode is not checked.  The caller is responsible
65  * for checking the opcode and calling the correct packet read function.
66  *
67  * Returns the packet size on success, a negative error code otherwise.
68  * Returns -pte_bad_packet if the packet payload is corrupt.
69  * Returns -pte_eos if the packet does not fit into the trace buffer.
70  * Returns -pte_internal if @packet, @pos, or @config is NULL.
71  */
72 extern int pt_pkt_read_unknown(struct pt_packet *packet, const uint8_t *pos,
73 			       const struct pt_config *config);
74 extern int pt_pkt_read_psb(const uint8_t *pos, const struct pt_config *config);
75 extern int pt_pkt_read_ip(struct pt_packet_ip *packet, const uint8_t *pos,
76 			  const struct pt_config *config);
77 extern int pt_pkt_read_tnt_8(struct pt_packet_tnt *packet, const uint8_t *pos,
78 			     const struct pt_config *config);
79 extern int pt_pkt_read_tnt_64(struct pt_packet_tnt *packet, const uint8_t *pos,
80 			      const struct pt_config *config);
81 extern int pt_pkt_read_pip(struct pt_packet_pip *packet, const uint8_t *pos,
82 			   const struct pt_config *config);
83 extern int pt_pkt_read_mode(struct pt_packet_mode *packet, const uint8_t *pos,
84 			    const struct pt_config *config);
85 extern int pt_pkt_read_tsc(struct pt_packet_tsc *packet, const uint8_t *pos,
86 			   const struct pt_config *config);
87 extern int pt_pkt_read_cbr(struct pt_packet_cbr *packet, const uint8_t *pos,
88 			   const struct pt_config *config);
89 extern int pt_pkt_read_tma(struct pt_packet_tma *packet, const uint8_t *pos,
90 			   const struct pt_config *config);
91 extern int pt_pkt_read_mtc(struct pt_packet_mtc *packet, const uint8_t *pos,
92 			   const struct pt_config *config);
93 extern int pt_pkt_read_cyc(struct pt_packet_cyc *packet, const uint8_t *pos,
94 			   const struct pt_config *config);
95 extern int pt_pkt_read_vmcs(struct pt_packet_vmcs *packet, const uint8_t *pos,
96 			    const struct pt_config *config);
97 extern int pt_pkt_read_mnt(struct pt_packet_mnt *packet, const uint8_t *pos,
98 			   const struct pt_config *config);
99 extern int pt_pkt_read_exstop(struct pt_packet_exstop *packet,
100 			      const uint8_t *pos,
101 			      const struct pt_config *config);
102 extern int pt_pkt_read_mwait(struct pt_packet_mwait *packet, const uint8_t *pos,
103 			     const struct pt_config *config);
104 extern int pt_pkt_read_pwre(struct pt_packet_pwre *packet, const uint8_t *pos,
105 			    const struct pt_config *config);
106 extern int pt_pkt_read_pwrx(struct pt_packet_pwrx *packet, const uint8_t *pos,
107 			    const struct pt_config *config);
108 extern int pt_pkt_read_ptw(struct pt_packet_ptw *packet, const uint8_t *pos,
109 			   const struct pt_config *config);
110 
111 #endif /* PT_PACKET_H */
112