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();
65 procvm_init_clean(kproc);
67 vmm_mount_pd(VMS_MOUNT_1, vmroot(kproc));
69 struct thread* kthread = create_thread(kproc, VMS_MOUNT_1, with_ustack);
72 vmm_unmount_pd(VMS_MOUNT_1);
73 delete_process(kproc);
77 commit_process(kproc);
78 start_thread(kthread, VMS_MOUNT_1, entry);
80 vmm_unmount_pd(VMS_MOUNT_1);
90 spawn_process_usr(struct thread** created, char* path,
91 const char** argv, const char** envp)
93 // FIXME remote injection of user stack not yet implemented
95 struct proc_info* proc = alloc_process();
97 assert(!kernel_process(proc));
99 procvm_init_clean(proc);
101 vmm_mount_pd(VMS_MOUNT_1, vmroot(proc));
104 struct thread* main_thread;
105 if (!(main_thread = create_thread(proc, VMS_MOUNT_1, true))) {
110 struct exec_container container;
111 exec_init_container(&container, main_thread, VMS_MOUNT_1, argv, envp);
112 if ((errno = exec_load_byname(&container, path))) {
116 commit_process(proc);
117 start_thread(main_thread, VMS_MOUNT_1, container.exe.entry);
120 *created = main_thread;
123 vmm_unmount_pd(VMS_MOUNT_1);
127 vmm_unmount_pd(VMS_MOUNT_1);
128 delete_process(proc);
133 ptr_t proc_vmroot() {
134 return __current->mm->vmroot;