AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
kthread.c File Reference

Kernel threads. More...

#include <core/system.h>
#include <core/arch.h>
#include <core/panic.h>
#include <core/string.h>
#include <mm/vm.h>
#include <sys/kthread.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <ds/queue.h>

Go to the source code of this file.

Functions

static int kproc_init (void)
 Makes process 0, the kernel threads' process, the first time a kernel thread is made.
static void kthread_start (void)
 Runs a kernel thread's function: every kernel thread starts here, on its own stack (arch_kthread_create()).
int kthread_create (const char *name, void(*fn)(void *), void *arg, struct thread **ref)
 Makes a kernel thread, and makes it ready to run.

Variables

struct proc * kproc

Detailed Description

Kernel threads.

Kernel threads are the threads of process 0, "[kernel]", as on the BSDs. They run kernel functions on their kernel stacks, in the kernel's address space, and are scheduled like any other thread. Process 0 has no parent, has its own session and process group, and takes no signals.

Definition in file kthread.c.

Function Documentation

◆ kproc_init()

int kproc_init ( void )
static

Makes process 0, the kernel threads' process, the first time a kernel thread is made.

Returns 0, or -ENOMEM.

Definition at line 27 of file kthread.c.

References kmalloc(), kproc, kproc_init(), kvm_space, M_ZERO, proc::name, panic, proc::pid, vm_space::pmap, procs, proc::running, session_new(), SIG_DFL, SIG_MAX, proc::sigaction, and proc::vm_space.

Referenced by kproc_init(), and kthread_create().

◆ kthread_create()

int kthread_create ( const char * name,
void(* fn )(void *),
void * arg,
struct thread ** ref )

Makes a kernel thread, and makes it ready to run.

Parameters
namethe thread's name, as ps shows it ("[net]")
fnthe function it runs, which must never return
argthe argument fn is called with
refif not NULL, set to the new thread
Returns
0, or -ENOMEM if there was no memory for the thread

Definition at line 71 of file kthread.c.

References thread::arch, arch_kthread_create(), thread::karg, thread::kentry, kfree(), kproc, kproc_init(), kthread_create(), kthread_start(), thread::name, NULL, RUNNABLE, sched_thread_ready(), thread::spawned, thread::state, thread_new(), and proc::threads.

Referenced by kthread_create(), and netif_register().

◆ kthread_start()

void kthread_start ( void )
static

Runs a kernel thread's function: every kernel thread starts here, on its own stack (arch_kthread_create()).

The function must not return.

Definition at line 56 of file kthread.c.

References curthread, kthread_start(), and panic.

Referenced by kthread_create(), and kthread_start().

Variable Documentation

◆ kproc

struct proc* kproc

Definition at line 23 of file kthread.c.

Referenced by kproc_init(), kthread_create(), signal_interrupts(), signal_send(), and signal_to().