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:
@ -1,12 +1,10 @@
|
||||
build:
|
||||
cp -r include/* ../out/usr/include
|
||||
cp -r include/* ../out/include
|
||||
make -C libgcc build
|
||||
make -C libinit build
|
||||
make -C libssp build
|
||||
make -C libsys build
|
||||
|
||||
clean:
|
||||
make -C libgcc clean
|
||||
make -C libinit clean
|
||||
make -C libssp clean
|
||||
make -C libsys clean
|
||||
|
@ -1,11 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_BASE_H__
|
||||
#define __FENNIX_LIBS_BASE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
long DoCtl(uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4);
|
||||
|
||||
uintptr_t KrnlRequestPages(size_t Count);
|
||||
void KrnlFreePages(uintptr_t Address, size_t Count);
|
||||
|
||||
#endif // !__FENNIX_LIBS_BASE_H__
|
@ -1,32 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_SYS_FILE_H__
|
||||
#define __FENNIX_LIBS_SYS_FILE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *KernelPrivate;
|
||||
} File;
|
||||
|
||||
enum FileFlags
|
||||
{
|
||||
FILE_READ = 1,
|
||||
FILE_WRITE = 2,
|
||||
FILE_APPEND = 4,
|
||||
FILE_CREATE = 8,
|
||||
FILE_TRUNCATE = 16,
|
||||
FILE_EXCLUSIVE = 32,
|
||||
FILE_DIRECTORY = 64,
|
||||
FILE_SYMLINK = 128,
|
||||
FILE_NONBLOCK = 256,
|
||||
FILE_CLOEXEC = 512,
|
||||
};
|
||||
|
||||
File *FileOpen(const char *Path, uint64_t Flags);
|
||||
void FileClose(File *File);
|
||||
uint64_t FileRead(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size);
|
||||
uint64_t FileWrite(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size);
|
||||
uint64_t FileSeek(File *File, uint64_t Offset, uint64_t Whence);
|
||||
uint64_t FileStatus(File *File);
|
||||
|
||||
#endif // !__FENNIX_LIBS_SYS_FILE_H__
|
@ -1,122 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_SYS_PROC_H__
|
||||
#define __FENNIX_LIBS_SYS_PROC_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
enum ProcessState
|
||||
{
|
||||
PROCESS_STATE_READY,
|
||||
PROCESS_STATE_RUNNING,
|
||||
PROCESS_STATE_SLEEPING,
|
||||
PROCESS_STATE_WAITING,
|
||||
PROCESS_STATE_STOPPED,
|
||||
PROCESS_STATE_TERMINATED
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Name[256];
|
||||
unsigned long ID;
|
||||
enum ProcessState State;
|
||||
void *KernelPrivate;
|
||||
} Process;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Name[256];
|
||||
unsigned long ID;
|
||||
enum ProcessState State;
|
||||
void *KernelPrivate;
|
||||
} Thread;
|
||||
|
||||
/**
|
||||
* @brief Create a new process from a path
|
||||
*
|
||||
* @param Path Path to the executable
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *Spawn(const char *Path);
|
||||
|
||||
/**
|
||||
* @brief Create a new thread
|
||||
*
|
||||
* @param EntryPoint Entry point of the thread
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *SpawnThread(uintptr_t EntryPoint);
|
||||
|
||||
/**
|
||||
* @brief Get list of threads
|
||||
*
|
||||
* @param Process Process to get the threads from
|
||||
* @return Thread** Pointer to the thread list (NULL terminated)
|
||||
*/
|
||||
Thread **GetThreadList(Process *Process);
|
||||
|
||||
/**
|
||||
* @brief Get process by ID
|
||||
*
|
||||
* @param ID Process ID
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *GetProcessByID(unsigned long ID);
|
||||
|
||||
/**
|
||||
* @brief Get thread by ID
|
||||
*
|
||||
* @param ID Thread ID
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *GetThreadByID(unsigned long ID);
|
||||
|
||||
/**
|
||||
* @brief Get current process
|
||||
*
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *GetCurrentProcess();
|
||||
|
||||
/**
|
||||
* @brief Get current thread
|
||||
*
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *GetCurrentThread();
|
||||
|
||||
/**
|
||||
* @brief [SYSTEM] Create a new empty process
|
||||
*
|
||||
* @param KernelPrivate Process parent
|
||||
* @param Name Process name
|
||||
* @param TrustLevel Process trust level [RESERVED FOR TRUSTED PROCESSES]
|
||||
* @param Image Process file image already loaded in memory
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *KrnlCreateProcess(void *KernelPrivate,
|
||||
const char *Name,
|
||||
long TrustLevel,
|
||||
void *Image);
|
||||
|
||||
/**
|
||||
* @brief [SYSTEM] Create a new thread
|
||||
*
|
||||
* @param KernelPrivate Process parent
|
||||
* @param EntryPoint Entry point of the thread
|
||||
* @param argv Arguments
|
||||
* @param envp Environment variables
|
||||
* @param auxv Auxiliary variables
|
||||
* @param Offset Offset of the entry point
|
||||
* @param Architecture Architecture of the thread
|
||||
* @param Compatibility Compatibility of the thread
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *KrnlCreateThread(void *KernelPrivate,
|
||||
unsigned long EntryPoint,
|
||||
const char **argv,
|
||||
const char **envp,
|
||||
void *auxv,
|
||||
unsigned long Offset,
|
||||
long Architecture,
|
||||
long Compatibility);
|
||||
|
||||
#endif // !__FENNIX_LIBS_SYS_PROC_H__
|
@ -1,6 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_SSP_H__
|
||||
#define __FENNIX_LIBS_SSP_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !__FENNIX_LIBS_SSP_H__
|
@ -27,10 +27,11 @@ else ifeq ($(OSARCH), i386)
|
||||
ASM_ARCH := elf32
|
||||
endif
|
||||
|
||||
CFLAGS := -fvisibility=hidden -fPIC -fPIE -I../include -I../../libc/include
|
||||
CFLAGS := -fvisibility=hidden -fPIC -fPIE -I../include -I../../out/include
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(OBJECT_NAME)
|
||||
|
@ -1,7 +1,16 @@
|
||||
#include <libinit/init.h>
|
||||
#include <unistd.h>
|
||||
#include <features.h>
|
||||
#include "printf.h"
|
||||
|
||||
#ifdef __FENNIX_LIBC__
|
||||
#define cprintf printf_libinit
|
||||
#define cvprintf vprintf_libinit
|
||||
#else
|
||||
#define cprintf printf
|
||||
#define cvprintf vprintf
|
||||
#endif
|
||||
|
||||
void init_log(const char *fmt, ...)
|
||||
{
|
||||
static short log_lock = 0;
|
||||
@ -10,12 +19,12 @@ void init_log(const char *fmt, ...)
|
||||
__sync_synchronize();
|
||||
log_lock = 1;
|
||||
|
||||
printf_libinit("\eCCCCCC[\e0088FFinit\eCCCCCC] \eAAAAAA");
|
||||
cprintf("\eCCCCCC[\e0088FFinit\eCCCCCC] \eAAAAAA");
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf_libinit(fmt, args);
|
||||
cvprintf(fmt, args);
|
||||
va_end(args);
|
||||
printf_libinit("\eCCCCCC");
|
||||
cprintf("\eCCCCCC");
|
||||
|
||||
log_lock = 0;
|
||||
__sync_synchronize();
|
||||
|
@ -49,8 +49,9 @@
|
||||
#include <cstdint>
|
||||
#include <climits>
|
||||
#else
|
||||
#include <types.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#endif // __cplusplus
|
||||
|
||||
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
||||
|
@ -39,11 +39,14 @@
|
||||
#ifndef PRINTF_H_
|
||||
#define PRINTF_H_
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -27,10 +27,11 @@ else ifeq ($(OSARCH), i386)
|
||||
ASM_ARCH := elf32
|
||||
endif
|
||||
|
||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../libc/include
|
||||
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)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef PUBLIC
|
||||
#define PUBLIC __attribute__((visibility("default")))
|
||||
#endif // !PUBLIC
|
||||
@ -26,19 +25,13 @@ static void __attribute__((constructor, no_stack_protector)) __guard_setup(void)
|
||||
PUBLIC __attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
|
||||
{
|
||||
const char *msg = "Stack smashing detected";
|
||||
__asm__ __volatile__("syscall"
|
||||
:
|
||||
: "a"(0), "D"(0x57AC)
|
||||
: "rcx", "r11", "memory");
|
||||
exit(0x57AC);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
PUBLIC __attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
|
||||
{
|
||||
const char *msg = "Buffer overflow detected";
|
||||
__asm__ __volatile__("syscall"
|
||||
:
|
||||
: "a"(0), "D"(0xF700)
|
||||
: "rcx", "r11", "memory");
|
||||
exit(0xF700);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
#include <libsys/base.h>
|
||||
|
||||
#include "../../../Kernel/syscalls.h"
|
||||
|
||||
long DoCtl(uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4)
|
||||
{
|
||||
return syscall5(_KernelCTL, Command, Arg1, Arg2, Arg3, Arg4);
|
||||
}
|
||||
|
||||
uintptr_t KrnlRequestPages(size_t Count)
|
||||
{
|
||||
return syscall1(_RequestPages, Count);
|
||||
}
|
||||
|
||||
void KrnlFreePages(uintptr_t Address, size_t Count)
|
||||
{
|
||||
syscall2(_FreePages, Address, Count);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#include <libsys/base.h>
|
||||
#include <libsys/file.h>
|
||||
|
||||
#include "../../../Kernel/syscalls.h"
|
||||
|
||||
__attribute__((visibility("hidden"))) long __FILE_GetPageSize()
|
||||
{
|
||||
static long PageSize = 0;
|
||||
if (PageSize == 0)
|
||||
PageSize = DoCtl(KCTL_GET_PAGE_SIZE, 0, 0, 0, 0);
|
||||
return PageSize;
|
||||
}
|
||||
|
||||
File *FileOpen(const char *Path, uint64_t Flags)
|
||||
{
|
||||
File *FilePtr = (File *)KrnlRequestPages(sizeof(File) / __FILE_GetPageSize() + 1);
|
||||
FilePtr->KernelPrivate = (void *)syscall2(_FileOpen, (uint64_t)Path, Flags);
|
||||
return FilePtr;
|
||||
}
|
||||
|
||||
void FileClose(File *File)
|
||||
{
|
||||
syscall1(_FileClose, (uint64_t)File->KernelPrivate);
|
||||
KrnlFreePages((uintptr_t)File, sizeof(File) / __FILE_GetPageSize() + 1);
|
||||
}
|
||||
|
||||
uint64_t FileRead(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size)
|
||||
{
|
||||
return syscall4(_FileRead, (uint64_t)File->KernelPrivate, Offset, (uint64_t)Buffer, Size);
|
||||
}
|
||||
|
||||
uint64_t FileWrite(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size)
|
||||
{
|
||||
return syscall4(_FileWrite, (uint64_t)File->KernelPrivate, Offset, (uint64_t)Buffer, Size);
|
||||
}
|
||||
|
||||
uint64_t FileSeek(File *File, uint64_t Offset, uint64_t Whence)
|
||||
{
|
||||
return syscall3(_FileSeek, (uint64_t)File->KernelPrivate, Offset, Whence);
|
||||
}
|
||||
|
||||
uint64_t FileStatus(File *File)
|
||||
{
|
||||
return syscall1(_FileStatus, (uint64_t)File->KernelPrivate);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
# Config file
|
||||
include ../../../Makefile.conf
|
||||
|
||||
NAME=sys
|
||||
|
||||
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../../libc/include
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
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,6 +0,0 @@
|
||||
#include <libsys/base.h>
|
||||
#include <libsys/proc.h>
|
||||
|
||||
#include "../../../Kernel/syscalls.h"
|
||||
|
||||
|
Reference in New Issue
Block a user