[*] Fix issues related to inconstent retardation in the asinine freetard world

GNU and its consequences have been a disaster for the human race
This commit is contained in:
Reece Wilson 2023-08-26 12:18:10 +01:00
parent 502987a38e
commit 3ca8de022e
6 changed files with 89 additions and 40 deletions

View File

@ -9,6 +9,8 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <linux/futex.h> #include <linux/futex.h>
#define AURORA_IS_GLIBC
namespace Aurora namespace Aurora
{ {
#define read_barrier() __asm__ __volatile__("lfence" ::: "memory") #define read_barrier() __asm__ __volatile__("lfence" ::: "memory")
@ -20,32 +22,67 @@ namespace Aurora
} }
template <typename... T>
long syscallFuckYou(T &&... args)
{
// sysdeps/unix/sysv/linux/x86_64/syscall.S
// Freetards deserve the rope
long iFuckResult = syscall(AuForward<T &&>(args)...);
#if defined(AURORA_IS_GLIBC)
if (iFuckResult == -1
&& errno < 0)
{
// Lynch freetards
return (0 - errno);
}
#else
// TODO: if defined UNIX has a libc wrapper. why would we assume there's a CRT to begin with?
errno = (0 - iFuckResult);
#endif
// Hit freetards over the head with a baseball bat
return iFuckResult;
// Imagine going out of your way to define a varadic syscall wrapper that works without any special formatting parameters,
// works across all abis, just to fuck it into uselessness by returning -ENOSYS and -1 spuriously.
// Nooo we cant just have all the != 0 and if (n >= 0) checks pass, we must enforce `error == -1` is true everywhere as a convention!!!
// People trying to interface with the kernel directly must never know what the kernel actually said!!!
// Look through all their (GNU) garbage hand written assembly *and* C macros, you'll see its litered with SYSCALL_ERROR_LABEL,
// because i swear to god it looks like cmpq and jae are the only instructions they know how to use.
// Worse, its rationalized as and I quote,
// "Linus said he will make sure the no syscall returns a value in -1 .. -4095 as a valid result so we can safely test with -4095"
// So these copy/pasted instructions are hard-coding a "linus said so once"-based test, and now Linux-like OSes are forever limited to 4k errors?
// I guess it's like the other FUTEX issue where every single thead and every single process under Linux is bound to one ABI defined by glib,
// and the kernels stance on the matter is, I quote "must only be changed if the change is first communicated with the glibc folks."
// That meaning, it doesn't matter because they're just going to half-ass things together holding hands.
// Daily reminder, Lin-shit is half-assed HW abstraction layer held together with forced driver source sharing and glibc+freeedesktop hopes and dreams.
// Fucking retards, I swear
}
int pidfd_getfd(int pidfd, int targetfd, int pidfd_getfd(int pidfd, int targetfd,
unsigned int flags) unsigned int flags)
{ {
return syscall(SYS_pidfd_getfd, pidfd, targetfd, flags); return syscallFuckYou(SYS_pidfd_getfd, pidfd, targetfd, flags);
} }
int pidfd_open(pid_t pid, unsigned int flags) int pidfd_open(pid_t pid, unsigned int flags)
{ {
return syscall(SYS_pidfd_open, pid, flags); return syscallFuckYou(SYS_pidfd_open, pid, flags);
} }
long set_robust_list(struct robust_list_head *head, size_t len) long set_robust_list(struct robust_list_head *head, size_t len)
{ {
return syscall(SYS_set_robust_list, head, len); return syscallFuckYou(SYS_set_robust_list, head, len);
} }
long get_robust_list(int pid, struct robust_list_head **head_ptr, size_t *len_ptr) long get_robust_list(int pid, struct robust_list_head **head_ptr, size_t *len_ptr)
{ {
return syscall(SYS_get_robust_list, pid, head_ptr, len_ptr); return syscallFuckYou(SYS_get_robust_list, pid, head_ptr, len_ptr);
} }
static int futex(uint32_t *uaddr, int futex_op, uint32_t val, static int futex(uint32_t *uaddr, int futex_op, uint32_t val,
const struct timespec *timeout, const struct timespec *timeout,
uint32_t *uaddr2, uint32_t val3) uint32_t *uaddr2, uint32_t val3)
{ {
return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3); return syscallFuckYou(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
} }
int futex_wait(uint32_t *addr, uint32_t expected) int futex_wait(uint32_t *addr, uint32_t expected)
@ -111,17 +148,17 @@ namespace Aurora
int io_setup(unsigned nr, aio_context_t *ctxp) int io_setup(unsigned nr, aio_context_t *ctxp)
{ {
return syscall(__NR_io_setup, nr, ctxp); return syscallFuckYou(__NR_io_setup, nr, ctxp);
} }
int io_destroy(aio_context_t ctx) int io_destroy(aio_context_t ctx)
{ {
return syscall(__NR_io_destroy, ctx); return syscallFuckYou(__NR_io_destroy, ctx);
} }
int io_submit(aio_context_t ctx, long nr, struct iocb **iocbpp) int io_submit(aio_context_t ctx, long nr, struct iocb **iocbpp)
{ {
return syscall(__NR_io_submit, ctx, nr, iocbpp); return syscallFuckYou(__NR_io_submit, ctx, nr, iocbpp);
} }
#if 0 #if 0
@ -191,16 +228,28 @@ namespace Aurora
} }
do_syscall: do_syscall:
return syscall(__NR_io_getevents, int iKernelCount {};
ctx, min_nr - i, if ((iKernelCount = syscallFuckYou(__NR_io_getevents,
max_nr - i, ctx, min_nr - i,
&events[i], timeout) + i; max_nr - i,
&events[i], timeout)) > 0)
{
return i + iKernelCount;
}
else if (i)
{
return i;
}
else
{
return iKernelCount;
}
} }
int io_cancel(aio_context_t ctx_id, struct iocb *iocb, int io_cancel(aio_context_t ctx_id, struct iocb *iocb,
struct io_event *result) struct io_event *result)
{ {
return syscall(SYS_io_cancel, ctx_id, iocb, result); return syscallFuckYou(SYS_io_cancel, ctx_id, iocb, result);
} }
ssize_t sys_getrandom(void *pBuffer, size_t uLength) ssize_t sys_getrandom(void *pBuffer, size_t uLength)
@ -210,11 +259,11 @@ namespace Aurora
if (gShouldNotGetRand) if (gShouldNotGetRand)
{ {
return ENOSYS; return -ENOSYS;
} }
ret = syscall(SYS_getrandom, pBuffer, uLength, 1); ret = syscallFuckYou(SYS_getrandom, pBuffer, uLength, 1);
if (ret == ENOSYS) if (ret == -ENOSYS)
{ {
gShouldNotGetRand = 1; gShouldNotGetRand = 1;
} }

View File

@ -488,17 +488,17 @@ namespace Aurora::Threading
continue; continue;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
continue; continue;
} }
if (ret == ETIMEDOUT || errno == ETIMEDOUT) if (ret == -ETIMEDOUT)
{ {
return false; return false;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
return !expect.Compare(pTargetAddress); return !expect.Compare(pTargetAddress);
#endif #endif
@ -695,17 +695,17 @@ namespace Aurora::Threading
continue; continue;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
continue; continue;
} }
if (ret == ETIMEDOUT || errno == ETIMEDOUT) if (ret == -ETIMEDOUT)
{ {
return false; return false;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
#endif #endif

View File

@ -82,7 +82,7 @@ namespace Aurora::Threading::Primitives
{ {
ret = futex_wait(&this->uState_, state, &tspec); ret = futex_wait(&this->uState_, state, &tspec);
} }
while (ret == EINTR); while (ret == -EINTR);
} }
else else
{ {
@ -97,14 +97,14 @@ namespace Aurora::Threading::Primitives
break; break;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
bStatus = true; bStatus = true;
break; break;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret) RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret)
} }
@ -166,14 +166,14 @@ namespace Aurora::Threading::Primitives
break; break;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
bStatus = true; bStatus = true;
break; break;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret) RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret)

View File

@ -63,7 +63,7 @@ namespace Aurora::Threading::Primitives
{ {
ret = futex_wait(&this->uState_, 0, &tspec); ret = futex_wait(&this->uState_, 0, &tspec);
} }
while (ret == EINTR); while (ret == -EINTR);
} }
else else
{ {
@ -78,14 +78,14 @@ namespace Aurora::Threading::Primitives
continue; continue;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
bStatus = true; bStatus = true;
continue; continue;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Condvar wait failed: {}", ret) RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Condvar wait failed: {}", ret)
} }

View File

@ -108,7 +108,7 @@ namespace Aurora::Threading::Primitives
{ {
ret = futex_wait(&this->state_, state, &tspec); ret = futex_wait(&this->state_, state, &tspec);
} }
while (ret == EINTR); while (ret == -EINTR);
} }
else else
{ {
@ -123,14 +123,14 @@ namespace Aurora::Threading::Primitives
break; break;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == EAGAIN)
{ {
bStatus = true; bStatus = true;
break; break;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret) RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret)
} }

View File

@ -109,7 +109,7 @@ namespace Aurora::Threading::Primitives
{ {
ret = futex_wait(&this->dwState_, 0, &tspec); ret = futex_wait(&this->dwState_, 0, &tspec);
} }
while (ret == EINTR); while (ret == -EINTR);
} }
else else
{ {
@ -124,14 +124,14 @@ namespace Aurora::Threading::Primitives
continue; continue;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
bStatus = true; bStatus = true;
continue; continue;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "semaphore wait failed: {}", ret) RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "semaphore wait failed: {}", ret)
} }
@ -192,7 +192,7 @@ namespace Aurora::Threading::Primitives
{ {
ret = futex_wait(&this->dwState_, 0, &tspec); ret = futex_wait(&this->dwState_, 0, &tspec);
} }
while (ret == EINTR); while (ret == -EINTR);
} }
else else
{ {
@ -207,14 +207,14 @@ namespace Aurora::Threading::Primitives
continue; continue;
} }
if (ret == EAGAIN || errno == EAGAIN) if (ret == -EAGAIN)
{ {
bStatus = true; bStatus = true;
continue; continue;
} }
} }
while (ret == EINTR); while (ret == -EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "semaphore wait failed: {}", ret) RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "semaphore wait failed: {}", ret)
} }