Debian Codegraph @

js/src/wasm/WasmRealm.h

raw
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 2016 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_realm_h
20 #define wasm_realm_h
21
22 #include "js/TracingAPI.h"
23
24 #include "wasm/WasmTypeDecls.h"
25
26 namespace js {
27
28 class WasmTagObject;
29
30 namespace wasm {
31
32 // wasm::Realm lives in JS::Realm and contains the wasm-related per-realm state.
33 // wasm::Realm tracks every live instance in the realm and must be notified, via
34 // registerInstance(), of any new WasmInstanceObject.
35
36 class Realm {
37 JSRuntime* runtime_;
38 InstanceVector instances_;
39
40 public:
41 explicit Realm(JSRuntime* rt);
42 ~Realm();
43
44 // Before a WasmInstanceObject can be considered fully constructed and
45 // valid, it must be registered with the Realm. If this method fails,
46 // an error has been reported and the instance object must be abandoned.
47 // After a successful registration, an Instance must call
48 // unregisterInstance() before being destroyed.
49
50 bool registerInstance(JSContext* cx, Handle<WasmInstanceObject*> instanceObj);
51 void unregisterInstance(Instance& instance);
52
53 // Return a vector of all live instances in the realm. The lifetime of
54 // these Instances is determined by their owning WasmInstanceObject.
55 // Note that accessing instances()[i]->object() triggers a read barrier
56 // since instances() is effectively a weak list.
57
58 const InstanceVector& instances() const { return instances_; }
59
60 // Ensure all Instances in this Realm have profiling labels created.
61
62 void ensureProfilingLabels(bool profilingEnabled);
63
64 // about:memory reporting
65
66 void addSizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf,
67 size_t* realmTables);
68 };
69
70 // Interrupt all running wasm Instances that have been registered with
71 // wasm::Realms in the given JSContext.
72
73 extern void InterruptRunningCode(JSContext* cx);
74
75 // After a wasm Instance sees an interrupt request and calls
76 // CheckForInterrupt(), it should call RunningCodeInterrupted() to clear the
77 // interrupt request for all wasm Instances to avoid spurious trapping.
78
79 void ResetInterruptState(JSContext* cx);
80
81 #ifdef ENABLE_WASM_JSPI
82 void UpdateInstanceStackLimitsForSuspendableStack(JSContext* cx,
83 JS::NativeStackLimit limit);
84 void ResetInstanceStackLimits(JSContext* cx);
85 #endif
86
87 } // namespace wasm
88 } // namespace js
89
90 #endif // wasm_realm_h