Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mimsy!oddjob!gargoyle!ihnp4!inuxc!iuvax!bsu-cs!dhesi From: dhesi@bsu-cs.UUCP (Rahul Dhesi) Newsgroups: comp.sys.ibm.pc Subject: Re: signal() for Turbo C Message-ID: <1059@bsu-cs.UUCP> Date: Wed, 26-Aug-87 12:40:06 EDT Article-I.D.: bsu-cs.1059 Posted: Wed Aug 26 12:40:06 1987 Date-Received: Fri, 28-Aug-87 07:31:29 EDT References: <1009@bsu-cs.UUCP> <2670002@hpsrla.HP.COM> Reply-To: dhesi@bsu-cs.UUCP (Rahul Dhesi) Organization: CS Dept, Ball St U, Muncie, Indiana Lines: 58 Summary: Suggested bug fix to C0.ASM for better stack handling In article <2670002@hpsrla.HP.COM> darrylo@hpsrla.HP.COM (Darryl Okahata) writes about my signal() for Turbo C: > Thanks to Rahul Dhesi for writing this! However, there are little >"gotchas" that one has to be careful of: > > 1. Any routine called through the handler set up by the ctrlbreak() > call uses the stack given to it by DOS. The handler does not set > up a stack before calling the specified routine. It *appears* that > the stack used is the one that was being used when the DOS function > that was called was interrupted. When I tested the signal() handler code, I did run out of stack space. Then I initialized _stklen to a bigger value and the program ran correctly. So any shortage of stack space is occurring simply because the Turbo C stack is not big enough. The default stack, if you don't create _stklen, is only 128 bytes, which is peanuts. To set up the stack (this is not given in the Turbo C manual but was on a readme file on the disk) just declare a global variable thus: unsigned _stklen = 3000; /* set up 3000 byte stack */ Also note that I believe that the small model start-up code for Turbo C does not properly handle _stklen to set a bigger stack. I changed and recompiled the startup module for the small memory model to fix this apparent bug. I made the following changes in C0.ASM: 1. Search for the line _stklenOK label near and after it insert the statement: mov bx,di 2. The following statements occur in two places in C0.ASM: cmp bp,di ja ExcessOfMemory Comment these out the FIRST time they occur. For the small model startup code at least, the above changes seemed to solve two problems: (a) It seemed to me that _stklen wasn't working; (b) Even when I thought I had _stklen working, the startup code was allocating as much stack space as was available, even if you specified less. The above is only for the small model code, and only for version 1.0 of Turbo C (but note that all versions of Turbo C are called version 1.0, so the startup code for your version 1.0 could be different from mine). I have a lot of weasel words here because I didn't exhaustively test to see if what I thought happened really did happen. But I'm happy with the results of the changes I made, and signal() works perfectly now. -- Rahul Dhesi UUCP: {ihnp4,seismo}!{iuvax,pur-ee}!bsu-cs!dhesi