[PATCH v2] linux-user: Emulate the Anonymous: keyword in /proc/self/smaps

Ilya Leoshkevich posted 1 patch 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230807122206.655701-1-iii@linux.ibm.com
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/syscall.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
[PATCH v2] linux-user: Emulate the Anonymous: keyword in /proc/self/smaps
Posted by Ilya Leoshkevich 9 months ago
Core dumps produced by gdb's gcore when connected to qemu's gdbstub
lack stack. The reason is that gdb includes only anonymous memory in
core dumps, which is distinguished by a non-0 Anonymous: value.

Consider the mappings with PAGE_ANON fully anonymous, and the mappings
without it fully non-anonymous.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---

v1: https://lists.gnu.org/archive/html/qemu-devel/2023-08/msg00848.html
v1 -> v2: Fix a build issue when TARGET_VSYSCALL_PAGE is set.

 linux-user/syscall.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7c2c2f6e2fa..3dd493486f6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8037,7 +8037,7 @@ static int open_self_cmdline(CPUArchState *cpu_env, int fd)
     return 0;
 }
 
-static void show_smaps(int fd, unsigned long size)
+static void show_smaps(int fd, unsigned long size, int flags)
 {
     unsigned long page_size_kb = TARGET_PAGE_SIZE >> 10;
     unsigned long size_kb = size >> 10;
@@ -8053,7 +8053,7 @@ static void show_smaps(int fd, unsigned long size)
                 "Private_Clean:         0 kB\n"
                 "Private_Dirty:         0 kB\n"
                 "Referenced:            0 kB\n"
-                "Anonymous:             0 kB\n"
+                "Anonymous:             %lu kB\n"
                 "LazyFree:              0 kB\n"
                 "AnonHugePages:         0 kB\n"
                 "ShmemPmdMapped:        0 kB\n"
@@ -8063,7 +8063,9 @@ static void show_smaps(int fd, unsigned long size)
                 "Swap:                  0 kB\n"
                 "SwapPss:               0 kB\n"
                 "Locked:                0 kB\n"
-                "THPeligible:    0\n", size_kb, page_size_kb, page_size_kb);
+                "THPeligible:    0\n",
+            size_kb, page_size_kb, page_size_kb,
+            (flags & PAGE_ANON) ? size_kb : 0);
 }
 
 static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps)
@@ -8114,7 +8116,7 @@ static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps)
                 dprintf(fd, "\n");
             }
             if (smaps) {
-                show_smaps(fd, max - min);
+                show_smaps(fd, max - min, flags);
                 dprintf(fd, "VmFlags:%s%s%s%s%s%s%s%s\n",
                         (flags & PAGE_READ) ? " rd" : "",
                         (flags & PAGE_WRITE_ORG) ? " wr" : "",
@@ -8140,7 +8142,7 @@ static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps)
                     TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE);
     dprintf(fd, "%*s%s\n", 73 - count, "",  "[vsyscall]");
     if (smaps) {
-        show_smaps(fd, TARGET_PAGE_SIZE);
+        show_smaps(fd, TARGET_PAGE_SIZE, PAGE_EXEC);
         dprintf(fd, "VmFlags: ex\n");
     }
 #endif
-- 
2.41.0