|
| 1 | +const std = @import("std"); |
| 2 | +const Allocator = std.mem.Allocator; |
| 3 | +const os = @import("../os.zig"); |
| 4 | + |
| 5 | +pub const Map = extern struct { |
| 6 | + offset: c_ulong = 0, |
| 7 | + size: c_ulong = 0, |
| 8 | + type: Type = undefined, |
| 9 | + flags: u8 = 0, |
| 10 | + handle: usize = 0, |
| 11 | + mtrr: c_int = 0, |
| 12 | + |
| 13 | + pub const reqGet = os.IOCTL.IOWR(0x4, Map); |
| 14 | + pub const reqAdd = os.IOCTL.IOWR(0x15, Map); |
| 15 | + pub const reqRemove = os.IOCTL.IOWR(0x1B, Map); |
| 16 | + |
| 17 | + pub fn get(self: *Map, fd: std.os.fd_t) !void { |
| 18 | + return switch (std.os.errno(os.ioctl(fd, reqGet, @intFromPtr(self)))) { |
| 19 | + .SUCCESS => {}, |
| 20 | + .BADF => error.NotOpenForWriting, |
| 21 | + .NOENT => error.NotFound, |
| 22 | + .FAULT => unreachable, |
| 23 | + .INVAL => unreachable, |
| 24 | + .NOTTY => error.NotATerminal, |
| 25 | + .OPNOTSUPP => error.NotSupported, |
| 26 | + else => |e| std.os.unexpectedErrno(e), |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + pub fn add(self: *Map, fd: std.os.fd_t) !void { |
| 31 | + return switch (std.os.errno(os.ioctl(fd, reqAdd, @intFromPtr(self)))) { |
| 32 | + .SUCCESS => {}, |
| 33 | + .BADF => error.NotOpenForWriting, |
| 34 | + .NOENT => error.NotFound, |
| 35 | + .FAULT => unreachable, |
| 36 | + .INVAL => unreachable, |
| 37 | + .NOTTY => error.NotATerminal, |
| 38 | + .OPNOTSUPP => error.NotSupported, |
| 39 | + else => |e| std.os.unexpectedErrno(e), |
| 40 | + }; |
| 41 | + } |
| 42 | + |
| 43 | + pub fn remove(self: *Map, fd: std.os.fd_t) !void { |
| 44 | + return switch (std.os.errno(os.ioctl(fd, reqRemove, @intFromPtr(self)))) { |
| 45 | + .SUCCESS => {}, |
| 46 | + .BADF => error.NotOpenForWriting, |
| 47 | + .NOENT => error.NotFound, |
| 48 | + .FAULT => unreachable, |
| 49 | + .INVAL => unreachable, |
| 50 | + .NOTTY => error.NotATerminal, |
| 51 | + .OPNOTSUPP => error.NotSupported, |
| 52 | + else => |e| std.os.unexpectedErrno(e), |
| 53 | + }; |
| 54 | + } |
| 55 | + |
| 56 | + pub const Type = enum(u8) { |
| 57 | + framebuffer = 0, |
| 58 | + registers = 1, |
| 59 | + shm = 2, |
| 60 | + agp = 3, |
| 61 | + scatterGather = 4, |
| 62 | + consistent = 5, |
| 63 | + }; |
| 64 | + |
| 65 | + pub const Flags = enum(u8) { |
| 66 | + restricted = 1, |
| 67 | + readOnly = 2, |
| 68 | + locked = 3, |
| 69 | + kernel = 8, |
| 70 | + writeCombining = 0x10, |
| 71 | + containsLock = 0x20, |
| 72 | + removable = 0x40, |
| 73 | + driver = 0x80, |
| 74 | + }; |
| 75 | +}; |
0 commit comments