Ejemplo n.º 1
0
        public override Stream RequestCodeStream()
        {
            LinkerStream        stream = base.RequestCodeStream() as LinkerStream;
            VirtualMemoryStream vms    = (VirtualMemoryStream)stream.BaseStream;

            if (this.Method.Address == IntPtr.Zero)
            {
                this.Method.Address = new IntPtr(vms.Base.ToInt64() + vms.Position);
            }
            return(stream);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allocates a symbol of the given name in the specified section.
        /// </summary>
        /// <param name="name">The name of the symbol.</param>
        /// <param name="section">The executable section to allocate from.</param>
        /// <param name="size">The number of bytes to allocate. If zero, indicates an unknown amount of memory is required.</param>
        /// <param name="alignment">The alignment. A value of zero indicates the use of a default alignment for the section.</param>
        /// <returns>
        /// A stream, which can be used to populate the section.
        /// </returns>
        public override Stream Allocate(string name, SectionKind section, int size, int alignment)
        {
            LinkerStream stream = (LinkerStream)base.Allocate(name, section, size, alignment);

            try
            {
                VirtualMemoryStream vms    = (VirtualMemoryStream)stream.BaseStream;
                LinkerSymbol        symbol = this.GetSymbol(name);
                symbol.VirtualAddress = new IntPtr(vms.Base.ToInt64() + vms.Position);
            }
            catch
            {
                stream.Dispose();
                throw;
            }

            return(stream);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Allocates a stream of the specified size from the section.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <param name="alignment">The alignment.</param>
        /// <returns></returns>
        public Stream Allocate(int size, int alignment)
        {
            Stream stream = this.stream;
            if (null == stream)
            {
                // Request 64K of memory
                VirtualMemoryStream vms = new VirtualMemoryStream(RuntimeBase.Instance.MemoryManager, 16 * 4096);

                // Save the stream for further references
                this.stream = stream = vms;
                base.VirtualAddress = vms.Base;
            }

            if (size != 0 && size > (stream.Length - stream.Position))
                throw new OutOfMemoryException(@"Not enough space in section to allocate symbol.");

            return stream;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Allocates a stream of the specified size from the section.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <param name="alignment">The alignment.</param>
        /// <returns></returns>
        public Stream Allocate(int size, int alignment)
        {
            Stream stream = this.stream;

            if (null == stream)
            {
                // Request 64K of memory
                VirtualMemoryStream vms = new VirtualMemoryStream(RuntimeBase.Instance.MemoryManager, 16 * 4096);

                // Save the stream for further references
                this.stream         = stream = vms;
                base.VirtualAddress = vms.Base;
            }

            if (size != 0 && size > (stream.Length - stream.Position))
            {
                throw new OutOfMemoryException(@"Not enough space in section to allocate symbol.");
            }

            return(stream);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Allocates memory in the specified section.
        /// </summary>
        /// <param name="member">The metadata member to allocate space for.</param>
        /// <param name="section">The executable section to allocate from.</param>
        /// <param name="size">The number of bytes to allocate. If zero, indicates an unknown amount of memory is required.</param>
        /// <param name="alignment">The alignment. A value of zero indicates the use of a default alignment for the section.</param>
        /// <returns>
        /// A stream, which can be used to populate the section.
        /// </returns>
        public override Stream Allocate(RuntimeMember member, SectionKind section, int size, int alignment)
        {
            string name = CreateSymbolName(member);

            LinkerStream stream = (LinkerStream)base.Allocate(name, section, size, alignment);

            try
            {
                VirtualMemoryStream vms = (VirtualMemoryStream)stream.BaseStream;

                // Save the member address
                member.Address = new IntPtr(vms.Base.ToInt64() + vms.Position);

                LinkerSymbol symbol = this.GetSymbol(name);
                symbol.VirtualAddress = member.Address;
            }
            catch
            {
                stream.Dispose();
                throw;
            }

            return(stream);
        }