feat(headers): stddef/stdint/stdbool/limits/float/assert + features wiring

This commit is contained in:
2026-09-03 17:34:16 -04:00
parent ce517ad0d6
commit dec1017527
22 changed files with 2076 additions and 2 deletions
+80
View File
@@ -0,0 +1,80 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "syscall.h"
/*
* The failing-assertion sink behind <assert.h>.
*
* Writes the standard-shaped diagnostic to fd 2 through the raw syscall
* layer, then traps. No abort(), exit() or stdio: those land in later todos
* and an assertion failure must be able to fire from a half-initialized
* runtime. __builtin_trap() terminates with SIGILL, which the assert QA
* harness expects (the standard only requires abnormal termination).
*
* Not declared hidden, unlike the other src/internal helpers: <assert.h>
* declares this symbol to consumers, so it is part of the public ABI surface
* and must resolve across the shared-library boundary.
*/
/* Convert v to decimal digits at p; returns the next free position. */
static char *
append_dec(char *p, int v)
{
char tmp[12];
int i = 0;
if (v == 0)
{
*p++ = '0';
return p;
}
while (v > 0)
{
tmp[i++] = (char)('0' + v % 10);
v /= 10;
}
while (i > 0)
{
*p++ = tmp[--i];
}
return p;
}
/* Append the string s at p; returns the next free position. */
static char *
append_str(char *p, const char *s)
{
while (*s != '\0')
{
*p++ = *s++;
}
return p;
}
/*
* The __vlibc_assert_fail name sits in the implementation-reserved namespace
* by design (it is the libc's private assert plumbing), so the
* reserved-identifier check is waived.
*/
__attribute__((noreturn)) void
__vlibc_assert_fail(const char *expr, const char *file, int line,
const char *func) // NOLINT(bugprone-reserved-identifier)
{
char msg[384];
char *p = msg;
p = append_str(p, "Assertion failed: ");
p = append_str(p, expr);
p = append_str(p, " (file ");
p = append_str(p, file);
p = append_str(p, ": line ");
p = append_dec(p, line);
p = append_str(p, ", func ");
p = append_str(p, func);
p = append_str(p, ")\n");
(void)__syscall3(SYS_write, 2, (long)msg, (long)(p - msg));
__builtin_trap();
}