mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-02 02:49:15 +00:00
refactor(userspace): build using cmake
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
58
Userspace/libc/sysdeps/fennix/generic/dl_start.c
Normal file
58
Userspace/libc/sysdeps/fennix/generic/dl_start.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifdef FENNIX_DYNAMIC_LOADER
|
||||
__attribute__((naked, used, no_stack_protector)) void _dl_start()
|
||||
{
|
||||
#if defined(__amd64__)
|
||||
__asm__(
|
||||
"xorq %rbp, %rbp\n" /* Clear rbp */
|
||||
|
||||
"push %rdi\n"
|
||||
"push %rsi\n"
|
||||
"push %rdx\n"
|
||||
"push %rcx\n"
|
||||
"push %r8\n"
|
||||
"push %r9\n"
|
||||
|
||||
"call __init_print_buffer\n" /* Call __init_print_buffer */
|
||||
"call _dl_preload\n" /* Call _dl_preload */
|
||||
"movl %eax, %edi\n" /* Move return value to edi */
|
||||
"cmp $0, %edi\n" /* Check if return value is 0 */
|
||||
"jne _exit\n" /* If not, jump to _exit */
|
||||
|
||||
"pop %r9\n"
|
||||
"pop %r8\n"
|
||||
"pop %rcx\n"
|
||||
"pop %rdx\n"
|
||||
"pop %rsi\n"
|
||||
"pop %rdi\n"
|
||||
|
||||
"call main\n" /* Call _dl_main */
|
||||
"movl %eax, %edi\n" /* Move return value to edi */
|
||||
"call _exit\n"); /* Call _exit */
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 _start not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm _start not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
#warning "aarch64 _start not implemented"
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
}
|
||||
#endif
|
60
Userspace/libc/sysdeps/fennix/generic/syscall_check.cpp
Normal file
60
Userspace/libc/sysdeps/fennix/generic/syscall_check.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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 <bits/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( == );
|
191
Userspace/libc/sysdeps/fennix/generic/syscalls.c
Normal file
191
Userspace/libc/sysdeps/fennix/generic/syscalls.c
Normal file
@ -0,0 +1,191 @@
|
||||
/*
|
||||
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 <bits/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <string.h>
|
||||
|
||||
void sysdep(Exit)(int Status)
|
||||
{
|
||||
call_exit(Status);
|
||||
}
|
||||
|
||||
int sysdep(Accept)(int Socket, struct sockaddr *restrict Address, socklen_t *restrict AddressLength)
|
||||
{
|
||||
return call_accept(Socket, Address, AddressLength);
|
||||
}
|
||||
|
||||
int sysdep(Bind)(int Socket, const struct sockaddr *Address, socklen_t AddressLength)
|
||||
{
|
||||
return call_bind(Socket, Address, AddressLength);
|
||||
}
|
||||
|
||||
int sysdep(Connect)(int Socket, const struct sockaddr *Address, socklen_t AddressLength)
|
||||
{
|
||||
return call_connect(Socket, Address, AddressLength);
|
||||
}
|
||||
|
||||
int sysdep(Listen)(int Socket, int Backlog)
|
||||
{
|
||||
return call_listen(Socket, Backlog);
|
||||
}
|
||||
|
||||
int sysdep(Socket)(int Domain, int Type, int Protocol)
|
||||
{
|
||||
return call_socket(Domain, Type, Protocol);
|
||||
}
|
||||
|
||||
int sysdep(UnixName)(struct utsname *Name)
|
||||
{
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int sysdep(WaitProcessID)(pid_t ProcessID, int *Status, int Options)
|
||||
{
|
||||
return call_waitpid(ProcessID, Status, Options);
|
||||
}
|
||||
|
||||
int sysdep(IOControl)(int Descriptor, unsigned long Operation, void *Argument)
|
||||
{
|
||||
return call_ioctl(Descriptor, Operation, Argument);
|
||||
}
|
||||
|
||||
void *sysdep(MemoryMap)(void *Address, size_t Length, int Protection, int Flags, int Descriptor, off_t Offset)
|
||||
{
|
||||
return (void *)call_mmap(Address, Length, Protection, Flags, Descriptor, Offset);
|
||||
}
|
||||
|
||||
int sysdep(MemoryUnmap)(void *Address, size_t Length)
|
||||
{
|
||||
return call_munmap(Address, Length);
|
||||
}
|
||||
|
||||
int sysdep(MemoryProtect)(void *Address, size_t Length, int Protection)
|
||||
{
|
||||
return call_mprotect(Address, Length, Protection);
|
||||
}
|
||||
|
||||
int sysdep(Fork)(void)
|
||||
{
|
||||
return call_fork();
|
||||
}
|
||||
|
||||
int sysdep(Read)(int Descriptor, void *Buffer, size_t Size)
|
||||
{
|
||||
return call_read(Descriptor, Buffer, Size);
|
||||
}
|
||||
|
||||
int sysdep(Write)(int Descriptor, const void *Buffer, size_t Size)
|
||||
{
|
||||
return call_write(Descriptor, Buffer, Size);
|
||||
}
|
||||
|
||||
int sysdep(PRead)(int Descriptor, void *Buffer, size_t Size, off_t Offset)
|
||||
{
|
||||
return call_pread(Descriptor, Buffer, Size, Offset);
|
||||
}
|
||||
|
||||
int sysdep(PWrite)(int Descriptor, const void *Buffer, size_t Size, off_t Offset)
|
||||
{
|
||||
return call_pwrite(Descriptor, Buffer, Size, Offset);
|
||||
}
|
||||
|
||||
int sysdep(Open)(const char *Pathname, int Flags, mode_t Mode)
|
||||
{
|
||||
return call_open(Pathname, Flags, Mode);
|
||||
}
|
||||
|
||||
int sysdep(Close)(int Descriptor)
|
||||
{
|
||||
return call_close(Descriptor);
|
||||
}
|
||||
|
||||
int sysdep(Access)(const char *Pathname, int Mode)
|
||||
{
|
||||
return call_access(Pathname, Mode);
|
||||
}
|
||||
|
||||
int sysdep(Tell)(int Descriptor)
|
||||
{
|
||||
return call_tell(Descriptor);
|
||||
}
|
||||
|
||||
int sysdep(Seek)(int Descriptor, off_t Offset, int Whence)
|
||||
{
|
||||
return call_seek(Descriptor, Offset, Whence);
|
||||
}
|
||||
|
||||
pid_t sysdep(GetProcessID)(void)
|
||||
{
|
||||
return call_getpid();
|
||||
}
|
||||
|
||||
pid_t sysdep(GetParentProcessID)(void)
|
||||
{
|
||||
return call_getppid();
|
||||
}
|
||||
|
||||
int sysdep(Execve)(const char *Pathname, char *const *Argv, char *const *Envp)
|
||||
{
|
||||
return call_execve(Pathname, Argv, Envp);
|
||||
}
|
||||
|
||||
int sysdep(Kill)(pid_t ProcessID, int Signal)
|
||||
{
|
||||
return call_kill(ProcessID, Signal);
|
||||
}
|
||||
|
||||
int sysdep(Stat)(const char *Pathname, struct stat *Statbuf)
|
||||
{
|
||||
return call_stat(Pathname, Statbuf);
|
||||
}
|
||||
|
||||
int sysdep(FStat)(int Descriptor, struct stat *Statbuf)
|
||||
{
|
||||
return call_fstat(Descriptor, Statbuf);
|
||||
}
|
||||
|
||||
int sysdep(LStat)(const char *Pathname, struct stat *Statbuf)
|
||||
{
|
||||
return call_lstat(Pathname, Statbuf);
|
||||
}
|
||||
|
||||
int sysdep(Truncate)(const char *Pathname, off_t Length)
|
||||
{
|
||||
return call_truncate(Pathname, Length);
|
||||
}
|
||||
|
||||
int sysdep(MakeDirectory)(const char *Pathname, mode_t Mode)
|
||||
{
|
||||
return call_mkdir(Pathname, Mode);
|
||||
}
|
||||
|
||||
int sysdep(ProcessControl)(unsigned long Option, unsigned long Arg1, unsigned long Arg2, unsigned long Arg3, unsigned long Arg4)
|
||||
{
|
||||
return call_prctl(Option, Arg1, Arg2, Arg3, Arg4);
|
||||
}
|
46
Userspace/libc/sysdeps/fennix/generic/tls.c
Normal file
46
Userspace/libc/sysdeps/fennix/generic/tls.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
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 <bits/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef FENNIX_DYNAMIC_LOADER
|
||||
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,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE,
|
||||
-1, 0);
|
||||
call_prctl(__SYS_SET_FS, ptr, 0, 0, 0);
|
||||
ptr->Self = ptr;
|
||||
ptr->CurrentError = 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user