summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2021-08-18 17:36:16 +0200
committerdzwdz2021-08-18 17:36:16 +0200
commitbaa4c5e085d81b2021b25adaba61d32e3f835a56 (patch)
tree6c3b421591933df64a368e7f59537963e7139ed6
parentab1f8ed9b9513de631193aaa024ddb86eb2a97b7 (diff)
fork() now has a return value; you can tell the child and parent apart
-rw-r--r--src/init/main.c11
-rw-r--r--src/kernel/syscalls.c6
-rw-r--r--src/kernel/syscalls.h3
3 files changed, 12 insertions, 8 deletions
diff --git a/src/init/main.c b/src/init/main.c
index a59ce9c..c6d19a3 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -19,10 +19,13 @@ int main() {
multipageify("I cross pages. "),
sizeof("I cross pages. ") - 1);
- _syscall_fork();
-
- _syscall_debuglog("fork ",
- sizeof("fork ") - 1);
+ if (_syscall_fork() > 0) {
+ _syscall_debuglog("parent ",
+ sizeof("parent ") - 1);
+ } else {
+ _syscall_debuglog("child ",
+ sizeof("child ") - 1);
+ }
_syscall_exit("bye from init! ",
sizeof("bye from init! ") - 1);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index e160270..6a61a9d 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -17,9 +17,9 @@ _Noreturn void _syscall_exit(const char *msg, size_t len) {
}
int _syscall_fork() {
- struct process *orig = process_current;
- process_current = process_fork(orig);
- process_switch(process_current);
+ struct process *child = process_fork(process_current);
+ regs_savereturn(&child->regs, 0);
+ return 1;
}
int _syscall_debuglog(const char *msg, size_t len) {
diff --git a/src/kernel/syscalls.h b/src/kernel/syscalls.h
index 78a47b2..d3ad2a8 100644
--- a/src/kernel/syscalls.h
+++ b/src/kernel/syscalls.h
@@ -16,7 +16,8 @@ enum {
_Noreturn void _syscall_exit(const char *msg, size_t len);
/** Creates a copy of the current process, and executes it.
- * All user memory pages get copied too. Doesn't return anything useful.. yet.
+ * All user memory pages get copied too.
+ * @return 0 in the child, a meaningless positive value in the parent.
*/
int _syscall_fork();