userspace: Rewrite everything

Everything.

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-01-04 06:27:54 +02:00
parent dea36a0228
commit 6dae34debd
135 changed files with 11707 additions and 5286 deletions

View File

@ -0,0 +1,73 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SYS_MMAN_H
#define _SYS_MMAN_H
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#include <sys/types.h>
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define PROT_NONE 0x0
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_FIXED 0x4
#define MAP_ANONYMOUS 0x8
#define MAP_ANON MAP_ANONYMOUS
#define MS_ASYNC 0x01
#define MS_SYNC 0x02
#define MS_INVALIDATE 0x04
#define MCL_CURRENT 0x01
#define MCL_FUTURE 0x02
#define MAP_FAILED ((void *)-1)
typedef struct posix_typed_mem_info
{
/* Maximum length which may be allocated from a typed memory object. */
size_t posix_tmi_length;
} posix_typed_mem_info;
int mlock(const void *, size_t);
int mlockall(int);
void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
int mprotect(void *addr, size_t len, int prot);
int msync(void *, size_t, int);
int munlock(const void *, size_t);
int munlockall(void);
int munmap(void *addr, size_t len);
int posix_madvise(void *, size_t, int);
int posix_mem_offset(const void *restrict, size_t, off_t *restrict, size_t *restrict, int *restrict);
int posix_typed_mem_get_info(int, struct posix_typed_mem_info *);
int posix_typed_mem_open(const char *, int, int);
int shm_open(const char *, int, mode_t);
int shm_unlink(const char *);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !_SYS_MMAN_H

View File

@ -1,18 +1,108 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SYS_STAT_H
#define _SYS_STAT_H
typedef unsigned int __dev_t;
typedef unsigned short __ino_t;
typedef unsigned short __mode_t;
typedef long __off_t;
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#define dev_t __dev_t
#define ino_t __ino_t
#define mode_t __mode_t
#define off_t __off_t
#include <time.h>
int mkdir(const char *path, mode_t mode);
int remove(const char *pathname);
int rename(const char *oldpath, const char *newpath);
struct stat
{
dev_t st_dev; /* Device ID of device containing file. */
ino_t st_ino; /* File serial number. */
mode_t st_mode; /* Mode of file (see below). */
nlink_t st_nlink; /* Number of hard links to the file. */
uid_t st_uid; /* User ID of file. */
gid_t st_gid; /* Group ID of file. */
dev_t st_rdev; /* Device ID (if file is character or block special). */
off_t st_size; /* For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. For a shared memory object, the length in bytes. For a typed memory object, the length in bytes. For other file types, the use of this field is unspecified. */
struct timespec st_atim; /* Last data access timestamp. */
struct timespec st_mtim; /* Last data modification timestamp. */
struct timespec st_ctim; /* Last file status change timestamp. */
blksize_t st_blksize; /* A file system-specific preferred I/O block size for this object. In some file system types, this may vary from file to file. */
blkcnt_t st_blocks; /* Number of blocks allocated for this object. */
};
#endif
#define S_IFMT
#define S_IFBLK
#define S_IFCHR
#define S_IFIFO
#define S_IFREG
#define S_IFDIR
#define S_IFLNK
#define S_IFSOCK
#define S_IRWXU 0700
#define S_IRUSR 0400
#define S_IWUSR 0200
#define S_IXUSR 0100
#define S_IRWXG 070
#define S_IRGRP 040
#define S_IWGRP 020
#define S_IXGRP 010
#define S_IRWXO 07
#define S_IROTH 04
#define S_IWOTH 02
#define S_IXOTH 01
#define S_ISUID 04000
#define S_ISGID 02000
#define S_ISVTX 01000
#define S_ISBLK(m)
#define S_ISCHR(m)
#define S_ISDIR(m)
#define S_ISFIFO(m)
#define S_ISREG(m)
#define S_ISLNK(m)
#define S_ISSOCK(m)
#define S_TYPEISMQ(buf)
#define S_TYPEISSEM(buf)
#define S_TYPEISSHM(buf)
#define S_TYPEISTMO(buf)
#define UTIME_NOW
#define UTIME_OMIT
int chmod(const char *, mode_t);
int fchmod(int, mode_t);
int fchmodat(int, const char *, mode_t, int);
int fstat(int, struct stat *);
int fstatat(int, const char *restrict, struct stat *restrict, int);
int futimens(int, const struct timespec[2]);
int lstat(const char *restrict, struct stat *restrict);
int mkdir(const char *, mode_t);
int mkdirat(int, const char *, mode_t);
int mkfifo(const char *, mode_t);
int mkfifoat(int, const char *, mode_t);
int mknod(const char *, mode_t, dev_t);
int mknodat(int, const char *, mode_t, dev_t);
int stat(const char *restrict, struct stat *restrict);
mode_t umask(mode_t);
int utimensat(int, const char *, const struct timespec[2], int);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !_SYS_STAT_H

View File

@ -1,6 +0,0 @@
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
#include <sys/types.h>
#endif

View File

@ -1,37 +1,141 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
#ifndef PUBLIC
#define PUBLIC __attribute__((visibility("default")))
#endif // !PUBLIC
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#ifndef PRIVATE
#define PRIVATE __attribute__((visibility("hidden")))
#endif // !PRIVATE
#define __iptr __INTPTR_TYPE__
__iptr __check_errno(__iptr status, __iptr err);
typedef int __pid_t;
typedef int __ssize_t;
typedef unsigned int __id_t;
typedef unsigned int __useconds_t;
#ifndef restrict
#define restrict __restrict__
#endif // restrict
#ifndef __pid_t_defined
typedef __pid_t pid_t;
#define __pid_t_defined
#ifndef export
#define export __attribute__((__visibility__("default")))
#endif // export
typedef long blkcnt_t;
typedef long blksize_t;
typedef long clock_t;
typedef int clockid_t;
typedef unsigned long dev_t;
typedef unsigned long fsblkcnt_t;
typedef unsigned long fsfilcnt_t;
typedef unsigned int gid_t;
typedef unsigned int id_t;
typedef unsigned long ino_t;
typedef unsigned short reclen_t;
typedef int key_t;
typedef unsigned int mode_t;
typedef unsigned int nlink_t;
typedef long off_t;
typedef int pid_t;
typedef struct pthread_attr_t
{
char __data;
} pthread_attr_t;
typedef struct pthread_cond_t
{
char __data;
} pthread_cond_t;
typedef struct pthread_condattr_t
{
char __data;
} pthread_condattr_t;
typedef unsigned int pthread_key_t;
typedef struct pthread_mutex_t
{
short locked;
char __data;
} pthread_mutex_t;
typedef struct pthread_mutexattr_t
{
char __data;
} pthread_mutexattr_t;
typedef struct pthread_once_t
{
int __initialized;
} pthread_once_t;
typedef struct pthread_rwlock_t
{
char __data;
} pthread_rwlock_t;
typedef struct pthread_rwlockattr_t
{
char __data;
} pthread_rwlockattr_t;
typedef struct pthread_barrier_t
{
char __data;
} pthread_barrier_t;
typedef unsigned long size_t;
typedef long ssize_t;
typedef long suseconds_t;
typedef long time_t;
typedef int timer_t;
typedef unsigned int uid_t;
typedef unsigned int useconds_t;
typedef struct __pthread
{
struct __pthread *Self;
/* For __tls_get_addr */
__UINTPTR_TYPE__ *Storage;
int CurrentError;
} __pthread;
#ifdef __cplusplus
typedef unsigned long pthread_t;
#else
typedef struct __pthread *pthread_t;
#endif
#ifndef __id_t_defined
typedef __id_t id_t;
#define __id_t_defined
#endif
#ifdef __cplusplus
}
#endif // __cplusplus
#ifndef __useconds_t_defined
typedef __useconds_t useconds_t;
#define __useconds_t_defined
#endif
#ifndef __ssize_t_defined
typedef __ssize_t ssize_t;
#define __ssize_t_defined
#endif
#endif
#endif // !_SYS_TYPES_H

View File

@ -1,108 +1,65 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SYS_WAIT_H
#define _SYS_WAIT_H
#include <sys/types.h>
typedef enum
#ifdef __cplusplus
extern "C"
{
P_ALL, /* Wait for any child. */
P_PID, /* Wait for specified process. */
P_PGID /* Wait for members of process group. */
} idtype_t;
#endif // __cplusplus
typedef struct
{
int stub;
} siginfo_t;
#include <signal.h>
#include <bits/waitstatus.h>
/* waitpid() */
#define WCONTINUED 0x00000008
#define WNOHANG 0x00000001
#define WUNTRACED 0x00000002
#define WCONTINUED 1
#define WNOHANG 2
#define WUNTRACED 4
#define WEXITED 8
#define WNOWAIT 16
#define WSTOPPED 32
/* waitid() */
#define WEXITED 0x00000004
#define WNOWAIT 0x00000020
#define WSTOPPED 0x00000002
/**
* @brief Macro for extracting the exit status from a status value.
*
* If the child process terminated normally by calling exit(3) or _exit(2),
* the macro WEXITSTATUS() returns the low-order 8 bits of the status value.
*
* @param status The status value to extract the exit status from.
* @return The exit status of the child process.
*/
#define WEXITSTATUS(status) __WEXITSTATUS(status)
#define WCOREDUMP(status) ((status) & 0x80)
#define WEXITSTATUS(status) (((status) >> 8) & 0xFF)
#define WIFCONTINUED(status) ((status) == 0xFFFF)
#define WIFEXITED(status) (((status) & 0x7F) == 0)
#define WIFSIGNALED(status) (((status) & 0x7F) > 0 && (((status) & 0x7F) != 0x7F))
#define WIFSTOPPED(status) (((status) & 0xFF) == 0x7F)
#define WSTOPSIG(status) WEXITSTATUS(status)
#define WTERMSIG(status) ((status) & 0x7F)
/**
* @brief Macro for extracting the termination signal from a status value.
*
* If the child process was terminated by a signal, the macro WTERMSIG()
* returns the signal number of the terminating signal.
*
* @param status The status value to extract the termination signal from.
* @return The termination signal of the child process.
*/
#define WTERMSIG(status) __WTERMSIG(status)
typedef enum
{
P_ALL,
P_PGID,
P_PID
} idtype_t;
/**
* @brief Macro for extracting the stop signal from a status value.
*
* If the child process was stopped by a signal, the macro WSTOPSIG()
* returns the signal number of the stop signal.
*
* @param status The status value to extract the stop signal from.
* @return The stop signal of the child process.
*/
#define WSTOPSIG(status) __WSTOPSIG(status)
typedef unsigned int id_t;
typedef int pid_t;
/**
* @brief Macro for testing whether a process exited normally.
*
* If the child process terminated normally by calling exit(3) or _exit(2),
* the macro WIFEXITED() returns a nonzero value. Otherwise, it returns 0.
*
* @param status The status value to test.
* @return A nonzero value if the child process exited normally, 0 otherwise.
*/
#define WIFEXITED(status) __WIFEXITED(status)
pid_t wait(int *);
int waitid(idtype_t, id_t, siginfo_t *, int);
pid_t waitpid(pid_t, int *, int);
/**
* @brief Macro for testing whether a process was terminated by a signal.
*
* If the child process was terminated by a signal, the macro WIFSIGNALED()
* returns a nonzero value. Otherwise, it returns 0.
*
* @param status The status value to test.
* @return A nonzero value if the child process was terminated by a signal, 0 otherwise.
*/
#define WIFSIGNALED(status) __WIFSIGNALED(status)
#ifdef __cplusplus
}
#endif // __cplusplus
/**
* @brief Macro for testing whether a process was stopped by a signal.
*
* If the child process was stopped by a signal, the macro WIFSTOPPED()
* returns a nonzero value. Otherwise, it returns 0.
*
* @param status The status value to test.
* @return A nonzero value if the child process was stopped by a signal, 0 otherwise.
*/
#define WIFSTOPPED(status) __WIFSTOPPED(status)
/**
* @brief Macro for testing whether a stopped process was continued.
*
* If the child process was stopped and has been resumed by delivery of SIGCONT,
* the macro WIFCONTINUED() returns a nonzero value. Otherwise, it returns 0.
*
* @param status The status value to test.
* @return A nonzero value if the child process was continued, 0 otherwise.
*/
#define WIFCONTINUED(status) __WIFCONTINUED(status)
pid_t wait(int *wstatus);
pid_t waitpid(pid_t pid, int *wstatus, int options);
int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
#endif
#endif // !_SYS_WAIT_H