| author | |
| committer | |
| log | d2b5105f54ac83fdd874df9408157773ae203798 |
| tree | 2c8b0d67123d2d619b154600d6c65da9274fd17f |
| parent | f0b1eec8095e442218ff9171e284393102596dc4 |
| signature |
* Add Linux ioctl creation utilities
* Apply suggestions from code review
Co-authored-by: Veikka Tuominen <git@vexu.eu>
* Update lib/std/os/linux.zig
Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>2 files changed, 64 insertions(+), 7 deletions(-)
lib/std/os/linux.zig+8-7| ... | ... | @@ -89,6 +89,7 @@ pub const user_desc = arch_bits.user_desc; |
| 89 | 89 | pub const tls = @import("linux/tls.zig"); |
| 90 | 90 | pub const pie = @import("linux/start_pie.zig"); |
| 91 | 91 | pub const BPF = @import("linux/bpf.zig"); |
| 92 | pub const IOCTL = @import("linux/ioctl.zig"); | |
| 92 | 93 | |
| 93 | 94 | pub const MAP = struct { |
| 94 | 95 | pub usingnamespace arch_bits.MAP; |
| ... | ... | @@ -2585,18 +2586,18 @@ pub const T = struct { |
| 2585 | 2586 | pub const IOCGSID = 0x5429; |
| 2586 | 2587 | pub const IOCGRS485 = 0x542E; |
| 2587 | 2588 | pub const IOCSRS485 = 0x542F; |
| 2588 | pub const IOCGPTN = 0x80045430; | |
| 2589 | pub const IOCSPTLCK = 0x40045431; | |
| 2590 | pub const IOCGDEV = 0x80045432; | |
| 2589 | pub const IOCGPTN = IOCTL.IOR('T', 0x30, c_uint); | |
| 2590 | pub const IOCSPTLCK = IOCTL.IOW('T', 0x31, c_int); | |
| 2591 | pub const IOCGDEV = IOCTL.IOR('T', 0x32, c_uint); | |
| 2591 | 2592 | pub const CGETX = 0x5432; |
| 2592 | 2593 | pub const CSETX = 0x5433; |
| 2593 | 2594 | pub const CSETXF = 0x5434; |
| 2594 | 2595 | pub const CSETXW = 0x5435; |
| 2595 | pub const IOCSIG = 0x40045436; | |
| 2596 | pub const IOCSIG = IOCTL.IOW('T', 0x36, c_int); | |
| 2596 | 2597 | pub const IOCVHANGUP = 0x5437; |
| 2597 | pub const IOCGPKT = 0x80045438; | |
| 2598 | pub const IOCGPTLCK = 0x80045439; | |
| 2599 | pub const IOCGEXCL = 0x80045440; | |
| 2598 | pub const IOCGPKT = IOCTL.IOR('T', 0x38, c_int); | |
| 2599 | pub const IOCGPTLCK = IOCTL.IOR('T', 0x39, c_int); | |
| 2600 | pub const IOCGEXCL = IOCTL.IOR('T', 0x40, c_int); | |
| 2600 | 2601 | }; |
| 2601 | 2602 | |
| 2602 | 2603 | pub const EPOLL = struct { |
lib/std/os/linux/ioctl.zig created+56| ... | ... | @@ -0,0 +1,56 @@ |
| 1 | const std = @import("../../std.zig"); | |
| 2 | ||
| 3 | const bits = switch (@import("builtin").cpu.arch) { | |
| 4 | .mips, | |
| 5 | .mipsel, | |
| 6 | .mips64, | |
| 7 | .mips64el, | |
| 8 | .powerpc, | |
| 9 | .powerpcle, | |
| 10 | .powerpc64, | |
| 11 | .powerpc64le, | |
| 12 | .sparc, | |
| 13 | .sparcv9, | |
| 14 | .sparcel, | |
| 15 | => .{ .size = 13, .dir = 3, .none = 1, .read = 2, .write = 4 }, | |
| 16 | else => .{ .size = 14, .dir = 2, .none = 0, .read = 2, .write = 1 }, | |
| 17 | }; | |
| 18 | ||
| 19 | const Direction = std.meta.Int(.unsigned, bits.dir); | |
| 20 | ||
| 21 | pub const Request = packed struct { | |
| 22 | nr: u8, | |
| 23 | io_type: u8, | |
| 24 | size: std.meta.Int(.unsigned, bits.size), | |
| 25 | dir: Direction, | |
| 26 | }; | |
| 27 | ||
| 28 | fn io_impl(dir: Direction, io_type: u8, nr: u8, comptime T: type) u32 { | |
| 29 | const request = Request{ | |
| 30 | .dir = dir, | |
| 31 | .size = @sizeOf(T), | |
| 32 | .io_type = io_type, | |
| 33 | .nr = nr, | |
| 34 | }; | |
| 35 | return @bitCast(u32, request); | |
| 36 | } | |
| 37 | ||
| 38 | pub fn IO(io_type: u8, nr: u8) u32 { | |
| 39 | return io_impl(bits.none, io_type, nr, void); | |
| 40 | } | |
| 41 | ||
| 42 | pub fn IOR(io_type: u8, nr: u8, comptime T: type) u32 { | |
| 43 | return io_impl(bits.read, io_type, nr, T); | |
| 44 | } | |
| 45 | ||
| 46 | pub fn IOW(io_type: u8, nr: u8, comptime T: type) u32 { | |
| 47 | return io_impl(bits.write, io_type, nr, T); | |
| 48 | } | |
| 49 | ||
| 50 | pub fn IOWR(io_type: u8, nr: u8, comptime T: type) u32 { | |
| 51 | return io_impl(bits.read | bits.write, io_type, nr, T); | |
| 52 | } | |
| 53 | ||
| 54 | comptime { | |
| 55 | std.debug.assert(@bitSizeOf(Request) == 32); | |
| 56 | } |