@encharm/cws 4.5.1 → 4.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +1 -1
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/package.json +1 -1
- package/src/Addon.h +6 -1
- package/src/headers/24/acorn_version.h +6 -0
- package/src/headers/24/addon_permission.h +31 -0
- package/src/headers/24/agent.h +195 -0
- package/src/headers/24/aliased_buffer-inl.h +244 -0
- package/src/headers/24/aliased_buffer.h +206 -0
- package/src/headers/24/aliased_struct-inl.h +54 -0
- package/src/headers/24/aliased_struct.h +63 -0
- package/src/headers/24/amaro_version.h +6 -0
- package/src/headers/24/application.h +165 -0
- package/src/headers/24/async_context_frame.h +33 -0
- package/src/headers/24/async_wrap-inl.h +96 -0
- package/src/headers/24/async_wrap.h +244 -0
- package/src/headers/24/base_object-inl.h +330 -0
- package/src/headers/24/base_object.h +338 -0
- package/src/headers/24/base_object_types.h +74 -0
- package/src/headers/24/bindingdata.h +272 -0
- package/src/headers/24/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/24/blob_serializer_deserializer.h +132 -0
- package/src/headers/24/callback_queue-inl.h +97 -0
- package/src/headers/24/callback_queue.h +79 -0
- package/src/headers/24/cares_wrap.h +447 -0
- package/src/headers/24/child_process_permission.h +31 -0
- package/src/headers/24/cid.h +127 -0
- package/src/headers/24/cjs_module_lexer_version.h +6 -0
- package/src/headers/24/cleanup_queue-inl.h +36 -0
- package/src/headers/24/cleanup_queue.h +79 -0
- package/src/headers/24/compile_cache.h +113 -0
- package/src/headers/24/connect_wrap.h +26 -0
- package/src/headers/24/connection_wrap.h +30 -0
- package/src/headers/24/cppgc_helpers-inl.h +65 -0
- package/src/headers/24/cppgc_helpers.h +162 -0
- package/src/headers/24/crypto/crypto_aes.h +97 -0
- package/src/headers/24/crypto/crypto_argon2.h +86 -0
- package/src/headers/24/crypto/crypto_bio.h +193 -0
- package/src/headers/24/crypto/crypto_chacha20_poly1305.h +64 -0
- package/src/headers/24/crypto/crypto_cipher.h +281 -0
- package/src/headers/24/crypto/crypto_clienthello-inl.h +90 -0
- package/src/headers/24/crypto/crypto_clienthello.h +131 -0
- package/src/headers/24/crypto/crypto_common.h +48 -0
- package/src/headers/24/crypto/crypto_context.h +171 -0
- package/src/headers/24/crypto/crypto_dh.h +126 -0
- package/src/headers/24/crypto/crypto_dsa.h +50 -0
- package/src/headers/24/crypto/crypto_ec.h +163 -0
- package/src/headers/24/crypto/crypto_hash.h +89 -0
- package/src/headers/24/crypto/crypto_hkdf.h +61 -0
- package/src/headers/24/crypto/crypto_hmac.h +92 -0
- package/src/headers/24/crypto/crypto_kem.h +113 -0
- package/src/headers/24/crypto/crypto_keygen.h +290 -0
- package/src/headers/24/crypto/crypto_keys.h +392 -0
- package/src/headers/24/crypto/crypto_ml_dsa.h +21 -0
- package/src/headers/24/crypto/crypto_pbkdf2.h +74 -0
- package/src/headers/24/crypto/crypto_random.h +124 -0
- package/src/headers/24/crypto/crypto_rsa.h +136 -0
- package/src/headers/24/crypto/crypto_scrypt.h +85 -0
- package/src/headers/24/crypto/crypto_sig.h +156 -0
- package/src/headers/24/crypto/crypto_spkac.h +21 -0
- package/src/headers/24/crypto/crypto_timing.h +20 -0
- package/src/headers/24/crypto/crypto_tls.h +309 -0
- package/src/headers/24/crypto/crypto_util.h +598 -0
- package/src/headers/24/crypto/crypto_x509.h +140 -0
- package/src/headers/24/data.h +148 -0
- package/src/headers/24/debug_utils-inl.h +232 -0
- package/src/headers/24/debug_utils.h +193 -0
- package/src/headers/24/defs.h +254 -0
- package/src/headers/24/diagnosticfilename-inl.h +33 -0
- package/src/headers/24/embedded_data.h +17 -0
- package/src/headers/24/encoding_binding.h +60 -0
- package/src/headers/24/endpoint.h +421 -0
- package/src/headers/24/env-inl.h +935 -0
- package/src/headers/24/env.h +1257 -0
- package/src/headers/24/env_properties.h +561 -0
- package/src/headers/24/fs_permission.h +167 -0
- package/src/headers/24/handle_wrap.h +123 -0
- package/src/headers/24/histogram-inl.h +107 -0
- package/src/headers/24/histogram.h +279 -0
- package/src/headers/24/http3.h +44 -0
- package/src/headers/24/inspector_agent.h +165 -0
- package/src/headers/24/inspector_io.h +78 -0
- package/src/headers/24/inspector_permission.h +31 -0
- package/src/headers/24/inspector_profiler.h +149 -0
- package/src/headers/24/inspector_socket.h +60 -0
- package/src/headers/24/inspector_socket_server.h +110 -0
- package/src/headers/24/io_agent.h +30 -0
- package/src/headers/24/js_native_api.h +615 -0
- package/src/headers/24/js_native_api_types.h +211 -0
- package/src/headers/24/js_native_api_v8.h +485 -0
- package/src/headers/24/js_native_api_v8_internals.h +45 -0
- package/src/headers/24/js_stream.h +52 -0
- package/src/headers/24/json_parser.h +40 -0
- package/src/headers/24/json_utils.h +172 -0
- package/src/headers/24/logstream.h +81 -0
- package/src/headers/24/main_thread_interface.h +116 -0
- package/src/headers/24/memory_tracker-inl.h +454 -0
- package/src/headers/24/memory_tracker.h +333 -0
- package/src/headers/24/module_wrap.h +229 -0
- package/src/headers/24/ncrypto.h +1625 -0
- package/src/headers/24/network_agent.h +118 -0
- package/src/headers/24/network_inspector.h +45 -0
- package/src/headers/24/network_resource_manager.h +29 -0
- package/src/headers/24/node.h +1620 -0
- package/src/headers/24/node_api.h +269 -0
- package/src/headers/24/node_api_internals.h +46 -0
- package/src/headers/24/node_api_types.h +52 -0
- package/src/headers/24/node_binding.h +163 -0
- package/src/headers/24/node_blob.h +159 -0
- package/src/headers/24/node_bob-inl.h +36 -0
- package/src/headers/24/node_bob.h +107 -0
- package/src/headers/24/node_buffer.h +92 -0
- package/src/headers/24/node_builtins.h +223 -0
- package/src/headers/24/node_config_file.h +65 -0
- package/src/headers/24/node_constants.h +82 -0
- package/src/headers/24/node_context_data.h +168 -0
- package/src/headers/24/node_contextify.h +261 -0
- package/src/headers/24/node_crypto.h +62 -0
- package/src/headers/24/node_debug.h +25 -0
- package/src/headers/24/node_dir.h +52 -0
- package/src/headers/24/node_dotenv.h +45 -0
- package/src/headers/24/node_errors.h +391 -0
- package/src/headers/24/node_exit_code.h +54 -0
- package/src/headers/24/node_external_reference.h +167 -0
- package/src/headers/24/node_file-inl.h +412 -0
- package/src/headers/24/node_file.h +540 -0
- package/src/headers/24/node_http2.h +1175 -0
- package/src/headers/24/node_http2_state.h +159 -0
- package/src/headers/24/node_http_common-inl.h +198 -0
- package/src/headers/24/node_http_common.h +535 -0
- package/src/headers/24/node_i18n.h +132 -0
- package/src/headers/24/node_internals.h +476 -0
- package/src/headers/24/node_json.h +24 -0
- package/src/headers/24/node_large_page.h +34 -0
- package/src/headers/24/node_locks.h +180 -0
- package/src/headers/24/node_main_instance.h +67 -0
- package/src/headers/24/node_mem-inl.h +112 -0
- package/src/headers/24/node_mem.h +45 -0
- package/src/headers/24/node_messaging.h +389 -0
- package/src/headers/24/node_metadata.h +164 -0
- package/src/headers/24/node_modules.h +93 -0
- package/src/headers/24/node_mutex.h +323 -0
- package/src/headers/24/node_object_wrap.h +132 -0
- package/src/headers/24/node_options-inl.h +524 -0
- package/src/headers/24/node_options.h +682 -0
- package/src/headers/24/node_perf.h +166 -0
- package/src/headers/24/node_perf_common.h +102 -0
- package/src/headers/24/node_platform.h +286 -0
- package/src/headers/24/node_process-inl.h +26 -0
- package/src/headers/24/node_process.h +111 -0
- package/src/headers/24/node_realm-inl.h +153 -0
- package/src/headers/24/node_realm.h +236 -0
- package/src/headers/24/node_report.h +43 -0
- package/src/headers/24/node_revert.h +82 -0
- package/src/headers/24/node_root_certs.h +3546 -0
- package/src/headers/24/node_sea.h +74 -0
- package/src/headers/24/node_shadow_realm.h +46 -0
- package/src/headers/24/node_snapshot_builder.h +57 -0
- package/src/headers/24/node_snapshotable.h +174 -0
- package/src/headers/24/node_sockaddr-inl.h +257 -0
- package/src/headers/24/node_sockaddr.h +394 -0
- package/src/headers/24/node_sqlite.h +270 -0
- package/src/headers/24/node_stat_watcher.h +73 -0
- package/src/headers/24/node_string.h +101 -0
- package/src/headers/24/node_task_runner.h +92 -0
- package/src/headers/24/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/24/node_threadsafe_cow.h +105 -0
- package/src/headers/24/node_trace_buffer.h +83 -0
- package/src/headers/24/node_trace_writer.h +75 -0
- package/src/headers/24/node_union_bytes.h +81 -0
- package/src/headers/24/node_url.h +101 -0
- package/src/headers/24/node_url_pattern.h +118 -0
- package/src/headers/24/node_v8.h +77 -0
- package/src/headers/24/node_v8_platform-inl.h +185 -0
- package/src/headers/24/node_version.h +110 -0
- package/src/headers/24/node_wasi.h +185 -0
- package/src/headers/24/node_wasm_web_api.h +55 -0
- package/src/headers/24/node_watchdog.h +154 -0
- package/src/headers/24/node_webstorage.h +60 -0
- package/src/headers/24/node_worker.h +159 -0
- package/src/headers/24/packet.h +155 -0
- package/src/headers/24/path.h +33 -0
- package/src/headers/24/permission/addon_permission.h +31 -0
- package/src/headers/24/permission/child_process_permission.h +31 -0
- package/src/headers/24/permission/fs_permission.h +167 -0
- package/src/headers/24/permission/inspector_permission.h +31 -0
- package/src/headers/24/permission/permission.h +100 -0
- package/src/headers/24/permission/permission_base.h +65 -0
- package/src/headers/24/permission/wasi_permission.h +31 -0
- package/src/headers/24/permission/worker_permission.h +31 -0
- package/src/headers/24/permission.h +100 -0
- package/src/headers/24/permission_base.h +65 -0
- package/src/headers/24/pipe_wrap.h +80 -0
- package/src/headers/24/preferredaddress.h +72 -0
- package/src/headers/24/protocol_helper.h +27 -0
- package/src/headers/24/queue.h +306 -0
- package/src/headers/24/req_wrap-inl.h +176 -0
- package/src/headers/24/req_wrap.h +79 -0
- package/src/headers/24/runtime_agent.h +41 -0
- package/src/headers/24/session.h +528 -0
- package/src/headers/24/sessionticket.h +108 -0
- package/src/headers/24/spawn_sync.h +243 -0
- package/src/headers/24/stream_base-inl.h +173 -0
- package/src/headers/24/stream_base.h +478 -0
- package/src/headers/24/stream_pipe.h +76 -0
- package/src/headers/24/stream_wrap.h +132 -0
- package/src/headers/24/streams.h +370 -0
- package/src/headers/24/string_bytes.h +109 -0
- package/src/headers/24/string_decoder-inl.h +31 -0
- package/src/headers/24/string_decoder.h +49 -0
- package/src/headers/24/target_agent.h +75 -0
- package/src/headers/24/tcp_wrap.h +105 -0
- package/src/headers/24/threadpoolwork-inl.h +70 -0
- package/src/headers/24/timer_wrap-inl.h +32 -0
- package/src/headers/24/timer_wrap.h +87 -0
- package/src/headers/24/timers.h +75 -0
- package/src/headers/24/tlscontext.h +228 -0
- package/src/headers/24/tokens.h +256 -0
- package/src/headers/24/trace_event.h +722 -0
- package/src/headers/24/trace_event_common.h +1109 -0
- package/src/headers/24/traced_value.h +129 -0
- package/src/headers/24/tracing_agent.h +43 -0
- package/src/headers/24/transportparams.h +166 -0
- package/src/headers/24/tty_wrap.h +65 -0
- package/src/headers/24/udp_wrap.h +230 -0
- package/src/headers/24/undici_version.h +6 -0
- package/src/headers/24/util-inl.h +711 -0
- package/src/headers/24/util.h +1016 -0
- package/src/headers/24/v8-external-memory-accounter.h +60 -0
- package/src/headers/24/v8-fast-api-calls.h +819 -0
- package/src/headers/24/v8-inspector.h +426 -0
- package/src/headers/24/wasi_permission.h +31 -0
- package/src/headers/24/worker_agent.h +40 -0
- package/src/headers/24/worker_inspector.h +124 -0
- package/src/headers/24/worker_permission.h +31 -0
- package/src/headers/24/zlib_version.h +6 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#ifndef SRC_NODE_LOCKS_H_
|
|
2
|
+
#define SRC_NODE_LOCKS_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <deque>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <unordered_set>
|
|
10
|
+
|
|
11
|
+
#include "base_object.h"
|
|
12
|
+
#include "env.h"
|
|
13
|
+
#include "node_mutex.h"
|
|
14
|
+
#include "v8.h"
|
|
15
|
+
|
|
16
|
+
namespace node::worker::locks {
|
|
17
|
+
|
|
18
|
+
class Lock final {
|
|
19
|
+
public:
|
|
20
|
+
enum class Mode { Shared, Exclusive };
|
|
21
|
+
|
|
22
|
+
Lock(Environment* env,
|
|
23
|
+
const std::u16string& name,
|
|
24
|
+
Mode mode,
|
|
25
|
+
const std::string& client_id,
|
|
26
|
+
v8::Local<v8::Promise::Resolver> waiting,
|
|
27
|
+
v8::Local<v8::Promise::Resolver> released);
|
|
28
|
+
~Lock() = default;
|
|
29
|
+
|
|
30
|
+
Lock(const Lock&) = delete;
|
|
31
|
+
Lock& operator=(const Lock&) = delete;
|
|
32
|
+
|
|
33
|
+
// Resource name for this lock as DOMString
|
|
34
|
+
const std::u16string& name() const { return name_; }
|
|
35
|
+
// Lock mode (shared or exclusive).
|
|
36
|
+
Mode mode() const { return mode_; }
|
|
37
|
+
// Client identifier string.
|
|
38
|
+
const std::string& client_id() const { return client_id_; }
|
|
39
|
+
// Environment that owns this lock.
|
|
40
|
+
Environment* env() const { return env_; }
|
|
41
|
+
|
|
42
|
+
// Returns true if this lock was stolen by another request.
|
|
43
|
+
bool is_stolen() const { return stolen_; }
|
|
44
|
+
// Marks this lock as stolen.
|
|
45
|
+
void mark_stolen() { stolen_ = true; }
|
|
46
|
+
|
|
47
|
+
// Promise that resolves when the user callback completes.
|
|
48
|
+
v8::Local<v8::Promise::Resolver> waiting_promise() {
|
|
49
|
+
return waiting_promise_.Get(env_->isolate());
|
|
50
|
+
}
|
|
51
|
+
// Promise that resolves when the lock is finally released.
|
|
52
|
+
v8::Local<v8::Promise::Resolver> released_promise() {
|
|
53
|
+
return released_promise_.Get(env_->isolate());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private:
|
|
57
|
+
Environment* env_;
|
|
58
|
+
std::u16string name_;
|
|
59
|
+
Mode mode_;
|
|
60
|
+
std::string client_id_;
|
|
61
|
+
bool stolen_ = false;
|
|
62
|
+
v8::Global<v8::Promise::Resolver> waiting_promise_;
|
|
63
|
+
v8::Global<v8::Promise::Resolver> released_promise_;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
class LockHolder final : public BaseObject {
|
|
67
|
+
public:
|
|
68
|
+
LockHolder(Environment* env,
|
|
69
|
+
v8::Local<v8::Object> obj,
|
|
70
|
+
std::shared_ptr<Lock> lock)
|
|
71
|
+
: BaseObject(env, obj), lock_(std::move(lock)) {
|
|
72
|
+
MakeWeak();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
~LockHolder() = default;
|
|
76
|
+
|
|
77
|
+
LockHolder(const LockHolder&) = delete;
|
|
78
|
+
LockHolder& operator=(const LockHolder&) = delete;
|
|
79
|
+
|
|
80
|
+
std::shared_ptr<Lock> lock() const { return lock_; }
|
|
81
|
+
|
|
82
|
+
SET_NO_MEMORY_INFO()
|
|
83
|
+
SET_MEMORY_INFO_NAME(LockHolder)
|
|
84
|
+
SET_SELF_SIZE(LockHolder)
|
|
85
|
+
|
|
86
|
+
static BaseObjectPtr<LockHolder> Create(Environment* env,
|
|
87
|
+
std::shared_ptr<Lock> lock);
|
|
88
|
+
|
|
89
|
+
private:
|
|
90
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
91
|
+
Environment* env);
|
|
92
|
+
|
|
93
|
+
std::shared_ptr<Lock> lock_;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
class LockRequest final {
|
|
97
|
+
public:
|
|
98
|
+
LockRequest(Environment* env,
|
|
99
|
+
v8::Local<v8::Promise::Resolver> waiting,
|
|
100
|
+
v8::Local<v8::Promise::Resolver> released,
|
|
101
|
+
v8::Local<v8::Function> callback,
|
|
102
|
+
const std::u16string& name,
|
|
103
|
+
Lock::Mode mode,
|
|
104
|
+
const std::string& client_id,
|
|
105
|
+
bool steal,
|
|
106
|
+
bool if_available);
|
|
107
|
+
~LockRequest() = default;
|
|
108
|
+
|
|
109
|
+
LockRequest(const LockRequest&) = delete;
|
|
110
|
+
LockRequest& operator=(const LockRequest&) = delete;
|
|
111
|
+
|
|
112
|
+
const std::u16string& name() const { return name_; }
|
|
113
|
+
Lock::Mode mode() const { return mode_; }
|
|
114
|
+
const std::string& client_id() const { return client_id_; }
|
|
115
|
+
bool steal() const { return steal_; }
|
|
116
|
+
// Returns true if this is an ifAvailable request.
|
|
117
|
+
bool if_available() const { return if_available_; }
|
|
118
|
+
Environment* env() const { return env_; }
|
|
119
|
+
|
|
120
|
+
v8::Local<v8::Promise::Resolver> waiting_promise() {
|
|
121
|
+
return waiting_promise_.Get(env_->isolate());
|
|
122
|
+
}
|
|
123
|
+
v8::Local<v8::Promise::Resolver> released_promise() {
|
|
124
|
+
return released_promise_.Get(env_->isolate());
|
|
125
|
+
}
|
|
126
|
+
v8::Local<v8::Function> callback() { return callback_.Get(env_->isolate()); }
|
|
127
|
+
|
|
128
|
+
private:
|
|
129
|
+
Environment* env_;
|
|
130
|
+
std::u16string name_;
|
|
131
|
+
Lock::Mode mode_;
|
|
132
|
+
std::string client_id_;
|
|
133
|
+
bool steal_;
|
|
134
|
+
bool if_available_;
|
|
135
|
+
v8::Global<v8::Promise::Resolver> waiting_promise_;
|
|
136
|
+
v8::Global<v8::Promise::Resolver> released_promise_;
|
|
137
|
+
v8::Global<v8::Function> callback_;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
class LockManager final {
|
|
141
|
+
public:
|
|
142
|
+
static void Request(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
143
|
+
static void Query(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
144
|
+
|
|
145
|
+
void ProcessQueue(Environment* env);
|
|
146
|
+
void CleanupEnvironment(Environment* env);
|
|
147
|
+
|
|
148
|
+
static void OnEnvironmentCleanup(void* arg);
|
|
149
|
+
static LockManager* GetCurrent() { return ¤t_; }
|
|
150
|
+
void ReleaseLockAndProcessQueue(Environment* env,
|
|
151
|
+
std::shared_ptr<Lock> lock,
|
|
152
|
+
v8::Local<v8::Value> result,
|
|
153
|
+
bool was_rejected = false);
|
|
154
|
+
|
|
155
|
+
private:
|
|
156
|
+
LockManager() = default;
|
|
157
|
+
~LockManager() = default;
|
|
158
|
+
|
|
159
|
+
LockManager(const LockManager&) = delete;
|
|
160
|
+
LockManager& operator=(const LockManager&) = delete;
|
|
161
|
+
|
|
162
|
+
bool IsGrantable(const LockRequest* req) const;
|
|
163
|
+
void CleanupStolenLocks(Environment* env);
|
|
164
|
+
void ReleaseLock(Lock* lock);
|
|
165
|
+
void WakeEnvironment(Environment* env);
|
|
166
|
+
|
|
167
|
+
static LockManager current_;
|
|
168
|
+
|
|
169
|
+
mutable Mutex mutex_;
|
|
170
|
+
// All entries for a given Environment* are purged in CleanupEnvironment().
|
|
171
|
+
std::unordered_map<std::u16string, std::deque<std::shared_ptr<Lock>>>
|
|
172
|
+
held_locks_;
|
|
173
|
+
std::deque<std::unique_ptr<LockRequest>> pending_queue_;
|
|
174
|
+
std::unordered_set<Environment*> registered_envs_;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
} // namespace node::worker::locks
|
|
178
|
+
|
|
179
|
+
#endif // NODE_WANT_INTERNALS
|
|
180
|
+
#endif // SRC_NODE_LOCKS_H_
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#ifndef SRC_NODE_MAIN_INSTANCE_H_
|
|
2
|
+
#define SRC_NODE_MAIN_INSTANCE_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <cstddef>
|
|
7
|
+
#include <memory>
|
|
8
|
+
|
|
9
|
+
#include "node.h"
|
|
10
|
+
#include "node_exit_code.h"
|
|
11
|
+
#include "util.h"
|
|
12
|
+
#include "uv.h"
|
|
13
|
+
#include "v8.h"
|
|
14
|
+
|
|
15
|
+
namespace node {
|
|
16
|
+
|
|
17
|
+
class ExternalReferenceRegistry;
|
|
18
|
+
struct EnvSerializeInfo;
|
|
19
|
+
struct SnapshotData;
|
|
20
|
+
|
|
21
|
+
// TODO(joyeecheung): align this with the Worker/WorkerThreadData class.
|
|
22
|
+
// We may be able to create an abstract class to reuse some of the routines.
|
|
23
|
+
class NodeMainInstance {
|
|
24
|
+
public:
|
|
25
|
+
// Create a main instance that owns the isolate
|
|
26
|
+
NodeMainInstance(const SnapshotData* snapshot_data,
|
|
27
|
+
uv_loop_t* event_loop,
|
|
28
|
+
MultiIsolatePlatform* platform,
|
|
29
|
+
const std::vector<std::string>& args,
|
|
30
|
+
const std::vector<std::string>& exec_args);
|
|
31
|
+
~NodeMainInstance();
|
|
32
|
+
|
|
33
|
+
// Start running the Node.js instances, return the exit code when finished.
|
|
34
|
+
ExitCode Run();
|
|
35
|
+
void Run(ExitCode* exit_code, Environment* env);
|
|
36
|
+
|
|
37
|
+
IsolateData* isolate_data() { return isolate_data_.get(); }
|
|
38
|
+
|
|
39
|
+
DeleteFnPtr<Environment, FreeEnvironment> CreateMainEnvironment(
|
|
40
|
+
ExitCode* exit_code);
|
|
41
|
+
|
|
42
|
+
NodeMainInstance(const NodeMainInstance&) = delete;
|
|
43
|
+
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
|
|
44
|
+
NodeMainInstance(NodeMainInstance&&) = delete;
|
|
45
|
+
NodeMainInstance& operator=(NodeMainInstance&&) = delete;
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
NodeMainInstance(v8::Isolate* isolate,
|
|
49
|
+
uv_loop_t* event_loop,
|
|
50
|
+
MultiIsolatePlatform* platform,
|
|
51
|
+
const std::vector<std::string>& args,
|
|
52
|
+
const std::vector<std::string>& exec_args);
|
|
53
|
+
|
|
54
|
+
std::vector<std::string> args_;
|
|
55
|
+
std::vector<std::string> exec_args_;
|
|
56
|
+
std::unique_ptr<ArrayBufferAllocator> array_buffer_allocator_;
|
|
57
|
+
v8::Isolate* isolate_;
|
|
58
|
+
MultiIsolatePlatform* platform_;
|
|
59
|
+
std::unique_ptr<IsolateData> isolate_data_;
|
|
60
|
+
std::unique_ptr<v8::Isolate::CreateParams> isolate_params_;
|
|
61
|
+
const SnapshotData* snapshot_data_ = nullptr;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace node
|
|
65
|
+
|
|
66
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
67
|
+
#endif // SRC_NODE_MAIN_INSTANCE_H_
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#ifndef SRC_NODE_MEM_INL_H_
|
|
2
|
+
#define SRC_NODE_MEM_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "node_mem.h"
|
|
7
|
+
#include "node_internals.h"
|
|
8
|
+
|
|
9
|
+
namespace node {
|
|
10
|
+
namespace mem {
|
|
11
|
+
|
|
12
|
+
template <typename Class, typename AllocatorStruct>
|
|
13
|
+
AllocatorStruct NgLibMemoryManager<Class, AllocatorStruct>::MakeAllocator() {
|
|
14
|
+
return AllocatorStruct {
|
|
15
|
+
static_cast<void*>(static_cast<Class*>(this)),
|
|
16
|
+
MallocImpl,
|
|
17
|
+
FreeImpl,
|
|
18
|
+
CallocImpl,
|
|
19
|
+
ReallocImpl
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
template <typename Class, typename T>
|
|
24
|
+
void* NgLibMemoryManager<Class, T>::ReallocImpl(void* ptr,
|
|
25
|
+
size_t size,
|
|
26
|
+
void* user_data) {
|
|
27
|
+
Class* manager = static_cast<Class*>(user_data);
|
|
28
|
+
|
|
29
|
+
size_t previous_size = 0;
|
|
30
|
+
char* original_ptr = nullptr;
|
|
31
|
+
|
|
32
|
+
// We prepend each allocated buffer with a size_t containing the full
|
|
33
|
+
// size of the allocation.
|
|
34
|
+
if (size > 0) size += sizeof(size_t);
|
|
35
|
+
|
|
36
|
+
if (ptr != nullptr) {
|
|
37
|
+
// We are free()ing or re-allocating.
|
|
38
|
+
original_ptr = static_cast<char*>(ptr) - sizeof(size_t);
|
|
39
|
+
previous_size = *reinterpret_cast<size_t*>(original_ptr);
|
|
40
|
+
// This means we called StopTracking() on this pointer before.
|
|
41
|
+
if (previous_size == 0) {
|
|
42
|
+
// Fall back to the standard Realloc() function.
|
|
43
|
+
char* ret = UncheckedRealloc(original_ptr, size);
|
|
44
|
+
if (ret != nullptr)
|
|
45
|
+
ret += sizeof(size_t);
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
manager->CheckAllocatedSize(previous_size);
|
|
51
|
+
|
|
52
|
+
char* mem = UncheckedRealloc(original_ptr, size);
|
|
53
|
+
|
|
54
|
+
if (mem != nullptr) {
|
|
55
|
+
// Adjust the memory info counter.
|
|
56
|
+
// TODO(addaleax): Avoid the double bookkeeping we do with
|
|
57
|
+
// current_nghttp2_memory_ + ExternalMemoryAccounter
|
|
58
|
+
// and provide versions of our memory allocation utilities that take an
|
|
59
|
+
// Environment*/Isolate* parameter and call the V8 method transparently.
|
|
60
|
+
const int64_t new_size = size - previous_size;
|
|
61
|
+
manager->IncreaseAllocatedSize(new_size);
|
|
62
|
+
manager->env()->external_memory_accounter()->Increase(
|
|
63
|
+
manager->env()->isolate(), new_size);
|
|
64
|
+
*reinterpret_cast<size_t*>(mem) = size;
|
|
65
|
+
mem += sizeof(size_t);
|
|
66
|
+
} else if (size == 0) {
|
|
67
|
+
manager->DecreaseAllocatedSize(previous_size);
|
|
68
|
+
manager->env()->external_memory_accounter()->Decrease(
|
|
69
|
+
manager->env()->isolate(), previous_size);
|
|
70
|
+
}
|
|
71
|
+
return mem;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
template <typename Class, typename T>
|
|
75
|
+
void* NgLibMemoryManager<Class, T>::MallocImpl(size_t size, void* user_data) {
|
|
76
|
+
return ReallocImpl(nullptr, size, user_data);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
template <typename Class, typename T>
|
|
80
|
+
void NgLibMemoryManager<Class, T>::FreeImpl(void* ptr, void* user_data) {
|
|
81
|
+
if (ptr == nullptr) return;
|
|
82
|
+
CHECK_NULL(ReallocImpl(ptr, 0, user_data));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template <typename Class, typename T>
|
|
86
|
+
void* NgLibMemoryManager<Class, T>::CallocImpl(size_t nmemb,
|
|
87
|
+
size_t size,
|
|
88
|
+
void* user_data) {
|
|
89
|
+
size_t real_size = MultiplyWithOverflowCheck(nmemb, size);
|
|
90
|
+
void* mem = MallocImpl(real_size, user_data);
|
|
91
|
+
if (mem != nullptr)
|
|
92
|
+
memset(mem, 0, real_size);
|
|
93
|
+
return mem;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
template <typename Class, typename T>
|
|
97
|
+
void NgLibMemoryManager<Class, T>::StopTrackingMemory(void* ptr) {
|
|
98
|
+
size_t* original_ptr = reinterpret_cast<size_t*>(
|
|
99
|
+
static_cast<char*>(ptr) - sizeof(size_t));
|
|
100
|
+
Class* manager = static_cast<Class*>(this);
|
|
101
|
+
manager->DecreaseAllocatedSize(*original_ptr);
|
|
102
|
+
manager->env()->external_memory_accounter()->Decrease(
|
|
103
|
+
manager->env()->isolate(), *original_ptr);
|
|
104
|
+
*original_ptr = 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
} // namespace mem
|
|
108
|
+
} // namespace node
|
|
109
|
+
|
|
110
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
111
|
+
|
|
112
|
+
#endif // SRC_NODE_MEM_INL_H_
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#ifndef SRC_NODE_MEM_H_
|
|
2
|
+
#define SRC_NODE_MEM_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <cstddef>
|
|
7
|
+
|
|
8
|
+
namespace node {
|
|
9
|
+
namespace mem {
|
|
10
|
+
|
|
11
|
+
// nghttp2 allows custom allocators that
|
|
12
|
+
// follow exactly the same structure and behavior, but
|
|
13
|
+
// use different struct names. To allow for code re-use,
|
|
14
|
+
// the NgLibMemoryManager template class can be used for both.
|
|
15
|
+
|
|
16
|
+
struct NgLibMemoryManagerBase {
|
|
17
|
+
virtual void StopTrackingMemory(void* ptr) = 0;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
template <typename Class, typename AllocatorStructName>
|
|
21
|
+
class NgLibMemoryManager : public NgLibMemoryManagerBase {
|
|
22
|
+
public:
|
|
23
|
+
// Class needs to provide these methods:
|
|
24
|
+
// void CheckAllocatedSize(size_t previous_size) const;
|
|
25
|
+
// void IncreaseAllocatedSize(size_t size);
|
|
26
|
+
// void DecreaseAllocatedSize(size_t size);
|
|
27
|
+
// Environment* env() const;
|
|
28
|
+
|
|
29
|
+
AllocatorStructName MakeAllocator();
|
|
30
|
+
|
|
31
|
+
void StopTrackingMemory(void* ptr) override;
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
static void* ReallocImpl(void* ptr, size_t size, void* user_data);
|
|
35
|
+
static void* MallocImpl(size_t size, void* user_data);
|
|
36
|
+
static void FreeImpl(void* ptr, void* user_data);
|
|
37
|
+
static void* CallocImpl(size_t nmemb, size_t size, void* user_data);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
} // namespace mem
|
|
41
|
+
} // namespace node
|
|
42
|
+
|
|
43
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
44
|
+
|
|
45
|
+
#endif // SRC_NODE_MEM_H_
|