Skip to content

Commit 77e09ef

Browse files
committed
[heartbleed] Add the blue screen to the cheri demo
1 parent 60e3c8f commit 77e09ef

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

examples/heartbleed/cheriot/heartbleed.cc

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using namespace CHERI;
1616
using namespace sonata::lcd;
17+
SonataLcd *lcd = nullptr;
1718

1819
constexpr bool DebugDemo = true;
1920
constexpr uint32_t LengthScrollMillis = 150u;
@@ -282,12 +283,41 @@ void network_send(void *handle, const char *package, size_t len)
282283
}
283284
}
284285

286+
/**
287+
* @brief Handles any CHERI Capability Violation errors. If the error was a
288+
* Bounds or Tag violation it assumes it is because of the incorrect memory
289+
* access in SnakeGame::check_if_colliding and therefore it recovers the program
290+
* and ends the game. Otherwise, this force unwinds and ends the program.
291+
*/
292+
extern "C" ErrorRecoveryBehaviour
293+
compartment_error_handler(ErrorState *frame, size_t mcause, size_t mtval)
294+
{
295+
lcd->fill_rect({0, 0, 160, 128}, Color::Blue);
296+
lcd->draw_str(
297+
{5, 30}, "Oops ;-(", Color::Blue, Color::White, Font::LucidaConsole_12pt);
298+
lcd->draw_str({30, 80},
299+
"Protected by",
300+
Color::Blue,
301+
Color::White,
302+
Font::LucidaConsole_10pt);
303+
lcd->draw_str(
304+
{50, 95}, "CHERIoT", Color::Blue, Color::White, Font::LucidaConsole_10pt);
305+
306+
Debug::log(
307+
"Unexpected CHERI Capability violation encountered. Stopping...");
308+
while (1)
309+
{
310+
asm("wfi");
311+
}
312+
return ErrorRecoveryBehaviour::ForceUnwind;
313+
}
314+
285315
[[noreturn]] void __cheri_compartment("heartbleed") entry()
286316
{
287317
// Initialise the LCD driver and calculate display information
288-
SonataLcd *lcd = new SonataLcd();
289-
Size displaySize = lcd->resolution();
290-
Point centre = {displaySize.width / 2, displaySize.height / 2};
318+
lcd = new SonataLcd();
319+
Size displaySize = lcd->resolution();
320+
Point centre = {displaySize.width / 2, displaySize.height / 2};
291321
lcd->clean(BackgroundColor);
292322
size_t w_boarder = 2;
293323
lcd->fill_rect({w_boarder, 50, 160 - w_boarder, 128}, Color::Grey);

0 commit comments

Comments
 (0)