diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 3140316b50e8..adc54b42eba2 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1011,7 +1011,43 @@ static Error checkThreadCommand(const MachOObjectFile &Obj, CmdName + " command"); } } else if (cputype == MachO::CPU_TYPE_X86_64) { - if (flavor == MachO::x86_THREAD_STATE64) { + if (flavor == MachO::x86_THREAD_STATE) { + if (count != MachO::x86_THREAD_STATE_COUNT) + return malformedError("load command " + Twine(LoadCommandIndex) + + " count not x86_THREAD_STATE_COUNT for " + "flavor number " + Twine(nflavor) + " which is " + "a x86_THREAD_STATE flavor in " + CmdName + + " command"); + if (state + sizeof(MachO::x86_thread_state_t) > end) + return malformedError("load command " + Twine(LoadCommandIndex) + + " x86_THREAD_STATE extends past end of " + "command in " + CmdName + " command"); + state += sizeof(MachO::x86_thread_state_t); + } else if (flavor == MachO::x86_FLOAT_STATE) { + if (count != MachO::x86_FLOAT_STATE_COUNT) + return malformedError("load command " + Twine(LoadCommandIndex) + + " count not x86_FLOAT_STATE_COUNT for " + "flavor number " + Twine(nflavor) + " which is " + "a x86_FLOAT_STATE flavor in " + CmdName + + " command"); + if (state + sizeof(MachO::x86_float_state_t) > end) + return malformedError("load command " + Twine(LoadCommandIndex) + + " x86_FLOAT_STATE extends past end of " + "command in " + CmdName + " command"); + state += sizeof(MachO::x86_float_state_t); + } else if (flavor == MachO::x86_EXCEPTION_STATE) { + if (count != MachO::x86_EXCEPTION_STATE_COUNT) + return malformedError("load command " + Twine(LoadCommandIndex) + + " count not x86_EXCEPTION_STATE_COUNT for " + "flavor number " + Twine(nflavor) + " which is " + "a x86_EXCEPTION_STATE flavor in " + CmdName + + " command"); + if (state + sizeof(MachO::x86_exception_state_t) > end) + return malformedError("load command " + Twine(LoadCommandIndex) + + " x86_EXCEPTION_STATE extends past end of " + "command in " + CmdName + " command"); + state += sizeof(MachO::x86_exception_state_t); + } else if (flavor == MachO::x86_THREAD_STATE64) { if (count != MachO::x86_THREAD_STATE64_COUNT) return malformedError("load command " + Twine(LoadCommandIndex) + " count not x86_THREAD_STATE64_COUNT for " @@ -1023,6 +1059,18 @@ static Error checkThreadCommand(const MachOObjectFile &Obj, " x86_THREAD_STATE64 extends past end of " "command in " + CmdName + " command"); state += sizeof(MachO::x86_thread_state64_t); + } else if (flavor == MachO::x86_EXCEPTION_STATE64) { + if (count != MachO::x86_EXCEPTION_STATE64_COUNT) + return malformedError("load command " + Twine(LoadCommandIndex) + + " count not x86_EXCEPTION_STATE64_COUNT for " + "flavor number " + Twine(nflavor) + " which is " + "a x86_EXCEPTION_STATE64 flavor in " + CmdName + + " command"); + if (state + sizeof(MachO::x86_exception_state64_t) > end) + return malformedError("load command " + Twine(LoadCommandIndex) + + " x86_EXCEPTION_STATE64 extends past end of " + "command in " + CmdName + " command"); + state += sizeof(MachO::x86_exception_state64_t); } else { return malformedError("load command " + Twine(LoadCommandIndex) + " unknown flavor (" + Twine(flavor) + ") for " diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index b6c26ac9869e..c5aba86b20e1 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -9328,6 +9328,26 @@ static void PrintThreadCommand(MachO::thread_command t, const char *Ptr, outs() << "\t esh.flavor " << es.esh.flavor << " esh.count " << es.esh.count << "\n"; } + } else if (flavor == MachO::x86_EXCEPTION_STATE64) { + outs() << " flavor x86_EXCEPTION_STATE64\n"; + if (count == MachO::x86_EXCEPTION_STATE64_COUNT) + outs() << " count x86_EXCEPTION_STATE64_COUNT\n"; + else + outs() << " count " << count + << " (not x86_EXCEPTION_STATE64_COUNT)\n"; + struct MachO::x86_exception_state64_t es64; + left = end - begin; + if (left >= sizeof(MachO::x86_exception_state64_t)) { + memcpy(&es64, begin, sizeof(MachO::x86_exception_state64_t)); + begin += sizeof(MachO::x86_exception_state64_t); + } else { + memset(&es64, '\0', sizeof(MachO::x86_exception_state64_t)); + memcpy(&es64, begin, left); + begin += left; + } + if (isLittleEndian != sys::IsLittleEndianHost) + swapStruct(es64); + Print_x86_exception_state_t(es64); } else { outs() << " flavor " << flavor << " (unknown)\n"; outs() << " count " << count << "\n";