Skip to content

Commit 00142bf

Browse files
t-8chgregkh
authored andcommitted
kernels/ksysfs.c: export kernel address bits
This can be used by userspace to determine the address size of the running kernel. It frees userspace from having to interpret this information from the UTS machine field. Userspace implementation: util-linux/util-linux#1966 Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/r/20221221-address-bits-v1-1-8446b13244ac@weissschuh.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e5da06b commit 00142bf

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
What: /sys/kernel/address_bit
2+
Date: May 2023
3+
KernelVersion: 6.3
4+
Contact: Thomas Weißschuh <linux@weissschuh.net>
5+
Description:
6+
The address size of the running kernel in bits.
7+
8+
Access: Read
9+
10+
Users: util-linux

kernel/ksysfs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ static ssize_t cpu_byteorder_show(struct kobject *kobj,
5151
}
5252
KERNEL_ATTR_RO(cpu_byteorder);
5353

54+
/* address bits */
55+
static ssize_t address_bits_show(struct kobject *kobj,
56+
struct kobj_attribute *attr, char *buf)
57+
{
58+
return sysfs_emit(buf, "%zu\n", sizeof(void *) * 8 /* CHAR_BIT */);
59+
}
60+
KERNEL_ATTR_RO(address_bits);
61+
5462
#ifdef CONFIG_UEVENT_HELPER
5563
/* uevent helper program, used during early boot */
5664
static ssize_t uevent_helper_show(struct kobject *kobj,
@@ -233,6 +241,7 @@ static struct attribute * kernel_attrs[] = {
233241
&fscaps_attr.attr,
234242
&uevent_seqnum_attr.attr,
235243
&cpu_byteorder_attr.attr,
244+
&address_bits_attr.attr,
236245
#ifdef CONFIG_UEVENT_HELPER
237246
&uevent_helper_attr.attr,
238247
#endif

0 commit comments

Comments
 (0)