procuding a (non-working) executable for tcc

This commit is contained in:
pommicket 2022-02-17 13:22:13 -05:00
parent 6e1158f49a
commit e900dd8d6f
71 changed files with 42663 additions and 96 deletions

View file

@ -88,6 +88,111 @@ static unsigned char __syscall_data[] = {
(((unsigned long (*)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long))__syscall_data)\
(no, arg1, arg2, arg3, arg4, arg5, arg6))
// we need to define ucontext_t
# define __ctx(fld) fld
typedef long long int greg_t;
#define __NGREG 23
typedef greg_t gregset_t[__NGREG];
#define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
typedef struct
{
unsigned long int __val[_SIGSET_NWORDS];
} __sigset_t, sigset_t;
typedef struct
{
void *ss_sp;
int ss_flags;
size_t ss_size;
} stack_t;
enum
{
REG_R8 = 0,
# define REG_R8 REG_R8
REG_R9,
# define REG_R9 REG_R9
REG_R10,
# define REG_R10 REG_R10
REG_R11,
# define REG_R11 REG_R11
REG_R12,
# define REG_R12 REG_R12
REG_R13,
# define REG_R13 REG_R13
REG_R14,
# define REG_R14 REG_R14
REG_R15,
# define REG_R15 REG_R15
REG_RDI,
# define REG_RDI REG_RDI
REG_RSI,
# define REG_RSI REG_RSI
REG_RBP,
# define REG_RBP REG_RBP
REG_RBX,
# define REG_RBX REG_RBX
REG_RDX,
# define REG_RDX REG_RDX
REG_RAX,
# define REG_RAX REG_RAX
REG_RCX,
# define REG_RCX REG_RCX
REG_RSP,
# define REG_RSP REG_RSP
REG_RIP,
# define REG_RIP REG_RIP
REG_EFL,
# define REG_EFL REG_EFL
REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */
# define REG_CSGSFS REG_CSGSFS
REG_ERR,
# define REG_ERR REG_ERR
REG_TRAPNO,
# define REG_TRAPNO REG_TRAPNO
REG_OLDMASK,
# define REG_OLDMASK REG_OLDMASK
REG_CR2
# define REG_CR2 REG_CR2
};
struct _libc_fpxreg
{
unsigned short int __ctx(significand)[4];
unsigned short int __ctx(exponent);
unsigned short int __glibc_reserved1[3];
};
struct _libc_xmmreg
{
uint32_t __ctx(element)[4];
};
struct _libc_fpstate
{
uint16_t __ctx(cwd);
uint16_t __ctx(swd);
uint16_t __ctx(ftw);
uint16_t __ctx(fop);
uint64_t __ctx(rip);
uint64_t __ctx(rdp);
uint32_t __ctx(mxcsr);
uint32_t __ctx(mxcr_mask);
struct _libc_fpxreg _st[8];
struct _libc_xmmreg _xmm[16];
uint32_t __glibc_reserved1[24];
};
typedef struct _libc_fpstate *fpregset_t;
typedef struct {
gregset_t __ctx(gregs);
fpregset_t __ctx(fpregs);
unsigned long long __reserved1 [8];
} mcontext_t;
typedef struct ucontext_t {
unsigned long int __ctx(uc_flags);
struct ucontext_t *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
struct _libc_fpstate __fpregs_mem;
unsigned long long int __ssp[4];
} ucontext_t;
long read(int fd, void *buf, size_t count) {
return __syscall(0, fd, buf, count, 0, 0, 0);
}
@ -116,6 +221,32 @@ int execve(const char *pathname, char *const argv[], char *const envp[]) {
return __syscall(59, pathname, argv, envp, 0, 0, 0);
}
int gettimeofday(struct timeval *tv, struct timezone *tz) {
return __syscall(96, tv, tz, 0, 0, 0, 0);
}
typedef long time_t;
struct timespec {
time_t tv_sec;
long tv_nsec;
};
struct timeval {
time_t tv_sec;
long tv_usec;
};
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
char *getcwd(char *buf, size_t size) {
long n = __syscall(79, buf, size, 0, 0, 0, 0);
if (n < 0) return NULL;
return buf;
}
#define _WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define _WIFEXITED(status) (__WTERMSIG(status) == 0)
@ -132,16 +263,11 @@ int wait4(int pid, int *status, int options, struct rusage *rusage) {
#define SIGINT 2
#define SIGSEGV 11
#define SIGTERM 15
#define SIGBUS 7
void abort(void) {
kill(getpid(), SIGABRT);
}
typedef long time_t;
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
@ -183,6 +309,29 @@ int __assert_failed(const char *file, int line, const char *expr) {
#define assert(x) (void)((x) || __assert_failed(__FILE__, __LINE__, #x))
#endif
int _clamp_long_to_int(long x) {
if (x < INT_MIN) return INT_MIN;
if (x > INT_MAX) return INT_MAX;
return x;
}
short _clamp_long_to_short(long x) {
if (x < SHRT_MIN) return SHRT_MIN;
if (x > SHRT_MAX) return SHRT_MAX;
return x;
}
unsigned _clamp_ulong_to_uint(unsigned long x) {
if (x > UINT_MAX) return UINT_MAX;
return x;
}
unsigned short _clamp_ulong_to_ushort(unsigned long x) {
if (x > USHRT_MAX) return USHRT_MAX;
return x;
}
#define EIO 5
#define EDOM 33
#define ERANGE 34
@ -201,6 +350,10 @@ int munmap(void *addr, size_t length) {
return __syscall(11, addr, length, 0, 0, 0, 0);
}
int mprotect(void *addr, size_t len, int prot) {
return __syscall(10, addr, len, prot, 0, 0, 0);
}
#define MREMAP_MAYMOVE 1
void *_mremap(void *addr, size_t old_size, size_t new_size, int flags) {
return __syscall(25, addr, old_size, new_size, flags, 0, 0);
@ -455,6 +608,14 @@ double strtod(const char *nptr, char **endptr) {
return sum * sign;
}
float strtof(const char *nptr, char **endptr) {
return strtod(nptr, endptr);
}
long double strtold(const char *nptr, char **endptr) {
return strtod(nptr, endptr);
}
char *strerror(int errnum) {
switch (errnum) {
case ERANGE: return "Range error";