mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-05-25 22:14:28 +00:00
Update userspace
This commit is contained in:
parent
883d2e3481
commit
17787dbc9b
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
printf("Usage: echo [args]\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
printf("%s ", argv[i]);
|
printf("%s ", argv[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -28,7 +28,7 @@ endif
|
|||||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
||||||
|
|
||||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||||
FILENAME = fsh
|
FILENAME = sh
|
||||||
|
|
||||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ CFLAGS = -I$(WORKSPACE)out/include \
|
|||||||
WARNCFLAG = -Wall -Wextra
|
WARNCFLAG = -Wall -Wextra
|
||||||
|
|
||||||
ifneq ($(OSARCH), aarch64)
|
ifneq ($(OSARCH), aarch64)
|
||||||
CFLAGS += -fstack-protector-all -fstack-clash-protection
|
# CFLAGS += -fstack-protector-all -fstack-clash-protection
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
@ -52,7 +52,7 @@ build: $(FILENAME)
|
|||||||
|
|
||||||
$(FILENAME): $(OBJ)
|
$(FILENAME): $(OBJ)
|
||||||
$(info Linking $@)
|
$(info Linking $@)
|
||||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -lssp -o $@
|
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||||
|
|
||||||
%.o: %.c $(HEADERS)
|
%.o: %.c $(HEADERS)
|
||||||
$(info Compiling $<)
|
$(info Compiling $<)
|
||||||
|
@ -35,50 +35,61 @@ void test_args(int argc, char *argv[], char *envp[])
|
|||||||
|
|
||||||
int main(int argc, char *argv[], char *envp[])
|
int main(int argc, char *argv[], char *envp[])
|
||||||
{
|
{
|
||||||
freopen("/dev/tty", "w", stdout);
|
printf("Hello, World!\n");
|
||||||
freopen("/dev/tty", "w", stderr);
|
// while (1);
|
||||||
|
// test_args(argc, argv, envp);
|
||||||
test_args(argc, argv, envp);
|
FILE *test = fopen("/test.txt", "r");
|
||||||
FILE *test = fopen("/Test.txt", "r");
|
|
||||||
if (test == NULL)
|
if (test == NULL)
|
||||||
{
|
{
|
||||||
printf("Failed to open file\n");
|
printf("Failed to open file\n");
|
||||||
return 1;
|
return -0xF11e;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Test.txt contents: ");
|
printf("Test.txt contents: ");
|
||||||
char ch;
|
char ch;
|
||||||
do
|
while (1)
|
||||||
{
|
{
|
||||||
ch = fgetc(test);
|
ch = fgetc(test);
|
||||||
|
if (ch == EOF)
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
putchar(ch);
|
putchar(ch);
|
||||||
} while (ch != EOF);
|
}
|
||||||
|
|
||||||
fclose(test);
|
fclose(test);
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid = fork();
|
||||||
int status;
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
|
|
||||||
if (pid == 0) // Child process
|
if (pid == 0) // Child process
|
||||||
{
|
{
|
||||||
|
pid_t pid2 = fork();
|
||||||
|
if (pid == 0) // Child process
|
||||||
|
{
|
||||||
|
char *shebang_args[] = {"/test.sh", NULL};
|
||||||
|
execv(shebang_args[0], shebang_args);
|
||||||
|
}
|
||||||
|
|
||||||
printf("Creating shell process\n");
|
printf("Creating shell process\n");
|
||||||
char *args[] = {"/bin/sh", NULL};
|
char *args[] = {"/bin/echo", "Hello, World!", NULL};
|
||||||
execv(args[0], args);
|
execv(args[0], args);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
else if (pid > 0)
|
else if (pid > 0)
|
||||||
{
|
{
|
||||||
|
printf("Waiting for child process %d to exit\n", pid);
|
||||||
|
int status;
|
||||||
wait(&status);
|
wait(&status);
|
||||||
if (WIFEXITED(status))
|
int exited = WIFEXITED(status);
|
||||||
|
if (exited)
|
||||||
{
|
{
|
||||||
printf("Child process exited with code: %d\n", WEXITSTATUS(status));
|
int exit_code = WEXITSTATUS(status);
|
||||||
return WEXITSTATUS(status);
|
printf("Child process exited with code: %d\n", exit_code);
|
||||||
|
return exit_code;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Execution failed.\n");
|
printf("Execution failed. (%d)\n", exited);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 1a54c1624fc6b830a8a478b0f6601c447bbc5cc9
|
Subproject commit b961b5551b5d56cc82bf8b14d43d41f859744344
|
@ -5,22 +5,15 @@
|
|||||||
|
|
||||||
uintptr_t RequestPages(size_t Count)
|
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)
|
int FreePages(uintptr_t Address, size_t Count)
|
||||||
{
|
{
|
||||||
return syscall2(sys_FreePages, Address, Count);
|
return syscall2(sc_munmap, Address, Count * 0x1000);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int abs(int i) { return i < 0 ? -i : i; }
|
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)
|
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)
|
if (fd < 0)
|
||||||
syscall1(sys_Exit, -0xF17E);
|
syscall1(sc_exit, -0xF17E);
|
||||||
|
|
||||||
Elf64_Ehdr ELFHeader;
|
Elf64_Ehdr ELFHeader;
|
||||||
syscall3(sys_FileRead, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
syscall3(sc_read, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||||
|
|
||||||
Elf64_Phdr ItrProgramHeader;
|
Elf64_Phdr ItrProgramHeader;
|
||||||
for (Elf64_Half i = 0; i < ELFHeader.e_phnum; i++)
|
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));
|
// 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(sc_lseek, fd, ELFHeader.e_phoff + ELFHeader.e_phentsize * i, sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
syscall3(sc_read, fd, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||||
if (ItrProgramHeader.p_type == PT_DYNAMIC)
|
if (ItrProgramHeader.p_type == PT_DYNAMIC)
|
||||||
{
|
{
|
||||||
struct Elf64_Dyn Dynamic; // = (struct Elf64_Dyn *)((uint8_t *)ElfFile + ItrProgramHeader.p_offset);
|
struct Elf64_Dyn Dynamic; // = (struct Elf64_Dyn *)((uint8_t *)ElfFile + ItrProgramHeader.p_offset);
|
||||||
syscall3(sys_FileSeek, fd, ItrProgramHeader.p_offset, SYSCALL_SEEK_SET);
|
syscall3(sc_lseek, fd, ItrProgramHeader.p_offset, sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &Dynamic, ItrProgramHeader.p_filesz);
|
syscall3(sc_read, fd, &Dynamic, ItrProgramHeader.p_filesz);
|
||||||
for (size_t i = 0; i < ItrProgramHeader.p_filesz / sizeof(struct Elf64_Dyn); i++)
|
for (size_t i = 0; i < ItrProgramHeader.p_filesz / sizeof(struct Elf64_Dyn); i++)
|
||||||
{
|
{
|
||||||
if (Dynamic.d_tag == Tag || Dynamic.d_tag == DT_NULL)
|
if (Dynamic.d_tag == Tag || Dynamic.d_tag == DT_NULL)
|
||||||
{
|
{
|
||||||
syscall1(sys_FileClose, fd);
|
syscall1(sc_close, fd);
|
||||||
return Dynamic;
|
return Dynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall3(sys_FileSeek, fd, ItrProgramHeader.p_offset + (i + 1) * sizeof(struct Elf64_Dyn), SYSCALL_SEEK_SET);
|
syscall3(sc_lseek, fd, ItrProgramHeader.p_offset + (i + 1) * sizeof(struct Elf64_Dyn), sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &Dynamic, sizeof(struct Elf64_Dyn));
|
syscall3(sc_read, fd, &Dynamic, sizeof(struct Elf64_Dyn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syscall1(sys_FileClose, fd);
|
syscall1(sc_close, fd);
|
||||||
return (struct Elf64_Dyn){0};
|
return (struct Elf64_Dyn){0};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,12 +161,12 @@ char *GetELFStringTable(Elf64_Ehdr *Header)
|
|||||||
|
|
||||||
Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
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)
|
if (fd < 0)
|
||||||
syscall1(sys_Exit, -0xF17E);
|
syscall1(sc_exit, -0xF17E);
|
||||||
|
|
||||||
Elf64_Ehdr ELFHeader;
|
Elf64_Ehdr ELFHeader;
|
||||||
syscall3(sys_FileRead, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
syscall3(sc_read, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||||
|
|
||||||
Elf64_Shdr SymbolTable;
|
Elf64_Shdr SymbolTable;
|
||||||
Elf64_Shdr StringTable;
|
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++)
|
for (Elf64_Half i = 0; i < ELFHeader.e_shnum; i++)
|
||||||
{
|
{
|
||||||
Elf64_Shdr shdr;
|
Elf64_Shdr shdr;
|
||||||
syscall3(sys_FileSeek, fd,
|
syscall3(sc_lseek, fd,
|
||||||
ELFHeader.e_shoff + ELFHeader.e_shentsize * i,
|
ELFHeader.e_shoff + ELFHeader.e_shentsize * i,
|
||||||
SYSCALL_SEEK_SET);
|
sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &shdr, sizeof(Elf64_Shdr));
|
syscall3(sc_read, fd, &shdr, sizeof(Elf64_Shdr));
|
||||||
|
|
||||||
switch (shdr.sh_type)
|
switch (shdr.sh_type)
|
||||||
{
|
{
|
||||||
case SHT_SYMTAB:
|
case SHT_SYMTAB:
|
||||||
{
|
{
|
||||||
SymbolTable = shdr;
|
SymbolTable = shdr;
|
||||||
syscall3(sys_FileSeek, fd,
|
syscall3(sc_lseek, fd,
|
||||||
ELFHeader.e_shoff + ELFHeader.e_shentsize * shdr.sh_link,
|
ELFHeader.e_shoff + ELFHeader.e_shentsize * shdr.sh_link,
|
||||||
SYSCALL_SEEK_SET);
|
sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &StringTable, sizeof(Elf64_Shdr));
|
syscall3(sc_read, fd, &StringTable, sizeof(Elf64_Shdr));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -208,7 +201,7 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
|||||||
|
|
||||||
if (SymbolTable.sh_size == 0 || StringTable.sh_size == 0)
|
if (SymbolTable.sh_size == 0 || StringTable.sh_size == 0)
|
||||||
{
|
{
|
||||||
syscall1(sys_FileClose, fd);
|
syscall1(sc_close, fd);
|
||||||
return (Elf64_Sym){0};
|
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)));
|
// Symbol = (Elf64_Sym *)((uintptr_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym)));
|
||||||
// String = (char *)((uintptr_t)Header + StringTable->sh_offset + Symbol->st_name);
|
// 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(sc_lseek, fd, SymbolTable.sh_offset + (i * sizeof(Elf64_Sym)), sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &Symbol, sizeof(Elf64_Sym));
|
syscall3(sc_read, fd, &Symbol, sizeof(Elf64_Sym));
|
||||||
|
|
||||||
syscall3(sys_FileSeek, fd, StringTable.sh_offset + Symbol.st_name, SYSCALL_SEEK_SET);
|
syscall3(sc_lseek, fd, StringTable.sh_offset + Symbol.st_name, sc_SEEK_SET);
|
||||||
syscall3(sys_FileRead, fd, &String, sizeof(char *));
|
syscall3(sc_read, fd, &String, sizeof(char *));
|
||||||
|
|
||||||
if (strcmp(String, Name) == 0)
|
if (strcmp(String, Name) == 0)
|
||||||
{
|
{
|
||||||
syscall1(sys_FileClose, fd);
|
syscall1(sc_close, fd);
|
||||||
return Symbol;
|
return Symbol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall1(sys_FileClose, fd);
|
syscall1(sc_close, fd);
|
||||||
return (Elf64_Sym){0};
|
return (Elf64_Sym){0};
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,8 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibsCollection *Info, long RelIndex))()
|
|||||||
Elf64_Ehdr lib_Header;
|
Elf64_Ehdr lib_Header;
|
||||||
Elf64_Ehdr app_Header;
|
Elf64_Ehdr app_Header;
|
||||||
|
|
||||||
int fd_lib = syscall2(sys_FileOpen, LibraryPathBuffer, "r");
|
int fd_lib = syscall2(sc_open, LibraryPathBuffer, "r");
|
||||||
int fd_app = syscall2(sys_FileOpen, ParentPath, "r");
|
int fd_app = syscall2(sc_open, ParentPath, "r");
|
||||||
|
|
||||||
if (fd_lib < 0)
|
if (fd_lib < 0)
|
||||||
{
|
{
|
||||||
@ -117,31 +117,31 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibsCollection *Info, long RelIndex))()
|
|||||||
goto RetryNextLib;
|
goto RetryNextLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall3(sys_FileRead, fd_lib, &lib_Header, sizeof(Elf64_Ehdr));
|
syscall3(sc_read, fd_lib, &lib_Header, sizeof(Elf64_Ehdr));
|
||||||
syscall3(sys_FileRead, fd_app, &app_Header, sizeof(Elf64_Ehdr));
|
syscall3(sc_read, fd_app, &app_Header, sizeof(Elf64_Ehdr));
|
||||||
|
|
||||||
Elf64_Phdr ItrProgramHeader;
|
Elf64_Phdr ItrProgramHeader;
|
||||||
|
|
||||||
for (Elf64_Half i = 0; i < lib_Header.e_phnum; i++)
|
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_phoff +
|
||||||
lib_Header.e_phentsize * i,
|
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);
|
lib_BaseAddress = MIN(lib_BaseAddress, ItrProgramHeader.p_vaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Elf64_Half i = 0; i < app_Header.e_phnum; i++)
|
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_phoff +
|
||||||
app_Header.e_phentsize * i,
|
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);
|
app_BaseAddress = MIN(app_BaseAddress, ItrProgramHeader.p_vaddr);
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ FailEnd:
|
|||||||
Print(DbgBuff);
|
Print(DbgBuff);
|
||||||
PrintNL(" not found");
|
PrintNL(" not found");
|
||||||
int ExitCode = 0x51801;
|
int ExitCode = 0x51801;
|
||||||
syscall1(sys_Exit, ExitCode);
|
syscall1(sc_exit, ExitCode);
|
||||||
while (1) // Make sure we don't return
|
while (1) // Make sure we don't return
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -274,15 +274,15 @@ FailEnd:
|
|||||||
int ld_main()
|
int ld_main()
|
||||||
{
|
{
|
||||||
/* Prevent race condition. */
|
/* Prevent race condition. */
|
||||||
uintptr_t KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
// uintptr_t KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||||
do
|
// do
|
||||||
{
|
// {
|
||||||
syscall1(sys_Sleep, 250);
|
// syscall1(sys_Sleep, 250);
|
||||||
KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
// KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||||
} while (KCTL_ret == false);
|
// } while (KCTL_ret == false);
|
||||||
|
|
||||||
if (KCTL_ret == false)
|
// if (KCTL_ret == false)
|
||||||
return -1;
|
// return -1;
|
||||||
|
|
||||||
/* Everything is ok, continue. */
|
/* Everything is ok, continue. */
|
||||||
return 0;
|
return 0;
|
||||||
@ -306,7 +306,7 @@ int ld_load(int argc, char *argv[], char *envp[])
|
|||||||
{
|
{
|
||||||
PrintDbgNL("Calling entry point");
|
PrintDbgNL("Calling entry point");
|
||||||
|
|
||||||
// void *KP = syscall2(sys_FileOpen, ParentPath, (long)"r");
|
// void *KP = syscall2(sc_open, ParentPath, (long)"r");
|
||||||
// if (KP == NULL)
|
// if (KP == NULL)
|
||||||
// {
|
// {
|
||||||
// PrintNL("Failed to open file");
|
// PrintNL("Failed to open file");
|
||||||
@ -314,7 +314,7 @@ int ld_load(int argc, char *argv[], char *envp[])
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// Elf64_Ehdr ELFHeader;
|
// 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;
|
// Elf64_Addr Entry = ELFHeader.e_entry;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ PUBLIC void _exit(int Code)
|
|||||||
{
|
{
|
||||||
__libc_fini_std();
|
__libc_fini_std();
|
||||||
__libc_fini_array();
|
__libc_fini_array();
|
||||||
syscall1(sys_Exit, (long)Code);
|
syscall1(sc_exit, (long)Code);
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,14 @@ extern "C" int liballoc_unlock()
|
|||||||
|
|
||||||
extern "C" void *liballoc_alloc(size_t Pages)
|
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)
|
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)
|
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)
|
if (fd < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -35,8 +35,8 @@ PUBLIC size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall3(sys_FileSeek, stream->_fileno, stream->_offset, SEEK_SET);
|
syscall3(sc_lseek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||||
return syscall3(sys_FileRead, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
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)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall3(sys_FileSeek, stream->_fileno, stream->_offset, SEEK_SET);
|
syscall3(sc_lseek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||||
return syscall3(sys_FileWrite, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
return syscall3(sc_write, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC int fclose(FILE *fp)
|
PUBLIC int fclose(FILE *fp)
|
||||||
@ -59,7 +59,7 @@ PUBLIC int fclose(FILE *fp)
|
|||||||
return EOF;
|
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)
|
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;
|
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)
|
if (new_offset < 0)
|
||||||
return -1;
|
return -1;
|
||||||
stream->_offset = new_offset;
|
stream->_offset = new_offset;
|
||||||
|
@ -13,7 +13,7 @@ PUBLIC int fputc(int c, FILE *stream)
|
|||||||
// return EOF;
|
// return EOF;
|
||||||
// }
|
// }
|
||||||
char str[2] = {c, '\0'};
|
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); }
|
PUBLIC int putc(int c, FILE *stream) { return fputc(c, stream); }
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
PUBLIC void abort(void)
|
PUBLIC void abort(void)
|
||||||
{
|
{
|
||||||
syscall1(sys_Exit, -0xAB057);
|
syscall1(sc_exit, -0xAB057);
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -47,5 +47,5 @@ PUBLIC int execve(const char *pathname, char *const argv[], char *const envp[])
|
|||||||
|
|
||||||
PUBLIC pid_t fork(void)
|
PUBLIC pid_t fork(void)
|
||||||
{
|
{
|
||||||
return syscall0(sys_Fork);
|
return syscall0(sc_fork);
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
PUBLIC unsigned int sleep(unsigned int seconds)
|
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)
|
PUBLIC int usleep(useconds_t usec)
|
||||||
{
|
{
|
||||||
return syscall1(sys_Sleep, usec);
|
// return syscall1(sys_Sleep, usec);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
build:
|
build:
|
||||||
# cp -r include/* ../out/include
|
# cp -r include/* ../out/include
|
||||||
make -C libgcc build
|
make -C libgcc build
|
||||||
make -C libssp build
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
make -C libgcc clean
|
make -C libgcc clean
|
||||||
make -C libssp clean
|
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
# Config file
|
|
||||||
include ../../../Makefile.conf
|
|
||||||
|
|
||||||
NAME=ssp
|
|
||||||
|
|
||||||
ifeq ($(USERSPACE_STATIC_LIBS), 1)
|
|
||||||
OBJECT_NAME := lib$(NAME).a
|
|
||||||
else
|
|
||||||
OBJECT_NAME := lib$(NAME).so
|
|
||||||
endif
|
|
||||||
|
|
||||||
OUTPUT_DIR=../../out/lib/
|
|
||||||
SYSROOT = --sysroot=../../out/
|
|
||||||
|
|
||||||
CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
|
||||||
AS = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)as
|
|
||||||
AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar
|
|
||||||
|
|
||||||
C_SOURCES = $(shell find ./ -type f -name '*.c')
|
|
||||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp')
|
|
||||||
S_SOURCES = $(shell find ./ -type f -name '*.S')
|
|
||||||
OBJ = ${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} ${S_SOURCES:.S=.o}
|
|
||||||
|
|
||||||
ifeq ($(OSARCH), amd64)
|
|
||||||
ASM_ARCH := elf64
|
|
||||||
else ifeq ($(OSARCH), i386)
|
|
||||||
ASM_ARCH := elf32
|
|
||||||
endif
|
|
||||||
|
|
||||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../out/include
|
|
||||||
|
|
||||||
ifeq ($(DEBUG), 1)
|
|
||||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
|
||||||
LDFLAGS += -ggdb3 -O0
|
|
||||||
endif
|
|
||||||
|
|
||||||
build: $(OBJECT_NAME)
|
|
||||||
|
|
||||||
$(OBJECT_NAME): $(OBJ)
|
|
||||||
$(info Linking $@)
|
|
||||||
ifeq ($(USERSPACE_STATIC_LIBS), 1)
|
|
||||||
$(AR) rcs $(OUTPUT_DIR)$@ $(OBJ)
|
|
||||||
else
|
|
||||||
$(CC) -nostdlib -shared -fPIC -fPIE -Wl,-soname,$(OBJECT_NAME) $(SYSROOT) $(OBJ) -o $(OUTPUT_DIR)$@
|
|
||||||
endif
|
|
||||||
|
|
||||||
%.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)
|
|
@ -1,37 +0,0 @@
|
|||||||
#ifndef STACK_CHK_GUARD_VALUE
|
|
||||||
#if UINTPTR_MAX == UINT32_MAX
|
|
||||||
#define STACK_CHK_GUARD_VALUE 0xDEAD57AC
|
|
||||||
#else
|
|
||||||
#define STACK_CHK_GUARD_VALUE 0xDEAD57AC00000000
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PUBLIC
|
|
||||||
#define PUBLIC __attribute__((visibility("default")))
|
|
||||||
#endif // !PUBLIC
|
|
||||||
|
|
||||||
#ifndef PRIVATE
|
|
||||||
#define PRIVATE __attribute__((visibility("hidden")))
|
|
||||||
#endif // !PRIVATE
|
|
||||||
|
|
||||||
PUBLIC __UINTPTR_TYPE__ __stack_chk_guard = 0;
|
|
||||||
|
|
||||||
static void __attribute__((constructor, no_stack_protector)) __guard_setup(void)
|
|
||||||
{
|
|
||||||
if (__stack_chk_guard == 0)
|
|
||||||
__stack_chk_guard = STACK_CHK_GUARD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PUBLIC __attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
|
|
||||||
{
|
|
||||||
const char *msg = "Stack smashing detected";
|
|
||||||
exit(0x57AC);
|
|
||||||
__builtin_unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
PUBLIC __attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
|
|
||||||
{
|
|
||||||
const char *msg = "Buffer overflow detected";
|
|
||||||
exit(0xF700);
|
|
||||||
__builtin_unreachable();
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user