[PATCH] procfs: match /proc/self/maps address width to Linux

Henrique Brito <[email protected]> Fri, 31 Jul 2026 22:25:00 -0300
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <CAMNY2LFvp+MRGxi=-ivb139k5BhUfeyv6VADyQtHa19kqE=FjA@mail.gmail.com>
Hello tech-kern,

I am Henrique, and I am taking part in GSoC 2026
with the "Testing compat_linux" project, mentored
by Stephen Borrill.

As part of the project, I am using LTP (Linux Test Project)
to verify the compatibility of compat_linux, running Linux
syscall test cases against NetBSD's compat_linux, and
investigating divergences from Linux's expected behavior.

One of the test cases, mmap04, was failing because
it could not correctly parse /proc/self/maps.

This happens due to a formatting difference: NetBSD
always pads addresses to a fixed width (8 hex digits
for 32-bit processes, 16 for 64-bit), while Linux only
guarantees a *minimum* of 8 hex digits.

For example, on Linux:
562d71282000-562d71284000 r--p 00000000 103:03 29361187
  /usr/bin/cat

while NetBSD currently produces:
0000000000460000-0000000000461000 r--p 0000000000000000 a8:00 10316226
                          /bin/cat

Since mmap04 builds its expected format string
assuming Linux's minimum-width behavior, the
extra zero-padding on NetBSD causes the
match to fail.

While the existing NetBSD output is neater to look at and
has the benefit of a fixed size, it diverges from Linux behaviour
and the mount_procfs(8) manual page states that maps is
intended to be "in a form like the proc as implemented in Linux",
I suggest that matching this specific behaviour is a desirable
change. Is there any reason not to make this change?

The attached patch changes the width calculation
in procfs_map.c so that addresses are zero-padded
to a minimum of 8 hex digits, matching Linux's format.

I verified the formatting logic in userspace before applying
it to the kernel, then confirmed:

- cat /proc/self/maps produces output matching Linux's
  format for addresses of varying sizes;
- LTP's mmap04 now passes (as far as the issue with maps go);

Patch below:

diff --git a/sys/miscfs/procfs/procfs_map.c b/sys/miscfs/procfs/procfs_map.c
index d37e357c333..40c59ab07f1 100644
--- a/sys/miscfs/procfs/procfs_map.c
+++ b/sys/miscfs/procfs/procfs_map.c
@@ -120,8 +120,7 @@ procfs_domap(struct lwp *curl, struct proc *p,
struct pfsnode *pfs,
        dev_t dev;
        long fileid;
        size_t pos;
-       int width = (int)((curl->l_proc->p_flag & PK_32) ? sizeof(int32_t) :
-           sizeof(void *)) * 2;
+       int width = sizeof(int32_t) * 2;

        if (uio->uio_rw != UIO_READ)

Feedback is very welcome.
Thanks, Henrique