Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
v8::VirtualAddressSpace Class Referenceabstract

#include <v8-platform.h>

Public Types

using Address = uintptr_t
 

Public Member Functions

 VirtualAddressSpace (size_t page_size, size_t allocation_granularity, Address base, size_t size, PagePermissions max_page_permissions)
 
virtual ~VirtualAddressSpace ()=default
 
size_t page_size () const
 
size_t allocation_granularity () const
 
Address base () const
 
size_t size () const
 
PagePermissions max_page_permissions () const
 
bool Contains (Address address) const
 
virtual void SetRandomSeed (int64_t seed)=0
 
virtual Address RandomPageAddress ()=0
 
virtual Address AllocatePages (Address hint, size_t size, size_t alignment, PagePermissions permissions)=0
 
virtual void FreePages (Address address, size_t size)=0
 
virtual bool SetPagePermissions (Address address, size_t size, PagePermissions permissions)=0
 
virtual bool AllocateGuardRegion (Address address, size_t size)=0
 
virtual void FreeGuardRegion (Address address, size_t size)=0
 
virtual Address AllocateSharedPages (Address hint, size_t size, PagePermissions permissions, PlatformSharedMemoryHandle handle, uint64_t offset)=0
 
virtual void FreeSharedPages (Address address, size_t size)=0
 
virtual bool CanAllocateSubspaces ()=0
 
virtual std::unique_ptr< VirtualAddressSpaceAllocateSubspace (Address hint, size_t size, size_t alignment, PagePermissions max_page_permissions)=0
 
virtual bool RecommitPages (Address address, size_t size, PagePermissions permissions)=0
 
virtual bool DiscardSystemPages (Address address, size_t size)
 
virtual bool DecommitPages (Address address, size_t size)=0
 

Static Public Attributes

static constexpr Address kNoHint = 0
 

Detailed Description

Class to manage a virtual memory address space.

This class represents a contiguous region of virtual address space in which sub-spaces and (private or shared) memory pages can be allocated, freed, and modified. This interface is meant to eventually replace the PageAllocator interface, and can be used as an alternative in the meantime.

This API is not yet stable and may change without notice!

Member Typedef Documentation

◆ Address

Constructor & Destructor Documentation

◆ VirtualAddressSpace()

v8::VirtualAddressSpace::VirtualAddressSpace ( size_t  page_size,
size_t  allocation_granularity,
Address  base,
size_t  size,
PagePermissions  max_page_permissions 
)
inline

◆ ~VirtualAddressSpace()

virtual v8::VirtualAddressSpace::~VirtualAddressSpace ( )
virtualdefault

Member Function Documentation

◆ AllocateGuardRegion()

virtual bool v8::VirtualAddressSpace::AllocateGuardRegion ( Address  address,
size_t  size 
)
pure virtual

Creates a guard region at the specified address.

Guard regions are guaranteed to cause a fault when accessed and generally do not count towards any memory consumption limits. Further, allocating guard regions can usually not fail in subspaces if the region does not overlap with another region, subspace, or page allocation.

Parameters
addressThe start address of the guard region. Must be aligned to the allocation_granularity().
sizeThe size of the guard region in bytes. Must be a multiple of the allocation_granularity().
Returns
true on success, false otherwise.

◆ AllocatePages()

virtual Address v8::VirtualAddressSpace::AllocatePages ( Address  hint,
size_t  size,
size_t  alignment,
PagePermissions  permissions 
)
pure virtual

◆ AllocateSharedPages()

virtual Address v8::VirtualAddressSpace::AllocateSharedPages ( Address  hint,
size_t  size,
PagePermissions  permissions,
PlatformSharedMemoryHandle  handle,
uint64_t  offset 
)
pure virtual

Allocates shared memory pages with the given permissions.

Parameters
hintPlacement hint. See AllocatePages.
sizeThe size of the allocation in bytes. Must be a multiple of the allocation_granularity().
permissionsThe page permissions of the newly allocated pages.
handleA platform-specific handle to a shared memory object. See the SharedMemoryHandleFromX routines above for ways to obtain these.
offsetThe offset in the shared memory object at which the mapping should start. Must be a multiple of the allocation_granularity().
Returns
the start address of the allocated pages on success, zero on failure.

◆ AllocateSubspace()

virtual std::unique_ptr< VirtualAddressSpace > v8::VirtualAddressSpace::AllocateSubspace ( Address  hint,
size_t  size,
size_t  alignment,
PagePermissions  max_page_permissions 
)
pure virtual

◆ allocation_granularity()

size_t v8::VirtualAddressSpace::allocation_granularity ( ) const
inline

The granularity of page allocations and, by extension, of subspace allocations. This is guaranteed to be a power of two and a multiple of the page_size(). In practice, this is equal to the page size on most OSes, but on Windows it is usually 64KB, while the page size is 4KB.

Returns
the allocation granularity in bytes.

◆ base()

Address v8::VirtualAddressSpace::base ( ) const
inline

The base address of the address space managed by this instance.

Returns
the base address of this address space.
Here is the caller graph for this function:

◆ CanAllocateSubspaces()

virtual bool v8::VirtualAddressSpace::CanAllocateSubspaces ( )
pure virtual

Whether this instance can allocate subspaces or not.

Returns
true if subspaces can be allocated, false if not.

◆ Contains()

bool v8::VirtualAddressSpace::Contains ( Address  address) const
inline

Whether the |address| is inside the address space managed by this instance.

Returns
true if it is inside the address space, false if not.
Here is the call graph for this function:

◆ DecommitPages()

virtual bool v8::VirtualAddressSpace::DecommitPages ( Address  address,
size_t  size 
)
pure virtual

Decommits any wired memory pages in the given range, allowing the OS to reclaim them, and marks the region as inacessible (kNoAccess). The address range stays reserved and can be accessed again later by changing its permissions. However, in that case the memory content is guaranteed to be zero-initialized again. The memory must have been previously allocated by a call to AllocatePages.

Returns
true on success, false otherwise.

◆ DiscardSystemPages()

virtual bool v8::VirtualAddressSpace::DiscardSystemPages ( Address  address,
size_t  size 
)
inlinevirtual

Frees memory in the given [address, address + size) range. address and size should be aligned to the page_size(). The next write to this memory area brings the memory transparently back. This should be treated as a hint to the OS that the pages are no longer needed. It does not guarantee that the pages will be discarded immediately or at all.

Returns
true on success, false otherwise. Since this method is only a hint, a successful invocation does not imply that pages have been removed.

◆ FreeGuardRegion()

virtual void v8::VirtualAddressSpace::FreeGuardRegion ( Address  address,
size_t  size 
)
pure virtual

Frees an existing guard region.

This function will terminate the process on failure as this implies a bug in the client. As such, there is no return value.

Parameters
addressThe start address of the guard region to free. This address must have previously been used as address parameter in a successful invocation of AllocateGuardRegion.
sizeThe size in bytes of the guard region to free. This must match the size passed to AllocateGuardRegion when the region was created.

◆ FreePages()

virtual void v8::VirtualAddressSpace::FreePages ( Address  address,
size_t  size 
)
pure virtual

Frees previously allocated pages.

This function will terminate the process on failure as this implies a bug in the client. As such, there is no return value.

Parameters
addressThe start address of the pages to free. This address must have been obtained through a call to AllocatePages.
sizeThe size in bytes of the region to free. This must match the size passed to AllocatePages when the pages were allocated.

◆ FreeSharedPages()

virtual void v8::VirtualAddressSpace::FreeSharedPages ( Address  address,
size_t  size 
)
pure virtual

Frees previously allocated shared pages.

This function will terminate the process on failure as this implies a bug in the client. As such, there is no return value.

Parameters
addressThe start address of the pages to free. This address must have been obtained through a call to AllocateSharedPages.
sizeThe size in bytes of the region to free. This must match the size passed to AllocateSharedPages when the pages were allocated.

◆ max_page_permissions()

PagePermissions v8::VirtualAddressSpace::max_page_permissions ( ) const
inline

The maximum page permissions that pages allocated inside this space can obtain.

Returns
the maximum page permissions.

◆ page_size()

size_t v8::VirtualAddressSpace::page_size ( ) const
inline

The page size used inside this space. Guaranteed to be a power of two. Used as granularity for all page-related operations except for allocation, which use the allocation_granularity(), see below.

Returns
the page size in bytes.

◆ RandomPageAddress()

virtual Address v8::VirtualAddressSpace::RandomPageAddress ( )
pure virtual

Returns a random address inside this address space, suitable for page allocations hints.

Returns
a random address aligned to allocation_granularity().

◆ RecommitPages()

virtual bool v8::VirtualAddressSpace::RecommitPages ( Address  address,
size_t  size,
PagePermissions  permissions 
)
pure virtual

Recommits discarded pages in the given range with given permissions. Discarded pages must be recommitted with their original permissions before they are used again.

Parameters
addressThe start address of the range. Must be aligned to page_size().
sizeThe size in bytes of the range. Must be a multiple of page_size().
permissionsThe permissions for the range that the pages must have.
Returns
true on success, false otherwise.

◆ SetPagePermissions()

virtual bool v8::VirtualAddressSpace::SetPagePermissions ( Address  address,
size_t  size,
PagePermissions  permissions 
)
pure virtual

Sets permissions of all allocated pages in the given range.

This operation can fail due to OOM, in which case false is returned. If the operation fails for a reason other than OOM, this function will terminate the process as this implies a bug in the client.

Parameters
addressThe start address of the range. Must be aligned to page_size().
sizeThe size in bytes of the range. Must be a multiple of page_size().
permissionsThe new permissions for the range.
Returns
true on success, false on OOM.

◆ SetRandomSeed()

virtual void v8::VirtualAddressSpace::SetRandomSeed ( int64_t  seed)
pure virtual

Sets the random seed so that GetRandomPageAddress() will generate repeatable sequences of random addresses.

Parameters
Theseed for the PRNG.

◆ size()

size_t v8::VirtualAddressSpace::size ( ) const
inline

The size of the address space managed by this instance.

Returns
the size of this address space in bytes.
Here is the caller graph for this function:

Member Data Documentation

◆ kNoHint

constexpr Address v8::VirtualAddressSpace::kNoHint = 0
staticconstexpr

Allocates private memory pages with the given alignment and permissions.

Parameters
hintIf nonzero, the allocation is attempted to be placed at the given address first. If that fails, the allocation is attempted to be placed elsewhere, possibly nearby, but that is not guaranteed. Specifying zero for the hint always causes this function to choose a random address. The hint, if specified, must be aligned to the specified alignment.
sizeThe size of the allocation in bytes. Must be a multiple of the allocation_granularity().
alignmentThe alignment of the allocation in bytes. Must be a multiple of the allocation_granularity() and should be a power of two.
permissionsThe page permissions of the newly allocated pages.
Returns
the start address of the allocated pages on success, zero on failure.

The documentation for this class was generated from the following file: