NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Why are there physmem and physmem64?



2017-02-17 4:19 GMT+09:00 Thor Lancelot Simon <tls%panix.com@localhost>:
>> >> How about replace physmem64 to physmem ?
>> >> remove: physmem
>> >> rename: physmem64 -> physmem
>> > This breaks binary compatibility (old programs might query "physmem"
>> > hard coded as a 32bit value).
>> Oh my god...
> I'm not sure I understand the reason for your shock.  "physmem" has been
> present, as a 32-bit value, in the sysctl MIB for roughly 30 years.  We
> can't just break binary compatibility with programs that use it.  In fact,
> changing the type in question would probably break source compatibility
> for numerous programs, too.

It is necessary to consider compatibility...
We do not know the scope of the impact of the change, so We can not
change it to a habit.
I GOOGLE. Even when changing time_t to 64 bit, it seems there were
some applications that had decided on 32bit.

e.g: https://mail-index.netbsd.org/tech-userlevel/2008/03/22/msg000231.html


Actually, My machine has 3GB memory. `sysctl -n hw.physmem` output
negative value(hw.physmem64 is output correctly):

% /sbin/sysctl -n hw.physmem hw.physmem64
-1074204672
3220762624

Because hw.physmem is signed int. Why does not hw.physmem have
CTLFLAG_UNSIGNED flag? memory value will not be negative.
https://nxr.netbsd.org/xref/src/sys/kern/init_sysctl_base.c#224

If hw.physmem has CTLFLAG_UNSIGNED flag, it will be output correctly.
(However, `sizeof(int)` is not specified. )
https://nxr.netbsd.org/xref/src/sbin/sysctl/sysctl.c#1910

If change it, sysctl work correctly.

% cd /usr/src/sys/kern
% diff -u init_sysctl.c.src init_sysctl.c
--- init_sysctl.c.src   2017-02-17 19:40:47.000000000 +0900
+++ init_sysctl.c       2017-02-17 19:41:20.000000000 +0900
@@ -671,7 +671,7 @@
        u = ((u_int)physmem > (UINT_MAX / PAGE_SIZE)) ?
                UINT_MAX : physmem * PAGE_SIZE;
        sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
+                      CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE|CTLFLAG_UNSIGNED,
                       CTLTYPE_INT, "physmem",
                       SYSCTL_DESCR("Bytes of physical memory"),
                       NULL, u, NULL, 0,


% /sbin/sysctl -n hw.physmem hw.physmem64
3220762624
3220762624


Home | Main Index | Thread Index | Old Index