forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out some things from the xX_main_Xx function
- Loading branch information
Showing
4 changed files
with
71 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include "kernel/init.h" | ||
#include "kernel/calls.h" | ||
#include "fs/tty.h" | ||
|
||
void mount_root(const char *source) { | ||
mounts = malloc(sizeof(struct mount)); | ||
mounts->point = ""; | ||
mounts->source = strdup(source); | ||
mounts->fs = &realfs; | ||
mounts->next = NULL; | ||
} | ||
|
||
static void nop_handler() {} | ||
|
||
// this function parses command line arguments and initializes global | ||
// data structures. thanks programming discussions discord server for the name. | ||
// https://discord.gg/9zT7NHP | ||
int create_init_process(const char *program, char *const argv[], char *const envp[]) { | ||
signal(SIGUSR1, nop_handler); | ||
|
||
current = process_create(); | ||
current->cpu.mem = mem_new(); | ||
current->ppid = 1; | ||
current->uid = current->gid = 0; | ||
current->root = generic_open("/", O_RDONLY_, 0); | ||
current->pwd = generic_dup(current->root); | ||
current->umask = 0022; | ||
current->thread = pthread_self(); | ||
sys_setsid(); | ||
|
||
return sys_execve(program, argv, envp); | ||
} | ||
|
||
int create_stdio(struct tty_driver driver) { | ||
// I can't wait for when init and udev works and I don't need to do this | ||
tty_drivers[TTY_VIRTUAL] = driver; | ||
|
||
// FIXME use generic_open (or something) to avoid this mess | ||
struct fd *fd = adhoc_fd_create(); | ||
fd->stat->rdev = dev_make(4, 0); | ||
fd->stat->mode = S_IFCHR | S_IRUSR; | ||
int err = dev_open(4, 0, DEV_CHAR, fd); | ||
if (err < 0) | ||
return err; | ||
current->files[0] = fd; | ||
current->files[1] = generic_dup(fd); | ||
current->files[2] = generic_dup(fd); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef KERNEL_INIT_H | ||
#define KERNEL_INIT_H | ||
|
||
#include "fs/tty.h" | ||
|
||
void mount_root(const char *source); | ||
int create_init_process(const char *program, char *const argv[], char *const envp[]); | ||
int create_stdio(struct tty_driver driver); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters