Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aarch64] IndexError on calling p.memory_maps() #2430

Open
nehaljwani opened this issue Jul 6, 2024 · 0 comments
Open

[aarch64] IndexError on calling p.memory_maps() #2430

nehaljwani opened this issue Jul 6, 2024 · 0 comments

Comments

@nehaljwani
Copy link

nehaljwani commented Jul 6, 2024

Summary

  • OS: Linux
  • Architecture: 64bit
  • Psutil version: 6.0.0
  • Python version: Python 3.12.4
  • Type: core

Description

I'm running a cross compiled python for aarch64. I've a setup qemu-aarch64 as the interpreter at /proc/sys/fs/binfmt_misc/qemu-aarch64 to be able to run the cross compiled program.

>>> import psutil
>>> import os
>>> p = psutil.Process(os.getpid())
>>> p.memory_maps()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/prefix/lib/python3.12/site-packages/psutil/__init__.py", line 1178, in memory_maps
    it = self._proc.memory_maps()
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/prefix/lib/python3.12/site-packages/psutil/_pslinux.py", line 1717, in wrapper
    return fun(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/prefix/lib/python3.12/site-packages/psutil/_pslinux.py", line 2091, in memory_maps
    for header, data in get_blocks(lines, current_block):
  File "/path/to/prefix/lib/python3.12/site-packages/psutil/_pslinux.py", line 2069, in get_blocks
    data[fields[0]] = int(fields[1]) * 1024
                          ~~~~~~^^^
IndexError: list index out of range

As one can see, there is no value in front of VmFlags (in the very first entry):

$ python3 -c "print(repr(open('/proc/self/smaps').read()))"|fmt -
$ /path/to/prefix/python3 -c "print(repr(open('/proc/self/smaps').read()))"|fmt - | head -30
'400000000000-400000001000 ---p 00000000 00:00 0
\nSize:                  4 kB\nKernelPageSize:        4 kB\nMMUPageSize:
4 kB\nRss:                   0 kB\nPss:                   0 kB\nPss_Dirty:
0 kB\nShared_Clean:          0 kB\nShared_Dirty:          0
kB\nPrivate_Clean:         0 kB\nPrivate_Dirty:         0
kB\nReferenced:            0 kB\nAnonymous:             0
kB\nLazyFree:              0 kB\nAnonHugePages:         0
kB\nShmemPmdMapped:        0 kB\nFilePmdMapped:         0
kB\nShared_Hugetlb:        0 kB\nPrivate_Hugetlb:       0 kB\nSwap:
0 kB\nSwapPss:               0 kB\nLocked:                0
kB\nTHPeligible:    0\nVmFlags:\n400000001000-400000801000 rw-p 00000000
00:00 0                          [stack]\nSize:                  8192
kB\nKernelPageSize:        4 kB\nMMUPageSize:           4 kB\nRss:
0 kB\nPss:                   0 kB\nPss_Dirty:             0
kB\nShared_Clean:          0 kB\nShared_Dirty:          0
kB\nPrivate_Clean:         0 kB\nPrivate_Dirty:         0 kB\nReferenced:
0 kB\nAnonymous:             0 kB\nLazyFree:              0
kB\nAnonHugePages:         0 kB\nShmemPmdMapped:        0
kB\nFilePmdMapped:         0 kB\nShared_Hugetlb:        0
kB\nPrivate_Hugetlb:       0 kB\nSwap:                  0 kB\nSwapPss:
0 kB\nLocked:                0 kB\nTHPeligible:    0\nVmFlags:
rd wr mr mw\n400000801000-40000081f000 r-xp 00000000 00:1c 23501397
...

The following diff resolves the issue, but I'm not 100% sure if it is the right fix as it seems more like a workaround:

diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 16718388..df183d01 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -2067,7 +2067,7 @@ class Process:
                     else:
                         try:
                             data[fields[0]] = int(fields[1]) * 1024
-                        except ValueError:
+                        except (ValueError, IndexError):
                             if fields[0].startswith(b'VmFlags:'):
                                 # see issue #369
                                 continue

Interestingly enough, if I read the /proc/<pid>/smaps file directly, VmFlags isn't unset:

$ cat /proc/2583591/smaps | head -30
00400000-00401000 r--p 00000000 00:1c 287073                             /opt/qemu-user/bin/qemu-aarch64
Size:                  4 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         4 kB
Private_Dirty:         0 kB
Referenced:            4 kB
Anonymous:             0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:    0
ProtectionKey:         0
VmFlags: rd mr mw me
...
@nehaljwani nehaljwani added the bug label Jul 6, 2024
@github-actions github-actions bot added the linux label Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant