ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_sbrk_trap.c
Go to the documentation of this file.
1
26
27#include "ra8_sbrk_trap.h"
28
29#include <stddef.h> // ra8-keep-include: `ptrdiff_t` used directly
30
31#include "ra8_error_handler.h"
32
33/* The newlib-nano heap allocator calls ``_sbrk`` by that exact name,
34 * so we must use a reserved identifier here. clang-tidy's
35 * bugprone-reserved-identifier / cert-dcl51-cpp complain correctly
36 * but we override because the name is fixed by newlib. */
37
38/* No coverage-exclusion marker here: the trap body is exercised
39 * deterministically by the host white-box test
40 * tests/hal/src/test_ra8_sbrk_trap_cov.c, which renames `_sbrk` to `_sbrk_cov`, mocks
41 * the fatal-error sink, and proves the function never returns. On a
42 * correctly-built firmware image this stays unreached at run time (glibc
43 * malloc on the host resolves its own break), but the three lines are
44 * covered on host, so no marker is needed. */
45void* _sbrk(ptrdiff_t incr)
46{
47 (void)incr;
48 ra8_fatal_error("SBRK", "_sbrk called -- firmware is heap-free", 0U);
49 __builtin_unreachable();
50}
Centralised fatal-error sink.
void ra8_fatal_error(const char *tag, const char *message, uint32_t err)
Report a fatal error, log it, and halt.
void * _sbrk(ptrdiff_t incr)
Trap that replaces newlib's heap-extension syscall.
The newlib heap syscall, replaced by a halting trap.