lkml.org 
[lkml]   [2019]   [Nov]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH -v5 04/17] x86/alternatives: Add and use text_gen_insn() helper
On Mon, 11 Nov 2019 14:12:56 +0100
Peter Zijlstra <peterz@infradead.org> wrote:

> +void *text_gen_insn(u8 opcode, const void *addr, const void *dest)
> +{
> + static union text_poke_insn insn; /* text_mutex */
> + int size = 0;
> +
> + lockdep_assert_held(&text_mutex);
> +
> + insn.opcode = opcode;
> +
> +#define __CASE(insn) \
> + case insn##_INSN_OPCODE: size = insn##_INSN_SIZE; break
> +
> + switch(opcode) {
> + __CASE(INT3);
> + __CASE(CALL);
> + __CASE(JMP32);
> + __CASE(JMP8);
> + }
> +
> + if (size > 1) {
> + insn.disp = (long)dest - (long)(addr + size);
> + if (size == 2)

Could we add a comment here. It took me a little bit to figure out why
you have this BUG_ON().

-- Steve


> + BUG_ON((insn.disp >> 31) != (insn.disp >> 7));
> + }
> +
> + return &insn.text;
> +}

\
 
 \ /
  Last update: 2019-11-12 18:11    [W:0.565 / U:0.392 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site