Beispiel #1
0
        public override Stream RequestCodeStream()
        {
            LinkerStream        stream = base.RequestCodeStream() as LinkerStream;
            VirtualMemoryStream vms    = (VirtualMemoryStream)stream.BaseStream;

            if (address == IntPtr.Zero)
            {
                address = new IntPtr(vms.Base.ToInt64() + vms.Position);
            }

            return(stream);
        }
		/// <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 (stream == null)
			{
				// Request 4Mb of memory
				VirtualMemoryStream vms = new VirtualMemoryStream(global::Mosa.Internal.Runtime.MemoryPageManager, 1024 * 1024 * 4);

				// 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;
		}
        /// <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(global::Mosa.Vm.Runtime.MemoryPageManager, 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;
        }
Beispiel #4
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 = GetSymbol(name);
                symbol.VirtualAddress = new IntPtr(vms.Base.ToInt64() + vms.Position);
                Trace.WriteLine("Symbol " + name + " located at 0x" + symbol.VirtualAddress.ToInt32().ToString("x08"));
            }
            catch
            {
                stream.Dispose();
                throw;
            }

            return(stream);
        }