|
14 | 14 |
|
15 | 15 | using namespace CHERI; |
16 | 16 | using namespace sonata::lcd; |
| 17 | +SonataLcd *lcd = nullptr; |
17 | 18 |
|
18 | 19 | constexpr bool DebugDemo = true; |
19 | 20 | constexpr uint32_t LengthScrollMillis = 150u; |
@@ -282,12 +283,41 @@ void network_send(void *handle, const char *package, size_t len) |
282 | 283 | } |
283 | 284 | } |
284 | 285 |
|
| 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 | + |
285 | 315 | [[noreturn]] void __cheri_compartment("heartbleed") entry() |
286 | 316 | { |
287 | 317 | // 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}; |
291 | 321 | lcd->clean(BackgroundColor); |
292 | 322 | size_t w_boarder = 2; |
293 | 323 | lcd->fill_rect({w_boarder, 50, 160 - w_boarder, 128}, Color::Grey); |
|
0 commit comments