1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef ECMASCRIPT_COMPILER_AOT_FILE_EXECUTED_MEMORY_ALLOCATOR_H 16 #define ECMASCRIPT_COMPILER_AOT_FILE_EXECUTED_MEMORY_ALLOCATOR_H 17 18 #include "ecmascript/mem/mem.h" 19 #include "ecmascript/platform/map.h" 20 21 namespace panda::ecmascript { 22 class ExecutedMemoryAllocator { 23 public: 24 struct ExeMem { 25 void *addr_ {nullptr}; 26 size_t size_ {0}; 27 }; 28 AllocateBuf(uint32_t size,ExeMem & exeMem)29 static void AllocateBuf(uint32_t size, ExeMem &exeMem) 30 { 31 MemMap buf = MachineCodePageMap(AlignUp(size, PageSize()), PAGE_PROT_EXEC_READWRITE); 32 exeMem.addr_ = buf.GetMem(); 33 exeMem.size_ = buf.GetSize(); 34 } 35 DestroyBuf(ExeMem & exeMem)36 static void DestroyBuf(ExeMem &exeMem) 37 { 38 if (exeMem.addr_ != nullptr) { 39 MachineCodePageUnmap(MemMap(exeMem.addr_, exeMem.size_)); 40 exeMem.addr_ = nullptr; 41 exeMem.size_ = 0; 42 } 43 } 44 }; 45 } // namespace panda::ecmascript 46 #endif // ECMASCRIPT_COMPILER_AOT_FILE_EXECUTED_MEMORY_ALLOCATOR_H 47