예제 #1
0
파일: Pager.cs 프로젝트: willvin313/SharpOS
        /// <summary>
        /// Aligns the pointer <paramref name="ptr" /> to the page granularity
        /// specified by <paramref name="granularity" />. This method asserts
        /// that the granularity is within the allowed range for the ADC layer
        /// in use.
        /// <returns>
        /// A pointer which is aligned to the page boundaries of the given
        /// granularity.
        /// </returns>
        /// </summary>
        public static void *PageAlign(void *ptr, uint granularity)
        {
            Diagnostics.Assert(granularity >= 0 && granularity <= GetBigGranularity(),
                               "Specified invalid granularity level");

            PageAllocator.Errors err = PageAllocator.Errors.Success;
            uint  size = GetGranularitySize(granularity, &err);
            ulong ptri = (ulong)ptr;

            Diagnostics.AssertZero((uint)err, "Failed to get granularity size");

            return((void *)(ptri - (ptri & (size - 1))));
        }