@@ -1925,6 +1925,8 @@ vector<string> current_env() {
19251925const uint8_t rdtsc_insn[2 ] = { 0x0f , 0x31 };
19261926
19271927static const uint8_t rdtscp_insn[] = { 0x0f , 0x01 , 0xf9 };
1928+ static const uint8_t tpause_insn[] = { 0x66 , 0x0f , 0xae , 0xf0 };
1929+ static const uint8_t tpause_rex_insn[] = { 0x66 , 0x41 , 0x0f , 0xae , 0xf0 };
19281930static const uint8_t cpuid_insn[] = { 0x0f , 0xa2 };
19291931static const uint8_t int3_insn[] = { 0xcc };
19301932static const uint8_t pushf_insn[] = { 0x9c };
@@ -1933,7 +1935,7 @@ static const uint8_t pushf16_insn[] = { 0x66, 0x9c };
19331935// XXX this probably needs to be extended to decode ignored prefixes
19341936SpecialInst special_instruction_at (Task* t, remote_code_ptr ip) {
19351937 if (is_x86ish (t->arch ())) {
1936- uint8_t insn[sizeof (rdtscp_insn )];
1938+ uint8_t insn[sizeof (tpause_rex_insn )];
19371939 ssize_t ret =
19381940 t->read_bytes_fallible (ip.to_data_ptr <uint8_t >(), sizeof (insn), insn);
19391941 if (ret < 0 ) {
@@ -1964,6 +1966,21 @@ SpecialInst special_instruction_at(Task* t, remote_code_ptr ip) {
19641966 !memcmp (insn, pushf16_insn, sizeof (pushf16_insn))) {
19651967 return {SpecialInstOpcode::X86_PUSHF16 };
19661968 }
1969+ // NB: These need to be last because they're destructive!
1970+ if (len >= sizeof (tpause_rex_insn)) {
1971+ // Mask off the register selector.
1972+ insn[4 ] &= ~0x07 ;
1973+ if (!memcmp (insn, tpause_rex_insn, sizeof (tpause_rex_insn))) {
1974+ return {SpecialInstOpcode::X86_TPAUSE_REX };
1975+ }
1976+ }
1977+ if (len >= sizeof (tpause_insn)) {
1978+ // Mask off the register selector.
1979+ insn[3 ] &= ~0x07 ;
1980+ if (!memcmp (insn, tpause_insn, sizeof (tpause_insn))) {
1981+ return {SpecialInstOpcode::X86_TPAUSE };
1982+ }
1983+ }
19671984 } else if (t->arch () == aarch64) {
19681985 uint8_t insn[4 ];
19691986 ssize_t ret =
@@ -1999,6 +2016,10 @@ size_t special_instruction_len(SpecialInstOpcode insn) {
19992016 return sizeof (pushf_insn);
20002017 } else if (insn == SpecialInstOpcode::X86_PUSHF16 ) {
20012018 return sizeof (pushf16_insn);
2019+ } else if (insn == SpecialInstOpcode::X86_TPAUSE ) {
2020+ return sizeof (tpause_insn);
2021+ } else if (insn == SpecialInstOpcode::X86_TPAUSE_REX ) {
2022+ return sizeof (tpause_rex_insn);
20022023 } else if (insn == SpecialInstOpcode::ARM_MRS_CNTFRQ_EL0 ||
20032024 insn == SpecialInstOpcode::ARM_MRS_CNTVCT_EL0 ||
20042025 insn == SpecialInstOpcode::ARM_MRS_CNTVCTSS_EL0 ) {
0 commit comments