mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
- Implement flicker-free atomic double-buffered frame rendering and sub-tick input polling in userland/lazybox/snake.c - Add multi-input support (PS/2 keyboard scancodes and serial ANSI arrow escape sequences) - Add sound effects (food beep, game over chime) and live speed scaling (+/- keys, P to pause) - Add POSIX /dev/shm shared memory subsystem in ipc/shm_posix.c and include/ipc/shm_posix.h - Add DNS resolver cache with TTL tracking in net/ipv4/dns_cache.c and include/net/dns_cache.h - Add audio tone and jingle synthesizer in sound/beep.c and include/sound/beep.h - Add %o octal formatting support in lib/vsprintf.c - Add LazyBox applets: 'shm', 'dnscache', and 'beep'
82 lines
1.8 KiB
C++
82 lines
1.8 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
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|