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 16 #ifndef ECMASCRIPT_PLATFORM_ELF_H 17 #define ECMASCRIPT_PLATFORM_ELF_H 18 19 #include <stdint.h> 20 #if !defined(PANDA_TARGET_WINDOWS) && !defined(PANDA_TARGET_MACOS) 21 #include <elf.h> 22 #else 23 typedef uint16_t Elf64_Half; 24 typedef uint32_t Elf64_Word; 25 typedef uint64_t Elf64_Addr; 26 typedef uint64_t Elf64_Off; 27 #define EI_NIDENT (16) 28 29 typedef struct { 30 unsigned char e_ident[EI_NIDENT]; 31 Elf64_Half e_type; 32 Elf64_Half e_machine; 33 Elf64_Word e_version; 34 Elf64_Addr e_entry; 35 Elf64_Off e_phoff; 36 Elf64_Off e_shoff; 37 Elf64_Word e_flags; 38 Elf64_Half e_ehsize; 39 Elf64_Half e_phentsize; 40 Elf64_Half e_phnum; 41 Elf64_Half e_shentsize; 42 Elf64_Half e_shnum; 43 Elf64_Half e_shstrndx; 44 } Elf64_Ehdr; 45 #endif 46 47 namespace panda::ecmascript::kungfu { 48 enum class Triple { 49 TRIPLE_AMD64, 50 TRIPLE_AARCH64, 51 TRIPLE_ARM32, 52 }; 53 } // namespace panda::ecmascript::kungfu 54 55 namespace panda::ecmascript { 56 void PackELFHeader(Elf64_Ehdr &header, uint32_t version, kungfu::Triple triple); 57 bool SupportELF(); 58 bool VerifyELFHeader(const Elf64_Ehdr &header, uint32_t version, bool silent = false); 59 } // namespace panda::ecmascript 60 #endif // ECMASCRIPT_PLATFORM_ELF_H 61