未处理的异常 0xC0000008:在动态重新编译器中指定了无效的句柄 [英] Unhandled exception 0xC0000008: An invalid handle was specified in dynamic recompiler

查看:62
本文介绍了未处理的异常 0xC0000008:在动态重新编译器中指定了无效的句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码是一个 MIPS->ARM 动态重新编译器.在多次运行recompile_function()后,它在下面代码的条件子句处崩溃,尽管它可以在前面的函数运行期间没有任何问题地运行这行代码.

The code is a MIPS->ARM dynamic recompiler. After many times of running recompile_function(), it crashes at the condition clause of below code, though it can run this line of code without any issue during the earlier function running.

void recompile_function(){

    //recompilation code
    ......

    if (out > (u_char *)((u_char *)base_addr + (1 << TARGET_SIZE_2) - MAX_OUTPUT_BLOCK_SIZE - JUMP_TABLE_SIZE))
        out = (u_char *)base_addr;

    // other code
    ......
}

变量输出是用于编写重新编译代码的指针.base_addr 始终指向已分配内存空间的原始起始位置.每次写入指令时,变量 out 前进 4 个字节,而 base_addr 保持不变.

Variable out is the pointer used to write the recompiled code. base_addr always points to the original start of the allocated memory space. Variable out progresses 4 bytes each time an instruction is written, while base_addr keeps unchanged.

extern char extra_memory[33554432];
#define BASE_ADDR ((int)(&extra_memory))
void *base_addr;
u_char *out;

void new_dynarec_init()
{
    protect_readwrite();
    base_addr = ((int)(&extra_memory));
    out = (u_char *)base_addr;
}

错误是frontend.exe 中 0x7738EC9F (ntdll.dll) 处的未处理异常:0xC0000008:指定的句柄无效."

The error is "Unhandled exception at 0x7738EC9F (ntdll.dll) in frontend.exe: 0xC0000008: An invalid handle was specified."

这是错误子句指令周围的反汇编代码.

This is the disassemble code around the faulting clause instruction.

#if NEW_DYNAREC == NEW_DYNAREC_ARM
    __clear_cache((void *)beginning, out);
53830242  ldr         r1,[r9]  
53830246  add         r3,r4,r5,lsl #2  
5383024A  mov         r0,r7  
5383024C  str         r3,[r2]  
5383024E  blx         __clear_cache_bugfix (537D19DCh)  
    //cacheflush((void *)beginning,out,0);
#endif

// If we're within 256K of the end of the buffer,
// start over from the beginning. (Is 256K enough?)
    if (out > (u_char *)((u_char *)base_addr + (1 << TARGET_SIZE_2) - MAX_OUTPUT_BLOCK_SIZE - JUMP_TABLE_SIZE))
53830252  mov         r2,#0xAA98  
53830256  movt        r2,#0x5462  
5383025A  ldr         r3,new_recompile_block+0A1E8h (53830550h)  
5383025C  ldr         r4,[r2]  
5383025E  ldr         r2,[r9]  
53830262  add         r3,r3,r4  
53830264  cmp         r2,r3  
53830266  bls         new_recompile_block+9F06h (5383026Eh)  
        out = (u_char *)base_addr;
53830268  mov         r2,r4  
5383026A  str         r4,[r9]   

这是调试器提示我的那一行.我检查了也指向这一行的反汇编窗口.更重要的是,如果我选择继续,则会弹出一个新错误,程序将在函数__report_gsfailure 中的代码行__fastfail"处崩溃.新错误是frontend.exe 中 0x53831547 (mupen64plus.dll) 处的未处理异常:堆栈 cookie 检测代码检测到基于堆栈的缓冲区溢出".0x53831546是代码行__fastfail"的地址.

It's the line the debugger prompts me. I checked the disassemble window that also points to this line. What's more, if I choose continue, a new error will pop up and the program will crash at the code line "__fastfail" in function __report_gsfailure. The new error is "Unhandled exception at 0x53831547 (mupen64plus.dll) in frontend.exe: Stack cookie instrumentation code detected a stack-based buffer overrun". 0x53831546 is the address of code line "__fastfail".

#pragma warning(push)
#pragma warning(disable: 4100) // unreferenced formal parameter
__declspec(noreturn) void __cdecl __report_gsfailure(GSFAILURE_PARAMETER)
{
5383153C  push        {r0,r1}  
5383153E  push        {r11,lr}  
53831542  mov         r11,sp  
    __fastfail(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE);
53831544  movs        r0,#2  
53831546  __fastfail  
}

// Declare stub for rangecheckfailure, since these occur often enough that the
// code bloat of setting up the parameters hurts performance
__declspec(noreturn) void __cdecl __report_rangecheckfailure()
{
53831548  push        {r11,lr}  
5383154C  mov         r11,sp  
    __report_securityfailure(FAST_FAIL_RANGE_CHECK_FAILURE);
5383154E  movs        r0,#8  
53831550  bl          __report_securityfailure (53831558h)  
53831554  __debugbreak  

寄存器 PC = 53831546 所以执行点是 __fastfail.

The register PC  = 53831546 so the execution point is __fastfail.

推荐答案

该错误是由位于崩溃条件子句上方的 __clear_cache 引起的.禁用该函数调用修复了崩溃.

The error is caused by __clear_cache which is located above the crashed condition clause. Disabling that function call fixed the crash.

这篇关于未处理的异常 0xC0000008:在动态重新编译器中指定了无效的句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆