29 for (
uint64_t i = 0; i < amount; i++)
46 void* fileData =
NULL;
71 fileData =
malloc(fileSize);
78 size_t readSize =
vfs_read(file, fileData, fileSize);
79 if (readSize != fileSize)
94 uint64_t loadSize = maxAddr - minAddr;
123 rsp -= (process->
argc + 1) *
sizeof(
char*);
127 argvStack[i] = addrs[i];
129 argvStack[process->
argc] = 0;
149 if (fileData !=
NULL)
230 if (childThread ==
NULL)
235 char** argvCopy =
NULL;
242 if (argc == 0 || argvCopy[0] ==
NULL)
322 if (newThread ==
NULL)
336 tid_t volatile result = newThread->
id;
#define assert(expression)
#define CONFIG_MAX_FD
Maximum file descriptor configuration.
#define GDT_SS_RING3
Value to load into the SS register for user data.
#define GDT_CS_RING3
Value to load into the CS register for user code.
#define GDT_SS_RING0
Value to load into the SS register for kernel data.
#define GDT_CS_RING0
Value to load into the CS register for kernel code.
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
void cwd_set(cwd_t *cwd, const path_t *newPath)
Set the current working directory.
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
void file_table_close_mode(file_table_t *table, mode_t mode)
Close all files in the file table with the specified mode.
uint64_t file_table_copy(file_table_t *dest, file_table_t *src, fd_t min, fd_t max)
Copy a file table, closing any overlapping file descriptors.
uint64_t namespace_copy(namespace_t *dest, namespace_t *src)
Copy mounts from one namespace to another.
namespace_t * namespace_new(namespace_t *parent)
Create a new namespace.
void path_put(path_t *path)
Put a path.
uint64_t pathname_init(pathname_t *pathname, const char *string)
Initialize a pathname.
#define LOG_DEBUG(format,...)
uint64_t space_check_access(space_t *space, const void *addr, size_t length)
Checks if a virtual memory region is within the allowed address range of the space.
void * vmm_alloc(space_t *space, void *virtAddr, size_t length, size_t alignment, pml_flags_t pmlFlags, vmm_alloc_flags_t allocFlags)
Allocates and maps virtual memory in a given address space.
@ VMM_ALLOC_OVERWRITE
If any page is already mapped, overwrite the mapping.
uint64_t env_copy(env_t *dest, env_t *src)
Copy environment variables from one environment to another.
process_t * process_new(priority_t priority, group_member_t *group, namespace_t *ns)
Allocates and initializes a new process.
uint64_t process_set_cmdline(process_t *process, char **argv, uint64_t argc)
Sets the command line arguments for a process.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
void loader_exec(void)
Causes the currently running thread to load and execute a new program.
uint64_t thread_copy_from_user_string_array(thread_t *thread, const char **user, char ***out, uint64_t *outAmount)
Safely copy a null-terminated array of strings and their contents from user space into a string vecto...
static thread_t * thread_current(void)
Retrieves the currently running thread.
_NORETURN void thread_jump(thread_t *thread)
Jump to a thread by calling thread_load() and then loading its interrupt frame.
thread_t * thread_new(process_t *process)
Creates a new thread structure.
#define WAIT_BLOCK(queue, condition)
Blocks until the condition is true, will test the condition on every wakeup.
_NORETURN void sched_exits(const char *status)
Terminates the currently executing process and all it's threads.
void sched_submit(thread_t *thread)
Submits a thread to the scheduler.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
size_t vfs_seek(file_t *file, ssize_t offset, seek_origin_t origin)
Seek in a file.
size_t vfs_read(file_t *file, void *buffer, size_t count)
Read from a file.
file_t * vfs_open(const pathname_t *pathname, process_t *process)
Open a file.
#define EINVAL
Invalid argument.
#define ENOEXEC
Exec format error.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
#define EACCES
Permission denied.
#define ASM(...)
Inline assembly macro.
void elf64_load_segments(const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset)
Load all loadable segments of an ELF file into memory.
uint64_t elf64_validate(Elf64_File *elf, void *data, uint64_t size)
Validate a files content and initalize a ELF64_File structure using it.
void elf64_get_loadable_bounds(const Elf64_File *elf, Elf64_Addr *minAddr, Elf64_Addr *maxAddr)
Get the loadable virtual memory bounds of an ELF file.
uint64_t Elf64_Addr
ELF64 Unsigned program address.
#define ROUND_DOWN(number, multiple)
spawn_flags_t
Spawn behaviour flags.
@ SPAWN_EMPTY_GROUP
Don't inherit the parent's process group, instead create a new group.
@ SPAWN_EMPTY_FDS
Dont inherit the file descriptors of the parent process.
@ SPAWN_STDIO_FDS
Only inherit stdin, stdout and stderr from the parent process.
@ SPAWN_EMPTY_NS
Create a new empty namespace, the new namespace will not contain any mountpoints or even a root.
@ SPAWN_COPY_NS
Don't share the parent's namespace, instead create a new copy of it.
@ SPAWN_EMPTY_ENV
Don't inherit the parent's environment variables.
@ SPAWN_EMPTY_CWD
Don't inherit the parent's current working directory, starts at root (/).
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define PAGE_SIZE
The size of a memory page in bytes.
__UINT64_TYPE__ tid_t
Thread Identifier.
__UINT64_TYPE__ pid_t
Process Identifier.
static void loader_entry(void)
static void loader_strv_free(char **array, uint64_t amount)
static const path_flag_t flags[]
#define RFLAGS_INTERRUPT_ENABLE
#define RFLAGS_ALWAYS_SET
#define atomic_fetch_or(object, operand)
#define atomic_load(object)
__UINTPTR_TYPE__ uintptr_t
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC char * strerror(int errnum)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
_PUBLIC void * memset(void *s, int c, size_t n)
Elf64_Addr e_entry
Entry point virtual address.
ELF File Helper structure.
Elf64_Ehdr * header
The data in the file, pointed to the start of the ELF header.
wait_queue_t suspendQueue
Virtual address space structure.
uintptr_t top
The top of the stack, this address is not inclusive.
Thread of execution structure.
process_t * process
The parent process that the thread executes within.
stack_pointer_t kernelStack
The kernel stack of the thread.
stack_pointer_t userStack
The user stack of the thread.
tid_t id
The thread id, unique within a process_t.