-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.os.linux.ifmap
contains fields of incorrect width
#19980
Comments
I'm not totally sure how to fix this, but am willing to submit a PR. Would the following be appropriate to determine the size of the field? // ...
mem_start: if (@import("builtin").cpu.arch == .x86_64) u64 else u32;
mem_end: if (@import("builtin").cpu.arch == .x86_64) u64 else u32;
// ... Or would it be better to make the fields |
I think |
Does zig support 16-bit architectures? If so, wouldn't |
possibly related: #5185 |
Ah ok, I understand. Thanks for the info! |
Zig Version
0.13.0-dev.211+6a65561e3
Steps to Reproduce and Observed Behavior
std.os.linux.ifmap
is currently defined as:Note the fields
mem_start
andmem_end
, which are defined asu32
s.On linux,
struct ifmap
is defined as:Note the fields
mem_start
andmem_end
are defined asunsigned long int
s. On 64-bit systems,sizeof(unsigned long int) == 8
.On my 64-bit system, the
u32
s cause incorrect size ofstd.os.linux.ifmap
:@sizeOf(std.os.linux.ifmap) == 32
sizeof(struct ifmap) == 40
.This breaks most
ioctl
s to configure network devices. I initially discovered this issue when trying to loop through each network device via theSIOCGIFCONF
ioctl
.Expected Behavior
I expect the size of
std.os.linux.ifmap
to be identical tostruct ifmap
.The C standard guarantees
long
is at least 32 bits but it doesn't, as far as I'm aware, make guarantees about the max size of along
. This causes the 4 byte discrepancy in each field (8 bytes total) between 32-bit and 64-bit architectures.The text was updated successfully, but these errors were encountered: