[ros-kernel] "My Computer" crash

Ge van Geldorp ge at gse.nl
Tue Feb 17 22:39:37 CET 2004


When double-clicking on "My Computer" in VMware, Explorer would often
crash, shutting down the system. I finally tracked it down to
HeapAlloc() not always returning 8-byte aligned blocks (sometimes it
would return blocks at xxxxxxx4 or xxxxxxxC). This causes
Local/GlobalAlloc to misbehave. Someone before me already tried to fix
it:

  phandle = RtlAllocateHeap(GetProcessHeap(), 0,
sizeof(GLOBAL_HANDLE));
  /* This little hack is to make sure that we get a pointer with 8-byte
  ** alignment.
  ** Fixme: When we are sure all allocations are 8-byte aligned,
  ** we can remove this hack.
  */
  if (ISPOINTER(INTERN_TO_HANDLE(phandle)))
  {
      hack_fix = RtlAllocateHeap(GetProcessHeap(), 0,
sizeof(GLOBAL_HANDLE));
      RtlFreeHeap(GetProcessHeap(), 0, phandle);
      phandle = hack_fix;
  }

Unfortunately, the 2nd call to RtlAllocateHeap() was not guaranteed to
return an 8-byte aligned block either. The end result was that
GlobalAlloc returned what looked like a pointer while in reality it was
a handle. Via a series of 4 memory overwrites this finally caused the
crash. A small debugging nightmare I might add.

Normally, I wouldn't bother y'all with this. However, I fixed it by
adjusting some structures in reactos/lib/ntdll/rtl/heap.c and making a
change to one of these low-level memory allocation routines while we're
in a freeze period makes me feel slightly uneasy. OTOH, the problem in
my opinion was seriously enough to need a fix ASAP.

Gé van Geldorp.




More information about the Ros-kernel mailing list