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 getStubLayout()40 StubLayout *getStubLayout() { 41 return stubs; 42 } 43 ELFSectionProgBits(int machine)44 ELFSectionProgBits(int machine) { 45 switch(machine) { 46 case EM_ARM: 47 stubs = new StubLayoutARM(); 48 break; 49 50 case EM_AARCH64: 51 stubs = new StubLayoutAARCH64(); 52 break; 53 54 case EM_MIPS: 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(); 64 break; 65 66 default: 67 stubs = NULL; 68 } 69 } 70 ~ELFSectionProgBits()71 ~ELFSectionProgBits() { 72 if (stubs) 73 delete stubs; 74 } 75 76 private: 77 template <typename Archiver> serialize(Archiver & AR)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 94