/// <summary> /// Returns the paging granularity of the pointer <paramref name="page" />. /// </summary> /// <returns> /// The granularity level or -1 if the pointer is not page-aligned. /// </returns> public static uint GetPointerGranularity(void *page) { ulong pagei = (ulong)page; uint levels = GetBigGranularity() + 1; for (uint x = 0; x < levels; ++x) { PageAllocator.Errors err = PageAllocator.Errors.Success; uint size = GetGranularitySize(x, &err); if (err != PageAllocator.Errors.Success) { TextMode.Write("Error: "); TextMode.Write((int)err); Diagnostics.Assert(false, "Failed to get pager granularity!"); } if ((pagei & (ulong)(size - 1)) == 0) { return(x); } } return(0xFFFFFFFF); }
/// <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)))); }