X-Authentication-Warning: sirppi.helsinki.fi: peuha owned process doing -bs Date: Wed, 26 Jan 2000 09:00:24 +0200 (EET) From: Esa A E Peuha Sender: peuha AT cc DOT helsinki DOT fi To: djgpp-workers AT delorie DOT com Subject: Patch for crt0.S Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com Here's a patch to crt0.S. This prevents the program from crashing in the rare case when the very first call to ___sbrk fails. *** src/libc/crt0/crt0.S Wed Aug 11 02:24:38 1999 --- src/libc/crt0/crt0~.S Sun Jan 23 21:19:34 2000 *************** *** 42,47 **** --- 42,51 ---- .long 0 sbrk16_api_seg: .word 0 + stubinfo_ds_selector: + .word 0 + stubinfo_cs_selector: + .word 0 zero: .long 0 *************** *** 99,104 **** --- 103,116 ---- stosl #endif + /* These are for the exit code, to allow it to be called before stubinfo is moved */ + .byte 0x64 /* fs: */ + pushw STUBINFO_DS_SELECTOR + popw stubinfo_ds_selector + .byte 0x64 /* fs: */ + pushw STUBINFO_CS_SELECTOR + popw stubinfo_cs_selector + /* Enable NULL pointer protection if DPMI supports it */ testb $0x1, __crt0_startup_flags+1 /* include/crt0.h */ jnz 1f *************** *** 238,243 **** --- 250,257 ---- movl STUBINFO_SIZE, %eax pushl %eax call ___sbrk + cmpl $-1, %eax + je no_memory movl %eax, __stubinfo movl %eax, %edi .byte 0x64 /* fs: */ *************** *** 329,341 **** movw $0x101, %ax int $0x31 /* Free block and selector */ 9: ! movl __stubinfo, %edx ! movl STUBINFO_CS_SELECTOR(%edx), %eax movw %ax, sbrk16_api_seg xorl %edi, %edi movl %edi, sbrk16_api_ofs /* Offset is zero */ ! movw STUBINFO_DS_SELECTOR(%edx), %es movb %cl, %dl /* Exit status */ movl $exit16_first_byte, %esi movl $(exit16_last_byte - exit16_first_byte), %ecx --- 343,354 ---- movw $0x101, %ax int $0x31 /* Free block and selector */ 9: ! movw stubinfo_cs_selector, %ax movw %ax, sbrk16_api_seg xorl %edi, %edi movl %edi, sbrk16_api_ofs /* Offset is zero */ ! movw stubinfo_ds_selector, %es movb %cl, %dl /* Exit status */ movl $exit16_first_byte, %esi movl $(exit16_last_byte - exit16_first_byte), %ecx -- Esa Peuha student of mathematics at the University of Helsinki http://www.helsinki.fi/~peuha/