Skip to content

Commit

Permalink
[sw/silicon_creator] Harden SHUTDOWN_IF_ERROR
Browse files Browse the repository at this point in the history
Signed-off-by: Alphan Ulusoy <[email protected]>
  • Loading branch information
alphan committed Feb 11, 2022
1 parent 1a2c4ec commit 4810dd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions sw/device/silicon_creator/lib/shutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdint.h>
#include <stdnoreturn.h>

#include "sw/device/lib/base/hardened.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
#include "sw/device/silicon_creator/lib/error.h"
Expand All @@ -22,12 +23,13 @@ extern "C" {
*
* @param expr_ An expression which results in an rom_error_t.
*/
#define SHUTDOWN_IF_ERROR(expr_) \
do { \
rom_error_t error = (expr_); \
if (error != kErrorOk) { \
shutdown_finalize(error); \
} \
#define SHUTDOWN_IF_ERROR(expr_) \
do { \
rom_error_t error_ = expr_; \
if (launder32(error_) != kErrorOk) { \
shutdown_finalize(error_); \
} \
HARDENED_CHECK_EQ(error_, kErrorOk); \
} while (false)

/**
Expand Down
8 changes: 6 additions & 2 deletions sw/device/silicon_creator/lib/shutdown_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,12 @@ TEST_F(ShutdownTest, FlashKill) {
TEST_F(ShutdownTest, ShutdownIfErrorOk) { SHUTDOWN_IF_ERROR(kErrorOk); }

TEST_F(ShutdownTest, ShutdownIfErrorUnknown) {
ExpectFinalize(kErrorUnknown);
SHUTDOWN_IF_ERROR(kErrorUnknown);
EXPECT_DEATH(
{
ExpectFinalize(kErrorUnknown);
SHUTDOWN_IF_ERROR(kErrorUnknown);
},
"");
}

TEST_F(ShutdownTest, SoftwareEscalate) {
Expand Down

0 comments on commit 4810dd7

Please sign in to comment.