Mercurial > vim
comparison src/os_win32.c @ 27581:78e3b38b0d33 v8.2.4317
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Commit: https://github.com/vim/vim/commit/63ff72aab91679725077eab5c5405267792268bd
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Feb 7 13:54:01 2022 +0000
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Problem: MS-Windows: Vim exits when Python 3 initialisation fails.
Solution: Hook into the exit() function to recover from the failure.
(Ken Takata, closes #9710)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 07 Feb 2022 15:00:04 +0100 |
parents | 4f1c67a5f446 |
children | a077948be0f4 |
comparison
equal
deleted
inserted
replaced
27580:bd5169e86dc5 | 27581:78e3b38b0d33 |
---|---|
570 return TRUE; | 570 return TRUE; |
571 return FALSE; | 571 return FALSE; |
572 } | 572 } |
573 #endif | 573 #endif |
574 | 574 |
575 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) || defined(PROTO) | 575 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) \ |
576 || defined(FEAT_PYTHON3) || defined(PROTO) | |
576 /* | 577 /* |
577 * Get related information about 'funcname' which is imported by 'hInst'. | 578 * Get related information about 'funcname' which is imported by 'hInst'. |
578 * If 'info' is 0, return the function address. | 579 * If 'info' is 0, return the function address. |
579 * If 'info' is 1, return the module name which the function is imported from. | 580 * If 'info' is 1, return the module name which the function is imported from. |
581 * If 'info' is 2, hook the function with 'ptr', and return the original | |
582 * function address. | |
580 */ | 583 */ |
581 static void * | 584 static void * |
582 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info) | 585 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info, |
586 const void *ptr) | |
583 { | 587 { |
584 PBYTE pImage = (PBYTE)hInst; | 588 PBYTE pImage = (PBYTE)hInst; |
585 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; | 589 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; |
586 PIMAGE_NT_HEADERS pPE; | 590 PIMAGE_NT_HEADERS pPE; |
587 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; | 591 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
609 continue; | 613 continue; |
610 pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage | 614 pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage |
611 + (UINT_PTR)(pINT->u1.AddressOfData)); | 615 + (UINT_PTR)(pINT->u1.AddressOfData)); |
612 if (strcmp((char *)pImpName->Name, funcname) == 0) | 616 if (strcmp((char *)pImpName->Name, funcname) == 0) |
613 { | 617 { |
618 void *original; | |
619 DWORD old, new = PAGE_READWRITE; | |
620 | |
614 switch (info) | 621 switch (info) |
615 { | 622 { |
616 case 0: | 623 case 0: |
617 return (void *)pIAT->u1.Function; | 624 return (void *)pIAT->u1.Function; |
618 case 1: | 625 case 1: |
619 return (void *)(pImage + pImpDesc->Name); | 626 return (void *)(pImage + pImpDesc->Name); |
627 case 2: | |
628 original = (void *)pIAT->u1.Function; | |
629 VirtualProtect(&pIAT->u1.Function, sizeof(void *), | |
630 new, &old); | |
631 pIAT->u1.Function = (UINT_PTR)ptr; | |
632 VirtualProtect(&pIAT->u1.Function, sizeof(void *), | |
633 old, &new); | |
634 return original; | |
620 default: | 635 default: |
621 return NULL; | 636 return NULL; |
622 } | 637 } |
623 } | 638 } |
624 } | 639 } |
632 HINSTANCE | 647 HINSTANCE |
633 find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname) | 648 find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname) |
634 { | 649 { |
635 char *modulename; | 650 char *modulename; |
636 | 651 |
637 modulename = (char *)get_imported_func_info(hInst, funcname, 1); | 652 modulename = (char *)get_imported_func_info(hInst, funcname, 1, NULL); |
638 if (modulename != NULL) | 653 if (modulename != NULL) |
639 return GetModuleHandleA(modulename); | 654 return GetModuleHandleA(modulename); |
640 return NULL; | 655 return NULL; |
641 } | 656 } |
642 | 657 |
644 * Get the address of 'funcname' which is imported by 'hInst' DLL. | 659 * Get the address of 'funcname' which is imported by 'hInst' DLL. |
645 */ | 660 */ |
646 void * | 661 void * |
647 get_dll_import_func(HINSTANCE hInst, const char *funcname) | 662 get_dll_import_func(HINSTANCE hInst, const char *funcname) |
648 { | 663 { |
649 return get_imported_func_info(hInst, funcname, 0); | 664 return get_imported_func_info(hInst, funcname, 0, NULL); |
665 } | |
666 | |
667 /* | |
668 * Hook the function named 'funcname' which is imported by 'hInst' DLL, | |
669 * and return the original function address. | |
670 */ | |
671 void * | |
672 hook_dll_import_func(HINSTANCE hInst, const char *funcname, const void *hook) | |
673 { | |
674 return get_imported_func_info(hInst, funcname, 2, hook); | |
650 } | 675 } |
651 #endif | 676 #endif |
652 | 677 |
653 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) | 678 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
654 # ifndef GETTEXT_DLL | 679 # ifndef GETTEXT_DLL |