-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.h
More file actions
90 lines (77 loc) · 2.55 KB
/
process.h
File metadata and controls
90 lines (77 loc) · 2.55 KB
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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
#ifndef WEENSYOS_PROCESS_H
#define WEENSYOS_PROCESS_H
#include "lib.h"
#include "x86-64.h"
#if WEENSYOS_KERNEL
#error "process.h should not be used by kernel code."
#endif
// process.h
//
// Support code for WeensyOS processes.
// SYSTEM CALLS
// sys_getpid
// Return current process ID.
static inline pid_t sys_getpid(void) {
pid_t result;
asm volatile ("int %1" : "=a" (result)
: "i" (INT_SYS_GETPID)
: "cc", "memory");
return result;
}
// sys_yield
// Yield control of the CPU to the kernel. The kernel will pick another
// process to run, if possible.
static inline void sys_yield(void) {
asm volatile ("int %0" : /* no result */
: "i" (INT_SYS_YIELD)
: "cc", "memory");
}
// sys_page_alloc(addr)
// Allocate a page of memory at address `addr`. `Addr` must be page-aligned
// (i.e., a multiple of PAGESIZE == 4096). Returns 0 on success and -1
// on failure.
static inline int sys_page_alloc(void* addr) {
int result;
asm volatile ("int %1" : "=a" (result)
: "i" (INT_SYS_PAGE_ALLOC), "D" /* %rdi */ (addr)
: "cc", "memory");
return result;
}
// sys_fork()
// Fork the current process. On success, return the child's process ID to
// the parent, and return 0 to the child. On failure, return -1.
static inline pid_t sys_fork(void) {
pid_t result;
asm volatile ("int %1" : "=a" (result)
: "i" (INT_SYS_FORK)
: "cc", "memory");
return result;
}
// sys_exit()
// Exit this process. Does not return.
static inline void sys_exit(void) __attribute__((noreturn));
static inline void sys_exit(void) {
asm volatile ("int %0" : /* no result */
: "i" (INT_SYS_EXIT)
: "cc", "memory");
spinloop: goto spinloop; // should never get here
}
// sys_panic(msg)
// Panic.
static inline pid_t __attribute__((noreturn)) sys_panic(const char* msg) {
asm volatile ("int %0" : /* no result */
: "i" (INT_SYS_PANIC), "D" (msg)
: "cc", "memory");
loop: goto loop;
}
// OTHER HELPER FUNCTIONS
// app_printf(format, ...)
// Calls console_printf() (see lib.h). The cursor position is read from
// `cursorpos`, a shared variable defined by the kernel, and written back
// into that variable. The initial color is based on the current process ID.
void app_printf(int colorid, const char* format, ...);
#endif