internal bool IsSubtype(UIntPtr candidateHandle)
        {
            if (candidateHandle == UIntPtr.Zero)
            {
                DebugLine("RST.IsSubType {0:x8} of {1:x8} => false",
                          __arglist(candidateHandle, handle));
                return(false);
            }

            RuntimeSystemType candidate = HandleTable.GetHandle(candidateHandle) as RuntimeSystemType;

            if (candidate == null)
            {
                DebugLine("RST.IsSubType {0:x8} of {1:x8} => false",
                          __arglist(candidateHandle, handle));
                return(false);
            }

            RuntimeSystemType current = this;

            while (current != null)
            {
                if (current == candidate)
                {
                    DebugLine("RST.IsSubType {0:x8} of {1:x8} => true",
                              __arglist(candidateHandle, handle));
                    return(true);
                }
                current = current.parent;
            }
            DebugLine("RST.IsSubType {0:x8} of {1:x8} => false",
                      __arglist(candidateHandle, handle));
            return(false);
        }
        private static UIntPtr For(RuntimeSystemType parent, MD5TypeEntry hash)
        {
            RuntimeSystemType rts = new RuntimeSystemType(parent, hash);

            // IMPORTANT we need to allocate these handles to the kernel, since
            // they are stored in shared heap object headers that move from process
            // to process.
            rts.handle = Process.kernelProcess.AllocateHandle(rts);

            // TODO: Figure out how to collect them
            //
            return(rts.handle);
        }
        internal UIntPtr LookupChildHandle(string name, long lowerHash, long upperHash)
        {
            MD5TypeEntry childhash = new MD5TypeEntry(name, lowerHash, upperHash);

            object childBox = this.ChildHandles[childhash];

            if (childBox == null)
            {
                lock (this.ChildHandles) {
                    childBox = this.ChildHandles[childhash];
                    if (childBox == null)
                    {
                        UIntPtr child = RuntimeSystemType.For(this, childhash);
                        this.ChildHandles.Add(childhash, child);
                        DebugLine("RST.LookupChild({0}.{1:x16}{2:x16}) => Create {3:x8}",
                                  __arglist(name, lowerHash, upperHash, child));
                        return(child);
                    }
                }
            }
            DebugLine("RST.LookupChild({0}.{1:x16}{2:x16}) => Find {3:x8}",
                      __arglist(name, lowerHash, upperHash, (UIntPtr)childBox));
            return((UIntPtr)childBox);
        }
 private RuntimeSystemType(RuntimeSystemType parent, MD5TypeEntry hash)
 {
     this.hash   = hash;
     this.parent = parent;
 }
 static RuntimeSystemType()
 {
     RootHandle = RuntimeSystemType.For(null, new MD5TypeEntry("System.Object"));
 }