Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Oct 23, 2021
1 parent a9e846e commit d9d1e27
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Dotx64Managed/API/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static partial class Memory
[Flags]
public enum Protection
{
Invalid = 0,
NoAccess = 0x01,
ReadOnly = 0x02,
ReadWrite = 0x04,
Expand Down Expand Up @@ -91,6 +92,14 @@ public static nuint GetBase(ulong address)
return GetBase((nuint)address);
}

/// <summary>
/// Gets the protection of the memory, if the cache is used this is the last queried page info.
/// It is normally safe to use the cache for performance, when the cache is used the internal
/// API will not use a syscall to determine the protection.
/// </summary>
/// <param name="address">Address of the page to query</param>
/// <param name="useCache">If this is true it will use the last queried page information</param>
/// <returns>In case of failure the result is Protection.Invalid otherwise actual protection</returns>
public static Protection GetProtection(nuint address, bool useCache)
{
return (Protection)Native.Memory.GetProtection(address, useCache);
Expand All @@ -100,6 +109,18 @@ public static Protection GetProtection(ulong address, bool useCache)
return GetProtection((nuint)address, useCache);
}

/// <summary>
/// Sets a new protection on the specified address, the address will be aligned to page
/// boundaries and sets the entire page which is by 4 KiB. This may split up
/// an existing range from the memory map.
/// Internally the size will be always aligned to a minimum of a single page, if the size
/// spans more than two pages then both pages will be modified.
/// <note>This will also update the cached protection info</note>
/// </summary>
/// <param name="address">Address of the page</param>
/// <param name="protect">New protection</param>
/// <param name="size">The size of the range</param>
/// <returns>True on success</returns>
public static bool SetProtection(nuint address, Protection protect, int size)
{
return Native.Memory.SetProtection(address, (UInt32)protect, size);
Expand Down

0 comments on commit d9d1e27

Please sign in to comment.