void Zone::reset(bool releaseMemory) noexcept { Block* cur = _block; // Can't be altered. if (cur == &Zone_zeroBlock) return; if (releaseMemory) { // Since cur can be in the middle of the double-linked list, we have to // traverse to both directions `prev` and `next` separately. Block* next = cur->next; do { Block* prev = cur->prev; ASMJIT_FREE(cur); cur = prev; } while (cur != nullptr); cur = next; while (cur != nullptr) { next = cur->next; ASMJIT_FREE(cur); cur = next; } _block = const_cast<Zone::Block*>(&Zone_zeroBlock); } else { while (cur->prev != nullptr) cur = cur->prev; cur->pos = cur->data; _block = cur; } }
//! Clear vector data and free internal buffer. void PodVectorBase::reset(bool releaseMemory) noexcept { Data* d = _d; if (d == &_nullData) return; if (releaseMemory && !isDataStatic(this, d)) { ASMJIT_FREE(d); _d = const_cast<Data*>(&_nullData); return; } d->length = 0; }
//! Clear vector data and free internal buffer. void PodVectorBase::reset(bool releaseMemory) { PodVectorData* d = _d; if (d == &_nullData) return; if (releaseMemory) { ASMJIT_FREE(d); _d = const_cast<PodVectorData*>(&_nullData); return; } d->length = 0; }
uint32_t RemoteCodeGenerator::generate(void** dest, Assembler* assembler) { // Disallow empty code generation. sysuint_t codeSize = assembler->getCodeSize(); if (codeSize == 0) { *dest = NULL; return AsmJit::ERROR_NO_FUNCTION; } // Allocate temporary memory where the code will be stored and relocated. void* codeData = ASMJIT_MALLOC(codeSize); if (codeData == NULL) { *dest = NULL; return ERROR_NO_HEAP_MEMORY; } // Memory will be never freed, use pernament allocation. // // NOTE: This allocates memory of the hProcess, not our process. void* processMemPtr = _memoryManager.alloc(codeSize, MEMORY_ALLOC_PERMANENT); if (processMemPtr == NULL) { ASMJIT_FREE(codeData); *dest = NULL; return ERROR_NO_VIRTUAL_MEMORY; } // Relocate and write the code to the process memory. assembler->relocCode(codeData, (sysuint_t)processMemPtr); WriteProcessMemory(_hProcess, processMemPtr, codeData, codeSize, NULL); ASMJIT_FREE(codeData); *dest = processMemPtr; return ERROR_NONE; }
void Assembler::reset(bool releaseMemory) { // CodeGen members. _baseAddress = kNoBaseAddress; _instOptions = 0; _error = kErrorOk; _baseZone.reset(releaseMemory); // Assembler members. if (releaseMemory && _buffer != NULL) { ASMJIT_FREE(_buffer); _buffer = NULL; _end = NULL; } _cursor = _buffer; _trampolineSize = 0; _comment = NULL; _unusedLinks = NULL; _labelList.reset(releaseMemory); _relocList.reset(releaseMemory); }