Beispiel #1
0
        private static unsafe void InitializeStringTable()
        {
            int    length       = 0;
            IntPtr strEETypePtr = GetModuleSection((int)ModuleSectionIds.StringEETypePtr, out length);

            Contract.Assert(length == IntPtr.Size);

            IntPtr strTableStart = GetModuleSection((int)ModuleSectionIds.StringFixupStart, out length);

            Contract.Assert(length % IntPtr.Size == 0);

            IntPtr strTableEnd = (IntPtr)((byte *)strTableStart + length);

            for (IntPtr *tab = (IntPtr *)strTableStart; tab < (IntPtr *)strTableEnd; tab++)
            {
                byte *bytes = (byte *)*tab;
                int   len   = (int)NativePrimitiveDecoder.DecodeUnsigned(ref bytes);
                int   count = LowLevelUTF8Encoding.GetCharCount(bytes, len);
                Contract.Assert(count >= 0);

                string newStr = RuntimeImports.RhNewArrayAsString(new EETypePtr(strEETypePtr), count);
                fixed(char *dest = newStr)
                {
                    int newCount = LowLevelUTF8Encoding.GetChars(bytes, len, dest, count);

                    Contract.Assert(newCount == count);
                }

                GCHandle handle = GCHandle.Alloc(newStr);
                *        tab    = (IntPtr)handle;
            }
        }
Beispiel #2
0
        private static unsafe void InitializeStringTable(IntPtr stringTableStart, int length)
        {
            IntPtr stringTableEnd = (IntPtr)((byte *)stringTableStart + length);

            for (IntPtr *tab = (IntPtr *)stringTableStart; tab < (IntPtr *)stringTableEnd; tab++)
            {
                byte *bytes = (byte *)*tab;
                int   len   = (int)NativePrimitiveDecoder.DecodeUnsigned(ref bytes);
                int   count = LowLevelUTF8Encoding.GetCharCount(bytes, len);
                Contract.Assert(count >= 0);

                string newStr = RuntimeImports.RhNewArrayAsString(EETypePtr.EETypePtrOf <string>(), count);
                fixed(char *dest = newStr)
                {
                    int newCount = LowLevelUTF8Encoding.GetChars(bytes, len, dest, count);

                    Contract.Assert(newCount == count);
                }

                GCHandle handle = GCHandle.Alloc(newStr);
                *        tab    = (IntPtr)handle;
            }
        }