Skip to content
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

@sizeOf on a struct is wrong #7213

Closed
bark2 opened this issue Nov 24, 2020 · 1 comment
Closed

@sizeOf on a struct is wrong #7213

bark2 opened this issue Nov 24, 2020 · 1 comment
Milestone

Comments

@bark2
Copy link

bark2 commented Nov 24, 2020

const std = @import("std");

const TtEntry1 = packed struct {
    valid: u1 = 0, // [0:0]
    walk: u1 = 0, // [1:1]
    indx: u2 = 0, //  [2:3]
    ns: u1 = 0, // security bit (EL3 or Secure EL1), [4:4]
    ap: u2 = 0, // access permission, [5:6]
    sh: u2 = 0, // shareable attribute, [7:8]
    af: u1 = 0, // access flag, [9:9]
    ng: u1 = 0, // not global, [10:10]
    reserved1: u1 = 0, // [11:11]
    addr: u36 = 0, // [12:47]
    reserve2: u5 = 0, // [48:52]
    pxn: u1 = 0, // [53:53]
    uxn: u1 = 0, // [54:54]
    software_use: u4 = 0, // [55:58]
    ignored: u5 = 0, // [59:63]
};

const TtEntry2 = packed struct {
    valid: u1 = 0, // [0]
    walk: u1 = 0, // [1]
    indx: u3 = 0, //  [2:4]
    ns: u1 = 0, // security bit (EL3 or Secure EL1), [5]
    ap: u2 = 0, // access permission, [6:7]
    sh: u2 = 0, // shareable attribute, [8:9]
    af: u1 = 0, // access flag, [10]
    ng: u1 = 0, // not global, [11]
    addr: u36 = 0, // [12:47]
    res1: u2 = 0, // [48:49]
    gp: u1 = 0, // [50]
    dbm: u1 = 0, // [51]
    continuous: u1 = 0, // [52]
    pxn: u1 = 0, // [53]
    uxn: u1 = 0, // [54]
    software_use: u4 = 0, // [55:58]
    ignored: u5 = 0, // [59:63]
};

test "sizeOf" {
    std.debug.print("\n@bitSizeOf 1: {}\n", .{@bitSizeOf(TtEntry1)});
    std.debug.print("@bitSizeOf 2: {}\n", .{@bitSizeOf(TtEntry2)});
    std.debug.print("@sizeOf 1: {}\n", .{@sizeOf(TtEntry1)});
    std.debug.print("@sizeOf 2: {}\n", .{@sizeOf(TtEntry2)});
}
~/src/kernel zig version                                                                                                
0.7.0
~/src/kernel zig test src/test.zig                                                                                      
Test [1/1] test "sizeOf"... 
@bitSizeOf 1: 64
@bitSizeOf 2: 64
@sizeOf 1: 8
@sizeOf 2: 9
All 1 tests passed.
@Aransentin
Copy link
Contributor

Packed structs are unfortunately a bit broken at the moment. #2627 is the issue for it.

@Vexu Vexu closed this as completed Nov 27, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants