I've been poking in the stack limit problem that Johnny reported.

Test program attached, it can be used with e.g.
  i386-mingw32ce-gcc -DSTACK_SIZE=6000 -o stack6000.exe stack.c
  i386-mingw32ce-gcc -DSTACK_SIZE=66000 -o stack66000.exe stack.c

The stack6000 execution succeeds and leaves the expected contents in
out.txt :
  In main
  Size : 6000
  After memset
The stack66000 execution creates a dialog on the screen saying
        Application Error
        Application stack66000.EXE encountered a serious error and must shut
down
It also adds one line to out.txt :
  In main

I've built a linux gcc 4.4.0, as expected the same application has no
problems on linux.

A difference between the assembly code generated for the two platforms
(see attached source files) is that the CE version calls a function
__chkstk to probe the stack (see gcc/config/i386/cygwin.asm), the linux
version does not.

large:                          (Linux)
        pushl   %ebp
        movl    %esp, %ebp
        subl    $66024, %esp
        movl    $.LC0, %eax
        movl    $66000, 8(%esp)
        movl    %eax, 4(%esp)
        movl    $outbuf, (%esp)
        call    sprintf
        movl    $outbuf, (%esp)
        call    Print


_large:                         (CE)
        pushl   %ebp
        movl    %esp, %ebp
        movl    $66024, %eax
        call    ___chkstk
        movl    $66000, 8(%esp)
        movl    $LC0, 4(%esp)
        movl    $_outbuf, (%esp)
        call    _sprintf
        movl    $_outbuf, (%esp)
        call    _Print

I've tried porting the piece of Linux assembler in the CE code. This
requires adding an underscore at some lines, removing dots at others.
The end result is the same though : crash.

Help ! :-(

        Danny
-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#include <windows.h>
#endif

void Print(char *s);
char	outbuf[32];

void large(void)
{
	char	buf[STACK_SIZE];

	sprintf(outbuf, "Size : %d\n", sizeof(buf));
	Print(outbuf);
	memset(&buf, 0, STACK_SIZE);
	Print("After memset\n");
}

int main(int argc, char *argv[])
{
	Print("In main\n");
	large();
	return 0;
}

void Print(char *s)
{
#ifdef WIN32
	HANDLE	h;
	DWORD	r;

	h = CreateFile(L"/temp/out.txt", GENERIC_WRITE, 0, NULL,
			OPEN_ALWAYS,
			FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL);
	SetFilePointer(h, 0L, NULL, FILE_END);
	WriteFile(h, s, strlen(s), &r, NULL);
	CloseHandle(h);
#else
#endif
}
        .file   "stack.c"
        .comm   _outbuf, 32      # 32
        .section .rdata,"dr"
LC0:
        .ascii "Size : %d\12\0"
LC1:
        .ascii "After memset\12\0"
        .text
.globl _large
_large:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $66024, %eax
        call    ___chkstk
        movl    $66000, 8(%esp)
        movl    $LC0, 4(%esp)
        movl    $_outbuf, (%esp)
        call    _sprintf
        movl    $_outbuf, (%esp)
        call    _Print
        movl    $66000, 8(%esp)
        movl    $0, 4(%esp)
        leal    -66008(%ebp), %eax
        movl    %eax, (%esp)
        call    _memset
        movl    $LC1, (%esp)
        call    _Print
        leave
        ret
        .def    ___main;        .scl    2;      .type   32;     .endef
        .section .rdata,"dr"
LC2:
        .ascii "In main\12\0"
        .text
.globl _main
_main:
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-16, %esp
        movl    $16, %eax
        call    ___chkstk
        call    ___main
        movl    $LC2, (%esp)
        call    _Print
        call    _large
        movl    $0, %eax
        leave
        ret
        .section .rdata,"dr"
        .align 2
LC3:
        .ascii "/\0t\0e\0m\0p\0/\0o\0u\0t\0.\0t\0x\0t\0\0\0"
        .text
.globl _Print
_Print:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $56, %eax
        call    ___chkstk
        movl    $0, 24(%esp)
        movl    $-2147483520, 20(%esp)
        movl    $4, 16(%esp)
        movl    $0, 12(%esp)
        movl    $0, 8(%esp)
        movl    $1073741824, 4(%esp)
        movl    $LC3, (%esp)
        call    _CreateFileW
        movl    %eax, -12(%ebp)
        movl    $2, 12(%esp)
        movl    $0, 8(%esp)
        movl    $0, 4(%esp)
        movl    -12(%ebp), %eax
        movl    %eax, (%esp)
        call    _SetFilePointer
        movl    8(%ebp), %eax
        movl    %eax, (%esp)
        call    _strlen
        movl    $0, 16(%esp)
        leal    -16(%ebp), %edx
        movl    %edx, 12(%esp)
        movl    %eax, 8(%esp)
        movl    8(%ebp), %eax
        movl    %eax, 4(%esp)
        movl    -12(%ebp), %eax
        movl    %eax, (%esp)
        call    _WriteFile
        movl    -12(%ebp), %eax
        movl    %eax, (%esp)
        call    _CloseHandle
        leave
        ret
        .def    _sprintf;       .scl    2;      .type   32;     .endef
        .def    _memset;        .scl    2;      .type   32;     .endef
        .def    _CreateFileW;   .scl    2;      .type   32;     .endef
        .def    _SetFilePointer;        .scl    2;      .type   32;     .endef
        .def    _strlen;        .scl    2;      .type   32;     .endef
        .def    _WriteFile;     .scl    2;      .type   32;     .endef
        .def    _CloseHandle;   .scl    2;      .type   32;     .endef
        .file   "stack.c"
        .comm   outbuf,32,32
        .section        .rodata
.LC0:
        .string "Size : %d\n"
.LC1:
        .string "After memset\n"
        .text
.globl large
        .type   large, @function
large:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $66024, %esp
        movl    $.LC0, %eax
        movl    $66000, 8(%esp)
        movl    %eax, 4(%esp)
        movl    $outbuf, (%esp)
        call    sprintf
        movl    $outbuf, (%esp)
        call    Print
        movl    $66000, 8(%esp)
        movl    $0, 4(%esp)
        leal    -66008(%ebp), %eax
        movl    %eax, (%esp)
        call    memset
        movl    $.LC1, (%esp)
        call    Print
        leave
        ret
        .size   large, .-large
        .section        .rodata
.LC2:
        .string "In main\n"
        .text
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-16, %esp
        subl    $16, %esp
        movl    $.LC2, (%esp)
        call    Print
        call    large
        movl    $0, %eax
        leave
        ret
        .size   main, .-main
.globl Print
        .type   Print, @function
Print:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   Print, .-Print
        .ident  "GCC: (GNU) 4.4.0"
        .section        .note.GNU-stack,"",@progbits
all::	stack6000.od stack66000.od \
	stack6000.lod stack66000.lod \
	stack6000.lod4 stack66000.lod4

stack6000.od:	stack6000.exe
	i386-mingw32ce-objdump -xD $< > $@

stack66000.od:	stack66000.exe
	i386-mingw32ce-objdump -xD $< > $@

stack6000.exe: stack.c
	i386-mingw32ce-gcc -g -o $@ stack.c -DSTACK_SIZE=6000
	i386-mingw32ce-gcc -S -o stack6000.ce.s stack.c -DSTACK_SIZE=6000

stack66000.exe: stack.c
	i386-mingw32ce-gcc -g -o $@ stack.c -DSTACK_SIZE=66000
	i386-mingw32ce-gcc -S -o stack66000.ce.s stack.c -DSTACK_SIZE=66000

clean:
	-rm -f *.o *.exe *.od *~
	-rm -f *.lod stack6000 stack66000
	-rm -f *.lod4 stack6000.gcc4 stack66000.gcc4
	-rm -f *.s

stack6000: stack.c
	gcc -o $@ stack.c -DSTACK_SIZE=6000

stack66000: stack.c
	gcc -o $@ stack.c -DSTACK_SIZE=66000

stack6000.lod:	stack6000
	objdump -xD $< > $@

stack66000.lod:	stack66000
	objdump -xD $< > $@

stack6000.gcc4: stack.c
	/opt/gcc440/bin/gcc -o $@ stack.c -DSTACK_SIZE=6000
	/opt/gcc440/bin/gcc -S -o stack6000.l.s stack.c -DSTACK_SIZE=6000

stack66000.gcc4: stack.c
	/opt/gcc440/bin/gcc -o $@ stack.c -DSTACK_SIZE=66000
	/opt/gcc440/bin/gcc -S -o stack66000.l.s stack.c -DSTACK_SIZE=66000

stack6000.lod4:	stack6000.gcc4
	objdump -xD $< > $@

stack66000.lod4:	stack66000.gcc4
	objdump -xD $< > $@

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to