The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
kstack.c File Reference
#include "kstack.h"
#include "memory_layout.h"
#include "phys.h"
#include "pmm.h"
#include "arch/arch.h"
#include "common/memory.h"
#include "kernel/process/process.h"
#include "kernel/sync/spinlock.h"
#include "kernel/memory/tlb.h"

Macros

#define KSTACK_SLOT_SIZE   (KSTACK_GUARD_SIZE + KERNEL_STACK_SIZE)
#define KSTACK_SLOTS   PROCESS_MAX
#define KSTACK_PAGES   (KERNEL_STACK_SIZE / PAGE_SIZE)
#define KSTACK_REGION_END   (KSTACK_REGION_BASE + KSTACK_SLOTS * KSTACK_SLOT_SIZE)

Functions

void kstack_init (void)
 reserve the kernel stack region.
uintptr_t kstack_alloc (void)
 allocate and map a zeroed kernel stack.
void kstack_free (uintptr_t base)
 unmap a kernel stack and return its frames and slot.
bool kstack_is_guard (uintptr_t addr)
 check whether an address falls in the guard page of any stack slot.

Macro Definition Documentation

◆ KSTACK_SLOT_SIZE

#define KSTACK_SLOT_SIZE   (KSTACK_GUARD_SIZE + KERNEL_STACK_SIZE)

◆ KSTACK_SLOTS

#define KSTACK_SLOTS   PROCESS_MAX

◆ KSTACK_PAGES

#define KSTACK_PAGES   (KERNEL_STACK_SIZE / PAGE_SIZE)

◆ KSTACK_REGION_END

#define KSTACK_REGION_END   (KSTACK_REGION_BASE + KSTACK_SLOTS * KSTACK_SLOT_SIZE)

Function Documentation

◆ kstack_init()

void kstack_init ( void )

reserve the kernel stack region.

must run after paging_init() and before the first address space is created (process_create()).

◆ kstack_alloc()

uintptr_t kstack_alloc ( void )

allocate and map a zeroed kernel stack.

Returns
the lowest address of the stack (it grows down from base + KERNEL_STACK_SIZE), or 0 if no slot or memory is free.

◆ kstack_free()

void kstack_free ( uintptr_t base)

unmap a kernel stack and return its frames and slot.

never free the stack the CPU is currently running on.

Parameters
basethe value kstack_alloc() returned.

◆ kstack_is_guard()

bool kstack_is_guard ( uintptr_t addr)

check whether an address falls in the guard page of any stack slot.

Parameters
addrthe address to check (e.g. a page fault's CR2).
Returns
true if addr is inside a guard page.