The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
kstack.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* kernel stacks with guard pages.
5
*
6
* every process's kernel stack lives in a fixed virtual region
7
* (KSTACK_REGION_BASE) split into one slot per process. a slot is an unmapped
8
* guard page followed by KERNEL_STACK_SIZE bytes of mapped stack, so running
9
* off the bottom of a stack faults on the guard page instead of silently
10
* overwriting whatever physical frame lies below it. the region's page table
11
* is reserved at boot and shared by every address space, so a stack mapped
12
* later is reachable from any process.
13
*/
14
15
#include "
common/stdint.h
"
16
#include "
kernel/memory/page.h
"
17
18
// size of the unmapped guard page below each stack
19
#define KSTACK_GUARD_SIZE PAGE_SIZE
20
21
/**
22
* reserve the kernel stack region. must run after paging_init() and before
23
* the first address space is created (process_create()).
24
*/
25
void
kstack_init
(
void
);
26
27
/**
28
* allocate and map a zeroed kernel stack.
29
* @return the lowest address of the stack (it grows down from
30
* base + KERNEL_STACK_SIZE), or 0 if no slot or memory is free.
31
*/
32
uintptr_t
kstack_alloc
(
void
);
33
34
/**
35
* unmap a kernel stack and return its frames and slot. never free the stack
36
* the CPU is currently running on.
37
* @param base the value kstack_alloc() returned.
38
*/
39
void
kstack_free
(
uintptr_t
base
);
40
41
/**
42
* check whether an address falls in the guard page of any stack slot.
43
* @param addr the address to check (e.g. a page fault's CR2).
44
* @return true if addr is inside a guard page.
45
*/
46
bool
kstack_is_guard
(
uintptr_t
addr);
stdint.h
base
uint32_t base
Definition
gdt.c:1
kstack_init
void kstack_init(void)
reserve the kernel stack region.
Definition
kstack.c:71
kstack_free
void kstack_free(uintptr_t base)
unmap a kernel stack and return its frames and slot.
Definition
kstack.c:121
kstack_alloc
uintptr_t kstack_alloc(void)
allocate and map a zeroed kernel stack.
Definition
kstack.c:82
kstack_is_guard
bool kstack_is_guard(uintptr_t addr)
check whether an address falls in the guard page of any stack slot.
Definition
kstack.c:133
uintptr_t
__UINTPTR_TYPE__ uintptr_t
Definition
stdint.h:19
page.h
src
kernel
memory
kstack.h
Generated by
1.18.0