Inserted hook to wrmsr operation. Windows Kernel put address on KPCR struct to fs/gs (x32/x64) register. Needs catch this moment and allow windbg server handle packets.
Signed-off-by: Mihail Abakumov <mikhail.abaku...@ispras.ru> Signed-off-by: Pavel Dovgalyuk <dovga...@ispras.ru> Signed-off-by: Dmitriy Koltunov <koltu...@ispras.ru> --- include/exec/windbgstub-utils.h | 2 ++ include/exec/windbgstub.h | 1 + stubs/windbgstub.c | 3 +++ target/i386/misc_helper.c | 3 +++ target/i386/windbgstub.c | 5 +++++ windbgstub.c | 13 +++++++++++++ 6 files changed, 27 insertions(+) diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h index 1c27ee4ce8..825d58b76b 100755 --- a/include/exec/windbgstub-utils.h +++ b/include/exec/windbgstub-utils.h @@ -50,4 +50,6 @@ _t; \ }) +bool windbg_on_load(void); + #endif diff --git a/include/exec/windbgstub.h b/include/exec/windbgstub.h index 21bc552e58..309f692383 100755 --- a/include/exec/windbgstub.h +++ b/include/exec/windbgstub.h @@ -18,6 +18,7 @@ #define WINDBG_DEBUG_ON false #endif +void windbg_try_load(void); int windbg_server_start(const char *device); #endif diff --git a/stubs/windbgstub.c b/stubs/windbgstub.c index 4951f59203..bd7e2dccd1 100755 --- a/stubs/windbgstub.c +++ b/stubs/windbgstub.c @@ -12,6 +12,9 @@ #include "qemu/osdep.h" #include "exec/windbgstub.h" +void windbg_try_load(void) +{} + int windbg_server_start(const char *device) { return 0; diff --git a/target/i386/misc_helper.c b/target/i386/misc_helper.c index 628f64aad5..ec1fcd2899 100644 --- a/target/i386/misc_helper.c +++ b/target/i386/misc_helper.c @@ -24,6 +24,7 @@ #include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "exec/address-spaces.h" +#include "exec/windbgstub.h" void helper_outb(CPUX86State *env, uint32_t port, uint32_t data) { @@ -385,6 +386,8 @@ void helper_wrmsr(CPUX86State *env) /* XXX: exception? */ break; } + + windbg_try_load(); } void helper_rdmsr(CPUX86State *env) diff --git a/target/i386/windbgstub.c b/target/i386/windbgstub.c index f54f5178fb..f2f83423a0 100755 --- a/target/i386/windbgstub.c +++ b/target/i386/windbgstub.c @@ -11,3 +11,8 @@ #include "qemu/osdep.h" #include "exec/windbgstub-utils.h" + +bool windbg_on_load(void) +{ + return false; +} diff --git a/windbgstub.c b/windbgstub.c index e30b8500e0..a2a6eb81b4 100755 --- a/windbgstub.c +++ b/windbgstub.c @@ -16,6 +16,7 @@ #include "qemu/cutils.h" #include "exec/windbgstub.h" #include "exec/windbgstub-utils.h" +#include "sysemu/kvm.h" typedef struct WindbgState { bool is_loaded; @@ -45,6 +46,13 @@ static void windbg_exit(void) g_free(windbg_state); } +void windbg_try_load(void) +{ + if (windbg_state && !windbg_state->is_loaded) { + windbg_state->is_loaded = windbg_on_load(); + } +} + int windbg_server_start(const char *device) { Chardev *chr = NULL; @@ -54,6 +62,11 @@ int windbg_server_start(const char *device) exit(1); } + if (kvm_enabled()) { + WINDBG_ERROR("KVM is not supported."); + exit(1); + } + if (!strstart(device, "pipe:", NULL)) { WINDBG_ERROR("Unsupported device. Supported only pipe."); exit(1);