Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-11-12
22:58 • Ticket [450795ffff] implement TclpCheckStackSpace() for unix status still Cl... artifact: 099f029f55 user: dkf
08:27 • Ticket [450795ffff]: 4 changes artifact: 5d84ca04bf user: msofer
07:11 • Closed ticket [450795ffff]. artifact: 664f4c79c1 user: hobbs
2002-02-28
00:33 • Ticket [450795ffff]: 4 changes artifact: bdb62b7216 user: msofer
00:33 • Add attachment stackSpace3.patch.gz to ticket [450795ffffffffff|450795f... artifact: ba4c3aedba user: msofer
2002-02-27
21:50 • Ticket [450795ffff] implement TclpCheckStackSpace() for unix status still Op... artifact: 3650ab36bc user: msofer
2002-02-26
22:56 • Ticket [450795ffff]: 4 changes artifact: 8a22192604 user: msofer
22:56 • Ticket [450795ffff]: 4 changes artifact: 1d5252b3b3 user: msofer
22:56 • Add attachment stackSpace2.patch.gz to ticket [450795ffffffffff|450795f... artifact: 768563674c user: msofer
22:52 • Ticket [450795ffff] implement TclpCheckStackSpace() for unix status still Op... artifact: 79b7c523cb user: msofer
22:22 • Ticket [450795ffff]: 4 changes artifact: 44fc7cdc0b user: msofer
22:22 • Ticket [450795ffff]: 4 changes artifact: 6b002961a0 user: msofer
20:57 • Ticket [450795ffff]: 4 changes artifact: abacd0a2c7 user: dkf
20:57 • Add attachment configure.patch to ticket [450795ffff] artifact: 792844340f user: dkf
20:57 • Ticket [450795ffff] implement TclpCheckStackSpace() for unix status still Op... artifact: 6b75a326ba user: dkf
00:42 • Ticket [450795ffff]: 1 change artifact: d2e196538e user: msofer
00:38 • Ticket [450795ffff]: 2 changes artifact: e4d7f3817f user: msofer
00:37 • Add attachment stackSpace.patch.gz to ticket [450795ffffffffff|450795ff... artifact: 1e2b3301f1 user: msofer
00:37 • Ticket [450795ffff] implement TclpCheckStackSpace() for unix status still Op... artifact: 7e42e45f89 user: msofer
2001-08-14
14:01 • New ticket [450795ffff]. artifact: 4c62c78ec2 user: msofer

implement TclpCheckStackSpace() for unix

Closed / Duplicate450795ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 23 years ago
Descriptionplain2001-08-14 14:01:42
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.
msoferplain2002-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!
msofer Ticket [450795ffff]: 2 changes [History diff]2002-02-26 00:38:31
msofer Ticket [450795ffff]: 1 change [History diff]2002-02-26 00:42:11
dkfplain2002-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. :^)
dkfplain2002-02-26 20:57:39
File Added - 18461: configure.patch
msoferplain2002-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
msoferplain2002-02-26 22:22:47
File Added - 18464: stackSpace2.patch.gz
msoferplain2002-02-26 22:52:19
File Deleted - 18464: 

Logged In: YES 
user_id=148712

Aargh! Removing patch2 2 (typos); back in a few minutes!
msoferplain2002-02-26 22:56:54
Logged In: YES 
user_id=148712

OKnow ...
msoferplain2002-02-26 22:56:55
File Added - 18465: stackSpace2.patch.gz
msoferplain2002-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))
msoferplain2002-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.
hobbsplain2003-11-12 07:11:16
Logged In: YES 
user_id=72656

dup of 746378 - we should compare the differences between 
these two approaches.
msoferplain2003-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.
dkf Ticket [450795ffff]: 1 change [History diff]2003-11-12 22:58:03
Log in (anonymous is fine) to add a comment.

Attachments: