| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 582c34d commit a8daccc
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,8 @@ IsolateData::IsolateData(Isolate* isolate, | |||
| 79 | 79 | if (platform_ != nullptr) | |
| 80 | 80 | platform_->RegisterIsolate(isolate_, event_loop); | |
| 81 | 81 | ||
| 82 | - options_.reset(new PerIsolateOptions(*per_process_opts->per_isolate)); | ||
| 82 | + options_.reset( | ||
| 83 | + new PerIsolateOptions(*(per_process::cli_options->per_isolate))); | ||
| 83 | 84 | ||
| 84 | 85 | // Create string and private symbol properties as internalized one byte | |
| 85 | 86 | // strings after the platform is properly initialized. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,21 +139,31 @@ using v8::Undefined; | |||
| 139 | 139 | using v8::V8; | |
| 140 | 140 | using v8::Value; | |
| 141 | 141 | ||
| 142 | + namespace per_process { | ||
| 143 | + // Tells whether --prof is passed. | ||
| 144 | + // TODO(joyeecheung): move env->options()->prof_process to | ||
| 145 | + // per_process::cli_options.prof_process and use that instead. | ||
| 142 | 146 | static bool v8_is_profiling = false; | |
| 143 | 147 | ||
| 144 | - // Bit flag used to track security reverts (see node_revert.h) | ||
| 145 | - unsigned int reverted = 0; | ||
| 148 | + // TODO(joyeecheung): these are no longer necessary. Remove them. | ||
| 149 | + // See: https://github.com/nodejs/node/pull/25302#discussion_r244924196 | ||
| 150 | + // Isolate on the main thread | ||
| 151 | + static Mutex main_isolate_mutex; | ||
| 152 | + static Isolate* main_isolate; | ||
| 146 | 153 | ||
| 154 | + // node_revert.h | ||
| 155 | + // Bit flag used to track security reverts. | ||
| 156 | + unsigned int reverted_cve = 0; | ||
| 157 | + | ||
| 158 | + // util.h | ||
| 159 | + // Tells whether the per-process V8::Initialize() is called and | ||
| 160 | + // if it is safe to call v8::Isolate::GetCurrent(). | ||
| 147 | 161 | bool v8_initialized = false; | |
| 148 | 162 | ||
| 163 | + // node_internals.h | ||
| 149 | 164 | // process-relative uptime base, initialized at start-up | |
| 150 | 165 | double prog_start_time; | |
| 151 | - | ||
| 152 | - Mutex per_process_opts_mutex; | ||
| 153 | - std::shared_ptr<PerProcessOptions> per_process_opts { | ||
| 154 | - new PerProcessOptions() }; | ||
| 155 | - static Mutex node_isolate_mutex; | ||
| 156 | - static Isolate* node_isolate; | ||
| 166 | + } // namespace per_process | ||
| 157 | 167 | ||
| 158 | 168 | // Ensures that __metadata trace events are only emitted | |
| 159 | 169 | // when tracing is enabled. | |
@@ -269,14 +279,15 @@ static struct { | |||
| 269 | 279 | #endif // HAVE_INSPECTOR | |
| 270 | 280 | ||
| 271 | 281 | void StartTracingAgent() { | |
| 272 | - if (per_process_opts->trace_event_categories.empty()) { | ||
| 282 | + if (per_process::cli_options->trace_event_categories.empty()) { | ||
| 273 | 283 | tracing_file_writer_ = tracing_agent_->DefaultHandle(); | |
| 274 | 284 | } else { | |
| 275 | 285 | tracing_file_writer_ = tracing_agent_->AddClient( | |
| 276 | - ParseCommaSeparatedSet(per_process_opts->trace_event_categories), | ||
| 286 | + ParseCommaSeparatedSet( | ||
| 287 | + per_process::cli_options->trace_event_categories), | ||
| 277 | 288 | std::unique_ptr<tracing::AsyncTraceWriter>( | |
| 278 | 289 | new tracing::NodeTraceWriter( | |
| 279 | - per_process_opts->trace_event_file_pattern)), | ||
| 290 | + per_process::cli_options->trace_event_file_pattern)), | ||
| 280 | 291 | tracing::Agent::kUseDefaultCategories); | |
| 281 | 292 | } | |
| 282 | 293 | } | |
@@ -504,7 +515,7 @@ const char* signo_string(int signo) { | |||
| 504 | 515 | } | |
| 505 | 516 | ||
| 506 | 517 | void* ArrayBufferAllocator::Allocate(size_t size) { | |
| 507 | - if (zero_fill_field_ || per_process_opts->zero_fill_all_buffers) | ||
| 518 | + if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers) | ||
| 508 | 519 | return UncheckedCalloc(size); | |
| 509 | 520 | else | |
| 510 | 521 | return UncheckedMalloc(size); | |
@@ -1254,12 +1265,12 @@ void ProcessArgv(std::vector<std::string>* args, | |||
| 1254 | 1265 | { | |
| 1255 | 1266 | // TODO(addaleax): The mutex here should ideally be held during the | |
| 1256 | 1267 | // entire function, but that doesn't play well with the exit() calls below. | |
| 1257 | - Mutex::ScopedLock lock(per_process_opts_mutex); | ||
| 1268 | + Mutex::ScopedLock lock(per_process::cli_options_mutex); | ||
| 1258 | 1269 | options_parser::PerProcessOptionsParser::instance.Parse( | |
| 1259 | 1270 | args, | |
| 1260 | 1271 | exec_args, | |
| 1261 | 1272 | &v8_args, | |
| 1262 | - per_process_opts.get(), | ||
| 1273 | + per_process::cli_options.get(), | ||
| 1263 | 1274 | is_env ? kAllowedInEnvironment : kDisallowedInEnvironment, | |
| 1264 | 1275 | &errors); | |
| 1265 | 1276 | } | |
@@ -1271,20 +1282,20 @@ void ProcessArgv(std::vector<std::string>* args, | |||
| 1271 | 1282 | exit(9); | |
| 1272 | 1283 | } | |
| 1273 | 1284 | ||
| 1274 | - if (per_process_opts->print_version) { | ||
| 1285 | + if (per_process::cli_options->print_version) { | ||
| 1275 | 1286 | printf("%s\n", NODE_VERSION); | |
| 1276 | 1287 | exit(0); | |
| 1277 | 1288 | } | |
| 1278 | 1289 | ||
| 1279 | - if (per_process_opts->print_v8_help) { | ||
| 1290 | + if (per_process::cli_options->print_v8_help) { | ||
| 1280 | 1291 | V8::SetFlagsFromString("--help", 6); | |
| 1281 | 1292 | exit(0); | |
| 1282 | 1293 | } | |
| 1283 | 1294 | ||
| 1284 | - for (const std::string& cve : per_process_opts->security_reverts) | ||
| 1295 | + for (const std::string& cve : per_process::cli_options->security_reverts) | ||
| 1285 | 1296 | Revert(cve.c_str()); | |
| 1286 | 1297 | ||
| 1287 | - auto env_opts = per_process_opts->per_isolate->per_env; | ||
| 1298 | + auto env_opts = per_process::cli_options->per_isolate->per_env; | ||
| 1288 | 1299 | if (std::find(v8_args.begin(), v8_args.end(), | |
| 1289 | 1300 | "--abort-on-uncaught-exception") != v8_args.end() || | |
| 1290 | 1301 | std::find(v8_args.begin(), v8_args.end(), | |
@@ -1297,14 +1308,14 @@ void ProcessArgv(std::vector<std::string>* args, | |||
| 1297 | 1308 | // behavior but it could also interfere with the user's intentions in ways | |
| 1298 | 1309 | // we fail to anticipate. Dillema. | |
| 1299 | 1310 | if (std::find(v8_args.begin(), v8_args.end(), "--prof") != v8_args.end()) { | |
| 1300 | - v8_is_profiling = true; | ||
| 1311 | + per_process::v8_is_profiling = true; | ||
| 1301 | 1312 | } | |
| 1302 | 1313 | ||
| 1303 | 1314 | #ifdef __POSIX__ | |
| 1304 | 1315 | // Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the | |
| 1305 | 1316 | // performance penalty of frequent EINTR wakeups when the profiler is running. | |
| 1306 | 1317 | // Only do this for v8.log profiling, as it breaks v8::CpuProfiler users. | |
| 1307 | - if (v8_is_profiling) { | ||
| 1318 | + if (per_process::v8_is_profiling) { | ||
| 1308 | 1319 | uv_loop_configure(uv_default_loop(), UV_LOOP_BLOCK_SIGNAL, SIGPROF); | |
| 1309 | 1320 | } | |
| 1310 | 1321 | #endif | |
@@ -1333,7 +1344,7 @@ void ProcessArgv(std::vector<std::string>* args, | |||
| 1333 | 1344 | void Init(std::vector<std::string>* argv, | |
| 1334 | 1345 | std::vector<std::string>* exec_argv) { | |
| 1335 | 1346 | // Initialize prog_start_time to get relative uptime. | |
| 1336 | - prog_start_time = static_cast<double>(uv_now(uv_default_loop())); | ||
| 1347 | + per_process::prog_start_time = static_cast<double>(uv_now(uv_default_loop())); | ||
| 1337 | 1348 | ||
| 1338 | 1349 | // Register built-in modules | |
| 1339 | 1350 | binding::RegisterBuiltinModules(); | |
@@ -1349,7 +1360,7 @@ void Init(std::vector<std::string>* argv, | |||
| 1349 | 1360 | #endif | |
| 1350 | 1361 | ||
| 1351 | 1362 | std::shared_ptr<EnvironmentOptions> default_env_options = | |
| 1352 | - per_process_opts->per_isolate->per_env; | ||
| 1363 | + per_process::cli_options->per_isolate->per_env; | ||
| 1353 | 1364 | { | |
| 1354 | 1365 | std::string text; | |
| 1355 | 1366 | default_env_options->pending_deprecation = | |
@@ -1378,7 +1389,7 @@ void Init(std::vector<std::string>* argv, | |||
| 1378 | 1389 | } | |
| 1379 | 1390 | ||
| 1380 | 1391 | #if HAVE_OPENSSL | |
| 1381 | - std::string* openssl_config = &per_process_opts->openssl_config; | ||
| 1392 | + std::string* openssl_config = &per_process::cli_options->openssl_config; | ||
| 1382 | 1393 | if (openssl_config->empty()) { | |
| 1383 | 1394 | credentials::SafeGetenv("OPENSSL_CONF", openssl_config); | |
| 1384 | 1395 | } | |
@@ -1412,16 +1423,17 @@ void Init(std::vector<std::string>* argv, | |||
| 1412 | 1423 | ProcessArgv(argv, exec_argv, false); | |
| 1413 | 1424 | ||
| 1414 | 1425 | // Set the process.title immediately after processing argv if --title is set. | |
| 1415 | - if (!per_process_opts->title.empty()) | ||
| 1416 | - uv_set_process_title(per_process_opts->title.c_str()); | ||
| 1426 | + if (!per_process::cli_options->title.empty()) | ||
| 1427 | + uv_set_process_title(per_process::cli_options->title.c_str()); | ||
| 1417 | 1428 | ||
| 1418 | 1429 | #if defined(NODE_HAVE_I18N_SUPPORT) | |
| 1419 | 1430 | // If the parameter isn't given, use the env variable. | |
| 1420 | - if (per_process_opts->icu_data_dir.empty()) | ||
| 1421 | - credentials::SafeGetenv("NODE_ICU_DATA", &per_process_opts->icu_data_dir); | ||
| 1431 | + if (per_process::cli_options->icu_data_dir.empty()) | ||
| 1432 | + credentials::SafeGetenv("NODE_ICU_DATA", | ||
| 1433 | + &per_process::cli_options->icu_data_dir); | ||
| 1422 | 1434 | // Initialize ICU. | |
| 1423 | 1435 | // If icu_data_dir is empty here, it will load the 'minimal' data. | |
| 1424 | - if (!i18n::InitializeICUDirectory(per_process_opts->icu_data_dir)) { | ||
| 1436 | + if (!i18n::InitializeICUDirectory(per_process::cli_options->icu_data_dir)) { | ||
| 1425 | 1437 | fprintf(stderr, | |
| 1426 | 1438 | "%s: could not initialize ICU " | |
| 1427 | 1439 | "(check NODE_ICU_DATA or --icu-data-dir parameters)\n", | |
@@ -1582,7 +1594,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data, | |||
| 1582 | 1594 | std::vector<std::string> args(argv, argv + argc); | |
| 1583 | 1595 | std::vector<std::string> exec_args(exec_argv, exec_argv + exec_argc); | |
| 1584 | 1596 | Environment* env = new Environment(isolate_data, context); | |
| 1585 | - env->Start(args, exec_args, v8_is_profiling); | ||
| 1597 | + env->Start(args, exec_args, per_process::v8_is_profiling); | ||
| 1586 | 1598 | return env; | |
| 1587 | 1599 | } | |
| 1588 | 1600 | ||
@@ -1656,7 +1668,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, | |||
| 1656 | 1668 | Local<Context> context = NewContext(isolate); | |
| 1657 | 1669 | Context::Scope context_scope(context); | |
| 1658 | 1670 | Environment env(isolate_data, context); | |
| 1659 | - env.Start(args, exec_args, v8_is_profiling); | ||
| 1671 | + env.Start(args, exec_args, per_process::v8_is_profiling); | ||
| 1660 | 1672 | ||
| 1661 | 1673 | const char* path = args.size() > 1 ? args[1].c_str() : nullptr; | |
| 1662 | 1674 | StartInspector(&env, path); | |
@@ -1763,9 +1775,9 @@ inline int Start(uv_loop_t* event_loop, | |||
| 1763 | 1775 | return 12; // Signal internal error. | |
| 1764 | 1776 | ||
| 1765 | 1777 | { | |
| 1766 | - Mutex::ScopedLock scoped_lock(node_isolate_mutex); | ||
| 1767 | - CHECK_NULL(node_isolate); | ||
| 1768 | - node_isolate = isolate; | ||
| 1778 | + Mutex::ScopedLock scoped_lock(per_process::main_isolate_mutex); | ||
| 1779 | + CHECK_NULL(per_process::main_isolate); | ||
| 1780 | + per_process::main_isolate = isolate; | ||
| 1769 | 1781 | } | |
| 1770 | 1782 | ||
| 1771 | 1783 | int exit_code; | |
@@ -1790,9 +1802,9 @@ inline int Start(uv_loop_t* event_loop, | |||
| 1790 | 1802 | } | |
| 1791 | 1803 | ||
| 1792 | 1804 | { | |
| 1793 | - Mutex::ScopedLock scoped_lock(node_isolate_mutex); | ||
| 1794 | - CHECK_EQ(node_isolate, isolate); | ||
| 1795 | - node_isolate = nullptr; | ||
| 1805 | + Mutex::ScopedLock scoped_lock(per_process::main_isolate_mutex); | ||
| 1806 | + CHECK_EQ(per_process::main_isolate, isolate); | ||
| 1807 | + per_process::main_isolate = nullptr; | ||
| 1796 | 1808 | } | |
| 1797 | 1809 | ||
| 1798 | 1810 | isolate->Dispose(); | |
@@ -1840,14 +1852,14 @@ int Start(int argc, char** argv) { | |||
| 1840 | 1852 | V8::SetEntropySource(crypto::EntropySource); | |
| 1841 | 1853 | #endif // HAVE_OPENSSL | |
| 1842 | 1854 | ||
| 1843 | - InitializeV8Platform(per_process_opts->v8_thread_pool_size); | ||
| 1855 | + InitializeV8Platform(per_process::cli_options->v8_thread_pool_size); | ||
| 1844 | 1856 | V8::Initialize(); | |
| 1845 | 1857 | performance::performance_v8_start = PERFORMANCE_NOW(); | |
| 1846 | - v8_initialized = true; | ||
| 1858 | + per_process::v8_initialized = true; | ||
| 1847 | 1859 | const int exit_code = | |
| 1848 | 1860 | Start(uv_default_loop(), args, exec_args); | |
| 1849 | 1861 | v8_platform.StopTracingAgent(); | |
| 1850 | - v8_initialized = false; | ||
| 1862 | + per_process::v8_initialized = false; | ||
| 1851 | 1863 | V8::Dispose(); | |
| 1852 | 1864 | ||
| 1853 | 1865 | // uv_run cannot be called from the time before the beforeExit callback | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,9 +59,9 @@ namespace node { | |||
| 59 | 59 | namespace { | |
| 60 | 60 | ||
| 61 | 61 | inline void* BufferMalloc(size_t length) { | |
| 62 | - return per_process_opts->zero_fill_all_buffers ? | ||
| 63 | - node::UncheckedCalloc(length) : | ||
| 64 | - node::UncheckedMalloc(length); | ||
| 62 | + return per_process::cli_options->zero_fill_all_buffers ? | ||
| 63 | + node::UncheckedCalloc(length) : | ||
| 64 | + node::UncheckedMalloc(length); | ||
| 65 | 65 | } | |
| 66 | 66 | ||
| 67 | 67 | } // namespace | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ static void Initialize(Local<Object> target, | |||
| 41 | 41 | #ifdef NODE_FIPS_MODE | |
| 42 | 42 | READONLY_TRUE_PROPERTY(target, "fipsMode"); | |
| 43 | 43 | // TODO(addaleax): Use options parser variable instead. | |
| 44 | - if (per_process_opts->force_fips_crypto) | ||
| 44 | + if (per_process::cli_options->force_fips_crypto) | ||
| 45 | 45 | READONLY_TRUE_PROPERTY(target, "fipsForced"); | |
| 46 | 46 | #endif | |
| 47 | 47 | ||
@@ -69,7 +69,7 @@ static void Initialize(Local<Object> target, | |||
| 69 | 69 | ||
| 70 | 70 | // TODO(addaleax): This seems to be an unused, private API. Remove it? | |
| 71 | 71 | READONLY_STRING_PROPERTY(target, "icuDataDir", | |
| 72 | - per_process_opts->icu_data_dir); | ||
| 72 | + per_process::cli_options->icu_data_dir); | ||
| 73 | 73 | ||
| 74 | 74 | #endif // NODE_HAVE_I18N_SUPPORT | |
| 75 | 75 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1234,9 +1234,10 @@ void DefineCryptoConstants(Local<Object> target) { | |||
| 1234 | 1234 | NODE_DEFINE_STRING_CONSTANT(target, | |
| 1235 | 1235 | "defaultCoreCipherList", | |
| 1236 | 1236 | DEFAULT_CIPHER_LIST_CORE); | |
| 1237 | - NODE_DEFINE_STRING_CONSTANT(target, | ||
| 1238 | - "defaultCipherList", | ||
| 1239 | - per_process_opts->tls_cipher_list.c_str()); | ||
| 1237 | + NODE_DEFINE_STRING_CONSTANT( | ||
| 1238 | + target, | ||
| 1239 | + "defaultCipherList", | ||
| 1240 | + per_process::cli_options->tls_cipher_list.c_str()); | ||
| 1240 | 1241 | ||
| 1241 | 1242 | NODE_DEFINE_CONSTANT(target, TLS1_VERSION); | |
| 1242 | 1243 | NODE_DEFINE_CONSTANT(target, TLS1_1_VERSION); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ bool SafeGetenv(const char* key, std::string* text) { | |||
| 38 | 38 | #endif | |
| 39 | 39 | ||
| 40 | 40 | { | |
| 41 | - Mutex::ScopedLock lock(environ_mutex); | ||
| 41 | + Mutex::ScopedLock lock(per_process::env_var_mutex); | ||
| 42 | 42 | if (const char* value = getenv(key)) { | |
| 43 | 43 | *text = value; | |
| 44 | 44 | return true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -769,7 +769,7 @@ static X509_STORE* NewRootCertStore() { | |||
| 769 | 769 | if (*system_cert_path != '\0') { | |
| 770 | 770 | X509_STORE_load_locations(store, system_cert_path, nullptr); | |
| 771 | 771 | } | |
| 772 | - if (per_process_opts->ssl_openssl_cert_store) { | ||
| 772 | + if (per_process::cli_options->ssl_openssl_cert_store) { | ||
| 773 | 773 | X509_STORE_set_default_paths(store); | |
| 774 | 774 | } else { | |
| 775 | 775 | for (X509* cert : root_certs_vector) { | |
@@ -6153,16 +6153,15 @@ void InitCryptoOnce() { | |||
| 6153 | 6153 | OPENSSL_no_config(); | |
| 6154 | 6154 | ||
| 6155 | 6155 | // --openssl-config=... | |
| 6156 | - if (!per_process_opts->openssl_config.empty()) { | ||
| 6156 | + if (!per_process::cli_options->openssl_config.empty()) { | ||
| 6157 | 6157 | OPENSSL_load_builtin_modules(); | |
| 6158 | 6158 | #ifndef OPENSSL_NO_ENGINE | |
| 6159 | 6159 | ENGINE_load_builtin_engines(); | |
| 6160 | 6160 | #endif | |
| 6161 | 6161 | ERR_clear_error(); | |
| 6162 | - CONF_modules_load_file( | ||
| 6163 | - per_process_opts->openssl_config.c_str(), | ||
| 6164 | - nullptr, | ||
| 6165 | - CONF_MFLAGS_DEFAULT_SECTION); | ||
| 6162 | + CONF_modules_load_file(per_process::cli_options->openssl_config.c_str(), | ||
| 6163 | + nullptr, | ||
| 6164 | + CONF_MFLAGS_DEFAULT_SECTION); | ||
| 6166 | 6165 | int err = ERR_get_error(); | |
| 6167 | 6166 | if (0 != err) { | |
| 6168 | 6167 | fprintf(stderr, | |
@@ -6178,8 +6177,8 @@ void InitCryptoOnce() { | |||
| 6178 | 6177 | #ifdef NODE_FIPS_MODE | |
| 6179 | 6178 | /* Override FIPS settings in cnf file, if needed. */ | |
| 6180 | 6179 | unsigned long err = 0; // NOLINT(runtime/int) | |
| 6181 | - if (per_process_opts->enable_fips_crypto || | ||
| 6182 | - per_process_opts->force_fips_crypto) { | ||
| 6180 | + if (per_process::cli_options->enable_fips_crypto || | ||
| 6181 | + per_process::cli_options->force_fips_crypto) { | ||
| 6183 | 6182 | if (0 == FIPS_mode() && !FIPS_mode_set(1)) { | |
| 6184 | 6183 | err = ERR_get_error(); | |
| 6185 | 6184 | } | |
@@ -6242,7 +6241,7 @@ void GetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | |||
| 6242 | 6241 | } | |
| 6243 | 6242 | ||
| 6244 | 6243 | void SetFipsCrypto(const FunctionCallbackInfo<Value>& args) { | |
| 6245 | - CHECK(!per_process_opts->force_fips_crypto); | ||
| 6244 | + CHECK(!per_process::cli_options->force_fips_crypto); | ||
| 6246 | 6245 | Environment* env = Environment::GetCurrent(args); | |
| 6247 | 6246 | const bool enabled = FIPS_mode(); | |
| 6248 | 6247 | bool enable; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments