working on it

This commit is contained in:
Dawid Sobczak 2025-04-05 10:55:40 +01:00
parent 56a6e78765
commit 35a88970c2
1094 changed files with 51093 additions and 51 deletions

View file

@ -0,0 +1,16 @@
#ifndef _INTERNAL_FUTEX_H
#define _INTERNAL_FUTEX_H
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
#define FUTEX_FD 2
#define FUTEX_REQUEUE 3
#define FUTEX_CMP_REQUEUE 4
#define FUTEX_WAKE_OP 5
#define FUTEX_LOCK_PI 6
#define FUTEX_UNLOCK_PI 7
#define FUTEX_TRYLOCK_PI 8
int __futex(volatile int *, int, int, void *);
#endif

View file

@ -0,0 +1,3 @@
#include "libc.h"
struct libc libc;

View file

@ -0,0 +1,43 @@
#ifndef LIBC_H
#define LIBC_H
#include <stdlib.h>
#include <stdio.h>
#define libc __libc
extern struct libc {
void (*lock)(volatile int *);
void (*cancelpt)(int);
int (*atexit)(void (*)(void));
void (*fini)(void);
void (*ldso_fini)(void);
int *(*errno_location)(void);
volatile int threads_minus_1;
int (*rsyscall)(int, long, long, long, long, long, long);
void (**tsd_keys)(void *);
} libc;
/* Designed to avoid any overhead in non-threaded processes */
void __lock(volatile int *);
#define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
#define UNLOCK(x) (*(x)=0)
#define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0)
#define CANCELPT_BEGIN CANCELPT(1)
#define CANCELPT_END CANCELPT(0)
extern char **__environ;
#define environ __environ
#undef weak_alias
#define weak_alias(old, new) \
extern __typeof(old) new __attribute__((weak, alias(#old)))
#undef LFS64_2
//#define LFS64_2(x, y) weak_alias(x, y)
#define LFS64_2(x, y) extern __typeof(x) y
#undef LFS64
#define LFS64(x) LFS64_2(x, x##64)
#endif

View file

@ -0,0 +1,5 @@
#include <locale.h>
struct __locale {
int dummy;
};

View file

@ -0,0 +1,79 @@
#ifndef _PTHREAD_IMPL_H
#define _PTHREAD_IMPL_H
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <limits.h>
#include <inttypes.h>
#include <setjmp.h>
#include <string.h>
#include <time.h>
#include "libc.h"
#include "syscall.h"
#include "atomic.h"
#include "futex.h"
#define pthread __pthread
struct pthread {
struct pthread *self;
unsigned long tlsdesc[4];
pid_t tid, pid;
int tsd_used, errno_val, *errno_ptr;
volatile int canceldisable, cancelasync, cancelpoint, cancel;
unsigned char *map_base;
size_t map_size;
void *start_arg;
void *(*start)(void *);
void *result;
jmp_buf exit_jmp_buf;
int detached;
int exitlock;
struct __ptcb *cancelbuf;
void **tsd;
pthread_attr_t attr;
};
#define __SU (sizeof(size_t)/sizeof(int))
#define _a_stacksize __u.__s[0]
#define _a_guardsize __u.__s[1]
#define _a_detach __u.__i[2*__SU+0]
#define _m_type __u.__i[0]
#define _m_lock __u.__i[1]
#define _m_waiters __u.__i[2]
#define _m_owner __u.__i[3]
#define _c_block __u.__i[0]
#define _rw_wrlock __u.__i[0]
#define _rw_readers __u.__i[1]
#define _rw_waiters __u.__i[2]
#define _rw_owner __u.__i[3]
#define _b_count __u.__i[0]
#define _b_limit __u.__i[1]
#define _b_left __u.__i[2]
#define _b_waiters __u.__i[3]
#include "pthread_arch.h"
#define SIGCANCEL 32
#define SIGSYSCALL 33
#define SIGTIMER 32 /* ?? */
int __set_thread_area(void *);
int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
int __libc_sigprocmask(int, const sigset_t *, sigset_t *);
void __lock(volatile int *);
void __unmapself(void *, size_t);
int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int);
void __wait(volatile int *, volatile int *, int, int);
void __wake(volatile int *, int, int);
#define DEFAULT_STACK_SIZE (16384-PAGE_SIZE)
#define DEFAULT_GUARD_SIZE PAGE_SIZE
#endif

View file

@ -0,0 +1,100 @@
#ifndef _STDIO_IMPL_H
#define _STDIO_IMPL_H
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <inttypes.h>
#include <wchar.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <sys/wait.h>
#include <math.h>
#include <float.h>
#include "syscall.h"
#include "libc.h"
#define UNGET 4
#define FLOCK(f) LOCK(&f->lock)
#define FUNLOCK(f) UNLOCK(&f->lock)
#define F_PERM 1
#define F_NORD 4
#define F_NOWR 8
#define F_EOF 16
#define F_ERR 32
struct __FILE_s {
unsigned flags;
unsigned char *rpos, *rstop;
unsigned char *rend, *wend;
unsigned char *wpos, *wstop;
unsigned char *wbase;
unsigned char *dummy01[3];
unsigned char *buf;
size_t buf_size;
FILE *prev, *next;
int fd;
int pipe_pid;
long dummy2;
short dummy3;
char dummy4;
signed char lbf;
int lock;
int lockcount;
void *owner;
off_t off;
int (*flush)(FILE *);
void **wide_data; /* must be NULL */
size_t (*read)(FILE *, unsigned char *, size_t);
size_t (*write)(FILE *, const unsigned char *, size_t);
off_t (*seek)(FILE *, off_t, int);
int mode;
int (*close)(FILE *);
};
size_t __stdio_read(FILE *, unsigned char *, size_t);
size_t __stdio_write(FILE *, const unsigned char *, size_t);
off_t __stdio_seek(FILE *, off_t, int);
int __stdio_close(FILE *);
int __overflow(FILE *, int);
int __oflow(FILE *);
int __uflow(FILE *);
int __underflow(FILE *);
int __fseeko(FILE *, off_t, int);
int __fseeko_unlocked(FILE *, off_t, int);
off_t __ftello(FILE *);
off_t __ftello_unlocked(FILE *);
size_t __fwritex(const unsigned char *, size_t, FILE *);
int __putc_unlocked(int, FILE *);
FILE *__fdopen(int, const char *);
extern struct ofl
{
FILE *head;
int lock;
} __ofl;
#define OFLLOCK() LOCK(&__ofl.lock)
#define OFLUNLOCK() UNLOCK(&__ofl.lock)
#define ofl_head (__ofl.head)
#define feof(f) ((f)->flags & F_EOF)
#define ferror(f) ((f)->flags & F_ERR)
/* Caller-allocated FILE * operations */
FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
int __fclose_ca(FILE *);
#endif

View file

@ -0,0 +1,11 @@
#include <errno.h>
#include <unistd.h>
long __syscall_ret(unsigned long r)
{
if (r >= (unsigned long)-1 - 4096) {
errno = -(long)r;
return -1;
}
return (long)r;
}