Subject: sysctl(HW_KERNEL_BITS), sysconf(_SC_KERNEL_BITS)
To: None <tech-kern@netbsd.org>
From: Simon Burge <simonb@netbsd.org>
List: tech-kern
Date: 04/20/2000 15:28:50
Darren Reed wrote:
> In some email I received from Simon Burge, sie wrote:
> > Eduardo Horvath wrote:
> >
> > > On Tue, 18 Apr 2000, Simon Burge wrote:
> > >
> > > > 3) Need the size of "char **" for same reasons as 2).
> > > >
> > > > Is there an easy way to tell if a process is a 32 or 64 bit process?
> > >
> > > No. But I added a P_32 flag to the proc struct to indicate that a process
> > > is running under 32-bit emulation.
> >
> > So for the 32 bit emul case, you'd need to know the possibility that
> > you might be running under emulation, which isn't really possible (eg,
> > mips ps today, with mips64 maybe occuring one day). But if we stored
> > the kernel's idea of the pointer size and looking at P_32 if the pointer
> > size is 8 bytes then we should be able to cover all possibilities...
> >
> > sysctl HW_KERNPTRSIZE ?
>
> I don't see anything in Solaris7 but HP-UX 11.0 has the following
> for sysconf():
Cool, but it's not on the HP-UX 9 box I have access to :-(
Make's it easier to choose a name when someone else has done it for you!
The following does the job for me. On an alpha:
alpha:~ 43> sysctl hw.kernel_bits
hw.kernel_bits = 64
alpha:~ 44> getconf KERNEL_BITS
64
and a peecee:
wincen:~ 47> sysctl hw.kernel_bits
hw.kernel_bits = 32
wincen:~ 48> getconf KERNEL_BITS
32
The HP description (that also matches current reality for NetBSD) of
"bits for a pointer _or_ long" - is this wording a concern?
Simon.
--
Index: lib/libc/gen/sysconf.3
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/gen/sysconf.3,v
retrieving revision 1.14
diff -p -u -r1.14 sysconf.3
--- sysconf.3 1999/09/27 16:27:12 1.14
+++ sysconf.3 2000/04/20 05:21:59
@@ -183,6 +183,8 @@ otherwise \-1.
.It Li _SC_2_UPE
Return 1 if the system supports the User Portability Utilities Option,
otherwise \-1.
+.It Li _SC_KERNEL_BITS
+Return the number of bits in a kernel pointer or long data type.
.El
.Sh RETURN VALUES
If the call to
Index: lib/libc/gen/sysconf.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/gen/sysconf.c,v
retrieving revision 1.12
diff -p -u -r1.12 sysconf.c
--- sysconf.c 2000/01/22 22:19:12 1.12
+++ sysconf.c 2000/04/20 05:21:59
@@ -232,6 +232,15 @@ sysconf(name)
case _SC_XOPEN_SHM:
mib[0] = CTL_KERN;
mib[1] = KERN_SYSVSHM;
+ goto yesno;
+ break;
+
+/* extensions */
+ case _SC_KERNEL_BITS:
+ mib[0] = CTL_HW;
+ mib[1] = HW_KERNEL_BITS;
+ break;
+
yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
return (-1);
if (value == 0)
Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/kern_sysctl.c,v
retrieving revision 1.61
diff -p -u -r1.61 kern_sysctl.c
--- kern_sysctl.c 2000/04/15 04:38:07 1.61
+++ kern_sysctl.c 2000/04/20 05:21:59
@@ -468,6 +473,8 @@ hw_sysctl(name, namelen, oldp, oldlenp,
return (sysctl_rdint(oldp, oldlenp, newp, PAGE_SIZE));
case HW_ALIGNBYTES:
return (sysctl_rdint(oldp, oldlenp, newp, ALIGNBYTES));
+ case HW_KERNEL_BITS:
+ return (sysctl_rdint(oldp, oldlenp, newp, sizeof(long) * NBBY));
default:
return (EOPNOTSUPP);
}
Index: sys/sys/sysctl.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/sysctl.h,v
retrieving revision 1.45
diff -p -u -r1.45 sysctl.h
--- sysctl.h 2000/04/15 17:51:27 1.45
+++ sysctl.h 2000/04/20 05:22:00
@@ -273,7 +364,8 @@ struct kinfo_proc {
#define HW_DISKSTATS 9 /* struct: diskstats[] */
#define HW_MACHINE_ARCH 10 /* string: machine architecture */
#define HW_ALIGNBYTES 11 /* int: ALIGNBYTES for the kernel */
-#define HW_MAXID 12 /* number of valid hw ids */
+#define HW_KERNEL_BITS 12 /* int: bits in a kernep pointer/long */
+#define HW_MAXID 13 /* number of valid hw ids */
#define CTL_HW_NAMES { \
{ 0, 0 }, \
@@ -288,6 +380,7 @@ struct kinfo_proc {
{ "diskstats", CTLTYPE_STRUCT }, \
{ "machine_arch", CTLTYPE_STRING }, \
{ "alignbytes", CTLTYPE_INT }, \
+ { "kernel_bits", CTLTYPE_INT }, \
}
/*
Index: usr.bin/getconf/getconf.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/getconf/getconf.c,v
retrieving revision 1.12
diff -p -u -r1.12 getconf.c
--- getconf.c 2000/04/20 00:41:20 1.12
+++ getconf.c 2000/04/20 05:22:00
@@ -152,6 +152,10 @@ const struct conf_variable conf_table[]
/* X/Open CAE Spec. Issue 5 Version 2 Configurable System Variables */
{ "FILESIZEBITS", PATHCONF, _PC_FILESIZEBITS },
+
+ /* Extensions */
+ { "KERNEL_BITS", SYSCONF, _SC_KERNEL_BITS },
+
{ NULL }
};