xref: /freebsd-src/contrib/processor-trace/libipt/internal/include/pt_sync.h (revision 74fe6c29fb7eef3418d7919dcd41dc1a04a982a1)
1*74fe6c29SRuslan Bukin /*
2*74fe6c29SRuslan Bukin  * Copyright (c) 2014-2018, Intel Corporation
3*74fe6c29SRuslan Bukin  *
4*74fe6c29SRuslan Bukin  * Redistribution and use in source and binary forms, with or without
5*74fe6c29SRuslan Bukin  * modification, are permitted provided that the following conditions are met:
6*74fe6c29SRuslan Bukin  *
7*74fe6c29SRuslan Bukin  *  * Redistributions of source code must retain the above copyright notice,
8*74fe6c29SRuslan Bukin  *    this list of conditions and the following disclaimer.
9*74fe6c29SRuslan Bukin  *  * Redistributions in binary form must reproduce the above copyright notice,
10*74fe6c29SRuslan Bukin  *    this list of conditions and the following disclaimer in the documentation
11*74fe6c29SRuslan Bukin  *    and/or other materials provided with the distribution.
12*74fe6c29SRuslan Bukin  *  * Neither the name of Intel Corporation nor the names of its contributors
13*74fe6c29SRuslan Bukin  *    may be used to endorse or promote products derived from this software
14*74fe6c29SRuslan Bukin  *    without specific prior written permission.
15*74fe6c29SRuslan Bukin  *
16*74fe6c29SRuslan Bukin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*74fe6c29SRuslan Bukin  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*74fe6c29SRuslan Bukin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*74fe6c29SRuslan Bukin  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20*74fe6c29SRuslan Bukin  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*74fe6c29SRuslan Bukin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*74fe6c29SRuslan Bukin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*74fe6c29SRuslan Bukin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*74fe6c29SRuslan Bukin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*74fe6c29SRuslan Bukin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*74fe6c29SRuslan Bukin  * POSSIBILITY OF SUCH DAMAGE.
27*74fe6c29SRuslan Bukin  */
28*74fe6c29SRuslan Bukin 
29*74fe6c29SRuslan Bukin #ifndef PT_SYNC_H
30*74fe6c29SRuslan Bukin #define PT_SYNC_H
31*74fe6c29SRuslan Bukin 
32*74fe6c29SRuslan Bukin #include <stdint.h>
33*74fe6c29SRuslan Bukin 
34*74fe6c29SRuslan Bukin struct pt_config;
35*74fe6c29SRuslan Bukin 
36*74fe6c29SRuslan Bukin 
37*74fe6c29SRuslan Bukin /* Synchronize onto the trace stream.
38*74fe6c29SRuslan Bukin  *
39*74fe6c29SRuslan Bukin  * Search for the next synchronization point in forward or backward direction
40*74fe6c29SRuslan Bukin  * starting at @pos using the trace configuration @config.
41*74fe6c29SRuslan Bukin  *
42*74fe6c29SRuslan Bukin  * On success, stores a pointer to the next synchronization point in @sync.
43*74fe6c29SRuslan Bukin  *
44*74fe6c29SRuslan Bukin  * Returns zero on success, a negative error code otherwise.
45*74fe6c29SRuslan Bukin  *
46*74fe6c29SRuslan Bukin  * Returns -pte_internal if @sync, @pos, or @config is NULL.
47*74fe6c29SRuslan Bukin  * Returns -pte_nosync if @pos lies outside of @config's buffer.
48*74fe6c29SRuslan Bukin  * Returns -pte_eos if no further synchronization point is found.
49*74fe6c29SRuslan Bukin  */
50*74fe6c29SRuslan Bukin extern int pt_sync_forward(const uint8_t **sync, const uint8_t *pos,
51*74fe6c29SRuslan Bukin 			   const struct pt_config *config);
52*74fe6c29SRuslan Bukin extern int pt_sync_backward(const uint8_t **sync, const uint8_t *pos,
53*74fe6c29SRuslan Bukin 			    const struct pt_config *config);
54*74fe6c29SRuslan Bukin 
55*74fe6c29SRuslan Bukin /* Manually synchronize onto the trace stream.
56*74fe6c29SRuslan Bukin  *
57*74fe6c29SRuslan Bukin  * Validate that @pos is within the bounds of @config's trace buffer and that
58*74fe6c29SRuslan Bukin  * there is a synchronization point at @pos.
59*74fe6c29SRuslan Bukin  *
60*74fe6c29SRuslan Bukin  * On success, stores @pos in @sync.
61*74fe6c29SRuslan Bukin  *
62*74fe6c29SRuslan Bukin  * Returns zero on success, a negative error code otherwise.
63*74fe6c29SRuslan Bukin  *
64*74fe6c29SRuslan Bukin  * Returns -pte_eos if @pos is outside of @config's trace buffer.
65*74fe6c29SRuslan Bukin  * Returns -pte_internal if @sync, @pos, or @config is NULL.
66*74fe6c29SRuslan Bukin  * Returns -pte_bad_packet if there is no PSB at @pos.
67*74fe6c29SRuslan Bukin  */
68*74fe6c29SRuslan Bukin extern int pt_sync_set(const uint8_t **sync, const uint8_t *pos,
69*74fe6c29SRuslan Bukin 		       const struct pt_config *config);
70*74fe6c29SRuslan Bukin 
71*74fe6c29SRuslan Bukin #endif /* PT_SYNC_H */
72