Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
An N Tran
project04aref
Commits
97fe004e
Commit
97fe004e
authored
2 years ago
by
An N Tran
Browse files
Options
Download
Email Patches
Plain Diff
Task 3
parent
85e72c3e
master
No related merge requests found
Pipeline
#73455
failed with stage
in 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kernel.c
+10
-14
kernel.c
with
10 additions
and
14 deletions
+10
-14
kernel.c
View file @
97fe004e
...
...
@@ -157,17 +157,16 @@ void process_setup(pid_t pid, const char* program_name) {
for
(
uintptr_t
a
=
round_down
(
seg
.
va
(),
PAGESIZE
);
a
<
seg
.
va
()
+
seg
.
size
();
a
+=
PAGESIZE
)
{
// (NB this is physical page allocation!)
assert
(
!
pages
[
a
/
PAGESIZE
].
used
());
++
pages
[
a
/
PAGESIZE
].
refcount
;
map_to_user_space
(
process_pagetable
,
a
);
uintptr_t
pa
=
(
uintptr_t
)
kalloc
(
PAGESIZE
);
memory_map
(
process_pagetable
,
a
,
pa
,
PTE_PWU
);
}
}
// initialize data in loadable segments
for
(
auto
seg
=
pgm
.
begin
();
seg
!=
pgm
.
end
();
++
seg
)
{
memset
((
void
*
)
seg
.
va
(),
0
,
seg
.
size
());
memcpy
((
void
*
)
seg
.
va
(),
seg
.
data
(),
seg
.
data_size
());
void
*
pa
=
memory_virtual_to_physical
(
process_pagetable
,
seg
.
va
());
memset
(
pa
,
0
,
seg
.
size
());
memcpy
(
pa
,
seg
.
data
(),
seg
.
data_size
());
}
// mark entry point
...
...
@@ -175,10 +174,8 @@ void process_setup(pid_t pid, const char* program_name) {
// allocate and map stack segment
uintptr_t
stack_addr
=
PROC_START_ADDR
+
PROC_SIZE
*
pid
-
PAGESIZE
;
// (NB this is physical page allocation!)
assert
(
!
pages
[
stack_addr
/
PAGESIZE
].
used
());
++
pages
[
stack_addr
/
PAGESIZE
].
refcount
;
map_to_user_space
(
process_pagetable
,
stack_addr
);
uintptr_t
pa
=
(
uintptr_t
)
kalloc
(
PAGESIZE
);
memory_map
(
process_pagetable
,
stack_addr
,
pa
,
PTE_PWU
);
ptable
[
pid
].
regs
.
reg_rsp
=
stack_addr
+
PAGESIZE
;
// mark process as runnable
...
...
@@ -327,10 +324,9 @@ uintptr_t syscall(regstate* regs) {
// in `u-lib.hh` (but in the handout code, it does not).
int
syscall_page_alloc
(
uintptr_t
addr
)
{
assert
(
!
pages
[
addr
/
PAGESIZE
].
used
());
pages
[
addr
/
PAGESIZE
].
refcount
=
1
;
memset
((
void
*
)
addr
,
0
,
PAGESIZE
);
map_to_user_space
(
current
->
pagetable
,
addr
);
uintptr_t
pa
=
(
uintptr_t
)
kalloc
(
PAGESIZE
);
memory_map
(
current
->
pagetable
,
addr
,
pa
,
PTE_PWU
);
memset
(
memory_virtual_to_physical
(
current
->
pagetable
,
addr
),
0
,
PAGESIZE
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help