std.os: add missing mmap errors

Man page for posix lists EMFILE, man page for linux ENFILE.
Also posix says "The mmap() function adds an extra reference to the file
associated with the file descriptor fildes which is not removed by a
subsequent close() on that file descriptor. This reference is removed
when there are no more mappings to the file."

It sounds counter-intuitive, that a process limit but no system limit can
be exceeeded.

As far as I understand, fildes is only used for file descriptor backed mmaps.
This commit is contained in:
Jan Philipp Hafer
2023-03-05 18:41:52 +01:00
committed by Andrew Kelley
parent ecc0108cea
commit 06b263825a
2 changed files with 26 additions and 18 deletions

View File

@@ -945,6 +945,7 @@ const LinuxThreadImpl = struct {
// map all memory needed without read/write permissions
// to avoid committing the whole region right away
// anonymous mapping ensures file descriptor limits are not exceeded
const mapped = os.mmap(
null,
map_bytes,
@@ -956,6 +957,8 @@ const LinuxThreadImpl = struct {
error.MemoryMappingNotSupported => unreachable,
error.AccessDenied => unreachable,
error.PermissionDenied => unreachable,
error.ProcessFdQuotaExceeded => unreachable,
error.SystemFdQuotaExceeded => unreachable,
else => |e| return e,
};
assert(mapped.len >= map_bytes);