32 pr_warn(
"failed to read elf header");
38 const char **argv_copy =
NULL;
39 const char **envp_copy =
NULL;
40 const char *path_copy =
strdup(path);
46 argv_copy = krealloc(argv_copy, (
argc + 1) *
sizeof(
char *));
52 argv_copy = kcalloc<const char *>(2);
53 argv_copy[0] =
strdup(path);
61 while (envp && envp[envc])
64 envp_copy = krealloc(envp_copy, (envc + 1) *
sizeof(
char *));
65 envp_copy[envc - 1] =
strdup(envp[envc - 1]);
70 envp_copy = kcalloc<const char *>(1);
75 envp_copy[envc] =
NULL;
79 proc->name = f->dentry->name;
80 thread->name = f->dentry->name;
84 for (
const auto &t : proc->thread_list)
96 proc->main_thread = thread;
114 if (stack_vmap.isErr())
116 pr_emerg(
"failed to allocate stack for new process");
121 stack_init(&thread->u_stack, (
void *) stack_vmap->vaddr, ustack_size);
126 .invocation = path_copy,
138 for (
int i = 0; i <
argc; i++)
141 for (
int i = 0; i < envc; i++)
148 pr_emerg(
"failed to fill process, execve failed");
153 memzero(proc->signal_info.handlers,
sizeof(proc->signal_info.handlers));
#define MOS_UNREACHABLE()
#define MOS_STACK_PAGES_USER
#define MOS_PROCESS_MAX_OPEN_FILES
#define MOS_ADDR_USER_STACK
PtrResult< vmap_t > cow_allocate_zeroed_pages(MMContext *handle, size_t npages, ptr_t vaddr, valloc_flags hints, vm_flags flags)
Allocate zero-on-demand pages at a specific address.
__nodiscard bool elf_read_and_verify_executable(file_t *file, elf_header_t *header)
__nodiscard bool elf_do_fill_process(Process *proc, file_t *file, elf_header_t elf, elf_startup_info_t *info)
long process_do_execveat(fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags)
MOSAPI void stack_init(downwards_stack_t *stack, void *mem_region_bottom, size_t size)
long signal_send_to_thread(Thread *target, signal_t signal)
Send a signal to a thread.
MOSAPI char * strdup(const char *src)
#define list_foreach(t, v, h)
Iterate over a list.
void vmap_finalise_init(vmap_t *vmap, vmap_content_t content, vmap_type_t type)
Finalize the initialization of a vmap object.
void vmap_destroy(vmap_t *vmap)
Destroy a vmap object, and unmmap the region.
@ VALLOC_DEFAULT
Default allocation flags.
PtrResult< file_t > vfs_openat(int fd, const char *path, open_flags flags)
Open a file at a given path.
__nodiscard bool io_valid(const io_t *io)
io_t * io_unref(io_t *io)
#define pr_emerg(fmt,...)
void process_exit(Process *&&proc, u8 exit_code, signal_t signal)
bool process_detach_fd(Process *process, fd_t fd)
#define memzero(ptr, size)
#define spinlock_acquire(lock)
#define spinlock_release(lock)
void thread_destroy(Thread *thread)
bool thread_wait_for_tid(tid_t tid)