PT_IMAGE_REMOVE_BY_FILENAME(3)
π PT_IMAGE_REMOVE_BY_FILENAME(3) π
okay so bestie, we're in section 3 of the manual (the library-call girlies section, iykyk) and today's main character is pt_image_remove_by_filename, with pt_image_remove_by_asid riding shotgun. both of them do one thing and they do it well: they yeet sections out of a traced memory image descriptor. so real. so necessary. let's get into it. π
β¨ NAME β¨
pt_image_remove_by_filename, pt_image_remove_by_asid β remove sections from a traced memory image descriptor π§Ήπ
π¦ SYNOPSIS π¦
#include <intel-pt.h>
int pt_image_remove_by_filename(struct pt_image *image,
const char *filename,
const struct pt_asid *asid);
int pt_image_remove_by_asid(struct pt_image *image,
const struct pt_asid *asid);
Link with -lipt.
πΈ DESCRIPTION πΈ
so pt_image_remove_by_filename() removes all sections from image that were added by a call to pt_image_add_file(3) with an identical filename argument, or by a call to pt_image_copy(3) from such a section. and listen β sections that are based on the same underlying file but that were added using a different filename argument are not removed. they stay. they're thriving. periodt. π
if the asid argument is not NULL, it removes only sections that were added with a matching address-space identifier. See pt_image_add_file(3).
and then pt_image_remove_by_asid(3) removes all sections from image that were added by a call to pt_image_add_file(3) with a matching asid argument, or by a call to pt_image_copy(3) from such a section. See pt_image_add_file(3). π
now, the matchmaking rules, because this is the part everyone gets wrong and I need you to lock in:
two pt_asid objects match in their cr3 or vmcs field if one of them does not provide the field (i.e. sets it to pt_asid_no_cr3 or pt_asid_no_vmcs respectively) or if the provided values are identical.
two pt_asid objects match if they match in all fields.
that's it. that's the whole vibe check. β¨
π₯ RETURN VALUE π₯
Both functions return the number of sections removed on success, or a negative pt_error_code enumeration constant in case of an error. no cap. π
π ERRORS π
pte_invalidβ the image argument isNULL, or the filename argument isNULL(pt_image_remove_by_filename()only). like, asid-only girlies don't even have a filename to be mad about. π€·
π EXAMPLE π
this one is a whole novel and I love her for it. read every comment, they're the plot:
int foo(struct pt_image *image, uint64_t cr3) {
struct pt_asid asid1, asid2;
int errcode;
pt_asid_init(&asid1);
asid1.cr3 = cr3;
pt_asid_init(&asid2);
asid2.cr3 = ~cr3;
errcode = pt_image_add_file(image, "/path/to/libfoo.so",
0xa000, 0x100, &asid1, 0xb000);
if (errcode < 0)
return errcode;
errcode = pt_image_add_file(image, "rel/path/to/libfoo.so",
0xa000, 0x100, &asid1, 0xc000);
if (errcode < 0)
return errcode;
/* This call would only remove the section added first:
*
* - filename matches only the first section's filename
* - NULL matches every asid
*/
(void) pt_image_remove_by_filename(image,
"/path/to/libfoo.so",
NULL);
/* This call would not remove any of the above sections:
*
* - filename matches the first section's filename
* - asid2 does not match asid1
*/
(void) pt_image_remove_by_filename(image,
"/path/to/libfoo.so",
&asid2);
/* This call would not remove any of the above sections:
*
* - asid2 does not match asid1
*/
(void) pt_image_remove_by_asid(image, &asid2);
/* This call would remove both sections:
*
* - asid1 matches itself
*/
(void) pt_image_remove_by_asid(image, &asid1);
/* This call would remove both sections:
*
* - NULL matches every asid
*/
(void) pt_image_remove_by_asid(image, NULL);
}
π SEE ALSO π
pt_image_alloc(3)pt_image_free(3)pt_image_add_file(3)pt_image_add_cached(3)pt_image_copy(3)pt_insn_set_image(3)pt_insn_get_image(3)
bestie this whole thing is giving "go read pt_image_add_file(3) before you text me back" energy and honestly? correct.
and that's the page!! π the footer down at the bottom is just the title echoing itself one more time β PT_IMAGE_REMOVE_BY_FILENAME(3) β no version, no date, just the name, like a signature at the end of a love letter. iconic behaviour honestly. go remove some sections, you've got this π«Άβ¨π
π¦ 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