1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * 4 * Copyright 2017 Mozilla Foundation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef wasm_process_h 20 #define wasm_process_h 21 22 #include "mozilla/Atomics.h" 23 24 namespace js { 25 namespace wasm { 26 27 class Code; 28 class CodeRange; 29 class CodeSegment; 30 31 // These methods return the wasm::CodeSegment (resp. wasm::Code) containing 32 // the given pc, if any exist in the process. These methods do not take a lock, 33 // and thus are safe to use in a profiling context. 34 35 const CodeSegment* LookupCodeSegment(const void* pc, 36 const CodeRange** codeRange = nullptr); 37 38 const Code* LookupCode(const void* pc, const CodeRange** codeRange = nullptr); 39 40 // Return whether the given PC is in any type of wasm code (module or builtin). 41 42 bool InCompiledCode(void* pc); 43 44 // A bool member that can be used as a very fast lookup to know if there is any 45 // code segment at all. 46 47 extern mozilla::Atomic<bool> CodeExists; 48 49 // These methods allow to (un)register CodeSegments so they can be looked up 50 // via pc in the methods described above. 51 52 bool RegisterCodeSegment(const CodeSegment* cs); 53 54 void UnregisterCodeSegment(const CodeSegment* cs); 55 56 // Whether this process is configured to use huge memory or not. 57 58 bool IsHugeMemoryEnabled(); 59 60 [[nodiscard]] bool DisableHugeMemory(); 61 62 // Called once before/after the last VM execution which could execute or compile 63 // wasm. 64 65 bool Init(); 66 67 void ShutDown(); 68 69 } // namespace wasm 70 } // namespace js 71 72 #endif // wasm_process_h 73