Date: Sat, 02 Jun 2001 12:57:13 +0300 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: djgpp-workers AT delorie DOT com Message-Id: <3405-Sat02Jun2001125713+0300-eliz@is.elta.co.il> X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9 CC: sandmann AT clio DOT rice DOT edu (Charles Sandmann) In-reply-to: <20010523195757.15393.qmail@tyr.diku.dk> (message from Morten Welinder on 23 May 2001 19:57:57 -0000) Subject: Re: Crashes due to selector depletion References: <4331-Wed23May2001214623+0300-eliz AT is DOT elta DOT co DOT il> <20010523195757 DOT 15393 DOT qmail AT tyr DOT diku DOT dk> Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Date: 23 May 2001 19:57:57 -0000 > From: Morten Welinder > > Can't you just use the character-at-a-time int 0x21 service > to print your message? Not terrible efficient, but you are > not looking for that here. Does the following look right? If no one objects, I will commit this. --- src/libc/crt0/crt1.c~0 Thu Jun 3 13:27:36 1999 +++ src/libc/crt0/crt1.c Sat Jun 2 12:29:32 2001 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include /* for _osmajor/_osminor */ @@ -45,8 +46,33 @@ setup_core_selector(void) int c = __dpmi_allocate_ldt_descriptors(1); if (c == -1) { - _dos_ds = 0; - return; + /* We cannot continue without a valid _dos_ds selector, since + setup_screens, called next, already uses it, and will crash + unless we do something. + + The failure to allocate a descriptor is known to happen on + Windows, when a long nested job (e.g., large recursive + Makefile) is in progress, due to the fact that the Windows DPMI + host leaks descriptors. + + So we want to print an error message and exit; but the tricky + part is that we cannot use the transfer buffer or any other + buffer in conventional memory, because we don't have a selector + for DOS memory. That's why we use function 02 of Int 21h. + (The idea is due to Morten Welinder.) */ + static const char no_dos_ds_msg[] = + "Cannot allocate selector for conventional memory; exiting\r\n"; + const char *p = no_dos_ds_msg; + __dpmi_regs r; + + r.h.ah = 2; + while (*p) + { + r.h.dl = *p & 0xff; + __dpmi_int(0x21, &r); + p++; + } + __exit(107); /* the same error code stub.asm uses for no selectors */ } _dos_ds = c;