Debian Codegraph @

js/src/wasm/WasmContext.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 2020 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_context_h
20 #define wasm_context_h
21
22 #include "mozilla/DoublyLinkedList.h"
23
24 namespace js::wasm {
25
26 #ifdef ENABLE_WASM_JSPI
27
28 class SuspenderObject;
29 class SuspenderObjectData;
30
31 class SuspenderContext {
32 private:
33 HeapPtr<SuspenderObject*> activeSuspender_;
34 // Using double-linked list to avoid allocation in the JIT code.
35 mozilla::DoublyLinkedList<SuspenderObjectData> suspendedStacks_;
36
37 public:
38 SuspenderContext();
39 ~SuspenderContext();
40 SuspenderObject* activeSuspender();
41 void setActiveSuspender(SuspenderObject* obj);
42 void trace(JSTracer* trc);
43 void traceRoots(JSTracer* trc);
44
45 friend class SuspenderObject;
46 };
47 #endif // ENABLE_WASM_JSPI
48
49 // wasm::Context lives in JSContext and contains the wasm-related per-context
50 // state.
51
52 class Context {
53 public:
54 Context()
55 : triedToInstallSignalHandlers(false),
56 haveSignalHandlers(false)
57 #ifdef ENABLE_WASM_JSPI
58 ,
59 suspendableStackLimit(JS::NativeStackLimitMin),
60 suspendableStacksCount(0)
61 #endif
62 {
63 }
64
65 // Used by wasm::EnsureThreadSignalHandlers(cx) to install thread signal
66 // handlers once per JSContext/thread.
67 bool triedToInstallSignalHandlers;
68 bool haveSignalHandlers;
69
70 #ifdef ENABLE_WASM_JSPI
71 JS::NativeStackLimit suspendableStackLimit;
72 mozilla::Atomic<uint32_t> suspendableStacksCount;
73 SuspenderContext promiseIntegration;
74 #endif
75 };
76
77 } // namespace js::wasm
78
79 #endif // wasm_context_h