Artifacts Associated With Ticket 1865728
Ticket change [9b26e1f41e] (rid 111074) by mmaslano on 2008-01-07 09:01:02:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The checking stack in tcl8.5.0 causing infinite loop in programmes using tcl scripts. The good example is run game 8Kingdoms with tcl8.5 and nothing is working, because of running in a loop. The problem was located in checking stack. Here is comparing a pointer returned from malloc with an address from a variable in the current stack frame, assuming that if stackaddress < heapaddress (on architectures where the stack grows down) that the stack has grown into the heap. With using address randomization or threads (multiple stacks in one address space) doesn't make sense to check it. Other thing are protected mode in OS, you can disallow the stack to grow into already allocated memory and then is checking really uselles. I solved my problem with option CFLAGS=-DTCL_NO_STACK_CHECK=1 and that fix my problems, but I appreciated clean code. Thank you.
- foundin initialized to: "None"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "mmaslano"
- subsystem initialized to: "None"
- title initialized to: "stack checking code isn't functional"
- type initialized to: "Bug"
Ticket change [eb36c1c58c] (rid 103502) by mistachkin on 2008-01-07 16:07:16:
- icomment:
Logged In: YES user_id=113501 Originator: NO The code did not used to compare heap versus stack addresses. I'm not sure what the current state of the code is; however, it also did not function correctly for on the FreeBSD box that I originally developed the Unix stack checking code on.
- login: "mistachkin"
- mimetype: "text/plain"
- priority changed to: "8"
- username: "mistachkin"
- icomment:
Ticket change [d2efd5b5fc] (rid 113610) by msofer on 2008-01-07 16:51:13:
- assignee changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 Originator: NO Please provide platform details, what you mean by "nothing is working because of running in a loop", and as much debugging help as possible. Do you get an infinite loop? A segfault? An error? Any message? Can you provide a script that shows the behaviour? A simple one is better than a big one ;) ---- The code is *not* "comparing a pointer returned from malloc with an address from a variable in the current stack". What is compared is a pointer to a variable in the current stack (&localint) to an address determined to be "the stack limit" for the current interp (iPtr->stackBound). This limit is determined in Unix as an address in the stack plus/minus (the stack size minus a safety buffer): an address in the stack not in the heap. The stack size itself is determined by the pthread library, except for the initial stack where it is determined by rlimit. See TclpGetCStackParams() and GetStackSize() in tclUnixInit.c, TclpThreadGetStackSize in tclUnixThrd.c. The code does work with threads, assuming the pthread library is doing its thing. As far as we know, modulo [Bug 1850424] referred to by the previous comment. Address randomization might however be an issue? Please provide details. Note that the code will possibly fail if your (C, not script) code: - has the main Tcl interp in a thread which is not the initial thread - a thread's stack size is changed after the first call to a Tcl command in it. On this please see the comments in TclpThreadGetStackSize(). Note that neither tclsh nor the thread extension do any of this.
- login: "msofer"
- mimetype: "text/plain"
- subsystem changed to: "41. Memory Allocation"
- username: "msofer"
Ticket change [ec1c4bf7a1] (rid 103653) by msofer on 2008-01-07 17:27:34:
- icomment:
Logged In: YES user_id=148712 Originator: NO See also thread at https://www.redhat.com/archives/fedora-devel-list/2008-January/msg00538.html
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [a50a9f4ce3] (rid 110308) by msofer on 2008-01-07 17:52:09:
- icomment:
Logged In: YES user_id=148712 Originator: NO It would help a bit to know what precisely that 8Kingdoms thing is doing with Tcl. Sources at http://kralovstvi.cvs.sourceforge.net/kralovstvi/kralovstvi (are those the right ones??) (1) seem to include old versions of our headers: tcl.h, tclDecls.h, tclPlatDecls.h, tclIntDecls.h, tclInt.h, tclIntPlatDecls.h (http://kralovstvi.cvs.sourceforge.net/kralovstvi/kralovstvi/external/TCL/). If they expect to use those with current sources, all bets are off - internal headers changed a fair bit in the last 21 months. (2) the main code http://kralovstvi.cvs.sourceforge.net/kralovstvi/kralovstvi/8Kingdoms.cpp?revision=1.34&view=markup (or is it?) does not mention Tcl at all, and is commented in russian (?) which does not help me much anyway. (3) code.google.com does not help either
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [159037fa8f] (rid 124588) by mmaslano on 2008-01-07 22:27:35:
- icomment:
Logged In: YES user_id=1580598 Originator: YES I read the thread mentioned below and that's all I know. I don't care about this game, but there could be something wrong with stack checking. Yes, you found the correct sources and they are completely in Czech :) As I was looking at this, comments wasn't helping, they were saying obvious things. Maybe you are right and they are using incorrect *.h files or whatever.
- login: "mmaslano"
- mimetype: "text/plain"
- username: "mmaslano"
- icomment:
Ticket change [11d0d5d2c1] (rid 95207) by mmaslano on 2008-01-07 22:27:52:
- icomment:
Logged In: YES user_id=1580598 Originator: YES I read the thread mentioned below and that's all I know. I don't care about this game, but there could be something wrong with stack checking. Yes, you found the correct sources and they are completely in Czech :) As I was looking at this, comments wasn't helping, they were saying obvious things. Maybe you are right and they are using incorrect *.h files or whatever.
- login: "mmaslano"
- mimetype: "text/plain"
- username: "mmaslano"
- icomment:
Ticket change [b625d7bd13] (rid 125375) by mmaslano on 2008-01-07 22:28:01:
- icomment:
Logged In: YES user_id=1580598 Originator: YES I read the thread mentioned below and that's all I know. I don't care about this game, but there could be something wrong with stack checking. Yes, you found the correct sources and they are completely in Czech :) As I was looking at this, comments wasn't helping, they were saying obvious things. Maybe you are right and they are using incorrect *.h files or whatever.
- login: "mmaslano"
- mimetype: "text/plain"
- username: "mmaslano"
- icomment:
Ticket change [bc272d8714] (rid 129615) by msofer on 2008-01-08 06:41:42:
- closedate changed to: "2008-01-07T23:41:42"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 Originator: NO It turns out that 8Kingdoms is calling into the same Tcl interp from different threads. The stack check mechanism was just the first subsystem to notice. Their usage in violation of Tcl threading model may have been "lucky" in that the interaction to Tcl is quite simple, possibly implementable as 8K communication with tclsh via a pipe.
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- username: "msofer"
Ticket change [6af64d4d8b] (rid 128232) by jwrdegoede on 2008-01-08 16:18:22:
- icomment:
Logged In: YES user_id=922849 Originator: NO Hi all, msofer is correct, I'm the initiator of the wrong accusation that stack and heap addresses were being compared. My bad entirely, I misread the code. Now that msofer has educated me about the tcl thread model I will be writing a proper fix for 8Kingdoms this. I'll also make sure that stackchecking gets re-enabled in the Fedora packages I'm kinda a high profile contributer there so when I said it was broken I was believed (wrongly) and it was disabled, but as said I'll make _sure_ it gets turned back on. Apologies for yelling fire where there was none, and thanks to msofer for taking the time to help me debug the real cause.
- login: "jwrdegoede"
- mimetype: "text/plain"
- username: "jwrdegoede"
- icomment:
Ticket change [bb7cd3137d] (rid 129494) by dkf on 2008-01-08 17:57:25:
- icomment:
Logged In: YES user_id=79902 Originator: NO As a side note, the purpose of the stack checking code is to allow us to _gracefully_ recover from rogue scripts that allocate very deep stacks (e.g. because they recurse on themselves unexpectedly). We assume that there's also some OS protection in place, but want to live within our means instead. :-)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment: