From 68b5a0979ec2dccbaf8488dd4b8ddcb9c4af9920 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 1 Feb 2014 00:12:36 -0800 Subject: [PATCH] Logging undefined extern calls. --- .../x64/lowering/lowering_sequences.cc | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/alloy/backend/x64/lowering/lowering_sequences.cc b/src/alloy/backend/x64/lowering/lowering_sequences.cc index 00489d38f..9b41948cc 100644 --- a/src/alloy/backend/x64/lowering/lowering_sequences.cc +++ b/src/alloy/backend/x64/lowering/lowering_sequences.cc @@ -103,6 +103,12 @@ void Dummy() { // } +void UndefinedCallExtern(void* raw_context, FunctionInfo* symbol_info) { + XELOGW("undefined extern call to %.8X %s", + symbol_info->address(), + symbol_info->name()); +} + uint64_t DynamicRegisterLoad(void* raw_context, uint32_t address) { auto thread_state = *((ThreadState**)raw_context); auto cbs = thread_state->runtime()->access_callbacks(); @@ -339,14 +345,18 @@ table->AddSequence(OPCODE_CALL_INDIRECT_TRUE, [](X64Emitter& e, Instr*& i) { table->AddSequence(OPCODE_CALL_EXTERN, [](X64Emitter& e, Instr*& i) { auto symbol_info = i->src1.symbol_info; XEASSERT(symbol_info->behavior() == FunctionInfo::BEHAVIOR_EXTERN); - XEASSERTNOTNULL(symbol_info->extern_handler()); - // rdx = target host function - // r8 = arg0 - // r9 = arg1 - e.mov(e.rdx, (uint64_t)symbol_info->extern_handler()); - e.mov(e.r8, (uint64_t)symbol_info->extern_arg0()); - e.mov(e.r9, (uint64_t)symbol_info->extern_arg1()); - TransitionToHost(e); + if (!symbol_info->extern_handler()) { + e.mov(e.rdx, (uint64_t)symbol_info); + CallNative(e, UndefinedCallExtern); + } else { + // rdx = target host function + // r8 = arg0 + // r9 = arg1 + e.mov(e.rdx, (uint64_t)symbol_info->extern_handler()); + e.mov(e.r8, (uint64_t)symbol_info->extern_arg0()); + e.mov(e.r9, (uint64_t)symbol_info->extern_arg1()); + TransitionToHost(e); + } i = e.Advance(i); return true; });