Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Memory regions

A memory region is a block of contiguous virtual memory pages represented by its starting virtual address, maximum size, and access permissions.

A memory region is a block of contiguous virtual memory pages represented by its starting virtual address, maximum size, and access permissions. Each memory region can originate from one of the memory pools.

IMemRegion1 is the OS Services interface for memory regions, and provides restricted access permission for a memory region, as follows:

interface IMemRegion1 : IMemRegion
{
    /*
    * Creates an IMemRegion1 object representing the same virtual
    * memory region as piMemRegion, but with more restricted access
    * permissions *
    * @param info Region info structure that is populated
    * by this function
    */
    GrantAccess (in uint32 ulPerms, 
    rout IMemRegion1 ppiMemRegion1); 
};

The IMemRegion1_GrantAccess() method assigns the specified permission to the region. A region defined with this method can have read-only access (MEMREGION_ACCESS_READ), write-only access (MEMREGION_ACCESS_WRITE), or execute access (MEMREGION_ACCESS_EXECUTE):

const int32 MEMREGION_ACCESS_READ = 0x1
const int32 MEMREGION_ACCESS_WRITE = 0x2
const int32 MEMREGION_ACCESS_EXECUTE = 0x4

Any combination of the above permissions is allowed.

A region defined with the IMemRegion1_GrantAccess() method can have the following cache and sharing flags:

const int32 MEMREGION_CACHE_NONE = 0x1
const int32 MEMREGION_CACHE_WRITEBACK = 0x2
const int32 MEMREGION_CACHE_WRITETHRU = 0x3
const int32 MEMREGION_VIRTUAL_EXCL = 0x100
const int32 MEMREGION_VIRTUAL_COMMON = 0x200
const int32 MEMREGION_SHARE_EXCL = 0x1000
const int32 MEMREGION_SHARE_COMMON = 0x2000

Using cache attribute settings, cacheable memory can be configured to be either write-through or write-back. A write-through cache continuously writes stored data to memory, keeping cache and memory data synchronously consistent. A write-back cache asynchronously writes dirty cache lines to memory only when absolutely necessary. A write-back cache improves performance by reducing write operations, but increases the risk of lost data if the system crashes. If no flag is specified, the default memory region cache access permission depends on the target, which may use either MEMREGION_CACHE_WRITEBACK or MEMREGION_CACHE_WRITETHRU as the default.

Each memory region has an associated service object that contains the following information:

  • A reference to the underlying virtual memory region
  • Share access rights

The memory region service objects are created through IMemGroup_CreateRegion(). Multiple memory region service objects can refer to the same virtual memory region.

Access Rights

A region can be created and destroyed independently of any other region. However, region access is controllable only at the group level.

A process can map an IMemRegion1 region with permissions lesser than or equal to the permissions of the region in its address space. Permissions for a region are assigned when it is created, either through IMemGroup_CreateRegion() or IMemRegion1_GrantAccess().

Passing an IMemRegion with implied access rights to another process is the only way to grant access to shared memory.