| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -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 |  | 
| Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_ELF_WRITER_H_ | 
 | 18 | #define ART_COMPILER_ELF_WRITER_H_ | 
| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 19 |  | 
| Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 20 | #include <stdint.h> | 
| Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 21 | #include <cstddef> | 
| Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 22 | #include <string> | 
| Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 23 | #include <vector> | 
 | 24 |  | 
| Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 25 | #include "base/macros.h" | 
| Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 26 | #include "base/mutex.h" | 
| Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 27 | #include "os.h" | 
 | 28 |  | 
| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 29 | namespace art { | 
| Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 30 |  | 
| Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 31 | class CompilerDriver; | 
| Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 32 | class DexFile; | 
| Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 33 | class ElfFile; | 
| Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 34 | class OatWriter; | 
| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 35 |  | 
 | 36 | class ElfWriter { | 
 | 37 |  public: | 
| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 38 |   // Looks up information about location of oat file in elf file container. | 
 | 39 |   // Used for ImageWriter to perform memory layout. | 
 | 40 |   static void GetOatElfInformation(File* file, | 
 | 41 |                                    size_t& oat_loaded_size, | 
 | 42 |                                    size_t& oat_data_offset); | 
 | 43 |  | 
| Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 44 |   // Returns runtime oat_data runtime address for an opened ElfFile. | 
| Tong Shen | 62d1ca3 | 2014-09-03 17:24:56 -0700 | [diff] [blame] | 45 |   static uintptr_t GetOatDataAddress(ElfFile* elf_file); | 
 | 46 |  | 
 | 47 |   static bool Fixup(File* file, uintptr_t oat_data_begin); | 
| Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 48 |  | 
 | 49 |  protected: | 
| Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 50 |   ElfWriter(const CompilerDriver& driver, File* elf_file) | 
 | 51 |     : compiler_driver_(&driver), elf_file_(elf_file) { | 
 | 52 |   } | 
| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 53 |  | 
| Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 54 |   virtual ~ElfWriter() {} | 
 | 55 |  | 
 | 56 |   virtual bool Write(OatWriter* oat_writer, | 
| Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 57 |                      const std::vector<const DexFile*>& dex_files, | 
 | 58 |                      const std::string& android_root, | 
 | 59 |                      bool is_host) | 
 | 60 |       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; | 
| Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 61 |  | 
| Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 62 |   const CompilerDriver* const compiler_driver_; | 
 | 63 |   File* const elf_file_; | 
| Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 64 | }; | 
 | 65 |  | 
 | 66 | }  // namespace art | 
 | 67 |  | 
| Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 68 | #endif  // ART_COMPILER_ELF_WRITER_H_ |