redo boot around an explicit system volume and fixed kernel/HAL images, redo volumes and filesystem paths around capabilities instead of drive numbers and kernel CWD state, add a capability/security model with derived and revocable handles and security contexts, add port IPC and rssrv to manage the userspace resource namespace and publish the system volume, move process, dll and path loading to userspace and add process builder syscalls, init now supervises rssrv and the session process, redo the syscall ABI around request structs and four arguments, add a volume manager and proper partition arrival/removal handling so FAT and NTFS mount dynamically, clean up the HAL/DDK boundary so drivers don't depend on HAL internals, save fpu state properly now, the serial driver doesn't hang on a missing port, fix AHCI startup races, fix timeout accounting, fix shared mmap writeback, more smoke tests
This commit is contained in:
1 parent
4add6789ba
commit
f882d339fb
232 files changed
+20934
-8898
No files matched your search
@@ -1,76 +1,90 @@
|
||||
// POSIX compatibility support for posix path.
|
||||
// POSIX compatibility support for path translation.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <ntlite/status.h>
|
||||
#include "posix_path.h"
|
||||
|
||||
// Checks whether drive Mount.
|
||||
static int IsDriveMount(const char* p) {
|
||||
return p && p[0] == '/' && p[1] >= '0' && p[1] <= '7' &&
|
||||
(p[2] == '\0' || p[2] == '/');
|
||||
}
|
||||
#define POSIX_SYSTEM_ROOT "/SystemRoot"
|
||||
|
||||
// Translates POSIX filesystem syntax into the native resource namespace.
|
||||
const char* PosixTranslatePath(const char* in, char* out, size_t outSize) {
|
||||
if (!in || !out || outSize < 4) return out;
|
||||
if (!in || !out || outSize == 0) return out;
|
||||
|
||||
if (strcmp(in, "/dev/null") == 0) return SYNTH_DEVNULL;
|
||||
if (strcmp(in, "/dev/zero") == 0) return SYNTH_DEVZERO;
|
||||
|
||||
if (IsDriveMount(in)) {
|
||||
out[0] = in[1];
|
||||
out[1] = ':';
|
||||
out[2] = '/';
|
||||
const char* rest = (in[2] == '/') ? in + 3 : "";
|
||||
size_t restLen = strlen(rest);
|
||||
if (restLen + 4 > outSize) restLen = outSize - 4;
|
||||
memcpy(out + 3, rest, restLen);
|
||||
out[3 + restLen] = '\0';
|
||||
if (in[0] == '/') {
|
||||
size_t prefixLength = sizeof(POSIX_SYSTEM_ROOT) - 1u;
|
||||
size_t restLength = strlen(in);
|
||||
if (prefixLength + restLength + 1u > outSize) {
|
||||
out[0] = '\0';
|
||||
return out;
|
||||
}
|
||||
memcpy(out, POSIX_SYSTEM_ROOT, prefixLength);
|
||||
memcpy(out + prefixLength, in, restLength + 1u);
|
||||
return out;
|
||||
}
|
||||
|
||||
if (in[0] == '/') {
|
||||
out[0] = '0';
|
||||
out[1] = ':';
|
||||
out[2] = '/';
|
||||
size_t rest = strlen(in + 1);
|
||||
if (rest + 4 > outSize) rest = outSize - 4;
|
||||
memcpy(out + 3, in + 1, rest);
|
||||
out[3 + rest] = '\0';
|
||||
} else {
|
||||
size_t len = strlen(in);
|
||||
if (len + 1 > outSize) len = outSize - 1;
|
||||
memcpy(out, in, len);
|
||||
out[len] = '\0';
|
||||
size_t length = strlen(in);
|
||||
if (length + 1u > outSize) {
|
||||
out[0] = '\0';
|
||||
return out;
|
||||
}
|
||||
|
||||
memcpy(out, in, length + 1u);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Implements the native To Posix operation.
|
||||
// Translates a canonical native SystemRoot path back to POSIX syntax.
|
||||
void NativeToPosix(const char* in, char* out, size_t outSize) {
|
||||
if (!in || !out || outSize == 0) return;
|
||||
|
||||
size_t prefixLength = sizeof(POSIX_SYSTEM_ROOT) - 1u;
|
||||
const char* src = in;
|
||||
char drive = 0;
|
||||
if (src[0] >= '0' && src[0] <= '7' && src[1] == ':' &&
|
||||
(src[2] == '\\' || src[2] == '/')) {
|
||||
drive = src[0];
|
||||
src += 3;
|
||||
if (strncmp(src, POSIX_SYSTEM_ROOT, prefixLength) == 0 &&
|
||||
(src[prefixLength] == '\0' || src[prefixLength] == '/')) {
|
||||
src += prefixLength;
|
||||
if (*src == '\0') src = "/";
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
if (drive && drive != '0') {
|
||||
if (outSize < 4) { out[0] = '\0'; return; }
|
||||
out[pos++] = '/';
|
||||
out[pos++] = drive;
|
||||
if (*src) out[pos++] = '/';
|
||||
} else {
|
||||
out[pos++] = '/';
|
||||
size_t length = strlen(src);
|
||||
if (length + 1u > outSize) {
|
||||
out[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
while (*src && pos + 1 < outSize) {
|
||||
out[pos++] = (*src == '\\') ? '/' : *src;
|
||||
src++;
|
||||
}
|
||||
out[pos] = '\0';
|
||||
memcpy(out, src, length + 1u);
|
||||
}
|
||||
|
||||
// Maps POSIX executable syntax into native resource/CWD syntax.
|
||||
KSTATUS PosixProcessPath(const char* in, char* out, size_t outSize) {
|
||||
if (!in || !out || outSize == 0) return NTLSTATUS_INVALID_PARAMETER;
|
||||
const char* translated = PosixTranslatePath(in, out, outSize);
|
||||
if (translated != out || out[0] == '\0') return NTLSTATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int PosixViewEqualsI(SYS_STRING_VIEW view, const char* text) {
|
||||
size_t length = strlen(text);
|
||||
if (view.Length != length) return 0;
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
char a = view.Data[i];
|
||||
char b = text[i];
|
||||
if (a >= 'A' && a <= 'Z') a = (char)(a - 'A' + 'a');
|
||||
if (b >= 'A' && b <= 'Z') b = (char)(b - 'A' + 'a');
|
||||
if (a != b) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// POSIX owns the msvcrt compatibility alias; all other import names are native.
|
||||
KSTATUS PosixResolveModuleName(void* context, SYS_STRING_VIEW requested, SYS_STRING_VIEW* canonicalOut) {
|
||||
(void)context;
|
||||
if (!canonicalOut || !SysSvIsValid(requested) || requested.Length == 0)
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
if (PosixViewEqualsI(requested, "msvcrt.dll")) {
|
||||
*canonicalOut = SYS_SV_LITERAL("posix.dll");
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
*canonicalOut = requested;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user