mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-07-10 14:49:22 +00:00
Update userspace
This commit is contained in:
@ -5,22 +5,15 @@
|
||||
|
||||
uintptr_t RequestPages(size_t Count)
|
||||
{
|
||||
return syscall1(sys_RequestPages, Count);
|
||||
return syscall6(sc_mmap, NULL, Count * 0x1000,
|
||||
sc_PROT_READ | sc_PROT_WRITE,
|
||||
sc_MAP_ANONYMOUS | sc_MAP_PRIVATE,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
int FreePages(uintptr_t Address, size_t Count)
|
||||
{
|
||||
return syscall2(sys_FreePages, Address, Count);
|
||||
}
|
||||
|
||||
int IPC(int Command, int Type, int ID, int Flags, void *Buffer, size_t Size)
|
||||
{
|
||||
return syscall6(sys_IPC, (long)Command, (long)Type, (long)ID, (long)Flags, (long)Buffer, (long)Size);
|
||||
}
|
||||
|
||||
uintptr_t KernelCTL(int Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4)
|
||||
{
|
||||
return syscall5(sys_KernelCTL, Command, Arg1, Arg2, Arg3, Arg4);
|
||||
return syscall2(sc_munmap, Address, Count * 0x1000);
|
||||
}
|
||||
|
||||
int abs(int i) { return i < 0 ? -i : i; }
|
||||
@ -112,38 +105,38 @@ int strcmp(const char *l, const char *r)
|
||||
|
||||
struct Elf64_Dyn ELFGetDynamicTag(char *Path, enum DynamicTags Tag)
|
||||
{
|
||||
int fd = syscall2(sys_FileOpen, Path, (long)"r");
|
||||
int fd = syscall2(sc_open, Path, (long)"r");
|
||||
if (fd < 0)
|
||||
syscall1(sys_Exit, -0xF17E);
|
||||
syscall1(sc_exit, -0xF17E);
|
||||
|
||||
Elf64_Ehdr ELFHeader;
|
||||
syscall3(sys_FileRead, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
syscall3(sc_read, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Phdr ItrProgramHeader;
|
||||
for (Elf64_Half i = 0; i < ELFHeader.e_phnum; i++)
|
||||
{
|
||||
// memcpy(&ItrProgramHeader, (uint8_t *)ElfFile + ELFHeader.e_phoff + ELFHeader.e_phentsize * i, sizeof(Elf64_Phdr));
|
||||
syscall3(sys_FileSeek, fd, ELFHeader.e_phoff + ELFHeader.e_phentsize * i, SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
syscall3(sc_lseek, fd, ELFHeader.e_phoff + ELFHeader.e_phentsize * i, sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
if (ItrProgramHeader.p_type == PT_DYNAMIC)
|
||||
{
|
||||
struct Elf64_Dyn Dynamic; // = (struct Elf64_Dyn *)((uint8_t *)ElfFile + ItrProgramHeader.p_offset);
|
||||
syscall3(sys_FileSeek, fd, ItrProgramHeader.p_offset, SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &Dynamic, ItrProgramHeader.p_filesz);
|
||||
syscall3(sc_lseek, fd, ItrProgramHeader.p_offset, sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &Dynamic, ItrProgramHeader.p_filesz);
|
||||
for (size_t i = 0; i < ItrProgramHeader.p_filesz / sizeof(struct Elf64_Dyn); i++)
|
||||
{
|
||||
if (Dynamic.d_tag == Tag || Dynamic.d_tag == DT_NULL)
|
||||
{
|
||||
syscall1(sys_FileClose, fd);
|
||||
syscall1(sc_close, fd);
|
||||
return Dynamic;
|
||||
}
|
||||
|
||||
syscall3(sys_FileSeek, fd, ItrProgramHeader.p_offset + (i + 1) * sizeof(struct Elf64_Dyn), SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &Dynamic, sizeof(struct Elf64_Dyn));
|
||||
syscall3(sc_lseek, fd, ItrProgramHeader.p_offset + (i + 1) * sizeof(struct Elf64_Dyn), sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &Dynamic, sizeof(struct Elf64_Dyn));
|
||||
}
|
||||
}
|
||||
}
|
||||
syscall1(sys_FileClose, fd);
|
||||
syscall1(sc_close, fd);
|
||||
return (struct Elf64_Dyn){0};
|
||||
}
|
||||
|
||||
@ -168,12 +161,12 @@ char *GetELFStringTable(Elf64_Ehdr *Header)
|
||||
|
||||
Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
{
|
||||
int fd = syscall2(sys_FileOpen, Path, (long)"r");
|
||||
int fd = syscall2(sc_open, Path, (long)"r");
|
||||
if (fd < 0)
|
||||
syscall1(sys_Exit, -0xF17E);
|
||||
syscall1(sc_exit, -0xF17E);
|
||||
|
||||
Elf64_Ehdr ELFHeader;
|
||||
syscall3(sys_FileRead, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
syscall3(sc_read, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Shdr SymbolTable;
|
||||
Elf64_Shdr StringTable;
|
||||
@ -183,20 +176,20 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
for (Elf64_Half i = 0; i < ELFHeader.e_shnum; i++)
|
||||
{
|
||||
Elf64_Shdr shdr;
|
||||
syscall3(sys_FileSeek, fd,
|
||||
syscall3(sc_lseek, fd,
|
||||
ELFHeader.e_shoff + ELFHeader.e_shentsize * i,
|
||||
SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &shdr, sizeof(Elf64_Shdr));
|
||||
sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &shdr, sizeof(Elf64_Shdr));
|
||||
|
||||
switch (shdr.sh_type)
|
||||
{
|
||||
case SHT_SYMTAB:
|
||||
{
|
||||
SymbolTable = shdr;
|
||||
syscall3(sys_FileSeek, fd,
|
||||
syscall3(sc_lseek, fd,
|
||||
ELFHeader.e_shoff + ELFHeader.e_shentsize * shdr.sh_link,
|
||||
SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &StringTable, sizeof(Elf64_Shdr));
|
||||
sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &StringTable, sizeof(Elf64_Shdr));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -208,7 +201,7 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
|
||||
if (SymbolTable.sh_size == 0 || StringTable.sh_size == 0)
|
||||
{
|
||||
syscall1(sys_FileClose, fd);
|
||||
syscall1(sc_close, fd);
|
||||
return (Elf64_Sym){0};
|
||||
}
|
||||
|
||||
@ -216,19 +209,19 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
{
|
||||
// Symbol = (Elf64_Sym *)((uintptr_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym)));
|
||||
// String = (char *)((uintptr_t)Header + StringTable->sh_offset + Symbol->st_name);
|
||||
syscall3(sys_FileSeek, fd, SymbolTable.sh_offset + (i * sizeof(Elf64_Sym)), SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &Symbol, sizeof(Elf64_Sym));
|
||||
syscall3(sc_lseek, fd, SymbolTable.sh_offset + (i * sizeof(Elf64_Sym)), sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &Symbol, sizeof(Elf64_Sym));
|
||||
|
||||
syscall3(sys_FileSeek, fd, StringTable.sh_offset + Symbol.st_name, SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &String, sizeof(char *));
|
||||
syscall3(sc_lseek, fd, StringTable.sh_offset + Symbol.st_name, sc_SEEK_SET);
|
||||
syscall3(sc_read, fd, &String, sizeof(char *));
|
||||
|
||||
if (strcmp(String, Name) == 0)
|
||||
{
|
||||
syscall1(sys_FileClose, fd);
|
||||
syscall1(sc_close, fd);
|
||||
return Symbol;
|
||||
}
|
||||
}
|
||||
|
||||
syscall1(sys_FileClose, fd);
|
||||
syscall1(sc_close, fd);
|
||||
return (Elf64_Sym){0};
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibsCollection *Info, long RelIndex))()
|
||||
Elf64_Ehdr lib_Header;
|
||||
Elf64_Ehdr app_Header;
|
||||
|
||||
int fd_lib = syscall2(sys_FileOpen, LibraryPathBuffer, "r");
|
||||
int fd_app = syscall2(sys_FileOpen, ParentPath, "r");
|
||||
int fd_lib = syscall2(sc_open, LibraryPathBuffer, "r");
|
||||
int fd_app = syscall2(sc_open, ParentPath, "r");
|
||||
|
||||
if (fd_lib < 0)
|
||||
{
|
||||
@ -117,31 +117,31 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibsCollection *Info, long RelIndex))()
|
||||
goto RetryNextLib;
|
||||
}
|
||||
|
||||
syscall3(sys_FileRead, fd_lib, &lib_Header, sizeof(Elf64_Ehdr));
|
||||
syscall3(sys_FileRead, fd_app, &app_Header, sizeof(Elf64_Ehdr));
|
||||
syscall3(sc_read, fd_lib, &lib_Header, sizeof(Elf64_Ehdr));
|
||||
syscall3(sc_read, fd_app, &app_Header, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Phdr ItrProgramHeader;
|
||||
|
||||
for (Elf64_Half i = 0; i < lib_Header.e_phnum; i++)
|
||||
{
|
||||
syscall3(sys_FileSeek, fd_lib,
|
||||
syscall3(sc_lseek, fd_lib,
|
||||
lib_Header.e_phoff +
|
||||
lib_Header.e_phentsize * i,
|
||||
SYSCALL_SEEK_SET);
|
||||
sc_SEEK_SET);
|
||||
|
||||
syscall3(sys_FileRead, fd_lib, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
syscall3(sc_read, fd_lib, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
|
||||
lib_BaseAddress = MIN(lib_BaseAddress, ItrProgramHeader.p_vaddr);
|
||||
}
|
||||
|
||||
for (Elf64_Half i = 0; i < app_Header.e_phnum; i++)
|
||||
{
|
||||
syscall3(sys_FileSeek, fd_app,
|
||||
syscall3(sc_lseek, fd_app,
|
||||
app_Header.e_phoff +
|
||||
app_Header.e_phentsize * i,
|
||||
SYSCALL_SEEK_SET);
|
||||
sc_SEEK_SET);
|
||||
|
||||
syscall3(sys_FileRead, fd_app, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
syscall3(sc_read, fd_app, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
|
||||
app_BaseAddress = MIN(app_BaseAddress, ItrProgramHeader.p_vaddr);
|
||||
}
|
||||
@ -265,7 +265,7 @@ FailEnd:
|
||||
Print(DbgBuff);
|
||||
PrintNL(" not found");
|
||||
int ExitCode = 0x51801;
|
||||
syscall1(sys_Exit, ExitCode);
|
||||
syscall1(sc_exit, ExitCode);
|
||||
while (1) // Make sure we don't return
|
||||
;
|
||||
}
|
||||
@ -274,15 +274,15 @@ FailEnd:
|
||||
int ld_main()
|
||||
{
|
||||
/* Prevent race condition. */
|
||||
uintptr_t KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||
do
|
||||
{
|
||||
syscall1(sys_Sleep, 250);
|
||||
KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||
} while (KCTL_ret == false);
|
||||
// uintptr_t KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||
// do
|
||||
// {
|
||||
// syscall1(sys_Sleep, 250);
|
||||
// KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||
// } while (KCTL_ret == false);
|
||||
|
||||
if (KCTL_ret == false)
|
||||
return -1;
|
||||
// if (KCTL_ret == false)
|
||||
// return -1;
|
||||
|
||||
/* Everything is ok, continue. */
|
||||
return 0;
|
||||
@ -306,7 +306,7 @@ int ld_load(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
PrintDbgNL("Calling entry point");
|
||||
|
||||
// void *KP = syscall2(sys_FileOpen, ParentPath, (long)"r");
|
||||
// void *KP = syscall2(sc_open, ParentPath, (long)"r");
|
||||
// if (KP == NULL)
|
||||
// {
|
||||
// PrintNL("Failed to open file");
|
||||
@ -314,7 +314,7 @@ int ld_load(int argc, char *argv[], char *envp[])
|
||||
// }
|
||||
|
||||
// Elf64_Ehdr ELFHeader;
|
||||
// syscall3(sys_FileRead, KP, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
// syscall3(sc_read, KP, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
// Elf64_Addr Entry = ELFHeader.e_entry;
|
||||
|
||||
|
@ -17,7 +17,7 @@ PUBLIC void _exit(int Code)
|
||||
{
|
||||
__libc_fini_std();
|
||||
__libc_fini_array();
|
||||
syscall1(sys_Exit, (long)Code);
|
||||
syscall1(sc_exit, (long)Code);
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
@ -17,10 +17,14 @@ extern "C" int liballoc_unlock()
|
||||
|
||||
extern "C" void *liballoc_alloc(size_t Pages)
|
||||
{
|
||||
return (void *)syscall1(sys_RequestPages, Pages);
|
||||
return (void *)syscall6(sc_mmap, NULL,
|
||||
Pages * 0x1000,
|
||||
sc_PROT_READ | sc_PROT_WRITE,
|
||||
sc_MAP_ANONYMOUS | sc_MAP_PRIVATE,
|
||||
-1, 0);
|
||||
}
|
||||
|
||||
extern "C" int liballoc_free(void *Address, size_t Pages)
|
||||
{
|
||||
return syscall2(sys_FreePages, (uint64_t)Address, Pages);
|
||||
return syscall2(sc_munmap, (uintptr_t)Address, Pages * 0x1000);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ PUBLIC FILE *freopen(const char *filename, const char *mode, FILE *stream)
|
||||
|
||||
PUBLIC FILE *fopen(const char *filename, const char *mode)
|
||||
{
|
||||
int fd = syscall2(sys_FileOpen, (uint64_t)filename, (uint64_t)mode);
|
||||
int fd = syscall2(sc_open, (uint64_t)filename, (uint64_t)mode);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
@ -35,8 +35,8 @@ PUBLIC size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
syscall3(sys_FileSeek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||
return syscall3(sys_FileRead, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||
syscall3(sc_lseek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||
return syscall3(sc_read, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||
}
|
||||
|
||||
PUBLIC size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
@ -47,8 +47,8 @@ PUBLIC size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
syscall3(sys_FileSeek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||
return syscall3(sys_FileWrite, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||
syscall3(sc_lseek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||
return syscall3(sc_write, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||
}
|
||||
|
||||
PUBLIC int fclose(FILE *fp)
|
||||
@ -59,7 +59,7 @@ PUBLIC int fclose(FILE *fp)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
return syscall1(sys_FileClose, fp->_fileno);
|
||||
return syscall1(sc_close, fp->_fileno);
|
||||
}
|
||||
|
||||
PUBLIC off_t fseek(FILE *stream, off_t offset, int whence)
|
||||
@ -70,7 +70,7 @@ PUBLIC off_t fseek(FILE *stream, off_t offset, int whence)
|
||||
return -1;
|
||||
}
|
||||
|
||||
off_t new_offset = syscall3(sys_FileSeek, stream->_fileno, offset, whence);
|
||||
off_t new_offset = syscall3(sc_lseek, stream->_fileno, offset, whence);
|
||||
if (new_offset < 0)
|
||||
return -1;
|
||||
stream->_offset = new_offset;
|
||||
|
@ -13,7 +13,7 @@ PUBLIC int fputc(int c, FILE *stream)
|
||||
// return EOF;
|
||||
// }
|
||||
char str[2] = {c, '\0'};
|
||||
return syscall3(sys_KernelCTL, KCTL_PRINT, str, 0);
|
||||
// return syscall3(sys_KernelCTL, KCTL_PRINT, str, 0);
|
||||
}
|
||||
|
||||
PUBLIC int putc(int c, FILE *stream) { return fputc(c, stream); }
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
PUBLIC void abort(void)
|
||||
{
|
||||
syscall1(sys_Exit, -0xAB057);
|
||||
syscall1(sc_exit, -0xAB057);
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
@ -47,5 +47,5 @@ PUBLIC int execve(const char *pathname, char *const argv[], char *const envp[])
|
||||
|
||||
PUBLIC pid_t fork(void)
|
||||
{
|
||||
return syscall0(sys_Fork);
|
||||
return syscall0(sc_fork);
|
||||
}
|
||||
|
@ -5,10 +5,10 @@
|
||||
|
||||
PUBLIC unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
return syscall1(sys_Sleep, seconds * 1000000);
|
||||
// return syscall1(sys_Sleep, seconds * 1000000);
|
||||
}
|
||||
|
||||
PUBLIC int usleep(useconds_t usec)
|
||||
{
|
||||
return syscall1(sys_Sleep, usec);
|
||||
// return syscall1(sys_Sleep, usec);
|
||||
}
|
||||
|
Reference in New Issue
Block a user