10#if defined(USE_SIMULATOR)
16base::Mutex* SimulatorBase::redirection_mutex_ =
nullptr;
19Redirection* SimulatorBase::redirection_ =
nullptr;
22base::Mutex* SimulatorBase::i_cache_mutex_ =
nullptr;
28void SimulatorBase::InitializeOncePerProcess() {
30 redirection_mutex_ =
new base::Mutex();
33 i_cache_mutex_ =
new base::Mutex();
40void SimulatorBase::GlobalTearDown() {
41 delete redirection_mutex_;
42 redirection_mutex_ =
nullptr;
44 Redirection::DeleteChain(redirection_);
45 redirection_ =
nullptr;
47 delete i_cache_mutex_;
48 i_cache_mutex_ =
nullptr;
50 if (i_cache_ !=
nullptr) {
52 entry = i_cache_->Next(entry)) {
53 delete static_cast<CachePage*
>(entry->value);
61Address SimulatorBase::RedirectExternalReference(
Address external_function,
64 Redirection* redirection = Redirection::Get(external_function, type);
65 return redirection->address_of_instruction();
69Address SimulatorBase::UnwrapRedirection(
Address redirection_trampoline) {
70 return reinterpret_cast<Address>(
71 Redirection::UnwrapRedirection(redirection_trampoline));
74Redirection::Redirection(
Address external_function,
76 : external_function_(external_function),
type_(type), next_(nullptr) {
77 next_ = Simulator::redirection();
78 base::MutexGuard lock_guard(Simulator::i_cache_mutex());
79 Simulator::SetRedirectInstruction(
80 reinterpret_cast<Instruction*
>(address_of_instruction()));
81 Simulator::FlushICache(Simulator::i_cache(),
82 reinterpret_cast<void*
>(&instruction_),
83 sizeof(instruction_));
84 Simulator::set_redirection(
this);
85#if ABI_USES_FUNCTION_DESCRIPTORS
86 function_descriptor_[0] =
reinterpret_cast<intptr_t
>(&instruction_);
87 function_descriptor_[1] = 0;
88 function_descriptor_[2] = 0;
93Redirection* Redirection::Get(Address external_function,
94 ExternalReference::Type type) {
95 Redirection* current = Simulator::redirection();
96 for (; current !=
nullptr; current = current->next_) {
97 if (current->external_function_ == external_function &&
98 current->type_ == type) {
102 return new Redirection(external_function, type);
105void SimulatorData::RegisterFunctionsAndSignatures(
106 Address* c_functions,
const CFunctionInfo*
const* c_signatures,
107 unsigned num_functions) {
108 base::MutexGuard guard(&signature_map_mutex_);
109 for (
unsigned i = 0;
i < num_functions; ++
i) {
110 EncodedCSignature
sig(c_signatures[
i]);
111 AddSignatureForTarget(c_functions[
i], sig);
115const EncodedCSignature& SimulatorData::GetSignatureForTarget(Address target) {
116 base::MutexGuard guard(&signature_map_mutex_);
117 auto entry = target_to_signature_table_.find(target);
118 if (entry != target_to_signature_table_.end()) {
119 const EncodedCSignature&
sig = entry->second;
122 return EncodedCSignature::Invalid();
TemplateHashMapEntry< void *, void * > Entry
CustomMatcherTemplateHashMapImpl< DefaultAllocationPolicy > CustomMatcherHashMap
LockGuard< Mutex > MutexGuard
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig