www.digitalmars.com         C & C++   DMDScript  

c++.dos.32-bits - Legal read/write pointer

I'm trying to come up with a function for X32VM that tests if a pointer is
legal.
I.e. within legal bounds for read and write. I'm a bit confused about the
x386_stacklow variable. Shouldn't that specify the low-watermark of ESP?

Anyway, here is the function.

----------- cut ---------------------------------------------------------------------------------------------
int valid_addr (unsigned long addr, int len)
{
  if (addr < 0x1000 || (addr >= 0xFFFFFFFFL - len))
     return (FALSE);

  if (addr > _x386_stacklow)  /* addr points to stack */
     return (TRUE);

  if (addr < _x386_stacklow && addr + len > get_ds_limit())  /* addr in DATA */
     return (FALSE);

  return (TRUE);
}

unsigned long get_ds_limit (void)
{
  unsigned long res;
  __asm { mov ax, ds
          and eax, 0FFFFh
          lsl eax, eax
          mov res, eax
        }
  return (res);
}
---------- cut ---------------------------------------------------------------------------------------------

What's the highest legal ESP? I tried with getting limit of SS, but that gave
me funny result. Can anyone improve this function?

Gisle V.
Jul 19 2002