Mercurial > vim
comparison src/os_unix.c @ 25581:b8aa2c93d156 v8.2.3327
patch 8.2.3327: no check for sysconf() failing
Commit: https://github.com/vim/vim/commit/ba9c23e77655766f6c59de8be732b7577f795ed3
Author: Zdenek Dohnal <zdohnal@redhat.com>
Date: Wed Aug 11 14:20:05 2021 +0200
patch 8.2.3327: no check for sysconf() failing
Problem: No check for sysconf() failing.
Solution: If sysconf() fails use SIGSTKSZ for the signal stack size.
(Zdenek Dohnal, closes #8743)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 11 Aug 2021 14:30:05 +0200 |
parents | 50c6b0250c04 |
children | f165d99cda45 |
comparison
equal
deleted
inserted
replaced
25580:540ac90ccb0c | 25581:b8aa2c93d156 |
---|---|
781 * This helps when we run out of stack space, which causes a SIGSEGV. The | 781 * This helps when we run out of stack space, which causes a SIGSEGV. The |
782 * signal handler then must run on another stack, since the normal stack is | 782 * signal handler then must run on another stack, since the normal stack is |
783 * completely full. | 783 * completely full. |
784 */ | 784 */ |
785 | 785 |
786 #if !defined SIGSTKSZ && !defined(HAVE_SYSCONF_SIGSTKSZ) | |
787 # define SIGSTKSZ 8000 // just a guess of how much stack is needed... | |
788 #endif | |
789 | |
790 # ifdef HAVE_SIGALTSTACK | 786 # ifdef HAVE_SIGALTSTACK |
791 static stack_t sigstk; // for sigaltstack() | 787 static stack_t sigstk; // for sigaltstack() |
792 # else | 788 # else |
793 static struct sigstack sigstk; // for sigstack() | 789 static struct sigstack sigstk; // for sigstack() |
794 # endif | 790 # endif |
791 | |
792 /* | |
793 * Get a size of signal stack. | |
794 * Preference (if available): sysconf > SIGSTKSZ > guessed size | |
795 */ | |
796 static long int get_signal_stack_size() | |
797 { | |
798 # ifdef HAVE_SYSCONF_SIGSTKSZ | |
799 long int size = -1; | |
800 | |
801 // return size only if sysconf doesn't return an error | |
802 if ((size = sysconf(_SC_SIGSTKSZ)) > -1) | |
803 return size; | |
804 # endif | |
805 | |
806 # ifdef SIGSTKSZ | |
807 // if sysconf() isn't available or gives error, return SIGSTKSZ | |
808 // if defined | |
809 return SIGSTKSZ; | |
810 # endif | |
811 | |
812 // otherwise guess the size | |
813 return 8000; | |
814 } | |
795 | 815 |
796 static char *signal_stack; | 816 static char *signal_stack; |
797 | 817 |
798 static void | 818 static void |
799 init_signal_stack(void) | 819 init_signal_stack(void) |
804 # ifdef HAVE_SS_BASE | 824 # ifdef HAVE_SS_BASE |
805 sigstk.ss_base = signal_stack; | 825 sigstk.ss_base = signal_stack; |
806 # else | 826 # else |
807 sigstk.ss_sp = signal_stack; | 827 sigstk.ss_sp = signal_stack; |
808 # endif | 828 # endif |
809 # ifdef HAVE_SYSCONF_SIGSTKSZ | 829 sigstk.ss_size = get_signal_stack_size(); |
810 sigstk.ss_size = sysconf(_SC_SIGSTKSZ); | |
811 # else | |
812 sigstk.ss_size = SIGSTKSZ; | |
813 # endif | |
814 sigstk.ss_flags = 0; | 830 sigstk.ss_flags = 0; |
815 (void)sigaltstack(&sigstk, NULL); | 831 (void)sigaltstack(&sigstk, NULL); |
816 # else | 832 # else |
817 sigstk.ss_sp = signal_stack; | 833 sigstk.ss_sp = signal_stack; |
818 if (stack_grows_downwards) | 834 if (stack_grows_downwards) |
819 # ifdef HAVE_SYSCONF_SIGSTKSZ | 835 sigstk.ss_sp += get_signal_stack_size() - 1; |
820 sigstk.ss_sp += sysconf(_SC_SIGSTKSZ) - 1; | |
821 # else | |
822 sigstk.ss_sp += SIGSTKSZ - 1; | |
823 # endif | |
824 sigstk.ss_onstack = 0; | 836 sigstk.ss_onstack = 0; |
825 (void)sigstack(&sigstk, NULL); | 837 (void)sigstack(&sigstk, NULL); |
826 # endif | 838 # endif |
827 } | 839 } |
828 } | 840 } |
3276 * running out of stack space. | 3288 * running out of stack space. |
3277 * Use of sigaltstack() is preferred, it's more portable. | 3289 * Use of sigaltstack() is preferred, it's more portable. |
3278 * Ignore any errors. | 3290 * Ignore any errors. |
3279 */ | 3291 */ |
3280 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | 3292 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) |
3281 # ifdef HAVE_SYSCONF_SIGSTKSZ | 3293 signal_stack = alloc(get_signal_stack_size()); |
3282 signal_stack = alloc(sysconf(_SC_SIGSTKSZ)); | |
3283 # else | |
3284 signal_stack = alloc(SIGSTKSZ); | |
3285 # endif | |
3286 init_signal_stack(); | 3294 init_signal_stack(); |
3287 #endif | 3295 #endif |
3288 } | 3296 } |
3289 | 3297 |
3290 #if defined(EXITFREE) || defined(PROTO) | 3298 #if defined(EXITFREE) || defined(PROTO) |