aboutsummaryrefslogtreecommitdiff
path: root/common/uapi/proc.c
blob: c898339118abb73bc06de6f1efa489ff33152ca4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * @file proc.c
 * Process/thread handling syscall implementations.
 */

#include <apos/elf.h>
#include <apos/uapi.h>
#include <apos/bits.h>
#include <apos/mem_regions.h>

SYSCALL_DEFINE0(create)(){
	return (struct sys_ret){ OK, 0 };
}

/* Not entirely sure how I should handle forks/execs etc, mostly whether I
 * should allow forks/execs to be called directly or only though the process
 * manager. Probably though the process manager, although that will add in a
 * slight bit of delay.
 *
 * I suppose I could add in a runtime parameter
 * that would allow them to be called directly, and then the process manager
 * would have to periodically ask the kernel about all threads it is aware of
 * via sys_sync. Dunno.
 */
SYSCALL_DEFINE0(fork)(){
	return (struct sys_ret){ OK, 0 };
}

SYSCALL_DEFINE2(exec)(sys_arg_t bin, sys_arg_t interp){
	/* TODO: execute new process, probably with more sensible argc passing */
	struct tcb *r = cur_tcb();

	/* mark binary to be kept */
	struct mem_region *b = find_used_region(&r->sp_r, bin);
	if (!b)
		return (struct sys_ret){ERR_INVAL, 0};
	set_bit(b->flags, MR_KEEP);

	struct mem_region *i = 0;
	if (interp) {
		/* mark interpreter to be kept */
		i = find_used_region(&r->sp_r, interp);
		if (!i)
			return (struct sys_ret){ERR_INVAL, 1};
		set_bit(i->flags, MR_KEEP);
	}

	/* free everything except regions to be kept */
	clear_uvmem(r, false);

	/* restore to normal */
	clear_bit(b->flags, MR_KEEP);
	if (interp)
		clear_bit(b->flags, MR_KEEP);

	/* TODO: set entry? */
	load_elf(r, b, i);
	return (struct sys_ret){ OK, 0 };
}

SYSCALL_DEFINE2(signal)(sys_arg_t tid, sys_arg_t signal){
	/* TODO: signals? */
	return (struct sys_ret){ OK, 0 };
}

SYSCALL_DEFINE1(swap)(sys_arg_t tid){
	/* TODO: switch to process */
	/* TODO: should switch return the registers of the new thread that would
	 * be used for message passing? */
	return (struct sys_ret){ OK, 0 };
}