1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: Kprobe event argument syntax 4 5[ -f kprobe_events ] || exit_unsupported # this is configurable 6 7grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue 8 9echo 0 > events/enable 10echo > kprobe_events 11 12PROBEFUNC="vfs_read" 13GOODREG= 14BADREG= 15GOODSYM="_sdata" 16if ! grep -qw ${GOODSYM} /proc/kallsyms ; then 17 GOODSYM=$PROBEFUNC 18fi 19BADSYM="deaqswdefr" 20SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "` 21GOODTYPE="x16" 22BADTYPE="y16" 23 24case `uname -m` in 25x86_64|i[3456]86) 26 GOODREG=%ax 27 BADREG=%ex 28;; 29aarch64) 30 GOODREG=%x0 31 BADREG=%ax 32;; 33arm*) 34 GOODREG=%r0 35 BADREG=%ax 36;; 37ppc*) 38 GOODREG=%r3 39 BADREG=%msr 40;; 41*) 42 echo "Please implement other architecture here" 43 exit_untested 44esac 45 46test_goodarg() # Good-args 47{ 48 while [ "$1" ]; do 49 echo "p ${PROBEFUNC} $1" > kprobe_events 50 shift 1 51 done; 52} 53 54test_badarg() # Bad-args 55{ 56 while [ "$1" ]; do 57 ! echo "p ${PROBEFUNC} $1" > kprobe_events 58 shift 1 59 done; 60} 61 62echo > kprobe_events 63 64: "Register access" 65test_goodarg ${GOODREG} 66test_badarg ${BADREG} 67 68: "Symbol access" 69test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10" 70test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \ 71 "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10" 72 73: "Stack access" 74test_goodarg "\$stack" "\$stack0" "\$stack1" 75test_badarg "\$stackp" "\$stack0+10" "\$stack1-10" 76 77: "Retval access" 78echo "r ${PROBEFUNC} \$retval" > kprobe_events 79! echo "p ${PROBEFUNC} \$retval" > kprobe_events 80 81: "Comm access" 82test_goodarg "\$comm" 83 84: "Indirect memory access" 85test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \ 86 "+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))" 87test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \ 88 "+10(\$comm)" "+0(${GOODREG})+10" 89 90: "Name assignment" 91test_goodarg "varname=${GOODREG}" 92test_badarg "varname=varname2=${GOODREG}" 93 94: "Type syntax" 95test_goodarg "${GOODREG}:${GOODTYPE}" 96test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \ 97 "${GOODTYPE}:${GOODREG}" 98 99: "Combination check" 100 101test_goodarg "\$comm:string" "+0(\$stack):string" 102test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string" 103 104echo > kprobe_events 105