LibC: Cleanup and fix missing LibC headers

This commit is contained in:
Bananymous 2024-08-28 17:07:58 +03:00
parent d559339f5f
commit 57300687ff
4 changed files with 161 additions and 95 deletions

View File

@ -12,6 +12,9 @@ __BEGIN_DECLS
#define RTLD_GLOBAL 3 #define RTLD_GLOBAL 3
#define RTLD_LOCAL 4 #define RTLD_LOCAL 4
#define RTLD_NEXT ((void*)-1)
#define RTLD_DEFAULT ((void*) 0)
int dlclose(void* handle); int dlclose(void* handle);
char* dlerror(void); char* dlerror(void);
void* dlopen(const char* file, int mode); void* dlopen(const char* file, int mode);

View File

@ -52,11 +52,9 @@ __BEGIN_DECLS
#define PTHREAD_SCOPE_PROCESS 23 #define PTHREAD_SCOPE_PROCESS 23
#define PTHREAD_SCOPE_SYSTEM 24 #define PTHREAD_SCOPE_SYSTEM 24
#if 0 #define PTHREAD_COND_INITIALIZER (pthread_cond_t)0
#define PTHREAD_COND_INITIALIZER #define PTHREAD_MUTEX_INITIALIZER (pthread_mutex_t)0
#define PTHREAD_MUTEX_INITIALIZER #define PTHREAD_RWLOCK_INITIALIZER (pthread_rwlock_t)0
#define PTHREAD_RWLOCK_INITIALIZER
#endif
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void)); int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void));
int pthread_attr_destroy(pthread_attr_t* attr); int pthread_attr_destroy(pthread_attr_t* attr);

View File

@ -26,117 +26,190 @@ typedef unsigned long long sigset_t;
union sigval union sigval
{ {
int sival_int; /* Integer signal value. */ int sival_int; /* Integer signal value. */
void* sival_ptr; /* Pointer signal value. */ void* sival_ptr; /* Pointer signal value. */
}; };
struct sigevent struct sigevent
{ {
int sigev_notify; /* Notification type. */ int sigev_notify; /* Notification type. */
int sigev_signo; /* Signal number. */ int sigev_signo; /* Signal number. */
union sigval sigev_value; /* Signal value. */ union sigval sigev_value; /* Signal value. */
void (*sigev_notify_function)(union sigval); /* Notification function. */ void (*sigev_notify_function)(union sigval); /* Notification function. */
pthread_attr_t* sigev_notify_attributes; /* Notification attributes. */ pthread_attr_t* sigev_notify_attributes; /* Notification attributes. */
}; };
#define SIGEV_NONE 1 #define SIGEV_NONE 1
#define SIGEV_SIGNAL 2 #define SIGEV_SIGNAL 2
#define SIGEV_THREAD 3 #define SIGEV_THREAD 3
#define SIGABRT 1 #define SIGABRT 1
#define SIGALRM 2 #define SIGALRM 2
#define SIGBUS 3 #define SIGBUS 3
#define SIGCHLD 4 #define BUS_ADRALN 1
#define SIGCONT 5 #define BUS_ADRERR 2
#define SIGFPE 6 #define BUS_OBJERR 3
#define SIGHUP 7 #define SIGCHLD 4
#define SIGILL 8 #define CLD_EXITED 1
#define SIGINT 9 #define CLD_KILLED 2
#define SIGKILL 10 #define CLD_DUMPED 3
#define SIGPIPE 11 #define CLD_TRAPPED 4
#define SIGQUIT 12 #define CLD_STOPPED 5
#define SIGSEGV 13 #define CLD_CONTINUED 6
#define SIGSTOP 14 #define SIGCONT 5
#define SIGTERM 15 #define SIGFPE 6
#define SIGTSTP 16 #define FPE_INTDIV 1
#define SIGTTIN 17 #define FPE_INTOVF 2
#define SIGTTOU 18 #define FPE_FLTDIV 3
#define SIGUSR1 19 #define FPE_FLTOVF 4
#define SIGUSR2 20 #define FPE_FLTUND 5
#define SIGPOLL 21 #define FPE_FLTRES 6
#define SIGPROF 22 #define FPE_FLTINV 7
#define SIGSYS 23 #define FPE_FLTSUB 8
#define SIGTRAP 24 #define SIGHUP 7
#define SIGURG 25 #define SIGILL 8
#define SIGVTALRM 26 #define ILL_ILLOPC 1
#define SIGXCPU 27 #define ILL_ILLOPN 2
#define SIGXFSZ 28 #define ILL_ILLADR 3
#define SIGWINCH 29 #define ILL_ILLTRP 4
#define SIGRTMIN 30 #define ILL_PRVOPC 5
#define SIGRTMAX (SIGRTMIN+32) #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 _SIGMIN SIGABRT
#define _SIGMAX SIGRTMAX #define _SIGMAX SIGRTMAX
#define SIG_BLOCK 1 #define SIG_BLOCK 1
#define SIG_UNBLOCK 2 #define SIG_UNBLOCK 2
#define SIG_SETMASK 3 #define SIG_SETMASK 3
#define SA_NOCLDSTOP 0x001 #define SA_NOCLDSTOP 0x001
#define SA_ONSTACK 0x002 #define SA_ONSTACK 0x002
#define SA_RESETHAND 0x004 #define SA_RESETHAND 0x004
#define SA_RESTART 0x008 #define SA_RESTART 0x008
#define SA_SIGINFO 0x010 #define SA_SIGINFO 0x010
#define SA_NOCLDWAIT 0x020 #define SA_NOCLDWAIT 0x020
#define SA_NODEFER 0x040 #define SA_NODEFER 0x040
#define SS_ONSTACK 0x080 #define SS_ONSTACK 0x080
#define SS_DISABLE 0x100 #define SS_DISABLE 0x100
#define MINSIGSTKSZ 0x200 #define MINSIGSTKSZ 0x200
#define SIGSTKSZ 0x400 #define SIGSTKSZ 0x400
typedef struct typedef struct
{ {
void** ss_sp; /* Stack base or pointer. */ void** ss_sp; /* Stack base or pointer. */
size_t ss_size; /* Stack size. */ size_t ss_size; /* Stack size. */
int ss_flags; /* Flags. */ int ss_flags; /* Flags. */
} stack_t; } 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 typedef struct __ucontext_t
{ {
struct __ucontext_t* uc_link; /* Pointer to the context that is resumed when this context returns. */ 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. */ 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. */ stack_t uc_stack; /* The stack used by this context. */
mcontext_t uc_mcontext; /* A machine-specific representation of the saved context. */ mcontext_t uc_mcontext; /* A machine-specific representation of the saved context. */
} ucontext_t; } ucontext_t;
typedef struct typedef struct
{ {
int si_signo; /* Signal number. */ int si_signo; /* Signal number. */
int si_code; /* Signal code. */ int si_code; /* Signal code. */
int si_errno; /* If non-zero, an errno value associated with this signal, as described in <errno.h>. */ int si_errno; /* If non-zero, an errno value associated with this signal, as described in <errno.h>. */
pid_t si_pid; /* Sending process ID. */ pid_t si_pid; /* Sending process ID. */
uid_t si_uid; /* Real user ID of sending process. */ uid_t si_uid; /* Real user ID of sending process. */
void* si_addr; /* Address of faulting instruction. */ void* si_addr; /* Address of faulting instruction. */
int si_status; /* Exit value or signal. */ int si_status; /* Exit value or signal. */
long si_band; /* Band event for SIGPOLL. */ long si_band; /* Band event for SIGPOLL. */
union sigval si_value; /* Signal value. */ union sigval si_value; /* Signal value. */
} siginfo_t; } siginfo_t;
struct sigaction struct sigaction
{ {
void (*sa_handler)(int); /* Pointer to a signal-catching function or one of the SIG_IGN or SIG_DFL. */ 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. */ sigset_t sa_mask; /* Set of signals to be blocked during execution of the signal handling function. */
int sa_flags; /* Special flags. */ int sa_flags; /* Special flags. */
void (*sa_sigaction)(int, siginfo_t*, void*); /* Pointer to a signal-catching function. */ void (*sa_sigaction)(int, siginfo_t*, void*); /* Pointer to a signal-catching function. */
}; };
// TODO: The <signal.h> 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 kill(pid_t pid, int sig);
int killpg(pid_t pgpr, int sig); int killpg(pid_t pgpr, int sig);
void psiginfo(const siginfo_t* pinfo, const char* message); void psiginfo(const siginfo_t* pinfo, const char* message);

View File

@ -149,15 +149,7 @@ __BEGIN_DECLS
#if !defined(__ssize_t_defined) && (defined(__need_all_types) || defined(__need_ssize_t)) #if !defined(__ssize_t_defined) && (defined(__need_all_types) || defined(__need_ssize_t))
#define __ssize_t_defined 1 #define __ssize_t_defined 1
#if __SIZEOF_SIZE_T__ == __SIZEOF_INT__ typedef __PTRDIFF_TYPE__ ssize_t;
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
#endif #endif
#undef __need_ssize_t #undef __need_ssize_t