Mail Archives: djgpp-workers/2001/08/09/05:00:28
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 -