Skip to content

Commit 0bea78a

Browse files
authored
Merge pull request #115 from WorksButNotTested/dontdump
Fix madvise(MADV_DONTDUMP)
2 parents d20fb07 + ad4b20f commit 0bea78a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

linux-user/mmap.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,20 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
12481248
switch (advice) {
12491249
case MADV_DONTDUMP:
12501250
if (len > 0) {
1251-
page_set_flags(start, start + len - 1, PAGE_DONTDUMP);
1251+
/*
1252+
* To set the page permissons, we must OR our new flags with the
1253+
* existing flags. Only mark the pages as PAGE_DONTDUMP if the
1254+
* entire range has the same flags. If any part of the range
1255+
* differs, we would need to process it one page at a time which
1256+
* might not be very performant. Since we are not obliged to respect
1257+
* this flag, we will support it for the most likely usage scenario.
1258+
* Note that we don't set PAGE_ANON, since this can only be set with
1259+
* new mappings.
1260+
*/
1261+
int flg = page_get_flags(start);
1262+
if (page_check_range(start, len, flg)) {
1263+
page_set_flags(start, start + len - 1, PAGE_DONTDUMP | (flg & ~PAGE_ANON) );
1264+
}
12521265
}
12531266
break;
12541267
case MADV_WIPEONFORK:

0 commit comments

Comments
 (0)