asmjit::JitAllocator::Span Class Reference

A memory reference returned by JitAllocator::alloc().

Span contains everything needed to actually write new code to the memory chunk it references.

Public Members


Public Types


Member Functions


Member Enumeration Documentation

class JitAllocator::Span::Flags : uint32_tenumstrong◆ 

Span flags.


No flags.


The process has never executed the region of the span.

  If this flag is set on a \ref Span it would mean that the allocator can avoid flushing
  instruction cache after a code has been written to it. 

Member Function Documentation

void* JitAllocator::Span::rx() constnoexcept◆ 

Returns a pointer having Read & Execute permissions (references executable memory).

This pointer is never NULL if the allocation succeeded, it points to an executable memory.

void* JitAllocator::Span::rw() constnoexcept◆ 

Returns a pointer having Read & Write permissions (references writable memory).

Depending on the type of the allocation strategy this could either be:

  • the same address as returned by rx() if the allocator uses RWX mapping (pages have all of Read, Write, and Execute permissions) or MAP_JIT, which requires either ProtectJitReadWriteScope or to call VirtMem::protectJitMemory() manually.
  • a valid pointer, but not the same as rx - this would be valid if dual mapping is used.
  • NULL pointer, in case that the allocation strategy doesn't use RWX, MAP_JIT, or dual mapping. In this case only JitAllocator can copy new code into the executable memory referenced by Addr.
If rw() returns a non-null pointer it's important to use either VirtMem::protectJitMemory() or ProtectJitReadWriteScope to guard the write, because in case of MAP_JIT it would temporarily switch the permissions of the pointer to RW (that's per thread permissions). if ProtectJitReadWriteScope is not used it's important to clear the instruction cache via VirtMem::flushInstructionCache() after the write is done.

size_t JitAllocator::Span::size() constnoexcept◆ 

Returns size of this span, aligned to the allocator granularity.

Flags JitAllocator::Span::flags() constnoexcept◆ 

Returns span flags.

void JitAllocator::Span::shrink(size_t newSize)noexcept◆ 

Shrinks this span to newSize.

This is the only function that is able to change the size of a span, and it's only use case is to shrink the span size during JitAllocator::write(). When the writer detects that the span size shrunk, it will automatically shrink the memory used by the span, and propagate the new aligned size to the caller.

bool JitAllocator::Span::isDirectlyWritable() constnoexcept◆ 

Returns whether rw() returns a non-null pointer.

Member Data Documentation

void* JitAllocator::Span::_rx = nullptr◆ 

Address of memory that has Read and Execute permissions.

void* JitAllocator::Span::_rw = nullptr◆ 

Address of memory that has Read and Write permissions.

size_t JitAllocator::Span::_size = 0◆ 

Size of the span in bytes (rounded up to the allocation granularity).

void* JitAllocator::Span::_block = nullptr◆ 

Pointer that references a memory block maintained by JitAllocator.

This pointer is considered private and should never be used nor inspected outside of AsmJit.

Flags JitAllocator::Span::_flags = Flags::kNone◆ 

Span flags.

uint32_t JitAllocator::Span::_reserved = 0◆ 

Reserved for future use.