Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:arch\x86\kernel\kprobes\opt.c Create Date:2022-07-28 08:39:21
Last Modify:2022-05-22 07:44:06 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Copy replacing target instructions* Target instructions MUST be relocatable (checked inside)* This is called when new aggr(opt)probe is allocated or reused.

Proto:int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *__unused)

Type:int

Parameter:

TypeParameterName
struct optimized_kprobe *op
struct kprobe *__unused
356  buf = NULL
360  If Not Decode whole function to ensure any instructions don't jump into target Then Return -EILSEQ
363  buf = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
364  If Not buf Then Return -ENOMEM
367  detour code buffer = slot = get_optinsn_slot()
368  If Not slot Then
369  ret = -ENOMEM
370  Go to out
377  rel = slot - location of the probe point + RELATIVEJUMP_SIZE
378  If abs - return absolute value of an argument*@x: the value. If it is unsigned type, it is converted to signed type first.* char is treated as if it was signed (regardless of whether it really is)* but the macro's return type is preserved as char.(rel) > 0x7fffffff Then
379  ret = -ERANGE
380  Go to err
384  memcpy(buf, ptinsn template addresses , TMPL_END_IDX)
387  ret = copy_optimized_instructions(buf + TMPL_END_IDX, location of the probe point , slot + TMPL_END_IDX)
389  If ret < 0 Then Go to err
391  the size of instructions copied to detour code buffer = ret
392  len = TMPL_END_IDX + the size of instructions copied to detour code buffer
395  Insert a move instruction which sets a pointer to eax/rdi (1st arg).
398  Insert a call instruction at address 'from', which calls address 'to'.
402  Insert a jump instruction at address 'from', which jumps to address 'to'.
404  len += RELATIVEJUMP_SIZE
407  xt_poke - Update instructions on a live kernel*@addr: address to modify*@opcode: source of the copy*@len: length to copy* Only atomic text poke/set should be allowed when not doing early patching
408  ret = 0
409  out :
410  free previously allocated memory
411  Return ret
413  err :
414  Free optimized instruction slot
415  Go to out