| OLD | NEW |
| 1 # Copyright (c) 2013 The Native Client Authors. All rights reserved. | 1 # Copyright (c) 2013 The Native Client 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 import cStringIO | 5 import cStringIO |
| 6 import ctypes | 6 import ctypes |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 import tempfile | 11 import tempfile |
| 12 | 12 |
| 13 import objdump_parser | 13 import objdump_parser |
| 14 | 14 |
| 15 | 15 |
| 16 # Some constants from validator.h | 16 # Some constants from validator.h |
| 17 VALIDATION_ERRORS_MASK = 0x01ffc000 | 17 VALIDATION_ERRORS_MASK = 0x05ffc000 |
| 18 UNSUPPORTED_INSTRUCTION = 0x04000000 |
| 18 BAD_JUMP_TARGET = 0x40000000 | 19 BAD_JUMP_TARGET = 0x40000000 |
| 19 | 20 |
| 20 RESTRICTED_REGISTER_MASK = 0x00001f00 | 21 RESTRICTED_REGISTER_MASK = 0x00001f00 |
| 21 RESTRICTED_REGISTER_SHIFT = 8 | 22 RESTRICTED_REGISTER_SHIFT = 8 |
| 22 | 23 |
| 23 NC_REG_RAX = 0 | 24 NC_REG_RAX = 0 |
| 24 NC_REG_RCX = 1 | 25 NC_REG_RCX = 1 |
| 25 NC_REG_RDX = 2 | 26 NC_REG_RDX = 2 |
| 26 NC_REG_RBX = 3 | 27 NC_REG_RBX = 3 |
| 27 NC_REG_RSP = 4 | 28 NC_REG_RSP = 4 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 """ | 170 """ |
| 170 | 171 |
| 171 data_addr = ctypes.cast(data, ctypes.c_void_p).value | 172 data_addr = ctypes.cast(data, ctypes.c_void_p).value |
| 172 | 173 |
| 173 def LowLevelCallback(begin, end, info, callback_data): | 174 def LowLevelCallback(begin, end, info, callback_data): |
| 174 if callback is not None: | 175 if callback is not None: |
| 175 begin_index = ctypes.cast(begin, ctypes.c_void_p).value - data_addr | 176 begin_index = ctypes.cast(begin, ctypes.c_void_p).value - data_addr |
| 176 end_index = ctypes.cast(end, ctypes.c_void_p).value - data_addr | 177 end_index = ctypes.cast(end, ctypes.c_void_p).value - data_addr |
| 177 callback(begin_index, end_index, info) | 178 callback(begin_index, end_index, info) |
| 178 | 179 |
| 180 # UNSUPPORTED_INSTRUCTION indicates validator failure only for pnacl-mode. |
| 181 # Since by default we are in non-pnacl-mode, the flag is simply cleared. |
| 182 info &= ~UNSUPPORTED_INSTRUCTION |
| 183 |
| 179 # See validator.h for details | 184 # See validator.h for details |
| 180 if info & (VALIDATION_ERRORS_MASK | BAD_JUMP_TARGET) != 0: | 185 if info & (VALIDATION_ERRORS_MASK | BAD_JUMP_TARGET) != 0: |
| 181 return 0 | 186 return 0 |
| 182 else: | 187 else: |
| 183 return 1 | 188 return 1 |
| 184 | 189 |
| 185 options = 0 | 190 options = 0 |
| 186 if on_each_instruction: | 191 if on_each_instruction: |
| 187 options |= CALL_USER_CALLBACK_ON_EACH_INSTRUCTION | 192 options |= CALL_USER_CALLBACK_ON_EACH_INSTRUCTION |
| 188 if restricted_register is not None: | 193 if restricted_register is not None: |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 data, | 329 data, |
| 325 bitness=bitness, | 330 bitness=bitness, |
| 326 callback=Callback) | 331 callback=Callback) |
| 327 | 332 |
| 328 assert not result | 333 assert not result |
| 329 assert errors == [31], errors | 334 assert errors == [31], errors |
| 330 | 335 |
| 331 | 336 |
| 332 if __name__ == '__main__': | 337 if __name__ == '__main__': |
| 333 main() | 338 main() |
| OLD | NEW |