[Kernel] Research on C++ exceptions.
This commit is contained in:
@@ -31,8 +31,7 @@ typedef struct {
|
|||||||
} X_THREADNAME_INFO;
|
} X_THREADNAME_INFO;
|
||||||
static_assert_size(X_THREADNAME_INFO, 0x10);
|
static_assert_size(X_THREADNAME_INFO, 0x10);
|
||||||
|
|
||||||
void RtlRaiseException(pointer_t<X_EXCEPTION_RECORD> record) {
|
void HandleSetThreadName(pointer_t<X_EXCEPTION_RECORD> record) {
|
||||||
if (record->exception_code == 0x406D1388) {
|
|
||||||
// SetThreadName. FFS.
|
// SetThreadName. FFS.
|
||||||
// https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
|
// https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
|
||||||
|
|
||||||
@@ -66,15 +65,68 @@ void RtlRaiseException(pointer_t<X_EXCEPTION_RECORD> record) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(benvanik): unwinding required here?
|
// TODO(benvanik): unwinding required here?
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (record->exception_code == 0xE06D7363) {
|
typedef struct {
|
||||||
|
xe::be<int32_t> mdisp;
|
||||||
|
xe::be<int32_t> pdisp;
|
||||||
|
xe::be<int32_t> vdisp;
|
||||||
|
} x_PMD;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
xe::be<uint32_t> properties;
|
||||||
|
xe::be<uint32_t> type_ptr;
|
||||||
|
x_PMD this_displacement;
|
||||||
|
xe::be<int32_t> size_or_offset;
|
||||||
|
xe::be<uint32_t> copy_function_ptr;
|
||||||
|
} x_s__CatchableType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
xe::be<int32_t> number_catchable_types;
|
||||||
|
xe::be<uint32_t> catchable_type_ptrs[1];
|
||||||
|
} x_s__CatchableTypeArray;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
xe::be<uint32_t> attributes;
|
||||||
|
xe::be<uint32_t> unwind_ptr;
|
||||||
|
xe::be<uint32_t> forward_compat_ptr;
|
||||||
|
xe::be<uint32_t> catchable_type_array_ptr;
|
||||||
|
} x_s__ThrowInfo;
|
||||||
|
|
||||||
|
void HandleCppException(pointer_t<X_EXCEPTION_RECORD> record) {
|
||||||
// C++ exception.
|
// C++ exception.
|
||||||
// https://blogs.msdn.com/b/oldnewthing/archive/2010/07/30/10044061.aspx
|
// https://blogs.msdn.com/b/oldnewthing/archive/2010/07/30/10044061.aspx
|
||||||
|
// http://www.drdobbs.com/visual-c-exception-handling-instrumentat/184416600
|
||||||
|
// http://www.openrce.org/articles/full_view/21
|
||||||
|
|
||||||
|
assert_true(record->number_parameters == 3);
|
||||||
|
assert_true(record->exception_information[0] == 0x19930520);
|
||||||
|
|
||||||
|
auto thrown_ptr = record->exception_information[1];
|
||||||
|
auto thrown = kernel_memory()->TranslateVirtual(thrown_ptr);
|
||||||
|
auto vftable_ptr = *reinterpret_cast<xe::be<uint32_t>*>(thrown);
|
||||||
|
|
||||||
|
auto throw_info_ptr = record->exception_information[2];
|
||||||
|
auto throw_info =
|
||||||
|
kernel_memory()->TranslateVirtual<x_s__ThrowInfo*>(throw_info_ptr);
|
||||||
|
auto catchable_types =
|
||||||
|
kernel_memory()->TranslateVirtual<x_s__CatchableTypeArray*>(
|
||||||
|
throw_info->catchable_type_array_ptr);
|
||||||
|
|
||||||
xe::debugging::Break();
|
xe::debugging::Break();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtlRaiseException(pointer_t<X_EXCEPTION_RECORD> record) {
|
||||||
|
switch (record->exception_code) {
|
||||||
|
case 0x406D1388: {
|
||||||
|
HandleSetThreadName(record);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 0xE06D7363: {
|
||||||
|
HandleCppException(record);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(benvanik): unwinding.
|
// TODO(benvanik): unwinding.
|
||||||
// This is going to suck.
|
// This is going to suck.
|
||||||
|
|||||||
Reference in New Issue
Block a user