AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
fork.c
Go to the documentation of this file.
1
6
7
#include <
core/system.h
>
8
#include <
core/string.h
>
9
#include <
core/arch.h
>
10
#include <
sys/proc.h
>
11
#include <
sys/sched.h
>
12
13
#include <aquila/errno.h>
14
15
struct
aarch64_thread
*
aarch64_thread_new
(
void
);
16
17
/*
18
* Sets up the child's thread of a `fork()`: its kernel stack, its saved
19
* registers (its parent's), and its FP/SIMD state.
20
*/
21
int
arch_proc_fork
(
struct
thread
*
thread
,
struct
proc
*fork)
22
{
23
struct
aarch64_thread
*parch =
thread
->
arch
;
24
struct
aarch64_thread
*farch =
aarch64_thread_new
();
25
26
if
(!farch)
27
return
-ENOMEM;
28
29
/* a copy of the fork system call's registers, at the top of its stack
30
* (where user mode's next exception lands) */
31
struct
aarch64_regs
*regs = (
struct
aarch64_regs
*) (farch->
kstack
-
sizeof
(
struct
aarch64_regs
));
32
*regs = *parch->
regs
;
33
farch->
regs
= regs;
34
35
/* when it's first chosen, it starts at aarch64_fork_return
36
* (cpu/vectors.S), which returns to user mode from that frame */
37
extern
void
aarch64_fork_return(
void
);
38
farch->
ctx
.
lr
= (
uintptr_t
) aarch64_fork_return;
39
farch->
ctx
.
sp
= (
uintptr_t
) regs;
40
farch->
ctx
.
fp
= 0;
41
42
/* its FP/SIMD registers are its parent's */
43
if
(
aarch64_fpsimd_fork
(
thread
, farch)) {
44
kfree
((
void
*) farch->
kstack_base
);
45
kfree
(farch);
46
return
-ENOMEM;
47
}
48
49
struct
thread
*fthread = (
struct
thread
*) fork->
threads
.
head
->
value
;
50
fthread->
arch
= farch;
51
52
return
0;
53
}
aarch64_thread_new
struct aarch64_thread * aarch64_thread_new(void)
Makes a thread's aarch64 state, with its kernel stack.
Definition
thread.c:30
arch_proc_fork
int arch_proc_fork(struct thread *thread, struct proc *fork)
Sets up the CPU state of a fork() child's thread: a copy of the parent's kernel stack,...
Definition
fork.c:21
aarch64_fpsimd_fork
int aarch64_fpsimd_fork(struct thread *parent, struct aarch64_thread *child)
Gives a child of fork() a copy of its parent's FP/SIMD state, if the parent has one.
Definition
fpsimd.c:129
arch.h
system.h
kfree
void kfree(void *)
Frees an object that kmalloc() gave.
Definition
kvmem.c:146
proc.h
sched.h
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
string.h
aarch64_ctx::lr
uint64_t lr
Definition
arch.h:16
aarch64_ctx::sp
uint64_t sp
Definition
arch.h:17
aarch64_ctx::fp
uint64_t fp
Definition
arch.h:15
aarch64_regs
What an exception saves on the kernel stack (cpu/vectors.S): the context it interrupted.
Definition
cpu.h:12
aarch64_thread
A thread's aarch64 state (thread->arch).
Definition
arch.h:25
aarch64_thread::ctx
struct aarch64_ctx ctx
Definition
arch.h:29
aarch64_thread::kstack_base
uintptr_t kstack_base
Definition
arch.h:27
aarch64_thread::kstack
uintptr_t kstack
Definition
arch.h:26
aarch64_thread::regs
struct aarch64_regs * regs
Definition
arch.h:33
proc
A process.
Definition
proc.h:75
proc::threads
struct queue threads
its threads
Definition
proc.h:136
qnode::value
void * value
Definition
queue.h:20
queue::head
struct qnode * head
Definition
queue.h:31
thread
A thread.
Definition
thread.h:23
thread::arch
void * arch
the architecture's own data: its registers, its kernel stack
Definition
thread.h:84
kernel
arch
aarch64
sys
fork.c
Generated by
1.18.0