1 /* 2 * Copyright (C) 2015 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_COMPILER_LINKER_ARM_RELATIVE_PATCHER_ARM_BASE_H_ 18 #define ART_COMPILER_LINKER_ARM_RELATIVE_PATCHER_ARM_BASE_H_ 19 20 #include <deque> 21 22 #include "linker/relative_patcher.h" 23 #include "method_reference.h" 24 25 namespace art { 26 namespace linker { 27 28 class ArmBaseRelativePatcher : public RelativePatcher { 29 public: 30 uint32_t ReserveSpace(uint32_t offset, 31 const CompiledMethod* compiled_method, 32 MethodReference method_ref) OVERRIDE; 33 uint32_t ReserveSpaceEnd(uint32_t offset) OVERRIDE; 34 uint32_t WriteThunks(OutputStream* out, uint32_t offset) OVERRIDE; 35 36 protected: 37 ArmBaseRelativePatcher(RelativePatcherTargetProvider* provider, 38 InstructionSet instruction_set, 39 std::vector<uint8_t> thunk_code, 40 uint32_t max_positive_displacement, 41 uint32_t max_negative_displacement); 42 43 uint32_t ReserveSpaceInternal(uint32_t offset, 44 const CompiledMethod* compiled_method, 45 MethodReference method_ref, 46 uint32_t max_extra_space); 47 uint32_t CalculateDisplacement(uint32_t patch_offset, uint32_t target_offset); 48 49 private: 50 bool ReserveSpaceProcessPatches(uint32_t quick_code_offset, MethodReference method_ref, 51 uint32_t next_aligned_offset); 52 53 RelativePatcherTargetProvider* const provider_; 54 const InstructionSet instruction_set_; 55 const std::vector<uint8_t> thunk_code_; 56 const uint32_t max_positive_displacement_; 57 const uint32_t max_negative_displacement_; 58 std::vector<uint32_t> thunk_locations_; 59 size_t current_thunk_to_write_; 60 61 // ReserveSpace() tracks unprocessed patches. 62 typedef std::pair<MethodReference, uint32_t> UnprocessedPatch; 63 std::deque<UnprocessedPatch> unprocessed_patches_; 64 65 friend class Arm64RelativePatcherTest; 66 friend class Thumb2RelativePatcherTest; 67 68 DISALLOW_COPY_AND_ASSIGN(ArmBaseRelativePatcher); 69 }; 70 71 } // namespace linker 72 } // namespace art 73 74 #endif // ART_COMPILER_LINKER_ARM_RELATIVE_PATCHER_ARM_BASE_H_ 75