40 lines
1003 B
C++
40 lines
1003 B
C++
/*
|
|
* heap.h
|
|
* Unified userspace heap API for MontaukOS programs
|
|
* Copyright (c) 2025-2026 Daniel Hammer
|
|
*/
|
|
|
|
#pragma once
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
// The allocator lives in libc. Keeping these declarations here lets
|
|
// freestanding C++ programs use the Montauk API without pulling in all of
|
|
// <stdlib.h>, while ensuring C, C++, and libraries share one heap.
|
|
extern "C" {
|
|
void* malloc(std::size_t size);
|
|
void free(void* ptr);
|
|
void* realloc(void* ptr, std::size_t size);
|
|
void* calloc(std::size_t count, std::size_t size);
|
|
}
|
|
|
|
namespace montauk {
|
|
|
|
inline void* malloc(uint64_t size) {
|
|
return ::malloc((std::size_t)size);
|
|
}
|
|
|
|
inline void mfree(void* ptr) {
|
|
::free(ptr);
|
|
}
|
|
|
|
inline void* realloc(void* ptr, uint64_t size) {
|
|
return ::realloc(ptr, (std::size_t)size);
|
|
}
|
|
|
|
inline void* calloc(uint64_t count, uint64_t size) {
|
|
return ::calloc((std::size_t)count, (std::size_t)size);
|
|
}
|
|
|
|
} // namespace montauk
|