Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
PATCH 1/1 Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
--- include/exec/page-protection.h | 6 ++++++ linux-user/elfload.c | 4 ++++ linux-user/mmap.c | 5 +++++ 3 files changed, 15 insertions(+)
include/exec/page-protection.h +6 -0
@@ -38,4 +38,10 @@*/ #define PAGE_PASSTHROUGH 0x0800 +/* +* For linux-user, indicates that the page should not be included in a core +* dump. +*/ +#define PAGE_DONTDUMP 0x1000 +#endif
linux-user/elfload.c +4 -0
@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,return 0 ; } +if (flags &PAGE_DONTDUMP ) { +return 0 ; + } +/* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from
linux-user/mmap.c +5 -0
@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)*/ mmap_lock ();switch (advice) { +case MADV_DONTDUMP : +if (len >0 ) { +page_set_flags (start, start + len -1 ,PAGE_DONTDUMP ); + } +break ;case MADV_WIPEONFORK :case MADV_KEEPONFORK : ret = -EINVAL ;
Signature · 1 line
2.43.0
Quoted 6 lines · WorksButNotTested
--- include/exec/page-protection.h | 6 ++++++ linux-user/elfload.c | 4 ++++ linux-user/mmap.c | 5 +++++ 3 files changed, 15 insertions(+)
Seems reasonable. Add a patch description and a Signed-off-by, please.
r~
Quoted 46 lines
include/exec/page-protection.h +6
-0@@ -38,4 +38,10 @@*/ #define PAGE_PASSTHROUGH 0x0800 +/* +* For linux-user, indicates that the page should not be included in a core +* dump. +*/ +#define PAGE_DONTDUMP 0x1000 +#endif linux-user/elfload.c +4
-0@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,return 0 ; } +if (flags &PAGE_DONTDUMP ) { +return 0 ; + } +/* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from linux-user/mmap.c +5
-0@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)*/ mmap_lock ();switch (advice) { +case MADV_DONTDUMP : +if (len >0 ) { +page_set_flags (start, start + len -1 ,PAGE_DONTDUMP ); + } +break ;case MADV_WIPEONFORK :case MADV_KEEPONFORK : ret = -EINVAL ;
Awesome. Thanks. How do I do that? Sorry I'm new to this workflow. Can you point me at a reference?
Quoted 65 lines · On Thu, 1 May 2025, 22:27 Richard Henderson, <[email protected]>…
Quoted 6 lines · WorksButNotTested
--- include/exec/page-protection.h | 6 ++++++ linux-user/elfload.c | 4 ++++ linux-user/mmap.c | 5 +++++ 3 files changed, 15 insertions(+)Seems reasonable. Add a patch description and a Signed-off-by, please.
r~
Review
Quoted 1 line
(quoted diff) +0
-0
b/include/exec/page-protection.hinclude/exec/page-protection.h line 42
Quoted 9 lines
index
c43231af8b..f8826d917e100644include/exec/page-protection.h +2
-0@@ -38,4 +38,10 @@*/ #define PAGE_PASSTHROUGH 0x0800 +/* +* For linux-user, indicates that the page should not be included in a core
linux-user/elfload.c static size_t vma_dump_size(target_ulong start,
Quoted 10 lines
include/exec/page-protection.h +4
-0+* dump. +*/ +#define PAGE_DONTDUMP 0x1000 +#endif linux-user/elfload.c +0
-0@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start,
target_ulongend,linux-user/mmap.c abi_long target_madvise(abi_ulong start,
Quoted 15 lines
linux-user/elfload.c +4
-0return 0 ; } +if (flags &PAGE_DONTDUMP ) { +return 0 ; + } +/* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from linux-user/mmap.c +0
-0@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start,
abi_ulonglen_in, int advice)Quoted 11 lines
linux-user/mmap.c +5
-0*/ mmap_lock ();switch (advice) { +case MADV_DONTDUMP : +if (len >0 ) { +page_set_flags (start, start + len -1 ,PAGE_DONTDUMP ); + } +break ;case MADV_WIPEONFORK :case MADV_KEEPONFORK : ret = -EINVAL ;
Quoted 2 lines · Jon Wilson
Awesome. Thanks. How do I do that? Sorry I'm new to this workflow. Can you point me at a reference?
qemu.org -> Contribute -> Patch submission guidelines:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html
Regards,
BALATON Zoltan