From 9319287fcd60fb8044a297c6099cdc4ba8a4b317 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 13 Sep 2022 11:13:32 -0700 Subject: [PATCH] c++ bootstrap hardening --- .efrocachemap | 40 +++++----- CHANGELOG.md | 2 +- assets/src/ba_data/python/ba/_bootstrap.py | 2 +- src/ballistica/ballistica.cc | 85 +++++++++++++++------- 4 files changed, 79 insertions(+), 50 deletions(-) diff --git a/.efrocachemap b/.efrocachemap index 82e6f6f8..81c70975 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -3995,26 +3995,26 @@ "assets/src/ba_data/python/ba/_generated/__init__.py": "https://files.ballistica.net/cache/ba1/ee/e8/cad05aa531c7faf7ff7b96db7f6e", "assets/src/ba_data/python/ba/_generated/enums.py": "https://files.ballistica.net/cache/ba1/b2/e5/0ee0561e16257a32830645239f34", "ballisticacore-windows/Generic/BallisticaCore.ico": "https://files.ballistica.net/cache/ba1/89/c0/e32c7d2a35dc9aef57cc73b0911a", - "build/prefab/full/linux_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/ca/c4/9784ffa7a202da7e851c447dc69a", - "build/prefab/full/linux_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/f0/15/1ffcc9804e84eaa6a652be53cbbd", - "build/prefab/full/linux_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ac/45/ff0681bcf7d1c5ac2c191d288434", - "build/prefab/full/linux_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/7f/27/4a4158050c3d77a7021e12bb9d20", - "build/prefab/full/linux_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/f1/c9/048c9c9267b456ff7e5610624fbd", - "build/prefab/full/linux_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/ad/fe/6afe3275a46a1384c348ee3917bc", - "build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/de/e3/69d0a6f6cbfba5a6e0d74c0442ba", - "build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/06/b6/824ee73b255e99093aeae719e2e4", - "build/prefab/full/mac_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/c7/0e/3dd207020a393e2fff196918e986", - "build/prefab/full/mac_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/7b/d3/3698352ea276344dd12e969da09e", - "build/prefab/full/mac_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ff/b3/5e9acbef286f6738de3023011556", - "build/prefab/full/mac_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ab/ab/50ea4865929b418bf25dac3f475d", - "build/prefab/full/mac_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/e2/9f/aae9e3204175fce33a75d486008a", - "build/prefab/full/mac_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/98/89/63eec19c696e364e349b0d200e91", - "build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/5b/75/bc745b50536aade78db0150d9d9e", - "build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/94/06/ba7c0d3e3d3e9d02594871687ec9", - "build/prefab/full/windows_x86_gui/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/a2/ea/87883b1f4063980a1a40a112f9ce", - "build/prefab/full/windows_x86_gui/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/da/0b/16a433cafa1e2a7f87caf83409bf", - "build/prefab/full/windows_x86_server/debug/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/3a/4c/8aa877e66c3a7ad25dbd0e075ef8", - "build/prefab/full/windows_x86_server/release/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/83/07/b36ff25c01d4790b4758e0c86e68", + "build/prefab/full/linux_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/84/d0/74f2b20adc517beeb0efafb4b4de", + "build/prefab/full/linux_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/60/85/8e8cbeee10bf0c4f5b38792cd972", + "build/prefab/full/linux_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/84/9e/70d571aa9d9c869ae544e81ceb9c", + "build/prefab/full/linux_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/61/4b/9cb4a70e2c5fd5046a2a0aa1d011", + "build/prefab/full/linux_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/c4/9b/24e583b9bf7bcb406a544f5d9d90", + "build/prefab/full/linux_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/d8/4b/b73ae2c2e711699daca03bb46fbc", + "build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/41/d1/b665246e68c64f90819807d6d528", + "build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/a4/81/daa5716db4fe65ae8ef4700af5a1", + "build/prefab/full/mac_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/47/e5/eabd47ace227af9fb05bdaeea7aa", + "build/prefab/full/mac_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/69/8b/c91d3562ac890e40aafb9f35cf5e", + "build/prefab/full/mac_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/16/b1/45dcdcd101c5b293f78913f62a0e", + "build/prefab/full/mac_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/81/bb/3fba8cad9c1ea3d01199b32385e7", + "build/prefab/full/mac_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/f3/0f/7c6074e1c2165b976e4a030d3876", + "build/prefab/full/mac_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/02/9a/c31ef4286904f9970519f42f0644", + "build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/84/62/f0fba929db90c96deac3d73a135b", + "build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/95/72/64f86aba6b2219f49bc5f89f2189", + "build/prefab/full/windows_x86_gui/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/a8/a4/237ffde4b291ffc0cfb795863c1b", + "build/prefab/full/windows_x86_gui/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/3f/58/877ef1ec2c1e7a4c405574ebc544", + "build/prefab/full/windows_x86_server/debug/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/37/7e/bdc6a0ba2c95bfecc16911a80983", + "build/prefab/full/windows_x86_server/release/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/f5/5c/e70d827e538c18b914f9d1cc52af", "build/prefab/lib/linux_arm64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/4b/02/e1d6afd343ce32d53c134c5fc4e7", "build/prefab/lib/linux_arm64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/ed/18/45e61446f5f7e02624fb87fb8c97", "build/prefab/lib/linux_arm64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/cf/46/393131611fa1395fd9c173d8426f", diff --git a/CHANGELOG.md b/CHANGELOG.md index bf01925f..07af68eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### 1.7.7 (build 20840, api 7, 2022-09-13) +### 1.7.7 (build 20842, api 7, 2022-09-13) - Added `ba.app.meta.load_exported_classes()` for loading classes discovered by the meta subsystem cleanly in a background thread. - Improved logging of missing playlist game types. - Some ba.Lstr functionality can now be used in background threads. diff --git a/assets/src/ba_data/python/ba/_bootstrap.py b/assets/src/ba_data/python/ba/_bootstrap.py index 8bbf492e..5dafc7f5 100644 --- a/assets/src/ba_data/python/ba/_bootstrap.py +++ b/assets/src/ba_data/python/ba/_bootstrap.py @@ -37,7 +37,7 @@ def bootstrap() -> None: # Give a soft warning if we're being used with a different binary # version than we expect. - expected_build = 20840 + expected_build = 20842 running_build: int = env['build_number'] if running_build != expected_build: print( diff --git a/src/ballistica/ballistica.cc b/src/ballistica/ballistica.cc index 5a4c81db..355a3e30 100644 --- a/src/ballistica/ballistica.cc +++ b/src/ballistica/ballistica.cc @@ -32,7 +32,7 @@ namespace ballistica { // These are set automatically via script; don't modify them here. -const int kAppBuildNumber = 20840; +const int kAppBuildNumber = 20842; const char* kAppVersion = "1.7.7"; // Our standalone globals. @@ -86,37 +86,66 @@ auto BallisticaMain(int argc, char** argv) -> int { // avoid any logic that accesses other globals since they may // not yet exist. + // Minimal globals we must assign immediately as they are needed + // during construction of the others. g_platform = Platform::Create(); g_app = new App(argc, argv); g_app_internal = CreateAppInternal(); g_main_thread = new Thread(ThreadTag::kMain, ThreadSource::kWrapMain); - g_app_flavor = g_platform->CreateAppFlavor(); - g_python = Python::Create(); - g_graphics = g_platform->CreateGraphics(); - g_graphics_server = new GraphicsServer(); - g_audio = new Audio(); - g_audio_server = new AudioServer(); - g_context = new Context(nullptr); - g_text_graphics = new TextGraphics(); - g_app_config = new AppConfig(); - g_v1_account = new V1Account(); - g_utils = new Utils(); - g_assets = new Assets(); - g_assets_server = new AssetsServer(); - g_ui = Object::NewUnmanaged(); - g_networking = new Networking(); - g_network_reader = new NetworkReader(); - g_network_writer = new NetworkWriter(); - g_input = new Input(); - g_logic = new Logic(); - g_scene_v1 = new SceneV1(); - if (!HeadlessMode()) { - g_bg_dynamics = new BGDynamics(); - g_bg_dynamics_server = new BGDynamicsServer(); - } - if (g_buildconfig.enable_stdio_console()) { - g_stdio_console = new StdioConsole(); - } + + // For everything else, we hold off until the end to actually assign + // them to their globals. This keeps us honest and catches any stray + // inter-global access that we might accidentally include in a + // constructor. + auto* app_flavor = g_platform->CreateAppFlavor(); + auto* python = Python::Create(); + auto* graphics = g_platform->CreateGraphics(); + auto* graphics_server = new GraphicsServer(); + auto* audio = new Audio(); + auto* audio_server = new AudioServer(); + auto* context = new Context(nullptr); + auto* text_graphics = new TextGraphics(); + auto* app_config = new AppConfig(); + auto* v1_account = new V1Account(); + auto* utils = new Utils(); + auto* assets = new Assets(); + auto* assets_server = new AssetsServer(); + auto* ui = Object::NewUnmanaged(); + auto* networking = new Networking(); + auto* network_reader = new NetworkReader(); + auto* network_writer = new NetworkWriter(); + auto* input = new Input(); + auto* logic = new Logic(); + auto* scene_v1 = new SceneV1(); + auto* bg_dynamics = HeadlessMode() ? nullptr : new BGDynamics; + auto* bg_dynamics_server = HeadlessMode() ? nullptr : new BGDynamicsServer; + auto* stdio_console = + g_buildconfig.enable_stdio_console() ? new StdioConsole() : nullptr; + + g_app_flavor = app_flavor; + g_python = python; + g_graphics = graphics; + g_graphics_server = graphics_server; + g_audio = audio; + g_audio_server = audio_server; + g_context = context; + g_text_graphics = text_graphics; + g_app_config = app_config; + g_v1_account = v1_account; + g_utils = utils; + g_assets = assets; + g_assets_server = assets_server; + g_ui = ui; + g_networking = networking; + g_network_reader = network_reader; + g_network_writer = network_writer; + g_input = input; + g_logic = logic; + g_scene_v1 = scene_v1; + g_bg_dynamics = bg_dynamics; + g_bg_dynamics_server = bg_dynamics_server; + g_stdio_console = stdio_console; + g_app->is_bootstrapped = true; // -------------------------------------------------------------------------