Exemple #1
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 virtual Stream Allocate(string name, SectionKind section, int size, int alignment)
        {
            Stream stream = Allocate(section, size, alignment);

            try
            {
                // Create a linker symbol for the name
                LinkerSymbol symbol = new LinkerSymbol(name, section, stream.Position);

                // Save the symbol for later use
                _symbols.Add(symbol.Name, symbol);

                // Wrap the stream to catch premature disposal
                stream = new LinkerStream(symbol, stream, size);
            } catch (ArgumentException argx)
            {
                throw new LinkerException(String.Format("Symbol {0} defined multiple times.", name), argx);
            }

            return(stream);
        }
        /// <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 virtual Stream Allocate(string name, SectionKind section, int size, int alignment)
        {
            Stream result;
            Stream baseStream = Allocate(section, size, alignment);

            try
            {
                // Create a linker symbol for the name
                LinkerSymbol symbol = new LinkerSymbol(name, section, baseStream.Position);

                // Save the symbol for later use
                _symbols.Add(symbol.Name, symbol);

                // Wrap the stream to catch premature disposal
                result = new LinkerStream(symbol, baseStream, size);
            }
            catch (ArgumentException argx)
            {
                throw new LinkerException(String.Format(@"Symbol {0} defined multiple times.", name), argx);
            }

            return result;
        }