The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
user_space.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * the user half of an address space: the page tables, the areas (vma.h)
5 * and the program break. the threads of a process use one user space
6 * together; it is freed when the last of them lets it go.
7 */
8
9#include "common/stdint.h"
10#include "kernel/memory/vma.h"
11#include "kernel/sync/mutex.h"
12#include "kernel/cpu/cpu.h"
13#include "arch/arch.h"
14
15typedef struct user_space
16{
17 volatile uint32_t users; // the processes (threads) that use it (atomic)
18 volatile uint32_t cpu_mask[CPU_MAX / 32]; // the cores that have it loaded (atomic bits)
19 addr_space_t page_directory; // the page tables (the kernel half is shared)
20 vma_table_t vmas; // what is mapped in the user half
21 uintptr_t brk; // the program break (for sbrk)
22 mutex_t lock; // held by a memory syscall (mmap, sbrk, fork) of a thread
24
25/**
26 * make an empty user space with one user.
27 * @return the space, or NULL if there is no memory.
28 */
30
31/**
32 * add a user to a space (a new thread that shares it).
33 * @param space the space.
34 * @return space.
35 */
37
38/**
39 * remove a user from a space. the last user frees it: its pages, its page
40 * tables and the object. a process that lets go of its own space must
41 * load other page tables first (user_space_activate), because a thread on
42 * another core can free the space at once.
43 * @param space the space, or NULL (nothing is done).
44 */
45void user_space_put(user_space_t *space);
46
47/**
48 * load the page tables of a space on the core that runs the call, and keep
49 * the cpu_mask of the old and the new space right: a TLB shootdown goes to
50 * the cores in the mask. every change of address space goes through here.
51 * call it with interrupts off.
52 * @param space the space, or NULL for the kernel's page tables.
53 */
55
56/**
57 * true if the core has the space loaded now.
58 * @param space the space.
59 * @param core the index of the core.
60 */
61bool user_space_on_cpu(const user_space_t *space, uint32_t core);
uintptr_t addr_space_t
an address space handle.
Definition arch.h:105
the data of each core (per-CPU data).
#define CPU_MAX
the most cores that ginnOS uses
Definition cpu.h:18
unsigned int uint32_t
Definition fb.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:19
sleeping mutex for long critical sections in process context (filesystem and disk I/O).
Definition mutex.h:20
the user half of an address space: the page tables, the areas (vma.h) and the program break.
Definition user_space.h:16
uintptr_t brk
Definition user_space.h:21
volatile uint32_t cpu_mask[CPU_MAX/32]
Definition user_space.h:18
addr_space_t page_directory
Definition user_space.h:19
vma_table_t vmas
Definition user_space.h:20
mutex_t lock
Definition user_space.h:22
volatile uint32_t users
Definition user_space.h:17
a process's areas, sorted by start.
Definition vma.h:58
bool user_space_on_cpu(const user_space_t *space, uint32_t core)
true if the core has the space loaded now.
Definition user_space.c:74
void user_space_activate(user_space_t *space)
load the page tables of a space on the core that runs the call, and keep the cpu_mask of the old and ...
Definition user_space.c:50
void user_space_put(user_space_t *space)
remove a user from a space.
Definition user_space.c:34
user_space_t * user_space_create(void)
make an empty user space with one user.
Definition user_space.c:8
user_space_t * user_space_get(user_space_t *space)
add a user to a space (a new thread that shares it).
Definition user_space.c:28
struct user_space user_space_t
the user half of an address space: the page tables, the areas (vma.h) and the program break.