Files
nt-lite/code/user/personalities/posix/posix_fd.h
T
maksw 73abd6f90d isolate POSIX builds from the host UCRT, wire lwext4 and ntfs-3g as ext4.sys and ntfs.sys, split the FAT driver into directory/file/async/driver/mount units, add posixsrv and dwm plus input/console/desktop syscall clients and a pile of new smoke targets, rename serial.sys to cereal.sys, name HDA/USB/lwIP/AHCI workers, harden ATA probing/reset/removal around actual hardware deadlines, absent-channel detection, diagnostics and explicit worker lifetime, redo ACPI S5 shutdown around GAS/MMIO and HW-reduced firmware, scan SSDTs for _S5 and deal with Intel SMI sleep trapping, make serial and SMP timeouts use real monotonic deadlines, add thread names and fix terminal thread teardown, scheduler and APC prepare/commit races, make advisory file locks queryable and preserve split ranges and add mutable file append state, add shared-memory pipes with kernel-assisted wait/wake, introduce capability-scoped input and display managers, split surface map rights into read/write, add explicit unmap and replace present with commit/generation/damage tracking while keeping physical presentation under the display manager, decouple native exception classes from Win32 exception numbers and translate them in kernel32, add opaque process startup data, bump the resource protocol to v3 with namespace directories, symlinks and enumeration and service control to v2 with generic READY handle exports, add the new POSIX errno/status surface and rebuild fds around posixsrv-owned shared open descriptions, descriptor-local flags, exact inheritance snapshots, dup/fcntl/record locks and shared-ring pipes, add waitpid, POSIX credentials/groups/sessions/passwd/group lookups and move sockets onto stable open descriptions, port the shells and apps to the new console/input services and surface commit API, teach init to load services.ini and start/supervise RSSRV, DWM and generic services under restricted capabilities while publishing their endpoints through RSSRV, split RSSRV into namespace, volume, display, session, input, console and resource components and make /SystemRoot a real symlink to the independently published system volume, shift the syscall table again, expand lock/resource/surface/POSIX/service/thread smoke coverage, make docs scream ASK QUESTIONS and DISCUSS at LLMs, replace MIT No Attribution with WTFPL+.
2026-09-16 10:33:20 +02:00

82 lines
3.2 KiB
C

// POSIX descriptor/open-description declarations internal to posix.dll.
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <ntlite/syscall.h>
#define POSIX_FD_MAX 64
#define POSIX_FD_INHERIT_SKIP_CLOEXEC 0x00000001u
// Open-description kinds owned by the POSIX personality.
typedef enum POSIX_FD_TYPE {
PosixFdFile = NTL_POSIX_OPEN_TYPE_FILE,
PosixFdConsoleRead = NTL_POSIX_OPEN_TYPE_CONSOLE_READ,
PosixFdConsoleWrite = NTL_POSIX_OPEN_TYPE_CONSOLE_WRITE,
PosixFdDevNull = NTL_POSIX_OPEN_TYPE_DEV_NULL,
PosixFdDevZero = NTL_POSIX_OPEN_TYPE_DEV_ZERO,
PosixFdSocket = NTL_POSIX_OPEN_TYPE_SOCKET,
PosixFdPipeRead = NTL_POSIX_OPEN_TYPE_PIPE_READ,
PosixFdPipeWrite = NTL_POSIX_OPEN_TYPE_PIPE_WRITE,
} POSIX_FD_TYPE;
// One refcounted open description shared by one or more descriptors.
typedef struct POSIX_OPEN_DESCRIPTION {
volatile long RefCount;
POSIX_FD_TYPE Type;
uint32_t KHandle;
uint64_t DescriptionId;
NTL_POSIX_SHARED_OPEN_DESCRIPTION* Shared;
} POSIX_OPEN_DESCRIPTION;
// One process-local descriptor entry with descriptor-local flags.
typedef struct POSIX_FD {
POSIX_OPEN_DESCRIPTION* Description;
int DescriptorFlags;
} POSIX_FD;
struct POSIX_PROCESS_STATE;
// Initializes the process descriptor table from inherited state or fresh standard descriptors.
uint32_t PosixFdInitializeProcess(struct POSIX_PROCESS_STATE* process, uint64_t inheritanceToken);
// Captures the current descriptor table in one server-owned inheritance snapshot.
KSTATUS PosixFdCreateInheritanceSnapshot(uint32_t flags, uint64_t* tokenOut);
// Arms one inheritance snapshot to the lifetime of the native child process.
KSTATUS PosixFdArmInheritanceSnapshot(uint64_t token, SYS_HANDLE processHandle);
// Cancels one unclaimed inheritance snapshot owned by the current process.
void PosixFdCancelInheritanceSnapshot(uint64_t token);
// Releases descriptor-table resources during failed process startup.
void PosixFdDestroyProcess(struct POSIX_PROCESS_STATE* process);
// Creates and installs one new open description at the lowest free descriptor >= 3.
int PosixFdCreate(POSIX_FD_TYPE type, uint32_t khandle, int statusFlags);
// Installs one process-local wrapper for a server-created shared open description.
int PosixFdImport(POSIX_FD_TYPE type, uint32_t khandle, uint64_t descriptionId,
NTL_POSIX_SHARED_OPEN_DESCRIPTION* shared, int descriptorFlags);
// Releases one server holder when import/construction fails before a local wrapper exists.
void PosixFdReleaseServerDescription(uint64_t descriptionId);
// Acquires a stable reference to an open description backing fd.
POSIX_OPEN_DESCRIPTION* PosixFdAcquire(int fd);
// Returns one atomic snapshot of shared open-description status flags.
int PosixFdGetStatusFlags(const POSIX_OPEN_DESCRIPTION* description);
// Applies F_SETFL mutable status through the server-owned open-description authority.
int PosixFdSetStatusFlags(POSIX_OPEN_DESCRIPTION* description, int statusFlags);
// Releases one stable open-description reference.
void PosixFdRelease(POSIX_OPEN_DESCRIPTION* description);
// Removes one descriptor and releases its table-owned open-description reference.
int PosixFdClose(int fd);
int PosixStatusToErrno(uint32_t status);