mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
stdlib: handle EEXIST in mmap with FIXED_NOREPLACE. Fixes #21475
This commit is contained in:
parent
ecc76348e6
commit
1cc388d526
@ -1420,6 +1420,7 @@ const LinuxThreadImpl = struct {
|
||||
error.PermissionDenied => unreachable,
|
||||
error.ProcessFdQuotaExceeded => unreachable,
|
||||
error.SystemFdQuotaExceeded => unreachable,
|
||||
error.MappingAlreadyExists => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
assert(mapped.len >= map_bytes);
|
||||
|
||||
@ -2434,14 +2434,17 @@ pub const ElfModule = struct {
|
||||
const end_pos = elf_file.getEndPos() catch return bad();
|
||||
const file_len = cast(usize, end_pos) orelse return error.Overflow;
|
||||
|
||||
const mapped_mem = try std.posix.mmap(
|
||||
const mapped_mem = std.posix.mmap(
|
||||
null,
|
||||
file_len,
|
||||
std.posix.PROT.READ,
|
||||
.{ .TYPE = .SHARED },
|
||||
elf_file.handle,
|
||||
0,
|
||||
);
|
||||
) catch |err| switch (err) {
|
||||
error.MappingAlreadyExists => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
errdefer std.posix.munmap(mapped_mem);
|
||||
|
||||
return load(
|
||||
|
||||
@ -4754,6 +4754,9 @@ pub const MMapError = error{
|
||||
ProcessFdQuotaExceeded,
|
||||
SystemFdQuotaExceeded,
|
||||
OutOfMemory,
|
||||
|
||||
/// Using FIXED_NOREPLACE flag and the process has already mapped memory at the given address
|
||||
MappingAlreadyExists,
|
||||
} || UnexpectedError;
|
||||
|
||||
/// Map files or devices into memory.
|
||||
@ -4792,6 +4795,7 @@ pub fn mmap(
|
||||
.MFILE => return error.ProcessFdQuotaExceeded,
|
||||
.NFILE => return error.SystemFdQuotaExceeded,
|
||||
.NOMEM => return error.OutOfMemory,
|
||||
.EXIST => return error.MappingAlreadyExists,
|
||||
else => return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user