1 // Copyright 2021 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_TRAP_HANDLER_TRAP_HANDLER_SIMULATOR_H_ 6 #define V8_TRAP_HANDLER_TRAP_HANDLER_SIMULATOR_H_ 7 8 #include <cstdint> 9 10 // This header defines the ProbeMemory function to be used by simulators to 11 // trigger a signal at a defined location, before doing an actual memory access. 12 13 // This implementation is only usable on an x64 host with non-x64 target (i.e. a 14 // simulator build on x64). 15 #if (!defined(_M_X64) && !defined(__x86_64__)) || defined(V8_TARGET_ARCH_X64) 16 #error "Do only include this file on simulator builds on x64." 17 #endif 18 19 namespace v8 { 20 namespace internal { 21 namespace trap_handler { 22 23 // Probe a memory address by doing a 1-byte read from the given address. If the 24 // address is not readable, this will cause a trap as usual, but the trap 25 // handler will recognise the address of the instruction doing the access and 26 // treat it specially. It will use the given {pc} to look up the respective 27 // landing pad and return to this function to return that landing pad. If {pc} 28 // is not registered as a protected instruction, the signal will be propagated 29 // as usual. 30 // If the read at {address} succeeds, this function returns {0} instead. 31 extern "C" uintptr_t ProbeMemory(uintptr_t address, uintptr_t pc); 32 33 } // namespace trap_handler 34 } // namespace internal 35 } // namespace v8 36 37 #endif // V8_TRAP_HANDLER_TRAP_HANDLER_SIMULATOR_H_ 38