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 <asm/mm_defs.h>
21 spawn_process(struct thread** created, ptr_t entry, bool with_ustack)
23 struct proc_info* kproc = alloc_process();
24 struct proc_mm* mm = vmspace(kproc);
26 procvm_initvms_mount(mm);
28 struct thread* kthread = create_thread(kproc, with_ustack);
32 delete_process(kproc);
36 commit_process(kproc);
37 start_thread(kthread, entry);
49 spawn_process_usr(struct thread** created, char* path,
50 const char** argv, const char** envp)
52 // FIXME remote injection of user stack not yet implemented
54 struct proc_info* proc = alloc_process();
55 struct proc_mm* mm = vmspace(proc);
57 assert(!kernel_process(proc));
59 procvm_initvms_mount(mm);
62 struct thread* main_thread;
63 if (!(main_thread = create_thread(proc, true))) {
68 struct exec_host container;
69 exec_init_container(&container, main_thread, VMS_MOUNT_1, argv, envp);
70 if ((errno = exec_load_byname(&container, path))) {
75 start_thread(main_thread, container.exe.entry);
78 *created = main_thread;
92 return __current->mm->vmroot;
95 __DEFINE_LXSYSCALL(pid_t, getpid)
97 return __current->pid;
100 __DEFINE_LXSYSCALL(pid_t, getppid)
102 return __current->parent->pid;
105 __DEFINE_LXSYSCALL(pid_t, getpgid)
107 return __current->pgid;
110 __DEFINE_LXSYSCALL2(int, setpgid, pid_t, pid, pid_t, pgid)
112 struct proc_info* proc = pid ? get_process(pid) : __current;
115 syscall_result(EINVAL);
119 pgid = pgid ? pgid : proc->pid;
121 struct proc_info* gruppenfuhrer = get_process(pgid);
123 if (!gruppenfuhrer || proc->pgid == gruppenfuhrer->pid) {
124 syscall_result(EINVAL);
128 llist_delete(&proc->grp_member);
129 llist_append(&gruppenfuhrer->grp_member, &proc->grp_member);
136 __can_change_real_id(const struct user_scope* procu, caps_t id_cap) {
137 if (uscope_with_capability(procu, id_cap)) {
141 if (check_current_acl(0, 0) != ACL_NO_MATCH) {
148 __DEFINE_LXSYSCALL1(int, setuid, uid_t, uid)
150 struct user_scope* procu;
152 procu = current_user_scope();
154 if (__can_change_real_id(procu, CAP_SETUID))
159 __current->suid = uid;
160 __current->euid = uid;
165 __DEFINE_LXSYSCALL1(int, setgid, gid_t, gid)
167 struct user_scope* procu;
169 procu = current_user_scope();
171 if (__can_change_real_id(procu, CAP_SETGID))
176 __current->sgid = gid;
177 __current->egid = gid;
182 __DEFINE_LXSYSCALL1(int, seteuid, uid_t, euid)
184 __current->euid = euid;
189 __DEFINE_LXSYSCALL1(int, setegid, gid_t, egid)
191 __current->egid = egid;
196 __DEFINE_LXSYSCALL2(int, setgroups, const gid_t*, gids, unsigned int, len)
198 struct user_scope* procu;
200 procu = current_user_scope();
202 if (check_current_acl(0, 0) == ACL_NO_MATCH) {
206 if (uscope_with_capability(procu, CAP_SETGID)) {
210 return uscope_setgroups(procu, gids, len);
214 __DEFINE_LXSYSCALL(uid_t, getuid)
216 return current_user_scope()->ruid;
219 __DEFINE_LXSYSCALL(gid_t, getgid)
221 return current_user_scope()->rgid;
224 __DEFINE_LXSYSCALL(uid_t, geteuid)
226 return __current->euid;
229 __DEFINE_LXSYSCALL(gid_t, getegid)
231 return __current->egid;
234 __DEFINE_LXSYSCALL2(int, getgroups, gid_t*, out_buf, unsigned int, len)
236 struct user_scope* procu;
237 struct ugroup_obj* gobj;
239 procu = current_user_scope();
240 gobj = user_groups(procu);
243 len = MIN(gobj->maxcap, len);
246 for (; i < len && gobj->list[i] != grp_list_end; i++)
248 out_buf[i] = gobj->list[i];