Skip to content

Commit

Permalink
sysconf: add _SC_OPEN_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored and RalfJung committed Nov 24, 2024
1 parent b0b5273 commit e713faa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// 512 seems to be a reasonable default. The value is not critical, in
// the sense that getpwuid_r takes and checks the buffer length.
("_SC_GETPW_R_SIZE_MAX", |this| Scalar::from_int(512, this.pointer_size())),
// Miri doesn't have a fixed limit on FDs, but we may be limited in terms of how
// many *host* FDs we can open. Just use some arbitrary, pretty big value;
// this can be adjusted if it causes problems.
// The spec imposes a minimum of `_POSIX_OPEN_MAX` (20).
("_SC_OPEN_MAX", |this| Scalar::from_int(2_i32.pow(16), this.pointer_size())),
];
for &(sysconf_name, value) in sysconfs {
let sysconf_name = this.eval_libc_i32(sysconf_name);
Expand Down
2 changes: 2 additions & 0 deletions tests/pass-dep/libc/libc-sysconf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ fn test_sysconfbasic() {
// note that in reality it can return -1 (no hard limit) on some platforms.
let gwmax = libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX);
assert!(gwmax >= 512);
let omax = libc::sysconf(libc::_SC_OPEN_MAX);
assert_eq!(omax, 65536);
}
}

Expand Down

0 comments on commit e713faa

Please sign in to comment.