This repository was archived by the owner on Jan 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Development #172
Merged
Merged
Development #172
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include "Random.h" | ||
| #include "../crypto/RNG.h" | ||
| #include "../fs/CharDevice.h" | ||
|
|
||
| static int RandomDevRead(struct CharDevice* dev, void* buffer, uint32_t size) { | ||
| uint8_t* buf = (uint8_t*)buffer; | ||
| if (rdrand_supported()) { | ||
| for (uint32_t i = 0; i < size; i += 2) { | ||
| uint16_t rand = rdrand16(); | ||
| buf[i] = rand & 0xFF; | ||
| if (i + 1 < size) { | ||
| buf[i + 1] = (rand >> 8) & 0xFF; | ||
| } | ||
| } | ||
| } else { | ||
| for (uint32_t i = 0; i < size; i += 8) { | ||
| uint64_t rand = xoroshiro128plus(); | ||
| for (int j = 0; j < 8 && (i + j) < size; ++j) { | ||
| buf[i + j] = (rand >> (j * 8)) & 0xFF; | ||
| } | ||
| } | ||
| } | ||
| return size; | ||
| } | ||
|
|
||
| static CharDevice_t g_random_device = { | ||
| .name = "Random", | ||
| .Read = RandomDevRead, | ||
| .Write = NULL, // Not supported | ||
| }; | ||
|
|
||
| void RandomInit(void) { | ||
| if (!rdrand_supported()) { | ||
| uint32_t lo, hi; | ||
| __asm__ volatile("rdtsc" : "=a"(lo), "=d"(hi)); | ||
| uint64_t tsc = ((uint64_t)hi << 32) | lo; | ||
| uint64_t entropy = tsc ^ (uint64_t)(uintptr_t)&g_random_device; | ||
| rng_seed(tsc, entropy); | ||
| } | ||
| CharDeviceRegister(&g_random_device); | ||
| } | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #ifndef VOIDFRAME_RANDOM_H | ||
| #define VOIDFRAME_RANDOM_H | ||
|
|
||
| #include "stdint.h" | ||
|
|
||
| void RandomInit(void); | ||
assembler-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #endif //VOIDFRAME_RANDOM_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| #include "ProcFS.h" | ||
| #include "VFS.h" | ||
| #include "KernelHeap.h" | ||
| #include "StringOps.h" | ||
| #include "Console.h" | ||
| #include "Format.h" | ||
| #include "stdlib.h" | ||
| #include "MemOps.h" | ||
| #include "Scheduler.h" | ||
|
|
||
| static ProcFSEntry* proc_list_head = NULL; | ||
|
|
||
| void ProcFSInit() { | ||
| proc_list_head = NULL; | ||
| PrintKernelF("VFS: Initialized ProcFS\n"); | ||
| } | ||
|
|
||
| void ProcFSRegisterProcess(uint32_t pid, void* data) { | ||
| ProcFSEntry* new_entry = (ProcFSEntry*)KernelMemoryAlloc(sizeof(ProcFSEntry)); | ||
| if (!new_entry) { | ||
| PrintKernelError("VFS: Failed to allocate memory for new process entry\n"); | ||
| return; | ||
| } | ||
| new_entry->pid = pid; | ||
| new_entry->next = proc_list_head; | ||
| proc_list_head = new_entry; | ||
| } | ||
|
|
||
| void ProcFSUnregisterProcess(uint32_t pid) { | ||
| ProcFSEntry* current = proc_list_head; | ||
| ProcFSEntry* prev = NULL; | ||
|
|
||
| while (current) { | ||
| if (current->pid == pid) { | ||
| if (prev) { | ||
| prev->next = current->next; | ||
| } else { | ||
| proc_list_head = current->next; | ||
| } | ||
| KernelFree(current); | ||
| return; | ||
| } | ||
| prev = current; | ||
| current = current->next; | ||
| } | ||
| } | ||
|
|
||
| int ProcfsMount(struct BlockDevice* device, const char* mount_point) { | ||
| (void)device; | ||
| (void)mount_point; | ||
| return 0; | ||
| } | ||
|
|
||
| int ProcfsReadFile(const char* path, void* buffer, uint32_t max_size) { | ||
| if (path[0] != '/') return -1; | ||
|
|
||
| char pid_str[16]; | ||
| int i = 1; | ||
| int j = 0; | ||
| while (path[i] != '/' && path[i] != '\0' && j < 15) { | ||
| pid_str[j++] = path[i++]; | ||
| } | ||
| pid_str[j] = '\0'; | ||
|
|
||
| if (path[i] == '\0') return -1; | ||
|
|
||
| uint32_t pid = atoi(pid_str); | ||
| CurrentProcessControlBlock* pcb = GetCurrentProcessByPID(pid); | ||
|
|
||
| if (!pcb) { | ||
| return -1; | ||
| } | ||
|
|
||
| const char* filename = &path[i + 1]; | ||
| char local_buffer[1024]; | ||
|
|
||
| if (FastStrCmp(filename, "info") == 0) { | ||
| int len = FormatA(local_buffer, sizeof(local_buffer), | ||
| "Name: %s\n" | ||
| "PID: %u\n" | ||
| "State: %d\n" | ||
| "PPID: %u\n" | ||
| "Priority: %d\n" | ||
| "Privilege: %d\n" | ||
| "CPU Time: %llu ticks\n" | ||
| "Creation Time: %llu\n", | ||
| pcb->name, | ||
| pcb->pid, | ||
| pcb->state, | ||
| pcb->parent_pid, | ||
| #if defined(VF_CONFIG_SCHED_MLFQ) | ||
| pcb->priority, | ||
| #else | ||
| pcb->nice, | ||
| #endif | ||
| pcb->privilege_level, | ||
| pcb->cpu_time_accumulated, | ||
| pcb->creation_time); | ||
|
|
||
| if (len > max_size) len = max_size; | ||
| FastMemcpy(buffer, local_buffer, len); | ||
| return len; | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| int ProcfsWriteFile(const char* path, const void* buffer, uint32_t size) { | ||
| (void)path; | ||
| (void)buffer; | ||
| (void)size; | ||
| return -1; | ||
| } | ||
|
|
||
| int ProcfsListDir(const char* path) { | ||
| if (FastStrCmp(path, "/") == 0) { | ||
| ProcFSEntry* current = proc_list_head; | ||
| while (current) { | ||
| PrintKernelF(" %d/\n", current->pid); | ||
| current = current->next; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| if (path[0] == '/' && path[1] != '\0') { | ||
| char pid_str[16]; | ||
| int i = 1; | ||
| int j = 0; | ||
| while (path[i] != '/' && path[i] != '\0' && j < 15) { | ||
| pid_str[j++] = path[i++]; | ||
| } | ||
| pid_str[j] = '\0'; | ||
|
|
||
| uint32_t pid = atoi(pid_str); | ||
| ProcFSEntry* current = proc_list_head; | ||
| while (current) { | ||
| if (current->pid == pid) { | ||
| if (path[i] == '\0' || (path[i] == '/' && path[i+1] == '\0')) { | ||
| PrintKernelF(" info\n"); | ||
| return 0; | ||
| } | ||
| } | ||
| current = current->next; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| int ProcfsIsDir(const char* path) { | ||
| if (FastStrCmp(path, "/") == 0) { | ||
| return 1; | ||
| } | ||
|
|
||
| if (path[0] == '/' && path[1] != '\0') { | ||
| char pid_str[16]; | ||
| int i = 1; | ||
| int j = 0; | ||
| while (path[i] != '/' && path[i] != '\0' && j < 15) { | ||
| pid_str[j++] = path[i++]; | ||
| } | ||
| pid_str[j] = '\0'; | ||
|
|
||
| uint32_t pid = atoi(pid_str); | ||
| ProcFSEntry* current = proc_list_head; | ||
| while (current) { | ||
| if (current->pid == pid) { | ||
| if (path[i] == '\0' || (path[i] == '/' && path[i+1] == '\0')) { | ||
| return 1; | ||
| } | ||
| } | ||
| current = current->next; | ||
| } | ||
| } | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #ifndef VOIDFRAME_PROCFS_H | ||
| #define VOIDFRAME_PROCFS_H | ||
|
|
||
| #include "../BlockDevice.h" | ||
| #include <stdint.h> | ||
| #include <stdbool.h> | ||
|
|
||
| // Represents an entry in the procfs, typically a process. | ||
| // The data pointer is generic and can be used to store scheduler-specific info. | ||
| typedef struct ProcFSEntry { | ||
| uint32_t pid; // Process ID | ||
| struct ProcFSEntry* next; // Pointer to the next process entry | ||
| } ProcFSEntry; | ||
|
|
||
| // Initializes the procfs filesystem. | ||
| void ProcFSInit(); | ||
|
|
||
| // Registers a new process with the given PID and associated data. | ||
| void ProcFSRegisterProcess(uint32_t pid, void* data); | ||
|
|
||
| // Unregisters a process from procfs using its PID. | ||
| void ProcFSUnregisterProcess(uint32_t pid); | ||
|
|
||
| // Mounts the procfs. This is a dummy function as procfs is a virtual filesystem. | ||
| int ProcfsMount(struct BlockDevice* device, const char* mount_point); | ||
|
|
||
| // Reads the content of a file within the procfs. | ||
| int ProcfsReadFile(const char* path, void* buffer, uint32_t max_size); | ||
|
|
||
| // Writes content to a file in procfs. Currently not supported. | ||
| int ProcfsWriteFile(const char* path, const void* buffer, uint32_t size); | ||
|
|
||
| // Lists the directory contents in procfs. | ||
| int ProcfsListDir(const char* path); | ||
|
|
||
| // Checks if a given path in procfs is a directory. | ||
| int ProcfsIsDir(const char* path); | ||
|
|
||
| #endif //VOIDFRAME_PROCFS_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.