// POSIX compatibility support for posix fd. #pragma once // posix_fd.h - file descriptor table (internal to posix.dll). #include #include typedef enum { FD_FREE, FD_FILE, FD_CONSOLE_R, // fd 0 - reads from keyboard via SysReadKeyboardChar FD_CONSOLE_W, // fd 1, 2 - writes via SysWriteConsole FD_DEVNULL, // /dev/null FD_DEVZERO, // /dev/zero FD_SOCKET, // kernel socket handle } FD_TYPE; typedef struct { FD_TYPE Type; uint32_t KHandle; // kernel handle; 0 for console/devnull/devzero bool Used; } FD_ENTRY; #define FD_MAX 64 #define FD_TABLE_PIDS 32 // circular, indexed by pid % FD_TABLE_PIDS // Called from _start before main(); sets up fds 0/1/2 for this process. __declspec(dllexport) void PosixFdInit(void); // Allocate the lowest free fd >= 3. Returns -1 and sets errno=EMFILE on failure. __declspec(dllexport) int FdAlloc(uint32_t pid, FD_TYPE type, uint32_t khandle); // Look up an fd. Returns NULL and sets errno=EBADF if invalid. __declspec(dllexport) FD_ENTRY* FdGet(uint32_t pid, int fd); // Release an fd slot (does NOT close the kernel handle). __declspec(dllexport) void FdFree(uint32_t pid, int fd); int PosixStatusToErrno(uint32_t s);