Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos_forked_resit
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s2-alsaloumi
Pintos_forked_resit
Commits
7a1b4383
Commit
7a1b4383
authored
1 year ago
by
h2-addad
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9b9a54d0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tests/vm/mmap-clean.c
+53
-0
53 additions, 0 deletions
src/tests/vm/mmap-clean.c
with
53 additions
and
0 deletions
src/tests/vm/mmap-clean.c
0 → 100644
+
53
−
0
View file @
7a1b4383
/* Verifies that mmap'd regions are only written back on munmap
if the data was actually modified in memory. */
#include
<string.h>
#include
<syscall.h>
#include
"tests/vm/sample.inc"
#include
"tests/lib.h"
#include
"tests/main.h"
void
test_main
(
void
)
{
static
const
char
overwrite
[]
=
"Now is the time for all good..."
;
static
char
buffer
[
sizeof
sample
-
1
];
char
*
actual
=
(
char
*
)
0x54321000
;
int
handle
;
mapid_t
map
;
/* Open file, map, verify data. */
CHECK
((
handle
=
open
(
"sample.txt"
))
>
1
,
"open
\"
sample.txt
\"
"
);
CHECK
((
map
=
mmap
(
handle
,
actual
))
!=
MAP_FAILED
,
"mmap
\"
sample.txt
\"
"
);
if
(
memcmp
(
actual
,
sample
,
strlen
(
sample
)))
fail
(
"read of mmap'd file reported bad data"
);
/* Modify file. */
CHECK
(
write
(
handle
,
overwrite
,
strlen
(
overwrite
))
==
(
int
)
strlen
(
overwrite
),
"write
\"
sample.txt
\"
"
);
/* Close mapping. Data should not be written back, because we
didn't modify it via the mapping. */
msg
(
"munmap
\"
sample.txt
\"
"
);
munmap
(
map
);
/* Read file back. */
msg
(
"seek
\"
sample.txt
\"
"
);
seek
(
handle
,
0
);
CHECK
(
read
(
handle
,
buffer
,
sizeof
buffer
)
==
sizeof
buffer
,
"read
\"
sample.txt
\"
"
);
/* Verify that file overwrite worked. */
if
(
memcmp
(
buffer
,
overwrite
,
strlen
(
overwrite
))
||
memcmp
(
buffer
+
strlen
(
overwrite
),
sample
+
strlen
(
overwrite
),
strlen
(
sample
)
-
strlen
(
overwrite
)))
{
if
(
!
memcmp
(
buffer
,
sample
,
strlen
(
sample
)))
fail
(
"munmap wrote back clean page"
);
else
fail
(
"read surprising data from file"
);
}
else
msg
(
"file change was retained after munmap"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment