authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-10 21:04:20+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-10 21:04:20+01:00
log9acfd167fa80e14b7beb1eb29830cb0c7d50e586
treebf95345561b37a4643287029ab80588045a1da17
parentec25b138481e16f2d73d12ed6ffacd8e7ba65e94
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.process: add PermissionDenied to ProtectMemoryError (for OpenBSD)

See EPERM notes on https://man.openbsd.org/mprotect.2.

1 files changed, 5 insertions(+), 0 deletions(-)

lib/std/process.zig+5
...@@ -1004,6 +1004,10 @@ pub fn unlockMemoryAll() UnlockMemoryError!void {...@@ -1004,6 +1004,10 @@ pub fn unlockMemoryAll() UnlockMemoryError!void {
10041004
1005pub const ProtectMemoryError = error{1005pub const ProtectMemoryError = error{
1006 UnsupportedOperation,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 /// The memory cannot be given the specified access. This can happen, for1011 /// The memory cannot be given the specified access. This can happen, for
1008 /// example, if you memory map a file to which you have read-only access,1012 /// example, if you memory map a file to which you have read-only access,
1009 /// then use `protectMemory` to mark it writable.1013 /// then use `protectMemory` to mark it writable.
...@@ -1052,6 +1056,7 @@ pub fn protectMemory(...@@ -1052,6 +1056,7 @@ pub fn protectMemory(
1052 };1056 };
1053 switch (posix.errno(posix.system.mprotect(memory.ptr, memory.len, flags))) {1057 switch (posix.errno(posix.system.mprotect(memory.ptr, memory.len, flags))) {
1054 .SUCCESS => return,1058 .SUCCESS => return,
1059 .PERM => return error.PermissionDenied,
1055 .INVAL => |err| return std.Io.Threaded.errnoBug(err),1060 .INVAL => |err| return std.Io.Threaded.errnoBug(err),
1056 .ACCES => return error.AccessDenied,1061 .ACCES => return error.AccessDenied,
1057 .NOMEM => return error.OutOfMemory,1062 .NOMEM => return error.OutOfMemory,