Ticket UUID: | 450795 | |||
Title: | implement TclpCheckStackSpace() for unix | |||
Type: | Patch | Version: | None | |
Submitter: | msofer | Created on: | 2001-08-14 14:01:42 | |
Subsystem: | 38. Init - Library - Autoload | Assigned To: | msofer | |
Priority: | 5 Medium | Severity: | ||
Status: | Closed | Last Modified: | 2003-11-12 22:58:03 | |
Resolution: | Duplicate | Closed By: | hobbs | |
Closed on: | 2003-11-12 00:11:16 | |||
Description: |
TclpCheckStackSpace() (in unix/tclUnixInit.c) should be implemented for unix - it is already implemented for both Mac and Win. It's role is to prevent C-stack overflow, producing an error instead of who knows what. | |||
User Comments: |
msofer added on 2003-11-12 08:27:55:
Logged In: YES user_id=148712 IIUC, 746378 started on this approach and improved it a lot - in particular, making it work also for threaded builds. If that is correct, this patch is superceded by 746378. hobbs added on 2003-11-12 07:11:16: Logged In: YES user_id=72656 dup of 746378 - we should compare the differences between these two approaches. msofer added on 2002-02-28 00:33:35: File Added - 18530: stackSpace3.patch.gz Logged In: YES user_id=148712 New "production-ready" stackSpace3.patch, for review. It is still missing the adaptation to threaded builds; as before, it does not guard against stack-heap collisions. msofer added on 2002-02-27 21:50:45: Logged In: YES user_id=148712 Note that this patch implements a "light" TclpCheckStackSpace: it monitors the remaining stack space with respect to the maximum allowed by the OS, but *not* against stack-heap collisions. The win implementation (and presumably the mac too) monitor both. Joe English has proposed a solution for linux/gcc in non-threaded builds that monitors the stack-heap distance "as long as you haven't called mmap()/shmget/whatever (not sure how that affects the memory map)". It is done by setting the condition to monitor to ((&here > tclMinCStackPos) && (&here > sbrk(0) + tclMinCStackSize)) msofer added on 2002-02-26 22:56:55: File Added - 18465: stackSpace2.patch.gz msofer added on 2002-02-26 22:56:54: Logged In: YES user_id=148712 OKnow ... msofer added on 2002-02-26 22:52:19: File Deleted - 18464: Logged In: YES user_id=148712 Aargh! Removing patch2 2 (typos); back in a few minutes! msofer added on 2002-02-26 22:22:47: File Added - 18464: stackSpace2.patch.gz msofer added on 2002-02-26 22:22:46: Logged In: YES user_id=148712 Improved stackSpace2.patch: * corrections as suggested by Donal * more checks and default behaviour in tclUnixInit.c dkf added on 2002-02-26 20:57:39: File Added - 18461: configure.patch dkf added on 2002-02-26 20:57:33: Logged In: YES user_id=79902 Looks mostly good to me, both with GCC and with SunPro CC on Solaris/SPARC, except for the configure script which ought to print out more of what it is doing with your stackspace check as well as cacheing the values concerned. Luckily, this is easy to add - see the extra patch which I supply which should be applied *after* yours. The other minor quibble I've noticed (from using SunPro CC) is that you shouldn't do #undef TclpCheckStackSpace() but rather just #undef TclpCheckStackSpace (SunPro CC is great, because it moans about completely different things to GCC. :^) msofer added on 2002-02-26 00:37:30: File Added - 18399: stackSpace.patch.gz Logged In: YES user_id=148712 I attach a patch (gzipped) that implements TclpCheckStackSpace. Please test it on different unixen - it runs ok with gcc (egcs-2.91.66, glibc 2.1.3) on linux/intel. Some comments: 1. in order to use, the new function TclpInitCheckStackSpace (tclUnixInit.c) should be called with a stack address as early as possible. In the patch, this is done from Tcl_Main so that the writers of special shells do not have to worry about it. 2. as it is here, the functionality is not available for embedders - the new function is not declared in the stubs tables. If the functionality is deemed necessary, it may be worth considering making it public (or called from some new Tcl_InitializeSystem). That would require TIPping. 3. if TclpInitCheckStackSpace is never called, the behaviour is the same as without the patch: it is always assumed that there is enough stack space to continue. Comments welcome! |
Attachments:
- stackSpace3.patch.gz [download] added by msofer on 2002-02-28 00:33:35. [details]
- stackSpace2.patch.gz [download] added by msofer on 2002-02-26 22:56:54. [details]
- configure.patch [download] added by dkf on 2002-02-26 20:57:34. [details]
- stackSpace.patch.gz [download] added by msofer on 2002-02-26 00:37:30. [details]