Teach DTrace about BTI on arm64

The Branch Target Identification (BTI) Armv8-A extension adds new
instructions that can be placed where we may indirrectly branch to,
e.g. at the start of a function called via a function pointer. We can't
emulate these in DTrace as the kernel will have raised a different
exception before the DTrace handler has run.

Skip over the BTI instruction if it's used as the first instruction in
a function.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Andrew Turner 2021-12-22 17:26:33 +00:00
parent 6521372e95
commit b5876847ac
2 changed files with 11 additions and 0 deletions

View File

@ -2466,6 +2466,9 @@ extern void dtrace_helpers_destroy(proc_t *);
#define B_DATA_MASK 0x00ffffff
#define B_INSTR 0x14000000
#define BTI_MASK 0xffffff3f
#define BTI_INSTR 0xd503241f
#define NOP_INSTR 0xd503201f
#define RET_INSTR 0xd65f03c0

View File

@ -118,6 +118,14 @@ fbt_provide_module_function(linker_file_t lf, int symindx,
instr = (uint32_t *)(symval->value);
limit = (uint32_t *)(symval->value + symval->size);
/*
* Ignore any bti instruction at the start of the function
* we need to keep it there for any indirect branches calling
* the function on Armv8.5+
*/
if ((*instr & BTI_MASK) == BTI_INSTR)
instr++;
/* Look for stp (pre-indexed) operation */
found = false;
/*