PT_PKT_SYNC_FORWARD(3)
β¨ PT_PKT_SYNC_FORWARD(3) β¨
okay bestie, sit down, hydrate, and let me tell you about pt_pkt_sync_forward, pt_pkt_sync_backward, and pt_pkt_sync_set β the trio that gets your Intel(R) Processor Trace packet decoder back in sync with the trace stream. this is the PT_PKT_SYNC_FORWARD(3) manual page, and it's lowkey iconic. π
πΈ NAME πΈ
pt_pkt_sync_forward, pt_pkt_sync_backward, pt_pkt_sync_set β synchronize an Intel(R) Processor Trace packet decoder
π¦ SYNOPSIS π¦
#include <intel-pt.h>
int pt_pkt_sync_forward(struct pt_packet_decoder *decoder);
int pt_pkt_sync_backward(struct pt_packet_decoder *decoder);
int pt_pkt_sync_set(struct pt_packet_decoder *decoder,
uint64_t offset);
Link with -lipt. (yes, that's the whole vibe, don't forget it π)
π DESCRIPTION π
so, pt_pkt_sync_forward() and pt_pkt_sync_backward() do the main character move: they take an Intel Processor Trace (Intel PT) packet decoder β the one pointed to by decoder β and synchronize it onto the trace stream inside decoder's trace buffer. the way they do it? they go looking for a Packet Stream Boundary (PSB) packet in that trace stream, and if they find one, they set decoder's current position to that packet. slay. β¨
pt_pkt_sync_forward()β searches in the forward direction, starting fromdecoder's current position and heading toward the end of the trace buffer. but ifdecoderis freshly allocated and hasn't been synchronized yet? the search starts from the beginning of the trace. new decoder, fresh start, we love that. π±pt_pkt_sync_backward()β searches in the backward direction, fromdecoder's current position toward the beginning of the trace buffer. and again, ifdecoderis brand new and never synced, the search starts from the end of the trace. backwards bestie behavior, but make it functional. π¦pt_pkt_sync_set()β no searching, no drama, it just setsdecoder's current position tooffsetbytes from the beginning of its trace buffer. direct. decisive. periodt. π
β RETURN VALUE β
all three synchronization functions return zero or a positive value when they ate π
, or a negative pt_error_code enumeration constant if something went wrong. π
π ERRORS π
pte_invalidβ thedecoderargument isNULL. (bestie. you gave it nothing. it cannot work with nothing.) πpte_eosβ there is no (further) PSB packet in the trace stream, which applies topt_pkt_sync_forward()andpt_pkt_sync_backward(). OR theoffsetargument is too big and the resulting position would land outside ofdecoder's trace buffer, which is thept_pkt_sync_set()case. either way: end of stream, no more crumbs. π
π EXAMPLE π
here's the moment you've been waiting for β this example re-synchronizes an Intel PT packet decoder after decode errors, and it's giving "keep going until the universe stops you":
int foo(struct pt_packet_decoder *decoder) {
for (;;) {
int errcode;
errcode = pt_pkt_sync_forward(decoder);
if (errcode < 0)
return errcode;
do {
errcode = decode(decoder);
} while (errcode >= 0);
}
}
look at that loop. resilient. unbothered. re-syncing every time life (the trace) throws a decode error at it. π₯
π SEE ALSO π
pt_pkt_alloc_decoder(3)pt_pkt_free_decoder(3)pt_pkt_get_offset(3)pt_pkt_get_sync_offset(3)pt_pkt_get_config(3)pt_pkt_next(3)
and that's the whole page, bestie π«Ά this was PT_PKT_SYNC_FORWARD(3), footer and all β go forth, synchronize, and stay on your PSB. iykyk. ππ§ββοΈ
π¦ where this page comes from
- fedora 43: libipt-devel 2.1.2-3.fc43 Β· BSD-3-Clause
- fedora 43: libipt-devel 2.1.2-3.fc43 Β· BSD-3-Clause
- fedora 44: libipt-devel 2.1.2-4.fc44 Β· BSD-3-Clause
- fedora 44: libipt-devel 2.1.2-4.fc44 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms