feat: port gcc to MontaukOS
This commit is contained in:
+10
-2
@@ -424,10 +424,18 @@ ifneq ($(wildcard ../toolchain/native-gcc/sdk/bin/gcc),)
|
||||
mkdir -p $(BINDIR)/tmp
|
||||
printf 'scratch space for compiler intermediates\n' > $(BINDIR)/tmp/readme.txt
|
||||
else
|
||||
@echo "devkit: toolchain/native-gcc/ not built; skipping native GCC"
|
||||
@echo "======================================================================"
|
||||
@echo "devkit: WARNING: toolchain/native-gcc/ not built."
|
||||
@echo " The image will ship WITHOUT the native GCC (g++, cc1plus, ...)."
|
||||
@echo " Run 'make sdk' from the repo root to build the full Montauk SDK."
|
||||
@echo "======================================================================"
|
||||
endif
|
||||
else
|
||||
@echo "devkit: toolchain/native/ not built; skipping native dev tools"
|
||||
@echo "======================================================================"
|
||||
@echo "devkit: WARNING: toolchain/native/ not built."
|
||||
@echo " The image will ship WITHOUT the Montauk SDK (0:/sdk dev tools)."
|
||||
@echo " Run 'make sdk' from the repo root to build it (one-time, long)."
|
||||
@echo "======================================================================"
|
||||
endif
|
||||
|
||||
clean:
|
||||
|
||||
@@ -123,13 +123,28 @@ namespace heap_detail {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline bool grow(uint64_t bytes) {
|
||||
uint64_t pages = (bytes + 0xFFF) / 0x1000;
|
||||
if (pages < 4) pages = 4;
|
||||
// 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 under allocation-heavy loads
|
||||
// (the native ld ran out mid-link). Doubling slabs keep the syscall
|
||||
// count logarithmic in total heap size.
|
||||
inline uint64_t g_grow_slab = 16 * 0x1000;
|
||||
|
||||
void* mem = montauk::alloc(pages * 0x1000);
|
||||
static inline bool grow(uint64_t bytes) {
|
||||
uint64_t want = (bytes + 0xFFF) & ~0xFFFULL;
|
||||
if (want < 0x4000) want = 0x4000;
|
||||
|
||||
uint64_t slab = (want > g_grow_slab) ? want : g_grow_slab;
|
||||
if (g_grow_slab < 4 * 1024 * 1024) g_grow_slab *= 2;
|
||||
|
||||
void* mem = montauk::alloc(slab);
|
||||
if (mem == nullptr && slab > want) {
|
||||
// Big slab refused (low memory): retry with the exact need.
|
||||
slab = want;
|
||||
mem = montauk::alloc(slab);
|
||||
}
|
||||
if (mem == nullptr) return false;
|
||||
insert_overflow(mem, pages * 0x1000);
|
||||
insert_overflow(mem, slab);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
Reference in New Issue
Block a user