Skip to content

Commit

Permalink
feat(kernel: process): provide an argument to the entrypoint function
Browse files Browse the repository at this point in the history
  • Loading branch information
d4ilyrun committed Jun 14, 2024
1 parent c888779 commit 79d7113
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
7 changes: 5 additions & 2 deletions include/kernel/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ void process_switch(process_t *process);
*
* @param name The name of the process
* @param entrypoint The function called when starting the process
* @param data Data passed to the entry function (can be NULL)
*/
process_t *process_create(char *name, process_entry_t entrypoint);
process_t *process_create(char *name, process_entry_t entrypoint, void *);

/** Effectively kill a process
*
Expand Down Expand Up @@ -134,12 +135,14 @@ void arch_process_switch(process_context_t *);
*
* @param process Pointer to process to initialize
* @param entrypoint The entrypoint used for starting this process
* @param data Data passed to the entry function (can be NULL)
*
* @return Whether we succeded or not
*
* @warning Do not call this function directly! This should only be
* called by @ref process_create
*/
bool arch_process_create(process_t *process, process_entry_t entrypoint);
bool arch_process_create(process_t *process, process_entry_t entrypoint,
void *);

/** @} */
5 changes: 3 additions & 2 deletions kernel/arch/i686/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void arch_process_entrypoint(void)
log_err("SCHED", "Failed to initilize VMM (%s)", current_process->name);
}

bool arch_process_create(process_t *process, process_entry_t entrypoint)
bool arch_process_create(process_t *process, process_entry_t entrypoint,
void *data)
{
// Allocate a kernel stack for the new process
u32 *kstack = kmalloc(KERNEL_STACK_SIZE, KMALLOC_KERNEL);
Expand All @@ -46,7 +47,7 @@ bool arch_process_create(process_t *process, process_entry_t entrypoint)
#define KSTACK(_i) kstack[KERNEL_STACK_SIZE / sizeof(u32) - (_i)]

// Stack frame for arch_process_entrypoint
KSTACK(0) = 0x1234; // arg1(NULL)
KSTACK(0) = (u32)data; // arg1
KSTACK(1) = 0; // nuke ebp
KSTACK(2) = (u32)entrypoint; // eip

Expand Down
4 changes: 1 addition & 3 deletions kernel/devices/uacpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ uacpi_status uacpi_kernel_schedule_work(uacpi_work_type type,
{
UNUSED(type);

// FIXME: pass argument to process
UNUSED(ctx);
process_t *process = process_create("kuacpi", handler);
process_t *process = process_create("kuacpi", handler, ctx);
if (process == NULL)
return UACPI_STATUS_OUT_OF_MEMORY;

Expand Down
2 changes: 1 addition & 1 deletion kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void kernel_main(struct multiboot_info *mbt, unsigned int magic)
}

process_t *kernel_timer_test =
process_create("ktimer_test", kernel_task_timer);
process_create("ktimer_test", kernel_task_timer, NULL);
sched_new_process(kernel_timer_test);

log_dbg("TASK", "Re-started task: '%s'", current_process->name);
Expand Down
4 changes: 2 additions & 2 deletions kernel/sys/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ process_t *current_process = &kernel_startup_process;
* * Create a new page directory
* * Copy the kernel's page table
*/
process_t *process_create(char *name, process_entry_t entrypoint)
process_t *process_create(char *name, process_entry_t entrypoint, void *data)
{
process_t *new = kmalloc(sizeof(*new), KMALLOC_KERNEL);
if (new == NULL) {
Expand All @@ -51,7 +51,7 @@ process_t *process_create(char *name, process_entry_t entrypoint)
new->pid = g_highest_pid++;
new->vmm = vmm;

if (!arch_process_create(new, entrypoint)) {
if (!arch_process_create(new, entrypoint, data)) {
kfree(vmm);
kfree(new);
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/sys/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void idle_task(void *data __attribute__((unused)))

void scheduler_init(void)
{
idle_process = process_create("<< IDLE >>", idle_task);
idle_process = process_create("<< IDLE >>", idle_task, NULL);
// use the largest PID possible to avoid any conflict later on
idle_process->pid = (pid_t)-1;
sched_new_process(idle_process);
Expand Down

0 comments on commit 79d7113

Please sign in to comment.