diff options
author | turret <turret@duck.com> | 2023-11-19 19:13:40 -0600 |
---|---|---|
committer | turret <turret@duck.com> | 2023-11-19 19:13:40 -0600 |
commit | 40bff7788865b519b79b1ee7eb9851914010ffb4 (patch) | |
tree | b11af475d4eb933acb2d610c555d6715f76def4e /init/subsys.c | |
parent | a8b2282eb88f24c3c5f461e1557fa2cf76ebc251 (diff) | |
download | discord-bot-skeleton-40bff7788865b519b79b1ee7eb9851914010ffb4.tar.gz discord-bot-skeleton-40bff7788865b519b79b1ee7eb9851914010ffb4.tar.bz2 discord-bot-skeleton-40bff7788865b519b79b1ee7eb9851914010ffb4.zip |
misc: minor bugs and comments
sprinkle a little bit of commenting throughout the codebase. hopefully
i dont regret what i've written
- clone: bottom of stack is passed through
- print: write newline at end of message
- initcall: functions return void type
very basic net startup. hopefully i dont regret implementing the
websocket protocol myself in a language as holy as C.
Diffstat (limited to 'init/subsys.c')
-rw-r--r-- | init/subsys.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/init/subsys.c b/init/subsys.c index 0435f1a..62ee54e 100644 --- a/init/subsys.c +++ b/init/subsys.c @@ -21,7 +21,9 @@ struct subsystem_info { int __subsystem_entry(struct subsystem_info *info) { - + /* entry point from clone(). we setup the process name so we know + what we are looking at from a glance in a ps view or htop or + whatever. */ char *name = malloc(16 * sizeof(char)); snprintf(name, 16, NAME_SHORTHAND ": %s", info->fn_name); name[15] = '\0'; @@ -30,6 +32,7 @@ int __subsystem_entry(struct subsystem_info *info) int ret = info->fn(); + /* we are expected to free info before exiting */ free(info); return ret; @@ -37,15 +40,20 @@ int __subsystem_entry(struct subsystem_info *info) int __impl_start_subsystem(char *fn_name, int (*fn)(void)) { + /* because CLONE_VM is being set, our stack is not duplicated and + therefore we need to map a stack */ void *stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_GROWSDOWN | MAP_STACK | MAP_PRIVATE, -1, 0); if((long)stack < 0) die("subsys mmap:"); + /* the libc gods have graced us with the ability to pass one (1) arg + to the function. struct required. the absence of a free is not a + memory leak because we free it above. */ struct subsystem_info *info = malloc(sizeof(struct subsystem_info)); info->fn_name = fn_name; info->fn = fn; - int pid = clone((int (*)(void *))__subsystem_entry, stack, CLONE_FILES | CLONE_VM, info); + int pid = clone((int (*)(void *))__subsystem_entry, (void *)((long)stack + STACK_SIZE), CLONE_FILES | CLONE_VM, info); if(pid < 0) { munmap(stack, STACK_SIZE); die("subsys clone:"); |