refactor(userspace): build using cmake

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-03-15 23:05:17 +00:00
parent 40f46312f8
commit 201ace7eec
73 changed files with 2819 additions and 2255 deletions

View File

@ -0,0 +1,33 @@
file(GLOB_RECURSE SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE SYSDEPS_SOURCES ${SYSDEPS_PATH}/*.c ${SYSDEPS_GENERIC}/*.c ${SYSDEPS_PATH}/*.cpp ${SYSDEPS_GENERIC}/*.cpp)
list(APPEND SRC_FILES ${SYSDEPS_SOURCES})
add_library(libc_obj OBJECT ${SRC_FILES})
set_target_properties(libc_obj PROPERTIES POSITION_INDEPENDENT_CODE 1)
message(STATUS "Adding sysdeps sources: ${SYSDEPS_SOURCES}")
add_library(libc_shared SHARED $<TARGET_OBJECTS:libc_obj>)
set_target_properties(libc_shared PROPERTIES OUTPUT_NAME "c")
target_compile_definitions(libc_shared PRIVATE PROGRAM_VERSION="${PROJECT_VERSION}")
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_COMMIT)
target_compile_definitions(libc_shared PRIVATE LIBC_GIT_COMMIT="${GIT_COMMIT}")
endif()
target_compile_options(libc_shared PRIVATE -fvisibility=hidden -fPIC)
target_link_options(libc_shared PRIVATE -nostdlib -shared -fPIC -fPIE -e _start -Wl,-soname,libc.so -lgcc)
add_library(libc_static STATIC $<TARGET_OBJECTS:libc_obj>)
set_target_properties(libc_static PROPERTIES OUTPUT_NAME "c")
target_compile_options(libc_static PRIVATE -fvisibility=hidden -fPIC)
install(TARGETS libc_shared libc_static DESTINATION lib)

View File

@ -1,48 +0,0 @@
default:
$(error Do not run this Makefile directly!)
DYNAMIC_NAME := libc.so
STATIC_NAME := libc.a
OUTPUT_DIR=$(WORKSPACE_DIR)/out/lib/
SYSROOT = --sysroot=$(WORKSPACE_DIR)/out/
S_SOURCES = $(shell find ./ -type f -name '*.S')
C_SOURCES = $(shell find ./ -type f -name '*.c')
CXX_SOURCES = $(shell find ./ -type f -name '*.cpp')
OBJ = ${S_SOURCES:.S=.o} ${C_SOURCES:.c=.o} ${CXX_SOURCES:.cpp=.o}
CFLAGS := -fvisibility=hidden -fPIC -I../include -I$(WORKSPACE_DIR)/out/include -DLIBC_GIT_COMMIT='"$(shell git rev-parse HEAD)"'
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always
endif
build: $(DYNAMIC_NAME) $(STATIC_NAME)
.PHONY: $(DYNAMIC_NAME) $(STATIC_NAME)
$(DYNAMIC_NAME): $(OBJ)
$(info Linking $@)
$(CC) -nostdlib -shared -fPIC -fPIE -e _start -Wl,-soname,$(DYNAMIC_NAME) $(SYSROOT) $(OBJ) -o $(DYNAMIC_NAME) -lgcc
cp $(DYNAMIC_NAME) $(OUTPUT_DIR)$(DYNAMIC_NAME)
$(STATIC_NAME): $(OBJ)
$(info Linking $@)
$(AR) -rcs $(STATIC_NAME) $(OBJ)
cp $(STATIC_NAME) $(OUTPUT_DIR)$(STATIC_NAME)
%.o: %.c
$(info Compiling $<)
$(CC) $(CFLAGS) -std=c17 -c $< -o $@
%.o: %.cpp
$(info Compiling $<)
$(CC) $(CFLAGS) -std=c++20 -c $< -o $@
%.o: %.S
$(info Compiling $<)
$(AS) -c $< -o $@
clean:
rm -f $(OBJ) $(DYNAMIC_NAME) $(STATIC_NAME)

View File

@ -15,8 +15,7 @@
along with Fennix Userspace. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <stdio.h>
int __init_pthread(void);
@ -34,7 +33,7 @@ __attribute__((visibility("default"))) void _exit(int Code)
{
fflush(stdout);
fflush(stderr);
call_exit(Code);
sysdep(Exit)(Code);
while (1)
;
}

View File

@ -15,8 +15,6 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../runtime/crt1.c"
const char __interp[] __attribute__((section(".interp"))) = "/lib/ld.so";
#ifndef LIBC_GIT_COMMIT
@ -47,6 +45,23 @@ const char __interp[] __attribute__((section(".interp"))) = "/lib/ld.so";
CONVERT_TO_BYTE(hex[36], hex[37]), \
CONVERT_TO_BYTE(hex[38], hex[39])}
typedef struct Elf_Nhdr
{
__UINT32_TYPE__ n_namesz;
__UINT32_TYPE__ n_descsz;
__UINT32_TYPE__ n_type;
char n_name[];
} __attribute__((packed)) Elf_Nhdr;
/* These are declared in GNU ld */
enum
{
NT_FNX_ABI_TAG = 1,
NT_FNX_VERSION = 2,
NT_FNX_BUILD_ID = 3,
NT_FNX_ARCH = 4
};
const struct
{
Elf_Nhdr header;

View File

@ -15,6 +15,7 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <arpa/inet.h>
#include <stdint.h>

View File

@ -15,10 +15,15 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <sys/types.h>
#include <pthread.h>
#include <errno.h>
#ifndef EOK
#define EOK 0
#endif
__iptr __check_errno(__iptr status, __iptr err)
{
if ((int)status >= EOK)
@ -37,9 +42,6 @@ export char *strerror(int errnum)
if (errnum < 0)
errnum = -errnum;
if (errnum > __ERRNO_MAX)
return (char *)"Not a valid error number";
switch (errnum)
{
case EOK:

View File

@ -15,8 +15,8 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -37,7 +37,7 @@ export int open(const char *path, int oflag, ...)
mode = va_arg(args, mode_t);
va_end(args);
}
return __check_errno(call_open(path, oflag, mode), -1);
return __check_errno(sysdep(Open)(path, oflag, mode), -1);
}
export int openat(int fd, const char *path, int oflag, ...);

View File

@ -15,6 +15,7 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <sys/types.h>
#include <fenv.h>

View File

@ -20,6 +20,7 @@
#include <float.h>
#include <errno.h>
#include <inttypes.h>
#include <bits/libc.h>
#include <fenv.h>
export int signgam;

View File

@ -15,6 +15,7 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <pthread.h>
#include <errno.h>

View File

@ -15,13 +15,14 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
export int kill(pid_t pid, int sig)
{
return call_kill(pid, sig);
return sysdep(Kill)(pid, sig);
}
export int killpg(pid_t, int);

View File

@ -19,7 +19,8 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <fcntl.h>
#include "../print/printf.h"
struct _IO_FILE *_i_open_files[256];
@ -74,7 +75,7 @@ export int fclose(FILE *stream)
if (stream->buffer)
free(stream->buffer);
call_close(stream->fd);
sysdep(Close)(stream->fd);
_i_open_files[stream->fd] = NULL;
free(stream);
return 0;
@ -105,7 +106,7 @@ export int fflush(FILE *stream)
{
if (stream->buffer_pos > 0)
{
ssize_t written = call_write(stream->fd, stream->buffer, stream->buffer_pos);
ssize_t written = sysdep(Write)(stream->fd, stream->buffer, stream->buffer_pos);
if (written < 0)
{
stream->error = 1;
@ -129,7 +130,7 @@ export int fgetc(FILE *stream)
if (stream->buffer_pos >= stream->buffer_size)
{
int res = call_read(stream->fd, stream->buffer, 4096);
int res = sysdep(Read)(stream->fd, stream->buffer, 4096);
if (res <= 0)
{
if (res == 0)
@ -180,33 +181,33 @@ export FILE *fopen(const char *restrict pathname, const char *restrict mode)
mode_t perm = 0;
if (strcmp(mode, "r") == 0)
flags = __SYS_O_RDONLY;
flags = O_RDONLY;
else if (strcmp(mode, "r+") == 0)
flags = __SYS_O_RDWR;
flags = O_RDWR;
else if (strcmp(mode, "w") == 0)
{
flags = __SYS_O_WRONLY | __SYS_O_CREAT | __SYS_O_TRUNC;
flags = O_WRONLY | O_CREAT | O_TRUNC;
perm = 0644;
}
else if (strcmp(mode, "w+") == 0)
{
flags = __SYS_O_RDWR | __SYS_O_CREAT | __SYS_O_TRUNC;
flags = O_RDWR | O_CREAT | O_TRUNC;
perm = 0644;
}
else if (strcmp(mode, "a") == 0)
{
flags = __SYS_O_WRONLY | __SYS_O_CREAT | __SYS_O_APPEND;
flags = O_WRONLY | O_CREAT | O_APPEND;
perm = 0644;
}
else if (strcmp(mode, "a+") == 0)
{
flags = __SYS_O_RDWR | __SYS_O_CREAT | __SYS_O_APPEND;
flags = O_RDWR | O_CREAT | O_APPEND;
perm = 0644;
}
else
return NULL;
int fd = call_open(pathname, flags, perm);
int fd = sysdep(Open)(pathname, flags, perm);
if (fd < 0)
return NULL;
@ -274,7 +275,7 @@ export size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restri
{
if (stream->buffer_pos >= stream->buffer_size)
{
int res = call_read(stream->fd, stream->buffer, stream->buffer_size);
int res = sysdep(Read)(stream->fd, stream->buffer, stream->buffer_size);
if (res <= 0)
{
if (res == 0)
@ -305,7 +306,7 @@ export int fscanf(FILE *restrict, const char *restrict, ...);
export int fseek(FILE *stream, long offset, int whence)
{
int res = call_seek(stream->fd, offset, whence);
int res = sysdep(Seek)(stream->fd, offset, whence);
if (res < 0)
{
stream->error = 1;
@ -321,7 +322,7 @@ export int fsetpos(FILE *, const fpos_t *);
export long ftell(FILE *stream)
{
return call_tell(stream->fd);
return sysdep(Tell)(stream->fd);
}
export off_t ftello(FILE *);
@ -347,7 +348,7 @@ export size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE
if (stream->buffer_pos == stream->buffer_size)
{
if (call_write(stream->fd, stream->buffer, stream->buffer_size) != stream->buffer_size)
if (sysdep(Write)(stream->fd, stream->buffer, stream->buffer_size) != stream->buffer_size)
{
stream->error = 1;
break;

View File

@ -17,7 +17,7 @@
#include <sys/types.h>
#include <string.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

View File

@ -16,7 +16,7 @@
*/
#include <sys/ioctl.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <stdarg.h>
#include <errno.h>
@ -27,6 +27,6 @@ export int ioctl(int fd, unsigned long op, ...)
va_start(args, op);
arg = va_arg(args, void *);
va_end(args);
int ret = call_ioctl(fd, op, arg);
int ret = sysdep(IOControl)(fd, op, arg);
return __check_errno(ret, -1);
}

View File

@ -16,7 +16,7 @@
*/
#include <sys/mman.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <errno.h>
export int mlock(const void *, size_t);
@ -24,12 +24,12 @@ export int mlockall(int);
export void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
{
return (void *)__check_errno((__iptr)call_mmap(addr, len, prot, flags, fildes, off), (__iptr)MAP_FAILED);
return (void *)__check_errno((__iptr)sysdep(MemoryMap)(addr, len, prot, flags, fildes, off), (__iptr)MAP_FAILED);
}
export int mprotect(void *addr, size_t len, int prot)
{
return __check_errno(call_mprotect(addr, len, prot), -1);
return __check_errno(sysdep(MemoryProtect)(addr, len, prot), -1);
}
export int msync(void *, size_t, int);
@ -38,7 +38,7 @@ export int munlockall(void);
export int munmap(void *addr, size_t len)
{
return __check_errno(call_munmap(addr, len), -1);
return __check_errno(sysdep(MemoryUnmap)(addr, len), -1);
}
export int posix_madvise(void *, size_t, int);

View File

@ -17,23 +17,23 @@
#include <sys/socket.h>
#include <errno.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
export int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len)
{
return __check_errno(call_accept(socket, address, address_len), -1);
return __check_errno(sysdep(Accept)(socket, address, address_len), -1);
}
export int accept4(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len, int flag);
export int bind(int socket, const struct sockaddr *address, socklen_t address_len)
{
return __check_errno(call_bind(socket, address, address_len), -1);
return __check_errno(sysdep(Bind)(socket, address, address_len), -1);
}
export int connect(int socket, const struct sockaddr *address, socklen_t address_len)
{
return __check_errno(call_connect(socket, address, address_len), -1);
return __check_errno(sysdep(Connect)(socket, address, address_len), -1);
}
export int getpeername(int, struct sockaddr *restrict, socklen_t *restrict);
@ -42,7 +42,7 @@ export int getsockopt(int, int, int, void *restrict, socklen_t *restrict);
export int listen(int socket, int backlog)
{
return __check_errno(call_listen(socket, backlog), -1);
return __check_errno(sysdep(Listen)(socket, backlog), -1);
}
export ssize_t recv(int, void *, size_t, int);
@ -57,7 +57,7 @@ export int sockatmark(int);
export int socket(int domain, int type, int protocol)
{
return __check_errno(call_socket(domain, type, protocol), -1);
return __check_errno(sysdep(Socket)(domain, type, protocol), -1);
}
export int socketpair(int, int, int, int[2]);

View File

@ -15,6 +15,7 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
@ -31,7 +32,7 @@ export int fstat(int fildes, struct stat *buf)
return -1;
}
return __check_errno(call_fstat(fildes, buf), -1);
return __check_errno(sysdep(FStat)(fildes, buf), -1);
}
export int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag)
@ -58,12 +59,12 @@ export int lstat(const char *restrict path, struct stat *restrict buf)
return -1;
}
return __check_errno(call_lstat(path, buf), -1);
return __check_errno(sysdep(LStat)(path, buf), -1);
}
export int mkdir(const char *path, mode_t mode)
{
return __check_errno(call_mkdir(path, mode), -1);
return __check_errno(sysdep(MakeDirectory)(path, mode), -1);
}
export int mkdirat(int fd, const char *path, mode_t mode)
@ -85,7 +86,7 @@ export int stat(const char *restrict path, struct stat *restrict buf)
return -1;
}
return __check_errno(call_stat(path, buf), -1);
return __check_errno(sysdep(Stat)(path, buf), -1);
}
export mode_t umask(mode_t);

View File

@ -21,7 +21,7 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
export int uname(struct utsname *name)
{
@ -31,16 +31,8 @@ export int uname(struct utsname *name)
return -1;
}
struct kutsname kname;
int result = call_uname(&kname);
if (result == 0)
{
strcpy(name->sysname, kname.sysname);
strcpy(name->release, kname.release);
strcpy(name->version, kname.version);
strcpy(name->machine, kname.machine);
}
else
int result = sysdep(UnixName)(name);
if (result != 0)
{
errno = result;
return -1;

View File

@ -16,7 +16,7 @@
*/
#include <sys/wait.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
@ -34,5 +34,5 @@ export int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
export pid_t waitpid(pid_t pid, int *stat_loc, int options)
{
return __check_errno(call_waitpid(pid, stat_loc, options), -1);
return __check_errno(sysdep(WaitProcessID)(pid, stat_loc, options), -1);
}

View File

@ -15,6 +15,7 @@
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <bits/libc.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <errno.h>

View File

@ -22,7 +22,7 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <fennix/syscalls.h>
#include <bits/libc.h>
#include <fcntl.h>
export char *optarg;
@ -44,7 +44,7 @@ export int chown(const char *, uid_t, gid_t);
export int close(int fildes)
{
return __check_errno(call_close(fildes), -1);
return __check_errno(sysdep(Close)(fildes), -1);
}
export size_t confstr(int, char *, size_t);
@ -130,7 +130,7 @@ export int execv(const char *path, char *const argv[])
export int execve(const char *path, char *const argv[], char *const envp[])
{
return __check_errno(call_execve(path, argv, envp), -1);
return __check_errno(sysdep(Execve)(path, argv, envp), -1);
}
export int execvp(const char *file, char *const argv[])
@ -167,7 +167,7 @@ export int fdatasync(int);
export pid_t fork(void)
{
return __check_errno(call_fork(), -1);
return __check_errno(sysdep(Fork)(), -1);
}
export long int fpathconf(int, int);
@ -225,12 +225,12 @@ export pid_t getpgrp(void);
export pid_t getpid(void)
{
return call_getpid();
return sysdep(GetProcessID)();
}
export pid_t getppid(void)
{
return call_getppid();
return sysdep(GetParentProcessID)();
}
export pid_t getsid(pid_t);
@ -261,19 +261,19 @@ export int pipe(int[2]);
export ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
{
return __check_errno(call_pread(fildes, buf, nbyte, offset), -1);
return __check_errno(sysdep(PRead)(fildes, buf, nbyte, offset), -1);
}
export int pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
export ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
{
return __check_errno(call_pwrite(fildes, buf, nbyte, offset), -1);
return __check_errno(sysdep(PWrite)(fildes, buf, nbyte, offset), -1);
}
export ssize_t read(int fildes, void *buf, size_t nbyte)
{
return __check_errno(call_read(fildes, buf, nbyte), -1);
return __check_errno(sysdep(Read)(fildes, buf, nbyte), -1);
}
export int readlink(const char *, char *, size_t);
@ -324,5 +324,5 @@ export pid_t vfork(void);
export ssize_t write(int fildes, const void *buf, size_t nbyte)
{
return __check_errno(call_write(fildes, buf, nbyte), -1);
return __check_errno(sysdep(Write)(fildes, buf, nbyte), -1);
}

View File

@ -1,60 +0,0 @@
/*
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/>.
*/
#include <fennix/syscalls.h>
#include <sys/mman.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
static_assert(__SYS_PROT_READ == PROT_READ);
static_assert(__SYS_PROT_WRITE == PROT_WRITE);
static_assert(__SYS_PROT_EXEC == PROT_EXEC);
static_assert(__SYS_PROT_NONE == PROT_NONE);
static_assert(__SYS_MAP_SHARED == MAP_SHARED);
static_assert(__SYS_MAP_PRIVATE == MAP_PRIVATE);
static_assert(__SYS_MAP_FIXED == MAP_FIXED);
static_assert(__SYS_MAP_ANONYMOUS == MAP_ANONYMOUS);
static_assert(__SYS_MAP_ANON == MAP_ANON);
static_assert(__SYS_F_OK == F_OK);
static_assert(__SYS_R_OK == R_OK);
static_assert(__SYS_W_OK == W_OK);
static_assert(__SYS_X_OK == X_OK);
static_assert(sizeof(__SYS_clockid_t) == sizeof(clockid_t));
// static_assert(sizeof(__SYS_socklen_t) == sizeof(socklen_t));
static_assert(__SYS_SEEK_SET == SEEK_SET);
static_assert(__SYS_SEEK_CUR == SEEK_CUR);
static_assert(__SYS_SEEK_END == SEEK_END);
static_assert(__SYS_SA_NOCLDSTOP == SA_NOCLDSTOP);
static_assert(__SYS_SA_NOCLDWAIT == SA_NOCLDWAIT);
static_assert(__SYS_SA_SIGINFO == SA_SIGINFO);
static_assert(__SYS_SA_ONSTACK == SA_ONSTACK);
static_assert(__SYS_SA_RESTART == SA_RESTART);
static_assert(__SYS_SA_NODEFER == SA_NODEFER);
static_assert(__SYS_SA_RESETHAND == SA_RESETHAND);
static_assert(__SYS_CLOCK_MONOTONIC == CLOCK_MONOTONIC);
static_assert(__SYS_CLOCK_PROCESS_CPUTIME_ID == CLOCK_PROCESS_CPUTIME_ID);
static_assert(__SYS_CLOCK_REALTIME == CLOCK_REALTIME);
static_assert(__SYS_CLOCK_THREAD_CPUTIME_ID == CLOCK_THREAD_CPUTIME_ID);
// static_assert( == );

View File

@ -1,44 +0,0 @@
/*
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/>.
*/
#include <fennix/syscalls.h>
#include <sys/types.h>
#include <inttypes.h>
#include <stddef.h>
#include <fennix/syscalls.h>
export __attribute__((naked, used, no_stack_protector)) void *__tls_get_addr(void *__data)
{
#warning "__tls_get_addr not implemented"
#if defined(__amd64__) || defined(__i386__)
__asm__("ud2");
#endif
}
int __init_pthread(void)
{
__pthread *ptr = (__pthread *)call_mmap(0,
0x1000,
__SYS_PROT_READ | __SYS_PROT_WRITE,
__SYS_MAP_ANONYMOUS | __SYS_MAP_PRIVATE,
-1, 0);
call_prctl(__SYS_SET_FS, ptr, 0, 0, 0);
ptr->Self = ptr;
ptr->CurrentError = 0;
return 0;
}