angr.analyses.decompiler.known_patterns.kernel_err¶
Linux kernel <linux/err.h> error-pointer idioms.
IS_ERR(p) tests (unsigned long)p >= (unsigned long)-MAX_ERRNO; the
threshold is derived from the context’s word width, so one definition covers
32- and 64-bit.
gcc emits the test in four different shapes depending on where it lands, and a
pattern that covers only one of them silently misses most real code: the literal
>= THR, the strength-reduced > THR-1 (the value form at -O2), and the
operand-swapped <= / < forms (the branch-condition form). All four are
matched. The comparison must be unsigned (a signed compare against the same
constant is an unrelated test), which is checked in where because the DSL
does not model BinaryOp.signed.
PTR_ERR and ERR_PTR are pure casts that compile to a bare register move
and leave no residue at all, so there is nothing to match and they are
deliberately absent.
Opt-in: these are kernel idioms, and renaming a comparison to IS_ERR() in a
user-space binary would be misleading even though the threshold constant is in
practice unique to err.h. Calibrated against
tests/x86_64/decompiler/known_patterns_kernel_macros (gcc -O2).