1 #include <klibc/string.h>
2 #include <lunaix/clock.h>
3 #include <lunaix/mm/mmap.h>
4 #include <lunaix/mm/vmm.h>
5 #include <lunaix/mm/region.h>
6 #include <lunaix/mm/valloc.h>
7 #include <lunaix/process.h>
8 #include <lunaix/spike.h>
9 #include <lunaix/status.h>
10 #include <lunaix/syscall.h>
11 #include <lunaix/syslog.h>
12 #include <lunaix/exec.h>
13 #include <lunaix/fs.h>
16 #include <sys/mm/mm_defs.h>
20 __DEFINE_LXSYSCALL(pid_t, getpid)
22 return __current->pid;
25 __DEFINE_LXSYSCALL(pid_t, getppid)
27 return __current->parent->pid;
30 __DEFINE_LXSYSCALL(pid_t, getpgid)
32 return __current->pgid;
35 __DEFINE_LXSYSCALL2(int, setpgid, pid_t, pid, pid_t, pgid)
37 struct proc_info* proc = pid ? get_process(pid) : __current;
40 syscall_result(EINVAL);
44 pgid = pgid ? pgid : proc->pid;
46 struct proc_info* gruppenfuhrer = get_process(pgid);
48 if (!gruppenfuhrer || proc->pgid == gruppenfuhrer->pid) {
49 syscall_result(EINVAL);
53 llist_delete(&proc->grp_member);
54 llist_append(&gruppenfuhrer->grp_member, &proc->grp_member);
61 spawn_process(struct thread** created, ptr_t entry, bool with_ustack)
63 struct proc_info* kproc = alloc_process();
64 struct proc_mm* mm = vmspace(kproc);
66 procvm_initvms_mount(mm);
68 struct thread* kthread = create_thread(kproc, with_ustack);
72 delete_process(kproc);
76 commit_process(kproc);
77 start_thread(kthread, entry);
89 spawn_process_usr(struct thread** created, char* path,
90 const char** argv, const char** envp)
92 // FIXME remote injection of user stack not yet implemented
94 struct proc_info* proc = alloc_process();
95 struct proc_mm* mm = vmspace(proc);
97 assert(!kernel_process(proc));
99 procvm_initvms_mount(mm);
102 struct thread* main_thread;
103 if (!(main_thread = create_thread(proc, true))) {
108 struct exec_host container;
109 exec_init_container(&container, main_thread, VMS_MOUNT_1, argv, envp);
110 if ((errno = exec_load_byname(&container, path))) {
114 commit_process(proc);
115 start_thread(main_thread, container.exe.entry);
118 *created = main_thread;
126 delete_process(proc);
131 ptr_t proc_vmroot() {
132 return __current->mm->vmroot;