To: vim-dev@vim.org Subject: Patch 6.2.496 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.2.496 Problem: FreeBSD 4.x: When compiled with the pthread library (Python) a complicated pattern may cause Vim to crash. Catching the signal doesn't work. Solution: When compiled with threads, instead of using the normal stacksize limit, use the size of the initial stack. Files: src/auto/configure, src/config.h.in, src/configure.in, src/os_unix.c *** ../vim-6.2.495/src/auto/configure Wed Apr 14 22:12:42 2004 --- src/auto/configure Sun Apr 25 13:22:47 2004 *************** *** 5642,5663 **** sys/resource.h sys/systeminfo.h locale.h \ sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \ poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \ ! libgen.h util/debug.h util/msg18n.h frame.h \ sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h wchar.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 ! echo "configure:5574: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" ! { (eval echo configure:5584: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* --- 5646,5667 ---- sys/resource.h sys/systeminfo.h locale.h \ sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \ poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \ ! libgen.h util/debug.h util/msg18n.h frame.h pthread_np.h \ sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h wchar.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 ! echo "configure:5655: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" ! { (eval echo configure:5665: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* *** ../vim-6.2.495/src/config.h.in Fri Mar 26 14:25:07 2004 --- src/config.h.in Sun Apr 25 13:23:10 2004 *************** *** 200,205 **** --- 200,206 ---- #undef HAVE_LOCALE_H #undef HAVE_NDIR_H #undef HAVE_POLL_H + #undef HAVE_PTHREAD_NP_H #undef HAVE_PWD_H #undef HAVE_SETJMP_H #undef HAVE_SGTTY_H *** ../vim-6.2.495/src/configure.in Wed Apr 14 22:12:42 2004 --- src/configure.in Sun Apr 25 13:22:43 2004 *************** *** 1835,1841 **** sys/resource.h sys/systeminfo.h locale.h \ sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \ poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \ ! libgen.h util/debug.h util/msg18n.h frame.h \ sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h wchar.h) dnl On Mac OS X strings.h exists but produces a warning message :-( --- 1835,1841 ---- sys/resource.h sys/systeminfo.h locale.h \ sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \ poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \ ! libgen.h util/debug.h util/msg18n.h frame.h pthread_np.h \ sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h wchar.h) dnl On Mac OS X strings.h exists but produces a warning message :-( *** ../vim-6.2.495/src/os_unix.c Wed Apr 14 11:08:53 2004 --- src/os_unix.c Sun Apr 25 13:27:36 2004 *************** *** 610,615 **** --- 610,620 ---- #if defined(HAVE_GETRLIMIT) || defined(PROTO) static char *stack_limit = NULL; + #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) + # include + # include + #endif + /* * Find out until how var the stack can grow without getting into trouble. * Called when starting up and when switching to the signal stack in *************** *** 620,625 **** --- 625,631 ---- { struct rlimit rlp; int i; + long lim; /* Set the stack limit to 15/16 of the allowable size. Skip this when the * limit doesn't fit in a long (rlim_cur might be "long long"). */ *************** *** 630,645 **** # endif ) { if (stack_grows_downwards) { ! stack_limit = (char *)((long)&i - ((long)rlp.rlim_cur / 16L * 15L)); if (stack_limit >= (char *)&i) /* overflow, set to 1/16 of current stack position */ stack_limit = (char *)((long)&i / 16L); } else { ! stack_limit = (char *)((long)&i + ((long)rlp.rlim_cur / 16L * 15L)); if (stack_limit <= (char *)&i) stack_limit = NULL; /* overflow */ } --- 636,669 ---- # endif ) { + lim = (long)rlp.rlim_cur; + #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) + { + pthread_attr_t attr; + size_t size; + + /* On FreeBSD the initial thread always has a fixed stack size, no + * matter what the limits are set to. Normally it's 1 Mbyte. */ + pthread_attr_init(&attr); + if (pthread_attr_get_np(pthread_self(), &attr) == 0) + { + pthread_attr_getstacksize(&attr, &size); + if (lim > (long)size) + lim = (long)size; + } + pthread_attr_destroy(&attr); + } + #endif if (stack_grows_downwards) { ! stack_limit = (char *)((long)&i - (lim / 16L * 15L)); if (stack_limit >= (char *)&i) /* overflow, set to 1/16 of current stack position */ stack_limit = (char *)((long)&i / 16L); } else { ! stack_limit = (char *)((long)&i + (lim / 16L * 15L)); if (stack_limit <= (char *)&i) stack_limit = NULL; /* overflow */ } *** ../vim-6.2.495/src/version.c Sun Apr 25 13:07:13 2004 --- src/version.c Sun Apr 25 13:38:12 2004 *************** *** 639,640 **** --- 639,642 ---- { /* Add new patch number below this line */ + /**/ + 496, /**/ -- Anyone who is capable of getting themselves made President should on no account be allowed to do the job. -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///