28 for (
uint64_t i = 0; i < amount; i++)
42 assert((argv !=
NULL && argc > 0) || ((argv ==
NULL || argv[0] ==
NULL) && argc == 0));
51 void* fileData =
NULL;
62 fileData =
malloc(fileSize);
69 if (readSize != fileSize)
83 uint64_t loadSize = maxAddr - minAddr;
99 for (
int64_t i = argc - 1; i >= 0; i--)
101 size_t len =
strlen(argv[i]) + 1;
103 memcpy(rsp, argv[i], len);
108 rsp -=
sizeof(
char*);
109 *((
char**)rsp) =
NULL;
110 for (
int64_t i = argc - 1; i >= 0; i--)
112 rsp -=
sizeof(
char*);
113 *((
char**)rsp) = argv[i];
135 if (fileData !=
NULL)
139 free((
void*)executable);
163 char** argvCopy =
NULL;
164 char* executable =
NULL;
182 if (childThread ==
NULL)
192 if (argc == 0 || argvCopy[0] ==
NULL)
197 executable =
strdup(argvCopy[0]);
198 if (executable ==
NULL)
261 pid_t volatile result = child->
id;
266 if (childThread !=
NULL)
275 free((
void*)executable);
294 if (newThread ==
NULL)
308 tid_t volatile result = newThread->
id;
#define assert(expression)
@ GDT_CS_RING3
Value to load into the CS register for user code.
@ GDT_CS_RING0
Value to load into the CS register for kernel code.
@ GDT_SS_RING3
Value to load into the SS register for user data.
@ GDT_SS_RING0
Value to load into the SS register for kernel data.
#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)
Get the current working directory.
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_set_parent(namespace_t *ns, namespace_t *parent)
Sets the parent of a namespace and inherits all mounts from the parent.
void path_put(path_t *path)
Put a path.
#define PATHNAME(string)
Helper to create a pathname.
uint64_t space_check_access(space_t *space, const void *addr, uint64_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, uint64_t length, 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.
void loader_exec(const char *executable, char **argv, uint64_t argc)
Causes the currently running thread to load and execute a new program.
process_t * process_new(priority_t priority)
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.
uint64_t process_copy_env(process_t *dest, process_t *src)
Copies the environment variables from one process to another.
void process_kill(process_t *process, int32_t status)
Kills a process.
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...
void thread_free(thread_t *thread)
Frees a thread structure.
_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_process_exit(int32_t status)
Terminates the currently executing process and all it's threads.
thread_t * sched_thread(void)
Retrieves the currently running thread.
void sched_submit(thread_t *thread)
Submits a thread to the scheduler.
#define UNREF(ptr)
Decrement reference count.
uint64_t vfs_seek(file_t *file, int64_t offset, seek_origin_t origin)
Seek in a file.
file_t * vfs_open(const pathname_t *pathname, process_t *process)
Open a file.
uint64_t vfs_read(file_t *file, void *buffer, uint64_t count)
Read from a file.
#define CONFIG_MAX_FD
Maximum file descriptor configuration.
#define EINVAL
Invalid argument.
#define ESPAWNFAIL
Process spawn failed.
#define errno
Error number variable.
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_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
Dont inherit the mountpoints of the parent's namespace.
@ 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.
__UINT64_TYPE__ tid_t
Thread Identifier.
__UINT64_TYPE__ pid_t
Process Identifier.
static void loader_strv_free(char **array, uint64_t amount)
static void loader_entry(const char *executable, char **argv, uint64_t argc)
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)
char * strdup(const char *src)
_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.