Files
nt-lite/code/user/personalities/posix/posix_internal.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

135 lines
4.7 KiB
C

// POSIX personality internal declarations and process/thread runtime state.
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <pthread.h>
#include <spawn.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <poll.h>
#include <pwd.h>
#include <grp.h>
#include <ntlite/posix_service.h>
#include <ntlite/posix_extensions.h>
#include <ntlite/syscall.h>
#include "posix_fd.h"
#define POSIX_PROCESS_STATE_MAGIC 0x50505243u
#define POSIX_THREAD_STATE_MAGIC 0x50544852u
#define POSIX_DLERROR_MAX 160u
#define POSIX_SPAWN_TABLE_SIZE 32u
#define POSIX_PTHREAD_TABLE_SIZE 32u
typedef struct POSIX_SPAWN_ENTRY {
pid_t Pid;
SYS_HANDLE Handle;
uint64_t FdInheritanceToken;
bool Used;
} POSIX_SPAWN_ENTRY;
typedef struct POSIX_PTHREAD_SLOT {
uint32_t Tid;
void* RetVal;
bool Used;
} POSIX_PTHREAD_SLOT;
typedef struct POSIX_LOGICAL_PROCESS_STATE {
uint32_t PosixPid;
uint32_t Generation;
} POSIX_LOGICAL_PROCESS_STATE;
typedef struct POSIX_PROCESS_STATE {
uint32_t Magic;
SYS_PEB* Peb;
SYS_HANDLE ServerEndpoint;
POSIX_LOGICAL_PROCESS_STATE DefaultIdentity;
SYS_HANDLE FdLock;
POSIX_FD FdTable[POSIX_FD_MAX];
POSIX_SPAWN_ENTRY SpawnTable[POSIX_SPAWN_TABLE_SIZE];
POSIX_PTHREAD_SLOT PthreadTable[POSIX_PTHREAD_TABLE_SIZE];
} POSIX_PROCESS_STATE;
typedef struct POSIX_THREAD_STATE {
uint32_t Magic;
int ErrnoValue;
uint8_t DlErrorPending;
uint8_t Reserved[3];
char DlError[POSIX_DLERROR_MAX];
POSIX_PROCESS_STATE* NativeProcess;
POSIX_LOGICAL_PROCESS_STATE* LogicalProcess;
struct passwd PasswordResult;
char PasswordName[NTL_POSIX_IDENTITY_NAME_MAX + 1u];
char PasswordHome[NTL_POSIX_IDENTITY_HOME_MAX + 1u];
char PasswordShell[NTL_POSIX_IDENTITY_SHELL_MAX + 1u];
struct group GroupResult;
char GroupName[NTL_POSIX_IDENTITY_NAME_MAX + 1u];
char* GroupMembers[1];
char LoginName[NTL_POSIX_IDENTITY_NAME_MAX + 1u];
} POSIX_THREAD_STATE;
// Initializes process-local POSIX state and attaches the initial thread.
uint32_t PosixRuntimeInitializeProcess(void);
// Returns the POSIX state for the current process after startup.
POSIX_PROCESS_STATE* PosixRuntimeProcessState(void);
// Returns the current thread state, attaching lazily when necessary.
POSIX_THREAD_STATE* PosixRuntimeThreadState(void);
// Attaches POSIX state to the current native TEB.
uint32_t PosixRuntimeAttachThread(void);
// Releases POSIX state owned by the current native TEB.
void PosixRuntimeDetachThread(void);
// Clears the current thread's dynamic-loader error state.
void PosixRuntimeClearDlError(void);
// Stores one dynamic-loader error in current-thread state.
void PosixRuntimeSetDlError(const char* message);
// Returns and consumes the current thread's dynamic-loader error.
char* PosixRuntimeTakeDlError(void);
// Calls posixsrv over the registered process endpoint and validates one fixed-size reply.
KSTATUS PosixRuntimeCallServer(const NTL_POSIX_REQUEST* request, NTL_POSIX_REPLY* replyOut);
// Calls posixsrv while transferring a bounded set of native capabilities.
KSTATUS PosixRuntimeCallServerWithHandles(const NTL_POSIX_REQUEST* request,
const SYS_PORT_HANDLE_TRANSFER* handles,
uint32_t handleCount,
NTL_POSIX_REPLY* replyOut);
// Calls posixsrv with independent request/reply capability transfer.
KSTATUS PosixRuntimeCallServerExchange(const NTL_POSIX_REQUEST* request,
const SYS_PORT_HANDLE_TRANSFER* requestHandles,
uint32_t requestHandleCount,
SYS_HANDLE* replyHandlesOut,
uint32_t replyHandleCapacity,
uint32_t expectedReplyHandleCount,
NTL_POSIX_REPLY* replyOut);
// Calls posixsrv and accepts a variable number of reply capabilities up to the supplied capacity.
KSTATUS PosixRuntimeCallServerExchangeVariable(const NTL_POSIX_REQUEST* request,
SYS_HANDLE* replyHandlesOut,
uint32_t replyHandleCapacity,
uint32_t* replyHandleCountOut,
NTL_POSIX_REPLY* replyOut);
// Queries the server-owned shared process attributes for the current logical process.
KSTATUS PosixRuntimeGetProcessAttributes(NTL_POSIX_REPLY* replyOut);