On Fri, Aug 12, 2005 at 05:07:19PM +1000, Bitmead, Chris wrote: >I'm writing an implemention of a scheme interpreter in C, and as people >familiar with that language know, it requires some stack manipulation. Now >to test this out I wrote a little program.... > > >#include <stdio.h> > >int main() { > char * st1; > st1 = (void *)malloc(5000) + 5000; > asm("mov %0, %%esp" : : "r" (st1)); > fprintf(stderr, "hello\n"); >} > >This program crashes silently and prints nothing under cygwin. However >this kind of thing works fine under Linux.
I doubt that the above would work very reliably on linux. Windows believes that it has control of the stack and I wouldn't be surprised to see that linux does too. I would expect that a multi-threaded linux app would not like the above. Since every cygwin app is multi-threaded by default you will run into problems pretty quickly. Windows stores information about the stack in offsets from the %fs register. See the description of this area in the file "winnt.h" in the structure NT_TIB. Cygwin manipulates this area after a fork (if necessary) in the file dcrt0.cc, function alloc_stack. Cygwin also uses the bottom of the stack for thread local storage. See the file how-cygtls-works.txt in the winsup/cygwin source directory for more details. So, anyway, you really have your work cut out for you if you want to create your own stack under cygwin. Doing this will require you to be very familiar with the way both Windows and cygwin handle the stack. Accommodating the above usage of just loading sp with a new pointer and having it "just work" is not a goal for cygwin. I really don't think it's even possible to make that work on Windows, let alone Cygwin. cgf -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/