| ... | ... | @@ -1004,6 +1004,10 @@ pub fn unlockMemoryAll() UnlockMemoryError!void { |
| 1004 | 1004 | |
| 1005 | 1005 | pub const ProtectMemoryError = error{ |
| 1006 | 1006 | UnsupportedOperation, |
| 1007 | /// OpenBSD will refuse to change memory protection if the specified region |
| 1008 | /// contains any pages that have previously been marked immutable using the |
| 1009 | /// `mimmutable` function. |
| 1010 | PermissionDenied, |
| 1007 | 1011 | /// The memory cannot be given the specified access. This can happen, for |
| 1008 | 1012 | /// example, if you memory map a file to which you have read-only access, |
| 1009 | 1013 | /// then use `protectMemory` to mark it writable. |
| ... | ... | @@ -1052,6 +1056,7 @@ pub fn protectMemory( |
| 1052 | 1056 | }; |
| 1053 | 1057 | switch (posix.errno(posix.system.mprotect(memory.ptr, memory.len, flags))) { |
| 1054 | 1058 | .SUCCESS => return, |
| 1059 | .PERM => return error.PermissionDenied, |
| 1055 | 1060 | .INVAL => |err| return std.Io.Threaded.errnoBug(err), |
| 1056 | 1061 | .ACCES => return error.AccessDenied, |
| 1057 | 1062 | .NOMEM => return error.OutOfMemory, |
| ... | ... | @@ -1061,10 +1066,11 @@ pub fn protectMemory( |
| 1061 | 1066 | return error.UnsupportedOperation; |
| 1062 | 1067 | } |
| 1063 | 1068 | |
| 1069 | var test_page: [std.heap.page_size_max]u8 align(std.heap.page_size_max) = undefined; |
| 1070 | |
| 1064 | 1071 | test lockMemory { |
| 1065 | | var page: [std.heap.page_size_min]u8 align(std.heap.page_size_min) = undefined; |
| 1066 | | lockMemory(&page, .{}) catch return error.SkipZigTest; |
| 1067 | | unlockMemory(&page) catch return error.SkipZigTest; |
| 1072 | lockMemory(&test_page, .{}) catch return error.SkipZigTest; |
| 1073 | unlockMemory(&test_page) catch return error.SkipZigTest; |
| 1068 | 1074 | } |
| 1069 | 1075 | |
| 1070 | 1076 | test lockMemoryAll { |
| ... | ... | @@ -1073,8 +1079,6 @@ test lockMemoryAll { |
| 1073 | 1079 | } |
| 1074 | 1080 | |
| 1075 | 1081 | test protectMemory { |
| 1076 | | if (builtin.cpu.arch == .hexagon) return error.SkipZigTest; // TODO |
| 1077 | | var page: [std.heap.page_size_min]u8 align(std.heap.page_size_min) = undefined; |
| 1078 | | protectMemory(&page, .{}) catch return error.SkipZigTest; |
| 1079 | | protectMemory(&page, .{ .read = true, .write = true }) catch return error.SkipZigTest; |
| 1082 | protectMemory(&test_page, .{}) catch return error.SkipZigTest; |
| 1083 | protectMemory(&test_page, .{ .read = true, .write = true }) catch return error.SkipZigTest; |
| 1080 | 1084 | } |