tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: [PATCH] procfs: match /proc/self/maps address width to Linux
On Mon, Aug 3, 2026 at 7:07 AM Stephen Borrill <netbsd%precedence.co.uk@localhost> wrote:
>
> > One review question could be whether it would be better to modify the
> > call to snprintf(3) to not use 'width' at all.
>
> I think that /proc/self/maps should be implementation-compatible with
> Linux. Not using width at all would not be compatible as Linux zero-pads
> to 8 (but no more).
Yes, we cannot remove it entirely, but now that width has a fixed value of 8,
we could just embed it directly in the snprintf(3) format string. (See
diff V2 bellow)
I kept the width variable mainly to minimize the diff and keep the change close
to the existing structure, but it is simple to remove it.
> Henrique's question really is, does anything actually care about the
> layout of maps outside of Linux apps (and Linuxy apps being built for
> NetBSD)? If there are no counter-arguments, I'll commit his patch.
I did some grepping around NetBSD src/ and couldn’t find anything that
this could break. Also, based on my testing, everything seemed to be fine.
Diff without the 'width' variable:
[PATCH V2]
diff --git a/sys/miscfs/procfs/procfs_map.c b/sys/miscfs/procfs/procfs_map.c
index d37e357c333..a3d5ba43a2e 100644
--- a/sys/miscfs/procfs/procfs_map.c
+++ b/sys/miscfs/procfs/procfs_map.c
@@ -120,8 +120,6 @@ 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;
if (uio->uio_rw != UIO_READ)
return EOPNOTSUPP;
@@ -166,15 +164,15 @@ again:
}
}
pos += snprintf(buffer + pos, bufsize - pos,
- "%.*"PRIxVADDR"-%.*"PRIxVADDR" %c%c%c%c "
- "%.*lx %.2llx:%.2llx %-8ld %25.s %s\n",
- width, entry->start,
- width, entry->end,
+ "%08"PRIxVADDR"-%08"PRIxVADDR" %c%c%c%c "
+ "%08lx %.2llx:%.2llx %-8ld %25.s %s\n",
+ entry->start,
+ entry->end,
(entry->protection & VM_PROT_READ) ? 'r' : '-',
(entry->protection & VM_PROT_WRITE) ? 'w' : '-',
(entry->protection & VM_PROT_EXECUTE) ? 'x' : '-',
(entry->etype & UVM_ET_COPYONWRITE) ? 'p' : 's',
- width, (unsigned long)entry->offset,
+ (unsigned long)entry->offset,
(unsigned long long)major(dev),
(unsigned long long)minor(dev), fileid, "", path);
} else {
--
Henrique Brito
Home |
Main Index |
Thread Index |
Old Index