Exemple #1
0
        /// <summary>
        /// Set memory protections, pre or post seal
        /// </summary>
        private void Protect()
        {
            var writeStart = _everythingSealed ? _postSealWriteStart : _writeStart;

            Memory.Protect(Memory.Start, _execEnd - Memory.Start, MemoryBlock.Protection.RX);
            Memory.Protect(_execEnd, writeStart - _execEnd, MemoryBlock.Protection.R);
            Memory.Protect(writeStart, Memory.EndExclusive - writeStart, MemoryBlock.Protection.RW);
            if (_invisible != null)
            {
                if (!WaterboxUtils.Aligned(_invisible.LoadAddress))
                {
                    throw new InvalidOperationException("Invisible section start not aligned!  Check linker script");
                }
                var end = WaterboxUtils.AlignUp(_invisible.LoadAddress + _invisible.Size);
                if (_sectionsByName.Values.Any(s => s != _invisible && s.LoadAddress < end && s.LoadAddress >= _invisible.LoadAddress))
                {
                    throw new InvalidOperationException("Invisible section end not aligned, or not padded!  Check linker script");
                }
                Memory.Protect(
                    _invisible.LoadAddress,
                    _invisible.Size,
                    MemoryBlock.Protection.RW_Invisible);
            }
        }