Skip to content

Commit c322ca8

Browse files
ptxed: drop category in iclass check
When checking the instruction class with ptxed --check, only use XED's instruction class, not the category. The latter gives the family of instructions that were added together, which isn't very helpful when considering the instruction classification. Signed-off-by: Markus Metzger <[email protected]>
1 parent e1a4d91 commit c322ca8

File tree

1 file changed

+98
-134
lines changed

1 file changed

+98
-134
lines changed

ptxed/src/ptxed.c

Lines changed: 98 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -667,181 +667,145 @@ static const char *visualize_iclass(enum pt_insn_class iclass)
667667
return "undefined";
668668
}
669669

670-
static void check_insn_iclass(const xed_inst_t *inst,
670+
static void check_insn_iclass(const xed_decoded_inst_t *inst,
671671
const struct pt_insn *insn, uint64_t offset)
672672
{
673-
xed_category_enum_t category;
674673
xed_iclass_enum_t iclass;
675674

676675
if (!inst || !insn) {
677676
printf("[internal error]\n");
678677
return;
679678
}
680679

681-
category = xed_inst_category(inst);
682-
iclass = xed_inst_iclass(inst);
683-
684-
switch (insn->iclass) {
685-
#if (LIBIPT_VERSION >= 0x201)
686-
case ptic_unknown:
687-
break;
688-
#else
689-
case ptic_error:
690-
break;
691-
#endif
692-
case ptic_ptwrite:
693-
case ptic_other:
694-
switch (category) {
695-
default:
680+
iclass = xed_decoded_inst_get_iclass(inst);
681+
switch (iclass) {
682+
default:
683+
if (insn->iclass == ptic_other)
696684
return;
697-
698-
case XED_CATEGORY_CALL:
699-
case XED_CATEGORY_RET:
700-
case XED_CATEGORY_UNCOND_BR:
701-
case XED_CATEGORY_SYSCALL:
702-
case XED_CATEGORY_SYSRET:
703-
break;
704-
705-
case XED_CATEGORY_COND_BR:
706-
switch (iclass) {
707-
case XED_ICLASS_XBEGIN:
708-
case XED_ICLASS_XEND:
709-
return;
710-
711-
default:
712-
break;
713-
}
714-
break;
715-
716-
case XED_CATEGORY_INTERRUPT:
717-
switch (iclass) {
718-
case XED_ICLASS_BOUND:
719-
return;
720-
721-
default:
722-
break;
723-
}
724-
break;
725-
}
726685
break;
727686

728-
case ptic_call:
729-
if (iclass == XED_ICLASS_CALL_NEAR)
687+
case XED_ICLASS_CALL_NEAR:
688+
if (insn->iclass == ptic_call)
730689
return;
731-
690+
#if (LIBIPT_VERSION >= 0x201)
691+
if (insn->iclass == ptic_indirect)
692+
return;
693+
#endif
732694
break;
733695

734-
case ptic_return:
735-
if (iclass == XED_ICLASS_RET_NEAR)
696+
case XED_ICLASS_RET_NEAR:
697+
if (insn->iclass == ptic_return)
736698
return;
737-
699+
#if (LIBIPT_VERSION >= 0x201)
700+
if (insn->iclass == ptic_indirect)
701+
return;
702+
#endif
738703
break;
739704

740-
case ptic_jump:
741-
if (iclass == XED_ICLASS_JMP)
705+
case XED_ICLASS_JMP:
706+
#if defined(XED_ICLASS_JMPABS_DEFINED) && XED_ICLASS_JMPABS_DEFINED
707+
case XED_ICLASS_JMPABS:
708+
#endif
709+
if (insn->iclass == ptic_jump)
742710
return;
743-
711+
#if (LIBIPT_VERSION >= 0x201)
712+
if (insn->iclass == ptic_indirect)
713+
return;
714+
#endif
744715
break;
745716

746-
case ptic_cond_jump:
747-
if (category == XED_CATEGORY_COND_BR)
717+
case XED_ICLASS_JB:
718+
case XED_ICLASS_JBE:
719+
case XED_ICLASS_JCXZ:
720+
case XED_ICLASS_JECXZ:
721+
case XED_ICLASS_JL:
722+
case XED_ICLASS_JLE:
723+
case XED_ICLASS_JNB:
724+
case XED_ICLASS_JNBE:
725+
case XED_ICLASS_JNL:
726+
case XED_ICLASS_JNLE:
727+
case XED_ICLASS_JNO:
728+
case XED_ICLASS_JNP:
729+
case XED_ICLASS_JNS:
730+
case XED_ICLASS_JNZ:
731+
case XED_ICLASS_JO:
732+
case XED_ICLASS_JP:
733+
case XED_ICLASS_JRCXZ:
734+
case XED_ICLASS_JS:
735+
case XED_ICLASS_JZ:
736+
case XED_ICLASS_LOOP:
737+
case XED_ICLASS_LOOPE:
738+
case XED_ICLASS_LOOPNE:
739+
if (insn->iclass == ptic_cond_jump)
748740
return;
749-
750741
break;
751742

752-
case ptic_far_call:
753-
switch (iclass) {
754-
default:
755-
break;
756-
757-
case XED_ICLASS_CALL_FAR:
758-
case XED_ICLASS_INT:
759-
case XED_ICLASS_INT1:
760-
case XED_ICLASS_INT3:
761-
case XED_ICLASS_INTO:
762-
case XED_ICLASS_SYSCALL:
743+
case XED_ICLASS_CALL_FAR:
744+
case XED_ICLASS_INT:
745+
case XED_ICLASS_INT1:
746+
case XED_ICLASS_INT3:
747+
case XED_ICLASS_INTO:
748+
case XED_ICLASS_SYSCALL:
763749
#if defined(XED_ICLASS_SYSCALL_AMD_DEFINED) && XED_ICLASS_SYSCALL_AMD_DEFINED
764-
case XED_ICLASS_SYSCALL_AMD:
750+
case XED_ICLASS_SYSCALL_AMD:
765751
#endif
766752
#if defined(XED_ICLASS_SYSCALL_32_DEFINED) && XED_ICLASS_SYSCALL_32_DEFINED
767-
case XED_ICLASS_SYSCALL_32:
753+
case XED_ICLASS_SYSCALL_32:
768754
#endif
769-
case XED_ICLASS_SYSENTER:
770-
case XED_ICLASS_VMCALL:
755+
case XED_ICLASS_SYSENTER:
756+
case XED_ICLASS_VMCALL:
757+
if (insn->iclass == ptic_far_call)
771758
return;
772-
}
773-
break;
774-
775-
case ptic_far_return:
776-
switch (iclass) {
777-
default:
778-
break;
779-
780-
case XED_ICLASS_RET_FAR:
781-
case XED_ICLASS_IRET:
782-
case XED_ICLASS_IRETD:
783-
case XED_ICLASS_IRETQ:
784-
case XED_ICLASS_SYSRET:
785-
case XED_ICLASS_SYSRET64:
786-
case XED_ICLASS_SYSRET_AMD:
787-
case XED_ICLASS_SYSEXIT:
788-
case XED_ICLASS_VMLAUNCH:
789-
case XED_ICLASS_VMRESUME:
790-
case XED_ICLASS_UIRET:
759+
#if (LIBIPT_VERSION >= 0x201)
760+
if (insn->iclass == ptic_indirect)
791761
return;
792-
}
762+
#endif
793763
break;
794764

795-
case ptic_far_jump:
796-
if (iclass == XED_ICLASS_JMP_FAR)
765+
#if defined(XED_ICLASS_ERETS_DEFINED) && XED_ICLASS_ERETS_DEFINED
766+
case XED_ICLASS_ERETS:
767+
#endif
768+
#if defined(XED_ICLASS_ERETU_DEFINED) && XED_ICLASS_ERETU_DEFINED
769+
case XED_ICLASS_ERETU:
770+
#endif
771+
case XED_ICLASS_IRET:
772+
case XED_ICLASS_IRETD:
773+
case XED_ICLASS_IRETQ:
774+
case XED_ICLASS_RET_FAR:
775+
case XED_ICLASS_SYSEXIT:
776+
case XED_ICLASS_SYSRET:
777+
case XED_ICLASS_SYSRET64:
778+
case XED_ICLASS_SYSRET_AMD:
779+
case XED_ICLASS_UIRET:
780+
case XED_ICLASS_VMLAUNCH:
781+
case XED_ICLASS_VMRESUME:
782+
if (insn->iclass == ptic_far_return)
797783
return;
798-
784+
#if (LIBIPT_VERSION >= 0x201)
785+
if (insn->iclass == ptic_indirect)
786+
return;
787+
#endif
799788
break;
800789

790+
case XED_ICLASS_JMP_FAR:
791+
if (insn->iclass == ptic_far_jump)
792+
return;
801793
#if (LIBIPT_VERSION >= 0x201)
802-
case ptic_indirect:
803-
switch (iclass) {
804-
default:
805-
break;
806-
807-
case XED_ICLASS_CALL_FAR:
808-
case XED_ICLASS_INT:
809-
case XED_ICLASS_INT1:
810-
case XED_ICLASS_INT3:
811-
case XED_ICLASS_INTO:
812-
case XED_ICLASS_SYSCALL:
813-
#if defined(XED_ICLASS_SYSCALL_AMD_DEFINED) && XED_ICLASS_SYSCALL_AMD_DEFINED
814-
case XED_ICLASS_SYSCALL_AMD:
815-
#endif
816-
#if defined(XED_ICLASS_SYSCALL_32_DEFINED) && XED_ICLASS_SYSCALL_32_DEFINED
817-
case XED_ICLASS_SYSCALL_32:
794+
if (insn->iclass == ptic_indirect)
795+
return;
818796
#endif
819-
case XED_ICLASS_SYSENTER:
820-
case XED_ICLASS_VMCALL:
821-
case XED_ICLASS_RET_FAR:
822-
case XED_ICLASS_IRET:
823-
case XED_ICLASS_IRETD:
824-
case XED_ICLASS_IRETQ:
825-
case XED_ICLASS_SYSRET:
826-
case XED_ICLASS_SYSRET64:
827-
case XED_ICLASS_SYSRET_AMD:
828-
case XED_ICLASS_SYSEXIT:
829-
case XED_ICLASS_VMLAUNCH:
830-
case XED_ICLASS_VMRESUME:
831-
case XED_ICLASS_JMP_FAR:
832-
case XED_ICLASS_JMP:
797+
break;
798+
799+
case XED_ICLASS_PTWRITE:
800+
if (insn->iclass == ptic_ptwrite)
833801
return;
834-
}
835802
break;
836-
#endif /* (LIBIPT_VERSION >= 0x201) */
837803
}
838804

839805
/* If we get here, @insn->iclass doesn't match XED's classification. */
840806
printf("[%" PRIx64 ", %" PRIx64 ": iclass error: iclass: %s, "
841-
"xed iclass: %s, category: %s]\n", offset, insn->ip,
842-
visualize_iclass(insn->iclass), xed_iclass_enum_t2str(iclass),
843-
xed_category_enum_t2str(category));
844-
807+
"xed iclass: %s]\n", offset, insn->ip,
808+
visualize_iclass(insn->iclass), xed_iclass_enum_t2str(iclass));
845809
}
846810

847811
static void check_insn_decode(xed_decoded_inst_t *inst,
@@ -904,7 +868,7 @@ static void check_insn(const struct pt_insn *insn, uint64_t offset)
904868
if (!xed_decoded_inst_valid(&inst))
905869
return;
906870

907-
check_insn_iclass(xed_decoded_inst_inst(&inst), insn, offset);
871+
check_insn_iclass(&inst, insn, offset);
908872
}
909873

910874
static void print_raw_insn(const struct pt_insn *insn)
@@ -1853,7 +1817,7 @@ static void check_block(const struct pt_block *block,
18531817
/* Check the last instruction's classification, if available. */
18541818
insn.iclass = block->iclass;
18551819
if (insn.iclass)
1856-
check_insn_iclass(xed_decoded_inst_inst(&inst), &insn, offset);
1820+
check_insn_iclass(&inst, &insn, offset);
18571821
}
18581822

18591823
static int drain_events_block(struct ptxed_decoder *decoder, uint64_t *time,

0 commit comments

Comments
 (0)