delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/12/10:56:02

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Fri, 12 Aug 2005 10:53:08 -0400
From: Christopher Faylor <cgf-no-personal-reply-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Cygwin.dll crash, alloca and custom stack
Message-ID: <20050812145308.GB10612@trixie.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
References: <602EF4562299D711978800065BEECE9A0D2D30CD AT cbrml50 DOT ag DOT gov DOT au>
Mime-Version: 1.0
In-Reply-To: <602EF4562299D711978800065BEECE9A0D2D30CD@cbrml50.ag.gov.au>
User-Agent: Mutt/1.5.8i

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019