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+.
This commit is contained in:
1 parent
3dacbd32c8
commit
73abd6f90d
441 files changed
+187073
-6549
No files matched your search
@@ -3,46 +3,38 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <ntlite/syscall.h>
|
||||
#include "posix.h"
|
||||
#include "posix_internal.h"
|
||||
|
||||
// Thread return-value table (PID-keyed like the fd table).
|
||||
#define PTHREAD_TABLE_PIDS 32
|
||||
#define PTHREAD_TABLE_SIZE 32
|
||||
// Allocates a join-result slot in process-local POSIX state.
|
||||
static POSIX_PTHREAD_SLOT* PthreadSlotAlloc(uint32_t tid) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
if (!process) return (POSIX_PTHREAD_SLOT*)0;
|
||||
|
||||
typedef struct {
|
||||
uint32_t Tid;
|
||||
void* RetVal;
|
||||
bool Used;
|
||||
} PTHREAD_SLOT;
|
||||
|
||||
static PTHREAD_SLOT gPthreadTable[PTHREAD_TABLE_PIDS][PTHREAD_TABLE_SIZE];
|
||||
|
||||
// Implements the pthread Slot Alloc operation.
|
||||
static PTHREAD_SLOT* PthreadSlotAlloc(uint32_t pid, uint32_t tid) {
|
||||
PTHREAD_SLOT* table = gPthreadTable[pid % PTHREAD_TABLE_PIDS];
|
||||
for (int i = 0; i < PTHREAD_TABLE_SIZE; i++) {
|
||||
if (!table[i].Used) {
|
||||
table[i] = (PTHREAD_SLOT){ tid, (void*)0, true };
|
||||
return &table[i];
|
||||
for (uint32_t i = 0; i < POSIX_PTHREAD_TABLE_SIZE; i++) {
|
||||
if (!process->PthreadTable[i].Used) {
|
||||
process->PthreadTable[i] = (POSIX_PTHREAD_SLOT){ tid, (void*)0, true };
|
||||
return &process->PthreadTable[i];
|
||||
}
|
||||
}
|
||||
return (PTHREAD_SLOT*)0;
|
||||
return (POSIX_PTHREAD_SLOT*)0;
|
||||
}
|
||||
|
||||
// Implements the pthread Slot Find operation.
|
||||
static PTHREAD_SLOT* PthreadSlotFind(uint32_t pid, uint32_t tid) {
|
||||
PTHREAD_SLOT* table = gPthreadTable[pid % PTHREAD_TABLE_PIDS];
|
||||
for (int i = 0; i < PTHREAD_TABLE_SIZE; i++)
|
||||
if (table[i].Used && table[i].Tid == tid)
|
||||
return &table[i];
|
||||
return (PTHREAD_SLOT*)0;
|
||||
// Finds a join-result slot in process-local POSIX state.
|
||||
static POSIX_PTHREAD_SLOT* PthreadSlotFind(uint32_t tid) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
if (!process) return (POSIX_PTHREAD_SLOT*)0;
|
||||
|
||||
for (uint32_t i = 0; i < POSIX_PTHREAD_TABLE_SIZE; i++) {
|
||||
if (process->PthreadTable[i].Used && process->PthreadTable[i].Tid == tid)
|
||||
return &process->PthreadTable[i];
|
||||
}
|
||||
return (POSIX_PTHREAD_SLOT*)0;
|
||||
}
|
||||
|
||||
// Trampoline - this is what actually runs as the new thread.
|
||||
typedef struct {
|
||||
void* (*Fn)(void*);
|
||||
void* Arg;
|
||||
uint32_t Pid; // owner pid, for the retval table
|
||||
void* Arg;
|
||||
} PTHREAD_TRAMP;
|
||||
|
||||
// Implements the pthread Trampoline operation.
|
||||
@@ -50,14 +42,18 @@ static void PthreadTrampoline(uintptr_t raw) {
|
||||
PTHREAD_TRAMP* tr = (PTHREAD_TRAMP*)raw;
|
||||
void* (*fn)(void*) = tr->Fn;
|
||||
void* arg = tr->Arg;
|
||||
uint32_t pid = tr->Pid;
|
||||
uint32_t tid = SysGetCurrentTid();
|
||||
|
||||
if (PosixRuntimeAttachThread() != NTLSTATUS_SUCCESS) {
|
||||
free(tr);
|
||||
SysExitThread(ENOMEM);
|
||||
}
|
||||
|
||||
// Create the join slot from inside the new thread. KeCreateThread makes the
|
||||
// thread runnable before the creator regains control, so the old design
|
||||
// raced on tr->Tid and could observe zero/stale memory.
|
||||
PTHREAD_SLOT* slot = PthreadSlotFind(pid, tid);
|
||||
if (!slot) slot = PthreadSlotAlloc(pid, tid);
|
||||
POSIX_PTHREAD_SLOT* slot = PthreadSlotFind(tid);
|
||||
if (!slot) slot = PthreadSlotAlloc(tid);
|
||||
|
||||
free(tr);
|
||||
|
||||
@@ -66,6 +62,7 @@ static void PthreadTrampoline(uintptr_t raw) {
|
||||
// Store retval for pthread_join.
|
||||
if (slot) slot->RetVal = retval;
|
||||
|
||||
PosixRuntimeDetachThread();
|
||||
SysExitThread(0);
|
||||
}
|
||||
|
||||
@@ -75,13 +72,10 @@ __declspec(dllexport) int pthread_create(pthread_t* t, const pthread_attr_t* att
|
||||
void* (*fn)(void*), void* arg) {
|
||||
(void)attr;
|
||||
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
|
||||
PTHREAD_TRAMP* tr = (PTHREAD_TRAMP*)malloc(sizeof(PTHREAD_TRAMP));
|
||||
if (!tr) return ENOMEM;
|
||||
tr->Fn = fn;
|
||||
tr->Arg = arg;
|
||||
tr->Pid = pid;
|
||||
|
||||
uint32_t tid = 0;
|
||||
uint32_t handle = 0;
|
||||
@@ -111,11 +105,10 @@ __declspec(dllexport) int pthread_create(pthread_t* t, const pthread_attr_t* att
|
||||
|
||||
// Implements the pthread join operation.
|
||||
__declspec(dllexport) int pthread_join(pthread_t t, void** retval) {
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
uint32_t s = SysWait(t.Handle, SYS_WAIT_FLAG_NONE);
|
||||
if (s != 0) return ESRCH;
|
||||
|
||||
PTHREAD_SLOT* slot = PthreadSlotFind(pid, t.Tid);
|
||||
POSIX_PTHREAD_SLOT* slot = PthreadSlotFind(t.Tid);
|
||||
if (retval) *retval = slot ? slot->RetVal : (void*)0;
|
||||
if (slot) slot->Used = false;
|
||||
SysCloseHandle(t.Handle);
|
||||
@@ -124,10 +117,10 @@ __declspec(dllexport) int pthread_join(pthread_t t, void** retval) {
|
||||
|
||||
// Implements the pthread exit operation.
|
||||
__declspec(dllexport) void pthread_exit(void* retval) {
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
uint32_t tid = SysGetCurrentTid();
|
||||
PTHREAD_SLOT* slot = PthreadSlotFind(pid, tid);
|
||||
POSIX_PTHREAD_SLOT* slot = PthreadSlotFind(tid);
|
||||
if (slot) slot->RetVal = retval;
|
||||
PosixRuntimeDetachThread();
|
||||
SysExitThread(0);
|
||||
while (1); // unreachable
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user