1 /* 2 * Copyright 2011, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ELF_SECTION_BITS_HXX 18 #define ELF_SECTION_BITS_HXX 19 20 #include "utils/flush_cpu_cache.h" 21 #include "utils/helper.h" 22 23 #include <llvm/Support/raw_ostream.h> 24 25 #ifndef USE_MINGW /* TODO create a proper HAVE_MMAN_H */ 26 #include <sys/mman.h> 27 #else 28 #include "mmanWindows.h" 29 #endif 30 31 template <unsigned Bitwidth> 32 inline void ELFSectionBits<Bitwidth>::print() const { 33 using namespace llvm; 34 35 char const *section_type_str = 36 (sh->getType() == SHT_NOBITS) ? "NOBITS" : "PROGBITS"; 37 38 out() << '\n' << fillformat('=', 79) << '\n'; 39 out().changeColor(raw_ostream::WHITE, true); 40 out() << "ELF " << section_type_str << ": " << sh->getName() << '\n'; 41 out().resetColor(); 42 out() << fillformat('-', 79) << '\n'; 43 44 out() << " Size : " << sh->getSize() << '\n'; 45 out() << " Start Address: " << (void *)chunk.getBuffer() << '\n'; 46 out() << fillformat('-', 79) << '\n'; 47 48 chunk.print(); 49 50 out() << fillformat('=', 79) << '\n'; 51 } 52 53 template <unsigned Bitwidth> 54 inline bool ELFSectionBits<Bitwidth>::protect() { 55 int prot = PROT_READ; 56 57 if (sh->getFlags() & SHF_WRITE) { 58 prot |= PROT_WRITE; 59 } 60 61 if (sh->getFlags() & SHF_EXECINSTR) { 62 prot |= PROT_EXEC; 63 } 64 65 return chunk.protect(prot); 66 } 67 68 #endif // ELF_SECTION_BITS_HXX 69