feat: port gcc to MontaukOS

This commit is contained in:
2026-07-17 15:47:45 +02:00
parent 324b18edda
commit 8e6b619b02
14 changed files with 493 additions and 19 deletions
+39 -4
View File
@@ -687,12 +687,28 @@ static void *heap_take_overflow(uint64_t needed) {
return NULL;
}
/* Next slab size for heap growth. The kernel tracks a finite number of
SYS_ALLOC records per process (MaxHeapAllocs), so growing once per
large allocation exhausts them: ld ran out mid-link and BFD reported
the resulting NULL mallocs as "file format not recognized". Doubling
slabs keep the syscall count logarithmic in total heap size. */
static uint64_t g_heap_slab = 16 * 0x1000;
static void heap_grow(uint64_t bytes) {
uint64_t pages = (bytes + 0xFFF) / 0x1000;
if (pages < 4) pages = 4;
void *mem = (void *)_zos_syscall1(SYS_ALLOC, (long)(pages * 0x1000));
uint64_t want = (bytes + 0xFFF) & ~0xFFFULL;
if (want < 0x4000) want = 0x4000;
uint64_t slab = (want > g_heap_slab) ? want : g_heap_slab;
if (g_heap_slab < 4 * 1024 * 1024) g_heap_slab *= 2;
void *mem = (void *)_zos_syscall1(SYS_ALLOC, (long)slab);
if (mem == NULL && slab > want) {
/* Big slab refused (low memory): retry with the exact need. */
slab = want;
mem = (void *)_zos_syscall1(SYS_ALLOC, (long)slab);
}
if (mem != NULL)
heap_insert_overflow(mem, pages * 0x1000);
heap_insert_overflow(mem, slab);
}
/* Refill a small-block bucket from overflow */
@@ -1504,6 +1520,25 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap) {
}
break;
}
case 'o': {
unsigned long val;
if (is_long >= 1) val = va_arg(ap, unsigned long);
else val = va_arg(ap, unsigned int);
/* %#o: force a leading zero digit */
if (alt && val != 0 && precision < 0) {
_pf_putc(&st, '0');
if (width > 0) width--;
}
if (left_align) {
size_t before = st.pos;
_pf_putnum(&st, val, 8, 0, 0, pad, 0, precision);
size_t len = st.pos - before;
for (size_t w = len; (int)w < width; w++) _pf_putc(&st, ' ');
} else {
_pf_putnum(&st, val, 8, 0, width, pad, 0, precision);
}
break;
}
case 'p': {
void *val = va_arg(ap, void *);
_pf_puts(&st, "0x");
Binary file not shown.