AsmJit
Low-Latency Machine Code Generation
Virtual memory management.
Describes whether instruction cache should be flushed after a write operation.
Virtual memory access and mmap-specific flags.
Constant | Description |
---|---|
kNone | No flags. |
kAccessRead | Memory is readable. |
kAccessWrite | Memory is writable. |
kAccessExecute | Memory is executable. |
kAccessReadWrite | A combination of kAccessRead and kAccessWrite. |
kAccessRW | A combination of kAccessRead, kAccessWrite. |
kAccessRX | A combination of kAccessRead and kAccessExecute. |
kAccessRWX | A combination of kAccessRead, kAccessWrite, and kAccessExecute. |
kMMapEnableMapJit | Use a This flag may be turned on by the allocator if there is no other way of allocating executable memory.
|
kMMapMaxAccessRead | Pass This flag allows to set a "maximum access" that the memory page can get during its lifetime. Use VirtMem::protect() to change the access flags.
|
kMMapMaxAccessWrite | Pass This flag allows to set a "maximum access" that the memory page can get during its lifetime. Use VirtMem::protect() to change the access flags.
|
kMMapMaxAccessExecute | Pass This flag allows to set a "maximum access" that the memory page can get during its lifetime. Use VirtMem::protect() to change the access flags.
|
kMMapMaxAccessReadWrite | A combination of kMMapMaxAccessRead and kMMapMaxAccessWrite. |
kMMapMaxAccessRW | A combination of kMMapMaxAccessRead and kMMapMaxAccessWrite. |
kMMapMaxAccessRX | A combination of kMMapMaxAccessRead and kMMapMaxAccessExecute. |
kMMapMaxAccessRWX | A combination of kMMapMaxAccessRead, kMMapMaxAccessWrite, kMMapMaxAccessExecute. |
kMapShared | Use
|
kMMapLargePages | Request large memory mapped pages.
|
kMappingPreferTmp | Not an access flag, only used by Please note that this flag will be ignored if the operating system allows to allocate an executable memory by a different API than
|
Hardened runtime flags.
Flushes instruction cache in the given region.
Only useful on non-x86 architectures, however, it's a good practice to call it on any platform to make your code more portable.
Returns virtual memory information, see VirtMem::Info
for more details.
Returns the size of the smallest large page supported.
AsmJit only uses the smallest large page at the moment as these are usually perfectly sized for executable memory allocation (standard size is 2MB, but different sizes are possible).
Returns either the detected large page size or 0, if large page support is either not supported by AsmJit or not accessible to the process.
Allocates virtual memory by either using mmap()
(POSIX) or VirtualAlloc()
(Windows).
size
should be aligned to page size, use VirtMem::info() to obtain it. Invalid size will not be corrected by the implementation and the allocation would not succeed in such case. Releases virtual memory previously allocated by VirtMem::alloc().
A cross-platform wrapper around mprotect()
(POSIX) and VirtualProtect()
(Windows).
Allocates virtual memory and creates two views of it where the first view has no write access.
This is an addition to the API that should be used in cases in which the operating system either enforces W^X security policy or the application wants to use this policy by default to improve security and prevent an accidental (or purposed) self-modifying code.
The memory returned in the dm
are two independent mappings of the same shared memory region. You must use VirtMem::releaseDualMapping() to release it when it's no longer needed. Never use VirtMem::release()
to release the memory returned by allocDualMapping()
as that would fail on Windows.
dm
would be set to nullptr
if the function fails. Releases virtual memory mapping previously allocated by VirtMem::allocDualMapping().
dm
would be set to nullptr
if the function succeeds. Returns runtime features provided by the OS.
Protects access of memory mapped with MAP_JIT flag for the current thread.
pthread_jit_write_protect_np()
call when available.This function must be called before and after a memory mapped with MAP_JIT flag is modified. Example:
See ProtectJitReadWriteScope, which makes it simpler than the code above.