mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat: Add freestanding C++17 OOP kernel subsystem and interactive Snake Game
- Add freestanding C++17 runtime with operator new/delete, pure virtual handlers, and global constructor execution in kernel/cpp/cxx_runtime.cpp - Implement C++ Object-Oriented telemetry and hardware services with polymorphism in kernel/cpp/cpp_module.cpp and include/kernel/cpp_kernel.h - Add interactive ANSI Snake Game in userland/lazybox/snake.c with real-time keyboard control and automated simulation mode - Initialize C++ subsystem during kernel boot step [8/14] in kernel/main.c - Add LazyBox applets: 'snake', 'cppinfo', and 'cpptest'
This commit is contained in:
1 parent
f3b47f9d22
commit
6eaf9397a2
10 files changed
+636
-6
No files matched your search
@@ -0,0 +1,81 @@
|
||||
// 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
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user