clean up and standardize types across the codebase, unify atomic operations, improve UTF-8 handling throughout the system, remove obsolete input and named queue interfaces, redesign process preparation and creation, tighten IPC and service boundaries, improve error handling and reliability, minor documentation cleanup, fix doom surfaces, fix panic in ini parsing.

This commit is contained in:
maksw committed 2026-10-12 18:17:43 +02:00
1 parent 899225f551
commit c0ad63c27f
226 files changed
+6562 -4147

No files matched your search

+32 -31
View File
@@ -1,5 +1,6 @@
// POSIX compatibility support for posix socket.
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
@@ -31,27 +32,27 @@ __declspec(dllexport) uint32_t htonl(uint32_t x) { return bswap32(x); }
__declspec(dllexport) uint32_t ntohl(uint32_t x) { return bswap32(x); }
// Parses byte.
static int ParseByte(const char** p, uint8_t* out) {
static bool ParseByte(const char** p, uint8_t* out) {
const char* s = *p;
if (*s < '0' || *s > '9') return 0;
if (*s < '0' || *s > '9') return false;
unsigned v = 0;
while (*s >= '0' && *s <= '9') {
v = v * 10 + (unsigned)(*s - '0');
if (v > 255) return 0;
if (v > 255) return false;
s++;
}
*out = (uint8_t)v;
*p = s;
return 1;
return true;
}
// Parses ipv4 Bytes.
static int ParseIpv4Bytes(const char* text, uint8_t out[4]) {
static bool ParseIpv4Bytes(const char* text, uint8_t out[4]) {
const char* p = text;
for (int i = 0; i < 4; i++) {
if (!ParseByte(&p, &out[i])) return 0;
if (!ParseByte(&p, &out[i])) return false;
if (i != 3) {
if (*p != '.') return 0;
if (*p != '.') return false;
p++;
}
}
@@ -65,14 +66,14 @@ static int ParseHex(char c) {
return -1;
}
static int ParseIpv6Bytes(const char* text, uint8_t out[16]) {
static bool ParseIpv6Bytes(const char* text, uint8_t out[16]) {
uint16_t words[8];
int count = 0;
int compress = -1;
const char* p = text;
if (!text || !*text || !out)
return 0;
return false;
memset(words, 0, sizeof(words));
if (p[0] == ':' && p[1] == ':') {
@@ -84,7 +85,7 @@ static int ParseIpv6Bytes(const char* text, uint8_t out[16]) {
while (*p) {
if (count >= 8)
return 0;
return false;
unsigned value = 0;
int digits = 0;
@@ -97,17 +98,17 @@ static int ParseIpv6Bytes(const char* text, uint8_t out[16]) {
digits++;
}
if (digits == 0)
return 0;
return false;
words[count++] = (uint16_t)value;
if (*p == '\0')
break;
if (*p != ':')
return 0;
return false;
p++;
if (*p == ':') {
if (compress >= 0)
return 0;
return false;
compress = count;
p++;
if (*p == '\0')
@@ -118,30 +119,30 @@ static int ParseIpv6Bytes(const char* text, uint8_t out[16]) {
if (compress >= 0) {
int zeros = 8 - count;
if (zeros <= 0)
return 0;
return false;
for (int i = count - 1; i >= compress; --i)
words[i + zeros] = words[i];
for (int i = 0; i < zeros; ++i)
words[compress + i] = 0;
} else if (count != 8) {
return 0;
return false;
}
for (int i = 0; i < 8; ++i) {
out[i * 2 + 0] = (uint8_t)(words[i] >> 8);
out[i * 2 + 1] = (uint8_t)words[i];
}
return 1;
return true;
}
static char* AppendHex16(char* out, uint16_t value) {
static const char hex[] = "0123456789abcdef";
int started = 0;
bool started = false;
for (int shift = 12; shift >= 0; shift -= 4) {
unsigned nibble = (value >> shift) & 0xfu;
if (nibble || started || shift == 0) {
*out++ = hex[nibble];
started = 1;
started = true;
}
}
return out;
@@ -300,7 +301,7 @@ static POSIX_OPEN_DESCRIPTION* SocketFdAcquire(int fd) {
// Creates a socket and installs it as a process-local descriptor.
__declspec(dllexport) int socket(int domain, int type, int protocol) {
uint32_t kh = SYS_HANDLE_INVALID;
uint32_t status = SysCreateSocket((uint32_t)domain, (uint32_t)type, (uint32_t)protocol, &kh);
KSTATUS status = SysCreateSocket((uint32_t)domain, (uint32_t)type, (uint32_t)protocol, &kh);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
return -1;
@@ -321,7 +322,7 @@ __declspec(dllexport) int bind(int fd, const struct sockaddr* addr, socklen_t ad
PosixFdRelease(description);
return -1;
}
uint32_t status = SysBindSocket(description->KHandle, &address, sizeof(address));
KSTATUS status = SysBindSocket(description->KHandle, &address, sizeof(address));
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -334,7 +335,7 @@ __declspec(dllexport) int bind(int fd, const struct sockaddr* addr, socklen_t ad
__declspec(dllexport) int listen(int fd, int backlog) {
POSIX_OPEN_DESCRIPTION* description = SocketFdAcquire(fd);
if (!description) return -1;
uint32_t status = SysListenSocket(description->KHandle, backlog < 0 ? 0u : (uint32_t)backlog);
KSTATUS status = SysListenSocket(description->KHandle, backlog < 0 ? 0u : (uint32_t)backlog);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -351,7 +352,7 @@ __declspec(dllexport) int accept(int fd, struct sockaddr* addr, socklen_t* addrl
SYS_SOCKET_ADDRESS remote;
size_t remoteSize = sizeof(remote);
uint32_t kh = SYS_HANDLE_INVALID;
uint32_t status = SysAcceptSocket(description->KHandle,
KSTATUS status = SysAcceptSocket(description->KHandle,
addr ? &remote : (SYS_SOCKET_ADDRESS*)0,
addr ? &remoteSize : (size_t*)0,
&kh);
@@ -379,7 +380,7 @@ __declspec(dllexport) int connect(int fd, const struct sockaddr* addr, socklen_t
PosixFdRelease(description);
return -1;
}
uint32_t status = SysConnectSocket(description->KHandle, &address, sizeof(address));
KSTATUS status = SysConnectSocket(description->KHandle, &address, sizeof(address));
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -397,7 +398,7 @@ __declspec(dllexport) ssize_t send(int fd, const void* buf, size_t len, int flag
sizeof(SYS_SOCKET_SEND_REQUEST), description->KHandle, (uint32_t)flags,
buf, len, &sent
};
uint32_t status = SysSendSocket(&request);
KSTATUS status = SysSendSocket(&request);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -415,7 +416,7 @@ __declspec(dllexport) ssize_t recv(int fd, void* buf, size_t len, int flags) {
sizeof(SYS_SOCKET_RECV_REQUEST), description->KHandle, (uint32_t)flags,
buf, len, &got
};
uint32_t status = SysRecvSocket(&request);
KSTATUS status = SysRecvSocket(&request);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -446,7 +447,7 @@ __declspec(dllexport) ssize_t sendto(int fd, const void* buf, size_t len, int fl
request.RemoteAddressSize = sizeof(remote);
request.SentOut = &sent;
uint32_t status = SysSendToSocket(description->KHandle, &request);
KSTATUS status = SysSendToSocket(description->KHandle, &request);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -474,7 +475,7 @@ __declspec(dllexport) ssize_t recvfrom(int fd, void* buf, size_t len, int flags,
request.RemoteAddressSizeInOut = src ? &remoteSize : (size_t*)0;
request.ReceivedOut = &got;
uint32_t status = SysRecvFromSocket(description->KHandle, &request);
KSTATUS status = SysRecvFromSocket(description->KHandle, &request);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -488,7 +489,7 @@ __declspec(dllexport) ssize_t recvfrom(int fd, void* buf, size_t len, int flags,
__declspec(dllexport) int shutdown(int fd, int how) {
POSIX_OPEN_DESCRIPTION* description = SocketFdAcquire(fd);
if (!description) return -1;
uint32_t status = SysShutdownSocket(description->KHandle, (uint32_t)how);
KSTATUS status = SysShutdownSocket(description->KHandle, (uint32_t)how);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -550,7 +551,7 @@ __declspec(dllexport) int setsockopt(int fd, int level, int optname, const void*
request.Option = option;
request.Value = &value;
request.ValueSize = sizeof(value);
uint32_t status = SysSetSocketOption(description->KHandle, &request);
KSTATUS status = SysSetSocketOption(description->KHandle, &request);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -584,7 +585,7 @@ __declspec(dllexport) int getsockopt(int fd, int level, int optname, void* optva
request.Value = &value;
request.ValueSize = sizeof(value);
request.ActualSizeOut = &actual;
uint32_t status = SysGetSocketOption(description->KHandle, &request);
KSTATUS status = SysGetSocketOption(description->KHandle, &request);
PosixFdRelease(description);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
@@ -723,7 +724,7 @@ static int ResolveNameFamily(const char* name, int family, SYS_SOCKET_ADDRESS* o
req.Family = family == AF_INET6 ? SYS_AF_INET6 : SYS_AF_INET;
req.AddressOut = out;
req.AddressSizeInOut = &size;
uint32_t s = SysResolveHost(&req);
KSTATUS s = SysResolveHost(&req);
if (s != 0) { errno = PosixStatusToErrno(s); return -1; }
return 0;
}