From: "Luke Bishop" Newsgroups: comp.os.msdos.djgpp Subject: Re: Creating and using a protected stack area: how? Date: 13 Apr 1998 01:24:31 GMT Organization: The Zone Lines: 18 Message-ID: <01bd65b2$d1f01c40$3348a5c6@technoid> References: NNTP-Posting-Host: n072h051.thezone.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk > > then when I have to switch the stack I simply copy SS to %ss and ESP to > > %esp (with an assembly procedure). > > I don't think this approach will work. GCC assumes SS = DS, so code > generated by GCC will not work correctly if you switch SS under its > feet. > > But you can have separate stacks in the same segment (i.e., change ESP > but leave SS alone). To protect the stack you should just probably set the memory protection on the 5 K block after the stack end to no read or write and use that. It simplifies the stack problems. Changing the segments is simple enough, but you shouldn't expect the return address to be valid. In fact, you should push the value of a thread-end callback to the stack, as you really dont want the function to try returning to some random function or just to the function that spawned it.