@@ -146,12 +146,11 @@ static bool has_notrack_prefix(struct insn *insn)
146146
147147int arch_decode_instruction (struct objtool_file * file , const struct section * sec ,
148148 unsigned long offset , unsigned int maxlen ,
149- unsigned int * len , enum insn_type * type ,
150- unsigned long * immediate ,
151- struct list_head * ops_list )
149+ struct instruction * insn )
152150{
151+ struct list_head * ops_list = & insn -> stack_ops ;
153152 const struct elf * elf = file -> elf ;
154- struct insn insn ;
153+ struct insn ins ;
155154 int x86_64 , ret ;
156155 unsigned char op1 , op2 , op3 , prefix ,
157156 rex = 0 , rex_b = 0 , rex_r = 0 , rex_w = 0 , rex_x = 0 ,
@@ -165,42 +164,42 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
165164 if (x86_64 == -1 )
166165 return -1 ;
167166
168- ret = insn_decode (& insn , sec -> data -> d_buf + offset , maxlen ,
167+ ret = insn_decode (& ins , sec -> data -> d_buf + offset , maxlen ,
169168 x86_64 ? INSN_MODE_64 : INSN_MODE_32 );
170169 if (ret < 0 ) {
171170 WARN ("can't decode instruction at %s:0x%lx" , sec -> name , offset );
172171 return -1 ;
173172 }
174173
175- * len = insn .length ;
176- * type = INSN_OTHER ;
174+ insn -> len = ins .length ;
175+ insn -> type = INSN_OTHER ;
177176
178- if (insn .vex_prefix .nbytes )
177+ if (ins .vex_prefix .nbytes )
179178 return 0 ;
180179
181- prefix = insn .prefixes .bytes [0 ];
180+ prefix = ins .prefixes .bytes [0 ];
182181
183- op1 = insn .opcode .bytes [0 ];
184- op2 = insn .opcode .bytes [1 ];
185- op3 = insn .opcode .bytes [2 ];
182+ op1 = ins .opcode .bytes [0 ];
183+ op2 = ins .opcode .bytes [1 ];
184+ op3 = ins .opcode .bytes [2 ];
186185
187- if (insn .rex_prefix .nbytes ) {
188- rex = insn .rex_prefix .bytes [0 ];
186+ if (ins .rex_prefix .nbytes ) {
187+ rex = ins .rex_prefix .bytes [0 ];
189188 rex_w = X86_REX_W (rex ) >> 3 ;
190189 rex_r = X86_REX_R (rex ) >> 2 ;
191190 rex_x = X86_REX_X (rex ) >> 1 ;
192191 rex_b = X86_REX_B (rex );
193192 }
194193
195- if (insn .modrm .nbytes ) {
196- modrm = insn .modrm .bytes [0 ];
194+ if (ins .modrm .nbytes ) {
195+ modrm = ins .modrm .bytes [0 ];
197196 modrm_mod = X86_MODRM_MOD (modrm );
198197 modrm_reg = X86_MODRM_REG (modrm ) + 8 * rex_r ;
199198 modrm_rm = X86_MODRM_RM (modrm ) + 8 * rex_b ;
200199 }
201200
202- if (insn .sib .nbytes ) {
203- sib = insn .sib .bytes [0 ];
201+ if (ins .sib .nbytes ) {
202+ sib = ins .sib .bytes [0 ];
204203 /* sib_scale = X86_SIB_SCALE(sib); */
205204 sib_index = X86_SIB_INDEX (sib ) + 8 * rex_x ;
206205 sib_base = X86_SIB_BASE (sib ) + 8 * rex_b ;
@@ -254,7 +253,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
254253 break ;
255254
256255 case 0x70 ... 0x7f :
257- * type = INSN_JUMP_CONDITIONAL ;
256+ insn -> type = INSN_JUMP_CONDITIONAL ;
258257 break ;
259258
260259 case 0x80 ... 0x83 :
@@ -278,7 +277,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
278277 if (!rm_is_reg (CFI_SP ))
279278 break ;
280279
281- imm = insn .immediate .value ;
280+ imm = ins .immediate .value ;
282281 if (op1 & 2 ) { /* sign extend */
283282 if (op1 & 1 ) { /* imm32 */
284283 imm <<= 32 ;
@@ -309,7 +308,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
309308 ADD_OP (op ) {
310309 op -> src .type = OP_SRC_AND ;
311310 op -> src .reg = CFI_SP ;
312- op -> src .offset = insn .immediate .value ;
311+ op -> src .offset = ins .immediate .value ;
313312 op -> dest .type = OP_DEST_REG ;
314313 op -> dest .reg = CFI_SP ;
315314 }
@@ -356,7 +355,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
356355 op -> src .reg = CFI_SP ;
357356 op -> dest .type = OP_DEST_REG_INDIRECT ;
358357 op -> dest .reg = modrm_rm ;
359- op -> dest .offset = insn .displacement .value ;
358+ op -> dest .offset = ins .displacement .value ;
360359 }
361360 break ;
362361 }
@@ -389,7 +388,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
389388 op -> src .reg = modrm_reg ;
390389 op -> dest .type = OP_DEST_REG_INDIRECT ;
391390 op -> dest .reg = CFI_BP ;
392- op -> dest .offset = insn .displacement .value ;
391+ op -> dest .offset = ins .displacement .value ;
393392 }
394393 break ;
395394 }
@@ -402,7 +401,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
402401 op -> src .reg = modrm_reg ;
403402 op -> dest .type = OP_DEST_REG_INDIRECT ;
404403 op -> dest .reg = CFI_SP ;
405- op -> dest .offset = insn .displacement .value ;
404+ op -> dest .offset = ins .displacement .value ;
406405 }
407406 break ;
408407 }
@@ -419,7 +418,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
419418 ADD_OP (op ) {
420419 op -> src .type = OP_SRC_REG_INDIRECT ;
421420 op -> src .reg = CFI_BP ;
422- op -> src .offset = insn .displacement .value ;
421+ op -> src .offset = ins .displacement .value ;
423422 op -> dest .type = OP_DEST_REG ;
424423 op -> dest .reg = modrm_reg ;
425424 }
@@ -432,7 +431,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
432431 ADD_OP (op ) {
433432 op -> src .type = OP_SRC_REG_INDIRECT ;
434433 op -> src .reg = CFI_SP ;
435- op -> src .offset = insn .displacement .value ;
434+ op -> src .offset = ins .displacement .value ;
436435 op -> dest .type = OP_DEST_REG ;
437436 op -> dest .reg = modrm_reg ;
438437 }
@@ -464,7 +463,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
464463
465464 /* lea disp(%src), %dst */
466465 ADD_OP (op ) {
467- op -> src .offset = insn .displacement .value ;
466+ op -> src .offset = ins .displacement .value ;
468467 if (!op -> src .offset ) {
469468 /* lea (%src), %dst */
470469 op -> src .type = OP_SRC_REG ;
@@ -487,7 +486,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
487486 break ;
488487
489488 case 0x90 :
490- * type = INSN_NOP ;
489+ insn -> type = INSN_NOP ;
491490 break ;
492491
493492 case 0x9c :
@@ -511,39 +510,39 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
511510 if (op2 == 0x01 ) {
512511
513512 if (modrm == 0xca )
514- * type = INSN_CLAC ;
513+ insn -> type = INSN_CLAC ;
515514 else if (modrm == 0xcb )
516- * type = INSN_STAC ;
515+ insn -> type = INSN_STAC ;
517516
518517 } else if (op2 >= 0x80 && op2 <= 0x8f ) {
519518
520- * type = INSN_JUMP_CONDITIONAL ;
519+ insn -> type = INSN_JUMP_CONDITIONAL ;
521520
522521 } else if (op2 == 0x05 || op2 == 0x07 || op2 == 0x34 ||
523522 op2 == 0x35 ) {
524523
525524 /* sysenter, sysret */
526- * type = INSN_CONTEXT_SWITCH ;
525+ insn -> type = INSN_CONTEXT_SWITCH ;
527526
528527 } else if (op2 == 0x0b || op2 == 0xb9 ) {
529528
530529 /* ud2 */
531- * type = INSN_BUG ;
530+ insn -> type = INSN_BUG ;
532531
533532 } else if (op2 == 0x0d || op2 == 0x1f ) {
534533
535534 /* nopl/nopw */
536- * type = INSN_NOP ;
535+ insn -> type = INSN_NOP ;
537536
538537 } else if (op2 == 0x1e ) {
539538
540539 if (prefix == 0xf3 && (modrm == 0xfa || modrm == 0xfb ))
541- * type = INSN_ENDBR ;
540+ insn -> type = INSN_ENDBR ;
542541
543542
544543 } else if (op2 == 0x38 && op3 == 0xf8 ) {
545- if (insn .prefixes .nbytes == 1 &&
546- insn .prefixes .bytes [0 ] == 0xf2 ) {
544+ if (ins .prefixes .nbytes == 1 &&
545+ ins .prefixes .bytes [0 ] == 0xf2 ) {
547546 /* ENQCMD cannot be used in the kernel. */
548547 WARN ("ENQCMD instruction at %s:%lx" , sec -> name ,
549548 offset );
@@ -591,29 +590,29 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
591590
592591 case 0xcc :
593592 /* int3 */
594- * type = INSN_TRAP ;
593+ insn -> type = INSN_TRAP ;
595594 break ;
596595
597596 case 0xe3 :
598597 /* jecxz/jrcxz */
599- * type = INSN_JUMP_CONDITIONAL ;
598+ insn -> type = INSN_JUMP_CONDITIONAL ;
600599 break ;
601600
602601 case 0xe9 :
603602 case 0xeb :
604- * type = INSN_JUMP_UNCONDITIONAL ;
603+ insn -> type = INSN_JUMP_UNCONDITIONAL ;
605604 break ;
606605
607606 case 0xc2 :
608607 case 0xc3 :
609- * type = INSN_RETURN ;
608+ insn -> type = INSN_RETURN ;
610609 break ;
611610
612611 case 0xc7 : /* mov imm, r/m */
613612 if (!opts .noinstr )
614613 break ;
615614
616- if (insn .length == 3 + 4 + 4 && !strncmp (sec -> name , ".init.text" , 10 )) {
615+ if (ins .length == 3 + 4 + 4 && !strncmp (sec -> name , ".init.text" , 10 )) {
617616 struct reloc * immr , * disp ;
618617 struct symbol * func ;
619618 int idx ;
@@ -661,17 +660,17 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
661660
662661 case 0xca : /* retf */
663662 case 0xcb : /* retf */
664- * type = INSN_CONTEXT_SWITCH ;
663+ insn -> type = INSN_CONTEXT_SWITCH ;
665664 break ;
666665
667666 case 0xe0 : /* loopne */
668667 case 0xe1 : /* loope */
669668 case 0xe2 : /* loop */
670- * type = INSN_JUMP_CONDITIONAL ;
669+ insn -> type = INSN_JUMP_CONDITIONAL ;
671670 break ;
672671
673672 case 0xe8 :
674- * type = INSN_CALL ;
673+ insn -> type = INSN_CALL ;
675674 /*
676675 * For the impact on the stack, a CALL behaves like
677676 * a PUSH of an immediate value (the return address).
@@ -683,30 +682,30 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
683682 break ;
684683
685684 case 0xfc :
686- * type = INSN_CLD ;
685+ insn -> type = INSN_CLD ;
687686 break ;
688687
689688 case 0xfd :
690- * type = INSN_STD ;
689+ insn -> type = INSN_STD ;
691690 break ;
692691
693692 case 0xff :
694693 if (modrm_reg == 2 || modrm_reg == 3 ) {
695694
696- * type = INSN_CALL_DYNAMIC ;
697- if (has_notrack_prefix (& insn ))
695+ insn -> type = INSN_CALL_DYNAMIC ;
696+ if (has_notrack_prefix (& ins ))
698697 WARN ("notrack prefix found at %s:0x%lx" , sec -> name , offset );
699698
700699 } else if (modrm_reg == 4 ) {
701700
702- * type = INSN_JUMP_DYNAMIC ;
703- if (has_notrack_prefix (& insn ))
701+ insn -> type = INSN_JUMP_DYNAMIC ;
702+ if (has_notrack_prefix (& ins ))
704703 WARN ("notrack prefix found at %s:0x%lx" , sec -> name , offset );
705704
706705 } else if (modrm_reg == 5 ) {
707706
708707 /* jmpf */
709- * type = INSN_CONTEXT_SWITCH ;
708+ insn -> type = INSN_CONTEXT_SWITCH ;
710709
711710 } else if (modrm_reg == 6 ) {
712711
@@ -723,7 +722,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
723722 break ;
724723 }
725724
726- * immediate = insn .immediate .nbytes ? insn .immediate .value : 0 ;
725+ insn -> immediate = ins .immediate .nbytes ? ins .immediate .value : 0 ;
727726
728727 return 0 ;
729728}
0 commit comments