| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COURGETTE_DISASSEMBLER_H_ | 5 #ifndef COURGETTE_DISASSEMBLER_H_ |
| 6 #define COURGETTE_DISASSEMBLER_H_ | 6 #define COURGETTE_DISASSEMBLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // ok() may always be called but returns true only after ParseHeader() | 85 // ok() may always be called but returns true only after ParseHeader() |
| 86 // succeeds. | 86 // succeeds. |
| 87 bool ok() const { return failure_reason_ == nullptr; } | 87 bool ok() const { return failure_reason_ == nullptr; } |
| 88 | 88 |
| 89 // Returns the length of the image. May reduce after ParseHeader(). | 89 // Returns the length of the image. May reduce after ParseHeader(). |
| 90 size_t length() const { return length_; } | 90 size_t length() const { return length_; } |
| 91 const uint8_t* start() const { return start_; } | 91 const uint8_t* start() const { return start_; } |
| 92 const uint8_t* end() const { return end_; } | 92 const uint8_t* end() const { return end_; } |
| 93 | 93 |
| 94 protected: | 94 protected: |
| 95 Disassembler(const void* start, size_t length); | 95 Disassembler(const uint8_t* start, size_t length); |
| 96 | 96 |
| 97 bool Good(); | 97 bool Good(); |
| 98 bool Bad(const char *reason); | 98 bool Bad(const char *reason); |
| 99 | 99 |
| 100 // Returns true if the array lies within our memory region. | 100 // Returns true if the array lies within our memory region. |
| 101 bool IsArrayInBounds(size_t offset, size_t elements, size_t element_size) { | 101 bool IsArrayInBounds(size_t offset, size_t elements, size_t element_size) { |
| 102 return offset <= length() && elements <= (length() - offset) / element_size; | 102 return offset <= length() && elements <= (length() - offset) / element_size; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Computes and stores all Labels before scanning program bytes. | 105 // Computes and stores all Labels before scanning program bytes. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 120 size_t length_; // In current memory. | 120 size_t length_; // In current memory. |
| 121 const uint8_t* start_; // In current memory, base for 'file offsets'. | 121 const uint8_t* start_; // In current memory, base for 'file offsets'. |
| 122 const uint8_t* end_; // In current memory. | 122 const uint8_t* end_; // In current memory. |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(Disassembler); | 124 DISALLOW_COPY_AND_ASSIGN(Disassembler); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 } // namespace courgette | 127 } // namespace courgette |
| 128 | 128 |
| 129 #endif // COURGETTE_DISASSEMBLER_H_ | 129 #endif // COURGETTE_DISASSEMBLER_H_ |
| OLD | NEW |