Stephen Hines | b53c8a5 | 2013-04-05 22:17:36 -0700 | [diff] [blame] | 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_PROGBITS_H |
| 18 | #define ELF_SECTION_PROGBITS_H |
| 19 | |
| 20 | #include "ELFTypes.h" |
| 21 | #include "ELFSectionBits.h" |
| 22 | #include "ELFSectionHeader.h" |
| 23 | #include "MemChunk.h" |
| 24 | #include "StubLayout.h" |
| 25 | |
| 26 | template <unsigned Bitwidth> |
| 27 | class ELFSectionProgBits : public ELFSectionBits<Bitwidth> { |
| 28 | public: |
| 29 | ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth); |
| 30 | |
| 31 | private: |
| 32 | StubLayout *stubs; |
| 33 | |
| 34 | public: |
| 35 | template <typename Archiver> |
| 36 | static ELFSectionProgBits *read(Archiver &AR, |
| 37 | ELFObjectTy *owner, |
| 38 | ELFSectionHeaderTy const *sh); |
| 39 | |
| 40 | StubLayout *getStubLayout() { |
| 41 | return stubs; |
| 42 | } |
| 43 | |
| 44 | ELFSectionProgBits(int machine) { |
| 45 | switch(machine) { |
| 46 | case EM_ARM: |
Xiaofei Wan | 72151aa | 2014-06-12 21:44:09 +0800 | [diff] [blame^] | 47 | stubs = new StubLayoutARM(); |
Stephen Hines | b53c8a5 | 2013-04-05 22:17:36 -0700 | [diff] [blame] | 48 | break; |
| 49 | |
Dave Allison | 30e2a4c | 2014-03-28 14:23:09 -0700 | [diff] [blame] | 50 | case EM_AARCH64: |
Xiaofei Wan | 72151aa | 2014-06-12 21:44:09 +0800 | [diff] [blame^] | 51 | stubs = new StubLayoutAARCH64(); |
Dave Allison | 30e2a4c | 2014-03-28 14:23:09 -0700 | [diff] [blame] | 52 | break; |
| 53 | |
Stephen Hines | b53c8a5 | 2013-04-05 22:17:36 -0700 | [diff] [blame] | 54 | case EM_MIPS: |
Xiaofei Wan | 72151aa | 2014-06-12 21:44:09 +0800 | [diff] [blame^] | 55 | stubs = new StubLayoutMIPS(); |
| 56 | break; |
| 57 | |
| 58 | case EM_386: |
| 59 | stubs = new StubLayoutX86(); |
| 60 | break; |
| 61 | |
| 62 | case EM_X86_64: |
| 63 | stubs = new StubLayoutX86_64(); |
Stephen Hines | b53c8a5 | 2013-04-05 22:17:36 -0700 | [diff] [blame] | 64 | break; |
| 65 | |
| 66 | default: |
Xiaofei Wan | 72151aa | 2014-06-12 21:44:09 +0800 | [diff] [blame^] | 67 | stubs = NULL; |
Stephen Hines | b53c8a5 | 2013-04-05 22:17:36 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | ~ELFSectionProgBits() { |
| 72 | if (stubs) |
| 73 | delete stubs; |
| 74 | } |
| 75 | |
| 76 | private: |
| 77 | template <typename Archiver> |
| 78 | bool serialize(Archiver &AR) { |
| 79 | ELFSectionHeaderTy const *sh = this->sh; |
| 80 | MemChunk &chunk = this->chunk; |
| 81 | |
| 82 | AR.seek(sh->getOffset(), true); |
| 83 | AR.prologue(sh->getSize()); |
| 84 | AR.readBytes(chunk.getBuffer(), sh->getSize()); |
| 85 | AR.epilogue(sh->getSize()); |
| 86 | |
| 87 | return AR; |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | #include "impl/ELFSectionProgBits.hxx" |
| 92 | |
| 93 | #endif // ELF_SECTION_PROGBITS_H |