Logan Chien | 0f0899a | 2012-03-23 10:48:18 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 ART_SRC_ELF_IMAGE_H_ |
| 18 | #define ART_SRC_ELF_IMAGE_H_ |
| 19 | |
| 20 | #include "globals.h" |
Logan Chien | 08e1ba3 | 2012-05-08 15:08:51 +0800 | [diff] [blame] | 21 | #include <string> |
Logan Chien | 799ef4f | 2012-04-23 00:17:47 +0800 | [diff] [blame] | 22 | #include <vector> |
Logan Chien | 0f0899a | 2012-03-23 10:48:18 +0800 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | class ElfImage { |
| 27 | public: |
Logan Chien | 799ef4f | 2012-04-23 00:17:47 +0800 | [diff] [blame] | 28 | explicit ElfImage(const std::vector<uint8_t>& v) |
| 29 | : begin_(&*v.begin()), size_(v.size()) { |
Logan Chien | 0f0899a | 2012-03-23 10:48:18 +0800 | [diff] [blame] | 30 | } |
| 31 | |
Logan Chien | 08e1ba3 | 2012-05-08 15:08:51 +0800 | [diff] [blame] | 32 | explicit ElfImage(const std::string& s) |
| 33 | : begin_(reinterpret_cast<const uint8_t*>(s.data())), size_(s.size()) { |
| 34 | } |
| 35 | |
Logan Chien | 0f0899a | 2012-03-23 10:48:18 +0800 | [diff] [blame] | 36 | explicit ElfImage(const byte* begin, size_t size) |
| 37 | : begin_(begin), size_(size) { |
| 38 | } |
| 39 | |
TDYa127 | 9d93ee6 | 2012-05-09 09:56:07 -0700 | [diff] [blame] | 40 | // TODO: Remove this after implement in-place linking. |
| 41 | ElfImage() : begin_(NULL), size_(0) { |
| 42 | } |
| 43 | |
Logan Chien | 0f0899a | 2012-03-23 10:48:18 +0800 | [diff] [blame] | 44 | const byte* begin() const { |
| 45 | return begin_; |
| 46 | } |
| 47 | |
| 48 | const byte* end() const { |
| 49 | return (begin_ + size_); |
| 50 | } |
| 51 | |
| 52 | size_t size() const { |
| 53 | return size_; |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | const byte* begin_; |
| 58 | size_t size_; |
| 59 | }; |
| 60 | |
| 61 | } // namespace art |
| 62 | |
| 63 | #endif // ART_SRC_ELF_IMAGE_H_ |