www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/08/09/05:00:28

From: pavenis AT lanet DOT lv
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, djgpp-workers AT delorie DOT com
Date: Thu, 9 Aug 2001 12:00:15 +0300
MIME-Version: 1.0
Subject: Re: Selector Exhaustion
Message-ID: <3B727B4F.7623.1B9185@localhost>
References: <10108090440 DOT AA13158 AT clio DOT rice DOT edu>
In-reply-to: <Pine.SUN.3.91.1010809091937.7420J-100000@is>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

On 9 Aug 2001, at 9:23, Eli Zaretskii wrote:

> 
> On Wed, 8 Aug 2001, Charles Sandmann wrote:
> 
> > Using a modified version of our "spawn" test routine, I tried the following:
> > 1) Allocate a selector before spawning.
> > 2) Spawn
> > 3) Allocate another selector.
> > 4) Free all selectors between the two selector values (inclusive).
> > 
> > Guess what?  I can clean up the selectors, no problem.  I can loop
> > forever.  Where I would puke after 600 loops before, the current
> > version will loop forever (well, at least as long as I've run it...)
> > 
> > This does have a few flaws - is assumes there won't be any selector
> > holes.
> 
> It also assumes all the selectors in between belong to the child program, 
> and thus are not used anymore.  Isn't that a dangerous assumption?

Perhaps one should look for size of hole using 
__dpmi_get_descriptor_access_rights(). 

See my test example at the end of message. 

Verified that it works in DOS session under Win98SE (no more 
descriptor leaks)

> > But this seems like an effective
> > way (at least on W2K) to get rid of the selector leakage.  Worth
> > investigation to put in libc?
> 
> I'd say post the patch and lets ask people to patch their libraries, 
> rebuild as many applications which spawn other programs, such as Make, 
> GCC, Emacs, and Bash, and lets test how well does it work for some
> time.
 
Andris

#include <go32.h>
#include <dpmi.h>
#include <stdio.h>
#include <process.h>
#include <sys/segments.h>
#include <sys/farptr.h>
#include <string.h>
#include <stubinfo.h>

int main(int argc, char *argv[])
{
  int i;
  if (argc > 1)
  {
    printf("%7s : my_cs:%04X my_ds:%04X dos_ds:%04X "
           "s_ds:%04X s_psp:%04X s_cs:%04X "
           "env_sel:%04X\n", 
           argv[1], _my_cs(),_my_ds(),_dos_ds,
           _stubinfo->ds_selector, _stubinfo->psp_selector,
           _stubinfo->cs_selector, _farpeekw(_stubinfo->psp_selector,0x2C)
          );
    return 0;
  }
  else
  {
      printf("Start:   my_cs: %04X    my_ds: %04X   dos_ds: %04X\n", 
                                    _my_cs(),_my_ds(),_dos_ds);
  }
  for (i=0;i<10000;i++)
  {
        int r, sel1, sel2, selh1;
        char cnt[20];
        sprintf (cnt,"%7d",i+1);
        sel1 = __dpmi_allocate_ldt_descriptors (1);
        for (selh1=sel1+8; selh1<0x00010000; selh1+=8)
        {
          r =__dpmi_get_descriptor_access_rights(selh1);
          if (!(r & 0x0080)) continue;
        }
        spawnl(P_WAIT, argv[0], argv[0], cnt, NULL);
        sel2 = __dpmi_allocate_ldt_descriptors (1);
        //printf ("%04X %04X %08X\n",sel1,sel2,selh1);
        if (sel2>sel1 && sel2<=selh1)
        {
          int sel;
          for (sel=sel1; sel<=sel2; sel++)
            __dpmi_free_ldt_descriptor (sel);
        }
        else
        {
          __dpmi_free_ldt_descriptor (sel1);
          __dpmi_free_ldt_descriptor (sel2);
        }
  }
  return 0;
}




- Raw text -


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