mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat: Add SLAB allocator, Ramdisk, Kernel Namespaces, Event Tracing, NetFilter Firewall, 8-Bit Melodies, and Shell Scripting (sh)
This commit is contained in:
1 parent
9f9a19bab0
commit
2f1f785cee
17 files changed
+1021
-115
No files matched your search
@@ -0,0 +1,12 @@
|
||||
#ifndef _DRIVERS_RAMDISK_H
|
||||
#define _DRIVERS_RAMDISK_H
|
||||
|
||||
#include <block/block.h>
|
||||
|
||||
#define RAMDISK_SIZE (4 * 1024 * 1024) // 4 MB Ramdisk
|
||||
#define RAMDISK_SECTOR_SIZE 512
|
||||
|
||||
void ramdisk_init(void);
|
||||
block_device_t* ramdisk_get_block_device(void);
|
||||
|
||||
#endif // _DRIVERS_RAMDISK_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef _KERNEL_NAMESPACE_H
|
||||
#define _KERNEL_NAMESPACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define CLONE_NEWPID 0x20000000
|
||||
#define CLONE_NEWUTS 0x04000000
|
||||
#define CLONE_NEWIPC 0x08000000
|
||||
#define CLONE_NEWNET 0x40000000
|
||||
#define CLONE_NEWNS 0x00020000
|
||||
|
||||
#define MAX_NAMESPACES 16
|
||||
|
||||
typedef struct uts_namespace {
|
||||
char hostname[64];
|
||||
char domainname[64];
|
||||
} uts_namespace_t;
|
||||
|
||||
typedef struct nsproxy {
|
||||
uint32_t id;
|
||||
char name[32];
|
||||
uts_namespace_t uts;
|
||||
uint32_t pid_offset;
|
||||
bool isolated_mounts;
|
||||
bool in_use;
|
||||
} nsproxy_t;
|
||||
|
||||
void namespace_init(void);
|
||||
nsproxy_t* namespace_create(const char* name, uint32_t flags);
|
||||
nsproxy_t* namespace_get_current(void);
|
||||
int namespace_switch(uint32_t id);
|
||||
size_t namespace_get_count(void);
|
||||
const nsproxy_t* namespace_get(size_t index);
|
||||
|
||||
#endif // _KERNEL_NAMESPACE_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef _KERNEL_TRACE_H
|
||||
#define _KERNEL_TRACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TRACE_BUFFER_SIZE 256
|
||||
#define TRACE_MSG_LEN 96
|
||||
|
||||
typedef enum {
|
||||
TRACE_CAT_SYS = 0,
|
||||
TRACE_CAT_IRQ,
|
||||
TRACE_CAT_SCHED,
|
||||
TRACE_CAT_MM,
|
||||
TRACE_CAT_NET,
|
||||
TRACE_CAT_FS,
|
||||
TRACE_CAT_MAX
|
||||
} trace_category_t;
|
||||
|
||||
typedef struct trace_entry {
|
||||
uint64_t timestamp;
|
||||
uint32_t cpu_id;
|
||||
uint32_t pid;
|
||||
trace_category_t category;
|
||||
char message[TRACE_MSG_LEN];
|
||||
} trace_entry_t;
|
||||
|
||||
void trace_init(void);
|
||||
void trace_record(trace_category_t cat, const char* msg);
|
||||
void trace_enable(bool enable);
|
||||
bool trace_is_enabled(void);
|
||||
void trace_clear(void);
|
||||
size_t trace_get_count(void);
|
||||
const trace_entry_t* trace_get_entry(size_t index);
|
||||
|
||||
#endif // _KERNEL_TRACE_H
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef _MM_SLAB_H
|
||||
#define _MM_SLAB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SLAB_NAME_MAX 32
|
||||
#define SLAB_MAX_CACHES 32
|
||||
|
||||
typedef struct kmem_cache kmem_cache_t;
|
||||
|
||||
typedef void (*kmem_ctor_fn_t)(void* obj);
|
||||
typedef void (*kmem_dtor_fn_t)(void* obj);
|
||||
|
||||
typedef struct kmem_slab {
|
||||
void* memory;
|
||||
uint32_t total_objects;
|
||||
uint32_t free_objects;
|
||||
uint32_t* freelist;
|
||||
uint32_t freelist_head;
|
||||
struct kmem_slab* next;
|
||||
} kmem_slab_t;
|
||||
|
||||
struct kmem_cache {
|
||||
char name[SLAB_NAME_MAX];
|
||||
size_t object_size;
|
||||
size_t alignment;
|
||||
size_t objects_per_slab;
|
||||
uint32_t active_objects;
|
||||
uint32_t total_slabs;
|
||||
kmem_ctor_fn_t ctor;
|
||||
kmem_dtor_fn_t dtor;
|
||||
kmem_slab_t* slabs_partial;
|
||||
kmem_slab_t* slabs_full;
|
||||
kmem_slab_t* slabs_empty;
|
||||
bool in_use;
|
||||
};
|
||||
|
||||
void slab_init(void);
|
||||
kmem_cache_t* kmem_cache_create(const char* name, size_t size, size_t align, kmem_ctor_fn_t ctor, kmem_dtor_fn_t dtor);
|
||||
void* kmem_cache_alloc(kmem_cache_t* cache);
|
||||
void kmem_cache_free(kmem_cache_t* cache, void* obj);
|
||||
int kmem_cache_destroy(kmem_cache_t* cache);
|
||||
|
||||
size_t slab_get_cache_count(void);
|
||||
const kmem_cache_t* slab_get_cache(size_t index);
|
||||
|
||||
#endif // _MM_SLAB_H
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef _NET_FILTER_H
|
||||
#define _NET_FILTER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FILTER_MAX_RULES 32
|
||||
|
||||
typedef enum {
|
||||
FILTER_ACTION_ACCEPT = 0,
|
||||
FILTER_ACTION_DROP,
|
||||
FILTER_ACTION_REJECT,
|
||||
FILTER_ACTION_LOG
|
||||
} filter_action_t;
|
||||
|
||||
typedef enum {
|
||||
FILTER_HOOK_PRE_ROUTING = 0,
|
||||
FILTER_HOOK_LOCAL_IN,
|
||||
FILTER_HOOK_FORWARD,
|
||||
FILTER_HOOK_LOCAL_OUT,
|
||||
FILTER_HOOK_POST_ROUTING,
|
||||
FILTER_HOOK_MAX
|
||||
} filter_hook_t;
|
||||
|
||||
typedef struct filter_rule {
|
||||
uint32_t id;
|
||||
filter_hook_t hook;
|
||||
uint32_t src_ip;
|
||||
uint32_t src_mask;
|
||||
uint32_t dst_ip;
|
||||
uint32_t dst_mask;
|
||||
uint8_t protocol;
|
||||
uint16_t src_port;
|
||||
uint16_t dst_port;
|
||||
filter_action_t action;
|
||||
uint64_t packet_count;
|
||||
uint64_t byte_count;
|
||||
char comment[32];
|
||||
bool in_use;
|
||||
} filter_rule_t;
|
||||
|
||||
void filter_init(void);
|
||||
int filter_add_rule(filter_hook_t hook, uint8_t proto, uint16_t dst_port, filter_action_t action, const char* comment);
|
||||
int filter_delete_rule(uint32_t rule_id);
|
||||
filter_action_t filter_evaluate(filter_hook_t hook, uint8_t proto, uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port, size_t len);
|
||||
|
||||
size_t filter_get_rule_count(void);
|
||||
const filter_rule_t* filter_get_rule(size_t index);
|
||||
|
||||
#endif // _NET_FILTER_H
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef _SOUND_MELODY_H
|
||||
#define _SOUND_MELODY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t freq;
|
||||
uint32_t duration_ms;
|
||||
} note_t;
|
||||
|
||||
void melody_init(void);
|
||||
void melody_play_startup(void);
|
||||
void melody_play_tetris(void);
|
||||
void melody_play_mario(void);
|
||||
void melody_play_custom(const note_t* notes, uint32_t count);
|
||||
|
||||
#endif // _SOUND_MELODY_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef _USERLAND_SH_H
|
||||
#define _USERLAND_SH_H
|
||||
|
||||
int sh_main(int argc, char** argv);
|
||||
int sh_execute_script(const char* filepath);
|
||||
const char* sh_get_env(const char* key);
|
||||
int sh_set_env(const char* key, const char* value);
|
||||
|
||||
#endif // _USERLAND_SH_H
|
||||
Reference in new issue
Block a user