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 #include <sys/mman.h>
26
27 template <unsigned Bitwidth>
print() const28 inline void ELFSectionBits<Bitwidth>::print() const {
29 using namespace llvm;
30
31 char const *section_type_str =
32 (sh->getType() == SHT_NOBITS) ? "NOBITS" : "PROGBITS";
33
34 out() << '\n' << fillformat('=', 79) << '\n';
35 out().changeColor(raw_ostream::WHITE, true);
36 out() << "ELF " << section_type_str << ": " << sh->getName() << '\n';
37 out().resetColor();
38 out() << fillformat('-', 79) << '\n';
39
40 out() << " Size : " << sh->getSize() << '\n';
41 out() << " Start Address: " << (void *)chunk.getBuffer() << '\n';
42 out() << fillformat('-', 79) << '\n';
43
44 chunk.print();
45
46 out() << fillformat('=', 79) << '\n';
47 }
48
49 template <unsigned Bitwidth>
protect()50 inline bool ELFSectionBits<Bitwidth>::protect() {
51 int prot = PROT_READ;
52
53 if (sh->getFlags() & SHF_WRITE) {
54 prot |= PROT_WRITE;
55 }
56
57 if (sh->getFlags() & SHF_EXECINSTR) {
58 prot |= PROT_EXEC;
59 }
60
61 return chunk.protect(prot);
62 }
63
64 #endif // ELF_SECTION_BITS_HXX
65