fix: various fixes
This commit is contained in:
@@ -72,7 +72,7 @@ namespace Hal {
|
||||
InterruptSourceOverride Overrides[MaxOverrides];
|
||||
int OverrideCount;
|
||||
|
||||
static constexpr int MaxLocalApics = 16;
|
||||
static constexpr int MaxLocalApics = 64;
|
||||
LocalApicEntry LocalApics[MaxLocalApics];
|
||||
int LocalApicCount;
|
||||
};
|
||||
|
||||
@@ -333,11 +333,11 @@ namespace Zenith {
|
||||
int childPid = Sched::Spawn(path, args);
|
||||
if (childPid < 0) return childPid;
|
||||
|
||||
// Inherit I/O redirection: if the parent is redirected, the child
|
||||
// is marked redirected too. It stores a parentPid pointing to the
|
||||
// process that owns the actual ring buffers (the one spawned via
|
||||
// spawn_redir). The child does NOT get its own buffers — Sys_Print
|
||||
// et al. look up the buffer owner at write time.
|
||||
// Inherit I/O redirection: if the parent is redirected, the child
|
||||
// is marked redirected too. It stores a parentPid pointing to the
|
||||
// process that owns the actual ring buffers (the one spawned via
|
||||
// spawn_redir). The child does NOT get its own buffers — Sys_Print
|
||||
// et al. look up the buffer owner at write time.
|
||||
if (parent && parent->redirected) {
|
||||
auto* child = Sched::GetProcessByPid(childPid);
|
||||
if (child) {
|
||||
@@ -789,6 +789,13 @@ namespace Zenith {
|
||||
return count;
|
||||
}
|
||||
|
||||
// ---- Kernel introspection syscalls ----
|
||||
|
||||
static void Sys_MemStats(MemStats* out) {
|
||||
if (out == nullptr) return;
|
||||
Memory::g_pfa->GetStats(out);
|
||||
}
|
||||
|
||||
// ---- Window scale syscalls ----
|
||||
|
||||
static int Sys_WinSetScale(int scale) {
|
||||
@@ -818,7 +825,7 @@ namespace Zenith {
|
||||
return WinServer::Destroy(windowId, Sched::GetCurrentPid());
|
||||
}
|
||||
|
||||
static int Sys_WinPresent(int windowId) {
|
||||
static uint64_t Sys_WinPresent(int windowId) {
|
||||
return WinServer::Present(windowId, Sched::GetCurrentPid());
|
||||
}
|
||||
|
||||
@@ -1017,6 +1024,9 @@ namespace Zenith {
|
||||
return (int64_t)Sys_WinSetScale((int)frame->arg1);
|
||||
case SYS_WINGETSCALE:
|
||||
return (int64_t)Sys_WinGetScale();
|
||||
case SYS_MEMSTATS:
|
||||
Sys_MemStats((MemStats*)frame->arg1);
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,9 @@ namespace Zenith {
|
||||
static constexpr uint64_t SYS_KILL = 62;
|
||||
static constexpr uint64_t SYS_DEVLIST = 63;
|
||||
|
||||
// Kernel introspection syscalls
|
||||
static constexpr uint64_t SYS_MEMSTATS = 67;
|
||||
|
||||
static constexpr int SOCK_TCP = 1;
|
||||
static constexpr int SOCK_UDP = 2;
|
||||
|
||||
@@ -162,6 +165,13 @@ namespace Zenith {
|
||||
uint64_t pixelVa; // VA of pixel buffer in caller's address space
|
||||
};
|
||||
|
||||
struct MemStats {
|
||||
uint64_t totalBytes;
|
||||
uint64_t freeBytes;
|
||||
uint64_t usedBytes;
|
||||
uint64_t pageSize;
|
||||
};
|
||||
|
||||
struct DevInfo {
|
||||
uint8_t category; // 0=CPU, 1=Interrupt, 2=Timer, 3=Input, 4=USB, 5=Network, 6=Display, 7=PCI
|
||||
uint8_t _pad[3];
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
namespace kcp {
|
||||
void Spinlock::Acquire() {
|
||||
while (atomic_flag.test_and_set(std::memory_order_acquire));
|
||||
while (atomic_flag.test_and_set(std::memory_order_acquire)) {
|
||||
asm volatile("pause");
|
||||
}
|
||||
}
|
||||
|
||||
void Spinlock::Release() {
|
||||
|
||||
@@ -105,4 +105,21 @@ namespace Memory {
|
||||
Free((void*)(uint64_t)ptr + (0x1000 * n));
|
||||
}
|
||||
}
|
||||
|
||||
void PageFrameAllocator::GetStats(Zenith::MemStats* out) {
|
||||
if (!out) return;
|
||||
Lock.Acquire();
|
||||
uint64_t freeBytes = 0;
|
||||
Page* current = head.next;
|
||||
while (current != nullptr) {
|
||||
freeBytes += current->size;
|
||||
current = current->next;
|
||||
}
|
||||
Lock.Release();
|
||||
|
||||
out->totalBytes = g_section.size;
|
||||
out->freeBytes = freeBytes;
|
||||
out->usedBytes = g_section.size > freeBytes ? g_section.size - freeBytes : 0;
|
||||
out->pageSize = 0x1000;
|
||||
}
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "Memmap.hpp"
|
||||
#include <Api/Syscall.hpp>
|
||||
|
||||
#include <CppLib/Spinlock.hpp>
|
||||
|
||||
@@ -27,6 +28,8 @@ public:
|
||||
void* ReallocConsecutive(void* ptr, int n);
|
||||
void Free(void* ptr);
|
||||
void Free(void* ptr, int n);
|
||||
|
||||
void GetStats(Zenith::MemStats* out);
|
||||
};
|
||||
|
||||
extern PageFrameAllocator* g_pfa;
|
||||
|
||||
Reference in New Issue
Block a user