duct taped posix.dll (just like microsoft), new cursor, more info in the fault handlers, processes now have a parse-it-yourself cmdline, add SYS_WAIT_THREAD and SYS_GET_PROCESS_PID, writing still doesn't work

This commit is contained in:
maksw committed 2026-05-05 15:24:58 +02:00
1 parent a37f5b1581
commit b5c831f593
26 files changed
+1107 -56

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
// posix_fd.c - file descriptor table
#include "posix.h"
#include "posix_fd.h"
// yeah
#ifdef errno
#undef errno
#endif
int errno = 0;
static FD_ENTRY gFdTable[FD_TABLE_PIDS][FD_MAX];
// Syscall stub declarations (from syscall.dll)
extern uint32_t SysGetCurrentPid(void);
void PosixFdInit(void) {
uint32_t pid = SysGetCurrentPid();
uint32_t slot = pid % FD_TABLE_PIDS;
// Clear this process's slice (handles inherited state from a previous
// process that happened to land on the same slot - unlikely but safe).
for (int i = 0; i < FD_MAX; i++)
gFdTable[slot][i] = (FD_ENTRY){ FD_FREE, 0, false };
gFdTable[slot][0] = (FD_ENTRY){ FD_CONSOLE_R, 0, true };
gFdTable[slot][1] = (FD_ENTRY){ FD_CONSOLE_W, 0, true };
gFdTable[slot][2] = (FD_ENTRY){ FD_CONSOLE_W, 0, true };
}
int FdAlloc(uint32_t pid, FD_TYPE type, uint32_t khandle) {
uint32_t slot = pid % FD_TABLE_PIDS;
for (int fd = 3; fd < FD_MAX; fd++) {
if (!gFdTable[slot][fd].Used) {
gFdTable[slot][fd] = (FD_ENTRY){ type, khandle, true };
return fd;
}
}
errno = EMFILE;
return -1;
}
FD_ENTRY* FdGet(uint32_t pid, int fd) {
if (fd < 0 || fd >= FD_MAX) { errno = EBADF; return (FD_ENTRY*)0; }
uint32_t slot = pid % FD_TABLE_PIDS;
FD_ENTRY* e = &gFdTable[slot][fd];
if (!e->Used) { errno = EBADF; return (FD_ENTRY*)0; }
return e;
}
void FdFree(uint32_t pid, int fd) {
if (fd < 0 || fd >= FD_MAX) return;
uint32_t slot = pid % FD_TABLE_PIDS;
gFdTable[slot][fd] = (FD_ENTRY){ FD_FREE, 0, false };
}