From 57300687ff44fab3b9e3b7dd89259a622a7d65c8 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 28 Aug 2024 17:07:58 +0300 Subject: [PATCH] LibC: Cleanup and fix missing LibC headers --- userspace/libraries/LibC/include/dlfcn.h | 3 + userspace/libraries/LibC/include/pthread.h | 8 +- userspace/libraries/LibC/include/signal.h | 235 ++++++++++++------- userspace/libraries/LibC/include/sys/types.h | 10 +- 4 files changed, 161 insertions(+), 95 deletions(-) diff --git a/userspace/libraries/LibC/include/dlfcn.h b/userspace/libraries/LibC/include/dlfcn.h index 8da41c6a19..274edf1614 100644 --- a/userspace/libraries/LibC/include/dlfcn.h +++ b/userspace/libraries/LibC/include/dlfcn.h @@ -12,6 +12,9 @@ __BEGIN_DECLS #define RTLD_GLOBAL 3 #define RTLD_LOCAL 4 +#define RTLD_NEXT ((void*)-1) +#define RTLD_DEFAULT ((void*) 0) + int dlclose(void* handle); char* dlerror(void); void* dlopen(const char* file, int mode); diff --git a/userspace/libraries/LibC/include/pthread.h b/userspace/libraries/LibC/include/pthread.h index 9cee94d69c..72f7784bbc 100644 --- a/userspace/libraries/LibC/include/pthread.h +++ b/userspace/libraries/LibC/include/pthread.h @@ -52,11 +52,9 @@ __BEGIN_DECLS #define PTHREAD_SCOPE_PROCESS 23 #define PTHREAD_SCOPE_SYSTEM 24 -#if 0 -#define PTHREAD_COND_INITIALIZER -#define PTHREAD_MUTEX_INITIALIZER -#define PTHREAD_RWLOCK_INITIALIZER -#endif +#define PTHREAD_COND_INITIALIZER (pthread_cond_t)0 +#define PTHREAD_MUTEX_INITIALIZER (pthread_mutex_t)0 +#define PTHREAD_RWLOCK_INITIALIZER (pthread_rwlock_t)0 int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void)); int pthread_attr_destroy(pthread_attr_t* attr); diff --git a/userspace/libraries/LibC/include/signal.h b/userspace/libraries/LibC/include/signal.h index 255fd5441c..89674506df 100644 --- a/userspace/libraries/LibC/include/signal.h +++ b/userspace/libraries/LibC/include/signal.h @@ -26,117 +26,190 @@ typedef unsigned long long sigset_t; union sigval { - int sival_int; /* Integer signal value. */ - void* sival_ptr; /* Pointer signal value. */ + int sival_int; /* Integer signal value. */ + void* sival_ptr; /* Pointer signal value. */ }; struct sigevent { - int sigev_notify; /* Notification type. */ - int sigev_signo; /* Signal number. */ - union sigval sigev_value; /* Signal value. */ - void (*sigev_notify_function)(union sigval); /* Notification function. */ - pthread_attr_t* sigev_notify_attributes; /* Notification attributes. */ + int sigev_notify; /* Notification type. */ + int sigev_signo; /* Signal number. */ + union sigval sigev_value; /* Signal value. */ + void (*sigev_notify_function)(union sigval); /* Notification function. */ + pthread_attr_t* sigev_notify_attributes; /* Notification attributes. */ }; -#define SIGEV_NONE 1 -#define SIGEV_SIGNAL 2 -#define SIGEV_THREAD 3 +#define SIGEV_NONE 1 +#define SIGEV_SIGNAL 2 +#define SIGEV_THREAD 3 -#define SIGABRT 1 -#define SIGALRM 2 -#define SIGBUS 3 -#define SIGCHLD 4 -#define SIGCONT 5 -#define SIGFPE 6 -#define SIGHUP 7 -#define SIGILL 8 -#define SIGINT 9 -#define SIGKILL 10 -#define SIGPIPE 11 -#define SIGQUIT 12 -#define SIGSEGV 13 -#define SIGSTOP 14 -#define SIGTERM 15 -#define SIGTSTP 16 -#define SIGTTIN 17 -#define SIGTTOU 18 -#define SIGUSR1 19 -#define SIGUSR2 20 -#define SIGPOLL 21 -#define SIGPROF 22 -#define SIGSYS 23 -#define SIGTRAP 24 -#define SIGURG 25 -#define SIGVTALRM 26 -#define SIGXCPU 27 -#define SIGXFSZ 28 -#define SIGWINCH 29 -#define SIGRTMIN 30 -#define SIGRTMAX (SIGRTMIN+32) +#define SIGABRT 1 +#define SIGALRM 2 +#define SIGBUS 3 +#define BUS_ADRALN 1 +#define BUS_ADRERR 2 +#define BUS_OBJERR 3 +#define SIGCHLD 4 +#define CLD_EXITED 1 +#define CLD_KILLED 2 +#define CLD_DUMPED 3 +#define CLD_TRAPPED 4 +#define CLD_STOPPED 5 +#define CLD_CONTINUED 6 +#define SIGCONT 5 +#define SIGFPE 6 +#define FPE_INTDIV 1 +#define FPE_INTOVF 2 +#define FPE_FLTDIV 3 +#define FPE_FLTOVF 4 +#define FPE_FLTUND 5 +#define FPE_FLTRES 6 +#define FPE_FLTINV 7 +#define FPE_FLTSUB 8 +#define SIGHUP 7 +#define SIGILL 8 +#define ILL_ILLOPC 1 +#define ILL_ILLOPN 2 +#define ILL_ILLADR 3 +#define ILL_ILLTRP 4 +#define ILL_PRVOPC 5 +#define ILL_PRVREG 6 +#define ILL_COPROC 7 +#define ILL_BADSTK 8 +#define SIGINT 9 +#define SIGKILL 10 +#define SIGPIPE 11 +#define SIGQUIT 12 +#define SIGSEGV 13 +#define SEGV_MAPERR 1 +#define SEGV_ACCERR 2 +#define SIGSTOP 14 +#define SIGTERM 15 +#define SIGTSTP 16 +#define SIGTTIN 17 +#define SIGTTOU 18 +#define SIGUSR1 19 +#define SIGUSR2 20 +#define SIGPOLL 21 +#define POLL_IN 1 +#define POLL_OUT 2 +#define POLL_MSG 3 +#define POLL_ERR 4 +#define POLL_PRI 5 +#define POLL_HUP 6 +#define SIGPROF 22 +#define SIGSYS 23 +#define SIGTRAP 24 +#define SIGURG 25 +#define SIGVTALRM 26 +#define SIGXCPU 27 +#define SIGXFSZ 28 +#define SIGWINCH 29 +#define SIGRTMIN 30 +#define SIGRTMAX (SIGRTMIN+32) + +#define SI_USER 10 +#define SI_QUEUE 11 +#define SI_TIMER 12 +#define SI_ASYNCIO 13 +#define SI_MESGQ 14 #define _SIGMIN SIGABRT #define _SIGMAX SIGRTMAX -#define SIG_BLOCK 1 -#define SIG_UNBLOCK 2 -#define SIG_SETMASK 3 +#define SIG_BLOCK 1 +#define SIG_UNBLOCK 2 +#define SIG_SETMASK 3 -#define SA_NOCLDSTOP 0x001 -#define SA_ONSTACK 0x002 -#define SA_RESETHAND 0x004 -#define SA_RESTART 0x008 -#define SA_SIGINFO 0x010 -#define SA_NOCLDWAIT 0x020 -#define SA_NODEFER 0x040 -#define SS_ONSTACK 0x080 -#define SS_DISABLE 0x100 -#define MINSIGSTKSZ 0x200 -#define SIGSTKSZ 0x400 +#define SA_NOCLDSTOP 0x001 +#define SA_ONSTACK 0x002 +#define SA_RESETHAND 0x004 +#define SA_RESTART 0x008 +#define SA_SIGINFO 0x010 +#define SA_NOCLDWAIT 0x020 +#define SA_NODEFER 0x040 +#define SS_ONSTACK 0x080 +#define SS_DISABLE 0x100 +#define MINSIGSTKSZ 0x200 +#define SIGSTKSZ 0x400 typedef struct { - void** ss_sp; /* Stack base or pointer. */ - size_t ss_size; /* Stack size. */ - int ss_flags; /* Flags. */ + void** ss_sp; /* Stack base or pointer. */ + size_t ss_size; /* Stack size. */ + int ss_flags; /* Flags. */ } stack_t; -typedef struct {} mcontext_t; +enum +{ +#if defined(__x86_64__) + REG_RAX, + REG_RBX, + REG_RCX, + REG_RDX, + REG_RDI, + REG_RSI, + REG_RSP, + REG_RBP, + REG_RIP, + REG_R8, + REG_R9, + REG_R10, + REG_R11, + REG_R12, + REG_R13, + REG_R14, + REG_R15, +#elif defined(__i686__) + REG_EAX, + REG_EBX, + REG_ECX, + REG_EDX, + REG_EDI, + REG_ESI, + REG_ESP, + REG_EBP, + REG_EIP, +#else +#error +#endif + __REG_COUNT +}; + +typedef struct +{ + long gregs[__REG_COUNT]; +} mcontext_t; typedef struct __ucontext_t { - struct __ucontext_t* uc_link; /* Pointer to the context that is resumed when this context returns. */ - sigset_t uc_sigmask; /* The set of signals that are blocked when this context is active. */ - stack_t uc_stack; /* The stack used by this context. */ - mcontext_t uc_mcontext; /* A machine-specific representation of the saved context. */ + struct __ucontext_t* uc_link; /* Pointer to the context that is resumed when this context returns. */ + sigset_t uc_sigmask; /* The set of signals that are blocked when this context is active. */ + stack_t uc_stack; /* The stack used by this context. */ + mcontext_t uc_mcontext; /* A machine-specific representation of the saved context. */ } ucontext_t; typedef struct { - int si_signo; /* Signal number. */ - int si_code; /* Signal code. */ - int si_errno; /* If non-zero, an errno value associated with this signal, as described in . */ - pid_t si_pid; /* Sending process ID. */ - uid_t si_uid; /* Real user ID of sending process. */ - void* si_addr; /* Address of faulting instruction. */ - int si_status; /* Exit value or signal. */ - long si_band; /* Band event for SIGPOLL. */ - union sigval si_value; /* Signal value. */ + int si_signo; /* Signal number. */ + int si_code; /* Signal code. */ + int si_errno; /* If non-zero, an errno value associated with this signal, as described in . */ + pid_t si_pid; /* Sending process ID. */ + uid_t si_uid; /* Real user ID of sending process. */ + void* si_addr; /* Address of faulting instruction. */ + int si_status; /* Exit value or signal. */ + long si_band; /* Band event for SIGPOLL. */ + union sigval si_value; /* Signal value. */ } siginfo_t; struct sigaction { - void (*sa_handler)(int); /* Pointer to a signal-catching function or one of the SIG_IGN or SIG_DFL. */ - sigset_t sa_mask; /* Set of signals to be blocked during execution of the signal handling function. */ - int sa_flags; /* Special flags. */ - void (*sa_sigaction)(int, siginfo_t*, void*); /* Pointer to a signal-catching function. */ + void (*sa_handler)(int); /* Pointer to a signal-catching function or one of the SIG_IGN or SIG_DFL. */ + sigset_t sa_mask; /* Set of signals to be blocked during execution of the signal handling function. */ + int sa_flags; /* Special flags. */ + void (*sa_sigaction)(int, siginfo_t*, void*); /* Pointer to a signal-catching function. */ }; -// TODO: The header shall define the symbolic constants in the -// Code column of the following table for use as values of si_code -// that are signal-specific or non-signal-specific reasons why the -// signal was generated. - int kill(pid_t pid, int sig); int killpg(pid_t pgpr, int sig); void psiginfo(const siginfo_t* pinfo, const char* message); diff --git a/userspace/libraries/LibC/include/sys/types.h b/userspace/libraries/LibC/include/sys/types.h index 3b661a31cc..e17d533f0a 100644 --- a/userspace/libraries/LibC/include/sys/types.h +++ b/userspace/libraries/LibC/include/sys/types.h @@ -149,15 +149,7 @@ __BEGIN_DECLS #if !defined(__ssize_t_defined) && (defined(__need_all_types) || defined(__need_ssize_t)) #define __ssize_t_defined 1 - #if __SIZEOF_SIZE_T__ == __SIZEOF_INT__ - typedef int ssize_t; - #elif __SIZEOF_SIZE_T__ == __SIZEOF_LONG__ - typedef long ssize_t; - #elif __SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__ - typedef long long ssize_t; - #else - #error "unsupported sizeof(size_t)" - #endif + typedef __PTRDIFF_TYPE__ ssize_t; #endif #undef __need_ssize_t