Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
wendelin.core
Commits
2dd54723
Commit
2dd54723
authored
Jun 26, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
t/map-private-dup: Demo program showing that we can't get aliasing with MAP_PRIVATE mappings
parent
e92f4f16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
t/map-private-dup.c
t/map-private-dup.c
+59
-0
No files found.
t/map-private-dup.c
0 → 100644
View file @
2dd54723
// Demo program showing that changes made to one MAP_PRIVATE mapping do not
// propagate to another MAP_PRIVATE mapping even in the same process.
#define _GNU_SOURCE
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#undef NDEBUG
#include <assert.h>
void
die
(
const
char
*
msg
)
{
perror
(
msg
);
exit
(
1
);
}
int
main
()
{
int
fd
;
uint8_t
*
P1
,
*
P2
;
fd
=
open
(
"map-private-dup.c"
,
O_RDONLY
);
if
(
fd
==
-
1
)
die
(
"open"
);
P1
=
mmap
(
NULL
,
4096
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
,
fd
,
0
);
if
(
P1
==
MAP_FAILED
)
die
(
"mmap P1"
);
printf
(
"P1 orig: %c %c %c ...
\n
"
,
P1
[
0
],
P1
[
1
],
P1
[
2
]);
P1
[
0
]
=
'x'
;
P1
[
1
]
=
'y'
;
P1
[
2
]
=
'z'
;
printf
(
"P1 changed: %c %c %c ...
\n
"
,
P1
[
0
],
P1
[
1
],
P1
[
2
]);
P2
=
mmap
(
NULL
,
4096
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
,
fd
,
0
);
if
(
P2
==
MAP_FAILED
)
die
(
"mmap P2"
);
printf
(
"P2 orig: %c %c %c ...
\n
"
,
P2
[
0
],
P2
[
1
],
P2
[
2
]);
// below asserts will fail because P2 does not see changes of P1.
assert
(
P2
[
0
]
==
'x'
);
assert
(
P2
[
1
]
==
'y'
);
assert
(
P2
[
2
]
==
'z'
);
P1
[
0
]
=
99
;
assert
(
P2
[
0
]
==
99
);
printf
(
"OK
\n
"
);
return
0
;
}
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