------------------------------------------------------------------------------ [ENHANCED] VFP 9.0 FIX - CATCH THE MEMORY ACCESS VIOLATION EXCEPTION January 2024 ------------------------------------------------------------------------------ CCB 1. BUG: If we enable catching the memory access violation exception in Visual FoxPro Advanced, when Visual FoxPro causes the memory access violation exception (exception code 0xC0000005), it will display the exception dialog box twice, and then it will display a dialog box "Are you sure you want to exit Visual FoxPro?", if we select "Yes", it will exit Visual FoxPro, if we select "No", it will cause the error "There is not enough memory to complete this operation (Error 43)", and then it will return to Visual FoxPro, now we can do some important work, and then exit Visual FoxPro. It is the startup default for Visual FoxPro Advanced Interactive Development Environment (IDE). Please refer to the picture testcatchexception.png: If we disable catching the memory access violation exception in Visual FoxPro Advanced, when Visual FoxPro causes the memory access violation exception (exception code 0xC0000005), it will display the exception dialog box twice, and then exit Visual FoxPro. It is the startup default for Visual FoxPro Advanced Runtime and Visual FoxPro Advanced Multi-threaded Runtime. 2. CAUSE: There are some BUGs in the following code. 3. RESOLUTION: We can write some code to fix the BUG. Fun61ca6d :: ; proc near pushd 01Ch ;0x0061ca6d : 6a1c pushd offset Data92b680 ;0x0061ca6f : 6880b69200 call Fun42c14f ;0x0061ca74 : e8d6f6e0ff mov eax , dword ptr [ ebp + 8 ] ;0x0061ca79 : 8b4508 xor edi , edi ;0x0061ca7c : 33ff mov dword ptr [ ebp - 28 ] , edi ;0x0061ca7e : 897de4 cmp dword ptr [ ebp + 12 ] , 0C00000FDh ;0x0061ca81 : 817d0cfd0000c0 jne Label61caa3 ;0x0061ca88 : 7519 mov eax , dword ptr [ eax + 4 ] ;0x0061ca8a : 8b4004 mov dword ptr [ eax + 0B8h ] , offset Label61ca63 ;0x0061ca8d : c780b800000063ca6100 call _resetstkoflw ;0x0061ca97 : ff15f4799100 or dword ptr [ ebp - 28 ] , 0FFFFFFFFh ;0x0061ca9d : 834de4ff jmp Label61cb1c ;0x0061caa1 : eb79 Label61caa3 :: cmp dword ptr [ ebp + 16 ] , edi ;0x0061caa3 : 397d10 je Label61cb1c ;0x0061caa6 : 7474 push eax ;0x0061caa8 : 50 push edi ;0x0061caa9 : 57 pushd offset Data9259b4 ;0x0061caaa : 68b4599200 call Fun61ca47 ;0x0061caaf : e893ffffff mov dword ptr [ ebp - 36 ] , eax ;0x0061cab4 : 8945dc cmp eax , 01h ;0x0061cab7 : 83f801 je Label61cb0f ;0x0061caba : 7453 mov dword ptr [ ebp - 4 ] , edi ;0x0061cabc : 897dfc call Fun5531c3 ;0x0061cabf : e8ff66f3ff push dword ptr [ ebp + 12 ] ;0x0061cac4 : ff750c call Fun846807 ;0x0061cac7 : e83b9d2200 mov esi , eax ;0x0061cacc : 8bf0 mov dword ptr [ ebp - 40 ] , esi ;0x0061cace : 8975d8 cmp esi , edi ;0x0061cad1 : 3bf7 je Label61cb0b ;0x0061cad3 : 7436 mov ecx , 0910h ;0x0061cad5 : b910090000 call Fun42c583 ;0x0061cada : e8a4fae0ff mov dword ptr [ ebp - 32 ] , eax ;0x0061cadf : 8945e0 pushd 01h ;0x0061cae2 : 6a01 call Fun7bddae ;0x0061cae4 : e8c5121a00 mov eax , dword ptr [esi] ;0x0061cae9 : 8b06 mov dword ptr [ ebp - 44 ] , eax ;0x0061caeb : 8945d4 pushd 010h ;0x0061caee : 6a10 push dword ptr [ ebp - 32 ] ;0x0061caf0 : ff75e0 push eax ;0x0061caf3 : 50 push edi ;0x0061caf4 : 57 call MessageBoxA ;0x0061caf5 : ff15d4729100 mov ecx , esi ;0x0061cafb : 8bce call Fun42c1e2 ;0x0061cafd : e8e0f6e0ff ; ; ------------------------------------------------------------------- ; VFP 9.0 FIX - CATCH THE MEMORY ACCESS VIOLATION EXCEPTION ; May 2022 ; ------------------------------------------------------------------- ; CCB ; ; Catch the memory access violation exception (exception code 0xC0000005). ; ; 2022/5/13, by ccb ; cmp dword ptr vfpa_sys9100_data,00h je Label61cb02 cmp dword ptr [ ebp + 12 ] , 0C0000005h jne Label61cb02 pushd 00h pushd 02h pushd 00h pushd 00h lea eax , byte ptr vfpa_sys9100_text push eax call Fun6da248 cmp eax , 02h jne Label61cb02 Label61cb00 :: mov eax , dword ptr [ ebp + 8 ] mov eax , dword ptr [ eax + 4 ] mov dword ptr [ eax + 0B8h ] , offset Label61cb01 call _resetstkoflw or dword ptr [ ebp - 28 ] , 0FFFFFFFFh jmp Label61cb1c Label61cb01 :: mov ecx , 0B6h jmp Fun544742 Label61cb02 :: jmp Label61cb0b ;0x0061cb02 : eb07 Label61cb0b :: or dword ptr [ ebp - 4 ] , 0FFFFFFFFh ;0x0061cb0b : 834dfcff Label61cb0f :: cmp dword ptr [ ebp - 36 ] , 02h ;0x0061cb0f : 837ddc02 jne Label61cb1c ;0x0061cb13 : 7507 mov dword ptr [ ebp - 28 ] , 01h ;0x0061cb15 : c745e401000000 Label61cb1c :: mov eax , dword ptr [ ebp - 28 ] ;0x0061cb1c : 8b45e4 call Fun42c18a ;0x0061cb1f : e866f6e0ff ret 0Ch ;0x0061cb24 : c20c00 4. APPLIES TO: VFP 6.0.8167.0 VFP 6.0.8961.0 (SP5) VFP 7.0.0.9262 VFP 7.0.0.9465 (SP1) VFP 8.0.0.2521 VFP 8.0.0.3117 (SP1) VFP 9.0.0.2412 VFP 9.0.0.3504 (SP1) VFP 9.0.0.4611 (SP2) VFP 9.0.0.5015 (SP2) VFP 9.0.0.5411 (SP2) VFP 9.0.0.5721 (SP2) VFP 9.0.0.5815 (SP2) VFP 9.0.0.6303 (SP2) VFP 9.0.0.6602 (SP2) VFP 9.0.0.7423 (SP2) The bug has been fixed in VFP Advanced. 5. REFERENCE WEBSITES: 1, baiyujia.com: http://www.baiyujia.com http://www.baiyujia.com/vfpdocuments/f_vfp9fix212.asp 6. OTHER: For reference only, there is no guarantees. Any questions or suggestions, please send me an email at ccb2000@163.com. |