From c19ee8b0fef0ab21361e627a8e884fab8799df7b Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 8 Mar 2024 00:26:53 -0800 Subject: [PATCH] [wpiutil, hal] Crash on failure for SetupNowRio() and wpi::Now() when not configured (#6417) This is an unrecoverable condition, so always terminate. --- hal/src/main/native/athena/HAL.cpp | 8 ++++++++ wpiutil/src/main/native/cpp/timestamp.cpp | 17 ++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index 33dcc85d15..2c57c9cea9 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -594,6 +594,14 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) { }); if (!SetupNowRio()) { + fmt::print(stderr, + "Failed to run SetupNowRio(). This is a fatal error. The " + "process is being terminated.\n"); + std::fflush(stderr); + // Attempt to force a segfault to get a better java log + *reinterpret_cast(0) = 0; + // If that fails, terminate + std::terminate(); return false; } diff --git a/wpiutil/src/main/native/cpp/timestamp.cpp b/wpiutil/src/main/native/cpp/timestamp.cpp index cc7e2e0f47..47ac70fe59 100644 --- a/wpiutil/src/main/native/cpp/timestamp.cpp +++ b/wpiutil/src/main/native/cpp/timestamp.cpp @@ -273,15 +273,14 @@ uint64_t wpi::Now() { if (nowUseDefaultOnFailure.test()) { return timestamp() - offset_val; } else { - static uint64_t last = 0; - uint64_t cur = timestamp(); - if ((cur - last) > 100000) { - last = cur; - fmt::print(stderr, - "FPGA not yet configured in wpi::Now(). Time will not be " - "correct.\n"); - std::fflush(stderr); - } + fmt::print(stderr, + "FPGA not yet configured in wpi::Now(). This is a fatal " + "error. The process is being terminated.\n"); + std::fflush(stderr); + // Attempt to force a segfault to get a better java log + *reinterpret_cast(0) = 0; + // If that fails, terminate + std::terminate(); return 1; } }