/
system.c
110 lines (89 loc) · 3.17 KB
/
system.c
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Abstract: Library for system related stuff.
// Author: Per Lundberg <per@chaosdev.io>
//
// © Copyright 2000 chaos development
// © Copyright 2007 chaos development
// © Copyright 2013 chaos development
// © Copyright 2015-2016 chaos development
#include <system/system.h>
void system_shutdown(void)
{
// TODO: Make sure we are root. If not, we will only end up killing our own processes, which is probably not what we want...
// TODO: Kill all processes.
while (TRUE);
}
// Sleep for a given amount of time. (In milliseconds)
return_type system_sleep(unsigned int time)
{
#if FALSE
time_type start_time, current_time;
system_call_timer_read(&start_time);
current_time = start_time;
while (current_time < start_time + time + 1)
{
system_call_timer_read(¤t_time);
system_call_dispatch_next();
}
#endif
kernelfs_self_type kernelfs_self;
kernelfs_self.kernelfs_class = KERNELFS_CLASS_SELF_INFO;
system_call_kernelfs_entry_read(&kernelfs_self);
system_call_thread_control(kernelfs_self.thread_id, THREAD_SLEEP, time);
return SYSTEM_RETURN_SUCCESS;
}
return_type system_sleep_microseconds(unsigned int time)
{
kernelfs_self_type kernelfs_self;
kernelfs_self.kernelfs_class = KERNELFS_CLASS_SELF_INFO;
system_call_kernelfs_entry_read(&kernelfs_self);
system_call_thread_control(kernelfs_self.thread_id, THREAD_SLEEP, (time / 1000) + 1);
return SYSTEM_RETURN_SUCCESS;
}
return_type system_process_name_set(const char *name)
{
system_call_process_name_set(name);
return SYSTEM_RETURN_SUCCESS;
}
return_type system_cluster_name_set(const char *name UNUSED)
{
// FIXME: Do something here. I guess we need a conforming system call first...
return SYSTEM_RETURN_SUCCESS;
}
return_type system_thread_name_set(const char *name)
{
system_call_thread_name_set(name);
return SYSTEM_RETURN_SUCCESS;
}
return_type system_thread_create(thread_entry_point_type *thread_entry_point, void *argument)
{
switch (system_call_thread_create(thread_entry_point, argument))
{
case STORM_RETURN_SUCCESS:
{
return SYSTEM_RETURN_SUCCESS;
}
// Someone has added a return code in thread.c in the kernel without handling it in the system library. Please fix this in
// the system library and send us a patch/pull request.
default:
{
return SYSTEM_RETURN_THREAD_CREATE_FAILED;
}
}
}
// Execute the program specified in the foreground (that is, this function doesn't return until the child process has been
// terminated)
// FIXME: Maybe have a flag that says whether we should wait or not?
// FIXME: Should we open a connection to the VFS on startup, or...?
return_type system_execute(const char *program UNUSED)
{
return SYSTEM_RETURN_SUCCESS;
}
// Exit the current thread. If this is the last thread of the process, the process will be terminated too.
void system_exit(void)
{
kernelfs_self_type kernelfs_self;
kernelfs_self.kernelfs_class = KERNELFS_CLASS_SELF_INFO;
system_call_kernelfs_entry_read(&kernelfs_self);
system_call_thread_control(kernelfs_self.thread_id, THREAD_TERMINATE, 0);
while (TRUE);
}