mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
- Implement modern freestanding C++17 containers (Vector<T>, UniquePtr<T>, String) in kernel/cpp/cpp_containers.hpp - Implement object-oriented Device driver model (Device, BlockDevice, CharDevice, VirtualRamDiskDevice, VirtualNullDevice, VirtualZeroDevice, DeviceManager) in kernel/cpp/cpp_device.hpp and kernel/cpp/cpp_device.cpp - Add C++ kernel performance microbenchmark suite in kernel/cpp/cpp_bench.cpp - Export C-FFI bridges and add cross-architecture fallbacks in kernel/cpp/cpp_fallback.c and include/kernel/cpp_kernel.h - Add LazyBox applets: 'cppdevs' and 'cppbench' - Update README.md documentation and command matrix
86 lines
1.9 KiB
C++
86 lines
1.9 KiB
C++
// Freestanding C++ Runtime for SUB-OS Kernel
|
|
// Provides operator new/delete, pure virtual error handling, and global constructor calling
|
|
|
|
#include <kernel/cpp_kernel.h>
|
|
|
|
extern "C" {
|
|
#include <mm/kmalloc.h>
|
|
#include <kernel/printk.h>
|
|
#include <kernel/panic.h>
|
|
#include <lib/string.h>
|
|
|
|
void* __dso_handle = nullptr;
|
|
|
|
typedef void (*ctor_fn_t)(void);
|
|
extern ctor_fn_t __init_array_start[];
|
|
extern ctor_fn_t __init_array_end[];
|
|
|
|
void cpp_call_global_constructors(void) {
|
|
if (+__init_array_end <= +__init_array_start) return;
|
|
size_t count = __init_array_end - __init_array_start;
|
|
for (size_t i = 0; i < count; i++) {
|
|
if (__init_array_start[i]) {
|
|
__init_array_start[i]();
|
|
}
|
|
}
|
|
}
|
|
|
|
int __cxa_atexit(void (*/*destructor*/)(void*), void* /*arg*/, void* /*dso*/) {
|
|
return 0; // Kernel runs indefinitely until shutdown
|
|
}
|
|
|
|
int atexit(void (*/*func*/)(void)) {
|
|
return 0;
|
|
}
|
|
|
|
void __cxa_pure_virtual(void) {
|
|
panic("C++ Pure Virtual Function Called");
|
|
}
|
|
}
|
|
|
|
// Freestanding Dynamic Memory Allocation Operators
|
|
void* operator new(size_t size) {
|
|
if (size == 0) size = 1;
|
|
void* ptr = kmalloc(size);
|
|
return ptr;
|
|
}
|
|
|
|
void* operator new[](size_t size) {
|
|
if (size == 0) size = 1;
|
|
void* ptr = kmalloc(size);
|
|
return ptr;
|
|
}
|
|
|
|
// Placement new
|
|
void* operator new(size_t /*size*/, void* ptr) noexcept {
|
|
return ptr;
|
|
}
|
|
|
|
void* operator new[](size_t /*size*/, void* ptr) noexcept {
|
|
return ptr;
|
|
}
|
|
|
|
void operator delete(void* ptr) noexcept {
|
|
if (ptr) {
|
|
kfree(ptr);
|
|
}
|
|
}
|
|
|
|
void operator delete[](void* ptr) noexcept {
|
|
if (ptr) {
|
|
kfree(ptr);
|
|
}
|
|
}
|
|
|
|
void operator delete(void* ptr, size_t /*size*/) noexcept {
|
|
if (ptr) {
|
|
kfree(ptr);
|
|
}
|
|
}
|
|
|
|
void operator delete[](void* ptr, size_t /*size*/) noexcept {
|
|
if (ptr) {
|
|
kfree(ptr);
|
|
}
|
|
}
|